Kromek Radangel gamma spectrometer USB HID daemon and WebUI. https://git.unino.de/pvivell/radangel
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

plotly-cartesian-latest.js 2.5MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359373603736137362373633736437365373663736737368373693737037371373723737337374373753737637377373783737937380373813738237383373843738537386373873738837389373903739137392373933739437395373963739737398373993740037401374023740337404374053740637407374083740937410374113741237413374143741537416374173741837419374203742137422374233742437425374263742737428374293743037431374323743337434374353743637437374383743937440374413744237443374443744537446374473744837449374503745137452374533745437455374563745737458374593746037461374623746337464374653746637467374683746937470374713747237473374743747537476374773747837479374803748137482374833748437485374863748737488374893749037491374923749337494374953749637497374983749937500375013750237503375043750537506375073750837509375103751137512375133751437515375163751737518375193752037521375223752337524375253752637527375283752937530375313753237533375343753537536375373753837539375403754137542375433754437545375463754737548375493755037551375523755337554375553755637557375583755937560375613756237563375643756537566375673756837569375703757137572375733757437575375763757737578375793758037581375823758337584375853758637587375883758937590375913759237593375943759537596375973759837599376003760137602376033760437605376063760737608376093761037611376123761337614376153761637617376183761937620376213762237623376243762537626376273762837629376303763137632376333763437635376363763737638376393764037641376423764337644376453764637647376483764937650376513765237653376543765537656376573765837659376603766137662376633766437665376663766737668376693767037671376723767337674376753767637677376783767937680376813768237683376843768537686376873768837689376903769137692376933769437695376963769737698376993770037701377023770337704377053770637707377083770937710377113771237713377143771537716377173771837719377203772137722377233772437725377263772737728377293773037731377323773337734377353773637737377383773937740377413774237743377443774537746377473774837749377503775137752377533775437755377563775737758377593776037761377623776337764377653776637767377683776937770377713777237773377743777537776377773777837779377803778137782377833778437785377863778737788377893779037791377923779337794377953779637797377983779937800378013780237803378043780537806378073780837809378103781137812378133781437815378163781737818378193782037821378223782337824378253782637827378283782937830378313783237833378343783537836378373783837839378403784137842378433784437845378463784737848378493785037851378523785337854378553785637857378583785937860378613786237863378643786537866378673786837869378703787137872378733787437875378763787737878378793788037881378823788337884378853788637887378883788937890378913789237893378943789537896378973789837899379003790137902379033790437905379063790737908379093791037911379123791337914379153791637917379183791937920379213792237923379243792537926379273792837929379303793137932379333793437935379363793737938379393794037941379423794337944379453794637947379483794937950379513795237953379543795537956379573795837959379603796137962379633796437965379663796737968379693797037971379723797337974379753797637977379783797937980379813798237983379843798537986379873798837989379903799137992379933799437995379963799737998379993800038001380023800338004380053800638007380083800938010380113801238013380143801538016380173801838019380203802138022380233802438025380263802738028380293803038031380323803338034380353803638037380383803938040380413804238043380443804538046380473804838049380503805138052380533805438055380563805738058380593806038061380623806338064380653806638067380683806938070380713807238073380743807538076380773807838079380803808138082380833808438085380863808738088380893809038091380923809338094380953809638097380983809938100381013810238103381043810538106381073810838109381103811138112381133811438115381163811738118381193812038121381223812338124381253812638127381283812938130381313813238133381343813538136381373813838139381403814138142381433814438145381463814738148381493815038151381523815338154381553815638157381583815938160381613816238163381643816538166381673816838169381703817138172381733817438175381763817738178381793818038181381823818338184381853818638187381883818938190381913819238193381943819538196381973819838199382003820138202382033820438205382063820738208382093821038211382123821338214382153821638217382183821938220382213822238223382243822538226382273822838229382303823138232382333823438235382363823738238382393824038241382423824338244382453824638247382483824938250382513825238253382543825538256382573825838259382603826138262382633826438265382663826738268382693827038271382723827338274382753827638277382783827938280382813828238283382843828538286382873828838289382903829138292382933829438295382963829738298382993830038301383023830338304383053830638307383083830938310383113831238313383143831538316383173831838319383203832138322383233832438325383263832738328383293833038331383323833338334383353833638337383383833938340383413834238343383443834538346383473834838349383503835138352383533835438355383563835738358383593836038361383623836338364383653836638367383683836938370383713837238373383743837538376383773837838379383803838138382383833838438385383863838738388383893839038391383923839338394383953839638397383983839938400384013840238403384043840538406384073840838409384103841138412384133841438415384163841738418384193842038421384223842338424384253842638427384283842938430384313843238433384343843538436384373843838439384403844138442384433844438445384463844738448384493845038451384523845338454384553845638457384583845938460384613846238463384643846538466384673846838469384703847138472384733847438475384763847738478384793848038481384823848338484384853848638487384883848938490384913849238493384943849538496384973849838499385003850138502385033850438505385063850738508385093851038511385123851338514385153851638517385183851938520385213852238523385243852538526385273852838529385303853138532385333853438535385363853738538385393854038541385423854338544385453854638547385483854938550385513855238553385543855538556385573855838559385603856138562385633856438565385663856738568385693857038571385723857338574385753857638577385783857938580385813858238583385843858538586385873858838589385903859138592385933859438595385963859738598385993860038601386023860338604386053860638607386083860938610386113861238613386143861538616386173861838619386203862138622386233862438625386263862738628386293863038631386323863338634386353863638637386383863938640386413864238643386443864538646386473864838649386503865138652386533865438655386563865738658386593866038661386623866338664386653866638667386683866938670386713867238673386743867538676386773867838679386803868138682386833868438685386863868738688386893869038691386923869338694386953869638697386983869938700387013870238703387043870538706387073870838709387103871138712387133871438715387163871738718387193872038721387223872338724387253872638727387283872938730387313873238733387343873538736387373873838739387403874138742387433874438745387463874738748387493875038751387523875338754387553875638757387583875938760387613876238763387643876538766387673876838769387703877138772387733877438775387763877738778387793878038781387823878338784387853878638787387883878938790387913879238793387943879538796387973879838799388003880138802388033880438805388063880738808388093881038811388123881338814388153881638817388183881938820388213882238823388243882538826388273882838829388303883138832388333883438835388363883738838388393884038841388423884338844388453884638847388483884938850388513885238853388543885538856388573885838859388603886138862388633886438865388663886738868388693887038871388723887338874388753887638877388783887938880388813888238883388843888538886388873888838889388903889138892388933889438895388963889738898388993890038901389023890338904389053890638907389083890938910389113891238913389143891538916389173891838919389203892138922389233892438925389263892738928389293893038931389323893338934389353893638937389383893938940389413894238943389443894538946389473894838949389503895138952389533895438955389563895738958389593896038961389623896338964389653896638967389683896938970389713897238973389743897538976389773897838979389803898138982389833898438985389863898738988389893899038991389923899338994389953899638997389983899939000390013900239003390043900539006390073900839009390103901139012390133901439015390163901739018390193902039021390223902339024390253902639027390283902939030390313903239033390343903539036390373903839039390403904139042390433904439045390463904739048390493905039051390523905339054390553905639057390583905939060390613906239063390643906539066390673906839069390703907139072390733907439075390763907739078390793908039081390823908339084390853908639087390883908939090390913909239093390943909539096390973909839099391003910139102391033910439105391063910739108391093911039111391123911339114391153911639117391183911939120391213912239123391243912539126391273912839129391303913139132391333913439135391363913739138391393914039141391423914339144391453914639147391483914939150391513915239153391543915539156391573915839159391603916139162391633916439165391663916739168391693917039171391723917339174391753917639177391783917939180391813918239183391843918539186391873918839189391903919139192391933919439195391963919739198391993920039201392023920339204392053920639207392083920939210392113921239213392143921539216392173921839219392203922139222392233922439225392263922739228392293923039231392323923339234392353923639237392383923939240392413924239243392443924539246392473924839249392503925139252392533925439255392563925739258392593926039261392623926339264392653926639267392683926939270392713927239273392743927539276392773927839279392803928139282392833928439285392863928739288392893929039291392923929339294392953929639297392983929939300393013930239303393043930539306393073930839309393103931139312393133931439315393163931739318393193932039321393223932339324393253932639327393283932939330393313933239333393343933539336393373933839339393403934139342393433934439345393463934739348393493935039351393523935339354393553935639357393583935939360393613936239363393643936539366393673936839369393703937139372393733937439375393763937739378393793938039381393823938339384393853938639387393883938939390393913939239393393943939539396393973939839399394003940139402394033940439405394063940739408394093941039411394123941339414394153941639417394183941939420394213942239423394243942539426394273942839429394303943139432394333943439435394363943739438394393944039441394423944339444394453944639447394483944939450394513945239453394543945539456394573945839459394603946139462394633946439465394663946739468394693947039471394723947339474394753947639477394783947939480394813948239483394843948539486394873948839489394903949139492394933949439495394963949739498394993950039501395023950339504395053950639507395083950939510395113951239513395143951539516395173951839519395203952139522395233952439525395263952739528395293953039531395323953339534395353953639537395383953939540395413954239543395443954539546395473954839549395503955139552395533955439555395563955739558395593956039561395623956339564395653956639567395683956939570395713957239573395743957539576395773957839579395803958139582395833958439585395863958739588395893959039591395923959339594395953959639597395983959939600396013960239603396043960539606396073960839609396103961139612396133961439615396163961739618396193962039621396223962339624396253962639627396283962939630396313963239633396343963539636396373963839639396403964139642396433964439645396463964739648396493965039651396523965339654396553965639657396583965939660396613966239663396643966539666396673966839669396703967139672396733967439675396763967739678396793968039681396823968339684396853968639687396883968939690396913969239693396943969539696396973969839699397003970139702397033970439705397063970739708397093971039711397123971339714397153971639717397183971939720397213972239723397243972539726397273972839729397303973139732397333973439735397363973739738397393974039741397423974339744397453974639747397483974939750397513975239753397543975539756397573975839759397603976139762397633976439765397663976739768397693977039771397723977339774397753977639777397783977939780397813978239783397843978539786397873978839789397903979139792397933979439795397963979739798397993980039801398023980339804398053980639807398083980939810398113981239813398143981539816398173981839819398203982139822398233982439825398263982739828398293983039831398323983339834398353983639837398383983939840398413984239843398443984539846398473984839849398503985139852398533985439855398563985739858398593986039861398623986339864398653986639867398683986939870398713987239873398743987539876398773987839879398803988139882398833988439885398863988739888398893989039891398923989339894398953989639897398983989939900399013990239903399043990539906399073990839909399103991139912399133991439915399163991739918399193992039921399223992339924399253992639927399283992939930399313993239933399343993539936399373993839939399403994139942399433994439945399463994739948399493995039951399523995339954399553995639957399583995939960399613996239963399643996539966399673996839969399703997139972399733997439975399763997739978399793998039981399823998339984399853998639987399883998939990399913999239993399943999539996399973999839999400004000140002400034000440005400064000740008400094001040011400124001340014400154001640017400184001940020400214002240023400244002540026400274002840029400304003140032400334003440035400364003740038400394004040041400424004340044400454004640047400484004940050400514005240053400544005540056400574005840059400604006140062400634006440065400664006740068400694007040071400724007340074400754007640077400784007940080400814008240083400844008540086400874008840089400904009140092400934009440095400964009740098400994010040101401024010340104401054010640107401084010940110401114011240113401144011540116401174011840119401204012140122401234012440125401264012740128401294013040131401324013340134401354013640137401384013940140401414014240143401444014540146401474014840149401504015140152401534015440155401564015740158401594016040161401624016340164401654016640167401684016940170401714017240173401744017540176401774017840179401804018140182401834018440185401864018740188401894019040191401924019340194401954019640197401984019940200402014020240203402044020540206402074020840209402104021140212402134021440215402164021740218402194022040221402224022340224402254022640227402284022940230402314023240233402344023540236402374023840239402404024140242402434024440245402464024740248402494025040251402524025340254402554025640257402584025940260402614026240263402644026540266402674026840269402704027140272402734027440275402764027740278402794028040281402824028340284402854028640287402884028940290402914029240293402944029540296402974029840299403004030140302403034030440305403064030740308403094031040311403124031340314403154031640317403184031940320403214032240323403244032540326403274032840329403304033140332403334033440335403364033740338403394034040341403424034340344403454034640347403484034940350403514035240353403544035540356403574035840359403604036140362403634036440365403664036740368403694037040371403724037340374403754037640377403784037940380403814038240383403844038540386403874038840389403904039140392403934039440395403964039740398403994040040401404024040340404404054040640407404084040940410404114041240413404144041540416404174041840419404204042140422404234042440425404264042740428404294043040431404324043340434404354043640437404384043940440404414044240443404444044540446404474044840449404504045140452404534045440455404564045740458404594046040461404624046340464404654046640467404684046940470404714047240473404744047540476404774047840479404804048140482404834048440485404864048740488404894049040491404924049340494404954049640497404984049940500405014050240503405044050540506405074050840509405104051140512405134051440515405164051740518405194052040521405224052340524405254052640527405284052940530405314053240533405344053540536405374053840539405404054140542405434054440545405464054740548405494055040551405524055340554405554055640557405584055940560405614056240563405644056540566405674056840569405704057140572405734057440575405764057740578405794058040581405824058340584405854058640587405884058940590405914059240593405944059540596405974059840599406004060140602406034060440605406064060740608406094061040611406124061340614406154061640617406184061940620406214062240623406244062540626406274062840629406304063140632406334063440635406364063740638406394064040641406424064340644406454064640647406484064940650406514065240653406544065540656406574065840659406604066140662406634066440665406664066740668406694067040671406724067340674406754067640677406784067940680406814068240683406844068540686406874068840689406904069140692406934069440695406964069740698406994070040701407024070340704407054070640707407084070940710407114071240713407144071540716407174071840719407204072140722407234072440725407264072740728407294073040731407324073340734407354073640737407384073940740407414074240743407444074540746407474074840749407504075140752407534075440755407564075740758407594076040761407624076340764407654076640767407684076940770407714077240773407744077540776407774077840779407804078140782407834078440785407864078740788407894079040791407924079340794407954079640797407984079940800408014080240803408044080540806408074080840809408104081140812408134081440815408164081740818408194082040821408224082340824408254082640827408284082940830408314083240833408344083540836408374083840839408404084140842408434084440845408464084740848408494085040851408524085340854408554085640857408584085940860408614086240863408644086540866408674086840869408704087140872408734087440875408764087740878408794088040881408824088340884408854088640887408884088940890408914089240893408944089540896408974089840899409004090140902409034090440905409064090740908409094091040911409124091340914409154091640917409184091940920409214092240923409244092540926409274092840929409304093140932409334093440935409364093740938409394094040941409424094340944409454094640947409484094940950409514095240953409544095540956409574095840959409604096140962409634096440965409664096740968409694097040971409724097340974409754097640977409784097940980409814098240983409844098540986409874098840989409904099140992409934099440995409964099740998409994100041001410024100341004410054100641007410084100941010410114101241013410144101541016410174101841019410204102141022410234102441025410264102741028410294103041031410324103341034410354103641037410384103941040410414104241043410444104541046410474104841049410504105141052410534105441055410564105741058410594106041061410624106341064410654106641067410684106941070410714107241073410744107541076410774107841079410804108141082410834108441085410864108741088410894109041091410924109341094410954109641097410984109941100411014110241103411044110541106411074110841109411104111141112411134111441115411164111741118411194112041121411224112341124411254112641127411284112941130411314113241133411344113541136411374113841139411404114141142411434114441145411464114741148411494115041151411524115341154411554115641157411584115941160411614116241163411644116541166411674116841169411704117141172411734117441175411764117741178411794118041181411824118341184411854118641187411884118941190411914119241193411944119541196411974119841199412004120141202412034120441205412064120741208412094121041211412124121341214412154121641217412184121941220412214122241223412244122541226412274122841229412304123141232412334123441235412364123741238412394124041241412424124341244412454124641247412484124941250412514125241253412544125541256412574125841259412604126141262412634126441265412664126741268412694127041271412724127341274412754127641277412784127941280412814128241283412844128541286412874128841289412904129141292412934129441295412964129741298412994130041301413024130341304413054130641307413084130941310413114131241313413144131541316413174131841319413204132141322413234132441325413264132741328413294133041331413324133341334413354133641337413384133941340413414134241343413444134541346413474134841349413504135141352413534135441355413564135741358413594136041361413624136341364413654136641367413684136941370413714137241373413744137541376413774137841379413804138141382413834138441385413864138741388413894139041391413924139341394413954139641397413984139941400414014140241403414044140541406414074140841409414104141141412414134141441415414164141741418414194142041421414224142341424414254142641427414284142941430414314143241433414344143541436414374143841439414404144141442414434144441445414464144741448414494145041451414524145341454414554145641457414584145941460414614146241463414644146541466414674146841469414704147141472414734147441475414764147741478414794148041481414824148341484414854148641487414884148941490414914149241493414944149541496414974149841499415004150141502415034150441505415064150741508415094151041511415124151341514415154151641517415184151941520415214152241523415244152541526415274152841529415304153141532415334153441535415364153741538415394154041541415424154341544415454154641547415484154941550415514155241553415544155541556415574155841559415604156141562415634156441565415664156741568415694157041571415724157341574415754157641577415784157941580415814158241583415844158541586415874158841589415904159141592415934159441595415964159741598415994160041601416024160341604416054160641607416084160941610416114161241613416144161541616416174161841619416204162141622416234162441625416264162741628416294163041631416324163341634416354163641637416384163941640416414164241643416444164541646416474164841649416504165141652416534165441655416564165741658416594166041661416624166341664416654166641667416684166941670416714167241673416744167541676416774167841679416804168141682416834168441685416864168741688416894169041691416924169341694416954169641697416984169941700417014170241703417044170541706417074170841709417104171141712417134171441715417164171741718417194172041721417224172341724417254172641727417284172941730417314173241733417344173541736417374173841739417404174141742417434174441745417464174741748417494175041751417524175341754417554175641757417584175941760417614176241763417644176541766417674176841769417704177141772417734177441775417764177741778417794178041781417824178341784417854178641787417884178941790417914179241793417944179541796417974179841799418004180141802418034180441805418064180741808418094181041811418124181341814418154181641817418184181941820418214182241823418244182541826418274182841829418304183141832418334183441835418364183741838418394184041841418424184341844418454184641847418484184941850418514185241853418544185541856418574185841859418604186141862418634186441865418664186741868418694187041871418724187341874418754187641877418784187941880418814188241883418844188541886418874188841889418904189141892418934189441895418964189741898418994190041901419024190341904419054190641907419084190941910419114191241913419144191541916419174191841919419204192141922419234192441925419264192741928419294193041931419324193341934419354193641937419384193941940419414194241943419444194541946419474194841949419504195141952419534195441955419564195741958419594196041961419624196341964419654196641967419684196941970419714197241973419744197541976419774197841979419804198141982419834198441985419864198741988419894199041991419924199341994419954199641997419984199942000420014200242003420044200542006420074200842009420104201142012420134201442015420164201742018420194202042021420224202342024420254202642027420284202942030420314203242033420344203542036420374203842039420404204142042420434204442045420464204742048420494205042051420524205342054420554205642057420584205942060420614206242063420644206542066420674206842069420704207142072420734207442075420764207742078420794208042081420824208342084420854208642087420884208942090420914209242093420944209542096420974209842099421004210142102421034210442105421064210742108421094211042111421124211342114421154211642117421184211942120421214212242123421244212542126421274212842129421304213142132421334213442135421364213742138421394214042141421424214342144421454214642147421484214942150421514215242153421544215542156421574215842159421604216142162421634216442165421664216742168421694217042171421724217342174421754217642177421784217942180421814218242183421844218542186421874218842189421904219142192421934219442195421964219742198421994220042201422024220342204422054220642207422084220942210422114221242213422144221542216422174221842219422204222142222422234222442225422264222742228422294223042231422324223342234422354223642237422384223942240422414224242243422444224542246422474224842249422504225142252422534225442255422564225742258422594226042261422624226342264422654226642267422684226942270422714227242273422744227542276422774227842279422804228142282422834228442285422864228742288422894229042291422924229342294422954229642297422984229942300423014230242303423044230542306423074230842309423104231142312423134231442315423164231742318423194232042321423224232342324423254232642327423284232942330423314233242333423344233542336423374233842339423404234142342423434234442345423464234742348423494235042351423524235342354423554235642357423584235942360423614236242363423644236542366423674236842369423704237142372423734237442375423764237742378423794238042381423824238342384423854238642387423884238942390423914239242393423944239542396423974239842399424004240142402424034240442405424064240742408424094241042411424124241342414424154241642417424184241942420424214242242423424244242542426424274242842429424304243142432424334243442435424364243742438424394244042441424424244342444424454244642447424484244942450424514245242453424544245542456424574245842459424604246142462424634246442465424664246742468424694247042471424724247342474424754247642477424784247942480424814248242483424844248542486424874248842489424904249142492424934249442495424964249742498424994250042501425024250342504425054250642507425084250942510425114251242513425144251542516425174251842519425204252142522425234252442525425264252742528425294253042531425324253342534425354253642537425384253942540425414254242543425444254542546425474254842549425504255142552425534255442555425564255742558425594256042561425624256342564425654256642567425684256942570425714257242573425744257542576425774257842579425804258142582425834258442585425864258742588425894259042591425924259342594425954259642597425984259942600426014260242603426044260542606426074260842609426104261142612426134261442615426164261742618426194262042621426224262342624426254262642627426284262942630426314263242633426344263542636426374263842639426404264142642426434264442645426464264742648426494265042651426524265342654426554265642657426584265942660426614266242663426644266542666426674266842669426704267142672426734267442675426764267742678426794268042681426824268342684426854268642687426884268942690426914269242693426944269542696426974269842699427004270142702427034270442705427064270742708427094271042711427124271342714427154271642717427184271942720427214272242723427244272542726427274272842729427304273142732427334273442735427364273742738427394274042741427424274342744427454274642747427484274942750427514275242753427544275542756427574275842759427604276142762427634276442765427664276742768427694277042771427724277342774427754277642777427784277942780427814278242783427844278542786427874278842789427904279142792427934279442795427964279742798427994280042801428024280342804428054280642807428084280942810428114281242813428144281542816428174281842819428204282142822428234282442825428264282742828428294283042831428324283342834428354283642837428384283942840428414284242843428444284542846428474284842849428504285142852428534285442855428564285742858428594286042861428624286342864428654286642867428684286942870428714287242873428744287542876428774287842879428804288142882428834288442885428864288742888428894289042891428924289342894428954289642897428984289942900429014290242903429044290542906429074290842909429104291142912429134291442915429164291742918429194292042921429224292342924429254292642927429284292942930429314293242933429344293542936429374293842939429404294142942429434294442945429464294742948429494295042951429524295342954429554295642957429584295942960429614296242963429644296542966429674296842969429704297142972429734297442975429764297742978429794298042981429824298342984429854298642987429884298942990429914299242993429944299542996429974299842999430004300143002430034300443005430064300743008430094301043011430124301343014430154301643017430184301943020430214302243023430244302543026430274302843029430304303143032430334303443035430364303743038430394304043041430424304343044430454304643047430484304943050430514305243053430544305543056430574305843059430604306143062430634306443065430664306743068430694307043071430724307343074430754307643077430784307943080430814308243083430844308543086430874308843089430904309143092430934309443095430964309743098430994310043101431024310343104431054310643107431084310943110431114311243113431144311543116431174311843119431204312143122431234312443125431264312743128431294313043131431324313343134431354313643137431384313943140431414314243143431444314543146431474314843149431504315143152431534315443155431564315743158431594316043161431624316343164431654316643167431684316943170431714317243173431744317543176431774317843179431804318143182431834318443185431864318743188431894319043191431924319343194431954319643197431984319943200432014320243203432044320543206432074320843209432104321143212432134321443215432164321743218432194322043221432224322343224432254322643227432284322943230432314323243233432344323543236432374323843239432404324143242432434324443245432464324743248432494325043251432524325343254432554325643257432584325943260432614326243263432644326543266432674326843269432704327143272432734327443275432764327743278432794328043281432824328343284432854328643287432884328943290432914329243293432944329543296432974329843299433004330143302433034330443305433064330743308433094331043311433124331343314433154331643317433184331943320433214332243323433244332543326433274332843329433304333143332433334333443335433364333743338433394334043341433424334343344433454334643347433484334943350433514335243353433544335543356433574335843359433604336143362433634336443365433664336743368433694337043371433724337343374433754337643377433784337943380433814338243383433844338543386433874338843389433904339143392433934339443395433964339743398433994340043401434024340343404434054340643407434084340943410434114341243413434144341543416434174341843419434204342143422434234342443425434264342743428434294343043431434324343343434434354343643437434384343943440434414344243443434444344543446434474344843449434504345143452434534345443455434564345743458434594346043461434624346343464434654346643467434684346943470434714347243473434744347543476434774347843479434804348143482434834348443485434864348743488434894349043491434924349343494434954349643497434984349943500435014350243503435044350543506435074350843509435104351143512435134351443515435164351743518435194352043521435224352343524435254352643527435284352943530435314353243533435344353543536435374353843539435404354143542435434354443545435464354743548435494355043551435524355343554435554355643557435584355943560435614356243563435644356543566435674356843569435704357143572435734357443575435764357743578435794358043581435824358343584435854358643587435884358943590435914359243593435944359543596435974359843599436004360143602436034360443605436064360743608436094361043611436124361343614436154361643617436184361943620436214362243623436244362543626436274362843629436304363143632436334363443635436364363743638436394364043641436424364343644436454364643647436484364943650436514365243653436544365543656436574365843659436604366143662436634366443665436664366743668436694367043671436724367343674436754367643677436784367943680436814368243683436844368543686436874368843689436904369143692436934369443695436964369743698436994370043701437024370343704437054370643707437084370943710437114371243713437144371543716437174371843719437204372143722437234372443725437264372743728437294373043731437324373343734437354373643737437384373943740437414374243743437444374543746437474374843749437504375143752437534375443755437564375743758437594376043761437624376343764437654376643767437684376943770437714377243773437744377543776437774377843779437804378143782437834378443785437864378743788437894379043791437924379343794437954379643797437984379943800438014380243803438044380543806438074380843809438104381143812438134381443815438164381743818438194382043821438224382343824438254382643827438284382943830438314383243833438344383543836438374383843839438404384143842438434384443845438464384743848438494385043851438524385343854438554385643857438584385943860438614386243863438644386543866438674386843869438704387143872438734387443875438764387743878438794388043881438824388343884438854388643887438884388943890438914389243893438944389543896438974389843899439004390143902439034390443905439064390743908439094391043911439124391343914439154391643917439184391943920439214392243923439244392543926439274392843929439304393143932439334393443935439364393743938439394394043941439424394343944439454394643947439484394943950439514395243953439544395543956439574395843959439604396143962439634396443965439664396743968439694397043971439724397343974439754397643977439784397943980439814398243983439844398543986439874398843989439904399143992439934399443995439964399743998439994400044001440024400344004440054400644007440084400944010440114401244013440144401544016440174401844019440204402144022440234402444025440264402744028440294403044031440324403344034440354403644037440384403944040440414404244043440444404544046440474404844049440504405144052440534405444055440564405744058440594406044061440624406344064440654406644067440684406944070440714407244073440744407544076440774407844079440804408144082440834408444085440864408744088440894409044091440924409344094440954409644097440984409944100441014410244103441044410544106441074410844109441104411144112441134411444115441164411744118441194412044121441224412344124441254412644127441284412944130441314413244133441344413544136441374413844139441404414144142441434414444145441464414744148441494415044151441524415344154441554415644157441584415944160441614416244163441644416544166441674416844169441704417144172441734417444175441764417744178441794418044181441824418344184441854418644187441884418944190441914419244193441944419544196441974419844199442004420144202442034420444205442064420744208442094421044211442124421344214442154421644217442184421944220442214422244223442244422544226442274422844229442304423144232442334423444235442364423744238442394424044241442424424344244442454424644247442484424944250442514425244253442544425544256442574425844259442604426144262442634426444265442664426744268442694427044271442724427344274442754427644277442784427944280442814428244283442844428544286442874428844289442904429144292442934429444295442964429744298442994430044301443024430344304443054430644307443084430944310443114431244313443144431544316443174431844319443204432144322443234432444325443264432744328443294433044331443324433344334443354433644337443384433944340443414434244343443444434544346443474434844349443504435144352443534435444355443564435744358443594436044361443624436344364443654436644367443684436944370443714437244373443744437544376443774437844379443804438144382443834438444385443864438744388443894439044391443924439344394443954439644397443984439944400444014440244403444044440544406444074440844409444104441144412444134441444415444164441744418444194442044421444224442344424444254442644427444284442944430444314443244433444344443544436444374443844439444404444144442444434444444445444464444744448444494445044451444524445344454444554445644457444584445944460444614446244463444644446544466444674446844469444704447144472444734447444475444764447744478444794448044481444824448344484444854448644487444884448944490444914449244493444944449544496444974449844499445004450144502445034450444505445064450744508445094451044511445124451344514445154451644517445184451944520445214452244523445244452544526445274452844529445304453144532445334453444535445364453744538445394454044541445424454344544445454454644547445484454944550445514455244553445544455544556445574455844559445604456144562445634456444565445664456744568445694457044571445724457344574445754457644577445784457944580445814458244583445844458544586445874458844589445904459144592445934459444595445964459744598445994460044601446024460344604446054460644607446084460944610446114461244613446144461544616446174461844619446204462144622446234462444625446264462744628446294463044631446324463344634446354463644637446384463944640446414464244643446444464544646446474464844649446504465144652446534465444655446564465744658446594466044661446624466344664446654466644667446684466944670446714467244673446744467544676446774467844679446804468144682446834468444685446864468744688446894469044691446924469344694446954469644697446984469944700447014470244703447044470544706447074470844709447104471144712447134471444715447164471744718447194472044721447224472344724447254472644727447284472944730447314473244733447344473544736447374473844739447404474144742447434474444745447464474744748447494475044751447524475344754447554475644757447584475944760447614476244763447644476544766447674476844769447704477144772447734477444775447764477744778447794478044781447824478344784447854478644787447884478944790447914479244793447944479544796447974479844799448004480144802448034480444805448064480744808448094481044811448124481344814448154481644817448184481944820448214482244823448244482544826448274482844829448304483144832448334483444835448364483744838448394484044841448424484344844448454484644847448484484944850448514485244853448544485544856448574485844859448604486144862448634486444865448664486744868448694487044871448724487344874448754487644877448784487944880448814488244883448844488544886448874488844889448904489144892448934489444895448964489744898448994490044901449024490344904449054490644907449084490944910449114491244913449144491544916449174491844919449204492144922449234492444925449264492744928449294493044931449324493344934449354493644937449384493944940449414494244943449444494544946449474494844949449504495144952449534495444955449564495744958449594496044961449624496344964449654496644967449684496944970449714497244973449744497544976449774497844979449804498144982449834498444985449864498744988449894499044991449924499344994449954499644997449984499945000450014500245003450044500545006450074500845009450104501145012450134501445015450164501745018450194502045021450224502345024450254502645027450284502945030450314503245033450344503545036450374503845039450404504145042450434504445045450464504745048450494505045051450524505345054450554505645057450584505945060450614506245063450644506545066450674506845069450704507145072450734507445075450764507745078450794508045081450824508345084450854508645087450884508945090450914509245093450944509545096450974509845099451004510145102451034510445105451064510745108451094511045111451124511345114451154511645117451184511945120451214512245123451244512545126451274512845129451304513145132451334513445135451364513745138451394514045141451424514345144451454514645147451484514945150451514515245153451544515545156451574515845159451604516145162451634516445165451664516745168451694517045171451724517345174451754517645177451784517945180451814518245183451844518545186451874518845189451904519145192451934519445195451964519745198451994520045201452024520345204452054520645207452084520945210452114521245213452144521545216452174521845219452204522145222452234522445225452264522745228452294523045231452324523345234452354523645237452384523945240452414524245243452444524545246452474524845249452504525145252452534525445255452564525745258452594526045261452624526345264452654526645267452684526945270452714527245273452744527545276452774527845279452804528145282452834528445285452864528745288452894529045291452924529345294452954529645297452984529945300453014530245303453044530545306453074530845309453104531145312453134531445315453164531745318453194532045321453224532345324453254532645327453284532945330453314533245333453344533545336453374533845339453404534145342453434534445345453464534745348453494535045351453524535345354453554535645357453584535945360453614536245363453644536545366453674536845369453704537145372453734537445375453764537745378453794538045381453824538345384453854538645387453884538945390453914539245393453944539545396453974539845399454004540145402454034540445405454064540745408454094541045411454124541345414454154541645417454184541945420454214542245423454244542545426454274542845429454304543145432454334543445435454364543745438454394544045441454424544345444454454544645447454484544945450454514545245453454544545545456454574545845459454604546145462454634546445465454664546745468454694547045471454724547345474454754547645477454784547945480454814548245483454844548545486454874548845489454904549145492454934549445495454964549745498454994550045501455024550345504455054550645507455084550945510455114551245513455144551545516455174551845519455204552145522455234552445525455264552745528455294553045531455324553345534455354553645537455384553945540455414554245543455444554545546455474554845549455504555145552455534555445555455564555745558455594556045561455624556345564455654556645567455684556945570455714557245573455744557545576455774557845579455804558145582455834558445585455864558745588455894559045591455924559345594455954559645597455984559945600456014560245603456044560545606456074560845609456104561145612456134561445615456164561745618456194562045621456224562345624456254562645627456284562945630456314563245633456344563545636456374563845639456404564145642456434564445645456464564745648456494565045651456524565345654456554565645657456584565945660456614566245663456644566545666456674566845669456704567145672456734567445675456764567745678456794568045681456824568345684456854568645687456884568945690456914569245693456944569545696456974569845699457004570145702457034570445705457064570745708457094571045711457124571345714457154571645717457184571945720457214572245723457244572545726457274572845729457304573145732457334573445735457364573745738457394574045741457424574345744457454574645747457484574945750457514575245753457544575545756457574575845759457604576145762457634576445765457664576745768457694577045771457724577345774457754577645777457784577945780457814578245783457844578545786457874578845789457904579145792457934579445795457964579745798457994580045801458024580345804458054580645807458084580945810458114581245813458144581545816458174581845819458204582145822458234582445825458264582745828458294583045831458324583345834458354583645837458384583945840458414584245843458444584545846458474584845849458504585145852458534585445855458564585745858458594586045861458624586345864458654586645867458684586945870458714587245873458744587545876458774587845879458804588145882458834588445885458864588745888458894589045891458924589345894458954589645897458984589945900459014590245903459044590545906459074590845909459104591145912459134591445915459164591745918459194592045921459224592345924459254592645927459284592945930459314593245933459344593545936459374593845939459404594145942459434594445945459464594745948459494595045951459524595345954459554595645957459584595945960459614596245963459644596545966459674596845969459704597145972459734597445975459764597745978459794598045981459824598345984459854598645987459884598945990459914599245993459944599545996459974599845999460004600146002460034600446005460064600746008460094601046011460124601346014460154601646017460184601946020460214602246023460244602546026460274602846029460304603146032460334603446035460364603746038460394604046041460424604346044460454604646047460484604946050460514605246053460544605546056460574605846059460604606146062460634606446065460664606746068460694607046071460724607346074460754607646077460784607946080460814608246083460844608546086460874608846089460904609146092460934609446095460964609746098460994610046101461024610346104461054610646107461084610946110461114611246113461144611546116461174611846119461204612146122461234612446125461264612746128461294613046131461324613346134461354613646137461384613946140461414614246143461444614546146461474614846149461504615146152461534615446155461564615746158461594616046161461624616346164461654616646167461684616946170461714617246173461744617546176461774617846179461804618146182461834618446185461864618746188461894619046191461924619346194461954619646197461984619946200462014620246203462044620546206462074620846209462104621146212462134621446215462164621746218462194622046221462224622346224462254622646227462284622946230462314623246233462344623546236462374623846239462404624146242462434624446245462464624746248462494625046251462524625346254462554625646257462584625946260462614626246263462644626546266462674626846269462704627146272462734627446275462764627746278462794628046281462824628346284462854628646287462884628946290462914629246293462944629546296462974629846299463004630146302463034630446305463064630746308463094631046311463124631346314463154631646317463184631946320463214632246323463244632546326463274632846329463304633146332463334633446335463364633746338463394634046341463424634346344463454634646347463484634946350463514635246353463544635546356463574635846359463604636146362463634636446365463664636746368463694637046371463724637346374463754637646377463784637946380463814638246383463844638546386463874638846389463904639146392463934639446395463964639746398463994640046401464024640346404464054640646407464084640946410464114641246413464144641546416464174641846419464204642146422464234642446425464264642746428464294643046431464324643346434464354643646437464384643946440464414644246443464444644546446464474644846449464504645146452464534645446455464564645746458464594646046461464624646346464464654646646467464684646946470464714647246473464744647546476464774647846479464804648146482464834648446485464864648746488464894649046491464924649346494464954649646497464984649946500465014650246503465044650546506465074650846509465104651146512465134651446515465164651746518465194652046521465224652346524465254652646527465284652946530465314653246533465344653546536465374653846539465404654146542465434654446545465464654746548465494655046551465524655346554465554655646557465584655946560465614656246563465644656546566465674656846569465704657146572465734657446575465764657746578465794658046581465824658346584465854658646587465884658946590465914659246593465944659546596465974659846599466004660146602466034660446605466064660746608466094661046611466124661346614466154661646617466184661946620466214662246623466244662546626466274662846629466304663146632466334663446635466364663746638466394664046641466424664346644466454664646647466484664946650466514665246653466544665546656466574665846659466604666146662466634666446665466664666746668466694667046671466724667346674466754667646677466784667946680466814668246683466844668546686466874668846689466904669146692466934669446695466964669746698466994670046701467024670346704467054670646707467084670946710467114671246713467144671546716467174671846719467204672146722467234672446725467264672746728467294673046731467324673346734467354673646737467384673946740467414674246743467444674546746467474674846749467504675146752467534675446755467564675746758467594676046761467624676346764467654676646767467684676946770467714677246773467744677546776467774677846779467804678146782467834678446785467864678746788467894679046791467924679346794467954679646797467984679946800468014680246803468044680546806468074680846809468104681146812468134681446815468164681746818468194682046821468224682346824468254682646827468284682946830468314683246833468344683546836468374683846839468404684146842468434684446845468464684746848468494685046851468524685346854468554685646857468584685946860468614686246863468644686546866468674686846869468704687146872468734687446875468764687746878468794688046881468824688346884468854688646887468884688946890468914689246893468944689546896468974689846899469004690146902469034690446905469064690746908469094691046911469124691346914469154691646917469184691946920469214692246923469244692546926469274692846929469304693146932469334693446935469364693746938469394694046941469424694346944469454694646947469484694946950469514695246953469544695546956469574695846959469604696146962469634696446965469664696746968469694697046971469724697346974469754697646977469784697946980469814698246983469844698546986469874698846989469904699146992469934699446995469964699746998469994700047001470024700347004470054700647007470084700947010470114701247013470144701547016470174701847019470204702147022470234702447025470264702747028470294703047031470324703347034470354703647037470384703947040470414704247043470444704547046470474704847049470504705147052470534705447055470564705747058470594706047061470624706347064470654706647067470684706947070470714707247073470744707547076470774707847079470804708147082470834708447085470864708747088470894709047091470924709347094470954709647097470984709947100471014710247103471044710547106471074710847109471104711147112471134711447115471164711747118471194712047121471224712347124471254712647127471284712947130471314713247133471344713547136471374713847139471404714147142471434714447145471464714747148471494715047151471524715347154471554715647157471584715947160471614716247163471644716547166471674716847169471704717147172471734717447175471764717747178471794718047181471824718347184471854718647187471884718947190471914719247193471944719547196471974719847199472004720147202472034720447205472064720747208472094721047211472124721347214472154721647217472184721947220472214722247223472244722547226472274722847229472304723147232472334723447235472364723747238472394724047241472424724347244472454724647247472484724947250472514725247253472544725547256472574725847259472604726147262472634726447265472664726747268472694727047271472724727347274472754727647277472784727947280472814728247283472844728547286472874728847289472904729147292472934729447295472964729747298472994730047301473024730347304473054730647307473084730947310473114731247313473144731547316473174731847319473204732147322473234732447325473264732747328473294733047331473324733347334473354733647337473384733947340473414734247343473444734547346473474734847349473504735147352473534735447355473564735747358473594736047361473624736347364473654736647367473684736947370473714737247373473744737547376473774737847379473804738147382473834738447385473864738747388473894739047391473924739347394473954739647397473984739947400474014740247403474044740547406474074740847409474104741147412474134741447415474164741747418474194742047421474224742347424474254742647427474284742947430474314743247433474344743547436474374743847439474404744147442474434744447445474464744747448474494745047451474524745347454474554745647457474584745947460474614746247463474644746547466474674746847469474704747147472474734747447475474764747747478474794748047481474824748347484474854748647487474884748947490474914749247493474944749547496474974749847499475004750147502475034750447505475064750747508475094751047511475124751347514475154751647517475184751947520475214752247523475244752547526475274752847529475304753147532475334753447535475364753747538475394754047541475424754347544475454754647547475484754947550475514755247553475544755547556475574755847559475604756147562475634756447565475664756747568475694757047571475724757347574475754757647577475784757947580475814758247583475844758547586475874758847589475904759147592475934759447595475964759747598475994760047601476024760347604476054760647607476084760947610476114761247613476144761547616476174761847619476204762147622476234762447625476264762747628476294763047631476324763347634476354763647637476384763947640476414764247643476444764547646476474764847649476504765147652476534765447655476564765747658476594766047661476624766347664476654766647667476684766947670476714767247673476744767547676476774767847679476804768147682476834768447685476864768747688476894769047691476924769347694476954769647697476984769947700477014770247703477044770547706477074770847709477104771147712477134771447715477164771747718477194772047721477224772347724477254772647727477284772947730477314773247733477344773547736477374773847739477404774147742477434774447745477464774747748477494775047751477524775347754477554775647757477584775947760477614776247763477644776547766477674776847769477704777147772477734777447775477764777747778477794778047781477824778347784477854778647787477884778947790477914779247793477944779547796477974779847799478004780147802478034780447805478064780747808478094781047811478124781347814478154781647817478184781947820478214782247823478244782547826478274782847829478304783147832478334783447835478364783747838478394784047841478424784347844478454784647847478484784947850478514785247853478544785547856478574785847859478604786147862478634786447865478664786747868478694787047871478724787347874478754787647877478784787947880478814788247883478844788547886478874788847889478904789147892478934789447895478964789747898478994790047901479024790347904479054790647907479084790947910479114791247913479144791547916479174791847919479204792147922479234792447925479264792747928479294793047931479324793347934479354793647937479384793947940479414794247943479444794547946479474794847949479504795147952479534795447955479564795747958479594796047961479624796347964479654796647967479684796947970479714797247973479744797547976479774797847979479804798147982479834798447985479864798747988479894799047991479924799347994479954799647997479984799948000480014800248003480044800548006480074800848009480104801148012480134801448015480164801748018480194802048021480224802348024480254802648027480284802948030480314803248033480344803548036480374803848039480404804148042480434804448045480464804748048480494805048051480524805348054480554805648057480584805948060480614806248063480644806548066480674806848069480704807148072480734807448075480764807748078480794808048081480824808348084480854808648087480884808948090480914809248093480944809548096480974809848099481004810148102481034810448105481064810748108481094811048111481124811348114481154811648117481184811948120481214812248123481244812548126481274812848129481304813148132481334813448135481364813748138481394814048141481424814348144481454814648147481484814948150481514815248153481544815548156481574815848159481604816148162481634816448165481664816748168481694817048171481724817348174481754817648177481784817948180481814818248183481844818548186481874818848189481904819148192481934819448195481964819748198481994820048201482024820348204482054820648207482084820948210482114821248213482144821548216482174821848219482204822148222482234822448225482264822748228482294823048231482324823348234482354823648237482384823948240482414824248243482444824548246482474824848249482504825148252482534825448255482564825748258482594826048261482624826348264482654826648267482684826948270482714827248273482744827548276482774827848279482804828148282482834828448285482864828748288482894829048291482924829348294482954829648297482984829948300483014830248303483044830548306483074830848309483104831148312483134831448315483164831748318483194832048321483224832348324483254832648327483284832948330483314833248333483344833548336483374833848339483404834148342483434834448345483464834748348483494835048351483524835348354483554835648357483584835948360483614836248363483644836548366483674836848369483704837148372483734837448375483764837748378483794838048381483824838348384483854838648387483884838948390483914839248393483944839548396483974839848399484004840148402484034840448405484064840748408484094841048411484124841348414484154841648417484184841948420484214842248423484244842548426484274842848429484304843148432484334843448435484364843748438484394844048441484424844348444484454844648447484484844948450484514845248453484544845548456484574845848459484604846148462484634846448465484664846748468484694847048471484724847348474484754847648477484784847948480484814848248483484844848548486484874848848489484904849148492484934849448495484964849748498484994850048501485024850348504485054850648507485084850948510485114851248513485144851548516485174851848519485204852148522485234852448525485264852748528485294853048531485324853348534485354853648537485384853948540485414854248543485444854548546485474854848549485504855148552485534855448555485564855748558485594856048561485624856348564485654856648567485684856948570485714857248573485744857548576485774857848579485804858148582485834858448585485864858748588485894859048591485924859348594485954859648597485984859948600486014860248603486044860548606486074860848609486104861148612486134861448615486164861748618486194862048621486224862348624486254862648627486284862948630486314863248633486344863548636486374863848639486404864148642486434864448645486464864748648486494865048651486524865348654486554865648657486584865948660486614866248663486644866548666486674866848669486704867148672486734867448675486764867748678486794868048681486824868348684486854868648687486884868948690486914869248693486944869548696486974869848699487004870148702487034870448705487064870748708487094871048711487124871348714487154871648717487184871948720487214872248723487244872548726487274872848729487304873148732487334873448735487364873748738487394874048741487424874348744487454874648747487484874948750487514875248753487544875548756487574875848759487604876148762487634876448765487664876748768487694877048771487724877348774487754877648777487784877948780487814878248783487844878548786487874878848789487904879148792487934879448795487964879748798487994880048801488024880348804488054880648807488084880948810488114881248813488144881548816488174881848819488204882148822488234882448825488264882748828488294883048831488324883348834488354883648837488384883948840488414884248843488444884548846488474884848849488504885148852488534885448855488564885748858488594886048861488624886348864488654886648867488684886948870488714887248873488744887548876488774887848879488804888148882488834888448885488864888748888488894889048891488924889348894488954889648897488984889948900489014890248903489044890548906489074890848909489104891148912489134891448915489164891748918489194892048921489224892348924489254892648927489284892948930489314893248933489344893548936489374893848939489404894148942489434894448945489464894748948489494895048951489524895348954489554895648957489584895948960489614896248963489644896548966489674896848969489704897148972489734897448975489764897748978489794898048981489824898348984489854898648987489884898948990489914899248993489944899548996489974899848999490004900149002490034900449005490064900749008490094901049011490124901349014490154901649017490184901949020490214902249023490244902549026490274902849029490304903149032490334903449035490364903749038490394904049041490424904349044490454904649047490484904949050490514905249053490544905549056490574905849059490604906149062490634906449065490664906749068490694907049071490724907349074490754907649077490784907949080490814908249083490844908549086490874908849089490904909149092490934909449095490964909749098490994910049101491024910349104491054910649107491084910949110491114911249113491144911549116491174911849119491204912149122491234912449125491264912749128491294913049131491324913349134491354913649137491384913949140491414914249143491444914549146491474914849149491504915149152491534915449155491564915749158491594916049161491624916349164491654916649167491684916949170491714917249173491744917549176491774917849179491804918149182491834918449185491864918749188491894919049191491924919349194491954919649197491984919949200492014920249203492044920549206492074920849209492104921149212492134921449215492164921749218492194922049221492224922349224492254922649227492284922949230492314923249233492344923549236492374923849239492404924149242492434924449245492464924749248492494925049251492524925349254492554925649257492584925949260492614926249263492644926549266492674926849269492704927149272492734927449275492764927749278492794928049281492824928349284492854928649287492884928949290492914929249293492944929549296492974929849299493004930149302493034930449305493064930749308493094931049311493124931349314493154931649317493184931949320493214932249323493244932549326493274932849329493304933149332493334933449335493364933749338493394934049341493424934349344493454934649347493484934949350493514935249353493544935549356493574935849359493604936149362493634936449365493664936749368493694937049371493724937349374493754937649377493784937949380493814938249383493844938549386493874938849389493904939149392493934939449395493964939749398493994940049401494024940349404494054940649407494084940949410494114941249413494144941549416494174941849419494204942149422494234942449425494264942749428494294943049431494324943349434494354943649437494384943949440494414944249443494444944549446494474944849449494504945149452494534945449455494564945749458494594946049461494624946349464494654946649467494684946949470494714947249473494744947549476494774947849479494804948149482494834948449485494864948749488494894949049491494924949349494494954949649497494984949949500495014950249503495044950549506495074950849509495104951149512495134951449515495164951749518495194952049521495224952349524495254952649527495284952949530495314953249533495344953549536495374953849539495404954149542495434954449545495464954749548495494955049551495524955349554495554955649557495584955949560495614956249563495644956549566495674956849569495704957149572495734957449575495764957749578495794958049581495824958349584495854958649587495884958949590495914959249593495944959549596495974959849599496004960149602496034960449605496064960749608496094961049611496124961349614496154961649617496184961949620496214962249623496244962549626496274962849629496304963149632496334963449635496364963749638496394964049641496424964349644496454964649647496484964949650496514965249653496544965549656496574965849659496604966149662496634966449665496664966749668496694967049671496724967349674496754967649677496784967949680496814968249683496844968549686496874968849689496904969149692496934969449695496964969749698496994970049701497024970349704497054970649707497084970949710497114971249713497144971549716497174971849719497204972149722497234972449725497264972749728497294973049731497324973349734497354973649737497384973949740497414974249743497444974549746497474974849749497504975149752497534975449755497564975749758497594976049761497624976349764497654976649767497684976949770497714977249773497744977549776497774977849779497804978149782497834978449785497864978749788497894979049791497924979349794497954979649797497984979949800498014980249803498044980549806498074980849809498104981149812498134981449815498164981749818498194982049821498224982349824498254982649827498284982949830498314983249833498344983549836498374983849839498404984149842498434984449845498464984749848498494985049851498524985349854498554985649857498584985949860498614986249863498644986549866498674986849869498704987149872498734987449875498764987749878498794988049881498824988349884498854988649887498884988949890498914989249893498944989549896498974989849899499004990149902499034990449905499064990749908499094991049911499124991349914499154991649917499184991949920499214992249923499244992549926499274992849929499304993149932499334993449935499364993749938499394994049941499424994349944499454994649947499484994949950499514995249953499544995549956499574995849959499604996149962499634996449965499664996749968499694997049971499724997349974499754997649977499784997949980499814998249983499844998549986499874998849989499904999149992499934999449995499964999749998499995000050001500025000350004500055000650007500085000950010500115001250013500145001550016500175001850019500205002150022500235002450025500265002750028500295003050031500325003350034500355003650037500385003950040500415004250043500445004550046500475004850049500505005150052500535005450055500565005750058500595006050061500625006350064500655006650067500685006950070500715007250073500745007550076500775007850079500805008150082500835008450085500865008750088500895009050091500925009350094500955009650097500985009950100501015010250103501045010550106501075010850109501105011150112501135011450115501165011750118501195012050121501225012350124501255012650127501285012950130501315013250133501345013550136501375013850139501405014150142501435014450145501465014750148501495015050151501525015350154501555015650157501585015950160501615016250163501645016550166501675016850169501705017150172501735017450175501765017750178501795018050181501825018350184501855018650187501885018950190501915019250193501945019550196501975019850199502005020150202502035020450205502065020750208502095021050211502125021350214502155021650217502185021950220502215022250223502245022550226502275022850229502305023150232502335023450235502365023750238502395024050241502425024350244502455024650247502485024950250502515025250253502545025550256502575025850259502605026150262502635026450265502665026750268502695027050271502725027350274502755027650277502785027950280502815028250283502845028550286502875028850289502905029150292502935029450295502965029750298502995030050301503025030350304503055030650307503085030950310503115031250313503145031550316503175031850319503205032150322503235032450325503265032750328503295033050331503325033350334503355033650337503385033950340503415034250343503445034550346503475034850349503505035150352503535035450355503565035750358503595036050361503625036350364503655036650367503685036950370503715037250373503745037550376503775037850379503805038150382503835038450385503865038750388503895039050391503925039350394503955039650397503985039950400504015040250403504045040550406504075040850409504105041150412504135041450415504165041750418504195042050421504225042350424504255042650427504285042950430504315043250433504345043550436504375043850439504405044150442504435044450445504465044750448504495045050451504525045350454504555045650457504585045950460504615046250463504645046550466504675046850469504705047150472504735047450475504765047750478504795048050481504825048350484504855048650487504885048950490504915049250493504945049550496504975049850499505005050150502505035050450505505065050750508505095051050511505125051350514505155051650517505185051950520505215052250523505245052550526505275052850529505305053150532505335053450535505365053750538505395054050541505425054350544505455054650547505485054950550505515055250553505545055550556505575055850559505605056150562505635056450565505665056750568505695057050571505725057350574505755057650577505785057950580505815058250583505845058550586505875058850589505905059150592505935059450595505965059750598505995060050601506025060350604506055060650607506085060950610506115061250613506145061550616506175061850619506205062150622506235062450625506265062750628506295063050631506325063350634506355063650637506385063950640506415064250643506445064550646506475064850649506505065150652506535065450655506565065750658506595066050661506625066350664506655066650667506685066950670506715067250673506745067550676506775067850679506805068150682506835068450685506865068750688506895069050691506925069350694506955069650697506985069950700507015070250703507045070550706507075070850709507105071150712507135071450715507165071750718507195072050721507225072350724507255072650727507285072950730507315073250733507345073550736507375073850739507405074150742507435074450745507465074750748507495075050751507525075350754507555075650757507585075950760507615076250763507645076550766507675076850769507705077150772507735077450775507765077750778507795078050781507825078350784507855078650787507885078950790507915079250793507945079550796507975079850799508005080150802508035080450805508065080750808508095081050811508125081350814508155081650817508185081950820508215082250823508245082550826508275082850829508305083150832508335083450835508365083750838508395084050841508425084350844508455084650847508485084950850508515085250853508545085550856508575085850859508605086150862508635086450865508665086750868508695087050871508725087350874508755087650877508785087950880508815088250883508845088550886508875088850889508905089150892508935089450895508965089750898508995090050901509025090350904509055090650907509085090950910509115091250913509145091550916509175091850919509205092150922509235092450925509265092750928509295093050931509325093350934509355093650937509385093950940509415094250943509445094550946509475094850949509505095150952509535095450955509565095750958509595096050961509625096350964509655096650967509685096950970509715097250973509745097550976509775097850979509805098150982509835098450985509865098750988509895099050991509925099350994509955099650997509985099951000510015100251003510045100551006510075100851009510105101151012510135101451015510165101751018510195102051021510225102351024510255102651027510285102951030510315103251033510345103551036510375103851039510405104151042510435104451045510465104751048510495105051051510525105351054510555105651057510585105951060510615106251063510645106551066510675106851069510705107151072510735107451075510765107751078510795108051081510825108351084510855108651087510885108951090510915109251093510945109551096510975109851099511005110151102511035110451105511065110751108511095111051111511125111351114511155111651117511185111951120511215112251123511245112551126511275112851129511305113151132511335113451135511365113751138511395114051141511425114351144511455114651147511485114951150511515115251153511545115551156511575115851159511605116151162511635116451165511665116751168511695117051171511725117351174511755117651177511785117951180511815118251183511845118551186511875118851189511905119151192511935119451195511965119751198511995120051201512025120351204512055120651207512085120951210512115121251213512145121551216512175121851219512205122151222512235122451225512265122751228512295123051231512325123351234512355123651237512385123951240512415124251243512445124551246512475124851249512505125151252512535125451255512565125751258512595126051261512625126351264512655126651267512685126951270512715127251273512745127551276512775127851279512805128151282512835128451285512865128751288512895129051291512925129351294512955129651297512985129951300513015130251303513045130551306513075130851309513105131151312513135131451315513165131751318513195132051321513225132351324513255132651327513285132951330513315133251333513345133551336513375133851339513405134151342513435134451345513465134751348513495135051351513525135351354513555135651357513585135951360513615136251363513645136551366513675136851369513705137151372513735137451375513765137751378513795138051381513825138351384513855138651387513885138951390513915139251393513945139551396513975139851399514005140151402514035140451405514065140751408514095141051411514125141351414514155141651417514185141951420514215142251423514245142551426514275142851429514305143151432514335143451435514365143751438514395144051441514425144351444514455144651447514485144951450514515145251453514545145551456514575145851459514605146151462514635146451465514665146751468514695147051471514725147351474514755147651477514785147951480514815148251483514845148551486514875148851489514905149151492514935149451495514965149751498514995150051501515025150351504515055150651507515085150951510515115151251513515145151551516515175151851519515205152151522515235152451525515265152751528515295153051531515325153351534515355153651537515385153951540515415154251543515445154551546515475154851549515505155151552515535155451555515565155751558515595156051561515625156351564515655156651567515685156951570515715157251573515745157551576515775157851579515805158151582515835158451585515865158751588515895159051591515925159351594515955159651597515985159951600516015160251603516045160551606516075160851609516105161151612516135161451615516165161751618516195162051621516225162351624516255162651627516285162951630516315163251633516345163551636516375163851639516405164151642516435164451645516465164751648516495165051651516525165351654516555165651657516585165951660516615166251663516645166551666516675166851669516705167151672516735167451675516765167751678516795168051681516825168351684516855168651687516885168951690516915169251693516945169551696516975169851699517005170151702517035170451705517065170751708517095171051711517125171351714517155171651717517185171951720517215172251723517245172551726517275172851729517305173151732517335173451735517365173751738517395174051741517425174351744517455174651747517485174951750517515175251753517545175551756517575175851759517605176151762517635176451765517665176751768517695177051771517725177351774517755177651777517785177951780517815178251783517845178551786517875178851789517905179151792517935179451795517965179751798517995180051801518025180351804518055180651807518085180951810518115181251813518145181551816518175181851819518205182151822518235182451825518265182751828518295183051831518325183351834518355183651837518385183951840518415184251843518445184551846518475184851849518505185151852518535185451855518565185751858518595186051861518625186351864518655186651867518685186951870518715187251873518745187551876518775187851879518805188151882518835188451885518865188751888518895189051891518925189351894518955189651897518985189951900519015190251903519045190551906519075190851909519105191151912519135191451915519165191751918519195192051921519225192351924519255192651927519285192951930519315193251933519345193551936519375193851939519405194151942519435194451945519465194751948519495195051951519525195351954519555195651957519585195951960519615196251963519645196551966519675196851969519705197151972519735197451975519765197751978519795198051981519825198351984519855198651987519885198951990519915199251993519945199551996519975199851999520005200152002520035200452005520065200752008520095201052011520125201352014520155201652017520185201952020520215202252023520245202552026520275202852029520305203152032520335203452035520365203752038520395204052041520425204352044520455204652047520485204952050520515205252053520545205552056520575205852059520605206152062520635206452065520665206752068520695207052071520725207352074520755207652077520785207952080520815208252083520845208552086520875208852089520905209152092520935209452095520965209752098520995210052101521025210352104521055210652107521085210952110521115211252113521145211552116521175211852119521205212152122521235212452125521265212752128521295213052131521325213352134521355213652137521385213952140521415214252143521445214552146521475214852149521505215152152521535215452155521565215752158521595216052161521625216352164521655216652167521685216952170521715217252173521745217552176521775217852179521805218152182521835218452185521865218752188521895219052191521925219352194521955219652197521985219952200522015220252203522045220552206522075220852209522105221152212522135221452215522165221752218522195222052221522225222352224522255222652227522285222952230522315223252233522345223552236522375223852239522405224152242522435224452245522465224752248522495225052251522525225352254522555225652257522585225952260522615226252263522645226552266522675226852269522705227152272522735227452275522765227752278522795228052281522825228352284522855228652287522885228952290522915229252293522945229552296522975229852299523005230152302523035230452305523065230752308523095231052311523125231352314523155231652317523185231952320523215232252323523245232552326523275232852329523305233152332523335233452335523365233752338523395234052341523425234352344523455234652347523485234952350523515235252353523545235552356523575235852359523605236152362523635236452365523665236752368523695237052371523725237352374523755237652377523785237952380523815238252383523845238552386523875238852389523905239152392523935239452395523965239752398523995240052401524025240352404524055240652407524085240952410524115241252413524145241552416524175241852419524205242152422524235242452425524265242752428524295243052431524325243352434524355243652437524385243952440524415244252443524445244552446524475244852449524505245152452524535245452455524565245752458524595246052461524625246352464524655246652467524685246952470524715247252473524745247552476524775247852479524805248152482524835248452485524865248752488524895249052491524925249352494524955249652497524985249952500525015250252503525045250552506525075250852509525105251152512525135251452515525165251752518525195252052521525225252352524525255252652527525285252952530525315253252533525345253552536525375253852539525405254152542525435254452545525465254752548525495255052551525525255352554525555255652557525585255952560525615256252563525645256552566525675256852569525705257152572525735257452575525765257752578525795258052581525825258352584525855258652587525885258952590525915259252593525945259552596525975259852599526005260152602526035260452605526065260752608526095261052611526125261352614526155261652617526185261952620526215262252623526245262552626526275262852629526305263152632526335263452635526365263752638526395264052641526425264352644526455264652647526485264952650526515265252653526545265552656526575265852659526605266152662526635266452665526665266752668526695267052671526725267352674526755267652677526785267952680526815268252683526845268552686526875268852689526905269152692526935269452695526965269752698526995270052701527025270352704527055270652707527085270952710527115271252713527145271552716527175271852719527205272152722527235272452725527265272752728527295273052731527325273352734527355273652737527385273952740527415274252743527445274552746527475274852749527505275152752527535275452755527565275752758527595276052761527625276352764527655276652767527685276952770527715277252773527745277552776527775277852779527805278152782527835278452785527865278752788527895279052791527925279352794527955279652797527985279952800528015280252803528045280552806528075280852809528105281152812528135281452815528165281752818528195282052821528225282352824528255282652827528285282952830528315283252833528345283552836528375283852839528405284152842528435284452845528465284752848528495285052851528525285352854528555285652857528585285952860528615286252863528645286552866528675286852869528705287152872528735287452875528765287752878528795288052881528825288352884528855288652887528885288952890528915289252893528945289552896528975289852899529005290152902529035290452905529065290752908529095291052911529125291352914529155291652917529185291952920529215292252923529245292552926529275292852929529305293152932529335293452935529365293752938529395294052941529425294352944529455294652947529485294952950529515295252953529545295552956529575295852959529605296152962529635296452965529665296752968529695297052971529725297352974529755297652977529785297952980529815298252983529845298552986529875298852989529905299152992529935299452995529965299752998529995300053001530025300353004530055300653007530085300953010530115301253013530145301553016530175301853019530205302153022530235302453025530265302753028530295303053031530325303353034530355303653037530385303953040530415304253043530445304553046530475304853049530505305153052530535305453055530565305753058530595306053061530625306353064530655306653067530685306953070530715307253073530745307553076530775307853079530805308153082530835308453085530865308753088530895309053091530925309353094530955309653097530985309953100531015310253103531045310553106531075310853109531105311153112531135311453115531165311753118531195312053121531225312353124531255312653127531285312953130531315313253133531345313553136531375313853139531405314153142531435314453145531465314753148531495315053151531525315353154531555315653157531585315953160531615316253163531645316553166531675316853169531705317153172531735317453175531765317753178531795318053181531825318353184531855318653187531885318953190531915319253193531945319553196531975319853199532005320153202532035320453205532065320753208532095321053211532125321353214532155321653217532185321953220532215322253223532245322553226532275322853229532305323153232532335323453235532365323753238532395324053241532425324353244532455324653247532485324953250532515325253253532545325553256532575325853259532605326153262532635326453265532665326753268532695327053271532725327353274532755327653277532785327953280532815328253283532845328553286532875328853289532905329153292532935329453295532965329753298532995330053301533025330353304533055330653307533085330953310533115331253313533145331553316533175331853319533205332153322533235332453325533265332753328533295333053331533325333353334533355333653337533385333953340533415334253343533445334553346533475334853349533505335153352533535335453355533565335753358533595336053361533625336353364533655336653367533685336953370533715337253373533745337553376533775337853379533805338153382533835338453385533865338753388533895339053391533925339353394533955339653397533985339953400534015340253403534045340553406534075340853409534105341153412534135341453415534165341753418534195342053421534225342353424534255342653427534285342953430534315343253433534345343553436534375343853439534405344153442534435344453445534465344753448534495345053451534525345353454534555345653457534585345953460534615346253463534645346553466534675346853469534705347153472534735347453475534765347753478534795348053481534825348353484534855348653487534885348953490534915349253493534945349553496534975349853499535005350153502535035350453505535065350753508535095351053511535125351353514535155351653517535185351953520535215352253523535245352553526535275352853529535305353153532535335353453535535365353753538535395354053541535425354353544535455354653547535485354953550535515355253553535545355553556535575355853559535605356153562535635356453565535665356753568535695357053571535725357353574535755357653577535785357953580535815358253583535845358553586535875358853589535905359153592535935359453595535965359753598535995360053601536025360353604536055360653607536085360953610536115361253613536145361553616536175361853619536205362153622536235362453625536265362753628536295363053631536325363353634536355363653637536385363953640536415364253643536445364553646536475364853649536505365153652536535365453655536565365753658536595366053661536625366353664536655366653667536685366953670536715367253673536745367553676536775367853679536805368153682536835368453685536865368753688536895369053691536925369353694536955369653697536985369953700537015370253703537045370553706537075370853709537105371153712537135371453715537165371753718537195372053721537225372353724537255372653727537285372953730537315373253733537345373553736537375373853739537405374153742537435374453745537465374753748537495375053751537525375353754537555375653757537585375953760537615376253763537645376553766537675376853769537705377153772537735377453775537765377753778537795378053781537825378353784537855378653787537885378953790537915379253793537945379553796537975379853799538005380153802538035380453805538065380753808538095381053811538125381353814538155381653817538185381953820538215382253823538245382553826538275382853829538305383153832538335383453835538365383753838538395384053841538425384353844538455384653847538485384953850538515385253853538545385553856538575385853859538605386153862538635386453865538665386753868538695387053871538725387353874538755387653877538785387953880538815388253883538845388553886538875388853889538905389153892538935389453895538965389753898538995390053901539025390353904539055390653907539085390953910539115391253913539145391553916539175391853919539205392153922539235392453925539265392753928539295393053931539325393353934539355393653937539385393953940539415394253943539445394553946539475394853949539505395153952539535395453955539565395753958539595396053961539625396353964539655396653967539685396953970539715397253973539745397553976539775397853979539805398153982539835398453985539865398753988539895399053991539925399353994539955399653997539985399954000540015400254003540045400554006540075400854009540105401154012540135401454015540165401754018540195402054021540225402354024540255402654027540285402954030540315403254033540345403554036540375403854039540405404154042540435404454045540465404754048540495405054051540525405354054540555405654057540585405954060540615406254063540645406554066540675406854069540705407154072540735407454075540765407754078540795408054081540825408354084540855408654087540885408954090540915409254093540945409554096540975409854099541005410154102541035410454105541065410754108541095411054111541125411354114541155411654117541185411954120541215412254123541245412554126541275412854129541305413154132541335413454135541365413754138541395414054141541425414354144541455414654147541485414954150541515415254153541545415554156541575415854159541605416154162541635416454165541665416754168541695417054171541725417354174541755417654177541785417954180541815418254183541845418554186541875418854189541905419154192541935419454195541965419754198541995420054201542025420354204542055420654207542085420954210542115421254213542145421554216542175421854219542205422154222542235422454225542265422754228542295423054231542325423354234542355423654237542385423954240542415424254243542445424554246542475424854249542505425154252542535425454255542565425754258542595426054261542625426354264542655426654267542685426954270542715427254273542745427554276542775427854279542805428154282542835428454285542865428754288542895429054291542925429354294542955429654297542985429954300543015430254303543045430554306543075430854309543105431154312543135431454315543165431754318543195432054321543225432354324543255432654327543285432954330543315433254333543345433554336543375433854339543405434154342543435434454345543465434754348543495435054351543525435354354543555435654357543585435954360543615436254363543645436554366543675436854369543705437154372543735437454375543765437754378543795438054381543825438354384543855438654387543885438954390543915439254393543945439554396543975439854399544005440154402544035440454405544065440754408544095441054411544125441354414544155441654417544185441954420544215442254423544245442554426544275442854429544305443154432544335443454435544365443754438544395444054441544425444354444544455444654447544485444954450544515445254453544545445554456544575445854459544605446154462544635446454465544665446754468544695447054471544725447354474544755447654477544785447954480544815448254483544845448554486544875448854489544905449154492544935449454495544965449754498544995450054501545025450354504545055450654507545085450954510545115451254513545145451554516545175451854519545205452154522545235452454525545265452754528545295453054531545325453354534545355453654537545385453954540545415454254543545445454554546545475454854549545505455154552545535455454555545565455754558545595456054561545625456354564545655456654567545685456954570545715457254573545745457554576545775457854579545805458154582545835458454585545865458754588545895459054591545925459354594545955459654597545985459954600546015460254603546045460554606546075460854609546105461154612546135461454615546165461754618546195462054621546225462354624546255462654627546285462954630546315463254633546345463554636546375463854639546405464154642546435464454645546465464754648546495465054651546525465354654546555465654657546585465954660546615466254663546645466554666546675466854669546705467154672546735467454675546765467754678546795468054681546825468354684546855468654687546885468954690546915469254693546945469554696546975469854699547005470154702547035470454705547065470754708547095471054711547125471354714547155471654717547185471954720547215472254723547245472554726547275472854729547305473154732547335473454735547365473754738547395474054741547425474354744547455474654747547485474954750547515475254753547545475554756547575475854759547605476154762547635476454765547665476754768547695477054771547725477354774547755477654777547785477954780547815478254783547845478554786547875478854789547905479154792547935479454795547965479754798547995480054801548025480354804548055480654807548085480954810548115481254813548145481554816548175481854819548205482154822548235482454825548265482754828548295483054831548325483354834548355483654837548385483954840548415484254843548445484554846548475484854849548505485154852548535485454855548565485754858548595486054861548625486354864548655486654867548685486954870548715487254873548745487554876548775487854879548805488154882548835488454885548865488754888548895489054891548925489354894548955489654897548985489954900549015490254903549045490554906549075490854909549105491154912549135491454915549165491754918549195492054921549225492354924549255492654927549285492954930549315493254933549345493554936549375493854939549405494154942549435494454945549465494754948549495495054951549525495354954549555495654957549585495954960549615496254963549645496554966549675496854969549705497154972549735497454975549765497754978549795498054981549825498354984549855498654987549885498954990549915499254993549945499554996549975499854999550005500155002550035500455005550065500755008550095501055011550125501355014550155501655017550185501955020550215502255023550245502555026550275502855029550305503155032550335503455035550365503755038550395504055041550425504355044550455504655047550485504955050550515505255053550545505555056550575505855059550605506155062550635506455065550665506755068550695507055071550725507355074550755507655077550785507955080550815508255083550845508555086550875508855089550905509155092550935509455095550965509755098550995510055101551025510355104551055510655107551085510955110551115511255113551145511555116551175511855119551205512155122551235512455125551265512755128551295513055131551325513355134551355513655137551385513955140551415514255143551445514555146551475514855149551505515155152551535515455155551565515755158551595516055161551625516355164551655516655167551685516955170551715517255173551745517555176551775517855179551805518155182551835518455185551865518755188551895519055191551925519355194551955519655197551985519955200552015520255203552045520555206552075520855209552105521155212552135521455215552165521755218552195522055221552225522355224552255522655227552285522955230552315523255233552345523555236552375523855239552405524155242552435524455245552465524755248552495525055251552525525355254552555525655257552585525955260552615526255263552645526555266552675526855269552705527155272552735527455275552765527755278552795528055281552825528355284552855528655287552885528955290552915529255293552945529555296552975529855299553005530155302553035530455305553065530755308553095531055311553125531355314553155531655317553185531955320553215532255323553245532555326553275532855329553305533155332553335533455335553365533755338553395534055341553425534355344553455534655347553485534955350553515535255353553545535555356553575535855359553605536155362553635536455365553665536755368553695537055371553725537355374553755537655377553785537955380553815538255383553845538555386553875538855389553905539155392553935539455395553965539755398553995540055401554025540355404554055540655407554085540955410554115541255413554145541555416554175541855419554205542155422554235542455425554265542755428554295543055431554325543355434554355543655437554385543955440554415544255443554445544555446554475544855449554505545155452554535545455455554565545755458554595546055461554625546355464554655546655467554685546955470554715547255473554745547555476554775547855479554805548155482554835548455485554865548755488554895549055491554925549355494554955549655497554985549955500555015550255503555045550555506555075550855509555105551155512555135551455515555165551755518555195552055521555225552355524555255552655527555285552955530555315553255533555345553555536555375553855539555405554155542555435554455545555465554755548555495555055551555525555355554555555555655557555585555955560555615556255563555645556555566555675556855569555705557155572555735557455575555765557755578555795558055581555825558355584555855558655587555885558955590555915559255593555945559555596555975559855599556005560155602556035560455605556065560755608556095561055611556125561355614556155561655617556185561955620556215562255623556245562555626556275562855629556305563155632556335563455635556365563755638556395564055641556425564355644556455564655647556485564955650556515565255653556545565555656556575565855659556605566155662556635566455665556665566755668556695567055671556725567355674556755567655677556785567955680556815568255683556845568555686556875568855689556905569155692556935569455695556965569755698556995570055701557025570355704557055570655707557085570955710557115571255713557145571555716557175571855719557205572155722557235572455725557265572755728557295573055731557325573355734557355573655737557385573955740557415574255743557445574555746557475574855749557505575155752557535575455755557565575755758557595576055761557625576355764557655576655767557685576955770557715577255773557745577555776557775577855779557805578155782557835578455785557865578755788557895579055791557925579355794557955579655797557985579955800558015580255803558045580555806558075580855809558105581155812558135581455815558165581755818558195582055821558225582355824558255582655827558285582955830558315583255833558345583555836558375583855839558405584155842558435584455845558465584755848558495585055851558525585355854558555585655857558585585955860558615586255863558645586555866558675586855869558705587155872558735587455875558765587755878558795588055881558825588355884558855588655887558885588955890558915589255893558945589555896558975589855899559005590155902559035590455905559065590755908559095591055911559125591355914559155591655917559185591955920559215592255923559245592555926559275592855929559305593155932559335593455935559365593755938559395594055941559425594355944559455594655947559485594955950559515595255953559545595555956559575595855959559605596155962559635596455965559665596755968559695597055971559725597355974559755597655977559785597955980559815598255983559845598555986559875598855989559905599155992559935599455995559965599755998559995600056001560025600356004560055600656007560085600956010560115601256013560145601556016560175601856019560205602156022560235602456025560265602756028560295603056031560325603356034560355603656037560385603956040560415604256043560445604556046560475604856049560505605156052560535605456055560565605756058560595606056061560625606356064560655606656067560685606956070560715607256073560745607556076560775607856079560805608156082560835608456085560865608756088560895609056091560925609356094560955609656097560985609956100561015610256103561045610556106561075610856109561105611156112561135611456115561165611756118561195612056121561225612356124561255612656127561285612956130561315613256133561345613556136561375613856139561405614156142561435614456145561465614756148561495615056151561525615356154561555615656157561585615956160561615616256163561645616556166561675616856169561705617156172561735617456175561765617756178561795618056181561825618356184561855618656187561885618956190561915619256193561945619556196561975619856199562005620156202562035620456205562065620756208562095621056211562125621356214562155621656217562185621956220562215622256223562245622556226562275622856229562305623156232562335623456235562365623756238562395624056241562425624356244562455624656247562485624956250562515625256253562545625556256562575625856259562605626156262562635626456265562665626756268562695627056271562725627356274562755627656277562785627956280562815628256283562845628556286562875628856289562905629156292562935629456295562965629756298562995630056301563025630356304563055630656307563085630956310563115631256313563145631556316563175631856319563205632156322563235632456325563265632756328563295633056331563325633356334563355633656337563385633956340563415634256343563445634556346563475634856349563505635156352563535635456355563565635756358563595636056361563625636356364563655636656367563685636956370563715637256373563745637556376563775637856379563805638156382563835638456385563865638756388563895639056391563925639356394563955639656397563985639956400564015640256403564045640556406564075640856409564105641156412564135641456415564165641756418564195642056421564225642356424564255642656427564285642956430564315643256433564345643556436564375643856439564405644156442564435644456445564465644756448564495645056451564525645356454564555645656457564585645956460564615646256463564645646556466564675646856469564705647156472564735647456475564765647756478564795648056481564825648356484564855648656487564885648956490564915649256493564945649556496564975649856499565005650156502565035650456505565065650756508565095651056511565125651356514565155651656517565185651956520565215652256523565245652556526565275652856529565305653156532565335653456535565365653756538565395654056541565425654356544565455654656547565485654956550565515655256553565545655556556565575655856559565605656156562565635656456565565665656756568565695657056571565725657356574565755657656577565785657956580565815658256583565845658556586565875658856589565905659156592565935659456595565965659756598565995660056601566025660356604566055660656607566085660956610566115661256613566145661556616566175661856619566205662156622566235662456625566265662756628566295663056631566325663356634566355663656637566385663956640566415664256643566445664556646566475664856649566505665156652566535665456655566565665756658566595666056661566625666356664566655666656667566685666956670566715667256673566745667556676566775667856679566805668156682566835668456685566865668756688566895669056691566925669356694566955669656697566985669956700567015670256703567045670556706567075670856709567105671156712567135671456715567165671756718567195672056721567225672356724567255672656727567285672956730567315673256733567345673556736567375673856739567405674156742567435674456745567465674756748567495675056751567525675356754567555675656757567585675956760567615676256763567645676556766567675676856769567705677156772567735677456775567765677756778567795678056781567825678356784567855678656787567885678956790567915679256793567945679556796567975679856799568005680156802568035680456805568065680756808568095681056811568125681356814568155681656817568185681956820568215682256823568245682556826568275682856829568305683156832568335683456835568365683756838568395684056841568425684356844568455684656847568485684956850568515685256853568545685556856568575685856859568605686156862568635686456865568665686756868568695687056871568725687356874568755687656877568785687956880568815688256883568845688556886568875688856889568905689156892568935689456895568965689756898568995690056901569025690356904569055690656907569085690956910569115691256913569145691556916569175691856919569205692156922569235692456925569265692756928569295693056931569325693356934569355693656937569385693956940569415694256943569445694556946569475694856949569505695156952569535695456955569565695756958569595696056961569625696356964569655696656967569685696956970569715697256973569745697556976569775697856979569805698156982569835698456985569865698756988569895699056991569925699356994569955699656997569985699957000570015700257003570045700557006570075700857009570105701157012570135701457015570165701757018570195702057021570225702357024570255702657027570285702957030570315703257033570345703557036570375703857039570405704157042570435704457045570465704757048570495705057051570525705357054570555705657057570585705957060570615706257063570645706557066570675706857069570705707157072570735707457075570765707757078570795708057081570825708357084570855708657087570885708957090570915709257093570945709557096570975709857099571005710157102571035710457105571065710757108571095711057111571125711357114571155711657117571185711957120571215712257123571245712557126571275712857129571305713157132571335713457135571365713757138571395714057141571425714357144571455714657147571485714957150571515715257153571545715557156571575715857159571605716157162571635716457165571665716757168571695717057171571725717357174571755717657177571785717957180571815718257183571845718557186571875718857189571905719157192571935719457195571965719757198571995720057201572025720357204572055720657207572085720957210572115721257213572145721557216572175721857219572205722157222572235722457225572265722757228572295723057231572325723357234572355723657237572385723957240572415724257243572445724557246572475724857249572505725157252572535725457255572565725757258572595726057261572625726357264572655726657267572685726957270572715727257273572745727557276572775727857279572805728157282572835728457285572865728757288572895729057291572925729357294572955729657297572985729957300573015730257303573045730557306573075730857309573105731157312573135731457315573165731757318573195732057321573225732357324573255732657327573285732957330573315733257333573345733557336573375733857339573405734157342573435734457345573465734757348573495735057351573525735357354573555735657357573585735957360573615736257363573645736557366573675736857369573705737157372573735737457375573765737757378573795738057381573825738357384573855738657387573885738957390573915739257393573945739557396573975739857399574005740157402574035740457405574065740757408574095741057411574125741357414574155741657417574185741957420574215742257423574245742557426574275742857429574305743157432574335743457435574365743757438574395744057441574425744357444574455744657447574485744957450574515745257453574545745557456574575745857459574605746157462574635746457465574665746757468574695747057471574725747357474574755747657477574785747957480574815748257483574845748557486574875748857489574905749157492574935749457495574965749757498574995750057501575025750357504575055750657507575085750957510575115751257513575145751557516575175751857519575205752157522575235752457525575265752757528575295753057531575325753357534575355753657537575385753957540575415754257543575445754557546575475754857549575505755157552575535755457555575565755757558575595756057561575625756357564575655756657567575685756957570575715757257573575745757557576575775757857579575805758157582575835758457585575865758757588575895759057591575925759357594575955759657597575985759957600576015760257603576045760557606576075760857609576105761157612576135761457615576165761757618576195762057621576225762357624576255762657627576285762957630576315763257633576345763557636576375763857639576405764157642576435764457645576465764757648576495765057651576525765357654576555765657657576585765957660576615766257663576645766557666576675766857669576705767157672576735767457675576765767757678576795768057681576825768357684576855768657687576885768957690576915769257693576945769557696576975769857699577005770157702577035770457705577065770757708577095771057711577125771357714577155771657717577185771957720577215772257723577245772557726577275772857729577305773157732577335773457735577365773757738577395774057741577425774357744577455774657747577485774957750577515775257753577545775557756577575775857759577605776157762577635776457765577665776757768577695777057771577725777357774577755777657777577785777957780577815778257783577845778557786577875778857789577905779157792577935779457795577965779757798577995780057801578025780357804578055780657807578085780957810578115781257813578145781557816578175781857819578205782157822578235782457825578265782757828578295783057831578325783357834578355783657837578385783957840578415784257843578445784557846578475784857849578505785157852578535785457855578565785757858578595786057861578625786357864578655786657867578685786957870578715787257873578745787557876578775787857879578805788157882578835788457885578865788757888578895789057891578925789357894578955789657897578985789957900579015790257903579045790557906579075790857909579105791157912579135791457915579165791757918579195792057921579225792357924579255792657927579285792957930579315793257933579345793557936579375793857939579405794157942579435794457945579465794757948579495795057951579525795357954579555795657957579585795957960579615796257963579645796557966579675796857969579705797157972579735797457975579765797757978579795798057981579825798357984579855798657987579885798957990579915799257993579945799557996579975799857999580005800158002580035800458005580065800758008580095801058011580125801358014580155801658017580185801958020580215802258023580245802558026580275802858029580305803158032580335803458035580365803758038580395804058041580425804358044580455804658047580485804958050580515805258053580545805558056580575805858059580605806158062580635806458065580665806758068580695807058071580725807358074580755807658077580785807958080580815808258083580845808558086580875808858089580905809158092580935809458095580965809758098580995810058101581025810358104581055810658107581085810958110581115811258113581145811558116581175811858119581205812158122581235812458125581265812758128581295813058131581325813358134581355813658137581385813958140581415814258143581445814558146581475814858149581505815158152581535815458155581565815758158581595816058161581625816358164581655816658167581685816958170581715817258173581745817558176581775817858179581805818158182581835818458185581865818758188581895819058191581925819358194581955819658197581985819958200582015820258203582045820558206582075820858209582105821158212582135821458215582165821758218582195822058221582225822358224582255822658227582285822958230582315823258233582345823558236582375823858239582405824158242582435824458245582465824758248582495825058251582525825358254582555825658257582585825958260582615826258263582645826558266582675826858269582705827158272582735827458275582765827758278582795828058281582825828358284582855828658287582885828958290582915829258293582945829558296582975829858299583005830158302583035830458305583065830758308583095831058311583125831358314583155831658317583185831958320583215832258323583245832558326583275832858329583305833158332583335833458335583365833758338583395834058341583425834358344583455834658347583485834958350583515835258353583545835558356583575835858359583605836158362583635836458365583665836758368583695837058371583725837358374583755837658377583785837958380583815838258383583845838558386583875838858389583905839158392583935839458395583965839758398583995840058401584025840358404584055840658407584085840958410584115841258413584145841558416584175841858419584205842158422584235842458425584265842758428584295843058431584325843358434584355843658437584385843958440584415844258443584445844558446584475844858449584505845158452584535845458455584565845758458584595846058461584625846358464584655846658467584685846958470584715847258473584745847558476584775847858479584805848158482584835848458485584865848758488584895849058491584925849358494584955849658497584985849958500585015850258503585045850558506585075850858509585105851158512585135851458515585165851758518585195852058521585225852358524585255852658527585285852958530585315853258533585345853558536585375853858539585405854158542585435854458545585465854758548585495855058551585525855358554585555855658557585585855958560585615856258563585645856558566585675856858569585705857158572585735857458575585765857758578585795858058581585825858358584585855858658587585885858958590585915859258593585945859558596585975859858599586005860158602586035860458605586065860758608586095861058611586125861358614586155861658617586185861958620586215862258623586245862558626586275862858629586305863158632586335863458635586365863758638586395864058641586425864358644586455864658647586485864958650586515865258653586545865558656586575865858659586605866158662586635866458665586665866758668586695867058671586725867358674586755867658677586785867958680586815868258683586845868558686586875868858689586905869158692586935869458695586965869758698586995870058701587025870358704587055870658707587085870958710587115871258713587145871558716587175871858719587205872158722587235872458725587265872758728587295873058731587325873358734587355873658737587385873958740587415874258743587445874558746587475874858749587505875158752587535875458755587565875758758587595876058761587625876358764587655876658767587685876958770587715877258773587745877558776587775877858779587805878158782587835878458785587865878758788587895879058791587925879358794587955879658797587985879958800588015880258803588045880558806588075880858809588105881158812588135881458815588165881758818588195882058821588225882358824588255882658827588285882958830588315883258833588345883558836588375883858839588405884158842588435884458845588465884758848588495885058851588525885358854588555885658857588585885958860588615886258863588645886558866588675886858869588705887158872588735887458875588765887758878588795888058881588825888358884588855888658887588885888958890588915889258893588945889558896588975889858899589005890158902589035890458905589065890758908589095891058911589125891358914589155891658917589185891958920589215892258923589245892558926589275892858929589305893158932589335893458935589365893758938589395894058941589425894358944589455894658947589485894958950589515895258953589545895558956589575895858959589605896158962589635896458965589665896758968589695897058971589725897358974589755897658977589785897958980589815898258983589845898558986589875898858989589905899158992589935899458995589965899758998589995900059001590025900359004590055900659007590085900959010590115901259013590145901559016590175901859019590205902159022590235902459025590265902759028590295903059031590325903359034590355903659037590385903959040590415904259043590445904559046590475904859049590505905159052590535905459055590565905759058590595906059061590625906359064590655906659067590685906959070590715907259073590745907559076590775907859079590805908159082590835908459085590865908759088590895909059091590925909359094590955909659097590985909959100591015910259103591045910559106591075910859109591105911159112591135911459115591165911759118591195912059121591225912359124591255912659127591285912959130591315913259133591345913559136591375913859139591405914159142591435914459145591465914759148591495915059151591525915359154591555915659157591585915959160591615916259163591645916559166591675916859169591705917159172591735917459175591765917759178591795918059181591825918359184591855918659187591885918959190591915919259193591945919559196591975919859199592005920159202592035920459205592065920759208592095921059211592125921359214592155921659217592185921959220592215922259223592245922559226592275922859229592305923159232592335923459235592365923759238592395924059241592425924359244592455924659247592485924959250592515925259253592545925559256592575925859259592605926159262592635926459265592665926759268592695927059271592725927359274592755927659277592785927959280592815928259283592845928559286592875928859289592905929159292592935929459295592965929759298592995930059301593025930359304593055930659307593085930959310593115931259313593145931559316593175931859319593205932159322593235932459325593265932759328593295933059331593325933359334593355933659337593385933959340593415934259343593445934559346593475934859349593505935159352593535935459355593565935759358593595936059361593625936359364593655936659367593685936959370593715937259373593745937559376593775937859379593805938159382593835938459385593865938759388593895939059391593925939359394593955939659397593985939959400594015940259403594045940559406594075940859409594105941159412594135941459415594165941759418594195942059421594225942359424594255942659427594285942959430594315943259433594345943559436594375943859439594405944159442594435944459445594465944759448594495945059451594525945359454594555945659457594585945959460594615946259463594645946559466594675946859469594705947159472594735947459475594765947759478594795948059481594825948359484594855948659487594885948959490594915949259493594945949559496594975949859499595005950159502595035950459505595065950759508595095951059511595125951359514595155951659517595185951959520595215952259523595245952559526595275952859529595305953159532595335953459535595365953759538595395954059541595425954359544595455954659547595485954959550595515955259553595545955559556595575955859559595605956159562595635956459565595665956759568595695957059571595725957359574595755957659577595785957959580595815958259583595845958559586595875958859589595905959159592595935959459595595965959759598595995960059601596025960359604596055960659607596085960959610596115961259613596145961559616596175961859619596205962159622596235962459625596265962759628596295963059631596325963359634596355963659637596385963959640596415964259643596445964559646596475964859649596505965159652596535965459655596565965759658596595966059661596625966359664596655966659667596685966959670596715967259673596745967559676596775967859679596805968159682596835968459685596865968759688596895969059691596925969359694596955969659697596985969959700597015970259703597045970559706597075970859709597105971159712597135971459715597165971759718597195972059721597225972359724597255972659727597285972959730597315973259733597345973559736597375973859739597405974159742597435974459745597465974759748597495975059751597525975359754597555975659757597585975959760597615976259763597645976559766597675976859769597705977159772597735977459775597765977759778597795978059781597825978359784597855978659787597885978959790597915979259793597945979559796597975979859799598005980159802598035980459805598065980759808598095981059811598125981359814598155981659817598185981959820598215982259823598245982559826598275982859829598305983159832598335983459835598365983759838598395984059841598425984359844598455984659847598485984959850598515985259853598545985559856598575985859859598605986159862598635986459865598665986759868598695987059871598725987359874598755987659877598785987959880598815988259883598845988559886598875988859889598905989159892598935989459895598965989759898598995990059901599025990359904599055990659907599085990959910599115991259913599145991559916599175991859919599205992159922599235992459925599265992759928599295993059931599325993359934599355993659937599385993959940599415994259943599445994559946599475994859949599505995159952599535995459955599565995759958599595996059961599625996359964599655996659967599685996959970599715997259973599745997559976599775997859979599805998159982599835998459985599865998759988599895999059991599925999359994599955999659997599985999960000600016000260003600046000560006600076000860009600106001160012600136001460015600166001760018600196002060021600226002360024600256002660027600286002960030600316003260033600346003560036600376003860039600406004160042600436004460045600466004760048600496005060051600526005360054600556005660057600586005960060600616006260063600646006560066600676006860069600706007160072600736007460075600766007760078600796008060081600826008360084600856008660087600886008960090600916009260093600946009560096600976009860099601006010160102601036010460105601066010760108601096011060111601126011360114601156011660117601186011960120601216012260123601246012560126601276012860129601306013160132601336013460135601366013760138601396014060141601426014360144601456014660147601486014960150601516015260153601546015560156601576015860159601606016160162601636016460165601666016760168601696017060171601726017360174601756017660177601786017960180601816018260183601846018560186601876018860189601906019160192601936019460195601966019760198601996020060201602026020360204602056020660207602086020960210602116021260213602146021560216602176021860219602206022160222602236022460225602266022760228602296023060231602326023360234602356023660237602386023960240602416024260243602446024560246602476024860249602506025160252602536025460255602566025760258602596026060261602626026360264602656026660267602686026960270602716027260273602746027560276602776027860279602806028160282602836028460285602866028760288602896029060291602926029360294602956029660297602986029960300603016030260303603046030560306603076030860309603106031160312603136031460315603166031760318603196032060321603226032360324603256032660327603286032960330603316033260333603346033560336603376033860339603406034160342603436034460345603466034760348603496035060351603526035360354603556035660357603586035960360603616036260363603646036560366603676036860369603706037160372603736037460375603766037760378603796038060381603826038360384603856038660387603886038960390603916039260393603946039560396603976039860399604006040160402604036040460405604066040760408604096041060411604126041360414604156041660417604186041960420604216042260423604246042560426604276042860429604306043160432604336043460435604366043760438604396044060441604426044360444604456044660447604486044960450604516045260453604546045560456604576045860459604606046160462604636046460465604666046760468604696047060471604726047360474604756047660477604786047960480604816048260483604846048560486604876048860489604906049160492604936049460495604966049760498604996050060501605026050360504605056050660507605086050960510605116051260513605146051560516605176051860519605206052160522605236052460525605266052760528605296053060531605326053360534605356053660537605386053960540605416054260543605446054560546605476054860549605506055160552605536055460555605566055760558605596056060561605626056360564605656056660567605686056960570605716057260573605746057560576605776057860579605806058160582605836058460585605866058760588605896059060591605926059360594605956059660597605986059960600606016060260603606046060560606606076060860609606106061160612606136061460615606166061760618606196062060621606226062360624606256062660627606286062960630606316063260633606346063560636606376063860639606406064160642606436064460645606466064760648606496065060651606526065360654606556065660657606586065960660606616066260663606646066560666606676066860669606706067160672606736067460675606766067760678606796068060681606826068360684606856068660687606886068960690606916069260693606946069560696606976069860699607006070160702607036070460705607066070760708607096071060711607126071360714607156071660717607186071960720607216072260723607246072560726607276072860729607306073160732607336073460735607366073760738607396074060741607426074360744607456074660747607486074960750607516075260753607546075560756607576075860759607606076160762607636076460765607666076760768607696077060771607726077360774607756077660777607786077960780607816078260783607846078560786607876078860789607906079160792607936079460795607966079760798607996080060801608026080360804608056080660807608086080960810608116081260813608146081560816608176081860819608206082160822608236082460825608266082760828608296083060831608326083360834608356083660837608386083960840608416084260843608446084560846608476084860849608506085160852608536085460855608566085760858608596086060861608626086360864608656086660867608686086960870608716087260873608746087560876608776087860879608806088160882608836088460885608866088760888608896089060891608926089360894608956089660897608986089960900609016090260903609046090560906609076090860909609106091160912609136091460915609166091760918609196092060921609226092360924609256092660927609286092960930609316093260933609346093560936609376093860939609406094160942609436094460945609466094760948609496095060951609526095360954609556095660957609586095960960609616096260963609646096560966609676096860969609706097160972609736097460975609766097760978609796098060981609826098360984609856098660987609886098960990609916099260993609946099560996609976099860999610006100161002610036100461005610066100761008610096101061011610126101361014610156101661017610186101961020610216102261023610246102561026610276102861029610306103161032610336103461035610366103761038610396104061041610426104361044610456104661047610486104961050610516105261053610546105561056610576105861059610606106161062610636106461065610666106761068610696107061071610726107361074610756107661077610786107961080610816108261083610846108561086610876108861089610906109161092610936109461095610966109761098610996110061101611026110361104611056110661107611086110961110611116111261113611146111561116611176111861119611206112161122611236112461125611266112761128611296113061131611326113361134611356113661137611386113961140611416114261143611446114561146611476114861149611506115161152611536115461155611566115761158611596116061161611626116361164611656116661167611686116961170611716117261173611746117561176611776117861179611806118161182611836118461185611866118761188611896119061191611926119361194611956119661197611986119961200612016120261203612046120561206612076120861209612106121161212612136121461215612166121761218612196122061221612226122361224612256122661227612286122961230612316123261233612346123561236612376123861239612406124161242612436124461245612466124761248612496125061251612526125361254612556125661257612586125961260612616126261263612646126561266612676126861269612706127161272612736127461275612766127761278612796128061281612826128361284612856128661287612886128961290612916129261293612946129561296612976129861299613006130161302613036130461305613066130761308613096131061311613126131361314613156131661317613186131961320613216132261323613246132561326613276132861329613306133161332613336133461335613366133761338613396134061341613426134361344613456134661347613486134961350613516135261353613546135561356613576135861359613606136161362613636136461365613666136761368613696137061371613726137361374613756137661377613786137961380613816138261383613846138561386613876138861389613906139161392613936139461395613966139761398613996140061401614026140361404614056140661407614086140961410614116141261413614146141561416614176141861419614206142161422614236142461425614266142761428614296143061431614326143361434614356143661437614386143961440614416144261443614446144561446614476144861449614506145161452614536145461455614566145761458614596146061461614626146361464614656146661467614686146961470614716147261473614746147561476614776147861479614806148161482614836148461485614866148761488614896149061491614926149361494614956149661497614986149961500615016150261503615046150561506615076150861509615106151161512615136151461515615166151761518615196152061521615226152361524615256152661527615286152961530615316153261533615346153561536615376153861539615406154161542615436154461545615466154761548615496155061551615526155361554615556155661557615586155961560615616156261563615646156561566615676156861569615706157161572615736157461575615766157761578615796158061581615826158361584615856158661587615886158961590615916159261593615946159561596615976159861599616006160161602616036160461605616066160761608616096161061611616126161361614616156161661617616186161961620616216162261623616246162561626616276162861629616306163161632616336163461635616366163761638616396164061641616426164361644616456164661647616486164961650616516165261653616546165561656616576165861659616606166161662616636166461665616666166761668616696167061671616726167361674616756167661677616786167961680616816168261683616846168561686616876168861689616906169161692616936169461695616966169761698616996170061701617026170361704617056170661707617086170961710617116171261713617146171561716617176171861719617206172161722617236172461725617266172761728617296173061731617326173361734617356173661737617386173961740617416174261743617446174561746617476174861749617506175161752617536175461755617566175761758617596176061761617626176361764617656176661767617686176961770617716177261773617746177561776617776177861779617806178161782617836178461785617866178761788617896179061791617926179361794617956179661797617986179961800618016180261803618046180561806618076180861809618106181161812618136181461815618166181761818618196182061821618226182361824618256182661827618286182961830618316183261833618346183561836618376183861839618406184161842618436184461845618466184761848618496185061851618526185361854618556185661857618586185961860618616186261863618646186561866618676186861869618706187161872618736187461875618766187761878618796188061881618826188361884618856188661887618886188961890618916189261893618946189561896618976189861899619006190161902619036190461905619066190761908619096191061911619126191361914619156191661917619186191961920619216192261923619246192561926619276192861929619306193161932619336193461935619366193761938619396194061941619426194361944619456194661947619486194961950619516195261953619546195561956619576195861959619606196161962619636196461965619666196761968619696197061971619726197361974619756197661977619786197961980619816198261983619846198561986619876198861989619906199161992619936199461995619966199761998619996200062001620026200362004620056200662007620086200962010620116201262013620146201562016620176201862019620206202162022620236202462025620266202762028620296203062031620326203362034620356203662037620386203962040620416204262043620446204562046620476204862049620506205162052620536205462055620566205762058620596206062061620626206362064620656206662067620686206962070620716207262073620746207562076620776207862079620806208162082620836208462085620866208762088620896209062091620926209362094620956209662097620986209962100621016210262103621046210562106621076210862109621106211162112621136211462115621166211762118621196212062121621226212362124621256212662127621286212962130621316213262133621346213562136621376213862139621406214162142621436214462145621466214762148621496215062151621526215362154621556215662157621586215962160621616216262163621646216562166621676216862169621706217162172621736217462175621766217762178621796218062181621826218362184621856218662187621886218962190621916219262193621946219562196621976219862199622006220162202622036220462205622066220762208622096221062211622126221362214622156221662217622186221962220622216222262223622246222562226622276222862229622306223162232622336223462235622366223762238622396224062241622426224362244622456224662247622486224962250622516225262253622546225562256622576225862259622606226162262622636226462265622666226762268622696227062271622726227362274622756227662277622786227962280622816228262283622846228562286622876228862289622906229162292622936229462295622966229762298622996230062301623026230362304623056230662307623086230962310623116231262313623146231562316623176231862319623206232162322623236232462325623266232762328623296233062331623326233362334623356233662337623386233962340623416234262343623446234562346623476234862349623506235162352623536235462355623566235762358623596236062361623626236362364623656236662367623686236962370623716237262373623746237562376623776237862379623806238162382623836238462385623866238762388623896239062391623926239362394623956239662397623986239962400624016240262403624046240562406624076240862409624106241162412624136241462415624166241762418624196242062421624226242362424624256242662427624286242962430624316243262433624346243562436624376243862439624406244162442624436244462445624466244762448624496245062451624526245362454624556245662457624586245962460624616246262463624646246562466624676246862469624706247162472624736247462475624766247762478624796248062481624826248362484624856248662487624886248962490624916249262493624946249562496624976249862499625006250162502625036250462505625066250762508625096251062511625126251362514625156251662517625186251962520625216252262523625246252562526625276252862529625306253162532625336253462535625366253762538625396254062541625426254362544625456254662547625486254962550625516255262553625546255562556625576255862559625606256162562625636256462565625666256762568625696257062571625726257362574625756257662577625786257962580625816258262583625846258562586625876258862589625906259162592625936259462595625966259762598625996260062601626026260362604626056260662607626086260962610626116261262613626146261562616626176261862619626206262162622626236262462625626266262762628626296263062631626326263362634626356263662637626386263962640626416264262643626446264562646626476264862649626506265162652626536265462655626566265762658626596266062661626626266362664626656266662667626686266962670626716267262673626746267562676626776267862679626806268162682626836268462685626866268762688626896269062691626926269362694626956269662697626986269962700627016270262703627046270562706627076270862709627106271162712627136271462715627166271762718627196272062721627226272362724627256272662727627286272962730627316273262733627346273562736627376273862739627406274162742627436274462745627466274762748627496275062751627526275362754627556275662757627586275962760627616276262763627646276562766627676276862769627706277162772627736277462775627766277762778627796278062781627826278362784627856278662787627886278962790627916279262793627946279562796627976279862799628006280162802628036280462805628066280762808628096281062811628126281362814628156281662817628186281962820628216282262823628246282562826628276282862829628306283162832628336283462835628366283762838628396284062841628426284362844628456284662847628486284962850628516285262853628546285562856628576285862859628606286162862628636286462865628666286762868628696287062871628726287362874628756287662877628786287962880628816288262883628846288562886628876288862889628906289162892628936289462895628966289762898628996290062901629026290362904629056290662907629086290962910629116291262913629146291562916629176291862919629206292162922629236292462925629266292762928629296293062931629326293362934629356293662937629386293962940629416294262943629446294562946629476294862949629506295162952629536295462955629566295762958629596296062961629626296362964629656296662967629686296962970629716297262973629746297562976629776297862979629806298162982629836298462985629866298762988629896299062991629926299362994629956299662997629986299963000630016300263003630046300563006630076300863009630106301163012630136301463015630166301763018630196302063021630226302363024630256302663027630286302963030630316303263033630346303563036630376303863039630406304163042630436304463045630466304763048630496305063051630526305363054630556305663057630586305963060630616306263063630646306563066630676306863069630706307163072630736307463075630766307763078630796308063081630826308363084630856308663087630886308963090630916309263093630946309563096630976309863099631006310163102631036310463105631066310763108631096311063111631126311363114631156311663117631186311963120631216312263123631246312563126631276312863129631306313163132631336313463135631366313763138631396314063141631426314363144631456314663147631486314963150631516315263153631546315563156631576315863159631606316163162631636316463165631666316763168631696317063171631726317363174631756317663177631786317963180631816318263183631846318563186631876318863189631906319163192631936319463195631966319763198631996320063201632026320363204632056320663207632086320963210632116321263213632146321563216632176321863219632206322163222632236322463225632266322763228632296323063231632326323363234632356323663237632386323963240632416324263243632446324563246632476324863249632506325163252632536325463255632566325763258632596326063261632626326363264632656326663267632686326963270632716327263273632746327563276632776327863279632806328163282632836328463285632866328763288632896329063291632926329363294632956329663297632986329963300633016330263303633046330563306633076330863309633106331163312633136331463315633166331763318633196332063321633226332363324633256332663327633286332963330633316333263333633346333563336633376333863339633406334163342633436334463345633466334763348633496335063351633526335363354633556335663357633586335963360633616336263363633646336563366633676336863369633706337163372633736337463375633766337763378633796338063381633826338363384633856338663387633886338963390633916339263393633946339563396633976339863399634006340163402634036340463405634066340763408634096341063411634126341363414634156341663417634186341963420634216342263423634246342563426634276342863429634306343163432634336343463435634366343763438634396344063441634426344363444634456344663447634486344963450634516345263453634546345563456634576345863459634606346163462634636346463465634666346763468634696347063471634726347363474634756347663477634786347963480634816348263483634846348563486634876348863489634906349163492634936349463495634966349763498634996350063501635026350363504635056350663507635086350963510635116351263513635146351563516635176351863519635206352163522635236352463525635266352763528635296353063531635326353363534635356353663537635386353963540635416354263543635446354563546635476354863549635506355163552635536355463555635566355763558635596356063561635626356363564635656356663567635686356963570635716357263573635746357563576635776357863579635806358163582635836358463585635866358763588635896359063591635926359363594635956359663597635986359963600636016360263603636046360563606636076360863609636106361163612636136361463615636166361763618636196362063621636226362363624636256362663627636286362963630636316363263633636346363563636636376363863639636406364163642636436364463645636466364763648636496365063651636526365363654636556365663657636586365963660636616366263663636646366563666636676366863669636706367163672636736367463675636766367763678636796368063681636826368363684636856368663687636886368963690636916369263693636946369563696636976369863699637006370163702637036370463705637066370763708637096371063711637126371363714637156371663717637186371963720637216372263723637246372563726637276372863729637306373163732637336373463735637366373763738637396374063741637426374363744637456374663747637486374963750637516375263753637546375563756637576375863759637606376163762637636376463765637666376763768637696377063771637726377363774637756377663777637786377963780637816378263783637846378563786637876378863789637906379163792637936379463795637966379763798637996380063801638026380363804638056380663807638086380963810638116381263813638146381563816638176381863819638206382163822638236382463825638266382763828638296383063831638326383363834638356383663837638386383963840638416384263843638446384563846638476384863849638506385163852638536385463855638566385763858638596386063861638626386363864638656386663867638686386963870638716387263873638746387563876638776387863879638806388163882638836388463885638866388763888638896389063891638926389363894638956389663897638986389963900639016390263903639046390563906639076390863909639106391163912639136391463915639166391763918639196392063921639226392363924639256392663927639286392963930639316393263933639346393563936639376393863939639406394163942639436394463945639466394763948639496395063951639526395363954639556395663957639586395963960639616396263963639646396563966639676396863969639706397163972639736397463975639766397763978639796398063981639826398363984639856398663987639886398963990639916399263993639946399563996639976399863999640006400164002640036400464005640066400764008640096401064011640126401364014640156401664017640186401964020640216402264023640246402564026640276402864029640306403164032640336403464035640366403764038640396404064041640426404364044640456404664047640486404964050640516405264053640546405564056640576405864059640606406164062640636406464065640666406764068640696407064071640726407364074640756407664077640786407964080640816408264083640846408564086640876408864089640906409164092640936409464095640966409764098640996410064101641026410364104641056410664107641086410964110641116411264113641146411564116641176411864119641206412164122641236412464125641266412764128641296413064131641326413364134641356413664137641386413964140641416414264143641446414564146641476414864149641506415164152641536415464155641566415764158641596416064161641626416364164641656416664167641686416964170641716417264173641746417564176641776417864179641806418164182641836418464185641866418764188641896419064191641926419364194641956419664197641986419964200642016420264203642046420564206642076420864209642106421164212642136421464215642166421764218642196422064221642226422364224642256422664227642286422964230642316423264233642346423564236642376423864239642406424164242642436424464245642466424764248642496425064251642526425364254642556425664257642586425964260642616426264263642646426564266642676426864269642706427164272642736427464275642766427764278642796428064281642826428364284642856428664287642886428964290642916429264293642946429564296642976429864299643006430164302643036430464305643066430764308643096431064311643126431364314643156431664317643186431964320643216432264323643246432564326643276432864329643306433164332643336433464335643366433764338643396434064341643426434364344643456434664347643486434964350643516435264353643546435564356643576435864359643606436164362643636436464365643666436764368643696437064371643726437364374643756437664377643786437964380643816438264383643846438564386643876438864389643906439164392643936439464395643966439764398643996440064401644026440364404644056440664407644086440964410644116441264413644146441564416644176441864419644206442164422644236442464425644266442764428644296443064431644326443364434644356443664437644386443964440644416444264443644446444564446644476444864449644506445164452644536445464455644566445764458644596446064461644626446364464644656446664467644686446964470644716447264473644746447564476644776447864479644806448164482644836448464485644866448764488644896449064491644926449364494644956449664497644986449964500645016450264503645046450564506645076450864509645106451164512645136451464515645166451764518645196452064521645226452364524645256452664527645286452964530645316453264533645346453564536645376453864539645406454164542645436454464545645466454764548645496455064551645526455364554645556455664557645586455964560645616456264563645646456564566645676456864569645706457164572645736457464575645766457764578645796458064581645826458364584645856458664587645886458964590645916459264593645946459564596645976459864599646006460164602646036460464605646066460764608646096461064611646126461364614646156461664617646186461964620646216462264623646246462564626646276462864629646306463164632646336463464635646366463764638646396464064641646426464364644646456464664647646486464964650646516465264653646546465564656646576465864659646606466164662646636466464665646666466764668646696467064671646726467364674646756467664677646786467964680646816468264683646846468564686646876468864689646906469164692646936469464695646966469764698646996470064701647026470364704647056470664707647086470964710647116471264713647146471564716647176471864719647206472164722647236472464725647266472764728647296473064731647326473364734647356473664737647386473964740647416474264743647446474564746647476474864749647506475164752647536475464755647566475764758647596476064761647626476364764647656476664767647686476964770647716477264773647746477564776647776477864779647806478164782647836478464785647866478764788647896479064791647926479364794647956479664797647986479964800648016480264803648046480564806648076480864809648106481164812648136481464815648166481764818648196482064821648226482364824648256482664827648286482964830648316483264833648346483564836648376483864839648406484164842648436484464845648466484764848648496485064851648526485364854648556485664857648586485964860648616486264863648646486564866648676486864869648706487164872648736487464875648766487764878648796488064881648826488364884648856488664887648886488964890648916489264893648946489564896648976489864899649006490164902649036490464905649066490764908649096491064911649126491364914649156491664917649186491964920649216492264923649246492564926649276492864929649306493164932649336493464935649366493764938649396494064941649426494364944649456494664947649486494964950649516495264953649546495564956649576495864959649606496164962649636496464965649666496764968649696497064971649726497364974649756497664977649786497964980649816498264983649846498564986649876498864989649906499164992649936499464995649966499764998649996500065001650026500365004650056500665007650086500965010650116501265013650146501565016650176501865019650206502165022650236502465025650266502765028650296503065031650326503365034650356503665037650386503965040650416504265043650446504565046650476504865049650506505165052650536505465055650566505765058650596506065061650626506365064650656506665067650686506965070650716507265073650746507565076650776507865079650806508165082650836508465085650866508765088650896509065091650926509365094650956509665097650986509965100651016510265103651046510565106651076510865109651106511165112651136511465115651166511765118651196512065121651226512365124651256512665127651286512965130651316513265133651346513565136651376513865139651406514165142651436514465145651466514765148651496515065151651526515365154651556515665157651586515965160651616516265163651646516565166651676516865169651706517165172651736517465175651766517765178651796518065181651826518365184651856518665187651886518965190651916519265193651946519565196651976519865199652006520165202652036520465205652066520765208652096521065211652126521365214652156521665217652186521965220652216522265223652246522565226652276522865229652306523165232652336523465235652366523765238652396524065241652426524365244652456524665247652486524965250652516525265253652546525565256652576525865259652606526165262652636526465265652666526765268652696527065271652726527365274652756527665277652786527965280652816528265283652846528565286652876528865289652906529165292652936529465295652966529765298652996530065301653026530365304653056530665307653086530965310653116531265313653146531565316653176531865319653206532165322653236532465325653266532765328653296533065331653326533365334653356533665337653386533965340653416534265343653446534565346653476534865349653506535165352653536535465355653566535765358653596536065361653626536365364653656536665367653686536965370653716537265373653746537565376653776537865379653806538165382653836538465385653866538765388653896539065391653926539365394653956539665397653986539965400654016540265403654046540565406654076540865409654106541165412654136541465415654166541765418654196542065421654226542365424654256542665427654286542965430654316543265433654346543565436654376543865439654406544165442654436544465445654466544765448654496545065451654526545365454654556545665457654586545965460654616546265463654646546565466654676546865469654706547165472654736547465475654766547765478654796548065481654826548365484654856548665487654886548965490654916549265493654946549565496654976549865499655006550165502655036550465505655066550765508655096551065511655126551365514655156551665517655186551965520655216552265523655246552565526655276552865529655306553165532655336553465535655366553765538655396554065541655426554365544655456554665547655486554965550655516555265553655546555565556655576555865559655606556165562655636556465565655666556765568655696557065571655726557365574655756557665577655786557965580655816558265583655846558565586655876558865589655906559165592655936559465595655966559765598655996560065601656026560365604656056560665607656086560965610656116561265613656146561565616656176561865619656206562165622656236562465625656266562765628656296563065631656326563365634656356563665637656386563965640656416564265643656446564565646656476564865649656506565165652656536565465655656566565765658656596566065661656626566365664656656566665667656686566965670656716567265673656746567565676656776567865679656806568165682656836568465685656866568765688656896569065691656926569365694656956569665697656986569965700657016570265703657046570565706657076570865709657106571165712657136571465715657166571765718657196572065721657226572365724657256572665727657286572965730657316573265733657346573565736657376573865739657406574165742657436574465745657466574765748657496575065751657526575365754657556575665757657586575965760657616576265763657646576565766657676576865769657706577165772657736577465775657766577765778657796578065781657826578365784657856578665787657886578965790657916579265793657946579565796657976579865799658006580165802658036580465805658066580765808658096581065811658126581365814658156581665817658186581965820658216582265823658246582565826658276582865829658306583165832658336583465835658366583765838658396584065841658426584365844658456584665847658486584965850658516585265853658546585565856658576585865859658606586165862658636586465865658666586765868658696587065871658726587365874658756587665877658786587965880658816588265883658846588565886658876588865889658906589165892658936589465895658966589765898658996590065901659026590365904659056590665907659086590965910659116591265913659146591565916659176591865919659206592165922659236592465925659266592765928659296593065931659326593365934659356593665937659386593965940659416594265943659446594565946659476594865949659506595165952659536595465955659566595765958659596596065961659626596365964659656596665967659686596965970659716597265973659746597565976659776597865979659806598165982659836598465985659866598765988659896599065991659926599365994659956599665997659986599966000660016600266003660046600566006660076600866009660106601166012660136601466015660166601766018660196602066021660226602366024660256602666027660286602966030660316603266033660346603566036660376603866039660406604166042660436604466045660466604766048660496605066051660526605366054660556605666057660586605966060660616606266063660646606566066660676606866069660706607166072660736607466075660766607766078660796608066081660826608366084660856608666087660886608966090660916609266093660946609566096660976609866099661006610166102661036610466105661066610766108661096611066111661126611366114661156611666117661186611966120661216612266123661246612566126661276612866129661306613166132661336613466135661366613766138661396614066141661426614366144661456614666147661486614966150661516615266153661546615566156661576615866159661606616166162661636616466165661666616766168661696617066171661726617366174661756617666177661786617966180661816618266183661846618566186661876618866189661906619166192661936619466195661966619766198661996620066201662026620366204662056620666207662086620966210662116621266213662146621566216662176621866219662206622166222662236622466225662266622766228662296623066231662326623366234662356623666237662386623966240662416624266243662446624566246662476624866249662506625166252662536625466255662566625766258662596626066261662626626366264662656626666267662686626966270662716627266273662746627566276662776627866279662806628166282662836628466285662866628766288662896629066291662926629366294662956629666297662986629966300663016630266303663046630566306663076630866309663106631166312663136631466315663166631766318663196632066321663226632366324663256632666327663286632966330663316633266333663346633566336663376633866339663406634166342663436634466345663466634766348663496635066351663526635366354663556635666357663586635966360663616636266363663646636566366663676636866369663706637166372663736637466375663766637766378663796638066381663826638366384663856638666387663886638966390663916639266393663946639566396663976639866399664006640166402664036640466405664066640766408664096641066411664126641366414664156641666417664186641966420664216642266423664246642566426664276642866429664306643166432664336643466435664366643766438664396644066441664426644366444664456644666447664486644966450664516645266453664546645566456664576645866459664606646166462664636646466465664666646766468664696647066471664726647366474664756647666477664786647966480664816648266483664846648566486664876648866489664906649166492664936649466495664966649766498664996650066501665026650366504665056650666507665086650966510665116651266513665146651566516665176651866519665206652166522665236652466525665266652766528665296653066531665326653366534665356653666537665386653966540665416654266543665446654566546665476654866549665506655166552665536655466555665566655766558665596656066561665626656366564665656656666567665686656966570665716657266573665746657566576665776657866579665806658166582665836658466585665866658766588665896659066591665926659366594665956659666597665986659966600666016660266603666046660566606666076660866609666106661166612666136661466615666166661766618666196662066621666226662366624666256662666627666286662966630666316663266633666346663566636666376663866639666406664166642666436664466645666466664766648666496665066651666526665366654666556665666657666586665966660666616666266663666646666566666666676666866669666706667166672666736667466675666766667766678666796668066681666826668366684666856668666687666886668966690666916669266693666946669566696666976669866699667006670166702667036670466705667066670766708667096671066711667126671366714667156671666717667186671966720667216672266723667246672566726667276672866729667306673166732667336673466735667366673766738667396674066741667426674366744667456674666747667486674966750667516675266753667546675566756667576675866759667606676166762667636676466765667666676766768667696677066771667726677366774667756677666777667786677966780667816678266783667846678566786667876678866789667906679166792667936679466795667966679766798667996680066801668026680366804668056680666807668086680966810668116681266813668146681566816668176681866819668206682166822668236682466825668266682766828668296683066831668326683366834668356683666837668386683966840668416684266843668446684566846668476684866849668506685166852668536685466855668566685766858668596686066861668626686366864668656686666867668686686966870668716687266873668746687566876668776687866879668806688166882668836688466885668866688766888668896689066891668926689366894668956689666897668986689966900669016690266903669046690566906669076690866909669106691166912669136691466915669166691766918669196692066921669226692366924669256692666927669286692966930669316693266933669346693566936669376693866939669406694166942669436694466945669466694766948669496695066951669526695366954669556695666957669586695966960669616696266963669646696566966669676696866969669706697166972669736697466975669766697766978669796698066981669826698366984669856698666987669886698966990669916699266993669946699566996669976699866999670006700167002670036700467005670066700767008670096701067011670126701367014670156701667017670186701967020670216702267023670246702567026670276702867029670306703167032670336703467035670366703767038670396704067041670426704367044670456704667047670486704967050670516705267053670546705567056670576705867059670606706167062670636706467065670666706767068670696707067071670726707367074670756707667077670786707967080670816708267083670846708567086670876708867089670906709167092670936709467095670966709767098670996710067101671026710367104671056710667107671086710967110671116711267113671146711567116671176711867119671206712167122671236712467125671266712767128671296713067131671326713367134671356713667137671386713967140671416714267143671446714567146671476714867149671506715167152671536715467155671566715767158671596716067161671626716367164671656716667167671686716967170671716717267173671746717567176671776717867179671806718167182671836718467185671866718767188671896719067191671926719367194671956719667197671986719967200672016720267203672046720567206672076720867209672106721167212672136721467215672166721767218672196722067221672226722367224672256722667227672286722967230672316723267233672346723567236672376723867239672406724167242672436724467245672466724767248672496725067251672526725367254672556725667257672586725967260672616726267263672646726567266672676726867269672706727167272672736727467275672766727767278672796728067281672826728367284672856728667287672886728967290672916729267293672946729567296672976729867299673006730167302673036730467305673066730767308673096731067311673126731367314673156731667317673186731967320673216732267323673246732567326673276732867329673306733167332673336733467335673366733767338673396734067341673426734367344673456734667347673486734967350673516735267353673546735567356673576735867359673606736167362673636736467365673666736767368673696737067371673726737367374673756737667377673786737967380673816738267383673846738567386673876738867389673906739167392673936739467395673966739767398673996740067401674026740367404674056740667407674086740967410674116741267413674146741567416674176741867419674206742167422674236742467425674266742767428674296743067431674326743367434674356743667437674386743967440674416744267443674446744567446674476744867449674506745167452674536745467455674566745767458674596746067461674626746367464674656746667467674686746967470674716747267473674746747567476674776747867479674806748167482674836748467485674866748767488674896749067491674926749367494674956749667497674986749967500675016750267503675046750567506675076750867509675106751167512675136751467515675166751767518675196752067521675226752367524675256752667527675286752967530675316753267533675346753567536675376753867539675406754167542675436754467545675466754767548675496755067551675526755367554675556755667557675586755967560675616756267563675646756567566675676756867569675706757167572675736757467575675766757767578675796758067581675826758367584675856758667587675886758967590675916759267593675946759567596675976759867599676006760167602676036760467605676066760767608676096761067611676126761367614676156761667617676186761967620676216762267623676246762567626676276762867629676306763167632676336763467635676366763767638676396764067641676426764367644676456764667647676486764967650676516765267653676546765567656676576765867659676606766167662676636766467665676666766767668676696767067671676726767367674676756767667677676786767967680676816768267683676846768567686676876768867689676906769167692676936769467695676966769767698676996770067701677026770367704677056770667707677086770967710677116771267713677146771567716677176771867719677206772167722677236772467725677266772767728677296773067731677326773367734677356773667737677386773967740677416774267743677446774567746677476774867749677506775167752677536775467755677566775767758677596776067761677626776367764677656776667767677686776967770677716777267773677746777567776677776777867779677806778167782677836778467785677866778767788677896779067791677926779367794677956779667797677986779967800678016780267803678046780567806678076780867809678106781167812678136781467815678166781767818678196782067821678226782367824678256782667827678286782967830678316783267833678346783567836678376783867839678406784167842678436784467845678466784767848678496785067851678526785367854678556785667857678586785967860678616786267863678646786567866678676786867869678706787167872678736787467875678766787767878678796788067881678826788367884678856788667887678886788967890678916789267893678946789567896678976789867899679006790167902679036790467905679066790767908679096791067911679126791367914679156791667917679186791967920679216792267923679246792567926679276792867929679306793167932679336793467935679366793767938679396794067941679426794367944679456794667947679486794967950679516795267953679546795567956679576795867959679606796167962679636796467965679666796767968679696797067971679726797367974679756797667977679786797967980679816798267983679846798567986679876798867989679906799167992679936799467995679966799767998679996800068001680026800368004680056800668007680086800968010680116801268013680146801568016680176801868019680206802168022680236802468025680266802768028680296803068031680326803368034680356803668037680386803968040680416804268043680446804568046680476804868049680506805168052680536805468055680566805768058680596806068061680626806368064680656806668067680686806968070680716807268073680746807568076680776807868079680806808168082680836808468085680866808768088680896809068091680926809368094680956809668097680986809968100681016810268103681046810568106681076810868109681106811168112681136811468115681166811768118681196812068121681226812368124681256812668127681286812968130681316813268133681346813568136681376813868139681406814168142681436814468145681466814768148681496815068151681526815368154681556815668157681586815968160681616816268163681646816568166681676816868169681706817168172681736817468175681766817768178681796818068181681826818368184681856818668187681886818968190681916819268193681946819568196681976819868199682006820168202682036820468205682066820768208682096821068211682126821368214682156821668217682186821968220682216822268223682246822568226682276822868229682306823168232682336823468235682366823768238682396824068241682426824368244682456824668247682486824968250682516825268253682546825568256682576825868259682606826168262682636826468265682666826768268682696827068271682726827368274682756827668277682786827968280682816828268283682846828568286682876828868289682906829168292682936829468295682966829768298682996830068301683026830368304683056830668307683086830968310683116831268313683146831568316683176831868319683206832168322683236832468325683266832768328683296833068331683326833368334683356833668337683386833968340683416834268343683446834568346683476834868349683506835168352683536835468355683566835768358683596836068361683626836368364683656836668367683686836968370683716837268373683746837568376683776837868379683806838168382683836838468385683866838768388683896839068391683926839368394683956839668397683986839968400684016840268403684046840568406684076840868409684106841168412684136841468415684166841768418684196842068421684226842368424684256842668427684286842968430684316843268433684346843568436684376843868439684406844168442684436844468445684466844768448684496845068451684526845368454684556845668457684586845968460684616846268463684646846568466684676846868469684706847168472684736847468475684766847768478684796848068481684826848368484684856848668487684886848968490684916849268493684946849568496684976849868499685006850168502685036850468505685066850768508685096851068511685126851368514685156851668517685186851968520685216852268523685246852568526685276852868529685306853168532685336853468535685366853768538685396854068541685426854368544685456854668547685486854968550685516855268553685546855568556685576855868559685606856168562685636856468565685666856768568685696857068571685726857368574685756857668577685786857968580685816858268583685846858568586685876858868589685906859168592685936859468595685966859768598685996860068601686026860368604686056860668607686086860968610686116861268613686146861568616686176861868619686206862168622686236862468625686266862768628686296863068631686326863368634686356863668637686386863968640686416864268643686446864568646686476864868649686506865168652686536865468655686566865768658686596866068661686626866368664686656866668667686686866968670686716867268673686746867568676686776867868679686806868168682686836868468685686866868768688686896869068691686926869368694686956869668697686986869968700687016870268703687046870568706687076870868709687106871168712687136871468715687166871768718687196872068721687226872368724687256872668727687286872968730687316873268733687346873568736687376873868739687406874168742687436874468745687466874768748687496875068751687526875368754687556875668757687586875968760687616876268763687646876568766687676876868769687706877168772687736877468775687766877768778687796878068781687826878368784687856878668787687886878968790687916879268793687946879568796687976879868799688006880168802688036880468805688066880768808688096881068811688126881368814688156881668817688186881968820688216882268823688246882568826688276882868829688306883168832688336883468835688366883768838688396884068841688426884368844688456884668847688486884968850688516885268853688546885568856688576885868859688606886168862688636886468865688666886768868688696887068871688726887368874688756887668877688786887968880688816888268883688846888568886688876888868889688906889168892688936889468895688966889768898688996890068901689026890368904689056890668907689086890968910689116891268913689146891568916689176891868919689206892168922689236892468925689266892768928689296893068931689326893368934689356893668937689386893968940689416894268943689446894568946689476894868949689506895168952689536895468955689566895768958689596896068961689626896368964689656896668967689686896968970689716897268973689746897568976689776897868979689806898168982689836898468985689866898768988689896899068991689926899368994689956899668997689986899969000690016900269003690046900569006690076900869009690106901169012690136901469015690166901769018690196902069021690226902369024690256902669027690286902969030690316903269033690346903569036690376903869039690406904169042690436904469045690466904769048690496905069051690526905369054690556905669057690586905969060690616906269063690646906569066690676906869069690706907169072690736907469075690766907769078690796908069081690826908369084690856908669087690886908969090690916909269093690946909569096690976909869099691006910169102691036910469105691066910769108691096911069111691126911369114691156911669117691186911969120691216912269123691246912569126691276912869129691306913169132691336913469135691366913769138691396914069141691426914369144691456914669147691486914969150691516915269153691546915569156691576915869159691606916169162691636916469165691666916769168691696917069171691726917369174691756917669177691786917969180691816918269183691846918569186691876918869189691906919169192691936919469195691966919769198691996920069201692026920369204692056920669207692086920969210692116921269213692146921569216692176921869219692206922169222692236922469225692266922769228692296923069231692326923369234692356923669237692386923969240692416924269243692446924569246692476924869249692506925169252692536925469255692566925769258692596926069261692626926369264692656926669267692686926969270692716927269273692746927569276692776927869279692806928169282692836928469285692866928769288692896929069291692926929369294692956929669297692986929969300693016930269303693046930569306693076930869309693106931169312693136931469315693166931769318693196932069321693226932369324693256932669327693286932969330693316933269333693346933569336693376933869339693406934169342693436934469345693466934769348693496935069351693526935369354693556935669357693586935969360693616936269363693646936569366693676936869369693706937169372693736937469375693766937769378693796938069381693826938369384693856938669387693886938969390693916939269393693946939569396693976939869399694006940169402694036940469405694066940769408694096941069411694126941369414694156941669417694186941969420694216942269423694246942569426694276942869429694306943169432694336943469435694366943769438694396944069441694426944369444694456944669447694486944969450694516945269453694546945569456694576945869459694606946169462694636946469465694666946769468694696947069471694726947369474694756947669477694786947969480694816948269483694846948569486694876948869489694906949169492694936949469495694966949769498694996950069501695026950369504695056950669507695086950969510695116951269513695146951569516695176951869519695206952169522695236952469525695266952769528695296953069531695326953369534695356953669537695386953969540695416954269543695446954569546695476954869549695506955169552695536955469555695566955769558695596956069561695626956369564695656956669567695686956969570695716957269573695746957569576695776957869579695806958169582695836958469585695866958769588695896959069591695926959369594695956959669597695986959969600696016960269603696046960569606696076960869609696106961169612696136961469615696166961769618696196962069621696226962369624696256962669627696286962969630696316963269633696346963569636696376963869639696406964169642696436964469645696466964769648696496965069651696526965369654696556965669657696586965969660696616966269663696646966569666696676966869669696706967169672696736967469675696766967769678696796968069681696826968369684696856968669687696886968969690696916969269693696946969569696696976969869699697006970169702697036970469705697066970769708697096971069711697126971369714697156971669717697186971969720697216972269723697246972569726697276972869729697306973169732697336973469735697366973769738697396974069741697426974369744697456974669747697486974969750697516975269753697546975569756697576975869759697606976169762697636976469765697666976769768697696977069771697726977369774697756977669777697786977969780697816978269783697846978569786697876978869789697906979169792697936979469795697966979769798697996980069801698026980369804698056980669807698086980969810698116981269813698146981569816698176981869819698206982169822698236982469825698266982769828698296983069831698326983369834698356983669837698386983969840698416984269843698446984569846698476984869849698506985169852698536985469855698566985769858698596986069861698626986369864698656986669867698686986969870698716987269873698746987569876698776987869879698806988169882698836988469885698866988769888698896989069891698926989369894698956989669897698986989969900699016990269903699046990569906699076990869909699106991169912699136991469915699166991769918699196992069921699226992369924699256992669927699286992969930699316993269933699346993569936699376993869939699406994169942699436994469945699466994769948699496995069951699526995369954699556995669957699586995969960699616996269963699646996569966699676996869969699706997169972699736997469975699766997769978699796998069981699826998369984699856998669987699886998969990699916999269993699946999569996699976999869999700007000170002700037000470005700067000770008700097001070011700127001370014700157001670017700187001970020700217002270023700247002570026700277002870029700307003170032700337003470035700367003770038700397004070041700427004370044700457004670047700487004970050700517005270053700547005570056700577005870059700607006170062700637006470065700667006770068700697007070071700727007370074700757007670077700787007970080700817008270083700847008570086700877008870089700907009170092700937009470095700967009770098700997010070101701027010370104701057010670107701087010970110701117011270113701147011570116701177011870119701207012170122701237012470125701267012770128701297013070131701327013370134701357013670137701387013970140701417014270143701447014570146701477014870149701507015170152701537015470155701567015770158701597016070161701627016370164701657016670167701687016970170701717017270173701747017570176701777017870179701807018170182701837018470185701867018770188701897019070191701927019370194701957019670197701987019970200702017020270203702047020570206702077020870209702107021170212702137021470215702167021770218702197022070221702227022370224702257022670227702287022970230702317023270233702347023570236702377023870239702407024170242702437024470245702467024770248702497025070251702527025370254702557025670257702587025970260702617026270263702647026570266702677026870269702707027170272702737027470275702767027770278702797028070281702827028370284702857028670287702887028970290702917029270293702947029570296702977029870299703007030170302703037030470305703067030770308703097031070311703127031370314703157031670317703187031970320703217032270323703247032570326703277032870329703307033170332703337033470335703367033770338703397034070341703427034370344703457034670347703487034970350703517035270353703547035570356703577035870359703607036170362703637036470365703667036770368703697037070371703727037370374703757037670377703787037970380703817038270383703847038570386703877038870389703907039170392703937039470395703967039770398703997040070401704027040370404704057040670407704087040970410704117041270413704147041570416704177041870419704207042170422704237042470425704267042770428704297043070431704327043370434704357043670437704387043970440704417044270443704447044570446704477044870449704507045170452704537045470455704567045770458704597046070461704627046370464704657046670467704687046970470704717047270473704747047570476704777047870479704807048170482704837048470485704867048770488704897049070491704927049370494704957049670497704987049970500705017050270503705047050570506705077050870509705107051170512705137051470515705167051770518705197052070521705227052370524705257052670527705287052970530705317053270533705347053570536705377053870539705407054170542705437054470545705467054770548705497055070551705527055370554705557055670557705587055970560705617056270563705647056570566705677056870569705707057170572705737057470575705767057770578705797058070581705827058370584705857058670587705887058970590705917059270593705947059570596705977059870599706007060170602706037060470605706067060770608706097061070611706127061370614706157061670617706187061970620706217062270623706247062570626706277062870629706307063170632706337063470635706367063770638706397064070641706427064370644706457064670647706487064970650706517065270653706547065570656706577065870659706607066170662706637066470665706667066770668706697067070671706727067370674706757067670677706787067970680706817068270683706847068570686706877068870689706907069170692706937069470695706967069770698706997070070701707027070370704707057070670707707087070970710707117071270713707147071570716707177071870719707207072170722707237072470725707267072770728707297073070731707327073370734707357073670737707387073970740707417074270743707447074570746707477074870749707507075170752707537075470755707567075770758707597076070761707627076370764707657076670767707687076970770707717077270773707747077570776707777077870779707807078170782707837078470785707867078770788707897079070791707927079370794707957079670797707987079970800708017080270803708047080570806708077080870809708107081170812708137081470815708167081770818708197082070821708227082370824708257082670827708287082970830708317083270833708347083570836708377083870839708407084170842708437084470845708467084770848708497085070851708527085370854708557085670857708587085970860708617086270863708647086570866708677086870869708707087170872708737087470875708767087770878708797088070881708827088370884708857088670887708887088970890708917089270893708947089570896708977089870899709007090170902709037090470905709067090770908709097091070911709127091370914709157091670917709187091970920709217092270923709247092570926709277092870929709307093170932709337093470935709367093770938709397094070941709427094370944709457094670947709487094970950709517095270953709547095570956709577095870959709607096170962709637096470965709667096770968709697097070971709727097370974709757097670977709787097970980709817098270983709847098570986709877098870989709907099170992709937099470995709967099770998709997100071001710027100371004710057100671007710087100971010710117101271013710147101571016710177101871019710207102171022710237102471025710267102771028710297103071031710327103371034710357103671037710387103971040710417104271043710447104571046710477104871049710507105171052710537105471055710567105771058710597106071061710627106371064710657106671067710687106971070710717107271073710747107571076710777107871079710807108171082710837108471085710867108771088710897109071091710927109371094710957109671097710987109971100711017110271103711047110571106711077110871109711107111171112711137111471115711167111771118711197112071121711227112371124711257112671127711287112971130711317113271133711347113571136711377113871139711407114171142711437114471145711467114771148711497115071151711527115371154711557115671157711587115971160711617116271163711647116571166711677116871169711707117171172711737117471175711767117771178711797118071181711827118371184711857118671187711887118971190711917119271193711947119571196711977119871199712007120171202712037120471205712067120771208712097121071211712127121371214712157121671217712187121971220712217122271223712247122571226712277122871229712307123171232712337123471235712367123771238712397124071241712427124371244712457124671247712487124971250712517125271253712547125571256712577125871259712607126171262712637126471265712667126771268712697127071271712727127371274712757127671277712787127971280712817128271283712847128571286712877128871289712907129171292712937129471295712967129771298712997130071301713027130371304713057130671307713087130971310713117131271313713147131571316713177131871319713207132171322713237132471325713267132771328713297133071331713327133371334713357133671337713387133971340713417134271343713447134571346713477134871349713507135171352713537135471355713567135771358713597136071361713627136371364713657136671367713687136971370713717137271373713747137571376713777137871379713807138171382713837138471385713867138771388713897139071391713927139371394713957139671397713987139971400714017140271403714047140571406714077140871409714107141171412714137141471415714167141771418714197142071421714227142371424714257142671427714287142971430714317143271433714347143571436714377143871439714407144171442714437144471445714467144771448714497145071451714527145371454714557145671457714587145971460714617146271463714647146571466714677146871469714707147171472714737147471475714767147771478714797148071481714827148371484714857148671487714887148971490714917149271493714947149571496714977149871499715007150171502715037150471505715067150771508715097151071511715127151371514715157151671517715187151971520715217152271523715247152571526715277152871529715307153171532715337153471535715367153771538715397154071541715427154371544715457154671547715487154971550715517155271553715547155571556715577155871559715607156171562715637156471565715667156771568715697157071571715727157371574715757157671577715787157971580715817158271583715847158571586715877158871589715907159171592715937159471595715967159771598715997160071601716027160371604716057160671607716087160971610716117161271613716147161571616716177161871619716207162171622716237162471625716267162771628716297163071631716327163371634716357163671637716387163971640716417164271643716447164571646716477164871649716507165171652716537165471655716567165771658716597166071661716627166371664716657166671667716687166971670716717167271673716747167571676716777167871679716807168171682716837168471685716867168771688716897169071691716927169371694716957169671697716987169971700717017170271703717047170571706717077170871709717107171171712717137171471715717167171771718717197172071721717227172371724717257172671727717287172971730717317173271733717347173571736717377173871739717407174171742717437174471745717467174771748717497175071751717527175371754717557175671757717587175971760717617176271763717647176571766717677176871769717707177171772717737177471775717767177771778717797178071781717827178371784717857178671787717887178971790717917179271793717947179571796717977179871799718007180171802718037180471805718067180771808718097181071811718127181371814718157181671817718187181971820718217182271823718247182571826718277182871829718307183171832718337183471835718367183771838718397184071841718427184371844718457184671847718487184971850718517185271853718547185571856718577185871859718607186171862718637186471865718667186771868718697187071871718727187371874718757187671877718787187971880718817188271883718847188571886718877188871889718907189171892718937189471895718967189771898718997190071901719027190371904719057190671907719087190971910719117191271913719147191571916719177191871919719207192171922719237192471925719267192771928719297193071931719327193371934719357193671937719387193971940719417194271943719447194571946719477194871949719507195171952719537195471955719567195771958719597196071961719627196371964719657196671967719687196971970719717197271973719747197571976719777197871979719807198171982719837198471985719867198771988719897199071991719927199371994719957199671997719987199972000720017200272003720047200572006720077200872009720107201172012720137201472015720167201772018720197202072021720227202372024720257202672027720287202972030720317203272033720347203572036720377203872039720407204172042720437204472045720467204772048720497205072051720527205372054720557205672057720587205972060720617206272063720647206572066720677206872069720707207172072720737207472075720767207772078720797208072081720827208372084720857208672087720887208972090720917209272093720947209572096720977209872099721007210172102721037210472105721067210772108721097211072111721127211372114721157211672117721187211972120721217212272123721247212572126721277212872129721307213172132721337213472135721367213772138721397214072141721427214372144721457214672147721487214972150721517215272153721547215572156721577215872159721607216172162721637216472165721667216772168721697217072171721727217372174721757217672177721787217972180721817218272183721847218572186721877218872189721907219172192721937219472195721967219772198721997220072201722027220372204722057220672207722087220972210722117221272213722147221572216722177221872219722207222172222722237222472225722267222772228722297223072231722327223372234722357223672237722387223972240722417224272243722447224572246722477224872249722507225172252722537225472255722567225772258722597226072261722627226372264722657226672267722687226972270722717227272273722747227572276722777227872279722807228172282722837228472285722867228772288722897229072291722927229372294722957229672297722987229972300723017230272303723047230572306723077230872309723107231172312723137231472315723167231772318723197232072321723227232372324723257232672327723287232972330723317233272333723347233572336723377233872339723407234172342723437234472345723467234772348723497235072351723527235372354723557235672357723587235972360723617236272363723647236572366723677236872369723707237172372723737237472375723767237772378723797238072381723827238372384723857238672387723887238972390723917239272393723947239572396723977239872399724007240172402724037240472405724067240772408724097241072411724127241372414724157241672417724187241972420724217242272423724247242572426724277242872429724307243172432724337243472435724367243772438724397244072441724427244372444724457244672447724487244972450724517245272453724547245572456724577245872459724607246172462724637246472465724667246772468724697247072471724727247372474724757247672477724787247972480724817248272483724847248572486724877248872489724907249172492724937249472495724967249772498724997250072501725027250372504725057250672507725087250972510725117251272513725147251572516725177251872519725207252172522725237252472525725267252772528725297253072531725327253372534725357253672537725387253972540725417254272543725447254572546725477254872549725507255172552725537255472555725567255772558725597256072561725627256372564725657256672567725687256972570725717257272573725747257572576725777257872579725807258172582725837258472585725867258772588725897259072591725927259372594725957259672597725987259972600726017260272603726047260572606726077260872609726107261172612726137261472615726167261772618726197262072621726227262372624726257262672627726287262972630726317263272633726347263572636726377263872639726407264172642726437264472645726467264772648726497265072651726527265372654726557265672657726587265972660726617266272663726647266572666726677266872669726707267172672726737267472675726767267772678726797268072681726827268372684726857268672687726887268972690726917269272693726947269572696726977269872699727007270172702727037270472705727067270772708727097271072711727127271372714727157271672717727187271972720727217272272723727247272572726727277272872729727307273172732727337273472735727367273772738727397274072741727427274372744727457274672747727487274972750727517275272753727547275572756727577275872759727607276172762727637276472765727667276772768727697277072771727727277372774727757277672777727787277972780727817278272783727847278572786727877278872789727907279172792727937279472795727967279772798727997280072801728027280372804728057280672807728087280972810728117281272813728147281572816728177281872819728207282172822728237282472825728267282772828728297283072831728327283372834728357283672837728387283972840728417284272843728447284572846728477284872849728507285172852728537285472855728567285772858728597286072861728627286372864728657286672867728687286972870728717287272873728747287572876728777287872879728807288172882728837288472885728867288772888728897289072891728927289372894728957289672897728987289972900729017290272903729047290572906729077290872909729107291172912729137291472915729167291772918729197292072921729227292372924729257292672927729287292972930729317293272933729347293572936729377293872939729407294172942729437294472945729467294772948729497295072951729527295372954729557295672957729587295972960729617296272963729647296572966729677296872969729707297172972729737297472975729767297772978729797298072981729827298372984729857298672987729887298972990729917299272993729947299572996729977299872999730007300173002730037300473005730067300773008730097301073011730127301373014730157301673017730187301973020730217302273023730247302573026730277302873029730307303173032730337303473035730367303773038730397304073041730427304373044730457304673047730487304973050730517305273053730547305573056730577305873059730607306173062730637306473065730667306773068730697307073071730727307373074730757307673077730787307973080730817308273083730847308573086730877308873089730907309173092730937309473095730967309773098730997310073101731027310373104731057310673107731087310973110731117311273113731147311573116731177311873119731207312173122731237312473125731267312773128731297313073131731327313373134731357313673137731387313973140731417314273143731447314573146731477314873149731507315173152731537315473155731567315773158731597316073161731627316373164731657316673167731687316973170731717317273173731747317573176731777317873179731807318173182731837318473185731867318773188731897319073191731927319373194731957319673197731987319973200732017320273203732047320573206732077320873209732107321173212732137321473215732167321773218732197322073221732227322373224732257322673227732287322973230732317323273233732347323573236732377323873239732407324173242732437324473245732467324773248732497325073251732527325373254732557325673257732587325973260732617326273263732647326573266732677326873269732707327173272732737327473275732767327773278732797328073281732827328373284732857328673287732887328973290732917329273293732947329573296732977329873299733007330173302733037330473305733067330773308733097331073311733127331373314733157331673317733187331973320733217332273323733247332573326733277332873329733307333173332733337333473335733367333773338733397334073341733427334373344733457334673347733487334973350733517335273353733547335573356733577335873359733607336173362733637336473365733667336773368733697337073371733727337373374733757337673377733787337973380733817338273383733847338573386733877338873389733907339173392733937339473395733967339773398733997340073401734027340373404734057340673407734087340973410734117341273413734147341573416734177341873419734207342173422734237342473425734267342773428734297343073431734327343373434734357343673437734387343973440734417344273443734447344573446734477344873449734507345173452734537345473455734567345773458734597346073461734627346373464734657346673467734687346973470734717347273473734747347573476734777347873479734807348173482734837348473485734867348773488734897349073491734927349373494734957349673497734987349973500735017350273503735047350573506735077350873509735107351173512735137351473515735167351773518735197352073521735227352373524735257352673527735287352973530735317353273533735347353573536735377353873539735407354173542735437354473545735467354773548735497355073551735527355373554735557355673557735587355973560735617356273563735647356573566735677356873569735707357173572735737357473575735767357773578735797358073581735827358373584735857358673587735887358973590735917359273593735947359573596735977359873599736007360173602736037360473605736067360773608736097361073611736127361373614736157361673617736187361973620736217362273623736247362573626736277362873629736307363173632736337363473635736367363773638736397364073641736427364373644736457364673647736487364973650736517365273653736547365573656736577365873659736607366173662736637366473665736667366773668736697367073671736727367373674736757367673677736787367973680736817368273683736847368573686736877368873689736907369173692736937369473695736967369773698736997370073701737027370373704737057370673707737087370973710737117371273713737147371573716737177371873719737207372173722737237372473725737267372773728737297373073731737327373373734737357373673737737387373973740737417374273743737447374573746737477374873749737507375173752737537375473755737567375773758737597376073761737627376373764737657376673767737687376973770737717377273773737747377573776737777377873779737807378173782737837378473785737867378773788737897379073791737927379373794737957379673797737987379973800738017380273803738047380573806738077380873809738107381173812738137381473815738167381773818738197382073821738227382373824738257382673827738287382973830738317383273833738347383573836738377383873839738407384173842738437384473845738467384773848738497385073851738527385373854738557385673857738587385973860738617386273863738647386573866738677386873869738707387173872738737387473875738767387773878738797388073881738827388373884738857388673887738887388973890738917389273893738947389573896738977389873899739007390173902739037390473905739067390773908739097391073911739127391373914739157391673917739187391973920739217392273923739247392573926739277392873929739307393173932739337393473935739367393773938739397394073941739427394373944739457394673947739487394973950739517395273953739547395573956739577395873959739607396173962739637396473965739667396773968739697397073971739727397373974739757397673977739787397973980739817398273983739847398573986739877398873989739907399173992739937399473995739967399773998739997400074001740027400374004740057400674007740087400974010740117401274013740147401574016740177401874019740207402174022740237402474025740267402774028740297403074031740327403374034740357403674037740387403974040740417404274043740447404574046740477404874049740507405174052740537405474055740567405774058740597406074061740627406374064740657406674067740687406974070740717407274073740747407574076740777407874079740807408174082740837408474085740867408774088740897409074091740927409374094740957409674097740987409974100741017410274103741047410574106741077410874109741107411174112741137411474115741167411774118741197412074121741227412374124741257412674127741287412974130741317413274133741347413574136741377413874139741407414174142741437414474145741467414774148741497415074151741527415374154741557415674157741587415974160741617416274163741647416574166741677416874169741707417174172741737417474175741767417774178741797418074181741827418374184741857418674187741887418974190741917419274193741947419574196741977419874199742007420174202742037420474205742067420774208742097421074211742127421374214742157421674217742187421974220742217422274223742247422574226742277422874229742307423174232742337423474235742367423774238742397424074241742427424374244742457424674247742487424974250742517425274253742547425574256742577425874259742607426174262742637426474265742667426774268742697427074271742727427374274742757427674277742787427974280742817428274283742847428574286742877428874289742907429174292742937429474295742967429774298742997430074301743027430374304743057430674307743087430974310743117431274313743147431574316743177431874319743207432174322743237432474325743267432774328743297433074331743327433374334743357433674337743387433974340743417434274343743447434574346743477434874349743507435174352743537435474355743567435774358743597436074361743627436374364743657436674367743687436974370743717437274373743747437574376743777437874379743807438174382743837438474385743867438774388743897439074391743927439374394743957439674397743987439974400744017440274403744047440574406744077440874409744107441174412744137441474415744167441774418744197442074421744227442374424744257442674427744287442974430744317443274433744347443574436744377443874439744407444174442744437444474445744467444774448744497445074451744527445374454744557445674457744587445974460744617446274463744647446574466744677446874469744707447174472744737447474475744767447774478744797448074481744827448374484744857448674487744887448974490744917449274493744947449574496744977449874499745007450174502745037450474505745067450774508745097451074511745127451374514745157451674517745187451974520745217452274523745247452574526745277452874529745307453174532745337453474535745367453774538745397454074541745427454374544745457454674547745487454974550745517455274553745547455574556745577455874559745607456174562745637456474565745667456774568745697457074571745727457374574745757457674577745787457974580745817458274583745847458574586745877458874589745907459174592745937459474595745967459774598745997460074601746027460374604746057460674607746087460974610746117461274613746147461574616746177461874619746207462174622746237462474625746267462774628746297463074631746327463374634746357463674637746387463974640746417464274643746447464574646746477464874649746507465174652746537465474655746567465774658746597466074661746627466374664746657466674667746687466974670746717467274673746747467574676746777467874679746807468174682746837468474685746867468774688746897469074691746927469374694746957469674697746987469974700747017470274703747047470574706747077470874709747107471174712747137471474715747167471774718747197472074721747227472374724747257472674727747287472974730747317473274733747347473574736747377473874739747407474174742747437474474745747467474774748747497475074751747527475374754747557475674757747587475974760747617476274763747647476574766747677476874769747707477174772747737477474775747767477774778747797478074781747827478374784747857478674787747887478974790747917479274793747947479574796747977479874799748007480174802748037480474805748067480774808748097481074811748127481374814748157481674817748187481974820748217482274823748247482574826748277482874829748307483174832748337483474835748367483774838748397484074841748427484374844748457484674847748487484974850748517485274853748547485574856748577485874859748607486174862748637486474865748667486774868748697487074871748727487374874748757487674877748787487974880748817488274883748847488574886748877488874889748907489174892748937489474895748967489774898748997490074901749027490374904749057490674907749087490974910749117491274913749147491574916749177491874919749207492174922749237492474925749267492774928749297493074931749327493374934749357493674937749387493974940749417494274943749447494574946749477494874949749507495174952749537495474955749567495774958749597496074961749627496374964749657496674967749687496974970749717497274973749747497574976749777497874979749807498174982749837498474985749867498774988749897499074991749927499374994749957499674997749987499975000750017500275003750047500575006750077500875009750107501175012750137501475015750167501775018750197502075021750227502375024750257502675027750287502975030750317503275033750347503575036750377503875039750407504175042750437504475045750467504775048750497505075051750527505375054750557505675057750587505975060750617506275063750647506575066750677506875069750707507175072750737507475075750767507775078750797508075081750827508375084750857508675087750887508975090750917509275093750947509575096750977509875099751007510175102751037510475105751067510775108751097511075111751127511375114751157511675117751187511975120751217512275123751247512575126751277512875129751307513175132751337513475135751367513775138751397514075141751427514375144751457514675147751487514975150751517515275153751547515575156751577515875159751607516175162751637516475165751667516775168751697517075171751727517375174751757517675177751787517975180751817518275183751847518575186751877518875189751907519175192751937519475195751967519775198751997520075201752027520375204752057520675207752087520975210752117521275213752147521575216752177521875219752207522175222752237522475225752267522775228752297523075231752327523375234752357523675237752387523975240752417524275243752447524575246752477524875249752507525175252752537525475255752567525775258752597526075261752627526375264752657526675267752687526975270752717527275273752747527575276752777527875279752807528175282752837528475285752867528775288752897529075291752927529375294752957529675297752987529975300753017530275303753047530575306753077530875309753107531175312753137531475315753167531775318753197532075321753227532375324753257532675327753287532975330753317533275333753347533575336753377533875339753407534175342753437534475345753467534775348753497535075351753527535375354753557535675357753587535975360753617536275363753647536575366753677536875369753707537175372753737537475375753767537775378753797538075381753827538375384753857538675387753887538975390753917539275393753947539575396753977539875399754007540175402754037540475405754067540775408754097541075411754127541375414754157541675417754187541975420754217542275423754247542575426754277542875429754307543175432754337543475435754367543775438754397544075441754427544375444754457544675447754487544975450754517545275453754547545575456754577545875459754607546175462754637546475465754667546775468754697547075471754727547375474754757547675477754787547975480754817548275483754847548575486754877548875489754907549175492754937549475495754967549775498754997550075501755027550375504755057550675507755087550975510755117551275513755147551575516755177551875519755207552175522755237552475525755267552775528755297553075531755327553375534755357553675537755387553975540755417554275543755447554575546755477554875549755507555175552755537555475555755567555775558755597556075561755627556375564755657556675567755687556975570755717557275573755747557575576755777557875579755807558175582755837558475585755867558775588755897559075591755927559375594755957559675597755987559975600756017560275603756047560575606756077560875609756107561175612756137561475615756167561775618756197562075621756227562375624756257562675627756287562975630756317563275633756347563575636756377563875639756407564175642756437564475645756467564775648756497565075651756527565375654756557565675657756587565975660756617566275663756647566575666756677566875669756707567175672756737567475675756767567775678756797568075681756827568375684756857568675687756887568975690756917569275693756947569575696756977569875699757007570175702757037570475705757067570775708757097571075711757127571375714757157571675717757187571975720757217572275723757247572575726757277572875729757307573175732757337573475735757367573775738757397574075741757427574375744757457574675747757487574975750757517575275753757547575575756757577575875759757607576175762757637576475765757667576775768757697577075771757727577375774757757577675777757787577975780757817578275783757847578575786757877578875789757907579175792757937579475795757967579775798757997580075801758027580375804758057580675807758087580975810758117581275813758147581575816758177581875819758207582175822758237582475825758267582775828758297583075831758327583375834758357583675837758387583975840758417584275843758447584575846758477584875849758507585175852758537585475855758567585775858758597586075861758627586375864758657586675867758687586975870758717587275873758747587575876758777587875879758807588175882758837588475885758867588775888758897589075891758927589375894758957589675897758987589975900759017590275903759047590575906759077590875909759107591175912759137591475915759167591775918759197592075921759227592375924759257592675927759287592975930759317593275933759347593575936759377593875939759407594175942759437594475945759467594775948759497595075951759527595375954759557595675957759587595975960759617596275963759647596575966759677596875969759707597175972759737597475975759767597775978759797598075981759827598375984759857598675987759887598975990759917599275993759947599575996759977599875999760007600176002760037600476005760067600776008760097601076011760127601376014760157601676017760187601976020760217602276023760247602576026760277602876029760307603176032760337603476035760367603776038760397604076041760427604376044760457604676047760487604976050760517605276053760547605576056760577605876059760607606176062760637606476065760667606776068760697607076071760727607376074760757607676077760787607976080760817608276083760847608576086760877608876089760907609176092760937609476095760967609776098760997610076101761027610376104761057610676107761087610976110761117611276113761147611576116761177611876119761207612176122761237612476125761267612776128761297613076131761327613376134761357613676137761387613976140761417614276143761447614576146761477614876149761507615176152761537615476155761567615776158761597616076161761627616376164761657616676167761687616976170761717617276173761747617576176761777617876179761807618176182761837618476185761867618776188761897619076191761927619376194761957619676197761987619976200762017620276203762047620576206762077620876209762107621176212762137621476215762167621776218762197622076221762227622376224762257622676227762287622976230762317623276233762347623576236762377623876239762407624176242762437624476245762467624776248762497625076251762527625376254762557625676257762587625976260762617626276263762647626576266762677626876269762707627176272762737627476275762767627776278762797628076281762827628376284762857628676287762887628976290762917629276293762947629576296762977629876299763007630176302763037630476305763067630776308763097631076311763127631376314763157631676317763187631976320763217632276323763247632576326763277632876329763307633176332763337633476335763367633776338763397634076341763427634376344763457634676347763487634976350763517635276353763547635576356763577635876359763607636176362763637636476365763667636776368763697637076371763727637376374763757637676377763787637976380763817638276383763847638576386763877638876389763907639176392763937639476395763967639776398763997640076401764027640376404764057640676407764087640976410764117641276413764147641576416764177641876419764207642176422764237642476425764267642776428764297643076431764327643376434764357643676437764387643976440764417644276443764447644576446764477644876449764507645176452764537645476455764567645776458764597646076461764627646376464764657646676467764687646976470764717647276473764747647576476764777647876479764807648176482764837648476485764867648776488764897649076491764927649376494764957649676497764987649976500765017650276503765047650576506765077650876509765107651176512765137651476515765167651776518765197652076521765227652376524765257652676527765287652976530765317653276533765347653576536765377653876539765407654176542765437654476545765467654776548765497655076551765527655376554765557655676557765587655976560765617656276563765647656576566765677656876569765707657176572765737657476575765767657776578765797658076581765827658376584765857658676587765887658976590765917659276593765947659576596765977659876599766007660176602766037660476605766067660776608766097661076611766127661376614766157661676617766187661976620766217662276623766247662576626766277662876629766307663176632766337663476635766367663776638766397664076641766427664376644766457664676647766487664976650766517665276653766547665576656766577665876659766607666176662766637666476665766667666776668766697667076671766727667376674766757667676677766787667976680766817668276683766847668576686766877668876689766907669176692766937669476695766967669776698766997670076701767027670376704767057670676707767087670976710767117671276713767147671576716767177671876719767207672176722767237672476725767267672776728767297673076731767327673376734767357673676737767387673976740767417674276743767447674576746767477674876749767507675176752767537675476755767567675776758767597676076761767627676376764767657676676767767687676976770767717677276773767747677576776767777677876779767807678176782767837678476785767867678776788767897679076791767927679376794767957679676797767987679976800768017680276803768047680576806768077680876809768107681176812768137681476815768167681776818768197682076821768227682376824768257682676827768287682976830768317683276833768347683576836768377683876839768407684176842768437684476845768467684776848768497685076851768527685376854768557685676857768587685976860768617686276863768647686576866768677686876869768707687176872768737687476875768767687776878768797688076881768827688376884768857688676887768887688976890768917689276893768947689576896768977689876899769007690176902769037690476905769067690776908769097691076911769127691376914769157691676917769187691976920769217692276923769247692576926769277692876929769307693176932769337693476935769367693776938769397694076941769427694376944769457694676947769487694976950769517695276953769547695576956769577695876959769607696176962769637696476965769667696776968769697697076971769727697376974769757697676977769787697976980769817698276983769847698576986769877698876989769907699176992769937699476995769967699776998769997700077001770027700377004770057700677007770087700977010770117701277013770147701577016770177701877019770207702177022770237702477025770267702777028770297703077031770327703377034770357703677037770387703977040770417704277043770447704577046770477704877049770507705177052770537705477055770567705777058770597706077061770627706377064770657706677067770687706977070770717707277073770747707577076770777707877079770807708177082770837708477085770867708777088770897709077091770927709377094770957709677097770987709977100771017710277103771047710577106771077710877109771107711177112771137711477115771167711777118771197712077121771227712377124771257712677127771287712977130771317713277133771347713577136771377713877139771407714177142771437714477145771467714777148771497715077151771527715377154771557715677157771587715977160771617716277163771647716577166771677716877169771707717177172771737717477175771767717777178771797718077181771827718377184771857718677187771887718977190771917719277193771947719577196771977719877199772007720177202772037720477205772067720777208772097721077211772127721377214772157721677217772187721977220772217722277223772247722577226772277722877229772307723177232772337723477235772367723777238772397724077241772427724377244772457724677247772487724977250772517725277253772547725577256772577725877259772607726177262772637726477265772667726777268772697727077271772727727377274772757727677277772787727977280772817728277283772847728577286772877728877289772907729177292772937729477295772967729777298772997730077301773027730377304773057730677307773087730977310773117731277313773147731577316773177731877319773207732177322773237732477325773267732777328773297733077331773327733377334773357733677337773387733977340773417734277343773447734577346773477734877349773507735177352773537735477355773567735777358773597736077361773627736377364773657736677367773687736977370773717737277373773747737577376773777737877379773807738177382773837738477385773867738777388773897739077391773927739377394773957739677397773987739977400774017740277403774047740577406774077740877409774107741177412774137741477415774167741777418774197742077421774227742377424774257742677427774287742977430774317743277433774347743577436774377743877439774407744177442774437744477445774467744777448774497745077451774527745377454774557745677457774587745977460774617746277463774647746577466774677746877469774707747177472774737747477475774767747777478774797748077481774827748377484774857748677487774887748977490774917749277493774947749577496774977749877499775007750177502775037750477505775067750777508775097751077511775127751377514775157751677517775187751977520775217752277523775247752577526775277752877529775307753177532775337753477535775367753777538775397754077541775427754377544775457754677547775487754977550775517755277553775547755577556775577755877559775607756177562775637756477565775667756777568775697757077571775727757377574775757757677577775787757977580775817758277583775847758577586775877758877589775907759177592775937759477595775967759777598775997760077601776027760377604776057760677607776087760977610776117761277613776147761577616776177761877619776207762177622776237762477625776267762777628776297763077631776327763377634776357763677637776387763977640776417764277643776447764577646776477764877649776507765177652776537765477655776567765777658776597766077661776627766377664776657766677667776687766977670776717767277673776747767577676776777767877679776807768177682776837768477685776867768777688776897769077691776927769377694776957769677697776987769977700777017770277703777047770577706777077770877709777107771177712777137771477715777167771777718777197772077721777227772377724777257772677727777287772977730777317773277733777347773577736777377773877739777407774177742777437774477745777467774777748777497775077751777527775377754777557775677757777587775977760777617776277763777647776577766777677776877769777707777177772777737777477775777767777777778777797778077781777827778377784777857778677787777887778977790777917779277793777947779577796777977779877799778007780177802778037780477805778067780777808778097781077811778127781377814778157781677817778187781977820778217782277823778247782577826778277782877829778307783177832778337783477835778367783777838778397784077841778427784377844778457784677847778487784977850778517785277853778547785577856778577785877859778607786177862778637786477865778667786777868778697787077871778727787377874778757787677877778787787977880778817788277883778847788577886778877788877889778907789177892778937789477895778967789777898778997790077901779027790377904779057790677907779087790977910779117791277913779147791577916779177791877919779207792177922779237792477925779267792777928779297793077931779327793377934779357793677937779387793977940779417794277943779447794577946779477794877949779507795177952779537795477955779567795777958779597796077961779627796377964779657796677967779687796977970779717797277973779747797577976779777797877979779807798177982779837798477985779867798777988779897799077991779927799377994779957799677997779987799978000780017800278003780047800578006780077800878009780107801178012780137801478015780167801778018780197802078021780227802378024780257802678027780287802978030780317803278033780347803578036780377803878039780407804178042780437804478045780467804778048780497805078051780527805378054780557805678057780587805978060780617806278063780647806578066780677806878069780707807178072780737807478075780767807778078780797808078081780827808378084780857808678087780887808978090780917809278093780947809578096780977809878099781007810178102781037810478105781067810778108781097811078111781127811378114781157811678117781187811978120781217812278123781247812578126781277812878129781307813178132781337813478135781367813778138781397814078141781427814378144781457814678147781487814978150781517815278153781547815578156781577815878159781607816178162781637816478165781667816778168781697817078171781727817378174781757817678177781787817978180781817818278183781847818578186781877818878189781907819178192781937819478195781967819778198781997820078201782027820378204782057820678207782087820978210782117821278213782147821578216782177821878219782207822178222782237822478225782267822778228782297823078231782327823378234782357823678237782387823978240782417824278243782447824578246782477824878249782507825178252782537825478255782567825778258782597826078261782627826378264782657826678267782687826978270782717827278273782747827578276782777827878279782807828178282782837828478285782867828778288782897829078291782927829378294782957829678297782987829978300783017830278303783047830578306783077830878309783107831178312783137831478315783167831778318783197832078321783227832378324783257832678327783287832978330783317833278333783347833578336783377833878339783407834178342783437834478345783467834778348783497835078351783527835378354783557835678357783587835978360783617836278363783647836578366783677836878369783707837178372783737837478375783767837778378783797838078381783827838378384783857838678387783887838978390783917839278393783947839578396783977839878399784007840178402784037840478405784067840778408784097841078411784127841378414784157841678417784187841978420784217842278423784247842578426784277842878429784307843178432784337843478435784367843778438784397844078441784427844378444784457844678447784487844978450784517845278453784547845578456784577845878459784607846178462784637846478465784667846778468784697847078471784727847378474784757847678477784787847978480784817848278483784847848578486784877848878489784907849178492784937849478495784967849778498784997850078501785027850378504785057850678507785087850978510785117851278513785147851578516785177851878519785207852178522785237852478525785267852778528785297853078531785327853378534785357853678537785387853978540785417854278543785447854578546785477854878549785507855178552785537855478555785567855778558785597856078561785627856378564785657856678567785687856978570785717857278573785747857578576785777857878579785807858178582785837858478585785867858778588785897859078591785927859378594785957859678597785987859978600786017860278603786047860578606786077860878609786107861178612786137861478615786167861778618786197862078621786227862378624786257862678627786287862978630786317863278633786347863578636786377863878639786407864178642786437864478645786467864778648786497865078651786527865378654786557865678657786587865978660786617866278663786647866578666786677866878669786707867178672786737867478675786767867778678786797868078681786827868378684786857868678687786887868978690786917869278693786947869578696786977869878699787007870178702787037870478705787067870778708787097871078711787127871378714787157871678717787187871978720787217872278723787247872578726787277872878729787307873178732787337873478735787367873778738787397874078741787427874378744787457874678747787487874978750787517875278753787547875578756787577875878759787607876178762787637876478765787667876778768787697877078771787727877378774787757877678777787787877978780787817878278783787847878578786787877878878789787907879178792787937879478795787967879778798787997880078801788027880378804788057880678807788087880978810788117881278813788147881578816788177881878819788207882178822788237882478825788267882778828788297883078831788327883378834788357883678837788387883978840788417884278843788447884578846788477884878849788507885178852788537885478855788567885778858788597886078861788627886378864788657886678867788687886978870788717887278873788747887578876788777887878879788807888178882788837888478885788867888778888788897889078891788927889378894788957889678897788987889978900789017890278903789047890578906789077890878909789107891178912789137891478915789167891778918789197892078921789227892378924789257892678927789287892978930789317893278933789347893578936789377893878939789407894178942789437894478945789467894778948789497895078951789527895378954789557895678957789587895978960789617896278963789647896578966789677896878969789707897178972789737897478975789767897778978789797898078981789827898378984789857898678987789887898978990789917899278993789947899578996789977899878999790007900179002790037900479005790067900779008790097901079011790127901379014790157901679017790187901979020790217902279023790247902579026790277902879029790307903179032790337903479035790367903779038790397904079041790427904379044790457904679047790487904979050790517905279053790547905579056790577905879059790607906179062790637906479065790667906779068790697907079071790727907379074790757907679077790787907979080790817908279083790847908579086790877908879089790907909179092790937909479095790967909779098790997910079101791027910379104791057910679107791087910979110791117911279113791147911579116791177911879119791207912179122791237912479125791267912779128791297913079131791327913379134791357913679137791387913979140791417914279143791447914579146791477914879149791507915179152791537915479155791567915779158791597916079161791627916379164791657916679167791687916979170791717917279173791747917579176791777917879179791807918179182791837918479185791867918779188791897919079191791927919379194791957919679197791987919979200792017920279203792047920579206792077920879209792107921179212792137921479215792167921779218792197922079221792227922379224792257922679227792287922979230792317923279233792347923579236792377923879239792407924179242792437924479245792467924779248792497925079251792527925379254792557925679257792587925979260792617926279263792647926579266792677926879269792707927179272792737927479275792767927779278792797928079281792827928379284792857928679287792887928979290792917929279293
  1. /**
  2. * plotly.js (cartesian) v1.41.3
  3. * Copyright 2012-2018, Plotly, Inc.
  4. * All rights reserved.
  5. * Licensed under the MIT license
  6. */
  7. (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Plotly = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(_dereq_,module,exports){
  8. 'use strict';
  9. var Lib = _dereq_('../src/lib');
  10. var rules = {
  11. "X,X div": "direction:ltr;font-family:'Open Sans', verdana, arial, sans-serif;margin:0;padding:0;",
  12. "X input,X button": "font-family:'Open Sans', verdana, arial, sans-serif;",
  13. "X input:focus,X button:focus": "outline:none;",
  14. "X a": "text-decoration:none;",
  15. "X a:hover": "text-decoration:none;",
  16. "X .crisp": "shape-rendering:crispEdges;",
  17. "X .user-select-none": "-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;-o-user-select:none;user-select:none;",
  18. "X svg": "overflow:hidden;",
  19. "X svg a": "fill:#447adb;",
  20. "X svg a:hover": "fill:#3c6dc5;",
  21. "X .main-svg": "position:absolute;top:0;left:0;pointer-events:none;",
  22. "X .main-svg .draglayer": "pointer-events:all;",
  23. "X .cursor-default": "cursor:default;",
  24. "X .cursor-pointer": "cursor:pointer;",
  25. "X .cursor-crosshair": "cursor:crosshair;",
  26. "X .cursor-move": "cursor:move;",
  27. "X .cursor-col-resize": "cursor:col-resize;",
  28. "X .cursor-row-resize": "cursor:row-resize;",
  29. "X .cursor-ns-resize": "cursor:ns-resize;",
  30. "X .cursor-ew-resize": "cursor:ew-resize;",
  31. "X .cursor-sw-resize": "cursor:sw-resize;",
  32. "X .cursor-s-resize": "cursor:s-resize;",
  33. "X .cursor-se-resize": "cursor:se-resize;",
  34. "X .cursor-w-resize": "cursor:w-resize;",
  35. "X .cursor-e-resize": "cursor:e-resize;",
  36. "X .cursor-nw-resize": "cursor:nw-resize;",
  37. "X .cursor-n-resize": "cursor:n-resize;",
  38. "X .cursor-ne-resize": "cursor:ne-resize;",
  39. "X .cursor-grab": "cursor:-webkit-grab;cursor:grab;",
  40. "X .modebar": "position:absolute;top:2px;right:2px;z-index:1001;background:rgba(255,255,255,0.7);",
  41. "X .modebar--hover": "opacity:0;-webkit-transition:opacity 0.3s ease 0s;-moz-transition:opacity 0.3s ease 0s;-ms-transition:opacity 0.3s ease 0s;-o-transition:opacity 0.3s ease 0s;transition:opacity 0.3s ease 0s;",
  42. "X:hover .modebar--hover": "opacity:1;",
  43. "X .modebar-group": "float:left;display:inline-block;box-sizing:border-box;margin-left:8px;position:relative;vertical-align:middle;white-space:nowrap;",
  44. "X .modebar-group:first-child": "margin-left:0px;",
  45. "X .modebar-btn": "position:relative;font-size:16px;padding:3px 4px;cursor:pointer;line-height:normal;box-sizing:border-box;",
  46. "X .modebar-btn svg": "position:relative;top:2px;",
  47. "X .modebar-btn path": "fill:rgba(0,31,95,0.3);",
  48. "X .modebar-btn.active path,X .modebar-btn:hover path": "fill:rgba(0,22,72,0.5);",
  49. "X .modebar-btn.modebar-btn--logo": "padding:3px 1px;",
  50. "X .modebar-btn.modebar-btn--logo path": "fill:#447adb !important;",
  51. "X [data-title]:before,X [data-title]:after": "position:absolute;-webkit-transform:translate3d(0, 0, 0);-moz-transform:translate3d(0, 0, 0);-ms-transform:translate3d(0, 0, 0);-o-transform:translate3d(0, 0, 0);transform:translate3d(0, 0, 0);display:none;opacity:0;z-index:1001;pointer-events:none;top:110%;right:50%;",
  52. "X [data-title]:hover:before,X [data-title]:hover:after": "display:block;opacity:1;",
  53. "X [data-title]:before": "content:'';position:absolute;background:transparent;border:6px solid transparent;z-index:1002;margin-top:-12px;border-bottom-color:#69738a;margin-right:-6px;",
  54. "X [data-title]:after": "content:attr(data-title);background:#69738a;color:white;padding:8px 10px;font-size:12px;line-height:12px;white-space:nowrap;margin-right:-18px;border-radius:2px;",
  55. "X .select-outline": "fill:none;stroke-width:1;shape-rendering:crispEdges;",
  56. "X .select-outline-1": "stroke:white;",
  57. "X .select-outline-2": "stroke:black;stroke-dasharray:2px 2px;",
  58. Y: "font-family:'Open Sans';position:fixed;top:50px;right:20px;z-index:10000;font-size:10pt;max-width:180px;",
  59. "Y p": "margin:0;",
  60. "Y .notifier-note": "min-width:180px;max-width:250px;border:1px solid #fff;z-index:3000;margin:0;background-color:#8c97af;background-color:rgba(140,151,175,0.9);color:#fff;padding:10px;overflow-wrap:break-word;word-wrap:break-word;-ms-hyphens:auto;-webkit-hyphens:auto;hyphens:auto;",
  61. "Y .notifier-close": "color:#fff;opacity:0.8;float:right;padding:0 5px;background:none;border:none;font-size:20px;font-weight:bold;line-height:20px;",
  62. "Y .notifier-close:hover": "color:#444;text-decoration:none;cursor:pointer;"
  63. };
  64. for(var selector in rules) {
  65. var fullSelector = selector.replace(/^,/,' ,')
  66. .replace(/X/g, '.js-plotly-plot .plotly')
  67. .replace(/Y/g, '.plotly-notifier');
  68. Lib.addStyleRule(fullSelector, rules[selector]);
  69. }
  70. },{"../src/lib":169}],2:[function(_dereq_,module,exports){
  71. 'use strict';
  72. module.exports = {
  73. 'undo': {
  74. 'width': 857.1,
  75. 'height': 1000,
  76. 'path': 'm857 350q0-87-34-166t-91-137-137-92-166-34q-96 0-183 41t-147 114q-4 6-4 13t5 11l76 77q6 5 14 5 9-1 13-7 41-53 100-82t126-29q58 0 110 23t92 61 61 91 22 111-22 111-61 91-92 61-110 23q-55 0-105-20t-90-57l77-77q17-16 8-38-10-23-33-23h-250q-15 0-25 11t-11 25v250q0 24 22 33 22 10 39-8l72-72q60 57 137 88t159 31q87 0 166-34t137-92 91-137 34-166z',
  77. 'transform': 'matrix(1 0 0 -1 0 850)'
  78. },
  79. 'home': {
  80. 'width': 928.6,
  81. 'height': 1000,
  82. 'path': 'm786 296v-267q0-15-11-26t-25-10h-214v214h-143v-214h-214q-15 0-25 10t-11 26v267q0 1 0 2t0 2l321 264 321-264q1-1 1-4z m124 39l-34-41q-5-5-12-6h-2q-7 0-12 3l-386 322-386-322q-7-4-13-4-7 2-12 7l-35 41q-4 5-3 13t6 12l401 334q18 15 42 15t43-15l136-114v109q0 8 5 13t13 5h107q8 0 13-5t5-13v-227l122-102q5-5 6-12t-4-13z',
  83. 'transform': 'matrix(1 0 0 -1 0 850)'
  84. },
  85. 'camera-retro': {
  86. 'width': 1000,
  87. 'height': 1000,
  88. 'path': 'm518 386q0 8-5 13t-13 5q-37 0-63-27t-26-63q0-8 5-13t13-5 12 5 5 13q0 23 16 38t38 16q8 0 13 5t5 13z m125-73q0-59-42-101t-101-42-101 42-42 101 42 101 101 42 101-42 42-101z m-572-320h858v71h-858v-71z m643 320q0 89-62 152t-152 62-151-62-63-152 63-151 151-63 152 63 62 151z m-571 358h214v72h-214v-72z m-72-107h858v143h-462l-36-71h-360v-72z m929 143v-714q0-30-21-51t-50-21h-858q-29 0-50 21t-21 51v714q0 30 21 51t50 21h858q29 0 50-21t21-51z',
  89. 'transform': 'matrix(1 0 0 -1 0 850)'
  90. },
  91. 'zoombox': {
  92. 'width': 1000,
  93. 'height': 1000,
  94. 'path': 'm1000-25l-250 251c40 63 63 138 63 218 0 224-182 406-407 406-224 0-406-182-406-406s183-406 407-406c80 0 155 22 218 62l250-250 125 125z m-812 250l0 438 437 0 0-438-437 0z m62 375l313 0 0-312-313 0 0 312z',
  95. 'transform': 'matrix(1 0 0 -1 0 850)'
  96. },
  97. 'pan': {
  98. 'width': 1000,
  99. 'height': 1000,
  100. 'path': 'm1000 350l-187 188 0-125-250 0 0 250 125 0-188 187-187-187 125 0 0-250-250 0 0 125-188-188 186-187 0 125 252 0 0-250-125 0 187-188 188 188-125 0 0 250 250 0 0-126 187 188z',
  101. 'transform': 'matrix(1 0 0 -1 0 850)'
  102. },
  103. 'zoom_plus': {
  104. 'width': 1000,
  105. 'height': 1000,
  106. 'path': 'm1 787l0-875 875 0 0 875-875 0z m687-500l-187 0 0-187-125 0 0 187-188 0 0 125 188 0 0 187 125 0 0-187 187 0 0-125z',
  107. 'transform': 'matrix(1 0 0 -1 0 850)'
  108. },
  109. 'zoom_minus': {
  110. 'width': 1000,
  111. 'height': 1000,
  112. 'path': 'm0 788l0-876 875 0 0 876-875 0z m688-500l-500 0 0 125 500 0 0-125z',
  113. 'transform': 'matrix(1 0 0 -1 0 850)'
  114. },
  115. 'autoscale': {
  116. 'width': 1000,
  117. 'height': 1000,
  118. 'path': 'm250 850l-187 0-63 0 0-62 0-188 63 0 0 188 187 0 0 62z m688 0l-188 0 0-62 188 0 0-188 62 0 0 188 0 62-62 0z m-875-938l0 188-63 0 0-188 0-62 63 0 187 0 0 62-187 0z m875 188l0-188-188 0 0-62 188 0 62 0 0 62 0 188-62 0z m-125 188l-1 0-93-94-156 156 156 156 92-93 2 0 0 250-250 0 0-2 93-92-156-156-156 156 94 92 0 2-250 0 0-250 0 0 93 93 157-156-157-156-93 94 0 0 0-250 250 0 0 0-94 93 156 157 156-157-93-93 0 0 250 0 0 250z',
  119. 'transform': 'matrix(1 0 0 -1 0 850)'
  120. },
  121. 'tooltip_basic': {
  122. 'width': 1500,
  123. 'height': 1000,
  124. 'path': 'm375 725l0 0-375-375 375-374 0-1 1125 0 0 750-1125 0z',
  125. 'transform': 'matrix(1 0 0 -1 0 850)'
  126. },
  127. 'tooltip_compare': {
  128. 'width': 1125,
  129. 'height': 1000,
  130. 'path': 'm187 786l0 2-187-188 188-187 0 0 937 0 0 373-938 0z m0-499l0 1-187-188 188-188 0 0 937 0 0 376-938-1z',
  131. 'transform': 'matrix(1 0 0 -1 0 850)'
  132. },
  133. 'plotlylogo': {
  134. 'width': 1542,
  135. 'height': 1000,
  136. 'path': 'm0-10h182v-140h-182v140z m228 146h183v-286h-183v286z m225 714h182v-1000h-182v1000z m225-285h182v-715h-182v715z m225 142h183v-857h-183v857z m231-428h182v-429h-182v429z m225-291h183v-138h-183v138z',
  137. 'transform': 'matrix(1 0 0 -1 0 850)'
  138. },
  139. 'z-axis': {
  140. 'width': 1000,
  141. 'height': 1000,
  142. 'path': 'm833 5l-17 108v41l-130-65 130-66c0 0 0 38 0 39 0-1 36-14 39-25 4-15-6-22-16-30-15-12-39-16-56-20-90-22-187-23-279-23-261 0-341 34-353 59 3 60 228 110 228 110-140-8-351-35-351-116 0-120 293-142 474-142 155 0 477 22 477 142 0 50-74 79-163 96z m-374 94c-58-5-99-21-99-40 0-24 65-43 144-43 79 0 143 19 143 43 0 19-42 34-98 40v216h87l-132 135-133-135h88v-216z m167 515h-136v1c16 16 31 34 46 52l84 109v54h-230v-71h124v-1c-16-17-28-32-44-51l-89-114v-51h245v72z',
  143. 'transform': 'matrix(1 0 0 -1 0 850)'
  144. },
  145. '3d_rotate': {
  146. 'width': 1000,
  147. 'height': 1000,
  148. 'path': 'm922 660c-5 4-9 7-14 11-359 263-580-31-580-31l-102 28 58-400c0 1 1 1 2 2 118 108 351 249 351 249s-62 27-100 42c88 83 222 183 347 122 16-8 30-17 44-27-2 1-4 2-6 4z m36-329c0 0 64 229-88 296-62 27-124 14-175-11 157-78 225-208 249-266 8-19 11-31 11-31 2 5 6 15 11 32-5-13-8-20-8-20z m-775-239c70-31 117-50 198-32-121 80-199 346-199 346l-96-15-58-12c0 0 55-226 155-287z m603 133l-317-139c0 0 4-4 19-14 7-5 24-15 24-15s-177-147-389 4c235-287 536-112 536-112l31-22 100 299-4-1z m-298-153c6-4 14-9 24-15 0 0-17 10-24 15z',
  149. 'transform': 'matrix(1 0 0 -1 0 850)'
  150. },
  151. 'camera': {
  152. 'width': 1000,
  153. 'height': 1000,
  154. 'path': 'm500 450c-83 0-150-67-150-150 0-83 67-150 150-150 83 0 150 67 150 150 0 83-67 150-150 150z m400 150h-120c-16 0-34 13-39 29l-31 93c-6 15-23 28-40 28h-340c-16 0-34-13-39-28l-31-94c-6-15-23-28-40-28h-120c-55 0-100-45-100-100v-450c0-55 45-100 100-100h800c55 0 100 45 100 100v450c0 55-45 100-100 100z m-400-550c-138 0-250 112-250 250 0 138 112 250 250 250 138 0 250-112 250-250 0-138-112-250-250-250z m365 380c-19 0-35 16-35 35 0 19 16 35 35 35 19 0 35-16 35-35 0-19-16-35-35-35z',
  155. 'transform': 'matrix(1 0 0 -1 0 850)'
  156. },
  157. 'movie': {
  158. 'width': 1000,
  159. 'height': 1000,
  160. 'path': 'm938 413l-188-125c0 37-17 71-44 94 64 38 107 107 107 187 0 121-98 219-219 219-121 0-219-98-219-219 0-61 25-117 66-156h-115c30 33 49 76 49 125 0 103-84 187-187 187s-188-84-188-187c0-57 26-107 65-141-38-22-65-62-65-109v-250c0-70 56-126 125-126h500c69 0 125 56 125 126l188-126c34 0 62 28 62 63v375c0 35-28 63-62 63z m-750 0c-69 0-125 56-125 125s56 125 125 125 125-56 125-125-56-125-125-125z m406-1c-87 0-157 70-157 157 0 86 70 156 157 156s156-70 156-156-70-157-156-157z',
  161. 'transform': 'matrix(1 0 0 -1 0 850)'
  162. },
  163. 'question': {
  164. 'width': 857.1,
  165. 'height': 1000,
  166. 'path': 'm500 82v107q0 8-5 13t-13 5h-107q-8 0-13-5t-5-13v-107q0-8 5-13t13-5h107q8 0 13 5t5 13z m143 375q0 49-31 91t-77 65-95 23q-136 0-207-119-9-14 4-24l74-55q4-4 10-4 9 0 14 7 30 38 48 51 19 14 48 14 27 0 48-15t21-33q0-21-11-34t-38-25q-35-16-65-48t-29-70v-20q0-8 5-13t13-5h107q8 0 13 5t5 13q0 10 12 27t30 28q18 10 28 16t25 19 25 27 16 34 7 45z m214-107q0-117-57-215t-156-156-215-58-216 58-155 156-58 215 58 215 155 156 216 58 215-58 156-156 57-215z',
  167. 'transform': 'matrix(1 0 0 -1 0 850)'
  168. },
  169. 'disk': {
  170. 'width': 857.1,
  171. 'height': 1000,
  172. 'path': 'm214-7h429v214h-429v-214z m500 0h72v500q0 8-6 21t-11 20l-157 156q-5 6-19 12t-22 5v-232q0-22-15-38t-38-16h-322q-22 0-37 16t-16 38v232h-72v-714h72v232q0 22 16 38t37 16h465q22 0 38-16t15-38v-232z m-214 518v178q0 8-5 13t-13 5h-107q-7 0-13-5t-5-13v-178q0-8 5-13t13-5h107q7 0 13 5t5 13z m357-18v-518q0-22-15-38t-38-16h-750q-23 0-38 16t-16 38v750q0 22 16 38t38 16h517q23 0 50-12t42-26l156-157q16-15 27-42t11-49z',
  173. 'transform': 'matrix(1 0 0 -1 0 850)'
  174. },
  175. 'lasso': {
  176. 'width': 1031,
  177. 'height': 1000,
  178. 'path': 'm1018 538c-36 207-290 336-568 286-277-48-473-256-436-463 10-57 36-108 76-151-13-66 11-137 68-183 34-28 75-41 114-42l-55-70 0 0c-2-1-3-2-4-3-10-14-8-34 5-45 14-11 34-8 45 4 1 1 2 3 2 5l0 0 113 140c16 11 31 24 45 40 4 3 6 7 8 11 48-3 100 0 151 9 278 48 473 255 436 462z m-624-379c-80 14-149 48-197 96 42 42 109 47 156 9 33-26 47-66 41-105z m-187-74c-19 16-33 37-39 60 50-32 109-55 174-68-42-25-95-24-135 8z m360 75c-34-7-69-9-102-8 8 62-16 128-68 170-73 59-175 54-244-5-9 20-16 40-20 61-28 159 121 317 333 354s407-60 434-217c28-159-121-318-333-355z',
  179. 'transform': 'matrix(1 0 0 -1 0 850)'
  180. },
  181. 'selectbox': {
  182. 'width': 1000,
  183. 'height': 1000,
  184. 'path': 'm0 850l0-143 143 0 0 143-143 0z m286 0l0-143 143 0 0 143-143 0z m285 0l0-143 143 0 0 143-143 0z m286 0l0-143 143 0 0 143-143 0z m-857-286l0-143 143 0 0 143-143 0z m857 0l0-143 143 0 0 143-143 0z m-857-285l0-143 143 0 0 143-143 0z m857 0l0-143 143 0 0 143-143 0z m-857-286l0-143 143 0 0 143-143 0z m286 0l0-143 143 0 0 143-143 0z m285 0l0-143 143 0 0 143-143 0z m286 0l0-143 143 0 0 143-143 0z',
  185. 'transform': 'matrix(1 0 0 -1 0 850)'
  186. },
  187. 'spikeline': {
  188. 'width': 1000,
  189. 'height': 1000,
  190. 'path': 'M512 409c0-57-46-104-103-104-57 0-104 47-104 104 0 57 47 103 104 103 57 0 103-46 103-103z m-327-39l92 0 0 92-92 0z m-185 0l92 0 0 92-92 0z m370-186l92 0 0 93-92 0z m0-184l92 0 0 92-92 0z',
  191. 'transform': 'matrix(1.5 0 0 -1.5 0 850)'
  192. }
  193. };
  194. },{}],3:[function(_dereq_,module,exports){
  195. /**
  196. * Copyright 2012-2018, Plotly, Inc.
  197. * All rights reserved.
  198. *
  199. * This source code is licensed under the MIT license found in the
  200. * LICENSE file in the root directory of this source tree.
  201. */
  202. 'use strict';
  203. module.exports = _dereq_('../src/traces/bar');
  204. },{"../src/traces/bar":274}],4:[function(_dereq_,module,exports){
  205. /**
  206. * Copyright 2012-2018, Plotly, Inc.
  207. * All rights reserved.
  208. *
  209. * This source code is licensed under the MIT license found in the
  210. * LICENSE file in the root directory of this source tree.
  211. */
  212. 'use strict';
  213. module.exports = _dereq_('../src/traces/box');
  214. },{"../src/traces/box":288}],5:[function(_dereq_,module,exports){
  215. /**
  216. * Copyright 2012-2018, Plotly, Inc.
  217. * All rights reserved.
  218. *
  219. * This source code is licensed under the MIT license found in the
  220. * LICENSE file in the root directory of this source tree.
  221. */
  222. 'use strict';
  223. module.exports = _dereq_('../src/traces/contour');
  224. },{"../src/traces/contour":308}],6:[function(_dereq_,module,exports){
  225. /**
  226. * Copyright 2012-2018, Plotly, Inc.
  227. * All rights reserved.
  228. *
  229. * This source code is licensed under the MIT license found in the
  230. * LICENSE file in the root directory of this source tree.
  231. */
  232. 'use strict';
  233. module.exports = _dereq_('../src/core');
  234. },{"../src/core":153}],7:[function(_dereq_,module,exports){
  235. /**
  236. * Copyright 2012-2018, Plotly, Inc.
  237. * All rights reserved.
  238. *
  239. * This source code is licensed under the MIT license found in the
  240. * LICENSE file in the root directory of this source tree.
  241. */
  242. 'use strict';
  243. module.exports = _dereq_('../src/traces/heatmap');
  244. },{"../src/traces/heatmap":324}],8:[function(_dereq_,module,exports){
  245. /**
  246. * Copyright 2012-2018, Plotly, Inc.
  247. * All rights reserved.
  248. *
  249. * This source code is licensed under the MIT license found in the
  250. * LICENSE file in the root directory of this source tree.
  251. */
  252. 'use strict';
  253. module.exports = _dereq_('../src/traces/histogram');
  254. },{"../src/traces/histogram":342}],9:[function(_dereq_,module,exports){
  255. /**
  256. * Copyright 2012-2018, Plotly, Inc.
  257. * All rights reserved.
  258. *
  259. * This source code is licensed under the MIT license found in the
  260. * LICENSE file in the root directory of this source tree.
  261. */
  262. 'use strict';
  263. module.exports = _dereq_('../src/traces/histogram2d');
  264. },{"../src/traces/histogram2d":348}],10:[function(_dereq_,module,exports){
  265. /**
  266. * Copyright 2012-2018, Plotly, Inc.
  267. * All rights reserved.
  268. *
  269. * This source code is licensed under the MIT license found in the
  270. * LICENSE file in the root directory of this source tree.
  271. */
  272. 'use strict';
  273. module.exports = _dereq_('../src/traces/histogram2dcontour');
  274. },{"../src/traces/histogram2dcontour":352}],11:[function(_dereq_,module,exports){
  275. /**
  276. * Copyright 2012-2018, Plotly, Inc.
  277. * All rights reserved.
  278. *
  279. * This source code is licensed under the MIT license found in the
  280. * LICENSE file in the root directory of this source tree.
  281. */
  282. 'use strict';
  283. var Plotly = _dereq_('./core');
  284. Plotly.register([
  285. _dereq_('./bar'),
  286. _dereq_('./box'),
  287. _dereq_('./heatmap'),
  288. _dereq_('./histogram'),
  289. _dereq_('./histogram2d'),
  290. _dereq_('./histogram2dcontour'),
  291. _dereq_('./pie'),
  292. _dereq_('./contour'),
  293. _dereq_('./scatterternary'),
  294. _dereq_('./violin')
  295. ]);
  296. module.exports = Plotly;
  297. },{"./bar":3,"./box":4,"./contour":5,"./core":6,"./heatmap":7,"./histogram":8,"./histogram2d":9,"./histogram2dcontour":10,"./pie":12,"./scatterternary":13,"./violin":14}],12:[function(_dereq_,module,exports){
  298. /**
  299. * Copyright 2012-2018, Plotly, Inc.
  300. * All rights reserved.
  301. *
  302. * This source code is licensed under the MIT license found in the
  303. * LICENSE file in the root directory of this source tree.
  304. */
  305. 'use strict';
  306. module.exports = _dereq_('../src/traces/pie');
  307. },{"../src/traces/pie":359}],13:[function(_dereq_,module,exports){
  308. /**
  309. * Copyright 2012-2018, Plotly, Inc.
  310. * All rights reserved.
  311. *
  312. * This source code is licensed under the MIT license found in the
  313. * LICENSE file in the root directory of this source tree.
  314. */
  315. 'use strict';
  316. module.exports = _dereq_('../src/traces/scatterternary');
  317. },{"../src/traces/scatterternary":398}],14:[function(_dereq_,module,exports){
  318. /**
  319. * Copyright 2012-2018, Plotly, Inc.
  320. * All rights reserved.
  321. *
  322. * This source code is licensed under the MIT license found in the
  323. * LICENSE file in the root directory of this source tree.
  324. */
  325. 'use strict';
  326. module.exports = _dereq_('../src/traces/violin');
  327. },{"../src/traces/violin":406}],15:[function(_dereq_,module,exports){
  328. // Copyright Joyent, Inc. and other Node contributors.
  329. //
  330. // Permission is hereby granted, free of charge, to any person obtaining a
  331. // copy of this software and associated documentation files (the
  332. // "Software"), to deal in the Software without restriction, including
  333. // without limitation the rights to use, copy, modify, merge, publish,
  334. // distribute, sublicense, and/or sell copies of the Software, and to permit
  335. // persons to whom the Software is furnished to do so, subject to the
  336. // following conditions:
  337. //
  338. // The above copyright notice and this permission notice shall be included
  339. // in all copies or substantial portions of the Software.
  340. //
  341. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  342. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  343. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  344. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  345. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  346. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  347. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  348. var objectCreate = Object.create || objectCreatePolyfill
  349. var objectKeys = Object.keys || objectKeysPolyfill
  350. var bind = Function.prototype.bind || functionBindPolyfill
  351. function EventEmitter() {
  352. if (!this._events || !Object.prototype.hasOwnProperty.call(this, '_events')) {
  353. this._events = objectCreate(null);
  354. this._eventsCount = 0;
  355. }
  356. this._maxListeners = this._maxListeners || undefined;
  357. }
  358. module.exports = EventEmitter;
  359. // Backwards-compat with node 0.10.x
  360. EventEmitter.EventEmitter = EventEmitter;
  361. EventEmitter.prototype._events = undefined;
  362. EventEmitter.prototype._maxListeners = undefined;
  363. // By default EventEmitters will print a warning if more than 10 listeners are
  364. // added to it. This is a useful default which helps finding memory leaks.
  365. var defaultMaxListeners = 10;
  366. var hasDefineProperty;
  367. try {
  368. var o = {};
  369. if (Object.defineProperty) Object.defineProperty(o, 'x', { value: 0 });
  370. hasDefineProperty = o.x === 0;
  371. } catch (err) { hasDefineProperty = false }
  372. if (hasDefineProperty) {
  373. Object.defineProperty(EventEmitter, 'defaultMaxListeners', {
  374. enumerable: true,
  375. get: function() {
  376. return defaultMaxListeners;
  377. },
  378. set: function(arg) {
  379. // check whether the input is a positive number (whose value is zero or
  380. // greater and not a NaN).
  381. if (typeof arg !== 'number' || arg < 0 || arg !== arg)
  382. throw new TypeError('"defaultMaxListeners" must be a positive number');
  383. defaultMaxListeners = arg;
  384. }
  385. });
  386. } else {
  387. EventEmitter.defaultMaxListeners = defaultMaxListeners;
  388. }
  389. // Obviously not all Emitters should be limited to 10. This function allows
  390. // that to be increased. Set to zero for unlimited.
  391. EventEmitter.prototype.setMaxListeners = function setMaxListeners(n) {
  392. if (typeof n !== 'number' || n < 0 || isNaN(n))
  393. throw new TypeError('"n" argument must be a positive number');
  394. this._maxListeners = n;
  395. return this;
  396. };
  397. function $getMaxListeners(that) {
  398. if (that._maxListeners === undefined)
  399. return EventEmitter.defaultMaxListeners;
  400. return that._maxListeners;
  401. }
  402. EventEmitter.prototype.getMaxListeners = function getMaxListeners() {
  403. return $getMaxListeners(this);
  404. };
  405. // These standalone emit* functions are used to optimize calling of event
  406. // handlers for fast cases because emit() itself often has a variable number of
  407. // arguments and can be deoptimized because of that. These functions always have
  408. // the same number of arguments and thus do not get deoptimized, so the code
  409. // inside them can execute faster.
  410. function emitNone(handler, isFn, self) {
  411. if (isFn)
  412. handler.call(self);
  413. else {
  414. var len = handler.length;
  415. var listeners = arrayClone(handler, len);
  416. for (var i = 0; i < len; ++i)
  417. listeners[i].call(self);
  418. }
  419. }
  420. function emitOne(handler, isFn, self, arg1) {
  421. if (isFn)
  422. handler.call(self, arg1);
  423. else {
  424. var len = handler.length;
  425. var listeners = arrayClone(handler, len);
  426. for (var i = 0; i < len; ++i)
  427. listeners[i].call(self, arg1);
  428. }
  429. }
  430. function emitTwo(handler, isFn, self, arg1, arg2) {
  431. if (isFn)
  432. handler.call(self, arg1, arg2);
  433. else {
  434. var len = handler.length;
  435. var listeners = arrayClone(handler, len);
  436. for (var i = 0; i < len; ++i)
  437. listeners[i].call(self, arg1, arg2);
  438. }
  439. }
  440. function emitThree(handler, isFn, self, arg1, arg2, arg3) {
  441. if (isFn)
  442. handler.call(self, arg1, arg2, arg3);
  443. else {
  444. var len = handler.length;
  445. var listeners = arrayClone(handler, len);
  446. for (var i = 0; i < len; ++i)
  447. listeners[i].call(self, arg1, arg2, arg3);
  448. }
  449. }
  450. function emitMany(handler, isFn, self, args) {
  451. if (isFn)
  452. handler.apply(self, args);
  453. else {
  454. var len = handler.length;
  455. var listeners = arrayClone(handler, len);
  456. for (var i = 0; i < len; ++i)
  457. listeners[i].apply(self, args);
  458. }
  459. }
  460. EventEmitter.prototype.emit = function emit(type) {
  461. var er, handler, len, args, i, events;
  462. var doError = (type === 'error');
  463. events = this._events;
  464. if (events)
  465. doError = (doError && events.error == null);
  466. else if (!doError)
  467. return false;
  468. // If there is no 'error' event listener then throw.
  469. if (doError) {
  470. if (arguments.length > 1)
  471. er = arguments[1];
  472. if (er instanceof Error) {
  473. throw er; // Unhandled 'error' event
  474. } else {
  475. // At least give some kind of context to the user
  476. var err = new Error('Unhandled "error" event. (' + er + ')');
  477. err.context = er;
  478. throw err;
  479. }
  480. return false;
  481. }
  482. handler = events[type];
  483. if (!handler)
  484. return false;
  485. var isFn = typeof handler === 'function';
  486. len = arguments.length;
  487. switch (len) {
  488. // fast cases
  489. case 1:
  490. emitNone(handler, isFn, this);
  491. break;
  492. case 2:
  493. emitOne(handler, isFn, this, arguments[1]);
  494. break;
  495. case 3:
  496. emitTwo(handler, isFn, this, arguments[1], arguments[2]);
  497. break;
  498. case 4:
  499. emitThree(handler, isFn, this, arguments[1], arguments[2], arguments[3]);
  500. break;
  501. // slower
  502. default:
  503. args = new Array(len - 1);
  504. for (i = 1; i < len; i++)
  505. args[i - 1] = arguments[i];
  506. emitMany(handler, isFn, this, args);
  507. }
  508. return true;
  509. };
  510. function _addListener(target, type, listener, prepend) {
  511. var m;
  512. var events;
  513. var existing;
  514. if (typeof listener !== 'function')
  515. throw new TypeError('"listener" argument must be a function');
  516. events = target._events;
  517. if (!events) {
  518. events = target._events = objectCreate(null);
  519. target._eventsCount = 0;
  520. } else {
  521. // To avoid recursion in the case that type === "newListener"! Before
  522. // adding it to the listeners, first emit "newListener".
  523. if (events.newListener) {
  524. target.emit('newListener', type,
  525. listener.listener ? listener.listener : listener);
  526. // Re-assign `events` because a newListener handler could have caused the
  527. // this._events to be assigned to a new object
  528. events = target._events;
  529. }
  530. existing = events[type];
  531. }
  532. if (!existing) {
  533. // Optimize the case of one listener. Don't need the extra array object.
  534. existing = events[type] = listener;
  535. ++target._eventsCount;
  536. } else {
  537. if (typeof existing === 'function') {
  538. // Adding the second element, need to change to array.
  539. existing = events[type] =
  540. prepend ? [listener, existing] : [existing, listener];
  541. } else {
  542. // If we've already got an array, just append.
  543. if (prepend) {
  544. existing.unshift(listener);
  545. } else {
  546. existing.push(listener);
  547. }
  548. }
  549. // Check for listener leak
  550. if (!existing.warned) {
  551. m = $getMaxListeners(target);
  552. if (m && m > 0 && existing.length > m) {
  553. existing.warned = true;
  554. var w = new Error('Possible EventEmitter memory leak detected. ' +
  555. existing.length + ' "' + String(type) + '" listeners ' +
  556. 'added. Use emitter.setMaxListeners() to ' +
  557. 'increase limit.');
  558. w.name = 'MaxListenersExceededWarning';
  559. w.emitter = target;
  560. w.type = type;
  561. w.count = existing.length;
  562. if (typeof console === 'object' && console.warn) {
  563. console.warn('%s: %s', w.name, w.message);
  564. }
  565. }
  566. }
  567. }
  568. return target;
  569. }
  570. EventEmitter.prototype.addListener = function addListener(type, listener) {
  571. return _addListener(this, type, listener, false);
  572. };
  573. EventEmitter.prototype.on = EventEmitter.prototype.addListener;
  574. EventEmitter.prototype.prependListener =
  575. function prependListener(type, listener) {
  576. return _addListener(this, type, listener, true);
  577. };
  578. function onceWrapper() {
  579. if (!this.fired) {
  580. this.target.removeListener(this.type, this.wrapFn);
  581. this.fired = true;
  582. switch (arguments.length) {
  583. case 0:
  584. return this.listener.call(this.target);
  585. case 1:
  586. return this.listener.call(this.target, arguments[0]);
  587. case 2:
  588. return this.listener.call(this.target, arguments[0], arguments[1]);
  589. case 3:
  590. return this.listener.call(this.target, arguments[0], arguments[1],
  591. arguments[2]);
  592. default:
  593. var args = new Array(arguments.length);
  594. for (var i = 0; i < args.length; ++i)
  595. args[i] = arguments[i];
  596. this.listener.apply(this.target, args);
  597. }
  598. }
  599. }
  600. function _onceWrap(target, type, listener) {
  601. var state = { fired: false, wrapFn: undefined, target: target, type: type, listener: listener };
  602. var wrapped = bind.call(onceWrapper, state);
  603. wrapped.listener = listener;
  604. state.wrapFn = wrapped;
  605. return wrapped;
  606. }
  607. EventEmitter.prototype.once = function once(type, listener) {
  608. if (typeof listener !== 'function')
  609. throw new TypeError('"listener" argument must be a function');
  610. this.on(type, _onceWrap(this, type, listener));
  611. return this;
  612. };
  613. EventEmitter.prototype.prependOnceListener =
  614. function prependOnceListener(type, listener) {
  615. if (typeof listener !== 'function')
  616. throw new TypeError('"listener" argument must be a function');
  617. this.prependListener(type, _onceWrap(this, type, listener));
  618. return this;
  619. };
  620. // Emits a 'removeListener' event if and only if the listener was removed.
  621. EventEmitter.prototype.removeListener =
  622. function removeListener(type, listener) {
  623. var list, events, position, i, originalListener;
  624. if (typeof listener !== 'function')
  625. throw new TypeError('"listener" argument must be a function');
  626. events = this._events;
  627. if (!events)
  628. return this;
  629. list = events[type];
  630. if (!list)
  631. return this;
  632. if (list === listener || list.listener === listener) {
  633. if (--this._eventsCount === 0)
  634. this._events = objectCreate(null);
  635. else {
  636. delete events[type];
  637. if (events.removeListener)
  638. this.emit('removeListener', type, list.listener || listener);
  639. }
  640. } else if (typeof list !== 'function') {
  641. position = -1;
  642. for (i = list.length - 1; i >= 0; i--) {
  643. if (list[i] === listener || list[i].listener === listener) {
  644. originalListener = list[i].listener;
  645. position = i;
  646. break;
  647. }
  648. }
  649. if (position < 0)
  650. return this;
  651. if (position === 0)
  652. list.shift();
  653. else
  654. spliceOne(list, position);
  655. if (list.length === 1)
  656. events[type] = list[0];
  657. if (events.removeListener)
  658. this.emit('removeListener', type, originalListener || listener);
  659. }
  660. return this;
  661. };
  662. EventEmitter.prototype.removeAllListeners =
  663. function removeAllListeners(type) {
  664. var listeners, events, i;
  665. events = this._events;
  666. if (!events)
  667. return this;
  668. // not listening for removeListener, no need to emit
  669. if (!events.removeListener) {
  670. if (arguments.length === 0) {
  671. this._events = objectCreate(null);
  672. this._eventsCount = 0;
  673. } else if (events[type]) {
  674. if (--this._eventsCount === 0)
  675. this._events = objectCreate(null);
  676. else
  677. delete events[type];
  678. }
  679. return this;
  680. }
  681. // emit removeListener for all listeners on all events
  682. if (arguments.length === 0) {
  683. var keys = objectKeys(events);
  684. var key;
  685. for (i = 0; i < keys.length; ++i) {
  686. key = keys[i];
  687. if (key === 'removeListener') continue;
  688. this.removeAllListeners(key);
  689. }
  690. this.removeAllListeners('removeListener');
  691. this._events = objectCreate(null);
  692. this._eventsCount = 0;
  693. return this;
  694. }
  695. listeners = events[type];
  696. if (typeof listeners === 'function') {
  697. this.removeListener(type, listeners);
  698. } else if (listeners) {
  699. // LIFO order
  700. for (i = listeners.length - 1; i >= 0; i--) {
  701. this.removeListener(type, listeners[i]);
  702. }
  703. }
  704. return this;
  705. };
  706. function _listeners(target, type, unwrap) {
  707. var events = target._events;
  708. if (!events)
  709. return [];
  710. var evlistener = events[type];
  711. if (!evlistener)
  712. return [];
  713. if (typeof evlistener === 'function')
  714. return unwrap ? [evlistener.listener || evlistener] : [evlistener];
  715. return unwrap ? unwrapListeners(evlistener) : arrayClone(evlistener, evlistener.length);
  716. }
  717. EventEmitter.prototype.listeners = function listeners(type) {
  718. return _listeners(this, type, true);
  719. };
  720. EventEmitter.prototype.rawListeners = function rawListeners(type) {
  721. return _listeners(this, type, false);
  722. };
  723. EventEmitter.listenerCount = function(emitter, type) {
  724. if (typeof emitter.listenerCount === 'function') {
  725. return emitter.listenerCount(type);
  726. } else {
  727. return listenerCount.call(emitter, type);
  728. }
  729. };
  730. EventEmitter.prototype.listenerCount = listenerCount;
  731. function listenerCount(type) {
  732. var events = this._events;
  733. if (events) {
  734. var evlistener = events[type];
  735. if (typeof evlistener === 'function') {
  736. return 1;
  737. } else if (evlistener) {
  738. return evlistener.length;
  739. }
  740. }
  741. return 0;
  742. }
  743. EventEmitter.prototype.eventNames = function eventNames() {
  744. return this._eventsCount > 0 ? Reflect.ownKeys(this._events) : [];
  745. };
  746. // About 1.5x faster than the two-arg version of Array#splice().
  747. function spliceOne(list, index) {
  748. for (var i = index, k = i + 1, n = list.length; k < n; i += 1, k += 1)
  749. list[i] = list[k];
  750. list.pop();
  751. }
  752. function arrayClone(arr, n) {
  753. var copy = new Array(n);
  754. for (var i = 0; i < n; ++i)
  755. copy[i] = arr[i];
  756. return copy;
  757. }
  758. function unwrapListeners(arr) {
  759. var ret = new Array(arr.length);
  760. for (var i = 0; i < ret.length; ++i) {
  761. ret[i] = arr[i].listener || arr[i];
  762. }
  763. return ret;
  764. }
  765. function objectCreatePolyfill(proto) {
  766. var F = function() {};
  767. F.prototype = proto;
  768. return new F;
  769. }
  770. function objectKeysPolyfill(obj) {
  771. var keys = [];
  772. for (var k in obj) if (Object.prototype.hasOwnProperty.call(obj, k)) {
  773. keys.push(k);
  774. }
  775. return k;
  776. }
  777. function functionBindPolyfill(context) {
  778. var fn = this;
  779. return function () {
  780. return fn.apply(context, arguments);
  781. };
  782. }
  783. },{}],16:[function(_dereq_,module,exports){
  784. !function() {
  785. var d3 = {
  786. version: "3.5.17"
  787. };
  788. var d3_arraySlice = [].slice, d3_array = function(list) {
  789. return d3_arraySlice.call(list);
  790. };
  791. var d3_document = this.document;
  792. function d3_documentElement(node) {
  793. return node && (node.ownerDocument || node.document || node).documentElement;
  794. }
  795. function d3_window(node) {
  796. return node && (node.ownerDocument && node.ownerDocument.defaultView || node.document && node || node.defaultView);
  797. }
  798. if (d3_document) {
  799. try {
  800. d3_array(d3_document.documentElement.childNodes)[0].nodeType;
  801. } catch (e) {
  802. d3_array = function(list) {
  803. var i = list.length, array = new Array(i);
  804. while (i--) array[i] = list[i];
  805. return array;
  806. };
  807. }
  808. }
  809. if (!Date.now) Date.now = function() {
  810. return +new Date();
  811. };
  812. if (d3_document) {
  813. try {
  814. d3_document.createElement("DIV").style.setProperty("opacity", 0, "");
  815. } catch (error) {
  816. var d3_element_prototype = this.Element.prototype, d3_element_setAttribute = d3_element_prototype.setAttribute, d3_element_setAttributeNS = d3_element_prototype.setAttributeNS, d3_style_prototype = this.CSSStyleDeclaration.prototype, d3_style_setProperty = d3_style_prototype.setProperty;
  817. d3_element_prototype.setAttribute = function(name, value) {
  818. d3_element_setAttribute.call(this, name, value + "");
  819. };
  820. d3_element_prototype.setAttributeNS = function(space, local, value) {
  821. d3_element_setAttributeNS.call(this, space, local, value + "");
  822. };
  823. d3_style_prototype.setProperty = function(name, value, priority) {
  824. d3_style_setProperty.call(this, name, value + "", priority);
  825. };
  826. }
  827. }
  828. d3.ascending = d3_ascending;
  829. function d3_ascending(a, b) {
  830. return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
  831. }
  832. d3.descending = function(a, b) {
  833. return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
  834. };
  835. d3.min = function(array, f) {
  836. var i = -1, n = array.length, a, b;
  837. if (arguments.length === 1) {
  838. while (++i < n) if ((b = array[i]) != null && b >= b) {
  839. a = b;
  840. break;
  841. }
  842. while (++i < n) if ((b = array[i]) != null && a > b) a = b;
  843. } else {
  844. while (++i < n) if ((b = f.call(array, array[i], i)) != null && b >= b) {
  845. a = b;
  846. break;
  847. }
  848. while (++i < n) if ((b = f.call(array, array[i], i)) != null && a > b) a = b;
  849. }
  850. return a;
  851. };
  852. d3.max = function(array, f) {
  853. var i = -1, n = array.length, a, b;
  854. if (arguments.length === 1) {
  855. while (++i < n) if ((b = array[i]) != null && b >= b) {
  856. a = b;
  857. break;
  858. }
  859. while (++i < n) if ((b = array[i]) != null && b > a) a = b;
  860. } else {
  861. while (++i < n) if ((b = f.call(array, array[i], i)) != null && b >= b) {
  862. a = b;
  863. break;
  864. }
  865. while (++i < n) if ((b = f.call(array, array[i], i)) != null && b > a) a = b;
  866. }
  867. return a;
  868. };
  869. d3.extent = function(array, f) {
  870. var i = -1, n = array.length, a, b, c;
  871. if (arguments.length === 1) {
  872. while (++i < n) if ((b = array[i]) != null && b >= b) {
  873. a = c = b;
  874. break;
  875. }
  876. while (++i < n) if ((b = array[i]) != null) {
  877. if (a > b) a = b;
  878. if (c < b) c = b;
  879. }
  880. } else {
  881. while (++i < n) if ((b = f.call(array, array[i], i)) != null && b >= b) {
  882. a = c = b;
  883. break;
  884. }
  885. while (++i < n) if ((b = f.call(array, array[i], i)) != null) {
  886. if (a > b) a = b;
  887. if (c < b) c = b;
  888. }
  889. }
  890. return [ a, c ];
  891. };
  892. function d3_number(x) {
  893. return x === null ? NaN : +x;
  894. }
  895. function d3_numeric(x) {
  896. return !isNaN(x);
  897. }
  898. d3.sum = function(array, f) {
  899. var s = 0, n = array.length, a, i = -1;
  900. if (arguments.length === 1) {
  901. while (++i < n) if (d3_numeric(a = +array[i])) s += a;
  902. } else {
  903. while (++i < n) if (d3_numeric(a = +f.call(array, array[i], i))) s += a;
  904. }
  905. return s;
  906. };
  907. d3.mean = function(array, f) {
  908. var s = 0, n = array.length, a, i = -1, j = n;
  909. if (arguments.length === 1) {
  910. while (++i < n) if (d3_numeric(a = d3_number(array[i]))) s += a; else --j;
  911. } else {
  912. while (++i < n) if (d3_numeric(a = d3_number(f.call(array, array[i], i)))) s += a; else --j;
  913. }
  914. if (j) return s / j;
  915. };
  916. d3.quantile = function(values, p) {
  917. var H = (values.length - 1) * p + 1, h = Math.floor(H), v = +values[h - 1], e = H - h;
  918. return e ? v + e * (values[h] - v) : v;
  919. };
  920. d3.median = function(array, f) {
  921. var numbers = [], n = array.length, a, i = -1;
  922. if (arguments.length === 1) {
  923. while (++i < n) if (d3_numeric(a = d3_number(array[i]))) numbers.push(a);
  924. } else {
  925. while (++i < n) if (d3_numeric(a = d3_number(f.call(array, array[i], i)))) numbers.push(a);
  926. }
  927. if (numbers.length) return d3.quantile(numbers.sort(d3_ascending), .5);
  928. };
  929. d3.variance = function(array, f) {
  930. var n = array.length, m = 0, a, d, s = 0, i = -1, j = 0;
  931. if (arguments.length === 1) {
  932. while (++i < n) {
  933. if (d3_numeric(a = d3_number(array[i]))) {
  934. d = a - m;
  935. m += d / ++j;
  936. s += d * (a - m);
  937. }
  938. }
  939. } else {
  940. while (++i < n) {
  941. if (d3_numeric(a = d3_number(f.call(array, array[i], i)))) {
  942. d = a - m;
  943. m += d / ++j;
  944. s += d * (a - m);
  945. }
  946. }
  947. }
  948. if (j > 1) return s / (j - 1);
  949. };
  950. d3.deviation = function() {
  951. var v = d3.variance.apply(this, arguments);
  952. return v ? Math.sqrt(v) : v;
  953. };
  954. function d3_bisector(compare) {
  955. return {
  956. left: function(a, x, lo, hi) {
  957. if (arguments.length < 3) lo = 0;
  958. if (arguments.length < 4) hi = a.length;
  959. while (lo < hi) {
  960. var mid = lo + hi >>> 1;
  961. if (compare(a[mid], x) < 0) lo = mid + 1; else hi = mid;
  962. }
  963. return lo;
  964. },
  965. right: function(a, x, lo, hi) {
  966. if (arguments.length < 3) lo = 0;
  967. if (arguments.length < 4) hi = a.length;
  968. while (lo < hi) {
  969. var mid = lo + hi >>> 1;
  970. if (compare(a[mid], x) > 0) hi = mid; else lo = mid + 1;
  971. }
  972. return lo;
  973. }
  974. };
  975. }
  976. var d3_bisect = d3_bisector(d3_ascending);
  977. d3.bisectLeft = d3_bisect.left;
  978. d3.bisect = d3.bisectRight = d3_bisect.right;
  979. d3.bisector = function(f) {
  980. return d3_bisector(f.length === 1 ? function(d, x) {
  981. return d3_ascending(f(d), x);
  982. } : f);
  983. };
  984. d3.shuffle = function(array, i0, i1) {
  985. if ((m = arguments.length) < 3) {
  986. i1 = array.length;
  987. if (m < 2) i0 = 0;
  988. }
  989. var m = i1 - i0, t, i;
  990. while (m) {
  991. i = Math.random() * m-- | 0;
  992. t = array[m + i0], array[m + i0] = array[i + i0], array[i + i0] = t;
  993. }
  994. return array;
  995. };
  996. d3.permute = function(array, indexes) {
  997. var i = indexes.length, permutes = new Array(i);
  998. while (i--) permutes[i] = array[indexes[i]];
  999. return permutes;
  1000. };
  1001. d3.pairs = function(array) {
  1002. var i = 0, n = array.length - 1, p0, p1 = array[0], pairs = new Array(n < 0 ? 0 : n);
  1003. while (i < n) pairs[i] = [ p0 = p1, p1 = array[++i] ];
  1004. return pairs;
  1005. };
  1006. d3.transpose = function(matrix) {
  1007. if (!(n = matrix.length)) return [];
  1008. for (var i = -1, m = d3.min(matrix, d3_transposeLength), transpose = new Array(m); ++i < m; ) {
  1009. for (var j = -1, n, row = transpose[i] = new Array(n); ++j < n; ) {
  1010. row[j] = matrix[j][i];
  1011. }
  1012. }
  1013. return transpose;
  1014. };
  1015. function d3_transposeLength(d) {
  1016. return d.length;
  1017. }
  1018. d3.zip = function() {
  1019. return d3.transpose(arguments);
  1020. };
  1021. d3.keys = function(map) {
  1022. var keys = [];
  1023. for (var key in map) keys.push(key);
  1024. return keys;
  1025. };
  1026. d3.values = function(map) {
  1027. var values = [];
  1028. for (var key in map) values.push(map[key]);
  1029. return values;
  1030. };
  1031. d3.entries = function(map) {
  1032. var entries = [];
  1033. for (var key in map) entries.push({
  1034. key: key,
  1035. value: map[key]
  1036. });
  1037. return entries;
  1038. };
  1039. d3.merge = function(arrays) {
  1040. var n = arrays.length, m, i = -1, j = 0, merged, array;
  1041. while (++i < n) j += arrays[i].length;
  1042. merged = new Array(j);
  1043. while (--n >= 0) {
  1044. array = arrays[n];
  1045. m = array.length;
  1046. while (--m >= 0) {
  1047. merged[--j] = array[m];
  1048. }
  1049. }
  1050. return merged;
  1051. };
  1052. var abs = Math.abs;
  1053. d3.range = function(start, stop, step) {
  1054. if (arguments.length < 3) {
  1055. step = 1;
  1056. if (arguments.length < 2) {
  1057. stop = start;
  1058. start = 0;
  1059. }
  1060. }
  1061. if ((stop - start) / step === Infinity) throw new Error("infinite range");
  1062. var range = [], k = d3_range_integerScale(abs(step)), i = -1, j;
  1063. start *= k, stop *= k, step *= k;
  1064. if (step < 0) while ((j = start + step * ++i) > stop) range.push(j / k); else while ((j = start + step * ++i) < stop) range.push(j / k);
  1065. return range;
  1066. };
  1067. function d3_range_integerScale(x) {
  1068. var k = 1;
  1069. while (x * k % 1) k *= 10;
  1070. return k;
  1071. }
  1072. function d3_class(ctor, properties) {
  1073. for (var key in properties) {
  1074. Object.defineProperty(ctor.prototype, key, {
  1075. value: properties[key],
  1076. enumerable: false
  1077. });
  1078. }
  1079. }
  1080. d3.map = function(object, f) {
  1081. var map = new d3_Map();
  1082. if (object instanceof d3_Map) {
  1083. object.forEach(function(key, value) {
  1084. map.set(key, value);
  1085. });
  1086. } else if (Array.isArray(object)) {
  1087. var i = -1, n = object.length, o;
  1088. if (arguments.length === 1) while (++i < n) map.set(i, object[i]); else while (++i < n) map.set(f.call(object, o = object[i], i), o);
  1089. } else {
  1090. for (var key in object) map.set(key, object[key]);
  1091. }
  1092. return map;
  1093. };
  1094. function d3_Map() {
  1095. this._ = Object.create(null);
  1096. }
  1097. var d3_map_proto = "__proto__", d3_map_zero = "\x00";
  1098. d3_class(d3_Map, {
  1099. has: d3_map_has,
  1100. get: function(key) {
  1101. return this._[d3_map_escape(key)];
  1102. },
  1103. set: function(key, value) {
  1104. return this._[d3_map_escape(key)] = value;
  1105. },
  1106. remove: d3_map_remove,
  1107. keys: d3_map_keys,
  1108. values: function() {
  1109. var values = [];
  1110. for (var key in this._) values.push(this._[key]);
  1111. return values;
  1112. },
  1113. entries: function() {
  1114. var entries = [];
  1115. for (var key in this._) entries.push({
  1116. key: d3_map_unescape(key),
  1117. value: this._[key]
  1118. });
  1119. return entries;
  1120. },
  1121. size: d3_map_size,
  1122. empty: d3_map_empty,
  1123. forEach: function(f) {
  1124. for (var key in this._) f.call(this, d3_map_unescape(key), this._[key]);
  1125. }
  1126. });
  1127. function d3_map_escape(key) {
  1128. return (key += "") === d3_map_proto || key[0] === d3_map_zero ? d3_map_zero + key : key;
  1129. }
  1130. function d3_map_unescape(key) {
  1131. return (key += "")[0] === d3_map_zero ? key.slice(1) : key;
  1132. }
  1133. function d3_map_has(key) {
  1134. return d3_map_escape(key) in this._;
  1135. }
  1136. function d3_map_remove(key) {
  1137. return (key = d3_map_escape(key)) in this._ && delete this._[key];
  1138. }
  1139. function d3_map_keys() {
  1140. var keys = [];
  1141. for (var key in this._) keys.push(d3_map_unescape(key));
  1142. return keys;
  1143. }
  1144. function d3_map_size() {
  1145. var size = 0;
  1146. for (var key in this._) ++size;
  1147. return size;
  1148. }
  1149. function d3_map_empty() {
  1150. for (var key in this._) return false;
  1151. return true;
  1152. }
  1153. d3.nest = function() {
  1154. var nest = {}, keys = [], sortKeys = [], sortValues, rollup;
  1155. function map(mapType, array, depth) {
  1156. if (depth >= keys.length) return rollup ? rollup.call(nest, array) : sortValues ? array.sort(sortValues) : array;
  1157. var i = -1, n = array.length, key = keys[depth++], keyValue, object, setter, valuesByKey = new d3_Map(), values;
  1158. while (++i < n) {
  1159. if (values = valuesByKey.get(keyValue = key(object = array[i]))) {
  1160. values.push(object);
  1161. } else {
  1162. valuesByKey.set(keyValue, [ object ]);
  1163. }
  1164. }
  1165. if (mapType) {
  1166. object = mapType();
  1167. setter = function(keyValue, values) {
  1168. object.set(keyValue, map(mapType, values, depth));
  1169. };
  1170. } else {
  1171. object = {};
  1172. setter = function(keyValue, values) {
  1173. object[keyValue] = map(mapType, values, depth);
  1174. };
  1175. }
  1176. valuesByKey.forEach(setter);
  1177. return object;
  1178. }
  1179. function entries(map, depth) {
  1180. if (depth >= keys.length) return map;
  1181. var array = [], sortKey = sortKeys[depth++];
  1182. map.forEach(function(key, keyMap) {
  1183. array.push({
  1184. key: key,
  1185. values: entries(keyMap, depth)
  1186. });
  1187. });
  1188. return sortKey ? array.sort(function(a, b) {
  1189. return sortKey(a.key, b.key);
  1190. }) : array;
  1191. }
  1192. nest.map = function(array, mapType) {
  1193. return map(mapType, array, 0);
  1194. };
  1195. nest.entries = function(array) {
  1196. return entries(map(d3.map, array, 0), 0);
  1197. };
  1198. nest.key = function(d) {
  1199. keys.push(d);
  1200. return nest;
  1201. };
  1202. nest.sortKeys = function(order) {
  1203. sortKeys[keys.length - 1] = order;
  1204. return nest;
  1205. };
  1206. nest.sortValues = function(order) {
  1207. sortValues = order;
  1208. return nest;
  1209. };
  1210. nest.rollup = function(f) {
  1211. rollup = f;
  1212. return nest;
  1213. };
  1214. return nest;
  1215. };
  1216. d3.set = function(array) {
  1217. var set = new d3_Set();
  1218. if (array) for (var i = 0, n = array.length; i < n; ++i) set.add(array[i]);
  1219. return set;
  1220. };
  1221. function d3_Set() {
  1222. this._ = Object.create(null);
  1223. }
  1224. d3_class(d3_Set, {
  1225. has: d3_map_has,
  1226. add: function(key) {
  1227. this._[d3_map_escape(key += "")] = true;
  1228. return key;
  1229. },
  1230. remove: d3_map_remove,
  1231. values: d3_map_keys,
  1232. size: d3_map_size,
  1233. empty: d3_map_empty,
  1234. forEach: function(f) {
  1235. for (var key in this._) f.call(this, d3_map_unescape(key));
  1236. }
  1237. });
  1238. d3.behavior = {};
  1239. function d3_identity(d) {
  1240. return d;
  1241. }
  1242. d3.rebind = function(target, source) {
  1243. var i = 1, n = arguments.length, method;
  1244. while (++i < n) target[method = arguments[i]] = d3_rebind(target, source, source[method]);
  1245. return target;
  1246. };
  1247. function d3_rebind(target, source, method) {
  1248. return function() {
  1249. var value = method.apply(source, arguments);
  1250. return value === source ? target : value;
  1251. };
  1252. }
  1253. function d3_vendorSymbol(object, name) {
  1254. if (name in object) return name;
  1255. name = name.charAt(0).toUpperCase() + name.slice(1);
  1256. for (var i = 0, n = d3_vendorPrefixes.length; i < n; ++i) {
  1257. var prefixName = d3_vendorPrefixes[i] + name;
  1258. if (prefixName in object) return prefixName;
  1259. }
  1260. }
  1261. var d3_vendorPrefixes = [ "webkit", "ms", "moz", "Moz", "o", "O" ];
  1262. function d3_noop() {}
  1263. d3.dispatch = function() {
  1264. var dispatch = new d3_dispatch(), i = -1, n = arguments.length;
  1265. while (++i < n) dispatch[arguments[i]] = d3_dispatch_event(dispatch);
  1266. return dispatch;
  1267. };
  1268. function d3_dispatch() {}
  1269. d3_dispatch.prototype.on = function(type, listener) {
  1270. var i = type.indexOf("."), name = "";
  1271. if (i >= 0) {
  1272. name = type.slice(i + 1);
  1273. type = type.slice(0, i);
  1274. }
  1275. if (type) return arguments.length < 2 ? this[type].on(name) : this[type].on(name, listener);
  1276. if (arguments.length === 2) {
  1277. if (listener == null) for (type in this) {
  1278. if (this.hasOwnProperty(type)) this[type].on(name, null);
  1279. }
  1280. return this;
  1281. }
  1282. };
  1283. function d3_dispatch_event(dispatch) {
  1284. var listeners = [], listenerByName = new d3_Map();
  1285. function event() {
  1286. var z = listeners, i = -1, n = z.length, l;
  1287. while (++i < n) if (l = z[i].on) l.apply(this, arguments);
  1288. return dispatch;
  1289. }
  1290. event.on = function(name, listener) {
  1291. var l = listenerByName.get(name), i;
  1292. if (arguments.length < 2) return l && l.on;
  1293. if (l) {
  1294. l.on = null;
  1295. listeners = listeners.slice(0, i = listeners.indexOf(l)).concat(listeners.slice(i + 1));
  1296. listenerByName.remove(name);
  1297. }
  1298. if (listener) listeners.push(listenerByName.set(name, {
  1299. on: listener
  1300. }));
  1301. return dispatch;
  1302. };
  1303. return event;
  1304. }
  1305. d3.event = null;
  1306. function d3_eventPreventDefault() {
  1307. d3.event.preventDefault();
  1308. }
  1309. function d3_eventSource() {
  1310. var e = d3.event, s;
  1311. while (s = e.sourceEvent) e = s;
  1312. return e;
  1313. }
  1314. function d3_eventDispatch(target) {
  1315. var dispatch = new d3_dispatch(), i = 0, n = arguments.length;
  1316. while (++i < n) dispatch[arguments[i]] = d3_dispatch_event(dispatch);
  1317. dispatch.of = function(thiz, argumentz) {
  1318. return function(e1) {
  1319. try {
  1320. var e0 = e1.sourceEvent = d3.event;
  1321. e1.target = target;
  1322. d3.event = e1;
  1323. dispatch[e1.type].apply(thiz, argumentz);
  1324. } finally {
  1325. d3.event = e0;
  1326. }
  1327. };
  1328. };
  1329. return dispatch;
  1330. }
  1331. d3.requote = function(s) {
  1332. return s.replace(d3_requote_re, "\\$&");
  1333. };
  1334. var d3_requote_re = /[\\\^\$\*\+\?\|\[\]\(\)\.\{\}]/g;
  1335. var d3_subclass = {}.__proto__ ? function(object, prototype) {
  1336. object.__proto__ = prototype;
  1337. } : function(object, prototype) {
  1338. for (var property in prototype) object[property] = prototype[property];
  1339. };
  1340. function d3_selection(groups) {
  1341. d3_subclass(groups, d3_selectionPrototype);
  1342. return groups;
  1343. }
  1344. var d3_select = function(s, n) {
  1345. return n.querySelector(s);
  1346. }, d3_selectAll = function(s, n) {
  1347. return n.querySelectorAll(s);
  1348. }, d3_selectMatches = function(n, s) {
  1349. var d3_selectMatcher = n.matches || n[d3_vendorSymbol(n, "matchesSelector")];
  1350. d3_selectMatches = function(n, s) {
  1351. return d3_selectMatcher.call(n, s);
  1352. };
  1353. return d3_selectMatches(n, s);
  1354. };
  1355. if (typeof Sizzle === "function") {
  1356. d3_select = function(s, n) {
  1357. return Sizzle(s, n)[0] || null;
  1358. };
  1359. d3_selectAll = Sizzle;
  1360. d3_selectMatches = Sizzle.matchesSelector;
  1361. }
  1362. d3.selection = function() {
  1363. return d3.select(d3_document.documentElement);
  1364. };
  1365. var d3_selectionPrototype = d3.selection.prototype = [];
  1366. d3_selectionPrototype.select = function(selector) {
  1367. var subgroups = [], subgroup, subnode, group, node;
  1368. selector = d3_selection_selector(selector);
  1369. for (var j = -1, m = this.length; ++j < m; ) {
  1370. subgroups.push(subgroup = []);
  1371. subgroup.parentNode = (group = this[j]).parentNode;
  1372. for (var i = -1, n = group.length; ++i < n; ) {
  1373. if (node = group[i]) {
  1374. subgroup.push(subnode = selector.call(node, node.__data__, i, j));
  1375. if (subnode && "__data__" in node) subnode.__data__ = node.__data__;
  1376. } else {
  1377. subgroup.push(null);
  1378. }
  1379. }
  1380. }
  1381. return d3_selection(subgroups);
  1382. };
  1383. function d3_selection_selector(selector) {
  1384. return typeof selector === "function" ? selector : function() {
  1385. return d3_select(selector, this);
  1386. };
  1387. }
  1388. d3_selectionPrototype.selectAll = function(selector) {
  1389. var subgroups = [], subgroup, node;
  1390. selector = d3_selection_selectorAll(selector);
  1391. for (var j = -1, m = this.length; ++j < m; ) {
  1392. for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
  1393. if (node = group[i]) {
  1394. subgroups.push(subgroup = d3_array(selector.call(node, node.__data__, i, j)));
  1395. subgroup.parentNode = node;
  1396. }
  1397. }
  1398. }
  1399. return d3_selection(subgroups);
  1400. };
  1401. function d3_selection_selectorAll(selector) {
  1402. return typeof selector === "function" ? selector : function() {
  1403. return d3_selectAll(selector, this);
  1404. };
  1405. }
  1406. var d3_nsXhtml = "http://www.w3.org/1999/xhtml";
  1407. var d3_nsPrefix = {
  1408. svg: "http://www.w3.org/2000/svg",
  1409. xhtml: d3_nsXhtml,
  1410. xlink: "http://www.w3.org/1999/xlink",
  1411. xml: "http://www.w3.org/XML/1998/namespace",
  1412. xmlns: "http://www.w3.org/2000/xmlns/"
  1413. };
  1414. d3.ns = {
  1415. prefix: d3_nsPrefix,
  1416. qualify: function(name) {
  1417. var i = name.indexOf(":"), prefix = name;
  1418. if (i >= 0 && (prefix = name.slice(0, i)) !== "xmlns") name = name.slice(i + 1);
  1419. return d3_nsPrefix.hasOwnProperty(prefix) ? {
  1420. space: d3_nsPrefix[prefix],
  1421. local: name
  1422. } : name;
  1423. }
  1424. };
  1425. d3_selectionPrototype.attr = function(name, value) {
  1426. if (arguments.length < 2) {
  1427. if (typeof name === "string") {
  1428. var node = this.node();
  1429. name = d3.ns.qualify(name);
  1430. return name.local ? node.getAttributeNS(name.space, name.local) : node.getAttribute(name);
  1431. }
  1432. for (value in name) this.each(d3_selection_attr(value, name[value]));
  1433. return this;
  1434. }
  1435. return this.each(d3_selection_attr(name, value));
  1436. };
  1437. function d3_selection_attr(name, value) {
  1438. name = d3.ns.qualify(name);
  1439. function attrNull() {
  1440. this.removeAttribute(name);
  1441. }
  1442. function attrNullNS() {
  1443. this.removeAttributeNS(name.space, name.local);
  1444. }
  1445. function attrConstant() {
  1446. this.setAttribute(name, value);
  1447. }
  1448. function attrConstantNS() {
  1449. this.setAttributeNS(name.space, name.local, value);
  1450. }
  1451. function attrFunction() {
  1452. var x = value.apply(this, arguments);
  1453. if (x == null) this.removeAttribute(name); else this.setAttribute(name, x);
  1454. }
  1455. function attrFunctionNS() {
  1456. var x = value.apply(this, arguments);
  1457. if (x == null) this.removeAttributeNS(name.space, name.local); else this.setAttributeNS(name.space, name.local, x);
  1458. }
  1459. return value == null ? name.local ? attrNullNS : attrNull : typeof value === "function" ? name.local ? attrFunctionNS : attrFunction : name.local ? attrConstantNS : attrConstant;
  1460. }
  1461. function d3_collapse(s) {
  1462. return s.trim().replace(/\s+/g, " ");
  1463. }
  1464. d3_selectionPrototype.classed = function(name, value) {
  1465. if (arguments.length < 2) {
  1466. if (typeof name === "string") {
  1467. var node = this.node(), n = (name = d3_selection_classes(name)).length, i = -1;
  1468. if (value = node.classList) {
  1469. while (++i < n) if (!value.contains(name[i])) return false;
  1470. } else {
  1471. value = node.getAttribute("class");
  1472. while (++i < n) if (!d3_selection_classedRe(name[i]).test(value)) return false;
  1473. }
  1474. return true;
  1475. }
  1476. for (value in name) this.each(d3_selection_classed(value, name[value]));
  1477. return this;
  1478. }
  1479. return this.each(d3_selection_classed(name, value));
  1480. };
  1481. function d3_selection_classedRe(name) {
  1482. return new RegExp("(?:^|\\s+)" + d3.requote(name) + "(?:\\s+|$)", "g");
  1483. }
  1484. function d3_selection_classes(name) {
  1485. return (name + "").trim().split(/^|\s+/);
  1486. }
  1487. function d3_selection_classed(name, value) {
  1488. name = d3_selection_classes(name).map(d3_selection_classedName);
  1489. var n = name.length;
  1490. function classedConstant() {
  1491. var i = -1;
  1492. while (++i < n) name[i](this, value);
  1493. }
  1494. function classedFunction() {
  1495. var i = -1, x = value.apply(this, arguments);
  1496. while (++i < n) name[i](this, x);
  1497. }
  1498. return typeof value === "function" ? classedFunction : classedConstant;
  1499. }
  1500. function d3_selection_classedName(name) {
  1501. var re = d3_selection_classedRe(name);
  1502. return function(node, value) {
  1503. if (c = node.classList) return value ? c.add(name) : c.remove(name);
  1504. var c = node.getAttribute("class") || "";
  1505. if (value) {
  1506. re.lastIndex = 0;
  1507. if (!re.test(c)) node.setAttribute("class", d3_collapse(c + " " + name));
  1508. } else {
  1509. node.setAttribute("class", d3_collapse(c.replace(re, " ")));
  1510. }
  1511. };
  1512. }
  1513. d3_selectionPrototype.style = function(name, value, priority) {
  1514. var n = arguments.length;
  1515. if (n < 3) {
  1516. if (typeof name !== "string") {
  1517. if (n < 2) value = "";
  1518. for (priority in name) this.each(d3_selection_style(priority, name[priority], value));
  1519. return this;
  1520. }
  1521. if (n < 2) {
  1522. var node = this.node();
  1523. return d3_window(node).getComputedStyle(node, null).getPropertyValue(name);
  1524. }
  1525. priority = "";
  1526. }
  1527. return this.each(d3_selection_style(name, value, priority));
  1528. };
  1529. function d3_selection_style(name, value, priority) {
  1530. function styleNull() {
  1531. this.style.removeProperty(name);
  1532. }
  1533. function styleConstant() {
  1534. this.style.setProperty(name, value, priority);
  1535. }
  1536. function styleFunction() {
  1537. var x = value.apply(this, arguments);
  1538. if (x == null) this.style.removeProperty(name); else this.style.setProperty(name, x, priority);
  1539. }
  1540. return value == null ? styleNull : typeof value === "function" ? styleFunction : styleConstant;
  1541. }
  1542. d3_selectionPrototype.property = function(name, value) {
  1543. if (arguments.length < 2) {
  1544. if (typeof name === "string") return this.node()[name];
  1545. for (value in name) this.each(d3_selection_property(value, name[value]));
  1546. return this;
  1547. }
  1548. return this.each(d3_selection_property(name, value));
  1549. };
  1550. function d3_selection_property(name, value) {
  1551. function propertyNull() {
  1552. delete this[name];
  1553. }
  1554. function propertyConstant() {
  1555. this[name] = value;
  1556. }
  1557. function propertyFunction() {
  1558. var x = value.apply(this, arguments);
  1559. if (x == null) delete this[name]; else this[name] = x;
  1560. }
  1561. return value == null ? propertyNull : typeof value === "function" ? propertyFunction : propertyConstant;
  1562. }
  1563. d3_selectionPrototype.text = function(value) {
  1564. return arguments.length ? this.each(typeof value === "function" ? function() {
  1565. var v = value.apply(this, arguments);
  1566. this.textContent = v == null ? "" : v;
  1567. } : value == null ? function() {
  1568. this.textContent = "";
  1569. } : function() {
  1570. this.textContent = value;
  1571. }) : this.node().textContent;
  1572. };
  1573. d3_selectionPrototype.html = function(value) {
  1574. return arguments.length ? this.each(typeof value === "function" ? function() {
  1575. var v = value.apply(this, arguments);
  1576. this.innerHTML = v == null ? "" : v;
  1577. } : value == null ? function() {
  1578. this.innerHTML = "";
  1579. } : function() {
  1580. this.innerHTML = value;
  1581. }) : this.node().innerHTML;
  1582. };
  1583. d3_selectionPrototype.append = function(name) {
  1584. name = d3_selection_creator(name);
  1585. return this.select(function() {
  1586. return this.appendChild(name.apply(this, arguments));
  1587. });
  1588. };
  1589. function d3_selection_creator(name) {
  1590. function create() {
  1591. var document = this.ownerDocument, namespace = this.namespaceURI;
  1592. return namespace === d3_nsXhtml && document.documentElement.namespaceURI === d3_nsXhtml ? document.createElement(name) : document.createElementNS(namespace, name);
  1593. }
  1594. function createNS() {
  1595. return this.ownerDocument.createElementNS(name.space, name.local);
  1596. }
  1597. return typeof name === "function" ? name : (name = d3.ns.qualify(name)).local ? createNS : create;
  1598. }
  1599. d3_selectionPrototype.insert = function(name, before) {
  1600. name = d3_selection_creator(name);
  1601. before = d3_selection_selector(before);
  1602. return this.select(function() {
  1603. return this.insertBefore(name.apply(this, arguments), before.apply(this, arguments) || null);
  1604. });
  1605. };
  1606. d3_selectionPrototype.remove = function() {
  1607. return this.each(d3_selectionRemove);
  1608. };
  1609. function d3_selectionRemove() {
  1610. var parent = this.parentNode;
  1611. if (parent) parent.removeChild(this);
  1612. }
  1613. d3_selectionPrototype.data = function(value, key) {
  1614. var i = -1, n = this.length, group, node;
  1615. if (!arguments.length) {
  1616. value = new Array(n = (group = this[0]).length);
  1617. while (++i < n) {
  1618. if (node = group[i]) {
  1619. value[i] = node.__data__;
  1620. }
  1621. }
  1622. return value;
  1623. }
  1624. function bind(group, groupData) {
  1625. var i, n = group.length, m = groupData.length, n0 = Math.min(n, m), updateNodes = new Array(m), enterNodes = new Array(m), exitNodes = new Array(n), node, nodeData;
  1626. if (key) {
  1627. var nodeByKeyValue = new d3_Map(), keyValues = new Array(n), keyValue;
  1628. for (i = -1; ++i < n; ) {
  1629. if (node = group[i]) {
  1630. if (nodeByKeyValue.has(keyValue = key.call(node, node.__data__, i))) {
  1631. exitNodes[i] = node;
  1632. } else {
  1633. nodeByKeyValue.set(keyValue, node);
  1634. }
  1635. keyValues[i] = keyValue;
  1636. }
  1637. }
  1638. for (i = -1; ++i < m; ) {
  1639. if (!(node = nodeByKeyValue.get(keyValue = key.call(groupData, nodeData = groupData[i], i)))) {
  1640. enterNodes[i] = d3_selection_dataNode(nodeData);
  1641. } else if (node !== true) {
  1642. updateNodes[i] = node;
  1643. node.__data__ = nodeData;
  1644. }
  1645. nodeByKeyValue.set(keyValue, true);
  1646. }
  1647. for (i = -1; ++i < n; ) {
  1648. if (i in keyValues && nodeByKeyValue.get(keyValues[i]) !== true) {
  1649. exitNodes[i] = group[i];
  1650. }
  1651. }
  1652. } else {
  1653. for (i = -1; ++i < n0; ) {
  1654. node = group[i];
  1655. nodeData = groupData[i];
  1656. if (node) {
  1657. node.__data__ = nodeData;
  1658. updateNodes[i] = node;
  1659. } else {
  1660. enterNodes[i] = d3_selection_dataNode(nodeData);
  1661. }
  1662. }
  1663. for (;i < m; ++i) {
  1664. enterNodes[i] = d3_selection_dataNode(groupData[i]);
  1665. }
  1666. for (;i < n; ++i) {
  1667. exitNodes[i] = group[i];
  1668. }
  1669. }
  1670. enterNodes.update = updateNodes;
  1671. enterNodes.parentNode = updateNodes.parentNode = exitNodes.parentNode = group.parentNode;
  1672. enter.push(enterNodes);
  1673. update.push(updateNodes);
  1674. exit.push(exitNodes);
  1675. }
  1676. var enter = d3_selection_enter([]), update = d3_selection([]), exit = d3_selection([]);
  1677. if (typeof value === "function") {
  1678. while (++i < n) {
  1679. bind(group = this[i], value.call(group, group.parentNode.__data__, i));
  1680. }
  1681. } else {
  1682. while (++i < n) {
  1683. bind(group = this[i], value);
  1684. }
  1685. }
  1686. update.enter = function() {
  1687. return enter;
  1688. };
  1689. update.exit = function() {
  1690. return exit;
  1691. };
  1692. return update;
  1693. };
  1694. function d3_selection_dataNode(data) {
  1695. return {
  1696. __data__: data
  1697. };
  1698. }
  1699. d3_selectionPrototype.datum = function(value) {
  1700. return arguments.length ? this.property("__data__", value) : this.property("__data__");
  1701. };
  1702. d3_selectionPrototype.filter = function(filter) {
  1703. var subgroups = [], subgroup, group, node;
  1704. if (typeof filter !== "function") filter = d3_selection_filter(filter);
  1705. for (var j = 0, m = this.length; j < m; j++) {
  1706. subgroups.push(subgroup = []);
  1707. subgroup.parentNode = (group = this[j]).parentNode;
  1708. for (var i = 0, n = group.length; i < n; i++) {
  1709. if ((node = group[i]) && filter.call(node, node.__data__, i, j)) {
  1710. subgroup.push(node);
  1711. }
  1712. }
  1713. }
  1714. return d3_selection(subgroups);
  1715. };
  1716. function d3_selection_filter(selector) {
  1717. return function() {
  1718. return d3_selectMatches(this, selector);
  1719. };
  1720. }
  1721. d3_selectionPrototype.order = function() {
  1722. for (var j = -1, m = this.length; ++j < m; ) {
  1723. for (var group = this[j], i = group.length - 1, next = group[i], node; --i >= 0; ) {
  1724. if (node = group[i]) {
  1725. if (next && next !== node.nextSibling) next.parentNode.insertBefore(node, next);
  1726. next = node;
  1727. }
  1728. }
  1729. }
  1730. return this;
  1731. };
  1732. d3_selectionPrototype.sort = function(comparator) {
  1733. comparator = d3_selection_sortComparator.apply(this, arguments);
  1734. for (var j = -1, m = this.length; ++j < m; ) this[j].sort(comparator);
  1735. return this.order();
  1736. };
  1737. function d3_selection_sortComparator(comparator) {
  1738. if (!arguments.length) comparator = d3_ascending;
  1739. return function(a, b) {
  1740. return a && b ? comparator(a.__data__, b.__data__) : !a - !b;
  1741. };
  1742. }
  1743. d3_selectionPrototype.each = function(callback) {
  1744. return d3_selection_each(this, function(node, i, j) {
  1745. callback.call(node, node.__data__, i, j);
  1746. });
  1747. };
  1748. function d3_selection_each(groups, callback) {
  1749. for (var j = 0, m = groups.length; j < m; j++) {
  1750. for (var group = groups[j], i = 0, n = group.length, node; i < n; i++) {
  1751. if (node = group[i]) callback(node, i, j);
  1752. }
  1753. }
  1754. return groups;
  1755. }
  1756. d3_selectionPrototype.call = function(callback) {
  1757. var args = d3_array(arguments);
  1758. callback.apply(args[0] = this, args);
  1759. return this;
  1760. };
  1761. d3_selectionPrototype.empty = function() {
  1762. return !this.node();
  1763. };
  1764. d3_selectionPrototype.node = function() {
  1765. for (var j = 0, m = this.length; j < m; j++) {
  1766. for (var group = this[j], i = 0, n = group.length; i < n; i++) {
  1767. var node = group[i];
  1768. if (node) return node;
  1769. }
  1770. }
  1771. return null;
  1772. };
  1773. d3_selectionPrototype.size = function() {
  1774. var n = 0;
  1775. d3_selection_each(this, function() {
  1776. ++n;
  1777. });
  1778. return n;
  1779. };
  1780. function d3_selection_enter(selection) {
  1781. d3_subclass(selection, d3_selection_enterPrototype);
  1782. return selection;
  1783. }
  1784. var d3_selection_enterPrototype = [];
  1785. d3.selection.enter = d3_selection_enter;
  1786. d3.selection.enter.prototype = d3_selection_enterPrototype;
  1787. d3_selection_enterPrototype.append = d3_selectionPrototype.append;
  1788. d3_selection_enterPrototype.empty = d3_selectionPrototype.empty;
  1789. d3_selection_enterPrototype.node = d3_selectionPrototype.node;
  1790. d3_selection_enterPrototype.call = d3_selectionPrototype.call;
  1791. d3_selection_enterPrototype.size = d3_selectionPrototype.size;
  1792. d3_selection_enterPrototype.select = function(selector) {
  1793. var subgroups = [], subgroup, subnode, upgroup, group, node;
  1794. for (var j = -1, m = this.length; ++j < m; ) {
  1795. upgroup = (group = this[j]).update;
  1796. subgroups.push(subgroup = []);
  1797. subgroup.parentNode = group.parentNode;
  1798. for (var i = -1, n = group.length; ++i < n; ) {
  1799. if (node = group[i]) {
  1800. subgroup.push(upgroup[i] = subnode = selector.call(group.parentNode, node.__data__, i, j));
  1801. subnode.__data__ = node.__data__;
  1802. } else {
  1803. subgroup.push(null);
  1804. }
  1805. }
  1806. }
  1807. return d3_selection(subgroups);
  1808. };
  1809. d3_selection_enterPrototype.insert = function(name, before) {
  1810. if (arguments.length < 2) before = d3_selection_enterInsertBefore(this);
  1811. return d3_selectionPrototype.insert.call(this, name, before);
  1812. };
  1813. function d3_selection_enterInsertBefore(enter) {
  1814. var i0, j0;
  1815. return function(d, i, j) {
  1816. var group = enter[j].update, n = group.length, node;
  1817. if (j != j0) j0 = j, i0 = 0;
  1818. if (i >= i0) i0 = i + 1;
  1819. while (!(node = group[i0]) && ++i0 < n) ;
  1820. return node;
  1821. };
  1822. }
  1823. d3.select = function(node) {
  1824. var group;
  1825. if (typeof node === "string") {
  1826. group = [ d3_select(node, d3_document) ];
  1827. group.parentNode = d3_document.documentElement;
  1828. } else {
  1829. group = [ node ];
  1830. group.parentNode = d3_documentElement(node);
  1831. }
  1832. return d3_selection([ group ]);
  1833. };
  1834. d3.selectAll = function(nodes) {
  1835. var group;
  1836. if (typeof nodes === "string") {
  1837. group = d3_array(d3_selectAll(nodes, d3_document));
  1838. group.parentNode = d3_document.documentElement;
  1839. } else {
  1840. group = d3_array(nodes);
  1841. group.parentNode = null;
  1842. }
  1843. return d3_selection([ group ]);
  1844. };
  1845. d3_selectionPrototype.on = function(type, listener, capture) {
  1846. var n = arguments.length;
  1847. if (n < 3) {
  1848. if (typeof type !== "string") {
  1849. if (n < 2) listener = false;
  1850. for (capture in type) this.each(d3_selection_on(capture, type[capture], listener));
  1851. return this;
  1852. }
  1853. if (n < 2) return (n = this.node()["__on" + type]) && n._;
  1854. capture = false;
  1855. }
  1856. return this.each(d3_selection_on(type, listener, capture));
  1857. };
  1858. function d3_selection_on(type, listener, capture) {
  1859. var name = "__on" + type, i = type.indexOf("."), wrap = d3_selection_onListener;
  1860. if (i > 0) type = type.slice(0, i);
  1861. var filter = d3_selection_onFilters.get(type);
  1862. if (filter) type = filter, wrap = d3_selection_onFilter;
  1863. function onRemove() {
  1864. var l = this[name];
  1865. if (l) {
  1866. this.removeEventListener(type, l, l.$);
  1867. delete this[name];
  1868. }
  1869. }
  1870. function onAdd() {
  1871. var l = wrap(listener, d3_array(arguments));
  1872. onRemove.call(this);
  1873. this.addEventListener(type, this[name] = l, l.$ = capture);
  1874. l._ = listener;
  1875. }
  1876. function removeAll() {
  1877. var re = new RegExp("^__on([^.]+)" + d3.requote(type) + "$"), match;
  1878. for (var name in this) {
  1879. if (match = name.match(re)) {
  1880. var l = this[name];
  1881. this.removeEventListener(match[1], l, l.$);
  1882. delete this[name];
  1883. }
  1884. }
  1885. }
  1886. return i ? listener ? onAdd : onRemove : listener ? d3_noop : removeAll;
  1887. }
  1888. var d3_selection_onFilters = d3.map({
  1889. mouseenter: "mouseover",
  1890. mouseleave: "mouseout"
  1891. });
  1892. if (d3_document) {
  1893. d3_selection_onFilters.forEach(function(k) {
  1894. if ("on" + k in d3_document) d3_selection_onFilters.remove(k);
  1895. });
  1896. }
  1897. function d3_selection_onListener(listener, argumentz) {
  1898. return function(e) {
  1899. var o = d3.event;
  1900. d3.event = e;
  1901. argumentz[0] = this.__data__;
  1902. try {
  1903. listener.apply(this, argumentz);
  1904. } finally {
  1905. d3.event = o;
  1906. }
  1907. };
  1908. }
  1909. function d3_selection_onFilter(listener, argumentz) {
  1910. var l = d3_selection_onListener(listener, argumentz);
  1911. return function(e) {
  1912. var target = this, related = e.relatedTarget;
  1913. if (!related || related !== target && !(related.compareDocumentPosition(target) & 8)) {
  1914. l.call(target, e);
  1915. }
  1916. };
  1917. }
  1918. var d3_event_dragSelect, d3_event_dragId = 0;
  1919. function d3_event_dragSuppress(node) {
  1920. var name = ".dragsuppress-" + ++d3_event_dragId, click = "click" + name, w = d3.select(d3_window(node)).on("touchmove" + name, d3_eventPreventDefault).on("dragstart" + name, d3_eventPreventDefault).on("selectstart" + name, d3_eventPreventDefault);
  1921. if (d3_event_dragSelect == null) {
  1922. d3_event_dragSelect = "onselectstart" in node ? false : d3_vendorSymbol(node.style, "userSelect");
  1923. }
  1924. if (d3_event_dragSelect) {
  1925. var style = d3_documentElement(node).style, select = style[d3_event_dragSelect];
  1926. style[d3_event_dragSelect] = "none";
  1927. }
  1928. return function(suppressClick) {
  1929. w.on(name, null);
  1930. if (d3_event_dragSelect) style[d3_event_dragSelect] = select;
  1931. if (suppressClick) {
  1932. var off = function() {
  1933. w.on(click, null);
  1934. };
  1935. w.on(click, function() {
  1936. d3_eventPreventDefault();
  1937. off();
  1938. }, true);
  1939. setTimeout(off, 0);
  1940. }
  1941. };
  1942. }
  1943. d3.mouse = function(container) {
  1944. return d3_mousePoint(container, d3_eventSource());
  1945. };
  1946. var d3_mouse_bug44083 = this.navigator && /WebKit/.test(this.navigator.userAgent) ? -1 : 0;
  1947. function d3_mousePoint(container, e) {
  1948. if (e.changedTouches) e = e.changedTouches[0];
  1949. var svg = container.ownerSVGElement || container;
  1950. if (svg.createSVGPoint) {
  1951. var point = svg.createSVGPoint();
  1952. if (d3_mouse_bug44083 < 0) {
  1953. var window = d3_window(container);
  1954. if (window.scrollX || window.scrollY) {
  1955. svg = d3.select("body").append("svg").style({
  1956. position: "absolute",
  1957. top: 0,
  1958. left: 0,
  1959. margin: 0,
  1960. padding: 0,
  1961. border: "none"
  1962. }, "important");
  1963. var ctm = svg[0][0].getScreenCTM();
  1964. d3_mouse_bug44083 = !(ctm.f || ctm.e);
  1965. svg.remove();
  1966. }
  1967. }
  1968. if (d3_mouse_bug44083) point.x = e.pageX, point.y = e.pageY; else point.x = e.clientX,
  1969. point.y = e.clientY;
  1970. point = point.matrixTransform(container.getScreenCTM().inverse());
  1971. return [ point.x, point.y ];
  1972. }
  1973. var rect = container.getBoundingClientRect();
  1974. return [ e.clientX - rect.left - container.clientLeft, e.clientY - rect.top - container.clientTop ];
  1975. }
  1976. d3.touch = function(container, touches, identifier) {
  1977. if (arguments.length < 3) identifier = touches, touches = d3_eventSource().changedTouches;
  1978. if (touches) for (var i = 0, n = touches.length, touch; i < n; ++i) {
  1979. if ((touch = touches[i]).identifier === identifier) {
  1980. return d3_mousePoint(container, touch);
  1981. }
  1982. }
  1983. };
  1984. d3.behavior.drag = function() {
  1985. var event = d3_eventDispatch(drag, "drag", "dragstart", "dragend"), origin = null, mousedown = dragstart(d3_noop, d3.mouse, d3_window, "mousemove", "mouseup"), touchstart = dragstart(d3_behavior_dragTouchId, d3.touch, d3_identity, "touchmove", "touchend");
  1986. function drag() {
  1987. this.on("mousedown.drag", mousedown).on("touchstart.drag", touchstart);
  1988. }
  1989. function dragstart(id, position, subject, move, end) {
  1990. return function() {
  1991. var that = this, target = d3.event.target.correspondingElement || d3.event.target, parent = that.parentNode, dispatch = event.of(that, arguments), dragged = 0, dragId = id(), dragName = ".drag" + (dragId == null ? "" : "-" + dragId), dragOffset, dragSubject = d3.select(subject(target)).on(move + dragName, moved).on(end + dragName, ended), dragRestore = d3_event_dragSuppress(target), position0 = position(parent, dragId);
  1992. if (origin) {
  1993. dragOffset = origin.apply(that, arguments);
  1994. dragOffset = [ dragOffset.x - position0[0], dragOffset.y - position0[1] ];
  1995. } else {
  1996. dragOffset = [ 0, 0 ];
  1997. }
  1998. dispatch({
  1999. type: "dragstart"
  2000. });
  2001. function moved() {
  2002. var position1 = position(parent, dragId), dx, dy;
  2003. if (!position1) return;
  2004. dx = position1[0] - position0[0];
  2005. dy = position1[1] - position0[1];
  2006. dragged |= dx | dy;
  2007. position0 = position1;
  2008. dispatch({
  2009. type: "drag",
  2010. x: position1[0] + dragOffset[0],
  2011. y: position1[1] + dragOffset[1],
  2012. dx: dx,
  2013. dy: dy
  2014. });
  2015. }
  2016. function ended() {
  2017. if (!position(parent, dragId)) return;
  2018. dragSubject.on(move + dragName, null).on(end + dragName, null);
  2019. dragRestore(dragged);
  2020. dispatch({
  2021. type: "dragend"
  2022. });
  2023. }
  2024. };
  2025. }
  2026. drag.origin = function(x) {
  2027. if (!arguments.length) return origin;
  2028. origin = x;
  2029. return drag;
  2030. };
  2031. return d3.rebind(drag, event, "on");
  2032. };
  2033. function d3_behavior_dragTouchId() {
  2034. return d3.event.changedTouches[0].identifier;
  2035. }
  2036. d3.touches = function(container, touches) {
  2037. if (arguments.length < 2) touches = d3_eventSource().touches;
  2038. return touches ? d3_array(touches).map(function(touch) {
  2039. var point = d3_mousePoint(container, touch);
  2040. point.identifier = touch.identifier;
  2041. return point;
  2042. }) : [];
  2043. };
  2044. var ε = 1e-6, ε2 = ε * ε, π = Math.PI, τ = 2 * π, τε = τ - ε, halfπ = π / 2, d3_radians = π / 180, d3_degrees = 180 / π;
  2045. function d3_sgn(x) {
  2046. return x > 0 ? 1 : x < 0 ? -1 : 0;
  2047. }
  2048. function d3_cross2d(a, b, c) {
  2049. return (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]);
  2050. }
  2051. function d3_acos(x) {
  2052. return x > 1 ? 0 : x < -1 ? π : Math.acos(x);
  2053. }
  2054. function d3_asin(x) {
  2055. return x > 1 ? halfπ : x < -1 ? -halfπ : Math.asin(x);
  2056. }
  2057. function d3_sinh(x) {
  2058. return ((x = Math.exp(x)) - 1 / x) / 2;
  2059. }
  2060. function d3_cosh(x) {
  2061. return ((x = Math.exp(x)) + 1 / x) / 2;
  2062. }
  2063. function d3_tanh(x) {
  2064. return ((x = Math.exp(2 * x)) - 1) / (x + 1);
  2065. }
  2066. function d3_haversin(x) {
  2067. return (x = Math.sin(x / 2)) * x;
  2068. }
  2069. var ρ = Math.SQRT2, ρ2 = 2, ρ4 = 4;
  2070. d3.interpolateZoom = function(p0, p1) {
  2071. var ux0 = p0[0], uy0 = p0[1], w0 = p0[2], ux1 = p1[0], uy1 = p1[1], w1 = p1[2], dx = ux1 - ux0, dy = uy1 - uy0, d2 = dx * dx + dy * dy, i, S;
  2072. if (d2 < ε2) {
  2073. S = Math.log(w1 / w0) / ρ;
  2074. i = function(t) {
  2075. return [ ux0 + t * dx, uy0 + t * dy, w0 * Math.exp(ρ * t * S) ];
  2076. };
  2077. } else {
  2078. var d1 = Math.sqrt(d2), b0 = (w1 * w1 - w0 * w0 + ρ4 * d2) / (2 * w0 * ρ2 * d1), b1 = (w1 * w1 - w0 * w0 - ρ4 * d2) / (2 * w1 * ρ2 * d1), r0 = Math.log(Math.sqrt(b0 * b0 + 1) - b0), r1 = Math.log(Math.sqrt(b1 * b1 + 1) - b1);
  2079. S = (r1 - r0) / ρ;
  2080. i = function(t) {
  2081. var s = t * S, coshr0 = d3_cosh(r0), u = w0 / (ρ2 * d1) * (coshr0 * d3_tanh(ρ * s + r0) - d3_sinh(r0));
  2082. return [ ux0 + u * dx, uy0 + u * dy, w0 * coshr0 / d3_cosh(ρ * s + r0) ];
  2083. };
  2084. }
  2085. i.duration = S * 1e3;
  2086. return i;
  2087. };
  2088. d3.behavior.zoom = function() {
  2089. var view = {
  2090. x: 0,
  2091. y: 0,
  2092. k: 1
  2093. }, translate0, center0, center, size = [ 960, 500 ], scaleExtent = d3_behavior_zoomInfinity, duration = 250, zooming = 0, mousedown = "mousedown.zoom", mousemove = "mousemove.zoom", mouseup = "mouseup.zoom", mousewheelTimer, touchstart = "touchstart.zoom", touchtime, event = d3_eventDispatch(zoom, "zoomstart", "zoom", "zoomend"), x0, x1, y0, y1;
  2094. if (!d3_behavior_zoomWheel) {
  2095. d3_behavior_zoomWheel = "onwheel" in d3_document ? (d3_behavior_zoomDelta = function() {
  2096. return -d3.event.deltaY * (d3.event.deltaMode ? 120 : 1);
  2097. }, "wheel") : "onmousewheel" in d3_document ? (d3_behavior_zoomDelta = function() {
  2098. return d3.event.wheelDelta;
  2099. }, "mousewheel") : (d3_behavior_zoomDelta = function() {
  2100. return -d3.event.detail;
  2101. }, "MozMousePixelScroll");
  2102. }
  2103. function zoom(g) {
  2104. g.on(mousedown, mousedowned).on(d3_behavior_zoomWheel + ".zoom", mousewheeled).on("dblclick.zoom", dblclicked).on(touchstart, touchstarted);
  2105. }
  2106. zoom.event = function(g) {
  2107. g.each(function() {
  2108. var dispatch = event.of(this, arguments), view1 = view;
  2109. if (d3_transitionInheritId) {
  2110. d3.select(this).transition().each("start.zoom", function() {
  2111. view = this.__chart__ || {
  2112. x: 0,
  2113. y: 0,
  2114. k: 1
  2115. };
  2116. zoomstarted(dispatch);
  2117. }).tween("zoom:zoom", function() {
  2118. var dx = size[0], dy = size[1], cx = center0 ? center0[0] : dx / 2, cy = center0 ? center0[1] : dy / 2, i = d3.interpolateZoom([ (cx - view.x) / view.k, (cy - view.y) / view.k, dx / view.k ], [ (cx - view1.x) / view1.k, (cy - view1.y) / view1.k, dx / view1.k ]);
  2119. return function(t) {
  2120. var l = i(t), k = dx / l[2];
  2121. this.__chart__ = view = {
  2122. x: cx - l[0] * k,
  2123. y: cy - l[1] * k,
  2124. k: k
  2125. };
  2126. zoomed(dispatch);
  2127. };
  2128. }).each("interrupt.zoom", function() {
  2129. zoomended(dispatch);
  2130. }).each("end.zoom", function() {
  2131. zoomended(dispatch);
  2132. });
  2133. } else {
  2134. this.__chart__ = view;
  2135. zoomstarted(dispatch);
  2136. zoomed(dispatch);
  2137. zoomended(dispatch);
  2138. }
  2139. });
  2140. };
  2141. zoom.translate = function(_) {
  2142. if (!arguments.length) return [ view.x, view.y ];
  2143. view = {
  2144. x: +_[0],
  2145. y: +_[1],
  2146. k: view.k
  2147. };
  2148. rescale();
  2149. return zoom;
  2150. };
  2151. zoom.scale = function(_) {
  2152. if (!arguments.length) return view.k;
  2153. view = {
  2154. x: view.x,
  2155. y: view.y,
  2156. k: null
  2157. };
  2158. scaleTo(+_);
  2159. rescale();
  2160. return zoom;
  2161. };
  2162. zoom.scaleExtent = function(_) {
  2163. if (!arguments.length) return scaleExtent;
  2164. scaleExtent = _ == null ? d3_behavior_zoomInfinity : [ +_[0], +_[1] ];
  2165. return zoom;
  2166. };
  2167. zoom.center = function(_) {
  2168. if (!arguments.length) return center;
  2169. center = _ && [ +_[0], +_[1] ];
  2170. return zoom;
  2171. };
  2172. zoom.size = function(_) {
  2173. if (!arguments.length) return size;
  2174. size = _ && [ +_[0], +_[1] ];
  2175. return zoom;
  2176. };
  2177. zoom.duration = function(_) {
  2178. if (!arguments.length) return duration;
  2179. duration = +_;
  2180. return zoom;
  2181. };
  2182. zoom.x = function(z) {
  2183. if (!arguments.length) return x1;
  2184. x1 = z;
  2185. x0 = z.copy();
  2186. view = {
  2187. x: 0,
  2188. y: 0,
  2189. k: 1
  2190. };
  2191. return zoom;
  2192. };
  2193. zoom.y = function(z) {
  2194. if (!arguments.length) return y1;
  2195. y1 = z;
  2196. y0 = z.copy();
  2197. view = {
  2198. x: 0,
  2199. y: 0,
  2200. k: 1
  2201. };
  2202. return zoom;
  2203. };
  2204. function location(p) {
  2205. return [ (p[0] - view.x) / view.k, (p[1] - view.y) / view.k ];
  2206. }
  2207. function point(l) {
  2208. return [ l[0] * view.k + view.x, l[1] * view.k + view.y ];
  2209. }
  2210. function scaleTo(s) {
  2211. view.k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], s));
  2212. }
  2213. function translateTo(p, l) {
  2214. l = point(l);
  2215. view.x += p[0] - l[0];
  2216. view.y += p[1] - l[1];
  2217. }
  2218. function zoomTo(that, p, l, k) {
  2219. that.__chart__ = {
  2220. x: view.x,
  2221. y: view.y,
  2222. k: view.k
  2223. };
  2224. scaleTo(Math.pow(2, k));
  2225. translateTo(center0 = p, l);
  2226. that = d3.select(that);
  2227. if (duration > 0) that = that.transition().duration(duration);
  2228. that.call(zoom.event);
  2229. }
  2230. function rescale() {
  2231. if (x1) x1.domain(x0.range().map(function(x) {
  2232. return (x - view.x) / view.k;
  2233. }).map(x0.invert));
  2234. if (y1) y1.domain(y0.range().map(function(y) {
  2235. return (y - view.y) / view.k;
  2236. }).map(y0.invert));
  2237. }
  2238. function zoomstarted(dispatch) {
  2239. if (!zooming++) dispatch({
  2240. type: "zoomstart"
  2241. });
  2242. }
  2243. function zoomed(dispatch) {
  2244. rescale();
  2245. dispatch({
  2246. type: "zoom",
  2247. scale: view.k,
  2248. translate: [ view.x, view.y ]
  2249. });
  2250. }
  2251. function zoomended(dispatch) {
  2252. if (!--zooming) dispatch({
  2253. type: "zoomend"
  2254. }), center0 = null;
  2255. }
  2256. function mousedowned() {
  2257. var that = this, dispatch = event.of(that, arguments), dragged = 0, subject = d3.select(d3_window(that)).on(mousemove, moved).on(mouseup, ended), location0 = location(d3.mouse(that)), dragRestore = d3_event_dragSuppress(that);
  2258. d3_selection_interrupt.call(that);
  2259. zoomstarted(dispatch);
  2260. function moved() {
  2261. dragged = 1;
  2262. translateTo(d3.mouse(that), location0);
  2263. zoomed(dispatch);
  2264. }
  2265. function ended() {
  2266. subject.on(mousemove, null).on(mouseup, null);
  2267. dragRestore(dragged);
  2268. zoomended(dispatch);
  2269. }
  2270. }
  2271. function touchstarted() {
  2272. var that = this, dispatch = event.of(that, arguments), locations0 = {}, distance0 = 0, scale0, zoomName = ".zoom-" + d3.event.changedTouches[0].identifier, touchmove = "touchmove" + zoomName, touchend = "touchend" + zoomName, targets = [], subject = d3.select(that), dragRestore = d3_event_dragSuppress(that);
  2273. started();
  2274. zoomstarted(dispatch);
  2275. subject.on(mousedown, null).on(touchstart, started);
  2276. function relocate() {
  2277. var touches = d3.touches(that);
  2278. scale0 = view.k;
  2279. touches.forEach(function(t) {
  2280. if (t.identifier in locations0) locations0[t.identifier] = location(t);
  2281. });
  2282. return touches;
  2283. }
  2284. function started() {
  2285. var target = d3.event.target;
  2286. d3.select(target).on(touchmove, moved).on(touchend, ended);
  2287. targets.push(target);
  2288. var changed = d3.event.changedTouches;
  2289. for (var i = 0, n = changed.length; i < n; ++i) {
  2290. locations0[changed[i].identifier] = null;
  2291. }
  2292. var touches = relocate(), now = Date.now();
  2293. if (touches.length === 1) {
  2294. if (now - touchtime < 500) {
  2295. var p = touches[0];
  2296. zoomTo(that, p, locations0[p.identifier], Math.floor(Math.log(view.k) / Math.LN2) + 1);
  2297. d3_eventPreventDefault();
  2298. }
  2299. touchtime = now;
  2300. } else if (touches.length > 1) {
  2301. var p = touches[0], q = touches[1], dx = p[0] - q[0], dy = p[1] - q[1];
  2302. distance0 = dx * dx + dy * dy;
  2303. }
  2304. }
  2305. function moved() {
  2306. var touches = d3.touches(that), p0, l0, p1, l1;
  2307. d3_selection_interrupt.call(that);
  2308. for (var i = 0, n = touches.length; i < n; ++i, l1 = null) {
  2309. p1 = touches[i];
  2310. if (l1 = locations0[p1.identifier]) {
  2311. if (l0) break;
  2312. p0 = p1, l0 = l1;
  2313. }
  2314. }
  2315. if (l1) {
  2316. var distance1 = (distance1 = p1[0] - p0[0]) * distance1 + (distance1 = p1[1] - p0[1]) * distance1, scale1 = distance0 && Math.sqrt(distance1 / distance0);
  2317. p0 = [ (p0[0] + p1[0]) / 2, (p0[1] + p1[1]) / 2 ];
  2318. l0 = [ (l0[0] + l1[0]) / 2, (l0[1] + l1[1]) / 2 ];
  2319. scaleTo(scale1 * scale0);
  2320. }
  2321. touchtime = null;
  2322. translateTo(p0, l0);
  2323. zoomed(dispatch);
  2324. }
  2325. function ended() {
  2326. if (d3.event.touches.length) {
  2327. var changed = d3.event.changedTouches;
  2328. for (var i = 0, n = changed.length; i < n; ++i) {
  2329. delete locations0[changed[i].identifier];
  2330. }
  2331. for (var identifier in locations0) {
  2332. return void relocate();
  2333. }
  2334. }
  2335. d3.selectAll(targets).on(zoomName, null);
  2336. subject.on(mousedown, mousedowned).on(touchstart, touchstarted);
  2337. dragRestore();
  2338. zoomended(dispatch);
  2339. }
  2340. }
  2341. function mousewheeled() {
  2342. var dispatch = event.of(this, arguments);
  2343. if (mousewheelTimer) clearTimeout(mousewheelTimer); else d3_selection_interrupt.call(this),
  2344. translate0 = location(center0 = center || d3.mouse(this)), zoomstarted(dispatch);
  2345. mousewheelTimer = setTimeout(function() {
  2346. mousewheelTimer = null;
  2347. zoomended(dispatch);
  2348. }, 50);
  2349. d3_eventPreventDefault();
  2350. scaleTo(Math.pow(2, d3_behavior_zoomDelta() * .002) * view.k);
  2351. translateTo(center0, translate0);
  2352. zoomed(dispatch);
  2353. }
  2354. function dblclicked() {
  2355. var p = d3.mouse(this), k = Math.log(view.k) / Math.LN2;
  2356. zoomTo(this, p, location(p), d3.event.shiftKey ? Math.ceil(k) - 1 : Math.floor(k) + 1);
  2357. }
  2358. return d3.rebind(zoom, event, "on");
  2359. };
  2360. var d3_behavior_zoomInfinity = [ 0, Infinity ], d3_behavior_zoomDelta, d3_behavior_zoomWheel;
  2361. d3.color = d3_color;
  2362. function d3_color() {}
  2363. d3_color.prototype.toString = function() {
  2364. return this.rgb() + "";
  2365. };
  2366. d3.hsl = d3_hsl;
  2367. function d3_hsl(h, s, l) {
  2368. return this instanceof d3_hsl ? void (this.h = +h, this.s = +s, this.l = +l) : arguments.length < 2 ? h instanceof d3_hsl ? new d3_hsl(h.h, h.s, h.l) : d3_rgb_parse("" + h, d3_rgb_hsl, d3_hsl) : new d3_hsl(h, s, l);
  2369. }
  2370. var d3_hslPrototype = d3_hsl.prototype = new d3_color();
  2371. d3_hslPrototype.brighter = function(k) {
  2372. k = Math.pow(.7, arguments.length ? k : 1);
  2373. return new d3_hsl(this.h, this.s, this.l / k);
  2374. };
  2375. d3_hslPrototype.darker = function(k) {
  2376. k = Math.pow(.7, arguments.length ? k : 1);
  2377. return new d3_hsl(this.h, this.s, k * this.l);
  2378. };
  2379. d3_hslPrototype.rgb = function() {
  2380. return d3_hsl_rgb(this.h, this.s, this.l);
  2381. };
  2382. function d3_hsl_rgb(h, s, l) {
  2383. var m1, m2;
  2384. h = isNaN(h) ? 0 : (h %= 360) < 0 ? h + 360 : h;
  2385. s = isNaN(s) ? 0 : s < 0 ? 0 : s > 1 ? 1 : s;
  2386. l = l < 0 ? 0 : l > 1 ? 1 : l;
  2387. m2 = l <= .5 ? l * (1 + s) : l + s - l * s;
  2388. m1 = 2 * l - m2;
  2389. function v(h) {
  2390. if (h > 360) h -= 360; else if (h < 0) h += 360;
  2391. if (h < 60) return m1 + (m2 - m1) * h / 60;
  2392. if (h < 180) return m2;
  2393. if (h < 240) return m1 + (m2 - m1) * (240 - h) / 60;
  2394. return m1;
  2395. }
  2396. function vv(h) {
  2397. return Math.round(v(h) * 255);
  2398. }
  2399. return new d3_rgb(vv(h + 120), vv(h), vv(h - 120));
  2400. }
  2401. d3.hcl = d3_hcl;
  2402. function d3_hcl(h, c, l) {
  2403. return this instanceof d3_hcl ? void (this.h = +h, this.c = +c, this.l = +l) : arguments.length < 2 ? h instanceof d3_hcl ? new d3_hcl(h.h, h.c, h.l) : h instanceof d3_lab ? d3_lab_hcl(h.l, h.a, h.b) : d3_lab_hcl((h = d3_rgb_lab((h = d3.rgb(h)).r, h.g, h.b)).l, h.a, h.b) : new d3_hcl(h, c, l);
  2404. }
  2405. var d3_hclPrototype = d3_hcl.prototype = new d3_color();
  2406. d3_hclPrototype.brighter = function(k) {
  2407. return new d3_hcl(this.h, this.c, Math.min(100, this.l + d3_lab_K * (arguments.length ? k : 1)));
  2408. };
  2409. d3_hclPrototype.darker = function(k) {
  2410. return new d3_hcl(this.h, this.c, Math.max(0, this.l - d3_lab_K * (arguments.length ? k : 1)));
  2411. };
  2412. d3_hclPrototype.rgb = function() {
  2413. return d3_hcl_lab(this.h, this.c, this.l).rgb();
  2414. };
  2415. function d3_hcl_lab(h, c, l) {
  2416. if (isNaN(h)) h = 0;
  2417. if (isNaN(c)) c = 0;
  2418. return new d3_lab(l, Math.cos(h *= d3_radians) * c, Math.sin(h) * c);
  2419. }
  2420. d3.lab = d3_lab;
  2421. function d3_lab(l, a, b) {
  2422. return this instanceof d3_lab ? void (this.l = +l, this.a = +a, this.b = +b) : arguments.length < 2 ? l instanceof d3_lab ? new d3_lab(l.l, l.a, l.b) : l instanceof d3_hcl ? d3_hcl_lab(l.h, l.c, l.l) : d3_rgb_lab((l = d3_rgb(l)).r, l.g, l.b) : new d3_lab(l, a, b);
  2423. }
  2424. var d3_lab_K = 18;
  2425. var d3_lab_X = .95047, d3_lab_Y = 1, d3_lab_Z = 1.08883;
  2426. var d3_labPrototype = d3_lab.prototype = new d3_color();
  2427. d3_labPrototype.brighter = function(k) {
  2428. return new d3_lab(Math.min(100, this.l + d3_lab_K * (arguments.length ? k : 1)), this.a, this.b);
  2429. };
  2430. d3_labPrototype.darker = function(k) {
  2431. return new d3_lab(Math.max(0, this.l - d3_lab_K * (arguments.length ? k : 1)), this.a, this.b);
  2432. };
  2433. d3_labPrototype.rgb = function() {
  2434. return d3_lab_rgb(this.l, this.a, this.b);
  2435. };
  2436. function d3_lab_rgb(l, a, b) {
  2437. var y = (l + 16) / 116, x = y + a / 500, z = y - b / 200;
  2438. x = d3_lab_xyz(x) * d3_lab_X;
  2439. y = d3_lab_xyz(y) * d3_lab_Y;
  2440. z = d3_lab_xyz(z) * d3_lab_Z;
  2441. return new d3_rgb(d3_xyz_rgb(3.2404542 * x - 1.5371385 * y - .4985314 * z), d3_xyz_rgb(-.969266 * x + 1.8760108 * y + .041556 * z), d3_xyz_rgb(.0556434 * x - .2040259 * y + 1.0572252 * z));
  2442. }
  2443. function d3_lab_hcl(l, a, b) {
  2444. return l > 0 ? new d3_hcl(Math.atan2(b, a) * d3_degrees, Math.sqrt(a * a + b * b), l) : new d3_hcl(NaN, NaN, l);
  2445. }
  2446. function d3_lab_xyz(x) {
  2447. return x > .206893034 ? x * x * x : (x - 4 / 29) / 7.787037;
  2448. }
  2449. function d3_xyz_lab(x) {
  2450. return x > .008856 ? Math.pow(x, 1 / 3) : 7.787037 * x + 4 / 29;
  2451. }
  2452. function d3_xyz_rgb(r) {
  2453. return Math.round(255 * (r <= .00304 ? 12.92 * r : 1.055 * Math.pow(r, 1 / 2.4) - .055));
  2454. }
  2455. d3.rgb = d3_rgb;
  2456. function d3_rgb(r, g, b) {
  2457. return this instanceof d3_rgb ? void (this.r = ~~r, this.g = ~~g, this.b = ~~b) : arguments.length < 2 ? r instanceof d3_rgb ? new d3_rgb(r.r, r.g, r.b) : d3_rgb_parse("" + r, d3_rgb, d3_hsl_rgb) : new d3_rgb(r, g, b);
  2458. }
  2459. function d3_rgbNumber(value) {
  2460. return new d3_rgb(value >> 16, value >> 8 & 255, value & 255);
  2461. }
  2462. function d3_rgbString(value) {
  2463. return d3_rgbNumber(value) + "";
  2464. }
  2465. var d3_rgbPrototype = d3_rgb.prototype = new d3_color();
  2466. d3_rgbPrototype.brighter = function(k) {
  2467. k = Math.pow(.7, arguments.length ? k : 1);
  2468. var r = this.r, g = this.g, b = this.b, i = 30;
  2469. if (!r && !g && !b) return new d3_rgb(i, i, i);
  2470. if (r && r < i) r = i;
  2471. if (g && g < i) g = i;
  2472. if (b && b < i) b = i;
  2473. return new d3_rgb(Math.min(255, r / k), Math.min(255, g / k), Math.min(255, b / k));
  2474. };
  2475. d3_rgbPrototype.darker = function(k) {
  2476. k = Math.pow(.7, arguments.length ? k : 1);
  2477. return new d3_rgb(k * this.r, k * this.g, k * this.b);
  2478. };
  2479. d3_rgbPrototype.hsl = function() {
  2480. return d3_rgb_hsl(this.r, this.g, this.b);
  2481. };
  2482. d3_rgbPrototype.toString = function() {
  2483. return "#" + d3_rgb_hex(this.r) + d3_rgb_hex(this.g) + d3_rgb_hex(this.b);
  2484. };
  2485. function d3_rgb_hex(v) {
  2486. return v < 16 ? "0" + Math.max(0, v).toString(16) : Math.min(255, v).toString(16);
  2487. }
  2488. function d3_rgb_parse(format, rgb, hsl) {
  2489. var r = 0, g = 0, b = 0, m1, m2, color;
  2490. m1 = /([a-z]+)\((.*)\)/.exec(format = format.toLowerCase());
  2491. if (m1) {
  2492. m2 = m1[2].split(",");
  2493. switch (m1[1]) {
  2494. case "hsl":
  2495. {
  2496. return hsl(parseFloat(m2[0]), parseFloat(m2[1]) / 100, parseFloat(m2[2]) / 100);
  2497. }
  2498. case "rgb":
  2499. {
  2500. return rgb(d3_rgb_parseNumber(m2[0]), d3_rgb_parseNumber(m2[1]), d3_rgb_parseNumber(m2[2]));
  2501. }
  2502. }
  2503. }
  2504. if (color = d3_rgb_names.get(format)) {
  2505. return rgb(color.r, color.g, color.b);
  2506. }
  2507. if (format != null && format.charAt(0) === "#" && !isNaN(color = parseInt(format.slice(1), 16))) {
  2508. if (format.length === 4) {
  2509. r = (color & 3840) >> 4;
  2510. r = r >> 4 | r;
  2511. g = color & 240;
  2512. g = g >> 4 | g;
  2513. b = color & 15;
  2514. b = b << 4 | b;
  2515. } else if (format.length === 7) {
  2516. r = (color & 16711680) >> 16;
  2517. g = (color & 65280) >> 8;
  2518. b = color & 255;
  2519. }
  2520. }
  2521. return rgb(r, g, b);
  2522. }
  2523. function d3_rgb_hsl(r, g, b) {
  2524. var min = Math.min(r /= 255, g /= 255, b /= 255), max = Math.max(r, g, b), d = max - min, h, s, l = (max + min) / 2;
  2525. if (d) {
  2526. s = l < .5 ? d / (max + min) : d / (2 - max - min);
  2527. if (r == max) h = (g - b) / d + (g < b ? 6 : 0); else if (g == max) h = (b - r) / d + 2; else h = (r - g) / d + 4;
  2528. h *= 60;
  2529. } else {
  2530. h = NaN;
  2531. s = l > 0 && l < 1 ? 0 : h;
  2532. }
  2533. return new d3_hsl(h, s, l);
  2534. }
  2535. function d3_rgb_lab(r, g, b) {
  2536. r = d3_rgb_xyz(r);
  2537. g = d3_rgb_xyz(g);
  2538. b = d3_rgb_xyz(b);
  2539. var x = d3_xyz_lab((.4124564 * r + .3575761 * g + .1804375 * b) / d3_lab_X), y = d3_xyz_lab((.2126729 * r + .7151522 * g + .072175 * b) / d3_lab_Y), z = d3_xyz_lab((.0193339 * r + .119192 * g + .9503041 * b) / d3_lab_Z);
  2540. return d3_lab(116 * y - 16, 500 * (x - y), 200 * (y - z));
  2541. }
  2542. function d3_rgb_xyz(r) {
  2543. return (r /= 255) <= .04045 ? r / 12.92 : Math.pow((r + .055) / 1.055, 2.4);
  2544. }
  2545. function d3_rgb_parseNumber(c) {
  2546. var f = parseFloat(c);
  2547. return c.charAt(c.length - 1) === "%" ? Math.round(f * 2.55) : f;
  2548. }
  2549. var d3_rgb_names = d3.map({
  2550. aliceblue: 15792383,
  2551. antiquewhite: 16444375,
  2552. aqua: 65535,
  2553. aquamarine: 8388564,
  2554. azure: 15794175,
  2555. beige: 16119260,
  2556. bisque: 16770244,
  2557. black: 0,
  2558. blanchedalmond: 16772045,
  2559. blue: 255,
  2560. blueviolet: 9055202,
  2561. brown: 10824234,
  2562. burlywood: 14596231,
  2563. cadetblue: 6266528,
  2564. chartreuse: 8388352,
  2565. chocolate: 13789470,
  2566. coral: 16744272,
  2567. cornflowerblue: 6591981,
  2568. cornsilk: 16775388,
  2569. crimson: 14423100,
  2570. cyan: 65535,
  2571. darkblue: 139,
  2572. darkcyan: 35723,
  2573. darkgoldenrod: 12092939,
  2574. darkgray: 11119017,
  2575. darkgreen: 25600,
  2576. darkgrey: 11119017,
  2577. darkkhaki: 12433259,
  2578. darkmagenta: 9109643,
  2579. darkolivegreen: 5597999,
  2580. darkorange: 16747520,
  2581. darkorchid: 10040012,
  2582. darkred: 9109504,
  2583. darksalmon: 15308410,
  2584. darkseagreen: 9419919,
  2585. darkslateblue: 4734347,
  2586. darkslategray: 3100495,
  2587. darkslategrey: 3100495,
  2588. darkturquoise: 52945,
  2589. darkviolet: 9699539,
  2590. deeppink: 16716947,
  2591. deepskyblue: 49151,
  2592. dimgray: 6908265,
  2593. dimgrey: 6908265,
  2594. dodgerblue: 2003199,
  2595. firebrick: 11674146,
  2596. floralwhite: 16775920,
  2597. forestgreen: 2263842,
  2598. fuchsia: 16711935,
  2599. gainsboro: 14474460,
  2600. ghostwhite: 16316671,
  2601. gold: 16766720,
  2602. goldenrod: 14329120,
  2603. gray: 8421504,
  2604. green: 32768,
  2605. greenyellow: 11403055,
  2606. grey: 8421504,
  2607. honeydew: 15794160,
  2608. hotpink: 16738740,
  2609. indianred: 13458524,
  2610. indigo: 4915330,
  2611. ivory: 16777200,
  2612. khaki: 15787660,
  2613. lavender: 15132410,
  2614. lavenderblush: 16773365,
  2615. lawngreen: 8190976,
  2616. lemonchiffon: 16775885,
  2617. lightblue: 11393254,
  2618. lightcoral: 15761536,
  2619. lightcyan: 14745599,
  2620. lightgoldenrodyellow: 16448210,
  2621. lightgray: 13882323,
  2622. lightgreen: 9498256,
  2623. lightgrey: 13882323,
  2624. lightpink: 16758465,
  2625. lightsalmon: 16752762,
  2626. lightseagreen: 2142890,
  2627. lightskyblue: 8900346,
  2628. lightslategray: 7833753,
  2629. lightslategrey: 7833753,
  2630. lightsteelblue: 11584734,
  2631. lightyellow: 16777184,
  2632. lime: 65280,
  2633. limegreen: 3329330,
  2634. linen: 16445670,
  2635. magenta: 16711935,
  2636. maroon: 8388608,
  2637. mediumaquamarine: 6737322,
  2638. mediumblue: 205,
  2639. mediumorchid: 12211667,
  2640. mediumpurple: 9662683,
  2641. mediumseagreen: 3978097,
  2642. mediumslateblue: 8087790,
  2643. mediumspringgreen: 64154,
  2644. mediumturquoise: 4772300,
  2645. mediumvioletred: 13047173,
  2646. midnightblue: 1644912,
  2647. mintcream: 16121850,
  2648. mistyrose: 16770273,
  2649. moccasin: 16770229,
  2650. navajowhite: 16768685,
  2651. navy: 128,
  2652. oldlace: 16643558,
  2653. olive: 8421376,
  2654. olivedrab: 7048739,
  2655. orange: 16753920,
  2656. orangered: 16729344,
  2657. orchid: 14315734,
  2658. palegoldenrod: 15657130,
  2659. palegreen: 10025880,
  2660. paleturquoise: 11529966,
  2661. palevioletred: 14381203,
  2662. papayawhip: 16773077,
  2663. peachpuff: 16767673,
  2664. peru: 13468991,
  2665. pink: 16761035,
  2666. plum: 14524637,
  2667. powderblue: 11591910,
  2668. purple: 8388736,
  2669. rebeccapurple: 6697881,
  2670. red: 16711680,
  2671. rosybrown: 12357519,
  2672. royalblue: 4286945,
  2673. saddlebrown: 9127187,
  2674. salmon: 16416882,
  2675. sandybrown: 16032864,
  2676. seagreen: 3050327,
  2677. seashell: 16774638,
  2678. sienna: 10506797,
  2679. silver: 12632256,
  2680. skyblue: 8900331,
  2681. slateblue: 6970061,
  2682. slategray: 7372944,
  2683. slategrey: 7372944,
  2684. snow: 16775930,
  2685. springgreen: 65407,
  2686. steelblue: 4620980,
  2687. tan: 13808780,
  2688. teal: 32896,
  2689. thistle: 14204888,
  2690. tomato: 16737095,
  2691. turquoise: 4251856,
  2692. violet: 15631086,
  2693. wheat: 16113331,
  2694. white: 16777215,
  2695. whitesmoke: 16119285,
  2696. yellow: 16776960,
  2697. yellowgreen: 10145074
  2698. });
  2699. d3_rgb_names.forEach(function(key, value) {
  2700. d3_rgb_names.set(key, d3_rgbNumber(value));
  2701. });
  2702. function d3_functor(v) {
  2703. return typeof v === "function" ? v : function() {
  2704. return v;
  2705. };
  2706. }
  2707. d3.functor = d3_functor;
  2708. d3.xhr = d3_xhrType(d3_identity);
  2709. function d3_xhrType(response) {
  2710. return function(url, mimeType, callback) {
  2711. if (arguments.length === 2 && typeof mimeType === "function") callback = mimeType,
  2712. mimeType = null;
  2713. return d3_xhr(url, mimeType, response, callback);
  2714. };
  2715. }
  2716. function d3_xhr(url, mimeType, response, callback) {
  2717. var xhr = {}, dispatch = d3.dispatch("beforesend", "progress", "load", "error"), headers = {}, request = new XMLHttpRequest(), responseType = null;
  2718. if (this.XDomainRequest && !("withCredentials" in request) && /^(http(s)?:)?\/\//.test(url)) request = new XDomainRequest();
  2719. "onload" in request ? request.onload = request.onerror = respond : request.onreadystatechange = function() {
  2720. request.readyState > 3 && respond();
  2721. };
  2722. function respond() {
  2723. var status = request.status, result;
  2724. if (!status && d3_xhrHasResponse(request) || status >= 200 && status < 300 || status === 304) {
  2725. try {
  2726. result = response.call(xhr, request);
  2727. } catch (e) {
  2728. dispatch.error.call(xhr, e);
  2729. return;
  2730. }
  2731. dispatch.load.call(xhr, result);
  2732. } else {
  2733. dispatch.error.call(xhr, request);
  2734. }
  2735. }
  2736. request.onprogress = function(event) {
  2737. var o = d3.event;
  2738. d3.event = event;
  2739. try {
  2740. dispatch.progress.call(xhr, request);
  2741. } finally {
  2742. d3.event = o;
  2743. }
  2744. };
  2745. xhr.header = function(name, value) {
  2746. name = (name + "").toLowerCase();
  2747. if (arguments.length < 2) return headers[name];
  2748. if (value == null) delete headers[name]; else headers[name] = value + "";
  2749. return xhr;
  2750. };
  2751. xhr.mimeType = function(value) {
  2752. if (!arguments.length) return mimeType;
  2753. mimeType = value == null ? null : value + "";
  2754. return xhr;
  2755. };
  2756. xhr.responseType = function(value) {
  2757. if (!arguments.length) return responseType;
  2758. responseType = value;
  2759. return xhr;
  2760. };
  2761. xhr.response = function(value) {
  2762. response = value;
  2763. return xhr;
  2764. };
  2765. [ "get", "post" ].forEach(function(method) {
  2766. xhr[method] = function() {
  2767. return xhr.send.apply(xhr, [ method ].concat(d3_array(arguments)));
  2768. };
  2769. });
  2770. xhr.send = function(method, data, callback) {
  2771. if (arguments.length === 2 && typeof data === "function") callback = data, data = null;
  2772. request.open(method, url, true);
  2773. if (mimeType != null && !("accept" in headers)) headers["accept"] = mimeType + ",*/*";
  2774. if (request.setRequestHeader) for (var name in headers) request.setRequestHeader(name, headers[name]);
  2775. if (mimeType != null && request.overrideMimeType) request.overrideMimeType(mimeType);
  2776. if (responseType != null) request.responseType = responseType;
  2777. if (callback != null) xhr.on("error", callback).on("load", function(request) {
  2778. callback(null, request);
  2779. });
  2780. dispatch.beforesend.call(xhr, request);
  2781. request.send(data == null ? null : data);
  2782. return xhr;
  2783. };
  2784. xhr.abort = function() {
  2785. request.abort();
  2786. return xhr;
  2787. };
  2788. d3.rebind(xhr, dispatch, "on");
  2789. return callback == null ? xhr : xhr.get(d3_xhr_fixCallback(callback));
  2790. }
  2791. function d3_xhr_fixCallback(callback) {
  2792. return callback.length === 1 ? function(error, request) {
  2793. callback(error == null ? request : null);
  2794. } : callback;
  2795. }
  2796. function d3_xhrHasResponse(request) {
  2797. var type = request.responseType;
  2798. return type && type !== "text" ? request.response : request.responseText;
  2799. }
  2800. d3.dsv = function(delimiter, mimeType) {
  2801. var reFormat = new RegExp('["' + delimiter + "\n]"), delimiterCode = delimiter.charCodeAt(0);
  2802. function dsv(url, row, callback) {
  2803. if (arguments.length < 3) callback = row, row = null;
  2804. var xhr = d3_xhr(url, mimeType, row == null ? response : typedResponse(row), callback);
  2805. xhr.row = function(_) {
  2806. return arguments.length ? xhr.response((row = _) == null ? response : typedResponse(_)) : row;
  2807. };
  2808. return xhr;
  2809. }
  2810. function response(request) {
  2811. return dsv.parse(request.responseText);
  2812. }
  2813. function typedResponse(f) {
  2814. return function(request) {
  2815. return dsv.parse(request.responseText, f);
  2816. };
  2817. }
  2818. dsv.parse = function(text, f) {
  2819. var o;
  2820. return dsv.parseRows(text, function(row, i) {
  2821. if (o) return o(row, i - 1);
  2822. var a = new Function("d", "return {" + row.map(function(name, i) {
  2823. return JSON.stringify(name) + ": d[" + i + "]";
  2824. }).join(",") + "}");
  2825. o = f ? function(row, i) {
  2826. return f(a(row), i);
  2827. } : a;
  2828. });
  2829. };
  2830. dsv.parseRows = function(text, f) {
  2831. var EOL = {}, EOF = {}, rows = [], N = text.length, I = 0, n = 0, t, eol;
  2832. function token() {
  2833. if (I >= N) return EOF;
  2834. if (eol) return eol = false, EOL;
  2835. var j = I;
  2836. if (text.charCodeAt(j) === 34) {
  2837. var i = j;
  2838. while (i++ < N) {
  2839. if (text.charCodeAt(i) === 34) {
  2840. if (text.charCodeAt(i + 1) !== 34) break;
  2841. ++i;
  2842. }
  2843. }
  2844. I = i + 2;
  2845. var c = text.charCodeAt(i + 1);
  2846. if (c === 13) {
  2847. eol = true;
  2848. if (text.charCodeAt(i + 2) === 10) ++I;
  2849. } else if (c === 10) {
  2850. eol = true;
  2851. }
  2852. return text.slice(j + 1, i).replace(/""/g, '"');
  2853. }
  2854. while (I < N) {
  2855. var c = text.charCodeAt(I++), k = 1;
  2856. if (c === 10) eol = true; else if (c === 13) {
  2857. eol = true;
  2858. if (text.charCodeAt(I) === 10) ++I, ++k;
  2859. } else if (c !== delimiterCode) continue;
  2860. return text.slice(j, I - k);
  2861. }
  2862. return text.slice(j);
  2863. }
  2864. while ((t = token()) !== EOF) {
  2865. var a = [];
  2866. while (t !== EOL && t !== EOF) {
  2867. a.push(t);
  2868. t = token();
  2869. }
  2870. if (f && (a = f(a, n++)) == null) continue;
  2871. rows.push(a);
  2872. }
  2873. return rows;
  2874. };
  2875. dsv.format = function(rows) {
  2876. if (Array.isArray(rows[0])) return dsv.formatRows(rows);
  2877. var fieldSet = new d3_Set(), fields = [];
  2878. rows.forEach(function(row) {
  2879. for (var field in row) {
  2880. if (!fieldSet.has(field)) {
  2881. fields.push(fieldSet.add(field));
  2882. }
  2883. }
  2884. });
  2885. return [ fields.map(formatValue).join(delimiter) ].concat(rows.map(function(row) {
  2886. return fields.map(function(field) {
  2887. return formatValue(row[field]);
  2888. }).join(delimiter);
  2889. })).join("\n");
  2890. };
  2891. dsv.formatRows = function(rows) {
  2892. return rows.map(formatRow).join("\n");
  2893. };
  2894. function formatRow(row) {
  2895. return row.map(formatValue).join(delimiter);
  2896. }
  2897. function formatValue(text) {
  2898. return reFormat.test(text) ? '"' + text.replace(/\"/g, '""') + '"' : text;
  2899. }
  2900. return dsv;
  2901. };
  2902. d3.csv = d3.dsv(",", "text/csv");
  2903. d3.tsv = d3.dsv(" ", "text/tab-separated-values");
  2904. var d3_timer_queueHead, d3_timer_queueTail, d3_timer_interval, d3_timer_timeout, d3_timer_frame = this[d3_vendorSymbol(this, "requestAnimationFrame")] || function(callback) {
  2905. setTimeout(callback, 17);
  2906. };
  2907. d3.timer = function() {
  2908. d3_timer.apply(this, arguments);
  2909. };
  2910. function d3_timer(callback, delay, then) {
  2911. var n = arguments.length;
  2912. if (n < 2) delay = 0;
  2913. if (n < 3) then = Date.now();
  2914. var time = then + delay, timer = {
  2915. c: callback,
  2916. t: time,
  2917. n: null
  2918. };
  2919. if (d3_timer_queueTail) d3_timer_queueTail.n = timer; else d3_timer_queueHead = timer;
  2920. d3_timer_queueTail = timer;
  2921. if (!d3_timer_interval) {
  2922. d3_timer_timeout = clearTimeout(d3_timer_timeout);
  2923. d3_timer_interval = 1;
  2924. d3_timer_frame(d3_timer_step);
  2925. }
  2926. return timer;
  2927. }
  2928. function d3_timer_step() {
  2929. var now = d3_timer_mark(), delay = d3_timer_sweep() - now;
  2930. if (delay > 24) {
  2931. if (isFinite(delay)) {
  2932. clearTimeout(d3_timer_timeout);
  2933. d3_timer_timeout = setTimeout(d3_timer_step, delay);
  2934. }
  2935. d3_timer_interval = 0;
  2936. } else {
  2937. d3_timer_interval = 1;
  2938. d3_timer_frame(d3_timer_step);
  2939. }
  2940. }
  2941. d3.timer.flush = function() {
  2942. d3_timer_mark();
  2943. d3_timer_sweep();
  2944. };
  2945. function d3_timer_mark() {
  2946. var now = Date.now(), timer = d3_timer_queueHead;
  2947. while (timer) {
  2948. if (now >= timer.t && timer.c(now - timer.t)) timer.c = null;
  2949. timer = timer.n;
  2950. }
  2951. return now;
  2952. }
  2953. function d3_timer_sweep() {
  2954. var t0, t1 = d3_timer_queueHead, time = Infinity;
  2955. while (t1) {
  2956. if (t1.c) {
  2957. if (t1.t < time) time = t1.t;
  2958. t1 = (t0 = t1).n;
  2959. } else {
  2960. t1 = t0 ? t0.n = t1.n : d3_timer_queueHead = t1.n;
  2961. }
  2962. }
  2963. d3_timer_queueTail = t0;
  2964. return time;
  2965. }
  2966. function d3_format_precision(x, p) {
  2967. return p - (x ? Math.ceil(Math.log(x) / Math.LN10) : 1);
  2968. }
  2969. d3.round = function(x, n) {
  2970. return n ? Math.round(x * (n = Math.pow(10, n))) / n : Math.round(x);
  2971. };
  2972. var d3_formatPrefixes = [ "y", "z", "a", "f", "p", "n", "µ", "m", "", "k", "M", "G", "T", "P", "E", "Z", "Y" ].map(d3_formatPrefix);
  2973. d3.formatPrefix = function(value, precision) {
  2974. var i = 0;
  2975. if (value = +value) {
  2976. if (value < 0) value *= -1;
  2977. if (precision) value = d3.round(value, d3_format_precision(value, precision));
  2978. i = 1 + Math.floor(1e-12 + Math.log(value) / Math.LN10);
  2979. i = Math.max(-24, Math.min(24, Math.floor((i - 1) / 3) * 3));
  2980. }
  2981. return d3_formatPrefixes[8 + i / 3];
  2982. };
  2983. function d3_formatPrefix(d, i) {
  2984. var k = Math.pow(10, abs(8 - i) * 3);
  2985. return {
  2986. scale: i > 8 ? function(d) {
  2987. return d / k;
  2988. } : function(d) {
  2989. return d * k;
  2990. },
  2991. symbol: d
  2992. };
  2993. }
  2994. function d3_locale_numberFormat(locale) {
  2995. var locale_decimal = locale.decimal, locale_thousands = locale.thousands, locale_grouping = locale.grouping, locale_currency = locale.currency, formatGroup = locale_grouping && locale_thousands ? function(value, width) {
  2996. var i = value.length, t = [], j = 0, g = locale_grouping[0], length = 0;
  2997. while (i > 0 && g > 0) {
  2998. if (length + g + 1 > width) g = Math.max(1, width - length);
  2999. t.push(value.substring(i -= g, i + g));
  3000. if ((length += g + 1) > width) break;
  3001. g = locale_grouping[j = (j + 1) % locale_grouping.length];
  3002. }
  3003. return t.reverse().join(locale_thousands);
  3004. } : d3_identity;
  3005. return function(specifier) {
  3006. var match = d3_format_re.exec(specifier), fill = match[1] || " ", align = match[2] || ">", sign = match[3] || "-", symbol = match[4] || "", zfill = match[5], width = +match[6], comma = match[7], precision = match[8], type = match[9], scale = 1, prefix = "", suffix = "", integer = false, exponent = true;
  3007. if (precision) precision = +precision.substring(1);
  3008. if (zfill || fill === "0" && align === "=") {
  3009. zfill = fill = "0";
  3010. align = "=";
  3011. }
  3012. switch (type) {
  3013. case "n":
  3014. comma = true;
  3015. type = "g";
  3016. break;
  3017. case "%":
  3018. scale = 100;
  3019. suffix = "%";
  3020. type = "f";
  3021. break;
  3022. case "p":
  3023. scale = 100;
  3024. suffix = "%";
  3025. type = "r";
  3026. break;
  3027. case "b":
  3028. case "o":
  3029. case "x":
  3030. case "X":
  3031. if (symbol === "#") prefix = "0" + type.toLowerCase();
  3032. case "c":
  3033. exponent = false;
  3034. case "d":
  3035. integer = true;
  3036. precision = 0;
  3037. break;
  3038. case "s":
  3039. scale = -1;
  3040. type = "r";
  3041. break;
  3042. }
  3043. if (symbol === "$") prefix = locale_currency[0], suffix = locale_currency[1];
  3044. if (type == "r" && !precision) type = "g";
  3045. if (precision != null) {
  3046. if (type == "g") precision = Math.max(1, Math.min(21, precision)); else if (type == "e" || type == "f") precision = Math.max(0, Math.min(20, precision));
  3047. }
  3048. type = d3_format_types.get(type) || d3_format_typeDefault;
  3049. var zcomma = zfill && comma;
  3050. return function(value) {
  3051. var fullSuffix = suffix;
  3052. if (integer && value % 1) return "";
  3053. var negative = value < 0 || value === 0 && 1 / value < 0 ? (value = -value, "-") : sign === "-" ? "" : sign;
  3054. if (scale < 0) {
  3055. var unit = d3.formatPrefix(value, precision);
  3056. value = unit.scale(value);
  3057. fullSuffix = unit.symbol + suffix;
  3058. } else {
  3059. value *= scale;
  3060. }
  3061. value = type(value, precision);
  3062. var i = value.lastIndexOf("."), before, after;
  3063. if (i < 0) {
  3064. var j = exponent ? value.lastIndexOf("e") : -1;
  3065. if (j < 0) before = value, after = ""; else before = value.substring(0, j), after = value.substring(j);
  3066. } else {
  3067. before = value.substring(0, i);
  3068. after = locale_decimal + value.substring(i + 1);
  3069. }
  3070. if (!zfill && comma) before = formatGroup(before, Infinity);
  3071. var length = prefix.length + before.length + after.length + (zcomma ? 0 : negative.length), padding = length < width ? new Array(length = width - length + 1).join(fill) : "";
  3072. if (zcomma) before = formatGroup(padding + before, padding.length ? width - after.length : Infinity);
  3073. negative += prefix;
  3074. value = before + after;
  3075. return (align === "<" ? negative + value + padding : align === ">" ? padding + negative + value : align === "^" ? padding.substring(0, length >>= 1) + negative + value + padding.substring(length) : negative + (zcomma ? value : padding + value)) + fullSuffix;
  3076. };
  3077. };
  3078. }
  3079. var d3_format_re = /(?:([^{])?([<>=^]))?([+\- ])?([$#])?(0)?(\d+)?(,)?(\.-?\d+)?([a-z%])?/i;
  3080. var d3_format_types = d3.map({
  3081. b: function(x) {
  3082. return x.toString(2);
  3083. },
  3084. c: function(x) {
  3085. return String.fromCharCode(x);
  3086. },
  3087. o: function(x) {
  3088. return x.toString(8);
  3089. },
  3090. x: function(x) {
  3091. return x.toString(16);
  3092. },
  3093. X: function(x) {
  3094. return x.toString(16).toUpperCase();
  3095. },
  3096. g: function(x, p) {
  3097. return x.toPrecision(p);
  3098. },
  3099. e: function(x, p) {
  3100. return x.toExponential(p);
  3101. },
  3102. f: function(x, p) {
  3103. return x.toFixed(p);
  3104. },
  3105. r: function(x, p) {
  3106. return (x = d3.round(x, d3_format_precision(x, p))).toFixed(Math.max(0, Math.min(20, d3_format_precision(x * (1 + 1e-15), p))));
  3107. }
  3108. });
  3109. function d3_format_typeDefault(x) {
  3110. return x + "";
  3111. }
  3112. var d3_time = d3.time = {}, d3_date = Date;
  3113. function d3_date_utc() {
  3114. this._ = new Date(arguments.length > 1 ? Date.UTC.apply(this, arguments) : arguments[0]);
  3115. }
  3116. d3_date_utc.prototype = {
  3117. getDate: function() {
  3118. return this._.getUTCDate();
  3119. },
  3120. getDay: function() {
  3121. return this._.getUTCDay();
  3122. },
  3123. getFullYear: function() {
  3124. return this._.getUTCFullYear();
  3125. },
  3126. getHours: function() {
  3127. return this._.getUTCHours();
  3128. },
  3129. getMilliseconds: function() {
  3130. return this._.getUTCMilliseconds();
  3131. },
  3132. getMinutes: function() {
  3133. return this._.getUTCMinutes();
  3134. },
  3135. getMonth: function() {
  3136. return this._.getUTCMonth();
  3137. },
  3138. getSeconds: function() {
  3139. return this._.getUTCSeconds();
  3140. },
  3141. getTime: function() {
  3142. return this._.getTime();
  3143. },
  3144. getTimezoneOffset: function() {
  3145. return 0;
  3146. },
  3147. valueOf: function() {
  3148. return this._.valueOf();
  3149. },
  3150. setDate: function() {
  3151. d3_time_prototype.setUTCDate.apply(this._, arguments);
  3152. },
  3153. setDay: function() {
  3154. d3_time_prototype.setUTCDay.apply(this._, arguments);
  3155. },
  3156. setFullYear: function() {
  3157. d3_time_prototype.setUTCFullYear.apply(this._, arguments);
  3158. },
  3159. setHours: function() {
  3160. d3_time_prototype.setUTCHours.apply(this._, arguments);
  3161. },
  3162. setMilliseconds: function() {
  3163. d3_time_prototype.setUTCMilliseconds.apply(this._, arguments);
  3164. },
  3165. setMinutes: function() {
  3166. d3_time_prototype.setUTCMinutes.apply(this._, arguments);
  3167. },
  3168. setMonth: function() {
  3169. d3_time_prototype.setUTCMonth.apply(this._, arguments);
  3170. },
  3171. setSeconds: function() {
  3172. d3_time_prototype.setUTCSeconds.apply(this._, arguments);
  3173. },
  3174. setTime: function() {
  3175. d3_time_prototype.setTime.apply(this._, arguments);
  3176. }
  3177. };
  3178. var d3_time_prototype = Date.prototype;
  3179. function d3_time_interval(local, step, number) {
  3180. function round(date) {
  3181. var d0 = local(date), d1 = offset(d0, 1);
  3182. return date - d0 < d1 - date ? d0 : d1;
  3183. }
  3184. function ceil(date) {
  3185. step(date = local(new d3_date(date - 1)), 1);
  3186. return date;
  3187. }
  3188. function offset(date, k) {
  3189. step(date = new d3_date(+date), k);
  3190. return date;
  3191. }
  3192. function range(t0, t1, dt) {
  3193. var time = ceil(t0), times = [];
  3194. if (dt > 1) {
  3195. while (time < t1) {
  3196. if (!(number(time) % dt)) times.push(new Date(+time));
  3197. step(time, 1);
  3198. }
  3199. } else {
  3200. while (time < t1) times.push(new Date(+time)), step(time, 1);
  3201. }
  3202. return times;
  3203. }
  3204. function range_utc(t0, t1, dt) {
  3205. try {
  3206. d3_date = d3_date_utc;
  3207. var utc = new d3_date_utc();
  3208. utc._ = t0;
  3209. return range(utc, t1, dt);
  3210. } finally {
  3211. d3_date = Date;
  3212. }
  3213. }
  3214. local.floor = local;
  3215. local.round = round;
  3216. local.ceil = ceil;
  3217. local.offset = offset;
  3218. local.range = range;
  3219. var utc = local.utc = d3_time_interval_utc(local);
  3220. utc.floor = utc;
  3221. utc.round = d3_time_interval_utc(round);
  3222. utc.ceil = d3_time_interval_utc(ceil);
  3223. utc.offset = d3_time_interval_utc(offset);
  3224. utc.range = range_utc;
  3225. return local;
  3226. }
  3227. function d3_time_interval_utc(method) {
  3228. return function(date, k) {
  3229. try {
  3230. d3_date = d3_date_utc;
  3231. var utc = new d3_date_utc();
  3232. utc._ = date;
  3233. return method(utc, k)._;
  3234. } finally {
  3235. d3_date = Date;
  3236. }
  3237. };
  3238. }
  3239. d3_time.year = d3_time_interval(function(date) {
  3240. date = d3_time.day(date);
  3241. date.setMonth(0, 1);
  3242. return date;
  3243. }, function(date, offset) {
  3244. date.setFullYear(date.getFullYear() + offset);
  3245. }, function(date) {
  3246. return date.getFullYear();
  3247. });
  3248. d3_time.years = d3_time.year.range;
  3249. d3_time.years.utc = d3_time.year.utc.range;
  3250. d3_time.day = d3_time_interval(function(date) {
  3251. var day = new d3_date(2e3, 0);
  3252. day.setFullYear(date.getFullYear(), date.getMonth(), date.getDate());
  3253. return day;
  3254. }, function(date, offset) {
  3255. date.setDate(date.getDate() + offset);
  3256. }, function(date) {
  3257. return date.getDate() - 1;
  3258. });
  3259. d3_time.days = d3_time.day.range;
  3260. d3_time.days.utc = d3_time.day.utc.range;
  3261. d3_time.dayOfYear = function(date) {
  3262. var year = d3_time.year(date);
  3263. return Math.floor((date - year - (date.getTimezoneOffset() - year.getTimezoneOffset()) * 6e4) / 864e5);
  3264. };
  3265. [ "sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday" ].forEach(function(day, i) {
  3266. i = 7 - i;
  3267. var interval = d3_time[day] = d3_time_interval(function(date) {
  3268. (date = d3_time.day(date)).setDate(date.getDate() - (date.getDay() + i) % 7);
  3269. return date;
  3270. }, function(date, offset) {
  3271. date.setDate(date.getDate() + Math.floor(offset) * 7);
  3272. }, function(date) {
  3273. var day = d3_time.year(date).getDay();
  3274. return Math.floor((d3_time.dayOfYear(date) + (day + i) % 7) / 7) - (day !== i);
  3275. });
  3276. d3_time[day + "s"] = interval.range;
  3277. d3_time[day + "s"].utc = interval.utc.range;
  3278. d3_time[day + "OfYear"] = function(date) {
  3279. var day = d3_time.year(date).getDay();
  3280. return Math.floor((d3_time.dayOfYear(date) + (day + i) % 7) / 7);
  3281. };
  3282. });
  3283. d3_time.week = d3_time.sunday;
  3284. d3_time.weeks = d3_time.sunday.range;
  3285. d3_time.weeks.utc = d3_time.sunday.utc.range;
  3286. d3_time.weekOfYear = d3_time.sundayOfYear;
  3287. function d3_locale_timeFormat(locale) {
  3288. var locale_dateTime = locale.dateTime, locale_date = locale.date, locale_time = locale.time, locale_periods = locale.periods, locale_days = locale.days, locale_shortDays = locale.shortDays, locale_months = locale.months, locale_shortMonths = locale.shortMonths;
  3289. function d3_time_format(template) {
  3290. var n = template.length;
  3291. function format(date) {
  3292. var string = [], i = -1, j = 0, c, p, f;
  3293. while (++i < n) {
  3294. if (template.charCodeAt(i) === 37) {
  3295. string.push(template.slice(j, i));
  3296. if ((p = d3_time_formatPads[c = template.charAt(++i)]) != null) c = template.charAt(++i);
  3297. if (f = d3_time_formats[c]) c = f(date, p == null ? c === "e" ? " " : "0" : p);
  3298. string.push(c);
  3299. j = i + 1;
  3300. }
  3301. }
  3302. string.push(template.slice(j, i));
  3303. return string.join("");
  3304. }
  3305. format.parse = function(string) {
  3306. var d = {
  3307. y: 1900,
  3308. m: 0,
  3309. d: 1,
  3310. H: 0,
  3311. M: 0,
  3312. S: 0,
  3313. L: 0,
  3314. Z: null
  3315. }, i = d3_time_parse(d, template, string, 0);
  3316. if (i != string.length) return null;
  3317. if ("p" in d) d.H = d.H % 12 + d.p * 12;
  3318. var localZ = d.Z != null && d3_date !== d3_date_utc, date = new (localZ ? d3_date_utc : d3_date)();
  3319. if ("j" in d) date.setFullYear(d.y, 0, d.j); else if ("W" in d || "U" in d) {
  3320. if (!("w" in d)) d.w = "W" in d ? 1 : 0;
  3321. date.setFullYear(d.y, 0, 1);
  3322. date.setFullYear(d.y, 0, "W" in d ? (d.w + 6) % 7 + d.W * 7 - (date.getDay() + 5) % 7 : d.w + d.U * 7 - (date.getDay() + 6) % 7);
  3323. } else date.setFullYear(d.y, d.m, d.d);
  3324. date.setHours(d.H + (d.Z / 100 | 0), d.M + d.Z % 100, d.S, d.L);
  3325. return localZ ? date._ : date;
  3326. };
  3327. format.toString = function() {
  3328. return template;
  3329. };
  3330. return format;
  3331. }
  3332. function d3_time_parse(date, template, string, j) {
  3333. var c, p, t, i = 0, n = template.length, m = string.length;
  3334. while (i < n) {
  3335. if (j >= m) return -1;
  3336. c = template.charCodeAt(i++);
  3337. if (c === 37) {
  3338. t = template.charAt(i++);
  3339. p = d3_time_parsers[t in d3_time_formatPads ? template.charAt(i++) : t];
  3340. if (!p || (j = p(date, string, j)) < 0) return -1;
  3341. } else if (c != string.charCodeAt(j++)) {
  3342. return -1;
  3343. }
  3344. }
  3345. return j;
  3346. }
  3347. d3_time_format.utc = function(template) {
  3348. var local = d3_time_format(template);
  3349. function format(date) {
  3350. try {
  3351. d3_date = d3_date_utc;
  3352. var utc = new d3_date();
  3353. utc._ = date;
  3354. return local(utc);
  3355. } finally {
  3356. d3_date = Date;
  3357. }
  3358. }
  3359. format.parse = function(string) {
  3360. try {
  3361. d3_date = d3_date_utc;
  3362. var date = local.parse(string);
  3363. return date && date._;
  3364. } finally {
  3365. d3_date = Date;
  3366. }
  3367. };
  3368. format.toString = local.toString;
  3369. return format;
  3370. };
  3371. d3_time_format.multi = d3_time_format.utc.multi = d3_time_formatMulti;
  3372. var d3_time_periodLookup = d3.map(), d3_time_dayRe = d3_time_formatRe(locale_days), d3_time_dayLookup = d3_time_formatLookup(locale_days), d3_time_dayAbbrevRe = d3_time_formatRe(locale_shortDays), d3_time_dayAbbrevLookup = d3_time_formatLookup(locale_shortDays), d3_time_monthRe = d3_time_formatRe(locale_months), d3_time_monthLookup = d3_time_formatLookup(locale_months), d3_time_monthAbbrevRe = d3_time_formatRe(locale_shortMonths), d3_time_monthAbbrevLookup = d3_time_formatLookup(locale_shortMonths);
  3373. locale_periods.forEach(function(p, i) {
  3374. d3_time_periodLookup.set(p.toLowerCase(), i);
  3375. });
  3376. var d3_time_formats = {
  3377. a: function(d) {
  3378. return locale_shortDays[d.getDay()];
  3379. },
  3380. A: function(d) {
  3381. return locale_days[d.getDay()];
  3382. },
  3383. b: function(d) {
  3384. return locale_shortMonths[d.getMonth()];
  3385. },
  3386. B: function(d) {
  3387. return locale_months[d.getMonth()];
  3388. },
  3389. c: d3_time_format(locale_dateTime),
  3390. d: function(d, p) {
  3391. return d3_time_formatPad(d.getDate(), p, 2);
  3392. },
  3393. e: function(d, p) {
  3394. return d3_time_formatPad(d.getDate(), p, 2);
  3395. },
  3396. H: function(d, p) {
  3397. return d3_time_formatPad(d.getHours(), p, 2);
  3398. },
  3399. I: function(d, p) {
  3400. return d3_time_formatPad(d.getHours() % 12 || 12, p, 2);
  3401. },
  3402. j: function(d, p) {
  3403. return d3_time_formatPad(1 + d3_time.dayOfYear(d), p, 3);
  3404. },
  3405. L: function(d, p) {
  3406. return d3_time_formatPad(d.getMilliseconds(), p, 3);
  3407. },
  3408. m: function(d, p) {
  3409. return d3_time_formatPad(d.getMonth() + 1, p, 2);
  3410. },
  3411. M: function(d, p) {
  3412. return d3_time_formatPad(d.getMinutes(), p, 2);
  3413. },
  3414. p: function(d) {
  3415. return locale_periods[+(d.getHours() >= 12)];
  3416. },
  3417. S: function(d, p) {
  3418. return d3_time_formatPad(d.getSeconds(), p, 2);
  3419. },
  3420. U: function(d, p) {
  3421. return d3_time_formatPad(d3_time.sundayOfYear(d), p, 2);
  3422. },
  3423. w: function(d) {
  3424. return d.getDay();
  3425. },
  3426. W: function(d, p) {
  3427. return d3_time_formatPad(d3_time.mondayOfYear(d), p, 2);
  3428. },
  3429. x: d3_time_format(locale_date),
  3430. X: d3_time_format(locale_time),
  3431. y: function(d, p) {
  3432. return d3_time_formatPad(d.getFullYear() % 100, p, 2);
  3433. },
  3434. Y: function(d, p) {
  3435. return d3_time_formatPad(d.getFullYear() % 1e4, p, 4);
  3436. },
  3437. Z: d3_time_zone,
  3438. "%": function() {
  3439. return "%";
  3440. }
  3441. };
  3442. var d3_time_parsers = {
  3443. a: d3_time_parseWeekdayAbbrev,
  3444. A: d3_time_parseWeekday,
  3445. b: d3_time_parseMonthAbbrev,
  3446. B: d3_time_parseMonth,
  3447. c: d3_time_parseLocaleFull,
  3448. d: d3_time_parseDay,
  3449. e: d3_time_parseDay,
  3450. H: d3_time_parseHour24,
  3451. I: d3_time_parseHour24,
  3452. j: d3_time_parseDayOfYear,
  3453. L: d3_time_parseMilliseconds,
  3454. m: d3_time_parseMonthNumber,
  3455. M: d3_time_parseMinutes,
  3456. p: d3_time_parseAmPm,
  3457. S: d3_time_parseSeconds,
  3458. U: d3_time_parseWeekNumberSunday,
  3459. w: d3_time_parseWeekdayNumber,
  3460. W: d3_time_parseWeekNumberMonday,
  3461. x: d3_time_parseLocaleDate,
  3462. X: d3_time_parseLocaleTime,
  3463. y: d3_time_parseYear,
  3464. Y: d3_time_parseFullYear,
  3465. Z: d3_time_parseZone,
  3466. "%": d3_time_parseLiteralPercent
  3467. };
  3468. function d3_time_parseWeekdayAbbrev(date, string, i) {
  3469. d3_time_dayAbbrevRe.lastIndex = 0;
  3470. var n = d3_time_dayAbbrevRe.exec(string.slice(i));
  3471. return n ? (date.w = d3_time_dayAbbrevLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
  3472. }
  3473. function d3_time_parseWeekday(date, string, i) {
  3474. d3_time_dayRe.lastIndex = 0;
  3475. var n = d3_time_dayRe.exec(string.slice(i));
  3476. return n ? (date.w = d3_time_dayLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
  3477. }
  3478. function d3_time_parseMonthAbbrev(date, string, i) {
  3479. d3_time_monthAbbrevRe.lastIndex = 0;
  3480. var n = d3_time_monthAbbrevRe.exec(string.slice(i));
  3481. return n ? (date.m = d3_time_monthAbbrevLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
  3482. }
  3483. function d3_time_parseMonth(date, string, i) {
  3484. d3_time_monthRe.lastIndex = 0;
  3485. var n = d3_time_monthRe.exec(string.slice(i));
  3486. return n ? (date.m = d3_time_monthLookup.get(n[0].toLowerCase()), i + n[0].length) : -1;
  3487. }
  3488. function d3_time_parseLocaleFull(date, string, i) {
  3489. return d3_time_parse(date, d3_time_formats.c.toString(), string, i);
  3490. }
  3491. function d3_time_parseLocaleDate(date, string, i) {
  3492. return d3_time_parse(date, d3_time_formats.x.toString(), string, i);
  3493. }
  3494. function d3_time_parseLocaleTime(date, string, i) {
  3495. return d3_time_parse(date, d3_time_formats.X.toString(), string, i);
  3496. }
  3497. function d3_time_parseAmPm(date, string, i) {
  3498. var n = d3_time_periodLookup.get(string.slice(i, i += 2).toLowerCase());
  3499. return n == null ? -1 : (date.p = n, i);
  3500. }
  3501. return d3_time_format;
  3502. }
  3503. var d3_time_formatPads = {
  3504. "-": "",
  3505. _: " ",
  3506. "0": "0"
  3507. }, d3_time_numberRe = /^\s*\d+/, d3_time_percentRe = /^%/;
  3508. function d3_time_formatPad(value, fill, width) {
  3509. var sign = value < 0 ? "-" : "", string = (sign ? -value : value) + "", length = string.length;
  3510. return sign + (length < width ? new Array(width - length + 1).join(fill) + string : string);
  3511. }
  3512. function d3_time_formatRe(names) {
  3513. return new RegExp("^(?:" + names.map(d3.requote).join("|") + ")", "i");
  3514. }
  3515. function d3_time_formatLookup(names) {
  3516. var map = new d3_Map(), i = -1, n = names.length;
  3517. while (++i < n) map.set(names[i].toLowerCase(), i);
  3518. return map;
  3519. }
  3520. function d3_time_parseWeekdayNumber(date, string, i) {
  3521. d3_time_numberRe.lastIndex = 0;
  3522. var n = d3_time_numberRe.exec(string.slice(i, i + 1));
  3523. return n ? (date.w = +n[0], i + n[0].length) : -1;
  3524. }
  3525. function d3_time_parseWeekNumberSunday(date, string, i) {
  3526. d3_time_numberRe.lastIndex = 0;
  3527. var n = d3_time_numberRe.exec(string.slice(i));
  3528. return n ? (date.U = +n[0], i + n[0].length) : -1;
  3529. }
  3530. function d3_time_parseWeekNumberMonday(date, string, i) {
  3531. d3_time_numberRe.lastIndex = 0;
  3532. var n = d3_time_numberRe.exec(string.slice(i));
  3533. return n ? (date.W = +n[0], i + n[0].length) : -1;
  3534. }
  3535. function d3_time_parseFullYear(date, string, i) {
  3536. d3_time_numberRe.lastIndex = 0;
  3537. var n = d3_time_numberRe.exec(string.slice(i, i + 4));
  3538. return n ? (date.y = +n[0], i + n[0].length) : -1;
  3539. }
  3540. function d3_time_parseYear(date, string, i) {
  3541. d3_time_numberRe.lastIndex = 0;
  3542. var n = d3_time_numberRe.exec(string.slice(i, i + 2));
  3543. return n ? (date.y = d3_time_expandYear(+n[0]), i + n[0].length) : -1;
  3544. }
  3545. function d3_time_parseZone(date, string, i) {
  3546. return /^[+-]\d{4}$/.test(string = string.slice(i, i + 5)) ? (date.Z = -string,
  3547. i + 5) : -1;
  3548. }
  3549. function d3_time_expandYear(d) {
  3550. return d + (d > 68 ? 1900 : 2e3);
  3551. }
  3552. function d3_time_parseMonthNumber(date, string, i) {
  3553. d3_time_numberRe.lastIndex = 0;
  3554. var n = d3_time_numberRe.exec(string.slice(i, i + 2));
  3555. return n ? (date.m = n[0] - 1, i + n[0].length) : -1;
  3556. }
  3557. function d3_time_parseDay(date, string, i) {
  3558. d3_time_numberRe.lastIndex = 0;
  3559. var n = d3_time_numberRe.exec(string.slice(i, i + 2));
  3560. return n ? (date.d = +n[0], i + n[0].length) : -1;
  3561. }
  3562. function d3_time_parseDayOfYear(date, string, i) {
  3563. d3_time_numberRe.lastIndex = 0;
  3564. var n = d3_time_numberRe.exec(string.slice(i, i + 3));
  3565. return n ? (date.j = +n[0], i + n[0].length) : -1;
  3566. }
  3567. function d3_time_parseHour24(date, string, i) {
  3568. d3_time_numberRe.lastIndex = 0;
  3569. var n = d3_time_numberRe.exec(string.slice(i, i + 2));
  3570. return n ? (date.H = +n[0], i + n[0].length) : -1;
  3571. }
  3572. function d3_time_parseMinutes(date, string, i) {
  3573. d3_time_numberRe.lastIndex = 0;
  3574. var n = d3_time_numberRe.exec(string.slice(i, i + 2));
  3575. return n ? (date.M = +n[0], i + n[0].length) : -1;
  3576. }
  3577. function d3_time_parseSeconds(date, string, i) {
  3578. d3_time_numberRe.lastIndex = 0;
  3579. var n = d3_time_numberRe.exec(string.slice(i, i + 2));
  3580. return n ? (date.S = +n[0], i + n[0].length) : -1;
  3581. }
  3582. function d3_time_parseMilliseconds(date, string, i) {
  3583. d3_time_numberRe.lastIndex = 0;
  3584. var n = d3_time_numberRe.exec(string.slice(i, i + 3));
  3585. return n ? (date.L = +n[0], i + n[0].length) : -1;
  3586. }
  3587. function d3_time_zone(d) {
  3588. var z = d.getTimezoneOffset(), zs = z > 0 ? "-" : "+", zh = abs(z) / 60 | 0, zm = abs(z) % 60;
  3589. return zs + d3_time_formatPad(zh, "0", 2) + d3_time_formatPad(zm, "0", 2);
  3590. }
  3591. function d3_time_parseLiteralPercent(date, string, i) {
  3592. d3_time_percentRe.lastIndex = 0;
  3593. var n = d3_time_percentRe.exec(string.slice(i, i + 1));
  3594. return n ? i + n[0].length : -1;
  3595. }
  3596. function d3_time_formatMulti(formats) {
  3597. var n = formats.length, i = -1;
  3598. while (++i < n) formats[i][0] = this(formats[i][0]);
  3599. return function(date) {
  3600. var i = 0, f = formats[i];
  3601. while (!f[1](date)) f = formats[++i];
  3602. return f[0](date);
  3603. };
  3604. }
  3605. d3.locale = function(locale) {
  3606. return {
  3607. numberFormat: d3_locale_numberFormat(locale),
  3608. timeFormat: d3_locale_timeFormat(locale)
  3609. };
  3610. };
  3611. var d3_locale_enUS = d3.locale({
  3612. decimal: ".",
  3613. thousands: ",",
  3614. grouping: [ 3 ],
  3615. currency: [ "$", "" ],
  3616. dateTime: "%a %b %e %X %Y",
  3617. date: "%m/%d/%Y",
  3618. time: "%H:%M:%S",
  3619. periods: [ "AM", "PM" ],
  3620. days: [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ],
  3621. shortDays: [ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" ],
  3622. months: [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ],
  3623. shortMonths: [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ]
  3624. });
  3625. d3.format = d3_locale_enUS.numberFormat;
  3626. d3.geo = {};
  3627. function d3_adder() {}
  3628. d3_adder.prototype = {
  3629. s: 0,
  3630. t: 0,
  3631. add: function(y) {
  3632. d3_adderSum(y, this.t, d3_adderTemp);
  3633. d3_adderSum(d3_adderTemp.s, this.s, this);
  3634. if (this.s) this.t += d3_adderTemp.t; else this.s = d3_adderTemp.t;
  3635. },
  3636. reset: function() {
  3637. this.s = this.t = 0;
  3638. },
  3639. valueOf: function() {
  3640. return this.s;
  3641. }
  3642. };
  3643. var d3_adderTemp = new d3_adder();
  3644. function d3_adderSum(a, b, o) {
  3645. var x = o.s = a + b, bv = x - a, av = x - bv;
  3646. o.t = a - av + (b - bv);
  3647. }
  3648. d3.geo.stream = function(object, listener) {
  3649. if (object && d3_geo_streamObjectType.hasOwnProperty(object.type)) {
  3650. d3_geo_streamObjectType[object.type](object, listener);
  3651. } else {
  3652. d3_geo_streamGeometry(object, listener);
  3653. }
  3654. };
  3655. function d3_geo_streamGeometry(geometry, listener) {
  3656. if (geometry && d3_geo_streamGeometryType.hasOwnProperty(geometry.type)) {
  3657. d3_geo_streamGeometryType[geometry.type](geometry, listener);
  3658. }
  3659. }
  3660. var d3_geo_streamObjectType = {
  3661. Feature: function(feature, listener) {
  3662. d3_geo_streamGeometry(feature.geometry, listener);
  3663. },
  3664. FeatureCollection: function(object, listener) {
  3665. var features = object.features, i = -1, n = features.length;
  3666. while (++i < n) d3_geo_streamGeometry(features[i].geometry, listener);
  3667. }
  3668. };
  3669. var d3_geo_streamGeometryType = {
  3670. Sphere: function(object, listener) {
  3671. listener.sphere();
  3672. },
  3673. Point: function(object, listener) {
  3674. object = object.coordinates;
  3675. listener.point(object[0], object[1], object[2]);
  3676. },
  3677. MultiPoint: function(object, listener) {
  3678. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  3679. while (++i < n) object = coordinates[i], listener.point(object[0], object[1], object[2]);
  3680. },
  3681. LineString: function(object, listener) {
  3682. d3_geo_streamLine(object.coordinates, listener, 0);
  3683. },
  3684. MultiLineString: function(object, listener) {
  3685. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  3686. while (++i < n) d3_geo_streamLine(coordinates[i], listener, 0);
  3687. },
  3688. Polygon: function(object, listener) {
  3689. d3_geo_streamPolygon(object.coordinates, listener);
  3690. },
  3691. MultiPolygon: function(object, listener) {
  3692. var coordinates = object.coordinates, i = -1, n = coordinates.length;
  3693. while (++i < n) d3_geo_streamPolygon(coordinates[i], listener);
  3694. },
  3695. GeometryCollection: function(object, listener) {
  3696. var geometries = object.geometries, i = -1, n = geometries.length;
  3697. while (++i < n) d3_geo_streamGeometry(geometries[i], listener);
  3698. }
  3699. };
  3700. function d3_geo_streamLine(coordinates, listener, closed) {
  3701. var i = -1, n = coordinates.length - closed, coordinate;
  3702. listener.lineStart();
  3703. while (++i < n) coordinate = coordinates[i], listener.point(coordinate[0], coordinate[1], coordinate[2]);
  3704. listener.lineEnd();
  3705. }
  3706. function d3_geo_streamPolygon(coordinates, listener) {
  3707. var i = -1, n = coordinates.length;
  3708. listener.polygonStart();
  3709. while (++i < n) d3_geo_streamLine(coordinates[i], listener, 1);
  3710. listener.polygonEnd();
  3711. }
  3712. d3.geo.area = function(object) {
  3713. d3_geo_areaSum = 0;
  3714. d3.geo.stream(object, d3_geo_area);
  3715. return d3_geo_areaSum;
  3716. };
  3717. var d3_geo_areaSum, d3_geo_areaRingSum = new d3_adder();
  3718. var d3_geo_area = {
  3719. sphere: function() {
  3720. d3_geo_areaSum += 4 * π;
  3721. },
  3722. point: d3_noop,
  3723. lineStart: d3_noop,
  3724. lineEnd: d3_noop,
  3725. polygonStart: function() {
  3726. d3_geo_areaRingSum.reset();
  3727. d3_geo_area.lineStart = d3_geo_areaRingStart;
  3728. },
  3729. polygonEnd: function() {
  3730. var area = 2 * d3_geo_areaRingSum;
  3731. d3_geo_areaSum += area < 0 ? 4 * π + area : area;
  3732. d3_geo_area.lineStart = d3_geo_area.lineEnd = d3_geo_area.point = d3_noop;
  3733. }
  3734. };
  3735. function d3_geo_areaRingStart() {
  3736. var λ00, φ00, λ0, cosφ0, sinφ0;
  3737. d3_geo_area.point = function(λ, φ) {
  3738. d3_geo_area.point = nextPoint;
  3739. λ0 = (λ00 = λ) * d3_radians, cosφ0 = Math.cos(φ = (φ00 = φ) * d3_radians / 2 + π / 4),
  3740. sinφ0 = Math.sin(φ);
  3741. };
  3742. function nextPoint(λ, φ) {
  3743. λ *= d3_radians;
  3744. φ = φ * d3_radians / 2 + π / 4;
  3745. var dλ = λ - λ0, sdλ = dλ >= 0 ? 1 : -1, adλ = sdλ * dλ, cosφ = Math.cos(φ), sinφ = Math.sin(φ), k = sinφ0 * sinφ, u = cosφ0 * cosφ + k * Math.cos(adλ), v = k * sdλ * Math.sin(adλ);
  3746. d3_geo_areaRingSum.add(Math.atan2(v, u));
  3747. λ0 = λ, cosφ0 = cosφ, sinφ0 = sinφ;
  3748. }
  3749. d3_geo_area.lineEnd = function() {
  3750. nextPoint(λ00, φ00);
  3751. };
  3752. }
  3753. function d3_geo_cartesian(spherical) {
  3754. var λ = spherical[0], φ = spherical[1], cosφ = Math.cos(φ);
  3755. return [ cosφ * Math.cos(λ), cosφ * Math.sin(λ), Math.sin(φ) ];
  3756. }
  3757. function d3_geo_cartesianDot(a, b) {
  3758. return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  3759. }
  3760. function d3_geo_cartesianCross(a, b) {
  3761. 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] ];
  3762. }
  3763. function d3_geo_cartesianAdd(a, b) {
  3764. a[0] += b[0];
  3765. a[1] += b[1];
  3766. a[2] += b[2];
  3767. }
  3768. function d3_geo_cartesianScale(vector, k) {
  3769. return [ vector[0] * k, vector[1] * k, vector[2] * k ];
  3770. }
  3771. function d3_geo_cartesianNormalize(d) {
  3772. var l = Math.sqrt(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]);
  3773. d[0] /= l;
  3774. d[1] /= l;
  3775. d[2] /= l;
  3776. }
  3777. function d3_geo_spherical(cartesian) {
  3778. return [ Math.atan2(cartesian[1], cartesian[0]), d3_asin(cartesian[2]) ];
  3779. }
  3780. function d3_geo_sphericalEqual(a, b) {
  3781. return abs(a[0] - b[0]) < ε && abs(a[1] - b[1]) < ε;
  3782. }
  3783. d3.geo.bounds = function() {
  3784. var λ0, φ0, λ1, φ1, λ_, λ__, φ__, p0, dλSum, ranges, range;
  3785. var bound = {
  3786. point: point,
  3787. lineStart: lineStart,
  3788. lineEnd: lineEnd,
  3789. polygonStart: function() {
  3790. bound.point = ringPoint;
  3791. bound.lineStart = ringStart;
  3792. bound.lineEnd = ringEnd;
  3793. dλSum = 0;
  3794. d3_geo_area.polygonStart();
  3795. },
  3796. polygonEnd: function() {
  3797. d3_geo_area.polygonEnd();
  3798. bound.point = point;
  3799. bound.lineStart = lineStart;
  3800. bound.lineEnd = lineEnd;
  3801. if (d3_geo_areaRingSum < 0) λ0 = -(λ1 = 180), φ0 = -(φ1 = 90); else if (dλSum > ε) φ1 = 90; else if (dλSum < -ε) φ0 = -90;
  3802. range[0] = λ0, range[1] = λ1;
  3803. }
  3804. };
  3805. function point(λ, φ) {
  3806. ranges.push(range = [ λ0 = λ, λ1 = λ ]);
  3807. if (φ < φ0) φ0 = φ;
  3808. if (φ > φ1) φ1 = φ;
  3809. }
  3810. function linePoint(λ, φ) {
  3811. var p = d3_geo_cartesian([ λ * d3_radians, φ * d3_radians ]);
  3812. if (p0) {
  3813. var normal = d3_geo_cartesianCross(p0, p), equatorial = [ normal[1], -normal[0], 0 ], inflection = d3_geo_cartesianCross(equatorial, normal);
  3814. d3_geo_cartesianNormalize(inflection);
  3815. inflection = d3_geo_spherical(inflection);
  3816. var dλ = λ - λ_, s = dλ > 0 ? 1 : -1, λi = inflection[0] * d3_degrees * s, antimeridian = abs(dλ) > 180;
  3817. if (antimeridian ^ (s * λ_ < λi && λi < s * λ)) {
  3818. var φi = inflection[1] * d3_degrees;
  3819. if (φi > φ1) φ1 = φi;
  3820. } else if (λi = (λi + 360) % 360 - 180, antimeridian ^ (s * λ_ < λi && λi < s * λ)) {
  3821. var φi = -inflection[1] * d3_degrees;
  3822. if (φi < φ0) φ0 = φi;
  3823. } else {
  3824. if (φ < φ0) φ0 = φ;
  3825. if (φ > φ1) φ1 = φ;
  3826. }
  3827. if (antimeridian) {
  3828. if (λ < λ_) {
  3829. if (angle(λ0, λ) > angle(λ0, λ1)) λ1 = λ;
  3830. } else {
  3831. if (angle(λ, λ1) > angle(λ0, λ1)) λ0 = λ;
  3832. }
  3833. } else {
  3834. if (λ1 >= λ0) {
  3835. if (λ < λ0) λ0 = λ;
  3836. if (λ > λ1) λ1 = λ;
  3837. } else {
  3838. if (λ > λ_) {
  3839. if (angle(λ0, λ) > angle(λ0, λ1)) λ1 = λ;
  3840. } else {
  3841. if (angle(λ, λ1) > angle(λ0, λ1)) λ0 = λ;
  3842. }
  3843. }
  3844. }
  3845. } else {
  3846. point(λ, φ);
  3847. }
  3848. p0 = p, λ_ = λ;
  3849. }
  3850. function lineStart() {
  3851. bound.point = linePoint;
  3852. }
  3853. function lineEnd() {
  3854. range[0] = λ0, range[1] = λ1;
  3855. bound.point = point;
  3856. p0 = null;
  3857. }
  3858. function ringPoint(λ, φ) {
  3859. if (p0) {
  3860. var dλ = λ - λ_;
  3861. dλSum += abs(dλ) > 180 ? dλ + (dλ > 0 ? 360 : -360) : dλ;
  3862. } else λ__ = λ, φ__ = φ;
  3863. d3_geo_area.point(λ, φ);
  3864. linePoint(λ, φ);
  3865. }
  3866. function ringStart() {
  3867. d3_geo_area.lineStart();
  3868. }
  3869. function ringEnd() {
  3870. ringPoint(λ__, φ__);
  3871. d3_geo_area.lineEnd();
  3872. if (abs(dλSum) > ε) λ0 = -(λ1 = 180);
  3873. range[0] = λ0, range[1] = λ1;
  3874. p0 = null;
  3875. }
  3876. function angle(λ0, λ1) {
  3877. return (λ1 -= λ0) < 0 ? λ1 + 360 : λ1;
  3878. }
  3879. function compareRanges(a, b) {
  3880. return a[0] - b[0];
  3881. }
  3882. function withinRange(x, range) {
  3883. return range[0] <= range[1] ? range[0] <= x && x <= range[1] : x < range[0] || range[1] < x;
  3884. }
  3885. return function(feature) {
  3886. φ1 = λ1 = -(λ0 = φ0 = Infinity);
  3887. ranges = [];
  3888. d3.geo.stream(feature, bound);
  3889. var n = ranges.length;
  3890. if (n) {
  3891. ranges.sort(compareRanges);
  3892. for (var i = 1, a = ranges[0], b, merged = [ a ]; i < n; ++i) {
  3893. b = ranges[i];
  3894. if (withinRange(b[0], a) || withinRange(b[1], a)) {
  3895. if (angle(a[0], b[1]) > angle(a[0], a[1])) a[1] = b[1];
  3896. if (angle(b[0], a[1]) > angle(a[0], a[1])) a[0] = b[0];
  3897. } else {
  3898. merged.push(a = b);
  3899. }
  3900. }
  3901. var best = -Infinity, dλ;
  3902. for (var n = merged.length - 1, i = 0, a = merged[n], b; i <= n; a = b, ++i) {
  3903. b = merged[i];
  3904. if ((dλ = angle(a[1], b[0])) > best) best = dλ, λ0 = b[0], λ1 = a[1];
  3905. }
  3906. }
  3907. ranges = range = null;
  3908. return λ0 === Infinity || φ0 === Infinity ? [ [ NaN, NaN ], [ NaN, NaN ] ] : [ [ λ0, φ0 ], [ λ1, φ1 ] ];
  3909. };
  3910. }();
  3911. d3.geo.centroid = function(object) {
  3912. d3_geo_centroidW0 = d3_geo_centroidW1 = d3_geo_centroidX0 = d3_geo_centroidY0 = d3_geo_centroidZ0 = d3_geo_centroidX1 = d3_geo_centroidY1 = d3_geo_centroidZ1 = d3_geo_centroidX2 = d3_geo_centroidY2 = d3_geo_centroidZ2 = 0;
  3913. d3.geo.stream(object, d3_geo_centroid);
  3914. var x = d3_geo_centroidX2, y = d3_geo_centroidY2, z = d3_geo_centroidZ2, m = x * x + y * y + z * z;
  3915. if (m < ε2) {
  3916. x = d3_geo_centroidX1, y = d3_geo_centroidY1, z = d3_geo_centroidZ1;
  3917. if (d3_geo_centroidW1 < ε) x = d3_geo_centroidX0, y = d3_geo_centroidY0, z = d3_geo_centroidZ0;
  3918. m = x * x + y * y + z * z;
  3919. if (m < ε2) return [ NaN, NaN ];
  3920. }
  3921. return [ Math.atan2(y, x) * d3_degrees, d3_asin(z / Math.sqrt(m)) * d3_degrees ];
  3922. };
  3923. var d3_geo_centroidW0, d3_geo_centroidW1, d3_geo_centroidX0, d3_geo_centroidY0, d3_geo_centroidZ0, d3_geo_centroidX1, d3_geo_centroidY1, d3_geo_centroidZ1, d3_geo_centroidX2, d3_geo_centroidY2, d3_geo_centroidZ2;
  3924. var d3_geo_centroid = {
  3925. sphere: d3_noop,
  3926. point: d3_geo_centroidPoint,
  3927. lineStart: d3_geo_centroidLineStart,
  3928. lineEnd: d3_geo_centroidLineEnd,
  3929. polygonStart: function() {
  3930. d3_geo_centroid.lineStart = d3_geo_centroidRingStart;
  3931. },
  3932. polygonEnd: function() {
  3933. d3_geo_centroid.lineStart = d3_geo_centroidLineStart;
  3934. }
  3935. };
  3936. function d3_geo_centroidPoint(λ, φ) {
  3937. λ *= d3_radians;
  3938. var cosφ = Math.cos(φ *= d3_radians);
  3939. d3_geo_centroidPointXYZ(cosφ * Math.cos(λ), cosφ * Math.sin(λ), Math.sin(φ));
  3940. }
  3941. function d3_geo_centroidPointXYZ(x, y, z) {
  3942. ++d3_geo_centroidW0;
  3943. d3_geo_centroidX0 += (x - d3_geo_centroidX0) / d3_geo_centroidW0;
  3944. d3_geo_centroidY0 += (y - d3_geo_centroidY0) / d3_geo_centroidW0;
  3945. d3_geo_centroidZ0 += (z - d3_geo_centroidZ0) / d3_geo_centroidW0;
  3946. }
  3947. function d3_geo_centroidLineStart() {
  3948. var x0, y0, z0;
  3949. d3_geo_centroid.point = function(λ, φ) {
  3950. λ *= d3_radians;
  3951. var cosφ = Math.cos(φ *= d3_radians);
  3952. x0 = cosφ * Math.cos(λ);
  3953. y0 = cosφ * Math.sin(λ);
  3954. z0 = Math.sin(φ);
  3955. d3_geo_centroid.point = nextPoint;
  3956. d3_geo_centroidPointXYZ(x0, y0, z0);
  3957. };
  3958. function nextPoint(λ, φ) {
  3959. λ *= d3_radians;
  3960. var cosφ = Math.cos(φ *= d3_radians), x = cosφ * Math.cos(λ), y = cosφ * Math.sin(λ), z = Math.sin(φ), w = Math.atan2(Math.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);
  3961. d3_geo_centroidW1 += w;
  3962. d3_geo_centroidX1 += w * (x0 + (x0 = x));
  3963. d3_geo_centroidY1 += w * (y0 + (y0 = y));
  3964. d3_geo_centroidZ1 += w * (z0 + (z0 = z));
  3965. d3_geo_centroidPointXYZ(x0, y0, z0);
  3966. }
  3967. }
  3968. function d3_geo_centroidLineEnd() {
  3969. d3_geo_centroid.point = d3_geo_centroidPoint;
  3970. }
  3971. function d3_geo_centroidRingStart() {
  3972. var λ00, φ00, x0, y0, z0;
  3973. d3_geo_centroid.point = function(λ, φ) {
  3974. λ00 = λ, φ00 = φ;
  3975. d3_geo_centroid.point = nextPoint;
  3976. λ *= d3_radians;
  3977. var cosφ = Math.cos(φ *= d3_radians);
  3978. x0 = cosφ * Math.cos(λ);
  3979. y0 = cosφ * Math.sin(λ);
  3980. z0 = Math.sin(φ);
  3981. d3_geo_centroidPointXYZ(x0, y0, z0);
  3982. };
  3983. d3_geo_centroid.lineEnd = function() {
  3984. nextPoint(λ00, φ00);
  3985. d3_geo_centroid.lineEnd = d3_geo_centroidLineEnd;
  3986. d3_geo_centroid.point = d3_geo_centroidPoint;
  3987. };
  3988. function nextPoint(λ, φ) {
  3989. λ *= d3_radians;
  3990. var cosφ = Math.cos(φ *= d3_radians), x = cosφ * Math.cos(λ), y = cosφ * Math.sin(λ), z = Math.sin(φ), cx = y0 * z - z0 * y, cy = z0 * x - x0 * z, cz = x0 * y - y0 * x, m = Math.sqrt(cx * cx + cy * cy + cz * cz), u = x0 * x + y0 * y + z0 * z, v = m && -d3_acos(u) / m, w = Math.atan2(m, u);
  3991. d3_geo_centroidX2 += v * cx;
  3992. d3_geo_centroidY2 += v * cy;
  3993. d3_geo_centroidZ2 += v * cz;
  3994. d3_geo_centroidW1 += w;
  3995. d3_geo_centroidX1 += w * (x0 + (x0 = x));
  3996. d3_geo_centroidY1 += w * (y0 + (y0 = y));
  3997. d3_geo_centroidZ1 += w * (z0 + (z0 = z));
  3998. d3_geo_centroidPointXYZ(x0, y0, z0);
  3999. }
  4000. }
  4001. function d3_geo_compose(a, b) {
  4002. function compose(x, y) {
  4003. return x = a(x, y), b(x[0], x[1]);
  4004. }
  4005. if (a.invert && b.invert) compose.invert = function(x, y) {
  4006. return x = b.invert(x, y), x && a.invert(x[0], x[1]);
  4007. };
  4008. return compose;
  4009. }
  4010. function d3_true() {
  4011. return true;
  4012. }
  4013. function d3_geo_clipPolygon(segments, compare, clipStartInside, interpolate, listener) {
  4014. var subject = [], clip = [];
  4015. segments.forEach(function(segment) {
  4016. if ((n = segment.length - 1) <= 0) return;
  4017. var n, p0 = segment[0], p1 = segment[n];
  4018. if (d3_geo_sphericalEqual(p0, p1)) {
  4019. listener.lineStart();
  4020. for (var i = 0; i < n; ++i) listener.point((p0 = segment[i])[0], p0[1]);
  4021. listener.lineEnd();
  4022. return;
  4023. }
  4024. var a = new d3_geo_clipPolygonIntersection(p0, segment, null, true), b = new d3_geo_clipPolygonIntersection(p0, null, a, false);
  4025. a.o = b;
  4026. subject.push(a);
  4027. clip.push(b);
  4028. a = new d3_geo_clipPolygonIntersection(p1, segment, null, false);
  4029. b = new d3_geo_clipPolygonIntersection(p1, null, a, true);
  4030. a.o = b;
  4031. subject.push(a);
  4032. clip.push(b);
  4033. });
  4034. clip.sort(compare);
  4035. d3_geo_clipPolygonLinkCircular(subject);
  4036. d3_geo_clipPolygonLinkCircular(clip);
  4037. if (!subject.length) return;
  4038. for (var i = 0, entry = clipStartInside, n = clip.length; i < n; ++i) {
  4039. clip[i].e = entry = !entry;
  4040. }
  4041. var start = subject[0], points, point;
  4042. while (1) {
  4043. var current = start, isSubject = true;
  4044. while (current.v) if ((current = current.n) === start) return;
  4045. points = current.z;
  4046. listener.lineStart();
  4047. do {
  4048. current.v = current.o.v = true;
  4049. if (current.e) {
  4050. if (isSubject) {
  4051. for (var i = 0, n = points.length; i < n; ++i) listener.point((point = points[i])[0], point[1]);
  4052. } else {
  4053. interpolate(current.x, current.n.x, 1, listener);
  4054. }
  4055. current = current.n;
  4056. } else {
  4057. if (isSubject) {
  4058. points = current.p.z;
  4059. for (var i = points.length - 1; i >= 0; --i) listener.point((point = points[i])[0], point[1]);
  4060. } else {
  4061. interpolate(current.x, current.p.x, -1, listener);
  4062. }
  4063. current = current.p;
  4064. }
  4065. current = current.o;
  4066. points = current.z;
  4067. isSubject = !isSubject;
  4068. } while (!current.v);
  4069. listener.lineEnd();
  4070. }
  4071. }
  4072. function d3_geo_clipPolygonLinkCircular(array) {
  4073. if (!(n = array.length)) return;
  4074. var n, i = 0, a = array[0], b;
  4075. while (++i < n) {
  4076. a.n = b = array[i];
  4077. b.p = a;
  4078. a = b;
  4079. }
  4080. a.n = b = array[0];
  4081. b.p = a;
  4082. }
  4083. function d3_geo_clipPolygonIntersection(point, points, other, entry) {
  4084. this.x = point;
  4085. this.z = points;
  4086. this.o = other;
  4087. this.e = entry;
  4088. this.v = false;
  4089. this.n = this.p = null;
  4090. }
  4091. function d3_geo_clip(pointVisible, clipLine, interpolate, clipStart) {
  4092. return function(rotate, listener) {
  4093. var line = clipLine(listener), rotatedClipStart = rotate.invert(clipStart[0], clipStart[1]);
  4094. var clip = {
  4095. point: point,
  4096. lineStart: lineStart,
  4097. lineEnd: lineEnd,
  4098. polygonStart: function() {
  4099. clip.point = pointRing;
  4100. clip.lineStart = ringStart;
  4101. clip.lineEnd = ringEnd;
  4102. segments = [];
  4103. polygon = [];
  4104. },
  4105. polygonEnd: function() {
  4106. clip.point = point;
  4107. clip.lineStart = lineStart;
  4108. clip.lineEnd = lineEnd;
  4109. segments = d3.merge(segments);
  4110. var clipStartInside = d3_geo_pointInPolygon(rotatedClipStart, polygon);
  4111. if (segments.length) {
  4112. if (!polygonStarted) listener.polygonStart(), polygonStarted = true;
  4113. d3_geo_clipPolygon(segments, d3_geo_clipSort, clipStartInside, interpolate, listener);
  4114. } else if (clipStartInside) {
  4115. if (!polygonStarted) listener.polygonStart(), polygonStarted = true;
  4116. listener.lineStart();
  4117. interpolate(null, null, 1, listener);
  4118. listener.lineEnd();
  4119. }
  4120. if (polygonStarted) listener.polygonEnd(), polygonStarted = false;
  4121. segments = polygon = null;
  4122. },
  4123. sphere: function() {
  4124. listener.polygonStart();
  4125. listener.lineStart();
  4126. interpolate(null, null, 1, listener);
  4127. listener.lineEnd();
  4128. listener.polygonEnd();
  4129. }
  4130. };
  4131. function point(λ, φ) {
  4132. var point = rotate(λ, φ);
  4133. if (pointVisible(λ = point[0], φ = point[1])) listener.point(λ, φ);
  4134. }
  4135. function pointLine(λ, φ) {
  4136. var point = rotate(λ, φ);
  4137. line.point(point[0], point[1]);
  4138. }
  4139. function lineStart() {
  4140. clip.point = pointLine;
  4141. line.lineStart();
  4142. }
  4143. function lineEnd() {
  4144. clip.point = point;
  4145. line.lineEnd();
  4146. }
  4147. var segments;
  4148. var buffer = d3_geo_clipBufferListener(), ringListener = clipLine(buffer), polygonStarted = false, polygon, ring;
  4149. function pointRing(λ, φ) {
  4150. ring.push([ λ, φ ]);
  4151. var point = rotate(λ, φ);
  4152. ringListener.point(point[0], point[1]);
  4153. }
  4154. function ringStart() {
  4155. ringListener.lineStart();
  4156. ring = [];
  4157. }
  4158. function ringEnd() {
  4159. pointRing(ring[0][0], ring[0][1]);
  4160. ringListener.lineEnd();
  4161. var clean = ringListener.clean(), ringSegments = buffer.buffer(), segment, n = ringSegments.length;
  4162. ring.pop();
  4163. polygon.push(ring);
  4164. ring = null;
  4165. if (!n) return;
  4166. if (clean & 1) {
  4167. segment = ringSegments[0];
  4168. var n = segment.length - 1, i = -1, point;
  4169. if (n > 0) {
  4170. if (!polygonStarted) listener.polygonStart(), polygonStarted = true;
  4171. listener.lineStart();
  4172. while (++i < n) listener.point((point = segment[i])[0], point[1]);
  4173. listener.lineEnd();
  4174. }
  4175. return;
  4176. }
  4177. if (n > 1 && clean & 2) ringSegments.push(ringSegments.pop().concat(ringSegments.shift()));
  4178. segments.push(ringSegments.filter(d3_geo_clipSegmentLength1));
  4179. }
  4180. return clip;
  4181. };
  4182. }
  4183. function d3_geo_clipSegmentLength1(segment) {
  4184. return segment.length > 1;
  4185. }
  4186. function d3_geo_clipBufferListener() {
  4187. var lines = [], line;
  4188. return {
  4189. lineStart: function() {
  4190. lines.push(line = []);
  4191. },
  4192. point: function(λ, φ) {
  4193. line.push([ λ, φ ]);
  4194. },
  4195. lineEnd: d3_noop,
  4196. buffer: function() {
  4197. var buffer = lines;
  4198. lines = [];
  4199. line = null;
  4200. return buffer;
  4201. },
  4202. rejoin: function() {
  4203. if (lines.length > 1) lines.push(lines.pop().concat(lines.shift()));
  4204. }
  4205. };
  4206. }
  4207. function d3_geo_clipSort(a, b) {
  4208. return ((a = a.x)[0] < 0 ? a[1] - halfπ - ε : halfπ - a[1]) - ((b = b.x)[0] < 0 ? b[1] - halfπ - ε : halfπ - b[1]);
  4209. }
  4210. var d3_geo_clipAntimeridian = d3_geo_clip(d3_true, d3_geo_clipAntimeridianLine, d3_geo_clipAntimeridianInterpolate, [ -π, -π / 2 ]);
  4211. function d3_geo_clipAntimeridianLine(listener) {
  4212. var λ0 = NaN, φ0 = NaN, sλ0 = NaN, clean;
  4213. return {
  4214. lineStart: function() {
  4215. listener.lineStart();
  4216. clean = 1;
  4217. },
  4218. point: function(λ1, φ1) {
  4219. var sλ1 = λ1 > 0 ? π : -π, dλ = abs(λ1 - λ0);
  4220. if (abs(dλ - π) < ε) {
  4221. listener.point(λ0, φ0 = (φ0 + φ1) / 2 > 0 ? halfπ : -halfπ);
  4222. listener.point(sλ0, φ0);
  4223. listener.lineEnd();
  4224. listener.lineStart();
  4225. listener.point(sλ1, φ0);
  4226. listener.point(λ1, φ0);
  4227. clean = 0;
  4228. } else if (sλ0 !== sλ1 && dλ >= π) {
  4229. if (abs(λ0 - sλ0) < ε) λ0 -= sλ0 * ε;
  4230. if (abs(λ1 - sλ1) < ε) λ1 -= sλ1 * ε;
  4231. φ0 = d3_geo_clipAntimeridianIntersect(λ0, φ0, λ1, φ1);
  4232. listener.point(sλ0, φ0);
  4233. listener.lineEnd();
  4234. listener.lineStart();
  4235. listener.point(sλ1, φ0);
  4236. clean = 0;
  4237. }
  4238. listener.point(λ0 = λ1, φ0 = φ1);
  4239. sλ0 = sλ1;
  4240. },
  4241. lineEnd: function() {
  4242. listener.lineEnd();
  4243. λ0 = φ0 = NaN;
  4244. },
  4245. clean: function() {
  4246. return 2 - clean;
  4247. }
  4248. };
  4249. }
  4250. function d3_geo_clipAntimeridianIntersect(λ0, φ0, λ1, φ1) {
  4251. var cosφ0, cosφ1, sinλ0_λ1 = Math.sin(λ0 - λ1);
  4252. return abs(sinλ0_λ1) > ε ? Math.atan((Math.sin(φ0) * (cosφ1 = Math.cos(φ1)) * Math.sin(λ1) - Math.sin(φ1) * (cosφ0 = Math.cos(φ0)) * Math.sin(λ0)) / (cosφ0 * cosφ1 * sinλ0_λ1)) : (φ0 + φ1) / 2;
  4253. }
  4254. function d3_geo_clipAntimeridianInterpolate(from, to, direction, listener) {
  4255. var φ;
  4256. if (from == null) {
  4257. φ = direction * halfπ;
  4258. listener.point(-π, φ);
  4259. listener.point(0, φ);
  4260. listener.point(π, φ);
  4261. listener.point(π, 0);
  4262. listener.point(π, -φ);
  4263. listener.point(0, -φ);
  4264. listener.point(-π, -φ);
  4265. listener.point(-π, 0);
  4266. listener.point(-π, φ);
  4267. } else if (abs(from[0] - to[0]) > ε) {
  4268. var s = from[0] < to[0] ? π : -π;
  4269. φ = direction * s / 2;
  4270. listener.point(-s, φ);
  4271. listener.point(0, φ);
  4272. listener.point(s, φ);
  4273. } else {
  4274. listener.point(to[0], to[1]);
  4275. }
  4276. }
  4277. function d3_geo_pointInPolygon(point, polygon) {
  4278. var meridian = point[0], parallel = point[1], meridianNormal = [ Math.sin(meridian), -Math.cos(meridian), 0 ], polarAngle = 0, winding = 0;
  4279. d3_geo_areaRingSum.reset();
  4280. for (var i = 0, n = polygon.length; i < n; ++i) {
  4281. var ring = polygon[i], m = ring.length;
  4282. if (!m) continue;
  4283. var point0 = ring[0], λ0 = point0[0], φ0 = point0[1] / 2 + π / 4, sinφ0 = Math.sin(φ0), cosφ0 = Math.cos(φ0), j = 1;
  4284. while (true) {
  4285. if (j === m) j = 0;
  4286. point = ring[j];
  4287. var λ = point[0], φ = point[1] / 2 + π / 4, sinφ = Math.sin(φ), cosφ = Math.cos(φ), dλ = λ - λ0, sdλ = dλ >= 0 ? 1 : -1, adλ = sdλ * dλ, antimeridian = adλ > π, k = sinφ0 * sinφ;
  4288. d3_geo_areaRingSum.add(Math.atan2(k * sdλ * Math.sin(adλ), cosφ0 * cosφ + k * Math.cos(adλ)));
  4289. polarAngle += antimeridian ? dλ + sdλ * τ : dλ;
  4290. if (antimeridian ^ λ0 >= meridian ^ λ >= meridian) {
  4291. var arc = d3_geo_cartesianCross(d3_geo_cartesian(point0), d3_geo_cartesian(point));
  4292. d3_geo_cartesianNormalize(arc);
  4293. var intersection = d3_geo_cartesianCross(meridianNormal, arc);
  4294. d3_geo_cartesianNormalize(intersection);
  4295. var φarc = (antimeridian ^ dλ >= 0 ? -1 : 1) * d3_asin(intersection[2]);
  4296. if (parallel > φarc || parallel === φarc && (arc[0] || arc[1])) {
  4297. winding += antimeridian ^ dλ >= 0 ? 1 : -1;
  4298. }
  4299. }
  4300. if (!j++) break;
  4301. λ0 = λ, sinφ0 = sinφ, cosφ0 = cosφ, point0 = point;
  4302. }
  4303. }
  4304. return (polarAngle < -ε || polarAngle < ε && d3_geo_areaRingSum < -ε) ^ winding & 1;
  4305. }
  4306. function d3_geo_clipCircle(radius) {
  4307. var cr = Math.cos(radius), smallRadius = cr > 0, notHemisphere = abs(cr) > ε, interpolate = d3_geo_circleInterpolate(radius, 6 * d3_radians);
  4308. return d3_geo_clip(visible, clipLine, interpolate, smallRadius ? [ 0, -radius ] : [ -π, radius - π ]);
  4309. function visible(λ, φ) {
  4310. return Math.cos(λ) * Math.cos(φ) > cr;
  4311. }
  4312. function clipLine(listener) {
  4313. var point0, c0, v0, v00, clean;
  4314. return {
  4315. lineStart: function() {
  4316. v00 = v0 = false;
  4317. clean = 1;
  4318. },
  4319. point: function(λ, φ) {
  4320. var point1 = [ λ, φ ], point2, v = visible(λ, φ), c = smallRadius ? v ? 0 : code(λ, φ) : v ? code(λ + (λ < 0 ? π : -π), φ) : 0;
  4321. if (!point0 && (v00 = v0 = v)) listener.lineStart();
  4322. if (v !== v0) {
  4323. point2 = intersect(point0, point1);
  4324. if (d3_geo_sphericalEqual(point0, point2) || d3_geo_sphericalEqual(point1, point2)) {
  4325. point1[0] += ε;
  4326. point1[1] += ε;
  4327. v = visible(point1[0], point1[1]);
  4328. }
  4329. }
  4330. if (v !== v0) {
  4331. clean = 0;
  4332. if (v) {
  4333. listener.lineStart();
  4334. point2 = intersect(point1, point0);
  4335. listener.point(point2[0], point2[1]);
  4336. } else {
  4337. point2 = intersect(point0, point1);
  4338. listener.point(point2[0], point2[1]);
  4339. listener.lineEnd();
  4340. }
  4341. point0 = point2;
  4342. } else if (notHemisphere && point0 && smallRadius ^ v) {
  4343. var t;
  4344. if (!(c & c0) && (t = intersect(point1, point0, true))) {
  4345. clean = 0;
  4346. if (smallRadius) {
  4347. listener.lineStart();
  4348. listener.point(t[0][0], t[0][1]);
  4349. listener.point(t[1][0], t[1][1]);
  4350. listener.lineEnd();
  4351. } else {
  4352. listener.point(t[1][0], t[1][1]);
  4353. listener.lineEnd();
  4354. listener.lineStart();
  4355. listener.point(t[0][0], t[0][1]);
  4356. }
  4357. }
  4358. }
  4359. if (v && (!point0 || !d3_geo_sphericalEqual(point0, point1))) {
  4360. listener.point(point1[0], point1[1]);
  4361. }
  4362. point0 = point1, v0 = v, c0 = c;
  4363. },
  4364. lineEnd: function() {
  4365. if (v0) listener.lineEnd();
  4366. point0 = null;
  4367. },
  4368. clean: function() {
  4369. return clean | (v00 && v0) << 1;
  4370. }
  4371. };
  4372. }
  4373. function intersect(a, b, two) {
  4374. var pa = d3_geo_cartesian(a), pb = d3_geo_cartesian(b);
  4375. var n1 = [ 1, 0, 0 ], n2 = d3_geo_cartesianCross(pa, pb), n2n2 = d3_geo_cartesianDot(n2, n2), n1n2 = n2[0], determinant = n2n2 - n1n2 * n1n2;
  4376. if (!determinant) return !two && a;
  4377. var c1 = cr * n2n2 / determinant, c2 = -cr * n1n2 / determinant, n1xn2 = d3_geo_cartesianCross(n1, n2), A = d3_geo_cartesianScale(n1, c1), B = d3_geo_cartesianScale(n2, c2);
  4378. d3_geo_cartesianAdd(A, B);
  4379. var u = n1xn2, w = d3_geo_cartesianDot(A, u), uu = d3_geo_cartesianDot(u, u), t2 = w * w - uu * (d3_geo_cartesianDot(A, A) - 1);
  4380. if (t2 < 0) return;
  4381. var t = Math.sqrt(t2), q = d3_geo_cartesianScale(u, (-w - t) / uu);
  4382. d3_geo_cartesianAdd(q, A);
  4383. q = d3_geo_spherical(q);
  4384. if (!two) return q;
  4385. var λ0 = a[0], λ1 = b[0], φ0 = a[1], φ1 = b[1], z;
  4386. if (λ1 < λ0) z = λ0, λ0 = λ1, λ1 = z;
  4387. var δλ = λ1 - λ0, polar = abs(δλ - π) < ε, meridian = polar || δλ < ε;
  4388. if (!polar && φ1 < φ0) z = φ0, φ0 = φ1, φ1 = z;
  4389. if (meridian ? polar ? φ0 + φ1 > 0 ^ q[1] < (abs(q[0] - λ0) < ε ? φ0 : φ1) : φ0 <= q[1] && q[1] <= φ1 : δλ > π ^ (λ0 <= q[0] && q[0] <= λ1)) {
  4390. var q1 = d3_geo_cartesianScale(u, (-w + t) / uu);
  4391. d3_geo_cartesianAdd(q1, A);
  4392. return [ q, d3_geo_spherical(q1) ];
  4393. }
  4394. }
  4395. function code(λ, φ) {
  4396. var r = smallRadius ? radius : π - radius, code = 0;
  4397. if (λ < -r) code |= 1; else if (λ > r) code |= 2;
  4398. if (φ < -r) code |= 4; else if (φ > r) code |= 8;
  4399. return code;
  4400. }
  4401. }
  4402. function d3_geom_clipLine(x0, y0, x1, y1) {
  4403. return function(line) {
  4404. var a = line.a, b = line.b, ax = a.x, ay = a.y, bx = b.x, by = b.y, t0 = 0, t1 = 1, dx = bx - ax, dy = by - ay, r;
  4405. r = x0 - ax;
  4406. if (!dx && r > 0) return;
  4407. r /= dx;
  4408. if (dx < 0) {
  4409. if (r < t0) return;
  4410. if (r < t1) t1 = r;
  4411. } else if (dx > 0) {
  4412. if (r > t1) return;
  4413. if (r > t0) t0 = r;
  4414. }
  4415. r = x1 - ax;
  4416. if (!dx && r < 0) return;
  4417. r /= dx;
  4418. if (dx < 0) {
  4419. if (r > t1) return;
  4420. if (r > t0) t0 = r;
  4421. } else if (dx > 0) {
  4422. if (r < t0) return;
  4423. if (r < t1) t1 = r;
  4424. }
  4425. r = y0 - ay;
  4426. if (!dy && r > 0) return;
  4427. r /= dy;
  4428. if (dy < 0) {
  4429. if (r < t0) return;
  4430. if (r < t1) t1 = r;
  4431. } else if (dy > 0) {
  4432. if (r > t1) return;
  4433. if (r > t0) t0 = r;
  4434. }
  4435. r = y1 - ay;
  4436. if (!dy && r < 0) return;
  4437. r /= dy;
  4438. if (dy < 0) {
  4439. if (r > t1) return;
  4440. if (r > t0) t0 = r;
  4441. } else if (dy > 0) {
  4442. if (r < t0) return;
  4443. if (r < t1) t1 = r;
  4444. }
  4445. if (t0 > 0) line.a = {
  4446. x: ax + t0 * dx,
  4447. y: ay + t0 * dy
  4448. };
  4449. if (t1 < 1) line.b = {
  4450. x: ax + t1 * dx,
  4451. y: ay + t1 * dy
  4452. };
  4453. return line;
  4454. };
  4455. }
  4456. var d3_geo_clipExtentMAX = 1e9;
  4457. d3.geo.clipExtent = function() {
  4458. var x0, y0, x1, y1, stream, clip, clipExtent = {
  4459. stream: function(output) {
  4460. if (stream) stream.valid = false;
  4461. stream = clip(output);
  4462. stream.valid = true;
  4463. return stream;
  4464. },
  4465. extent: function(_) {
  4466. if (!arguments.length) return [ [ x0, y0 ], [ x1, y1 ] ];
  4467. clip = d3_geo_clipExtent(x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1]);
  4468. if (stream) stream.valid = false, stream = null;
  4469. return clipExtent;
  4470. }
  4471. };
  4472. return clipExtent.extent([ [ 0, 0 ], [ 960, 500 ] ]);
  4473. };
  4474. function d3_geo_clipExtent(x0, y0, x1, y1) {
  4475. return function(listener) {
  4476. var listener_ = listener, bufferListener = d3_geo_clipBufferListener(), clipLine = d3_geom_clipLine(x0, y0, x1, y1), segments, polygon, ring;
  4477. var clip = {
  4478. point: point,
  4479. lineStart: lineStart,
  4480. lineEnd: lineEnd,
  4481. polygonStart: function() {
  4482. listener = bufferListener;
  4483. segments = [];
  4484. polygon = [];
  4485. clean = true;
  4486. },
  4487. polygonEnd: function() {
  4488. listener = listener_;
  4489. segments = d3.merge(segments);
  4490. var clipStartInside = insidePolygon([ x0, y1 ]), inside = clean && clipStartInside, visible = segments.length;
  4491. if (inside || visible) {
  4492. listener.polygonStart();
  4493. if (inside) {
  4494. listener.lineStart();
  4495. interpolate(null, null, 1, listener);
  4496. listener.lineEnd();
  4497. }
  4498. if (visible) {
  4499. d3_geo_clipPolygon(segments, compare, clipStartInside, interpolate, listener);
  4500. }
  4501. listener.polygonEnd();
  4502. }
  4503. segments = polygon = ring = null;
  4504. }
  4505. };
  4506. function insidePolygon(p) {
  4507. var wn = 0, n = polygon.length, y = p[1];
  4508. for (var i = 0; i < n; ++i) {
  4509. for (var j = 1, v = polygon[i], m = v.length, a = v[0], b; j < m; ++j) {
  4510. b = v[j];
  4511. if (a[1] <= y) {
  4512. if (b[1] > y && d3_cross2d(a, b, p) > 0) ++wn;
  4513. } else {
  4514. if (b[1] <= y && d3_cross2d(a, b, p) < 0) --wn;
  4515. }
  4516. a = b;
  4517. }
  4518. }
  4519. return wn !== 0;
  4520. }
  4521. function interpolate(from, to, direction, listener) {
  4522. var a = 0, a1 = 0;
  4523. if (from == null || (a = corner(from, direction)) !== (a1 = corner(to, direction)) || comparePoints(from, to) < 0 ^ direction > 0) {
  4524. do {
  4525. listener.point(a === 0 || a === 3 ? x0 : x1, a > 1 ? y1 : y0);
  4526. } while ((a = (a + direction + 4) % 4) !== a1);
  4527. } else {
  4528. listener.point(to[0], to[1]);
  4529. }
  4530. }
  4531. function pointVisible(x, y) {
  4532. return x0 <= x && x <= x1 && y0 <= y && y <= y1;
  4533. }
  4534. function point(x, y) {
  4535. if (pointVisible(x, y)) listener.point(x, y);
  4536. }
  4537. var x__, y__, v__, x_, y_, v_, first, clean;
  4538. function lineStart() {
  4539. clip.point = linePoint;
  4540. if (polygon) polygon.push(ring = []);
  4541. first = true;
  4542. v_ = false;
  4543. x_ = y_ = NaN;
  4544. }
  4545. function lineEnd() {
  4546. if (segments) {
  4547. linePoint(x__, y__);
  4548. if (v__ && v_) bufferListener.rejoin();
  4549. segments.push(bufferListener.buffer());
  4550. }
  4551. clip.point = point;
  4552. if (v_) listener.lineEnd();
  4553. }
  4554. function linePoint(x, y) {
  4555. x = Math.max(-d3_geo_clipExtentMAX, Math.min(d3_geo_clipExtentMAX, x));
  4556. y = Math.max(-d3_geo_clipExtentMAX, Math.min(d3_geo_clipExtentMAX, y));
  4557. var v = pointVisible(x, y);
  4558. if (polygon) ring.push([ x, y ]);
  4559. if (first) {
  4560. x__ = x, y__ = y, v__ = v;
  4561. first = false;
  4562. if (v) {
  4563. listener.lineStart();
  4564. listener.point(x, y);
  4565. }
  4566. } else {
  4567. if (v && v_) listener.point(x, y); else {
  4568. var l = {
  4569. a: {
  4570. x: x_,
  4571. y: y_
  4572. },
  4573. b: {
  4574. x: x,
  4575. y: y
  4576. }
  4577. };
  4578. if (clipLine(l)) {
  4579. if (!v_) {
  4580. listener.lineStart();
  4581. listener.point(l.a.x, l.a.y);
  4582. }
  4583. listener.point(l.b.x, l.b.y);
  4584. if (!v) listener.lineEnd();
  4585. clean = false;
  4586. } else if (v) {
  4587. listener.lineStart();
  4588. listener.point(x, y);
  4589. clean = false;
  4590. }
  4591. }
  4592. }
  4593. x_ = x, y_ = y, v_ = v;
  4594. }
  4595. return clip;
  4596. };
  4597. function corner(p, direction) {
  4598. return abs(p[0] - x0) < ε ? direction > 0 ? 0 : 3 : abs(p[0] - x1) < ε ? direction > 0 ? 2 : 1 : abs(p[1] - y0) < ε ? direction > 0 ? 1 : 0 : direction > 0 ? 3 : 2;
  4599. }
  4600. function compare(a, b) {
  4601. return comparePoints(a.x, b.x);
  4602. }
  4603. function comparePoints(a, b) {
  4604. var ca = corner(a, 1), cb = corner(b, 1);
  4605. return ca !== cb ? ca - cb : ca === 0 ? b[1] - a[1] : ca === 1 ? a[0] - b[0] : ca === 2 ? a[1] - b[1] : b[0] - a[0];
  4606. }
  4607. }
  4608. function d3_geo_conic(projectAt) {
  4609. var φ0 = 0, φ1 = π / 3, m = d3_geo_projectionMutator(projectAt), p = m(φ0, φ1);
  4610. p.parallels = function(_) {
  4611. if (!arguments.length) return [ φ0 / π * 180, φ1 / π * 180 ];
  4612. return m(φ0 = _[0] * π / 180, φ1 = _[1] * π / 180);
  4613. };
  4614. return p;
  4615. }
  4616. function d3_geo_conicEqualArea(φ0, φ1) {
  4617. var sinφ0 = Math.sin(φ0), n = (sinφ0 + Math.sin(φ1)) / 2, C = 1 + sinφ0 * (2 * n - sinφ0), ρ0 = Math.sqrt(C) / n;
  4618. function forward(λ, φ) {
  4619. var ρ = Math.sqrt(C - 2 * n * Math.sin(φ)) / n;
  4620. return [ ρ * Math.sin(λ *= n), ρ0 - ρ * Math.cos(λ) ];
  4621. }
  4622. forward.invert = function(x, y) {
  4623. var ρ0_y = ρ0 - y;
  4624. return [ Math.atan2(x, ρ0_y) / n, d3_asin((C - (x * x + ρ0_y * ρ0_y) * n * n) / (2 * n)) ];
  4625. };
  4626. return forward;
  4627. }
  4628. (d3.geo.conicEqualArea = function() {
  4629. return d3_geo_conic(d3_geo_conicEqualArea);
  4630. }).raw = d3_geo_conicEqualArea;
  4631. d3.geo.albers = function() {
  4632. return d3.geo.conicEqualArea().rotate([ 96, 0 ]).center([ -.6, 38.7 ]).parallels([ 29.5, 45.5 ]).scale(1070);
  4633. };
  4634. d3.geo.albersUsa = function() {
  4635. var lower48 = d3.geo.albers();
  4636. var alaska = d3.geo.conicEqualArea().rotate([ 154, 0 ]).center([ -2, 58.5 ]).parallels([ 55, 65 ]);
  4637. var hawaii = d3.geo.conicEqualArea().rotate([ 157, 0 ]).center([ -3, 19.9 ]).parallels([ 8, 18 ]);
  4638. var point, pointStream = {
  4639. point: function(x, y) {
  4640. point = [ x, y ];
  4641. }
  4642. }, lower48Point, alaskaPoint, hawaiiPoint;
  4643. function albersUsa(coordinates) {
  4644. var x = coordinates[0], y = coordinates[1];
  4645. point = null;
  4646. (lower48Point(x, y), point) || (alaskaPoint(x, y), point) || hawaiiPoint(x, y);
  4647. return point;
  4648. }
  4649. albersUsa.invert = function(coordinates) {
  4650. var k = lower48.scale(), t = lower48.translate(), x = (coordinates[0] - t[0]) / k, y = (coordinates[1] - t[1]) / k;
  4651. return (y >= .12 && y < .234 && x >= -.425 && x < -.214 ? alaska : y >= .166 && y < .234 && x >= -.214 && x < -.115 ? hawaii : lower48).invert(coordinates);
  4652. };
  4653. albersUsa.stream = function(stream) {
  4654. var lower48Stream = lower48.stream(stream), alaskaStream = alaska.stream(stream), hawaiiStream = hawaii.stream(stream);
  4655. return {
  4656. point: function(x, y) {
  4657. lower48Stream.point(x, y);
  4658. alaskaStream.point(x, y);
  4659. hawaiiStream.point(x, y);
  4660. },
  4661. sphere: function() {
  4662. lower48Stream.sphere();
  4663. alaskaStream.sphere();
  4664. hawaiiStream.sphere();
  4665. },
  4666. lineStart: function() {
  4667. lower48Stream.lineStart();
  4668. alaskaStream.lineStart();
  4669. hawaiiStream.lineStart();
  4670. },
  4671. lineEnd: function() {
  4672. lower48Stream.lineEnd();
  4673. alaskaStream.lineEnd();
  4674. hawaiiStream.lineEnd();
  4675. },
  4676. polygonStart: function() {
  4677. lower48Stream.polygonStart();
  4678. alaskaStream.polygonStart();
  4679. hawaiiStream.polygonStart();
  4680. },
  4681. polygonEnd: function() {
  4682. lower48Stream.polygonEnd();
  4683. alaskaStream.polygonEnd();
  4684. hawaiiStream.polygonEnd();
  4685. }
  4686. };
  4687. };
  4688. albersUsa.precision = function(_) {
  4689. if (!arguments.length) return lower48.precision();
  4690. lower48.precision(_);
  4691. alaska.precision(_);
  4692. hawaii.precision(_);
  4693. return albersUsa;
  4694. };
  4695. albersUsa.scale = function(_) {
  4696. if (!arguments.length) return lower48.scale();
  4697. lower48.scale(_);
  4698. alaska.scale(_ * .35);
  4699. hawaii.scale(_);
  4700. return albersUsa.translate(lower48.translate());
  4701. };
  4702. albersUsa.translate = function(_) {
  4703. if (!arguments.length) return lower48.translate();
  4704. var k = lower48.scale(), x = +_[0], y = +_[1];
  4705. lower48Point = lower48.translate(_).clipExtent([ [ x - .455 * k, y - .238 * k ], [ x + .455 * k, y + .238 * k ] ]).stream(pointStream).point;
  4706. alaskaPoint = alaska.translate([ x - .307 * k, y + .201 * k ]).clipExtent([ [ x - .425 * k + ε, y + .12 * k + ε ], [ x - .214 * k - ε, y + .234 * k - ε ] ]).stream(pointStream).point;
  4707. hawaiiPoint = hawaii.translate([ x - .205 * k, y + .212 * k ]).clipExtent([ [ x - .214 * k + ε, y + .166 * k + ε ], [ x - .115 * k - ε, y + .234 * k - ε ] ]).stream(pointStream).point;
  4708. return albersUsa;
  4709. };
  4710. return albersUsa.scale(1070);
  4711. };
  4712. var d3_geo_pathAreaSum, d3_geo_pathAreaPolygon, d3_geo_pathArea = {
  4713. point: d3_noop,
  4714. lineStart: d3_noop,
  4715. lineEnd: d3_noop,
  4716. polygonStart: function() {
  4717. d3_geo_pathAreaPolygon = 0;
  4718. d3_geo_pathArea.lineStart = d3_geo_pathAreaRingStart;
  4719. },
  4720. polygonEnd: function() {
  4721. d3_geo_pathArea.lineStart = d3_geo_pathArea.lineEnd = d3_geo_pathArea.point = d3_noop;
  4722. d3_geo_pathAreaSum += abs(d3_geo_pathAreaPolygon / 2);
  4723. }
  4724. };
  4725. function d3_geo_pathAreaRingStart() {
  4726. var x00, y00, x0, y0;
  4727. d3_geo_pathArea.point = function(x, y) {
  4728. d3_geo_pathArea.point = nextPoint;
  4729. x00 = x0 = x, y00 = y0 = y;
  4730. };
  4731. function nextPoint(x, y) {
  4732. d3_geo_pathAreaPolygon += y0 * x - x0 * y;
  4733. x0 = x, y0 = y;
  4734. }
  4735. d3_geo_pathArea.lineEnd = function() {
  4736. nextPoint(x00, y00);
  4737. };
  4738. }
  4739. var d3_geo_pathBoundsX0, d3_geo_pathBoundsY0, d3_geo_pathBoundsX1, d3_geo_pathBoundsY1;
  4740. var d3_geo_pathBounds = {
  4741. point: d3_geo_pathBoundsPoint,
  4742. lineStart: d3_noop,
  4743. lineEnd: d3_noop,
  4744. polygonStart: d3_noop,
  4745. polygonEnd: d3_noop
  4746. };
  4747. function d3_geo_pathBoundsPoint(x, y) {
  4748. if (x < d3_geo_pathBoundsX0) d3_geo_pathBoundsX0 = x;
  4749. if (x > d3_geo_pathBoundsX1) d3_geo_pathBoundsX1 = x;
  4750. if (y < d3_geo_pathBoundsY0) d3_geo_pathBoundsY0 = y;
  4751. if (y > d3_geo_pathBoundsY1) d3_geo_pathBoundsY1 = y;
  4752. }
  4753. function d3_geo_pathBuffer() {
  4754. var pointCircle = d3_geo_pathBufferCircle(4.5), buffer = [];
  4755. var stream = {
  4756. point: point,
  4757. lineStart: function() {
  4758. stream.point = pointLineStart;
  4759. },
  4760. lineEnd: lineEnd,
  4761. polygonStart: function() {
  4762. stream.lineEnd = lineEndPolygon;
  4763. },
  4764. polygonEnd: function() {
  4765. stream.lineEnd = lineEnd;
  4766. stream.point = point;
  4767. },
  4768. pointRadius: function(_) {
  4769. pointCircle = d3_geo_pathBufferCircle(_);
  4770. return stream;
  4771. },
  4772. result: function() {
  4773. if (buffer.length) {
  4774. var result = buffer.join("");
  4775. buffer = [];
  4776. return result;
  4777. }
  4778. }
  4779. };
  4780. function point(x, y) {
  4781. buffer.push("M", x, ",", y, pointCircle);
  4782. }
  4783. function pointLineStart(x, y) {
  4784. buffer.push("M", x, ",", y);
  4785. stream.point = pointLine;
  4786. }
  4787. function pointLine(x, y) {
  4788. buffer.push("L", x, ",", y);
  4789. }
  4790. function lineEnd() {
  4791. stream.point = point;
  4792. }
  4793. function lineEndPolygon() {
  4794. buffer.push("Z");
  4795. }
  4796. return stream;
  4797. }
  4798. function d3_geo_pathBufferCircle(radius) {
  4799. return "m0," + radius + "a" + radius + "," + radius + " 0 1,1 0," + -2 * radius + "a" + radius + "," + radius + " 0 1,1 0," + 2 * radius + "z";
  4800. }
  4801. var d3_geo_pathCentroid = {
  4802. point: d3_geo_pathCentroidPoint,
  4803. lineStart: d3_geo_pathCentroidLineStart,
  4804. lineEnd: d3_geo_pathCentroidLineEnd,
  4805. polygonStart: function() {
  4806. d3_geo_pathCentroid.lineStart = d3_geo_pathCentroidRingStart;
  4807. },
  4808. polygonEnd: function() {
  4809. d3_geo_pathCentroid.point = d3_geo_pathCentroidPoint;
  4810. d3_geo_pathCentroid.lineStart = d3_geo_pathCentroidLineStart;
  4811. d3_geo_pathCentroid.lineEnd = d3_geo_pathCentroidLineEnd;
  4812. }
  4813. };
  4814. function d3_geo_pathCentroidPoint(x, y) {
  4815. d3_geo_centroidX0 += x;
  4816. d3_geo_centroidY0 += y;
  4817. ++d3_geo_centroidZ0;
  4818. }
  4819. function d3_geo_pathCentroidLineStart() {
  4820. var x0, y0;
  4821. d3_geo_pathCentroid.point = function(x, y) {
  4822. d3_geo_pathCentroid.point = nextPoint;
  4823. d3_geo_pathCentroidPoint(x0 = x, y0 = y);
  4824. };
  4825. function nextPoint(x, y) {
  4826. var dx = x - x0, dy = y - y0, z = Math.sqrt(dx * dx + dy * dy);
  4827. d3_geo_centroidX1 += z * (x0 + x) / 2;
  4828. d3_geo_centroidY1 += z * (y0 + y) / 2;
  4829. d3_geo_centroidZ1 += z;
  4830. d3_geo_pathCentroidPoint(x0 = x, y0 = y);
  4831. }
  4832. }
  4833. function d3_geo_pathCentroidLineEnd() {
  4834. d3_geo_pathCentroid.point = d3_geo_pathCentroidPoint;
  4835. }
  4836. function d3_geo_pathCentroidRingStart() {
  4837. var x00, y00, x0, y0;
  4838. d3_geo_pathCentroid.point = function(x, y) {
  4839. d3_geo_pathCentroid.point = nextPoint;
  4840. d3_geo_pathCentroidPoint(x00 = x0 = x, y00 = y0 = y);
  4841. };
  4842. function nextPoint(x, y) {
  4843. var dx = x - x0, dy = y - y0, z = Math.sqrt(dx * dx + dy * dy);
  4844. d3_geo_centroidX1 += z * (x0 + x) / 2;
  4845. d3_geo_centroidY1 += z * (y0 + y) / 2;
  4846. d3_geo_centroidZ1 += z;
  4847. z = y0 * x - x0 * y;
  4848. d3_geo_centroidX2 += z * (x0 + x);
  4849. d3_geo_centroidY2 += z * (y0 + y);
  4850. d3_geo_centroidZ2 += z * 3;
  4851. d3_geo_pathCentroidPoint(x0 = x, y0 = y);
  4852. }
  4853. d3_geo_pathCentroid.lineEnd = function() {
  4854. nextPoint(x00, y00);
  4855. };
  4856. }
  4857. function d3_geo_pathContext(context) {
  4858. var pointRadius = 4.5;
  4859. var stream = {
  4860. point: point,
  4861. lineStart: function() {
  4862. stream.point = pointLineStart;
  4863. },
  4864. lineEnd: lineEnd,
  4865. polygonStart: function() {
  4866. stream.lineEnd = lineEndPolygon;
  4867. },
  4868. polygonEnd: function() {
  4869. stream.lineEnd = lineEnd;
  4870. stream.point = point;
  4871. },
  4872. pointRadius: function(_) {
  4873. pointRadius = _;
  4874. return stream;
  4875. },
  4876. result: d3_noop
  4877. };
  4878. function point(x, y) {
  4879. context.moveTo(x + pointRadius, y);
  4880. context.arc(x, y, pointRadius, 0, τ);
  4881. }
  4882. function pointLineStart(x, y) {
  4883. context.moveTo(x, y);
  4884. stream.point = pointLine;
  4885. }
  4886. function pointLine(x, y) {
  4887. context.lineTo(x, y);
  4888. }
  4889. function lineEnd() {
  4890. stream.point = point;
  4891. }
  4892. function lineEndPolygon() {
  4893. context.closePath();
  4894. }
  4895. return stream;
  4896. }
  4897. function d3_geo_resample(project) {
  4898. var δ2 = .5, cosMinDistance = Math.cos(30 * d3_radians), maxDepth = 16;
  4899. function resample(stream) {
  4900. return (maxDepth ? resampleRecursive : resampleNone)(stream);
  4901. }
  4902. function resampleNone(stream) {
  4903. return d3_geo_transformPoint(stream, function(x, y) {
  4904. x = project(x, y);
  4905. stream.point(x[0], x[1]);
  4906. });
  4907. }
  4908. function resampleRecursive(stream) {
  4909. var λ00, φ00, x00, y00, a00, b00, c00, λ0, x0, y0, a0, b0, c0;
  4910. var resample = {
  4911. point: point,
  4912. lineStart: lineStart,
  4913. lineEnd: lineEnd,
  4914. polygonStart: function() {
  4915. stream.polygonStart();
  4916. resample.lineStart = ringStart;
  4917. },
  4918. polygonEnd: function() {
  4919. stream.polygonEnd();
  4920. resample.lineStart = lineStart;
  4921. }
  4922. };
  4923. function point(x, y) {
  4924. x = project(x, y);
  4925. stream.point(x[0], x[1]);
  4926. }
  4927. function lineStart() {
  4928. x0 = NaN;
  4929. resample.point = linePoint;
  4930. stream.lineStart();
  4931. }
  4932. function linePoint(λ, φ) {
  4933. var c = d3_geo_cartesian([ λ, φ ]), p = project(λ, φ);
  4934. resampleLineTo(x0, y0, λ0, a0, b0, c0, x0 = p[0], y0 = p[1], λ0 = λ, a0 = c[0], b0 = c[1], c0 = c[2], maxDepth, stream);
  4935. stream.point(x0, y0);
  4936. }
  4937. function lineEnd() {
  4938. resample.point = point;
  4939. stream.lineEnd();
  4940. }
  4941. function ringStart() {
  4942. lineStart();
  4943. resample.point = ringPoint;
  4944. resample.lineEnd = ringEnd;
  4945. }
  4946. function ringPoint(λ, φ) {
  4947. linePoint(λ00 = λ, φ00 = φ), x00 = x0, y00 = y0, a00 = a0, b00 = b0, c00 = c0;
  4948. resample.point = linePoint;
  4949. }
  4950. function ringEnd() {
  4951. resampleLineTo(x0, y0, λ0, a0, b0, c0, x00, y00, λ00, a00, b00, c00, maxDepth, stream);
  4952. resample.lineEnd = lineEnd;
  4953. lineEnd();
  4954. }
  4955. return resample;
  4956. }
  4957. function resampleLineTo(x0, y0, λ0, a0, b0, c0, x1, y1, λ1, a1, b1, c1, depth, stream) {
  4958. var dx = x1 - x0, dy = y1 - y0, d2 = dx * dx + dy * dy;
  4959. if (d2 > 4 * δ2 && depth--) {
  4960. var a = a0 + a1, b = b0 + b1, c = c0 + c1, m = Math.sqrt(a * a + b * b + c * c), φ2 = Math.asin(c /= m), λ2 = abs(abs(c) - 1) < ε || abs(λ0 - λ1) < ε ? (λ0 + λ1) / 2 : Math.atan2(b, a), p = project(λ2, φ2), x2 = p[0], y2 = p[1], dx2 = x2 - x0, dy2 = y2 - y0, dz = dy * dx2 - dx * dy2;
  4961. if (dz * dz / d2 > δ2 || abs((dx * dx2 + dy * dy2) / d2 - .5) > .3 || a0 * a1 + b0 * b1 + c0 * c1 < cosMinDistance) {
  4962. resampleLineTo(x0, y0, λ0, a0, b0, c0, x2, y2, λ2, a /= m, b /= m, c, depth, stream);
  4963. stream.point(x2, y2);
  4964. resampleLineTo(x2, y2, λ2, a, b, c, x1, y1, λ1, a1, b1, c1, depth, stream);
  4965. }
  4966. }
  4967. }
  4968. resample.precision = function(_) {
  4969. if (!arguments.length) return Math.sqrt(δ2);
  4970. maxDepth = (δ2 = _ * _) > 0 && 16;
  4971. return resample;
  4972. };
  4973. return resample;
  4974. }
  4975. d3.geo.path = function() {
  4976. var pointRadius = 4.5, projection, context, projectStream, contextStream, cacheStream;
  4977. function path(object) {
  4978. if (object) {
  4979. if (typeof pointRadius === "function") contextStream.pointRadius(+pointRadius.apply(this, arguments));
  4980. if (!cacheStream || !cacheStream.valid) cacheStream = projectStream(contextStream);
  4981. d3.geo.stream(object, cacheStream);
  4982. }
  4983. return contextStream.result();
  4984. }
  4985. path.area = function(object) {
  4986. d3_geo_pathAreaSum = 0;
  4987. d3.geo.stream(object, projectStream(d3_geo_pathArea));
  4988. return d3_geo_pathAreaSum;
  4989. };
  4990. path.centroid = function(object) {
  4991. d3_geo_centroidX0 = d3_geo_centroidY0 = d3_geo_centroidZ0 = d3_geo_centroidX1 = d3_geo_centroidY1 = d3_geo_centroidZ1 = d3_geo_centroidX2 = d3_geo_centroidY2 = d3_geo_centroidZ2 = 0;
  4992. d3.geo.stream(object, projectStream(d3_geo_pathCentroid));
  4993. return d3_geo_centroidZ2 ? [ d3_geo_centroidX2 / d3_geo_centroidZ2, d3_geo_centroidY2 / d3_geo_centroidZ2 ] : d3_geo_centroidZ1 ? [ d3_geo_centroidX1 / d3_geo_centroidZ1, d3_geo_centroidY1 / d3_geo_centroidZ1 ] : d3_geo_centroidZ0 ? [ d3_geo_centroidX0 / d3_geo_centroidZ0, d3_geo_centroidY0 / d3_geo_centroidZ0 ] : [ NaN, NaN ];
  4994. };
  4995. path.bounds = function(object) {
  4996. d3_geo_pathBoundsX1 = d3_geo_pathBoundsY1 = -(d3_geo_pathBoundsX0 = d3_geo_pathBoundsY0 = Infinity);
  4997. d3.geo.stream(object, projectStream(d3_geo_pathBounds));
  4998. return [ [ d3_geo_pathBoundsX0, d3_geo_pathBoundsY0 ], [ d3_geo_pathBoundsX1, d3_geo_pathBoundsY1 ] ];
  4999. };
  5000. path.projection = function(_) {
  5001. if (!arguments.length) return projection;
  5002. projectStream = (projection = _) ? _.stream || d3_geo_pathProjectStream(_) : d3_identity;
  5003. return reset();
  5004. };
  5005. path.context = function(_) {
  5006. if (!arguments.length) return context;
  5007. contextStream = (context = _) == null ? new d3_geo_pathBuffer() : new d3_geo_pathContext(_);
  5008. if (typeof pointRadius !== "function") contextStream.pointRadius(pointRadius);
  5009. return reset();
  5010. };
  5011. path.pointRadius = function(_) {
  5012. if (!arguments.length) return pointRadius;
  5013. pointRadius = typeof _ === "function" ? _ : (contextStream.pointRadius(+_), +_);
  5014. return path;
  5015. };
  5016. function reset() {
  5017. cacheStream = null;
  5018. return path;
  5019. }
  5020. return path.projection(d3.geo.albersUsa()).context(null);
  5021. };
  5022. function d3_geo_pathProjectStream(project) {
  5023. var resample = d3_geo_resample(function(x, y) {
  5024. return project([ x * d3_degrees, y * d3_degrees ]);
  5025. });
  5026. return function(stream) {
  5027. return d3_geo_projectionRadians(resample(stream));
  5028. };
  5029. }
  5030. d3.geo.transform = function(methods) {
  5031. return {
  5032. stream: function(stream) {
  5033. var transform = new d3_geo_transform(stream);
  5034. for (var k in methods) transform[k] = methods[k];
  5035. return transform;
  5036. }
  5037. };
  5038. };
  5039. function d3_geo_transform(stream) {
  5040. this.stream = stream;
  5041. }
  5042. d3_geo_transform.prototype = {
  5043. point: function(x, y) {
  5044. this.stream.point(x, y);
  5045. },
  5046. sphere: function() {
  5047. this.stream.sphere();
  5048. },
  5049. lineStart: function() {
  5050. this.stream.lineStart();
  5051. },
  5052. lineEnd: function() {
  5053. this.stream.lineEnd();
  5054. },
  5055. polygonStart: function() {
  5056. this.stream.polygonStart();
  5057. },
  5058. polygonEnd: function() {
  5059. this.stream.polygonEnd();
  5060. }
  5061. };
  5062. function d3_geo_transformPoint(stream, point) {
  5063. return {
  5064. point: point,
  5065. sphere: function() {
  5066. stream.sphere();
  5067. },
  5068. lineStart: function() {
  5069. stream.lineStart();
  5070. },
  5071. lineEnd: function() {
  5072. stream.lineEnd();
  5073. },
  5074. polygonStart: function() {
  5075. stream.polygonStart();
  5076. },
  5077. polygonEnd: function() {
  5078. stream.polygonEnd();
  5079. }
  5080. };
  5081. }
  5082. d3.geo.projection = d3_geo_projection;
  5083. d3.geo.projectionMutator = d3_geo_projectionMutator;
  5084. function d3_geo_projection(project) {
  5085. return d3_geo_projectionMutator(function() {
  5086. return project;
  5087. })();
  5088. }
  5089. function d3_geo_projectionMutator(projectAt) {
  5090. var project, rotate, projectRotate, projectResample = d3_geo_resample(function(x, y) {
  5091. x = project(x, y);
  5092. return [ x[0] * k + δx, δy - x[1] * k ];
  5093. }), k = 150, x = 480, y = 250, λ = 0, φ = 0, δλ = 0, δφ = 0, δγ = 0, δx, δy, preclip = d3_geo_clipAntimeridian, postclip = d3_identity, clipAngle = null, clipExtent = null, stream;
  5094. function projection(point) {
  5095. point = projectRotate(point[0] * d3_radians, point[1] * d3_radians);
  5096. return [ point[0] * k + δx, δy - point[1] * k ];
  5097. }
  5098. function invert(point) {
  5099. point = projectRotate.invert((point[0] - δx) / k, (δy - point[1]) / k);
  5100. return point && [ point[0] * d3_degrees, point[1] * d3_degrees ];
  5101. }
  5102. projection.stream = function(output) {
  5103. if (stream) stream.valid = false;
  5104. stream = d3_geo_projectionRadians(preclip(rotate, projectResample(postclip(output))));
  5105. stream.valid = true;
  5106. return stream;
  5107. };
  5108. projection.clipAngle = function(_) {
  5109. if (!arguments.length) return clipAngle;
  5110. preclip = _ == null ? (clipAngle = _, d3_geo_clipAntimeridian) : d3_geo_clipCircle((clipAngle = +_) * d3_radians);
  5111. return invalidate();
  5112. };
  5113. projection.clipExtent = function(_) {
  5114. if (!arguments.length) return clipExtent;
  5115. clipExtent = _;
  5116. postclip = _ ? d3_geo_clipExtent(_[0][0], _[0][1], _[1][0], _[1][1]) : d3_identity;
  5117. return invalidate();
  5118. };
  5119. projection.scale = function(_) {
  5120. if (!arguments.length) return k;
  5121. k = +_;
  5122. return reset();
  5123. };
  5124. projection.translate = function(_) {
  5125. if (!arguments.length) return [ x, y ];
  5126. x = +_[0];
  5127. y = +_[1];
  5128. return reset();
  5129. };
  5130. projection.center = function(_) {
  5131. if (!arguments.length) return [ λ * d3_degrees, φ * d3_degrees ];
  5132. λ = _[0] % 360 * d3_radians;
  5133. φ = _[1] % 360 * d3_radians;
  5134. return reset();
  5135. };
  5136. projection.rotate = function(_) {
  5137. if (!arguments.length) return [ δλ * d3_degrees, δφ * d3_degrees, δγ * d3_degrees ];
  5138. δλ = _[0] % 360 * d3_radians;
  5139. δφ = _[1] % 360 * d3_radians;
  5140. δγ = _.length > 2 ? _[2] % 360 * d3_radians : 0;
  5141. return reset();
  5142. };
  5143. d3.rebind(projection, projectResample, "precision");
  5144. function reset() {
  5145. projectRotate = d3_geo_compose(rotate = d3_geo_rotation(δλ, δφ, δγ), project);
  5146. var center = project(λ, φ);
  5147. δx = x - center[0] * k;
  5148. δy = y + center[1] * k;
  5149. return invalidate();
  5150. }
  5151. function invalidate() {
  5152. if (stream) stream.valid = false, stream = null;
  5153. return projection;
  5154. }
  5155. return function() {
  5156. project = projectAt.apply(this, arguments);
  5157. projection.invert = project.invert && invert;
  5158. return reset();
  5159. };
  5160. }
  5161. function d3_geo_projectionRadians(stream) {
  5162. return d3_geo_transformPoint(stream, function(x, y) {
  5163. stream.point(x * d3_radians, y * d3_radians);
  5164. });
  5165. }
  5166. function d3_geo_equirectangular(λ, φ) {
  5167. return [ λ, φ ];
  5168. }
  5169. (d3.geo.equirectangular = function() {
  5170. return d3_geo_projection(d3_geo_equirectangular);
  5171. }).raw = d3_geo_equirectangular.invert = d3_geo_equirectangular;
  5172. d3.geo.rotation = function(rotate) {
  5173. rotate = d3_geo_rotation(rotate[0] % 360 * d3_radians, rotate[1] * d3_radians, rotate.length > 2 ? rotate[2] * d3_radians : 0);
  5174. function forward(coordinates) {
  5175. coordinates = rotate(coordinates[0] * d3_radians, coordinates[1] * d3_radians);
  5176. return coordinates[0] *= d3_degrees, coordinates[1] *= d3_degrees, coordinates;
  5177. }
  5178. forward.invert = function(coordinates) {
  5179. coordinates = rotate.invert(coordinates[0] * d3_radians, coordinates[1] * d3_radians);
  5180. return coordinates[0] *= d3_degrees, coordinates[1] *= d3_degrees, coordinates;
  5181. };
  5182. return forward;
  5183. };
  5184. function d3_geo_identityRotation(λ, φ) {
  5185. return [ λ > π ? λ - τ : λ < -π ? λ + τ : λ, φ ];
  5186. }
  5187. d3_geo_identityRotation.invert = d3_geo_equirectangular;
  5188. function d3_geo_rotation(δλ, δφ, δγ) {
  5189. return δλ ? δφ || δγ ? d3_geo_compose(d3_geo_rotationλ(δλ), d3_geo_rotationφγ(δφ, δγ)) : d3_geo_rotationλ(δλ) : δφ || δγ ? d3_geo_rotationφγ(δφ, δγ) : d3_geo_identityRotation;
  5190. }
  5191. function d3_geo_forwardRotationλ(δλ) {
  5192. return function(λ, φ) {
  5193. return λ += δλ, [ λ > π ? λ - τ : λ < -π ? λ + τ : λ, φ ];
  5194. };
  5195. }
  5196. function d3_geo_rotationλ(δλ) {
  5197. var rotation = d3_geo_forwardRotationλ(δλ);
  5198. rotation.invert = d3_geo_forwardRotationλ(-δλ);
  5199. return rotation;
  5200. }
  5201. function d3_geo_rotationφγ(δφ, δγ) {
  5202. var cosδφ = Math.cos(δφ), sinδφ = Math.sin(δφ), cosδγ = Math.cos(δγ), sinδγ = Math.sin(δγ);
  5203. function rotation(λ, φ) {
  5204. var cosφ = Math.cos(φ), x = Math.cos(λ) * cosφ, y = Math.sin(λ) * cosφ, z = Math.sin(φ), k = z * cosδφ + x * sinδφ;
  5205. return [ Math.atan2(y * cosδγ - k * sinδγ, x * cosδφ - z * sinδφ), d3_asin(k * cosδγ + y * sinδγ) ];
  5206. }
  5207. rotation.invert = function(λ, φ) {
  5208. var cosφ = Math.cos(φ), x = Math.cos(λ) * cosφ, y = Math.sin(λ) * cosφ, z = Math.sin(φ), k = z * cosδγ - y * sinδγ;
  5209. return [ Math.atan2(y * cosδγ + z * sinδγ, x * cosδφ + k * sinδφ), d3_asin(k * cosδφ - x * sinδφ) ];
  5210. };
  5211. return rotation;
  5212. }
  5213. d3.geo.circle = function() {
  5214. var origin = [ 0, 0 ], angle, precision = 6, interpolate;
  5215. function circle() {
  5216. var center = typeof origin === "function" ? origin.apply(this, arguments) : origin, rotate = d3_geo_rotation(-center[0] * d3_radians, -center[1] * d3_radians, 0).invert, ring = [];
  5217. interpolate(null, null, 1, {
  5218. point: function(x, y) {
  5219. ring.push(x = rotate(x, y));
  5220. x[0] *= d3_degrees, x[1] *= d3_degrees;
  5221. }
  5222. });
  5223. return {
  5224. type: "Polygon",
  5225. coordinates: [ ring ]
  5226. };
  5227. }
  5228. circle.origin = function(x) {
  5229. if (!arguments.length) return origin;
  5230. origin = x;
  5231. return circle;
  5232. };
  5233. circle.angle = function(x) {
  5234. if (!arguments.length) return angle;
  5235. interpolate = d3_geo_circleInterpolate((angle = +x) * d3_radians, precision * d3_radians);
  5236. return circle;
  5237. };
  5238. circle.precision = function(_) {
  5239. if (!arguments.length) return precision;
  5240. interpolate = d3_geo_circleInterpolate(angle * d3_radians, (precision = +_) * d3_radians);
  5241. return circle;
  5242. };
  5243. return circle.angle(90);
  5244. };
  5245. function d3_geo_circleInterpolate(radius, precision) {
  5246. var cr = Math.cos(radius), sr = Math.sin(radius);
  5247. return function(from, to, direction, listener) {
  5248. var step = direction * precision;
  5249. if (from != null) {
  5250. from = d3_geo_circleAngle(cr, from);
  5251. to = d3_geo_circleAngle(cr, to);
  5252. if (direction > 0 ? from < to : from > to) from += direction * τ;
  5253. } else {
  5254. from = radius + direction * τ;
  5255. to = radius - .5 * step;
  5256. }
  5257. for (var point, t = from; direction > 0 ? t > to : t < to; t -= step) {
  5258. listener.point((point = d3_geo_spherical([ cr, -sr * Math.cos(t), -sr * Math.sin(t) ]))[0], point[1]);
  5259. }
  5260. };
  5261. }
  5262. function d3_geo_circleAngle(cr, point) {
  5263. var a = d3_geo_cartesian(point);
  5264. a[0] -= cr;
  5265. d3_geo_cartesianNormalize(a);
  5266. var angle = d3_acos(-a[1]);
  5267. return ((-a[2] < 0 ? -angle : angle) + 2 * Math.PI - ε) % (2 * Math.PI);
  5268. }
  5269. d3.geo.distance = function(a, b) {
  5270. var Δλ = (b[0] - a[0]) * d3_radians, φ0 = a[1] * d3_radians, φ1 = b[1] * d3_radians, sinΔλ = Math.sin(Δλ), cosΔλ = Math.cos(Δλ), sinφ0 = Math.sin(φ0), cosφ0 = Math.cos(φ0), sinφ1 = Math.sin(φ1), cosφ1 = Math.cos(φ1), t;
  5271. return Math.atan2(Math.sqrt((t = cosφ1 * sinΔλ) * t + (t = cosφ0 * sinφ1 - sinφ0 * cosφ1 * cosΔλ) * t), sinφ0 * sinφ1 + cosφ0 * cosφ1 * cosΔλ);
  5272. };
  5273. d3.geo.graticule = function() {
  5274. var x1, x0, X1, X0, y1, y0, Y1, Y0, dx = 10, dy = dx, DX = 90, DY = 360, x, y, X, Y, precision = 2.5;
  5275. function graticule() {
  5276. return {
  5277. type: "MultiLineString",
  5278. coordinates: lines()
  5279. };
  5280. }
  5281. function lines() {
  5282. return d3.range(Math.ceil(X0 / DX) * DX, X1, DX).map(X).concat(d3.range(Math.ceil(Y0 / DY) * DY, Y1, DY).map(Y)).concat(d3.range(Math.ceil(x0 / dx) * dx, x1, dx).filter(function(x) {
  5283. return abs(x % DX) > ε;
  5284. }).map(x)).concat(d3.range(Math.ceil(y0 / dy) * dy, y1, dy).filter(function(y) {
  5285. return abs(y % DY) > ε;
  5286. }).map(y));
  5287. }
  5288. graticule.lines = function() {
  5289. return lines().map(function(coordinates) {
  5290. return {
  5291. type: "LineString",
  5292. coordinates: coordinates
  5293. };
  5294. });
  5295. };
  5296. graticule.outline = function() {
  5297. return {
  5298. type: "Polygon",
  5299. coordinates: [ X(X0).concat(Y(Y1).slice(1), X(X1).reverse().slice(1), Y(Y0).reverse().slice(1)) ]
  5300. };
  5301. };
  5302. graticule.extent = function(_) {
  5303. if (!arguments.length) return graticule.minorExtent();
  5304. return graticule.majorExtent(_).minorExtent(_);
  5305. };
  5306. graticule.majorExtent = function(_) {
  5307. if (!arguments.length) return [ [ X0, Y0 ], [ X1, Y1 ] ];
  5308. X0 = +_[0][0], X1 = +_[1][0];
  5309. Y0 = +_[0][1], Y1 = +_[1][1];
  5310. if (X0 > X1) _ = X0, X0 = X1, X1 = _;
  5311. if (Y0 > Y1) _ = Y0, Y0 = Y1, Y1 = _;
  5312. return graticule.precision(precision);
  5313. };
  5314. graticule.minorExtent = function(_) {
  5315. if (!arguments.length) return [ [ x0, y0 ], [ x1, y1 ] ];
  5316. x0 = +_[0][0], x1 = +_[1][0];
  5317. y0 = +_[0][1], y1 = +_[1][1];
  5318. if (x0 > x1) _ = x0, x0 = x1, x1 = _;
  5319. if (y0 > y1) _ = y0, y0 = y1, y1 = _;
  5320. return graticule.precision(precision);
  5321. };
  5322. graticule.step = function(_) {
  5323. if (!arguments.length) return graticule.minorStep();
  5324. return graticule.majorStep(_).minorStep(_);
  5325. };
  5326. graticule.majorStep = function(_) {
  5327. if (!arguments.length) return [ DX, DY ];
  5328. DX = +_[0], DY = +_[1];
  5329. return graticule;
  5330. };
  5331. graticule.minorStep = function(_) {
  5332. if (!arguments.length) return [ dx, dy ];
  5333. dx = +_[0], dy = +_[1];
  5334. return graticule;
  5335. };
  5336. graticule.precision = function(_) {
  5337. if (!arguments.length) return precision;
  5338. precision = +_;
  5339. x = d3_geo_graticuleX(y0, y1, 90);
  5340. y = d3_geo_graticuleY(x0, x1, precision);
  5341. X = d3_geo_graticuleX(Y0, Y1, 90);
  5342. Y = d3_geo_graticuleY(X0, X1, precision);
  5343. return graticule;
  5344. };
  5345. return graticule.majorExtent([ [ -180, -90 + ε ], [ 180, 90 - ε ] ]).minorExtent([ [ -180, -80 - ε ], [ 180, 80 + ε ] ]);
  5346. };
  5347. function d3_geo_graticuleX(y0, y1, dy) {
  5348. var y = d3.range(y0, y1 - ε, dy).concat(y1);
  5349. return function(x) {
  5350. return y.map(function(y) {
  5351. return [ x, y ];
  5352. });
  5353. };
  5354. }
  5355. function d3_geo_graticuleY(x0, x1, dx) {
  5356. var x = d3.range(x0, x1 - ε, dx).concat(x1);
  5357. return function(y) {
  5358. return x.map(function(x) {
  5359. return [ x, y ];
  5360. });
  5361. };
  5362. }
  5363. function d3_source(d) {
  5364. return d.source;
  5365. }
  5366. function d3_target(d) {
  5367. return d.target;
  5368. }
  5369. d3.geo.greatArc = function() {
  5370. var source = d3_source, source_, target = d3_target, target_;
  5371. function greatArc() {
  5372. return {
  5373. type: "LineString",
  5374. coordinates: [ source_ || source.apply(this, arguments), target_ || target.apply(this, arguments) ]
  5375. };
  5376. }
  5377. greatArc.distance = function() {
  5378. return d3.geo.distance(source_ || source.apply(this, arguments), target_ || target.apply(this, arguments));
  5379. };
  5380. greatArc.source = function(_) {
  5381. if (!arguments.length) return source;
  5382. source = _, source_ = typeof _ === "function" ? null : _;
  5383. return greatArc;
  5384. };
  5385. greatArc.target = function(_) {
  5386. if (!arguments.length) return target;
  5387. target = _, target_ = typeof _ === "function" ? null : _;
  5388. return greatArc;
  5389. };
  5390. greatArc.precision = function() {
  5391. return arguments.length ? greatArc : 0;
  5392. };
  5393. return greatArc;
  5394. };
  5395. d3.geo.interpolate = function(source, target) {
  5396. return d3_geo_interpolate(source[0] * d3_radians, source[1] * d3_radians, target[0] * d3_radians, target[1] * d3_radians);
  5397. };
  5398. function d3_geo_interpolate(x0, y0, x1, y1) {
  5399. var cy0 = Math.cos(y0), sy0 = Math.sin(y0), cy1 = Math.cos(y1), sy1 = Math.sin(y1), kx0 = cy0 * Math.cos(x0), ky0 = cy0 * Math.sin(x0), kx1 = cy1 * Math.cos(x1), ky1 = cy1 * Math.sin(x1), d = 2 * Math.asin(Math.sqrt(d3_haversin(y1 - y0) + cy0 * cy1 * d3_haversin(x1 - x0))), k = 1 / Math.sin(d);
  5400. var interpolate = d ? function(t) {
  5401. var B = Math.sin(t *= d) * k, A = Math.sin(d - t) * k, x = A * kx0 + B * kx1, y = A * ky0 + B * ky1, z = A * sy0 + B * sy1;
  5402. return [ Math.atan2(y, x) * d3_degrees, Math.atan2(z, Math.sqrt(x * x + y * y)) * d3_degrees ];
  5403. } : function() {
  5404. return [ x0 * d3_degrees, y0 * d3_degrees ];
  5405. };
  5406. interpolate.distance = d;
  5407. return interpolate;
  5408. }
  5409. d3.geo.length = function(object) {
  5410. d3_geo_lengthSum = 0;
  5411. d3.geo.stream(object, d3_geo_length);
  5412. return d3_geo_lengthSum;
  5413. };
  5414. var d3_geo_lengthSum;
  5415. var d3_geo_length = {
  5416. sphere: d3_noop,
  5417. point: d3_noop,
  5418. lineStart: d3_geo_lengthLineStart,
  5419. lineEnd: d3_noop,
  5420. polygonStart: d3_noop,
  5421. polygonEnd: d3_noop
  5422. };
  5423. function d3_geo_lengthLineStart() {
  5424. var λ0, sinφ0, cosφ0;
  5425. d3_geo_length.point = function(λ, φ) {
  5426. λ0 = λ * d3_radians, sinφ0 = Math.sin(φ *= d3_radians), cosφ0 = Math.cos(φ);
  5427. d3_geo_length.point = nextPoint;
  5428. };
  5429. d3_geo_length.lineEnd = function() {
  5430. d3_geo_length.point = d3_geo_length.lineEnd = d3_noop;
  5431. };
  5432. function nextPoint(λ, φ) {
  5433. var sinφ = Math.sin(φ *= d3_radians), cosφ = Math.cos(φ), t = abs((λ *= d3_radians) - λ0), cosΔλ = Math.cos(t);
  5434. d3_geo_lengthSum += Math.atan2(Math.sqrt((t = cosφ * Math.sin(t)) * t + (t = cosφ0 * sinφ - sinφ0 * cosφ * cosΔλ) * t), sinφ0 * sinφ + cosφ0 * cosφ * cosΔλ);
  5435. λ0 = λ, sinφ0 = sinφ, cosφ0 = cosφ;
  5436. }
  5437. }
  5438. function d3_geo_azimuthal(scale, angle) {
  5439. function azimuthal(λ, φ) {
  5440. var cosλ = Math.cos(λ), cosφ = Math.cos(φ), k = scale(cosλ * cosφ);
  5441. return [ k * cosφ * Math.sin(λ), k * Math.sin(φ) ];
  5442. }
  5443. azimuthal.invert = function(x, y) {
  5444. var ρ = Math.sqrt(x * x + y * y), c = angle(ρ), sinc = Math.sin(c), cosc = Math.cos(c);
  5445. return [ Math.atan2(x * sinc, ρ * cosc), Math.asin(ρ && y * sinc / ρ) ];
  5446. };
  5447. return azimuthal;
  5448. }
  5449. var d3_geo_azimuthalEqualArea = d3_geo_azimuthal(function(cosλcosφ) {
  5450. return Math.sqrt(2 / (1 + cosλcosφ));
  5451. }, function(ρ) {
  5452. return 2 * Math.asin(ρ / 2);
  5453. });
  5454. (d3.geo.azimuthalEqualArea = function() {
  5455. return d3_geo_projection(d3_geo_azimuthalEqualArea);
  5456. }).raw = d3_geo_azimuthalEqualArea;
  5457. var d3_geo_azimuthalEquidistant = d3_geo_azimuthal(function(cosλcosφ) {
  5458. var c = Math.acos(cosλcosφ);
  5459. return c && c / Math.sin(c);
  5460. }, d3_identity);
  5461. (d3.geo.azimuthalEquidistant = function() {
  5462. return d3_geo_projection(d3_geo_azimuthalEquidistant);
  5463. }).raw = d3_geo_azimuthalEquidistant;
  5464. function d3_geo_conicConformal(φ0, φ1) {
  5465. var cosφ0 = Math.cos(φ0), t = function(φ) {
  5466. return Math.tan(π / 4 + φ / 2);
  5467. }, n = φ0 === φ1 ? Math.sin(φ0) : Math.log(cosφ0 / Math.cos(φ1)) / Math.log(t(φ1) / t(φ0)), F = cosφ0 * Math.pow(t(φ0), n) / n;
  5468. if (!n) return d3_geo_mercator;
  5469. function forward(λ, φ) {
  5470. if (F > 0) {
  5471. if (φ < -halfπ + ε) φ = -halfπ + ε;
  5472. } else {
  5473. if (φ > halfπ - ε) φ = halfπ - ε;
  5474. }
  5475. var ρ = F / Math.pow(t(φ), n);
  5476. return [ ρ * Math.sin(n * λ), F - ρ * Math.cos(n * λ) ];
  5477. }
  5478. forward.invert = function(x, y) {
  5479. var ρ0_y = F - y, ρ = d3_sgn(n) * Math.sqrt(x * x + ρ0_y * ρ0_y);
  5480. return [ Math.atan2(x, ρ0_y) / n, 2 * Math.atan(Math.pow(F / ρ, 1 / n)) - halfπ ];
  5481. };
  5482. return forward;
  5483. }
  5484. (d3.geo.conicConformal = function() {
  5485. return d3_geo_conic(d3_geo_conicConformal);
  5486. }).raw = d3_geo_conicConformal;
  5487. function d3_geo_conicEquidistant(φ0, φ1) {
  5488. var cosφ0 = Math.cos(φ0), n = φ0 === φ1 ? Math.sin(φ0) : (cosφ0 - Math.cos(φ1)) / (φ1 - φ0), G = cosφ0 / n + φ0;
  5489. if (abs(n) < ε) return d3_geo_equirectangular;
  5490. function forward(λ, φ) {
  5491. var ρ = G - φ;
  5492. return [ ρ * Math.sin(n * λ), G - ρ * Math.cos(n * λ) ];
  5493. }
  5494. forward.invert = function(x, y) {
  5495. var ρ0_y = G - y;
  5496. return [ Math.atan2(x, ρ0_y) / n, G - d3_sgn(n) * Math.sqrt(x * x + ρ0_y * ρ0_y) ];
  5497. };
  5498. return forward;
  5499. }
  5500. (d3.geo.conicEquidistant = function() {
  5501. return d3_geo_conic(d3_geo_conicEquidistant);
  5502. }).raw = d3_geo_conicEquidistant;
  5503. var d3_geo_gnomonic = d3_geo_azimuthal(function(cosλcosφ) {
  5504. return 1 / cosλcosφ;
  5505. }, Math.atan);
  5506. (d3.geo.gnomonic = function() {
  5507. return d3_geo_projection(d3_geo_gnomonic);
  5508. }).raw = d3_geo_gnomonic;
  5509. function d3_geo_mercator(λ, φ) {
  5510. return [ λ, Math.log(Math.tan(π / 4 + φ / 2)) ];
  5511. }
  5512. d3_geo_mercator.invert = function(x, y) {
  5513. return [ x, 2 * Math.atan(Math.exp(y)) - halfπ ];
  5514. };
  5515. function d3_geo_mercatorProjection(project) {
  5516. var m = d3_geo_projection(project), scale = m.scale, translate = m.translate, clipExtent = m.clipExtent, clipAuto;
  5517. m.scale = function() {
  5518. var v = scale.apply(m, arguments);
  5519. return v === m ? clipAuto ? m.clipExtent(null) : m : v;
  5520. };
  5521. m.translate = function() {
  5522. var v = translate.apply(m, arguments);
  5523. return v === m ? clipAuto ? m.clipExtent(null) : m : v;
  5524. };
  5525. m.clipExtent = function(_) {
  5526. var v = clipExtent.apply(m, arguments);
  5527. if (v === m) {
  5528. if (clipAuto = _ == null) {
  5529. var k = π * scale(), t = translate();
  5530. clipExtent([ [ t[0] - k, t[1] - k ], [ t[0] + k, t[1] + k ] ]);
  5531. }
  5532. } else if (clipAuto) {
  5533. v = null;
  5534. }
  5535. return v;
  5536. };
  5537. return m.clipExtent(null);
  5538. }
  5539. (d3.geo.mercator = function() {
  5540. return d3_geo_mercatorProjection(d3_geo_mercator);
  5541. }).raw = d3_geo_mercator;
  5542. var d3_geo_orthographic = d3_geo_azimuthal(function() {
  5543. return 1;
  5544. }, Math.asin);
  5545. (d3.geo.orthographic = function() {
  5546. return d3_geo_projection(d3_geo_orthographic);
  5547. }).raw = d3_geo_orthographic;
  5548. var d3_geo_stereographic = d3_geo_azimuthal(function(cosλcosφ) {
  5549. return 1 / (1 + cosλcosφ);
  5550. }, function(ρ) {
  5551. return 2 * Math.atan(ρ);
  5552. });
  5553. (d3.geo.stereographic = function() {
  5554. return d3_geo_projection(d3_geo_stereographic);
  5555. }).raw = d3_geo_stereographic;
  5556. function d3_geo_transverseMercator(λ, φ) {
  5557. return [ Math.log(Math.tan(π / 4 + φ / 2)), -λ ];
  5558. }
  5559. d3_geo_transverseMercator.invert = function(x, y) {
  5560. return [ -y, 2 * Math.atan(Math.exp(x)) - halfπ ];
  5561. };
  5562. (d3.geo.transverseMercator = function() {
  5563. var projection = d3_geo_mercatorProjection(d3_geo_transverseMercator), center = projection.center, rotate = projection.rotate;
  5564. projection.center = function(_) {
  5565. return _ ? center([ -_[1], _[0] ]) : (_ = center(), [ _[1], -_[0] ]);
  5566. };
  5567. projection.rotate = function(_) {
  5568. return _ ? rotate([ _[0], _[1], _.length > 2 ? _[2] + 90 : 90 ]) : (_ = rotate(),
  5569. [ _[0], _[1], _[2] - 90 ]);
  5570. };
  5571. return rotate([ 0, 0, 90 ]);
  5572. }).raw = d3_geo_transverseMercator;
  5573. d3.geom = {};
  5574. function d3_geom_pointX(d) {
  5575. return d[0];
  5576. }
  5577. function d3_geom_pointY(d) {
  5578. return d[1];
  5579. }
  5580. d3.geom.hull = function(vertices) {
  5581. var x = d3_geom_pointX, y = d3_geom_pointY;
  5582. if (arguments.length) return hull(vertices);
  5583. function hull(data) {
  5584. if (data.length < 3) return [];
  5585. var fx = d3_functor(x), fy = d3_functor(y), i, n = data.length, points = [], flippedPoints = [];
  5586. for (i = 0; i < n; i++) {
  5587. points.push([ +fx.call(this, data[i], i), +fy.call(this, data[i], i), i ]);
  5588. }
  5589. points.sort(d3_geom_hullOrder);
  5590. for (i = 0; i < n; i++) flippedPoints.push([ points[i][0], -points[i][1] ]);
  5591. var upper = d3_geom_hullUpper(points), lower = d3_geom_hullUpper(flippedPoints);
  5592. var skipLeft = lower[0] === upper[0], skipRight = lower[lower.length - 1] === upper[upper.length - 1], polygon = [];
  5593. for (i = upper.length - 1; i >= 0; --i) polygon.push(data[points[upper[i]][2]]);
  5594. for (i = +skipLeft; i < lower.length - skipRight; ++i) polygon.push(data[points[lower[i]][2]]);
  5595. return polygon;
  5596. }
  5597. hull.x = function(_) {
  5598. return arguments.length ? (x = _, hull) : x;
  5599. };
  5600. hull.y = function(_) {
  5601. return arguments.length ? (y = _, hull) : y;
  5602. };
  5603. return hull;
  5604. };
  5605. function d3_geom_hullUpper(points) {
  5606. var n = points.length, hull = [ 0, 1 ], hs = 2;
  5607. for (var i = 2; i < n; i++) {
  5608. while (hs > 1 && d3_cross2d(points[hull[hs - 2]], points[hull[hs - 1]], points[i]) <= 0) --hs;
  5609. hull[hs++] = i;
  5610. }
  5611. return hull.slice(0, hs);
  5612. }
  5613. function d3_geom_hullOrder(a, b) {
  5614. return a[0] - b[0] || a[1] - b[1];
  5615. }
  5616. d3.geom.polygon = function(coordinates) {
  5617. d3_subclass(coordinates, d3_geom_polygonPrototype);
  5618. return coordinates;
  5619. };
  5620. var d3_geom_polygonPrototype = d3.geom.polygon.prototype = [];
  5621. d3_geom_polygonPrototype.area = function() {
  5622. var i = -1, n = this.length, a, b = this[n - 1], area = 0;
  5623. while (++i < n) {
  5624. a = b;
  5625. b = this[i];
  5626. area += a[1] * b[0] - a[0] * b[1];
  5627. }
  5628. return area * .5;
  5629. };
  5630. d3_geom_polygonPrototype.centroid = function(k) {
  5631. var i = -1, n = this.length, x = 0, y = 0, a, b = this[n - 1], c;
  5632. if (!arguments.length) k = -1 / (6 * this.area());
  5633. while (++i < n) {
  5634. a = b;
  5635. b = this[i];
  5636. c = a[0] * b[1] - b[0] * a[1];
  5637. x += (a[0] + b[0]) * c;
  5638. y += (a[1] + b[1]) * c;
  5639. }
  5640. return [ x * k, y * k ];
  5641. };
  5642. d3_geom_polygonPrototype.clip = function(subject) {
  5643. var input, closed = d3_geom_polygonClosed(subject), i = -1, n = this.length - d3_geom_polygonClosed(this), j, m, a = this[n - 1], b, c, d;
  5644. while (++i < n) {
  5645. input = subject.slice();
  5646. subject.length = 0;
  5647. b = this[i];
  5648. c = input[(m = input.length - closed) - 1];
  5649. j = -1;
  5650. while (++j < m) {
  5651. d = input[j];
  5652. if (d3_geom_polygonInside(d, a, b)) {
  5653. if (!d3_geom_polygonInside(c, a, b)) {
  5654. subject.push(d3_geom_polygonIntersect(c, d, a, b));
  5655. }
  5656. subject.push(d);
  5657. } else if (d3_geom_polygonInside(c, a, b)) {
  5658. subject.push(d3_geom_polygonIntersect(c, d, a, b));
  5659. }
  5660. c = d;
  5661. }
  5662. if (closed) subject.push(subject[0]);
  5663. a = b;
  5664. }
  5665. return subject;
  5666. };
  5667. function d3_geom_polygonInside(p, a, b) {
  5668. return (b[0] - a[0]) * (p[1] - a[1]) < (b[1] - a[1]) * (p[0] - a[0]);
  5669. }
  5670. function d3_geom_polygonIntersect(c, d, a, b) {
  5671. var x1 = c[0], x3 = a[0], x21 = d[0] - x1, x43 = b[0] - x3, y1 = c[1], y3 = a[1], y21 = d[1] - y1, y43 = b[1] - y3, ua = (x43 * (y1 - y3) - y43 * (x1 - x3)) / (y43 * x21 - x43 * y21);
  5672. return [ x1 + ua * x21, y1 + ua * y21 ];
  5673. }
  5674. function d3_geom_polygonClosed(coordinates) {
  5675. var a = coordinates[0], b = coordinates[coordinates.length - 1];
  5676. return !(a[0] - b[0] || a[1] - b[1]);
  5677. }
  5678. var d3_geom_voronoiEdges, d3_geom_voronoiCells, d3_geom_voronoiBeaches, d3_geom_voronoiBeachPool = [], d3_geom_voronoiFirstCircle, d3_geom_voronoiCircles, d3_geom_voronoiCirclePool = [];
  5679. function d3_geom_voronoiBeach() {
  5680. d3_geom_voronoiRedBlackNode(this);
  5681. this.edge = this.site = this.circle = null;
  5682. }
  5683. function d3_geom_voronoiCreateBeach(site) {
  5684. var beach = d3_geom_voronoiBeachPool.pop() || new d3_geom_voronoiBeach();
  5685. beach.site = site;
  5686. return beach;
  5687. }
  5688. function d3_geom_voronoiDetachBeach(beach) {
  5689. d3_geom_voronoiDetachCircle(beach);
  5690. d3_geom_voronoiBeaches.remove(beach);
  5691. d3_geom_voronoiBeachPool.push(beach);
  5692. d3_geom_voronoiRedBlackNode(beach);
  5693. }
  5694. function d3_geom_voronoiRemoveBeach(beach) {
  5695. var circle = beach.circle, x = circle.x, y = circle.cy, vertex = {
  5696. x: x,
  5697. y: y
  5698. }, previous = beach.P, next = beach.N, disappearing = [ beach ];
  5699. d3_geom_voronoiDetachBeach(beach);
  5700. var lArc = previous;
  5701. while (lArc.circle && abs(x - lArc.circle.x) < ε && abs(y - lArc.circle.cy) < ε) {
  5702. previous = lArc.P;
  5703. disappearing.unshift(lArc);
  5704. d3_geom_voronoiDetachBeach(lArc);
  5705. lArc = previous;
  5706. }
  5707. disappearing.unshift(lArc);
  5708. d3_geom_voronoiDetachCircle(lArc);
  5709. var rArc = next;
  5710. while (rArc.circle && abs(x - rArc.circle.x) < ε && abs(y - rArc.circle.cy) < ε) {
  5711. next = rArc.N;
  5712. disappearing.push(rArc);
  5713. d3_geom_voronoiDetachBeach(rArc);
  5714. rArc = next;
  5715. }
  5716. disappearing.push(rArc);
  5717. d3_geom_voronoiDetachCircle(rArc);
  5718. var nArcs = disappearing.length, iArc;
  5719. for (iArc = 1; iArc < nArcs; ++iArc) {
  5720. rArc = disappearing[iArc];
  5721. lArc = disappearing[iArc - 1];
  5722. d3_geom_voronoiSetEdgeEnd(rArc.edge, lArc.site, rArc.site, vertex);
  5723. }
  5724. lArc = disappearing[0];
  5725. rArc = disappearing[nArcs - 1];
  5726. rArc.edge = d3_geom_voronoiCreateEdge(lArc.site, rArc.site, null, vertex);
  5727. d3_geom_voronoiAttachCircle(lArc);
  5728. d3_geom_voronoiAttachCircle(rArc);
  5729. }
  5730. function d3_geom_voronoiAddBeach(site) {
  5731. var x = site.x, directrix = site.y, lArc, rArc, dxl, dxr, node = d3_geom_voronoiBeaches._;
  5732. while (node) {
  5733. dxl = d3_geom_voronoiLeftBreakPoint(node, directrix) - x;
  5734. if (dxl > ε) node = node.L; else {
  5735. dxr = x - d3_geom_voronoiRightBreakPoint(node, directrix);
  5736. if (dxr > ε) {
  5737. if (!node.R) {
  5738. lArc = node;
  5739. break;
  5740. }
  5741. node = node.R;
  5742. } else {
  5743. if (dxl > -ε) {
  5744. lArc = node.P;
  5745. rArc = node;
  5746. } else if (dxr > -ε) {
  5747. lArc = node;
  5748. rArc = node.N;
  5749. } else {
  5750. lArc = rArc = node;
  5751. }
  5752. break;
  5753. }
  5754. }
  5755. }
  5756. var newArc = d3_geom_voronoiCreateBeach(site);
  5757. d3_geom_voronoiBeaches.insert(lArc, newArc);
  5758. if (!lArc && !rArc) return;
  5759. if (lArc === rArc) {
  5760. d3_geom_voronoiDetachCircle(lArc);
  5761. rArc = d3_geom_voronoiCreateBeach(lArc.site);
  5762. d3_geom_voronoiBeaches.insert(newArc, rArc);
  5763. newArc.edge = rArc.edge = d3_geom_voronoiCreateEdge(lArc.site, newArc.site);
  5764. d3_geom_voronoiAttachCircle(lArc);
  5765. d3_geom_voronoiAttachCircle(rArc);
  5766. return;
  5767. }
  5768. if (!rArc) {
  5769. newArc.edge = d3_geom_voronoiCreateEdge(lArc.site, newArc.site);
  5770. return;
  5771. }
  5772. d3_geom_voronoiDetachCircle(lArc);
  5773. d3_geom_voronoiDetachCircle(rArc);
  5774. var lSite = lArc.site, ax = lSite.x, ay = lSite.y, bx = site.x - ax, by = site.y - ay, rSite = rArc.site, cx = rSite.x - ax, cy = rSite.y - ay, d = 2 * (bx * cy - by * cx), hb = bx * bx + by * by, hc = cx * cx + cy * cy, vertex = {
  5775. x: (cy * hb - by * hc) / d + ax,
  5776. y: (bx * hc - cx * hb) / d + ay
  5777. };
  5778. d3_geom_voronoiSetEdgeEnd(rArc.edge, lSite, rSite, vertex);
  5779. newArc.edge = d3_geom_voronoiCreateEdge(lSite, site, null, vertex);
  5780. rArc.edge = d3_geom_voronoiCreateEdge(site, rSite, null, vertex);
  5781. d3_geom_voronoiAttachCircle(lArc);
  5782. d3_geom_voronoiAttachCircle(rArc);
  5783. }
  5784. function d3_geom_voronoiLeftBreakPoint(arc, directrix) {
  5785. var site = arc.site, rfocx = site.x, rfocy = site.y, pby2 = rfocy - directrix;
  5786. if (!pby2) return rfocx;
  5787. var lArc = arc.P;
  5788. if (!lArc) return -Infinity;
  5789. site = lArc.site;
  5790. var lfocx = site.x, lfocy = site.y, plby2 = lfocy - directrix;
  5791. if (!plby2) return lfocx;
  5792. var hl = lfocx - rfocx, aby2 = 1 / pby2 - 1 / plby2, b = hl / plby2;
  5793. if (aby2) return (-b + Math.sqrt(b * b - 2 * aby2 * (hl * hl / (-2 * plby2) - lfocy + plby2 / 2 + rfocy - pby2 / 2))) / aby2 + rfocx;
  5794. return (rfocx + lfocx) / 2;
  5795. }
  5796. function d3_geom_voronoiRightBreakPoint(arc, directrix) {
  5797. var rArc = arc.N;
  5798. if (rArc) return d3_geom_voronoiLeftBreakPoint(rArc, directrix);
  5799. var site = arc.site;
  5800. return site.y === directrix ? site.x : Infinity;
  5801. }
  5802. function d3_geom_voronoiCell(site) {
  5803. this.site = site;
  5804. this.edges = [];
  5805. }
  5806. d3_geom_voronoiCell.prototype.prepare = function() {
  5807. var halfEdges = this.edges, iHalfEdge = halfEdges.length, edge;
  5808. while (iHalfEdge--) {
  5809. edge = halfEdges[iHalfEdge].edge;
  5810. if (!edge.b || !edge.a) halfEdges.splice(iHalfEdge, 1);
  5811. }
  5812. halfEdges.sort(d3_geom_voronoiHalfEdgeOrder);
  5813. return halfEdges.length;
  5814. };
  5815. function d3_geom_voronoiCloseCells(extent) {
  5816. var x0 = extent[0][0], x1 = extent[1][0], y0 = extent[0][1], y1 = extent[1][1], x2, y2, x3, y3, cells = d3_geom_voronoiCells, iCell = cells.length, cell, iHalfEdge, halfEdges, nHalfEdges, start, end;
  5817. while (iCell--) {
  5818. cell = cells[iCell];
  5819. if (!cell || !cell.prepare()) continue;
  5820. halfEdges = cell.edges;
  5821. nHalfEdges = halfEdges.length;
  5822. iHalfEdge = 0;
  5823. while (iHalfEdge < nHalfEdges) {
  5824. end = halfEdges[iHalfEdge].end(), x3 = end.x, y3 = end.y;
  5825. start = halfEdges[++iHalfEdge % nHalfEdges].start(), x2 = start.x, y2 = start.y;
  5826. if (abs(x3 - x2) > ε || abs(y3 - y2) > ε) {
  5827. halfEdges.splice(iHalfEdge, 0, new d3_geom_voronoiHalfEdge(d3_geom_voronoiCreateBorderEdge(cell.site, end, abs(x3 - x0) < ε && y1 - y3 > ε ? {
  5828. x: x0,
  5829. y: abs(x2 - x0) < ε ? y2 : y1
  5830. } : abs(y3 - y1) < ε && x1 - x3 > ε ? {
  5831. x: abs(y2 - y1) < ε ? x2 : x1,
  5832. y: y1
  5833. } : abs(x3 - x1) < ε && y3 - y0 > ε ? {
  5834. x: x1,
  5835. y: abs(x2 - x1) < ε ? y2 : y0
  5836. } : abs(y3 - y0) < ε && x3 - x0 > ε ? {
  5837. x: abs(y2 - y0) < ε ? x2 : x0,
  5838. y: y0
  5839. } : null), cell.site, null));
  5840. ++nHalfEdges;
  5841. }
  5842. }
  5843. }
  5844. }
  5845. function d3_geom_voronoiHalfEdgeOrder(a, b) {
  5846. return b.angle - a.angle;
  5847. }
  5848. function d3_geom_voronoiCircle() {
  5849. d3_geom_voronoiRedBlackNode(this);
  5850. this.x = this.y = this.arc = this.site = this.cy = null;
  5851. }
  5852. function d3_geom_voronoiAttachCircle(arc) {
  5853. var lArc = arc.P, rArc = arc.N;
  5854. if (!lArc || !rArc) return;
  5855. var lSite = lArc.site, cSite = arc.site, rSite = rArc.site;
  5856. if (lSite === rSite) return;
  5857. var bx = cSite.x, by = cSite.y, ax = lSite.x - bx, ay = lSite.y - by, cx = rSite.x - bx, cy = rSite.y - by;
  5858. var d = 2 * (ax * cy - ay * cx);
  5859. if (d >= -ε2) return;
  5860. var ha = ax * ax + ay * ay, hc = cx * cx + cy * cy, x = (cy * ha - ay * hc) / d, y = (ax * hc - cx * ha) / d, cy = y + by;
  5861. var circle = d3_geom_voronoiCirclePool.pop() || new d3_geom_voronoiCircle();
  5862. circle.arc = arc;
  5863. circle.site = cSite;
  5864. circle.x = x + bx;
  5865. circle.y = cy + Math.sqrt(x * x + y * y);
  5866. circle.cy = cy;
  5867. arc.circle = circle;
  5868. var before = null, node = d3_geom_voronoiCircles._;
  5869. while (node) {
  5870. if (circle.y < node.y || circle.y === node.y && circle.x <= node.x) {
  5871. if (node.L) node = node.L; else {
  5872. before = node.P;
  5873. break;
  5874. }
  5875. } else {
  5876. if (node.R) node = node.R; else {
  5877. before = node;
  5878. break;
  5879. }
  5880. }
  5881. }
  5882. d3_geom_voronoiCircles.insert(before, circle);
  5883. if (!before) d3_geom_voronoiFirstCircle = circle;
  5884. }
  5885. function d3_geom_voronoiDetachCircle(arc) {
  5886. var circle = arc.circle;
  5887. if (circle) {
  5888. if (!circle.P) d3_geom_voronoiFirstCircle = circle.N;
  5889. d3_geom_voronoiCircles.remove(circle);
  5890. d3_geom_voronoiCirclePool.push(circle);
  5891. d3_geom_voronoiRedBlackNode(circle);
  5892. arc.circle = null;
  5893. }
  5894. }
  5895. function d3_geom_voronoiClipEdges(extent) {
  5896. var edges = d3_geom_voronoiEdges, clip = d3_geom_clipLine(extent[0][0], extent[0][1], extent[1][0], extent[1][1]), i = edges.length, e;
  5897. while (i--) {
  5898. e = edges[i];
  5899. if (!d3_geom_voronoiConnectEdge(e, extent) || !clip(e) || abs(e.a.x - e.b.x) < ε && abs(e.a.y - e.b.y) < ε) {
  5900. e.a = e.b = null;
  5901. edges.splice(i, 1);
  5902. }
  5903. }
  5904. }
  5905. function d3_geom_voronoiConnectEdge(edge, extent) {
  5906. var vb = edge.b;
  5907. if (vb) return true;
  5908. var va = edge.a, x0 = extent[0][0], x1 = extent[1][0], y0 = extent[0][1], y1 = extent[1][1], lSite = edge.l, rSite = edge.r, lx = lSite.x, ly = lSite.y, rx = rSite.x, ry = rSite.y, fx = (lx + rx) / 2, fy = (ly + ry) / 2, fm, fb;
  5909. if (ry === ly) {
  5910. if (fx < x0 || fx >= x1) return;
  5911. if (lx > rx) {
  5912. if (!va) va = {
  5913. x: fx,
  5914. y: y0
  5915. }; else if (va.y >= y1) return;
  5916. vb = {
  5917. x: fx,
  5918. y: y1
  5919. };
  5920. } else {
  5921. if (!va) va = {
  5922. x: fx,
  5923. y: y1
  5924. }; else if (va.y < y0) return;
  5925. vb = {
  5926. x: fx,
  5927. y: y0
  5928. };
  5929. }
  5930. } else {
  5931. fm = (lx - rx) / (ry - ly);
  5932. fb = fy - fm * fx;
  5933. if (fm < -1 || fm > 1) {
  5934. if (lx > rx) {
  5935. if (!va) va = {
  5936. x: (y0 - fb) / fm,
  5937. y: y0
  5938. }; else if (va.y >= y1) return;
  5939. vb = {
  5940. x: (y1 - fb) / fm,
  5941. y: y1
  5942. };
  5943. } else {
  5944. if (!va) va = {
  5945. x: (y1 - fb) / fm,
  5946. y: y1
  5947. }; else if (va.y < y0) return;
  5948. vb = {
  5949. x: (y0 - fb) / fm,
  5950. y: y0
  5951. };
  5952. }
  5953. } else {
  5954. if (ly < ry) {
  5955. if (!va) va = {
  5956. x: x0,
  5957. y: fm * x0 + fb
  5958. }; else if (va.x >= x1) return;
  5959. vb = {
  5960. x: x1,
  5961. y: fm * x1 + fb
  5962. };
  5963. } else {
  5964. if (!va) va = {
  5965. x: x1,
  5966. y: fm * x1 + fb
  5967. }; else if (va.x < x0) return;
  5968. vb = {
  5969. x: x0,
  5970. y: fm * x0 + fb
  5971. };
  5972. }
  5973. }
  5974. }
  5975. edge.a = va;
  5976. edge.b = vb;
  5977. return true;
  5978. }
  5979. function d3_geom_voronoiEdge(lSite, rSite) {
  5980. this.l = lSite;
  5981. this.r = rSite;
  5982. this.a = this.b = null;
  5983. }
  5984. function d3_geom_voronoiCreateEdge(lSite, rSite, va, vb) {
  5985. var edge = new d3_geom_voronoiEdge(lSite, rSite);
  5986. d3_geom_voronoiEdges.push(edge);
  5987. if (va) d3_geom_voronoiSetEdgeEnd(edge, lSite, rSite, va);
  5988. if (vb) d3_geom_voronoiSetEdgeEnd(edge, rSite, lSite, vb);
  5989. d3_geom_voronoiCells[lSite.i].edges.push(new d3_geom_voronoiHalfEdge(edge, lSite, rSite));
  5990. d3_geom_voronoiCells[rSite.i].edges.push(new d3_geom_voronoiHalfEdge(edge, rSite, lSite));
  5991. return edge;
  5992. }
  5993. function d3_geom_voronoiCreateBorderEdge(lSite, va, vb) {
  5994. var edge = new d3_geom_voronoiEdge(lSite, null);
  5995. edge.a = va;
  5996. edge.b = vb;
  5997. d3_geom_voronoiEdges.push(edge);
  5998. return edge;
  5999. }
  6000. function d3_geom_voronoiSetEdgeEnd(edge, lSite, rSite, vertex) {
  6001. if (!edge.a && !edge.b) {
  6002. edge.a = vertex;
  6003. edge.l = lSite;
  6004. edge.r = rSite;
  6005. } else if (edge.l === rSite) {
  6006. edge.b = vertex;
  6007. } else {
  6008. edge.a = vertex;
  6009. }
  6010. }
  6011. function d3_geom_voronoiHalfEdge(edge, lSite, rSite) {
  6012. var va = edge.a, vb = edge.b;
  6013. this.edge = edge;
  6014. this.site = lSite;
  6015. this.angle = rSite ? Math.atan2(rSite.y - lSite.y, rSite.x - lSite.x) : edge.l === lSite ? Math.atan2(vb.x - va.x, va.y - vb.y) : Math.atan2(va.x - vb.x, vb.y - va.y);
  6016. }
  6017. d3_geom_voronoiHalfEdge.prototype = {
  6018. start: function() {
  6019. return this.edge.l === this.site ? this.edge.a : this.edge.b;
  6020. },
  6021. end: function() {
  6022. return this.edge.l === this.site ? this.edge.b : this.edge.a;
  6023. }
  6024. };
  6025. function d3_geom_voronoiRedBlackTree() {
  6026. this._ = null;
  6027. }
  6028. function d3_geom_voronoiRedBlackNode(node) {
  6029. node.U = node.C = node.L = node.R = node.P = node.N = null;
  6030. }
  6031. d3_geom_voronoiRedBlackTree.prototype = {
  6032. insert: function(after, node) {
  6033. var parent, grandpa, uncle;
  6034. if (after) {
  6035. node.P = after;
  6036. node.N = after.N;
  6037. if (after.N) after.N.P = node;
  6038. after.N = node;
  6039. if (after.R) {
  6040. after = after.R;
  6041. while (after.L) after = after.L;
  6042. after.L = node;
  6043. } else {
  6044. after.R = node;
  6045. }
  6046. parent = after;
  6047. } else if (this._) {
  6048. after = d3_geom_voronoiRedBlackFirst(this._);
  6049. node.P = null;
  6050. node.N = after;
  6051. after.P = after.L = node;
  6052. parent = after;
  6053. } else {
  6054. node.P = node.N = null;
  6055. this._ = node;
  6056. parent = null;
  6057. }
  6058. node.L = node.R = null;
  6059. node.U = parent;
  6060. node.C = true;
  6061. after = node;
  6062. while (parent && parent.C) {
  6063. grandpa = parent.U;
  6064. if (parent === grandpa.L) {
  6065. uncle = grandpa.R;
  6066. if (uncle && uncle.C) {
  6067. parent.C = uncle.C = false;
  6068. grandpa.C = true;
  6069. after = grandpa;
  6070. } else {
  6071. if (after === parent.R) {
  6072. d3_geom_voronoiRedBlackRotateLeft(this, parent);
  6073. after = parent;
  6074. parent = after.U;
  6075. }
  6076. parent.C = false;
  6077. grandpa.C = true;
  6078. d3_geom_voronoiRedBlackRotateRight(this, grandpa);
  6079. }
  6080. } else {
  6081. uncle = grandpa.L;
  6082. if (uncle && uncle.C) {
  6083. parent.C = uncle.C = false;
  6084. grandpa.C = true;
  6085. after = grandpa;
  6086. } else {
  6087. if (after === parent.L) {
  6088. d3_geom_voronoiRedBlackRotateRight(this, parent);
  6089. after = parent;
  6090. parent = after.U;
  6091. }
  6092. parent.C = false;
  6093. grandpa.C = true;
  6094. d3_geom_voronoiRedBlackRotateLeft(this, grandpa);
  6095. }
  6096. }
  6097. parent = after.U;
  6098. }
  6099. this._.C = false;
  6100. },
  6101. remove: function(node) {
  6102. if (node.N) node.N.P = node.P;
  6103. if (node.P) node.P.N = node.N;
  6104. node.N = node.P = null;
  6105. var parent = node.U, sibling, left = node.L, right = node.R, next, red;
  6106. if (!left) next = right; else if (!right) next = left; else next = d3_geom_voronoiRedBlackFirst(right);
  6107. if (parent) {
  6108. if (parent.L === node) parent.L = next; else parent.R = next;
  6109. } else {
  6110. this._ = next;
  6111. }
  6112. if (left && right) {
  6113. red = next.C;
  6114. next.C = node.C;
  6115. next.L = left;
  6116. left.U = next;
  6117. if (next !== right) {
  6118. parent = next.U;
  6119. next.U = node.U;
  6120. node = next.R;
  6121. parent.L = node;
  6122. next.R = right;
  6123. right.U = next;
  6124. } else {
  6125. next.U = parent;
  6126. parent = next;
  6127. node = next.R;
  6128. }
  6129. } else {
  6130. red = node.C;
  6131. node = next;
  6132. }
  6133. if (node) node.U = parent;
  6134. if (red) return;
  6135. if (node && node.C) {
  6136. node.C = false;
  6137. return;
  6138. }
  6139. do {
  6140. if (node === this._) break;
  6141. if (node === parent.L) {
  6142. sibling = parent.R;
  6143. if (sibling.C) {
  6144. sibling.C = false;
  6145. parent.C = true;
  6146. d3_geom_voronoiRedBlackRotateLeft(this, parent);
  6147. sibling = parent.R;
  6148. }
  6149. if (sibling.L && sibling.L.C || sibling.R && sibling.R.C) {
  6150. if (!sibling.R || !sibling.R.C) {
  6151. sibling.L.C = false;
  6152. sibling.C = true;
  6153. d3_geom_voronoiRedBlackRotateRight(this, sibling);
  6154. sibling = parent.R;
  6155. }
  6156. sibling.C = parent.C;
  6157. parent.C = sibling.R.C = false;
  6158. d3_geom_voronoiRedBlackRotateLeft(this, parent);
  6159. node = this._;
  6160. break;
  6161. }
  6162. } else {
  6163. sibling = parent.L;
  6164. if (sibling.C) {
  6165. sibling.C = false;
  6166. parent.C = true;
  6167. d3_geom_voronoiRedBlackRotateRight(this, parent);
  6168. sibling = parent.L;
  6169. }
  6170. if (sibling.L && sibling.L.C || sibling.R && sibling.R.C) {
  6171. if (!sibling.L || !sibling.L.C) {
  6172. sibling.R.C = false;
  6173. sibling.C = true;
  6174. d3_geom_voronoiRedBlackRotateLeft(this, sibling);
  6175. sibling = parent.L;
  6176. }
  6177. sibling.C = parent.C;
  6178. parent.C = sibling.L.C = false;
  6179. d3_geom_voronoiRedBlackRotateRight(this, parent);
  6180. node = this._;
  6181. break;
  6182. }
  6183. }
  6184. sibling.C = true;
  6185. node = parent;
  6186. parent = parent.U;
  6187. } while (!node.C);
  6188. if (node) node.C = false;
  6189. }
  6190. };
  6191. function d3_geom_voronoiRedBlackRotateLeft(tree, node) {
  6192. var p = node, q = node.R, parent = p.U;
  6193. if (parent) {
  6194. if (parent.L === p) parent.L = q; else parent.R = q;
  6195. } else {
  6196. tree._ = q;
  6197. }
  6198. q.U = parent;
  6199. p.U = q;
  6200. p.R = q.L;
  6201. if (p.R) p.R.U = p;
  6202. q.L = p;
  6203. }
  6204. function d3_geom_voronoiRedBlackRotateRight(tree, node) {
  6205. var p = node, q = node.L, parent = p.U;
  6206. if (parent) {
  6207. if (parent.L === p) parent.L = q; else parent.R = q;
  6208. } else {
  6209. tree._ = q;
  6210. }
  6211. q.U = parent;
  6212. p.U = q;
  6213. p.L = q.R;
  6214. if (p.L) p.L.U = p;
  6215. q.R = p;
  6216. }
  6217. function d3_geom_voronoiRedBlackFirst(node) {
  6218. while (node.L) node = node.L;
  6219. return node;
  6220. }
  6221. function d3_geom_voronoi(sites, bbox) {
  6222. var site = sites.sort(d3_geom_voronoiVertexOrder).pop(), x0, y0, circle;
  6223. d3_geom_voronoiEdges = [];
  6224. d3_geom_voronoiCells = new Array(sites.length);
  6225. d3_geom_voronoiBeaches = new d3_geom_voronoiRedBlackTree();
  6226. d3_geom_voronoiCircles = new d3_geom_voronoiRedBlackTree();
  6227. while (true) {
  6228. circle = d3_geom_voronoiFirstCircle;
  6229. if (site && (!circle || site.y < circle.y || site.y === circle.y && site.x < circle.x)) {
  6230. if (site.x !== x0 || site.y !== y0) {
  6231. d3_geom_voronoiCells[site.i] = new d3_geom_voronoiCell(site);
  6232. d3_geom_voronoiAddBeach(site);
  6233. x0 = site.x, y0 = site.y;
  6234. }
  6235. site = sites.pop();
  6236. } else if (circle) {
  6237. d3_geom_voronoiRemoveBeach(circle.arc);
  6238. } else {
  6239. break;
  6240. }
  6241. }
  6242. if (bbox) d3_geom_voronoiClipEdges(bbox), d3_geom_voronoiCloseCells(bbox);
  6243. var diagram = {
  6244. cells: d3_geom_voronoiCells,
  6245. edges: d3_geom_voronoiEdges
  6246. };
  6247. d3_geom_voronoiBeaches = d3_geom_voronoiCircles = d3_geom_voronoiEdges = d3_geom_voronoiCells = null;
  6248. return diagram;
  6249. }
  6250. function d3_geom_voronoiVertexOrder(a, b) {
  6251. return b.y - a.y || b.x - a.x;
  6252. }
  6253. d3.geom.voronoi = function(points) {
  6254. var x = d3_geom_pointX, y = d3_geom_pointY, fx = x, fy = y, clipExtent = d3_geom_voronoiClipExtent;
  6255. if (points) return voronoi(points);
  6256. function voronoi(data) {
  6257. var polygons = new Array(data.length), x0 = clipExtent[0][0], y0 = clipExtent[0][1], x1 = clipExtent[1][0], y1 = clipExtent[1][1];
  6258. d3_geom_voronoi(sites(data), clipExtent).cells.forEach(function(cell, i) {
  6259. var edges = cell.edges, site = cell.site, polygon = polygons[i] = edges.length ? edges.map(function(e) {
  6260. var s = e.start();
  6261. return [ s.x, s.y ];
  6262. }) : site.x >= x0 && site.x <= x1 && site.y >= y0 && site.y <= y1 ? [ [ x0, y1 ], [ x1, y1 ], [ x1, y0 ], [ x0, y0 ] ] : [];
  6263. polygon.point = data[i];
  6264. });
  6265. return polygons;
  6266. }
  6267. function sites(data) {
  6268. return data.map(function(d, i) {
  6269. return {
  6270. x: Math.round(fx(d, i) / ε) * ε,
  6271. y: Math.round(fy(d, i) / ε) * ε,
  6272. i: i
  6273. };
  6274. });
  6275. }
  6276. voronoi.links = function(data) {
  6277. return d3_geom_voronoi(sites(data)).edges.filter(function(edge) {
  6278. return edge.l && edge.r;
  6279. }).map(function(edge) {
  6280. return {
  6281. source: data[edge.l.i],
  6282. target: data[edge.r.i]
  6283. };
  6284. });
  6285. };
  6286. voronoi.triangles = function(data) {
  6287. var triangles = [];
  6288. d3_geom_voronoi(sites(data)).cells.forEach(function(cell, i) {
  6289. var site = cell.site, edges = cell.edges.sort(d3_geom_voronoiHalfEdgeOrder), j = -1, m = edges.length, e0, s0, e1 = edges[m - 1].edge, s1 = e1.l === site ? e1.r : e1.l;
  6290. while (++j < m) {
  6291. e0 = e1;
  6292. s0 = s1;
  6293. e1 = edges[j].edge;
  6294. s1 = e1.l === site ? e1.r : e1.l;
  6295. if (i < s0.i && i < s1.i && d3_geom_voronoiTriangleArea(site, s0, s1) < 0) {
  6296. triangles.push([ data[i], data[s0.i], data[s1.i] ]);
  6297. }
  6298. }
  6299. });
  6300. return triangles;
  6301. };
  6302. voronoi.x = function(_) {
  6303. return arguments.length ? (fx = d3_functor(x = _), voronoi) : x;
  6304. };
  6305. voronoi.y = function(_) {
  6306. return arguments.length ? (fy = d3_functor(y = _), voronoi) : y;
  6307. };
  6308. voronoi.clipExtent = function(_) {
  6309. if (!arguments.length) return clipExtent === d3_geom_voronoiClipExtent ? null : clipExtent;
  6310. clipExtent = _ == null ? d3_geom_voronoiClipExtent : _;
  6311. return voronoi;
  6312. };
  6313. voronoi.size = function(_) {
  6314. if (!arguments.length) return clipExtent === d3_geom_voronoiClipExtent ? null : clipExtent && clipExtent[1];
  6315. return voronoi.clipExtent(_ && [ [ 0, 0 ], _ ]);
  6316. };
  6317. return voronoi;
  6318. };
  6319. var d3_geom_voronoiClipExtent = [ [ -1e6, -1e6 ], [ 1e6, 1e6 ] ];
  6320. function d3_geom_voronoiTriangleArea(a, b, c) {
  6321. return (a.x - c.x) * (b.y - a.y) - (a.x - b.x) * (c.y - a.y);
  6322. }
  6323. d3.geom.delaunay = function(vertices) {
  6324. return d3.geom.voronoi().triangles(vertices);
  6325. };
  6326. d3.geom.quadtree = function(points, x1, y1, x2, y2) {
  6327. var x = d3_geom_pointX, y = d3_geom_pointY, compat;
  6328. if (compat = arguments.length) {
  6329. x = d3_geom_quadtreeCompatX;
  6330. y = d3_geom_quadtreeCompatY;
  6331. if (compat === 3) {
  6332. y2 = y1;
  6333. x2 = x1;
  6334. y1 = x1 = 0;
  6335. }
  6336. return quadtree(points);
  6337. }
  6338. function quadtree(data) {
  6339. var d, fx = d3_functor(x), fy = d3_functor(y), xs, ys, i, n, x1_, y1_, x2_, y2_;
  6340. if (x1 != null) {
  6341. x1_ = x1, y1_ = y1, x2_ = x2, y2_ = y2;
  6342. } else {
  6343. x2_ = y2_ = -(x1_ = y1_ = Infinity);
  6344. xs = [], ys = [];
  6345. n = data.length;
  6346. if (compat) for (i = 0; i < n; ++i) {
  6347. d = data[i];
  6348. if (d.x < x1_) x1_ = d.x;
  6349. if (d.y < y1_) y1_ = d.y;
  6350. if (d.x > x2_) x2_ = d.x;
  6351. if (d.y > y2_) y2_ = d.y;
  6352. xs.push(d.x);
  6353. ys.push(d.y);
  6354. } else for (i = 0; i < n; ++i) {
  6355. var x_ = +fx(d = data[i], i), y_ = +fy(d, i);
  6356. if (x_ < x1_) x1_ = x_;
  6357. if (y_ < y1_) y1_ = y_;
  6358. if (x_ > x2_) x2_ = x_;
  6359. if (y_ > y2_) y2_ = y_;
  6360. xs.push(x_);
  6361. ys.push(y_);
  6362. }
  6363. }
  6364. var dx = x2_ - x1_, dy = y2_ - y1_;
  6365. if (dx > dy) y2_ = y1_ + dx; else x2_ = x1_ + dy;
  6366. function insert(n, d, x, y, x1, y1, x2, y2) {
  6367. if (isNaN(x) || isNaN(y)) return;
  6368. if (n.leaf) {
  6369. var nx = n.x, ny = n.y;
  6370. if (nx != null) {
  6371. if (abs(nx - x) + abs(ny - y) < .01) {
  6372. insertChild(n, d, x, y, x1, y1, x2, y2);
  6373. } else {
  6374. var nPoint = n.point;
  6375. n.x = n.y = n.point = null;
  6376. insertChild(n, nPoint, nx, ny, x1, y1, x2, y2);
  6377. insertChild(n, d, x, y, x1, y1, x2, y2);
  6378. }
  6379. } else {
  6380. n.x = x, n.y = y, n.point = d;
  6381. }
  6382. } else {
  6383. insertChild(n, d, x, y, x1, y1, x2, y2);
  6384. }
  6385. }
  6386. function insertChild(n, d, x, y, x1, y1, x2, y2) {
  6387. var xm = (x1 + x2) * .5, ym = (y1 + y2) * .5, right = x >= xm, below = y >= ym, i = below << 1 | right;
  6388. n.leaf = false;
  6389. n = n.nodes[i] || (n.nodes[i] = d3_geom_quadtreeNode());
  6390. if (right) x1 = xm; else x2 = xm;
  6391. if (below) y1 = ym; else y2 = ym;
  6392. insert(n, d, x, y, x1, y1, x2, y2);
  6393. }
  6394. var root = d3_geom_quadtreeNode();
  6395. root.add = function(d) {
  6396. insert(root, d, +fx(d, ++i), +fy(d, i), x1_, y1_, x2_, y2_);
  6397. };
  6398. root.visit = function(f) {
  6399. d3_geom_quadtreeVisit(f, root, x1_, y1_, x2_, y2_);
  6400. };
  6401. root.find = function(point) {
  6402. return d3_geom_quadtreeFind(root, point[0], point[1], x1_, y1_, x2_, y2_);
  6403. };
  6404. i = -1;
  6405. if (x1 == null) {
  6406. while (++i < n) {
  6407. insert(root, data[i], xs[i], ys[i], x1_, y1_, x2_, y2_);
  6408. }
  6409. --i;
  6410. } else data.forEach(root.add);
  6411. xs = ys = data = d = null;
  6412. return root;
  6413. }
  6414. quadtree.x = function(_) {
  6415. return arguments.length ? (x = _, quadtree) : x;
  6416. };
  6417. quadtree.y = function(_) {
  6418. return arguments.length ? (y = _, quadtree) : y;
  6419. };
  6420. quadtree.extent = function(_) {
  6421. if (!arguments.length) return x1 == null ? null : [ [ x1, y1 ], [ x2, y2 ] ];
  6422. if (_ == null) x1 = y1 = x2 = y2 = null; else x1 = +_[0][0], y1 = +_[0][1], x2 = +_[1][0],
  6423. y2 = +_[1][1];
  6424. return quadtree;
  6425. };
  6426. quadtree.size = function(_) {
  6427. if (!arguments.length) return x1 == null ? null : [ x2 - x1, y2 - y1 ];
  6428. if (_ == null) x1 = y1 = x2 = y2 = null; else x1 = y1 = 0, x2 = +_[0], y2 = +_[1];
  6429. return quadtree;
  6430. };
  6431. return quadtree;
  6432. };
  6433. function d3_geom_quadtreeCompatX(d) {
  6434. return d.x;
  6435. }
  6436. function d3_geom_quadtreeCompatY(d) {
  6437. return d.y;
  6438. }
  6439. function d3_geom_quadtreeNode() {
  6440. return {
  6441. leaf: true,
  6442. nodes: [],
  6443. point: null,
  6444. x: null,
  6445. y: null
  6446. };
  6447. }
  6448. function d3_geom_quadtreeVisit(f, node, x1, y1, x2, y2) {
  6449. if (!f(node, x1, y1, x2, y2)) {
  6450. var sx = (x1 + x2) * .5, sy = (y1 + y2) * .5, children = node.nodes;
  6451. if (children[0]) d3_geom_quadtreeVisit(f, children[0], x1, y1, sx, sy);
  6452. if (children[1]) d3_geom_quadtreeVisit(f, children[1], sx, y1, x2, sy);
  6453. if (children[2]) d3_geom_quadtreeVisit(f, children[2], x1, sy, sx, y2);
  6454. if (children[3]) d3_geom_quadtreeVisit(f, children[3], sx, sy, x2, y2);
  6455. }
  6456. }
  6457. function d3_geom_quadtreeFind(root, x, y, x0, y0, x3, y3) {
  6458. var minDistance2 = Infinity, closestPoint;
  6459. (function find(node, x1, y1, x2, y2) {
  6460. if (x1 > x3 || y1 > y3 || x2 < x0 || y2 < y0) return;
  6461. if (point = node.point) {
  6462. var point, dx = x - node.x, dy = y - node.y, distance2 = dx * dx + dy * dy;
  6463. if (distance2 < minDistance2) {
  6464. var distance = Math.sqrt(minDistance2 = distance2);
  6465. x0 = x - distance, y0 = y - distance;
  6466. x3 = x + distance, y3 = y + distance;
  6467. closestPoint = point;
  6468. }
  6469. }
  6470. var children = node.nodes, xm = (x1 + x2) * .5, ym = (y1 + y2) * .5, right = x >= xm, below = y >= ym;
  6471. for (var i = below << 1 | right, j = i + 4; i < j; ++i) {
  6472. if (node = children[i & 3]) switch (i & 3) {
  6473. case 0:
  6474. find(node, x1, y1, xm, ym);
  6475. break;
  6476. case 1:
  6477. find(node, xm, y1, x2, ym);
  6478. break;
  6479. case 2:
  6480. find(node, x1, ym, xm, y2);
  6481. break;
  6482. case 3:
  6483. find(node, xm, ym, x2, y2);
  6484. break;
  6485. }
  6486. }
  6487. })(root, x0, y0, x3, y3);
  6488. return closestPoint;
  6489. }
  6490. d3.interpolateRgb = d3_interpolateRgb;
  6491. function d3_interpolateRgb(a, b) {
  6492. a = d3.rgb(a);
  6493. b = d3.rgb(b);
  6494. var ar = a.r, ag = a.g, ab = a.b, br = b.r - ar, bg = b.g - ag, bb = b.b - ab;
  6495. return function(t) {
  6496. return "#" + d3_rgb_hex(Math.round(ar + br * t)) + d3_rgb_hex(Math.round(ag + bg * t)) + d3_rgb_hex(Math.round(ab + bb * t));
  6497. };
  6498. }
  6499. d3.interpolateObject = d3_interpolateObject;
  6500. function d3_interpolateObject(a, b) {
  6501. var i = {}, c = {}, k;
  6502. for (k in a) {
  6503. if (k in b) {
  6504. i[k] = d3_interpolate(a[k], b[k]);
  6505. } else {
  6506. c[k] = a[k];
  6507. }
  6508. }
  6509. for (k in b) {
  6510. if (!(k in a)) {
  6511. c[k] = b[k];
  6512. }
  6513. }
  6514. return function(t) {
  6515. for (k in i) c[k] = i[k](t);
  6516. return c;
  6517. };
  6518. }
  6519. d3.interpolateNumber = d3_interpolateNumber;
  6520. function d3_interpolateNumber(a, b) {
  6521. a = +a, b = +b;
  6522. return function(t) {
  6523. return a * (1 - t) + b * t;
  6524. };
  6525. }
  6526. d3.interpolateString = d3_interpolateString;
  6527. function d3_interpolateString(a, b) {
  6528. var bi = d3_interpolate_numberA.lastIndex = d3_interpolate_numberB.lastIndex = 0, am, bm, bs, i = -1, s = [], q = [];
  6529. a = a + "", b = b + "";
  6530. while ((am = d3_interpolate_numberA.exec(a)) && (bm = d3_interpolate_numberB.exec(b))) {
  6531. if ((bs = bm.index) > bi) {
  6532. bs = b.slice(bi, bs);
  6533. if (s[i]) s[i] += bs; else s[++i] = bs;
  6534. }
  6535. if ((am = am[0]) === (bm = bm[0])) {
  6536. if (s[i]) s[i] += bm; else s[++i] = bm;
  6537. } else {
  6538. s[++i] = null;
  6539. q.push({
  6540. i: i,
  6541. x: d3_interpolateNumber(am, bm)
  6542. });
  6543. }
  6544. bi = d3_interpolate_numberB.lastIndex;
  6545. }
  6546. if (bi < b.length) {
  6547. bs = b.slice(bi);
  6548. if (s[i]) s[i] += bs; else s[++i] = bs;
  6549. }
  6550. return s.length < 2 ? q[0] ? (b = q[0].x, function(t) {
  6551. return b(t) + "";
  6552. }) : function() {
  6553. return b;
  6554. } : (b = q.length, function(t) {
  6555. for (var i = 0, o; i < b; ++i) s[(o = q[i]).i] = o.x(t);
  6556. return s.join("");
  6557. });
  6558. }
  6559. var d3_interpolate_numberA = /[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g, d3_interpolate_numberB = new RegExp(d3_interpolate_numberA.source, "g");
  6560. d3.interpolate = d3_interpolate;
  6561. function d3_interpolate(a, b) {
  6562. var i = d3.interpolators.length, f;
  6563. while (--i >= 0 && !(f = d3.interpolators[i](a, b))) ;
  6564. return f;
  6565. }
  6566. d3.interpolators = [ function(a, b) {
  6567. var t = typeof b;
  6568. return (t === "string" ? d3_rgb_names.has(b.toLowerCase()) || /^(#|rgb\(|hsl\()/i.test(b) ? d3_interpolateRgb : d3_interpolateString : b instanceof d3_color ? d3_interpolateRgb : Array.isArray(b) ? d3_interpolateArray : t === "object" && isNaN(b) ? d3_interpolateObject : d3_interpolateNumber)(a, b);
  6569. } ];
  6570. d3.interpolateArray = d3_interpolateArray;
  6571. function d3_interpolateArray(a, b) {
  6572. var x = [], c = [], na = a.length, nb = b.length, n0 = Math.min(a.length, b.length), i;
  6573. for (i = 0; i < n0; ++i) x.push(d3_interpolate(a[i], b[i]));
  6574. for (;i < na; ++i) c[i] = a[i];
  6575. for (;i < nb; ++i) c[i] = b[i];
  6576. return function(t) {
  6577. for (i = 0; i < n0; ++i) c[i] = x[i](t);
  6578. return c;
  6579. };
  6580. }
  6581. var d3_ease_default = function() {
  6582. return d3_identity;
  6583. };
  6584. var d3_ease = d3.map({
  6585. linear: d3_ease_default,
  6586. poly: d3_ease_poly,
  6587. quad: function() {
  6588. return d3_ease_quad;
  6589. },
  6590. cubic: function() {
  6591. return d3_ease_cubic;
  6592. },
  6593. sin: function() {
  6594. return d3_ease_sin;
  6595. },
  6596. exp: function() {
  6597. return d3_ease_exp;
  6598. },
  6599. circle: function() {
  6600. return d3_ease_circle;
  6601. },
  6602. elastic: d3_ease_elastic,
  6603. back: d3_ease_back,
  6604. bounce: function() {
  6605. return d3_ease_bounce;
  6606. }
  6607. });
  6608. var d3_ease_mode = d3.map({
  6609. "in": d3_identity,
  6610. out: d3_ease_reverse,
  6611. "in-out": d3_ease_reflect,
  6612. "out-in": function(f) {
  6613. return d3_ease_reflect(d3_ease_reverse(f));
  6614. }
  6615. });
  6616. d3.ease = function(name) {
  6617. var i = name.indexOf("-"), t = i >= 0 ? name.slice(0, i) : name, m = i >= 0 ? name.slice(i + 1) : "in";
  6618. t = d3_ease.get(t) || d3_ease_default;
  6619. m = d3_ease_mode.get(m) || d3_identity;
  6620. return d3_ease_clamp(m(t.apply(null, d3_arraySlice.call(arguments, 1))));
  6621. };
  6622. function d3_ease_clamp(f) {
  6623. return function(t) {
  6624. return t <= 0 ? 0 : t >= 1 ? 1 : f(t);
  6625. };
  6626. }
  6627. function d3_ease_reverse(f) {
  6628. return function(t) {
  6629. return 1 - f(1 - t);
  6630. };
  6631. }
  6632. function d3_ease_reflect(f) {
  6633. return function(t) {
  6634. return .5 * (t < .5 ? f(2 * t) : 2 - f(2 - 2 * t));
  6635. };
  6636. }
  6637. function d3_ease_quad(t) {
  6638. return t * t;
  6639. }
  6640. function d3_ease_cubic(t) {
  6641. return t * t * t;
  6642. }
  6643. function d3_ease_cubicInOut(t) {
  6644. if (t <= 0) return 0;
  6645. if (t >= 1) return 1;
  6646. var t2 = t * t, t3 = t2 * t;
  6647. return 4 * (t < .5 ? t3 : 3 * (t - t2) + t3 - .75);
  6648. }
  6649. function d3_ease_poly(e) {
  6650. return function(t) {
  6651. return Math.pow(t, e);
  6652. };
  6653. }
  6654. function d3_ease_sin(t) {
  6655. return 1 - Math.cos(t * halfπ);
  6656. }
  6657. function d3_ease_exp(t) {
  6658. return Math.pow(2, 10 * (t - 1));
  6659. }
  6660. function d3_ease_circle(t) {
  6661. return 1 - Math.sqrt(1 - t * t);
  6662. }
  6663. function d3_ease_elastic(a, p) {
  6664. var s;
  6665. if (arguments.length < 2) p = .45;
  6666. if (arguments.length) s = p / τ * Math.asin(1 / a); else a = 1, s = p / 4;
  6667. return function(t) {
  6668. return 1 + a * Math.pow(2, -10 * t) * Math.sin((t - s) * τ / p);
  6669. };
  6670. }
  6671. function d3_ease_back(s) {
  6672. if (!s) s = 1.70158;
  6673. return function(t) {
  6674. return t * t * ((s + 1) * t - s);
  6675. };
  6676. }
  6677. function d3_ease_bounce(t) {
  6678. return t < 1 / 2.75 ? 7.5625 * t * t : t < 2 / 2.75 ? 7.5625 * (t -= 1.5 / 2.75) * t + .75 : t < 2.5 / 2.75 ? 7.5625 * (t -= 2.25 / 2.75) * t + .9375 : 7.5625 * (t -= 2.625 / 2.75) * t + .984375;
  6679. }
  6680. d3.interpolateHcl = d3_interpolateHcl;
  6681. function d3_interpolateHcl(a, b) {
  6682. a = d3.hcl(a);
  6683. b = d3.hcl(b);
  6684. var ah = a.h, ac = a.c, al = a.l, bh = b.h - ah, bc = b.c - ac, bl = b.l - al;
  6685. if (isNaN(bc)) bc = 0, ac = isNaN(ac) ? b.c : ac;
  6686. if (isNaN(bh)) bh = 0, ah = isNaN(ah) ? b.h : ah; else if (bh > 180) bh -= 360; else if (bh < -180) bh += 360;
  6687. return function(t) {
  6688. return d3_hcl_lab(ah + bh * t, ac + bc * t, al + bl * t) + "";
  6689. };
  6690. }
  6691. d3.interpolateHsl = d3_interpolateHsl;
  6692. function d3_interpolateHsl(a, b) {
  6693. a = d3.hsl(a);
  6694. b = d3.hsl(b);
  6695. var ah = a.h, as = a.s, al = a.l, bh = b.h - ah, bs = b.s - as, bl = b.l - al;
  6696. if (isNaN(bs)) bs = 0, as = isNaN(as) ? b.s : as;
  6697. if (isNaN(bh)) bh = 0, ah = isNaN(ah) ? b.h : ah; else if (bh > 180) bh -= 360; else if (bh < -180) bh += 360;
  6698. return function(t) {
  6699. return d3_hsl_rgb(ah + bh * t, as + bs * t, al + bl * t) + "";
  6700. };
  6701. }
  6702. d3.interpolateLab = d3_interpolateLab;
  6703. function d3_interpolateLab(a, b) {
  6704. a = d3.lab(a);
  6705. b = d3.lab(b);
  6706. var al = a.l, aa = a.a, ab = a.b, bl = b.l - al, ba = b.a - aa, bb = b.b - ab;
  6707. return function(t) {
  6708. return d3_lab_rgb(al + bl * t, aa + ba * t, ab + bb * t) + "";
  6709. };
  6710. }
  6711. d3.interpolateRound = d3_interpolateRound;
  6712. function d3_interpolateRound(a, b) {
  6713. b -= a;
  6714. return function(t) {
  6715. return Math.round(a + b * t);
  6716. };
  6717. }
  6718. d3.transform = function(string) {
  6719. var g = d3_document.createElementNS(d3.ns.prefix.svg, "g");
  6720. return (d3.transform = function(string) {
  6721. if (string != null) {
  6722. g.setAttribute("transform", string);
  6723. var t = g.transform.baseVal.consolidate();
  6724. }
  6725. return new d3_transform(t ? t.matrix : d3_transformIdentity);
  6726. })(string);
  6727. };
  6728. function d3_transform(m) {
  6729. var r0 = [ m.a, m.b ], r1 = [ m.c, m.d ], kx = d3_transformNormalize(r0), kz = d3_transformDot(r0, r1), ky = d3_transformNormalize(d3_transformCombine(r1, r0, -kz)) || 0;
  6730. if (r0[0] * r1[1] < r1[0] * r0[1]) {
  6731. r0[0] *= -1;
  6732. r0[1] *= -1;
  6733. kx *= -1;
  6734. kz *= -1;
  6735. }
  6736. this.rotate = (kx ? Math.atan2(r0[1], r0[0]) : Math.atan2(-r1[0], r1[1])) * d3_degrees;
  6737. this.translate = [ m.e, m.f ];
  6738. this.scale = [ kx, ky ];
  6739. this.skew = ky ? Math.atan2(kz, ky) * d3_degrees : 0;
  6740. }
  6741. d3_transform.prototype.toString = function() {
  6742. return "translate(" + this.translate + ")rotate(" + this.rotate + ")skewX(" + this.skew + ")scale(" + this.scale + ")";
  6743. };
  6744. function d3_transformDot(a, b) {
  6745. return a[0] * b[0] + a[1] * b[1];
  6746. }
  6747. function d3_transformNormalize(a) {
  6748. var k = Math.sqrt(d3_transformDot(a, a));
  6749. if (k) {
  6750. a[0] /= k;
  6751. a[1] /= k;
  6752. }
  6753. return k;
  6754. }
  6755. function d3_transformCombine(a, b, k) {
  6756. a[0] += k * b[0];
  6757. a[1] += k * b[1];
  6758. return a;
  6759. }
  6760. var d3_transformIdentity = {
  6761. a: 1,
  6762. b: 0,
  6763. c: 0,
  6764. d: 1,
  6765. e: 0,
  6766. f: 0
  6767. };
  6768. d3.interpolateTransform = d3_interpolateTransform;
  6769. function d3_interpolateTransformPop(s) {
  6770. return s.length ? s.pop() + "," : "";
  6771. }
  6772. function d3_interpolateTranslate(ta, tb, s, q) {
  6773. if (ta[0] !== tb[0] || ta[1] !== tb[1]) {
  6774. var i = s.push("translate(", null, ",", null, ")");
  6775. q.push({
  6776. i: i - 4,
  6777. x: d3_interpolateNumber(ta[0], tb[0])
  6778. }, {
  6779. i: i - 2,
  6780. x: d3_interpolateNumber(ta[1], tb[1])
  6781. });
  6782. } else if (tb[0] || tb[1]) {
  6783. s.push("translate(" + tb + ")");
  6784. }
  6785. }
  6786. function d3_interpolateRotate(ra, rb, s, q) {
  6787. if (ra !== rb) {
  6788. if (ra - rb > 180) rb += 360; else if (rb - ra > 180) ra += 360;
  6789. q.push({
  6790. i: s.push(d3_interpolateTransformPop(s) + "rotate(", null, ")") - 2,
  6791. x: d3_interpolateNumber(ra, rb)
  6792. });
  6793. } else if (rb) {
  6794. s.push(d3_interpolateTransformPop(s) + "rotate(" + rb + ")");
  6795. }
  6796. }
  6797. function d3_interpolateSkew(wa, wb, s, q) {
  6798. if (wa !== wb) {
  6799. q.push({
  6800. i: s.push(d3_interpolateTransformPop(s) + "skewX(", null, ")") - 2,
  6801. x: d3_interpolateNumber(wa, wb)
  6802. });
  6803. } else if (wb) {
  6804. s.push(d3_interpolateTransformPop(s) + "skewX(" + wb + ")");
  6805. }
  6806. }
  6807. function d3_interpolateScale(ka, kb, s, q) {
  6808. if (ka[0] !== kb[0] || ka[1] !== kb[1]) {
  6809. var i = s.push(d3_interpolateTransformPop(s) + "scale(", null, ",", null, ")");
  6810. q.push({
  6811. i: i - 4,
  6812. x: d3_interpolateNumber(ka[0], kb[0])
  6813. }, {
  6814. i: i - 2,
  6815. x: d3_interpolateNumber(ka[1], kb[1])
  6816. });
  6817. } else if (kb[0] !== 1 || kb[1] !== 1) {
  6818. s.push(d3_interpolateTransformPop(s) + "scale(" + kb + ")");
  6819. }
  6820. }
  6821. function d3_interpolateTransform(a, b) {
  6822. var s = [], q = [];
  6823. a = d3.transform(a), b = d3.transform(b);
  6824. d3_interpolateTranslate(a.translate, b.translate, s, q);
  6825. d3_interpolateRotate(a.rotate, b.rotate, s, q);
  6826. d3_interpolateSkew(a.skew, b.skew, s, q);
  6827. d3_interpolateScale(a.scale, b.scale, s, q);
  6828. a = b = null;
  6829. return function(t) {
  6830. var i = -1, n = q.length, o;
  6831. while (++i < n) s[(o = q[i]).i] = o.x(t);
  6832. return s.join("");
  6833. };
  6834. }
  6835. function d3_uninterpolateNumber(a, b) {
  6836. b = (b -= a = +a) || 1 / b;
  6837. return function(x) {
  6838. return (x - a) / b;
  6839. };
  6840. }
  6841. function d3_uninterpolateClamp(a, b) {
  6842. b = (b -= a = +a) || 1 / b;
  6843. return function(x) {
  6844. return Math.max(0, Math.min(1, (x - a) / b));
  6845. };
  6846. }
  6847. d3.layout = {};
  6848. d3.layout.bundle = function() {
  6849. return function(links) {
  6850. var paths = [], i = -1, n = links.length;
  6851. while (++i < n) paths.push(d3_layout_bundlePath(links[i]));
  6852. return paths;
  6853. };
  6854. };
  6855. function d3_layout_bundlePath(link) {
  6856. var start = link.source, end = link.target, lca = d3_layout_bundleLeastCommonAncestor(start, end), points = [ start ];
  6857. while (start !== lca) {
  6858. start = start.parent;
  6859. points.push(start);
  6860. }
  6861. var k = points.length;
  6862. while (end !== lca) {
  6863. points.splice(k, 0, end);
  6864. end = end.parent;
  6865. }
  6866. return points;
  6867. }
  6868. function d3_layout_bundleAncestors(node) {
  6869. var ancestors = [], parent = node.parent;
  6870. while (parent != null) {
  6871. ancestors.push(node);
  6872. node = parent;
  6873. parent = parent.parent;
  6874. }
  6875. ancestors.push(node);
  6876. return ancestors;
  6877. }
  6878. function d3_layout_bundleLeastCommonAncestor(a, b) {
  6879. if (a === b) return a;
  6880. var aNodes = d3_layout_bundleAncestors(a), bNodes = d3_layout_bundleAncestors(b), aNode = aNodes.pop(), bNode = bNodes.pop(), sharedNode = null;
  6881. while (aNode === bNode) {
  6882. sharedNode = aNode;
  6883. aNode = aNodes.pop();
  6884. bNode = bNodes.pop();
  6885. }
  6886. return sharedNode;
  6887. }
  6888. d3.layout.chord = function() {
  6889. var chord = {}, chords, groups, matrix, n, padding = 0, sortGroups, sortSubgroups, sortChords;
  6890. function relayout() {
  6891. var subgroups = {}, groupSums = [], groupIndex = d3.range(n), subgroupIndex = [], k, x, x0, i, j;
  6892. chords = [];
  6893. groups = [];
  6894. k = 0, i = -1;
  6895. while (++i < n) {
  6896. x = 0, j = -1;
  6897. while (++j < n) {
  6898. x += matrix[i][j];
  6899. }
  6900. groupSums.push(x);
  6901. subgroupIndex.push(d3.range(n));
  6902. k += x;
  6903. }
  6904. if (sortGroups) {
  6905. groupIndex.sort(function(a, b) {
  6906. return sortGroups(groupSums[a], groupSums[b]);
  6907. });
  6908. }
  6909. if (sortSubgroups) {
  6910. subgroupIndex.forEach(function(d, i) {
  6911. d.sort(function(a, b) {
  6912. return sortSubgroups(matrix[i][a], matrix[i][b]);
  6913. });
  6914. });
  6915. }
  6916. k = (τ - padding * n) / k;
  6917. x = 0, i = -1;
  6918. while (++i < n) {
  6919. x0 = x, j = -1;
  6920. while (++j < n) {
  6921. var di = groupIndex[i], dj = subgroupIndex[di][j], v = matrix[di][dj], a0 = x, a1 = x += v * k;
  6922. subgroups[di + "-" + dj] = {
  6923. index: di,
  6924. subindex: dj,
  6925. startAngle: a0,
  6926. endAngle: a1,
  6927. value: v
  6928. };
  6929. }
  6930. groups[di] = {
  6931. index: di,
  6932. startAngle: x0,
  6933. endAngle: x,
  6934. value: groupSums[di]
  6935. };
  6936. x += padding;
  6937. }
  6938. i = -1;
  6939. while (++i < n) {
  6940. j = i - 1;
  6941. while (++j < n) {
  6942. var source = subgroups[i + "-" + j], target = subgroups[j + "-" + i];
  6943. if (source.value || target.value) {
  6944. chords.push(source.value < target.value ? {
  6945. source: target,
  6946. target: source
  6947. } : {
  6948. source: source,
  6949. target: target
  6950. });
  6951. }
  6952. }
  6953. }
  6954. if (sortChords) resort();
  6955. }
  6956. function resort() {
  6957. chords.sort(function(a, b) {
  6958. return sortChords((a.source.value + a.target.value) / 2, (b.source.value + b.target.value) / 2);
  6959. });
  6960. }
  6961. chord.matrix = function(x) {
  6962. if (!arguments.length) return matrix;
  6963. n = (matrix = x) && matrix.length;
  6964. chords = groups = null;
  6965. return chord;
  6966. };
  6967. chord.padding = function(x) {
  6968. if (!arguments.length) return padding;
  6969. padding = x;
  6970. chords = groups = null;
  6971. return chord;
  6972. };
  6973. chord.sortGroups = function(x) {
  6974. if (!arguments.length) return sortGroups;
  6975. sortGroups = x;
  6976. chords = groups = null;
  6977. return chord;
  6978. };
  6979. chord.sortSubgroups = function(x) {
  6980. if (!arguments.length) return sortSubgroups;
  6981. sortSubgroups = x;
  6982. chords = null;
  6983. return chord;
  6984. };
  6985. chord.sortChords = function(x) {
  6986. if (!arguments.length) return sortChords;
  6987. sortChords = x;
  6988. if (chords) resort();
  6989. return chord;
  6990. };
  6991. chord.chords = function() {
  6992. if (!chords) relayout();
  6993. return chords;
  6994. };
  6995. chord.groups = function() {
  6996. if (!groups) relayout();
  6997. return groups;
  6998. };
  6999. return chord;
  7000. };
  7001. d3.layout.force = function() {
  7002. var force = {}, event = d3.dispatch("start", "tick", "end"), timer, size = [ 1, 1 ], drag, alpha, friction = .9, linkDistance = d3_layout_forceLinkDistance, linkStrength = d3_layout_forceLinkStrength, charge = -30, chargeDistance2 = d3_layout_forceChargeDistance2, gravity = .1, theta2 = .64, nodes = [], links = [], distances, strengths, charges;
  7003. function repulse(node) {
  7004. return function(quad, x1, _, x2) {
  7005. if (quad.point !== node) {
  7006. var dx = quad.cx - node.x, dy = quad.cy - node.y, dw = x2 - x1, dn = dx * dx + dy * dy;
  7007. if (dw * dw / theta2 < dn) {
  7008. if (dn < chargeDistance2) {
  7009. var k = quad.charge / dn;
  7010. node.px -= dx * k;
  7011. node.py -= dy * k;
  7012. }
  7013. return true;
  7014. }
  7015. if (quad.point && dn && dn < chargeDistance2) {
  7016. var k = quad.pointCharge / dn;
  7017. node.px -= dx * k;
  7018. node.py -= dy * k;
  7019. }
  7020. }
  7021. return !quad.charge;
  7022. };
  7023. }
  7024. force.tick = function() {
  7025. if ((alpha *= .99) < .005) {
  7026. timer = null;
  7027. event.end({
  7028. type: "end",
  7029. alpha: alpha = 0
  7030. });
  7031. return true;
  7032. }
  7033. var n = nodes.length, m = links.length, q, i, o, s, t, l, k, x, y;
  7034. for (i = 0; i < m; ++i) {
  7035. o = links[i];
  7036. s = o.source;
  7037. t = o.target;
  7038. x = t.x - s.x;
  7039. y = t.y - s.y;
  7040. if (l = x * x + y * y) {
  7041. l = alpha * strengths[i] * ((l = Math.sqrt(l)) - distances[i]) / l;
  7042. x *= l;
  7043. y *= l;
  7044. t.x -= x * (k = s.weight + t.weight ? s.weight / (s.weight + t.weight) : .5);
  7045. t.y -= y * k;
  7046. s.x += x * (k = 1 - k);
  7047. s.y += y * k;
  7048. }
  7049. }
  7050. if (k = alpha * gravity) {
  7051. x = size[0] / 2;
  7052. y = size[1] / 2;
  7053. i = -1;
  7054. if (k) while (++i < n) {
  7055. o = nodes[i];
  7056. o.x += (x - o.x) * k;
  7057. o.y += (y - o.y) * k;
  7058. }
  7059. }
  7060. if (charge) {
  7061. d3_layout_forceAccumulate(q = d3.geom.quadtree(nodes), alpha, charges);
  7062. i = -1;
  7063. while (++i < n) {
  7064. if (!(o = nodes[i]).fixed) {
  7065. q.visit(repulse(o));
  7066. }
  7067. }
  7068. }
  7069. i = -1;
  7070. while (++i < n) {
  7071. o = nodes[i];
  7072. if (o.fixed) {
  7073. o.x = o.px;
  7074. o.y = o.py;
  7075. } else {
  7076. o.x -= (o.px - (o.px = o.x)) * friction;
  7077. o.y -= (o.py - (o.py = o.y)) * friction;
  7078. }
  7079. }
  7080. event.tick({
  7081. type: "tick",
  7082. alpha: alpha
  7083. });
  7084. };
  7085. force.nodes = function(x) {
  7086. if (!arguments.length) return nodes;
  7087. nodes = x;
  7088. return force;
  7089. };
  7090. force.links = function(x) {
  7091. if (!arguments.length) return links;
  7092. links = x;
  7093. return force;
  7094. };
  7095. force.size = function(x) {
  7096. if (!arguments.length) return size;
  7097. size = x;
  7098. return force;
  7099. };
  7100. force.linkDistance = function(x) {
  7101. if (!arguments.length) return linkDistance;
  7102. linkDistance = typeof x === "function" ? x : +x;
  7103. return force;
  7104. };
  7105. force.distance = force.linkDistance;
  7106. force.linkStrength = function(x) {
  7107. if (!arguments.length) return linkStrength;
  7108. linkStrength = typeof x === "function" ? x : +x;
  7109. return force;
  7110. };
  7111. force.friction = function(x) {
  7112. if (!arguments.length) return friction;
  7113. friction = +x;
  7114. return force;
  7115. };
  7116. force.charge = function(x) {
  7117. if (!arguments.length) return charge;
  7118. charge = typeof x === "function" ? x : +x;
  7119. return force;
  7120. };
  7121. force.chargeDistance = function(x) {
  7122. if (!arguments.length) return Math.sqrt(chargeDistance2);
  7123. chargeDistance2 = x * x;
  7124. return force;
  7125. };
  7126. force.gravity = function(x) {
  7127. if (!arguments.length) return gravity;
  7128. gravity = +x;
  7129. return force;
  7130. };
  7131. force.theta = function(x) {
  7132. if (!arguments.length) return Math.sqrt(theta2);
  7133. theta2 = x * x;
  7134. return force;
  7135. };
  7136. force.alpha = function(x) {
  7137. if (!arguments.length) return alpha;
  7138. x = +x;
  7139. if (alpha) {
  7140. if (x > 0) {
  7141. alpha = x;
  7142. } else {
  7143. timer.c = null, timer.t = NaN, timer = null;
  7144. event.end({
  7145. type: "end",
  7146. alpha: alpha = 0
  7147. });
  7148. }
  7149. } else if (x > 0) {
  7150. event.start({
  7151. type: "start",
  7152. alpha: alpha = x
  7153. });
  7154. timer = d3_timer(force.tick);
  7155. }
  7156. return force;
  7157. };
  7158. force.start = function() {
  7159. var i, n = nodes.length, m = links.length, w = size[0], h = size[1], neighbors, o;
  7160. for (i = 0; i < n; ++i) {
  7161. (o = nodes[i]).index = i;
  7162. o.weight = 0;
  7163. }
  7164. for (i = 0; i < m; ++i) {
  7165. o = links[i];
  7166. if (typeof o.source == "number") o.source = nodes[o.source];
  7167. if (typeof o.target == "number") o.target = nodes[o.target];
  7168. ++o.source.weight;
  7169. ++o.target.weight;
  7170. }
  7171. for (i = 0; i < n; ++i) {
  7172. o = nodes[i];
  7173. if (isNaN(o.x)) o.x = position("x", w);
  7174. if (isNaN(o.y)) o.y = position("y", h);
  7175. if (isNaN(o.px)) o.px = o.x;
  7176. if (isNaN(o.py)) o.py = o.y;
  7177. }
  7178. distances = [];
  7179. if (typeof linkDistance === "function") for (i = 0; i < m; ++i) distances[i] = +linkDistance.call(this, links[i], i); else for (i = 0; i < m; ++i) distances[i] = linkDistance;
  7180. strengths = [];
  7181. if (typeof linkStrength === "function") for (i = 0; i < m; ++i) strengths[i] = +linkStrength.call(this, links[i], i); else for (i = 0; i < m; ++i) strengths[i] = linkStrength;
  7182. charges = [];
  7183. if (typeof charge === "function") for (i = 0; i < n; ++i) charges[i] = +charge.call(this, nodes[i], i); else for (i = 0; i < n; ++i) charges[i] = charge;
  7184. function position(dimension, size) {
  7185. if (!neighbors) {
  7186. neighbors = new Array(n);
  7187. for (j = 0; j < n; ++j) {
  7188. neighbors[j] = [];
  7189. }
  7190. for (j = 0; j < m; ++j) {
  7191. var o = links[j];
  7192. neighbors[o.source.index].push(o.target);
  7193. neighbors[o.target.index].push(o.source);
  7194. }
  7195. }
  7196. var candidates = neighbors[i], j = -1, l = candidates.length, x;
  7197. while (++j < l) if (!isNaN(x = candidates[j][dimension])) return x;
  7198. return Math.random() * size;
  7199. }
  7200. return force.resume();
  7201. };
  7202. force.resume = function() {
  7203. return force.alpha(.1);
  7204. };
  7205. force.stop = function() {
  7206. return force.alpha(0);
  7207. };
  7208. force.drag = function() {
  7209. if (!drag) drag = d3.behavior.drag().origin(d3_identity).on("dragstart.force", d3_layout_forceDragstart).on("drag.force", dragmove).on("dragend.force", d3_layout_forceDragend);
  7210. if (!arguments.length) return drag;
  7211. this.on("mouseover.force", d3_layout_forceMouseover).on("mouseout.force", d3_layout_forceMouseout).call(drag);
  7212. };
  7213. function dragmove(d) {
  7214. d.px = d3.event.x, d.py = d3.event.y;
  7215. force.resume();
  7216. }
  7217. return d3.rebind(force, event, "on");
  7218. };
  7219. function d3_layout_forceDragstart(d) {
  7220. d.fixed |= 2;
  7221. }
  7222. function d3_layout_forceDragend(d) {
  7223. d.fixed &= ~6;
  7224. }
  7225. function d3_layout_forceMouseover(d) {
  7226. d.fixed |= 4;
  7227. d.px = d.x, d.py = d.y;
  7228. }
  7229. function d3_layout_forceMouseout(d) {
  7230. d.fixed &= ~4;
  7231. }
  7232. function d3_layout_forceAccumulate(quad, alpha, charges) {
  7233. var cx = 0, cy = 0;
  7234. quad.charge = 0;
  7235. if (!quad.leaf) {
  7236. var nodes = quad.nodes, n = nodes.length, i = -1, c;
  7237. while (++i < n) {
  7238. c = nodes[i];
  7239. if (c == null) continue;
  7240. d3_layout_forceAccumulate(c, alpha, charges);
  7241. quad.charge += c.charge;
  7242. cx += c.charge * c.cx;
  7243. cy += c.charge * c.cy;
  7244. }
  7245. }
  7246. if (quad.point) {
  7247. if (!quad.leaf) {
  7248. quad.point.x += Math.random() - .5;
  7249. quad.point.y += Math.random() - .5;
  7250. }
  7251. var k = alpha * charges[quad.point.index];
  7252. quad.charge += quad.pointCharge = k;
  7253. cx += k * quad.point.x;
  7254. cy += k * quad.point.y;
  7255. }
  7256. quad.cx = cx / quad.charge;
  7257. quad.cy = cy / quad.charge;
  7258. }
  7259. var d3_layout_forceLinkDistance = 20, d3_layout_forceLinkStrength = 1, d3_layout_forceChargeDistance2 = Infinity;
  7260. d3.layout.hierarchy = function() {
  7261. var sort = d3_layout_hierarchySort, children = d3_layout_hierarchyChildren, value = d3_layout_hierarchyValue;
  7262. function hierarchy(root) {
  7263. var stack = [ root ], nodes = [], node;
  7264. root.depth = 0;
  7265. while ((node = stack.pop()) != null) {
  7266. nodes.push(node);
  7267. if ((childs = children.call(hierarchy, node, node.depth)) && (n = childs.length)) {
  7268. var n, childs, child;
  7269. while (--n >= 0) {
  7270. stack.push(child = childs[n]);
  7271. child.parent = node;
  7272. child.depth = node.depth + 1;
  7273. }
  7274. if (value) node.value = 0;
  7275. node.children = childs;
  7276. } else {
  7277. if (value) node.value = +value.call(hierarchy, node, node.depth) || 0;
  7278. delete node.children;
  7279. }
  7280. }
  7281. d3_layout_hierarchyVisitAfter(root, function(node) {
  7282. var childs, parent;
  7283. if (sort && (childs = node.children)) childs.sort(sort);
  7284. if (value && (parent = node.parent)) parent.value += node.value;
  7285. });
  7286. return nodes;
  7287. }
  7288. hierarchy.sort = function(x) {
  7289. if (!arguments.length) return sort;
  7290. sort = x;
  7291. return hierarchy;
  7292. };
  7293. hierarchy.children = function(x) {
  7294. if (!arguments.length) return children;
  7295. children = x;
  7296. return hierarchy;
  7297. };
  7298. hierarchy.value = function(x) {
  7299. if (!arguments.length) return value;
  7300. value = x;
  7301. return hierarchy;
  7302. };
  7303. hierarchy.revalue = function(root) {
  7304. if (value) {
  7305. d3_layout_hierarchyVisitBefore(root, function(node) {
  7306. if (node.children) node.value = 0;
  7307. });
  7308. d3_layout_hierarchyVisitAfter(root, function(node) {
  7309. var parent;
  7310. if (!node.children) node.value = +value.call(hierarchy, node, node.depth) || 0;
  7311. if (parent = node.parent) parent.value += node.value;
  7312. });
  7313. }
  7314. return root;
  7315. };
  7316. return hierarchy;
  7317. };
  7318. function d3_layout_hierarchyRebind(object, hierarchy) {
  7319. d3.rebind(object, hierarchy, "sort", "children", "value");
  7320. object.nodes = object;
  7321. object.links = d3_layout_hierarchyLinks;
  7322. return object;
  7323. }
  7324. function d3_layout_hierarchyVisitBefore(node, callback) {
  7325. var nodes = [ node ];
  7326. while ((node = nodes.pop()) != null) {
  7327. callback(node);
  7328. if ((children = node.children) && (n = children.length)) {
  7329. var n, children;
  7330. while (--n >= 0) nodes.push(children[n]);
  7331. }
  7332. }
  7333. }
  7334. function d3_layout_hierarchyVisitAfter(node, callback) {
  7335. var nodes = [ node ], nodes2 = [];
  7336. while ((node = nodes.pop()) != null) {
  7337. nodes2.push(node);
  7338. if ((children = node.children) && (n = children.length)) {
  7339. var i = -1, n, children;
  7340. while (++i < n) nodes.push(children[i]);
  7341. }
  7342. }
  7343. while ((node = nodes2.pop()) != null) {
  7344. callback(node);
  7345. }
  7346. }
  7347. function d3_layout_hierarchyChildren(d) {
  7348. return d.children;
  7349. }
  7350. function d3_layout_hierarchyValue(d) {
  7351. return d.value;
  7352. }
  7353. function d3_layout_hierarchySort(a, b) {
  7354. return b.value - a.value;
  7355. }
  7356. function d3_layout_hierarchyLinks(nodes) {
  7357. return d3.merge(nodes.map(function(parent) {
  7358. return (parent.children || []).map(function(child) {
  7359. return {
  7360. source: parent,
  7361. target: child
  7362. };
  7363. });
  7364. }));
  7365. }
  7366. d3.layout.partition = function() {
  7367. var hierarchy = d3.layout.hierarchy(), size = [ 1, 1 ];
  7368. function position(node, x, dx, dy) {
  7369. var children = node.children;
  7370. node.x = x;
  7371. node.y = node.depth * dy;
  7372. node.dx = dx;
  7373. node.dy = dy;
  7374. if (children && (n = children.length)) {
  7375. var i = -1, n, c, d;
  7376. dx = node.value ? dx / node.value : 0;
  7377. while (++i < n) {
  7378. position(c = children[i], x, d = c.value * dx, dy);
  7379. x += d;
  7380. }
  7381. }
  7382. }
  7383. function depth(node) {
  7384. var children = node.children, d = 0;
  7385. if (children && (n = children.length)) {
  7386. var i = -1, n;
  7387. while (++i < n) d = Math.max(d, depth(children[i]));
  7388. }
  7389. return 1 + d;
  7390. }
  7391. function partition(d, i) {
  7392. var nodes = hierarchy.call(this, d, i);
  7393. position(nodes[0], 0, size[0], size[1] / depth(nodes[0]));
  7394. return nodes;
  7395. }
  7396. partition.size = function(x) {
  7397. if (!arguments.length) return size;
  7398. size = x;
  7399. return partition;
  7400. };
  7401. return d3_layout_hierarchyRebind(partition, hierarchy);
  7402. };
  7403. d3.layout.pie = function() {
  7404. var value = Number, sort = d3_layout_pieSortByValue, startAngle = 0, endAngle = τ, padAngle = 0;
  7405. function pie(data) {
  7406. var n = data.length, values = data.map(function(d, i) {
  7407. return +value.call(pie, d, i);
  7408. }), a = +(typeof startAngle === "function" ? startAngle.apply(this, arguments) : startAngle), da = (typeof endAngle === "function" ? endAngle.apply(this, arguments) : endAngle) - a, p = Math.min(Math.abs(da) / n, +(typeof padAngle === "function" ? padAngle.apply(this, arguments) : padAngle)), pa = p * (da < 0 ? -1 : 1), sum = d3.sum(values), k = sum ? (da - n * pa) / sum : 0, index = d3.range(n), arcs = [], v;
  7409. if (sort != null) index.sort(sort === d3_layout_pieSortByValue ? function(i, j) {
  7410. return values[j] - values[i];
  7411. } : function(i, j) {
  7412. return sort(data[i], data[j]);
  7413. });
  7414. index.forEach(function(i) {
  7415. arcs[i] = {
  7416. data: data[i],
  7417. value: v = values[i],
  7418. startAngle: a,
  7419. endAngle: a += v * k + pa,
  7420. padAngle: p
  7421. };
  7422. });
  7423. return arcs;
  7424. }
  7425. pie.value = function(_) {
  7426. if (!arguments.length) return value;
  7427. value = _;
  7428. return pie;
  7429. };
  7430. pie.sort = function(_) {
  7431. if (!arguments.length) return sort;
  7432. sort = _;
  7433. return pie;
  7434. };
  7435. pie.startAngle = function(_) {
  7436. if (!arguments.length) return startAngle;
  7437. startAngle = _;
  7438. return pie;
  7439. };
  7440. pie.endAngle = function(_) {
  7441. if (!arguments.length) return endAngle;
  7442. endAngle = _;
  7443. return pie;
  7444. };
  7445. pie.padAngle = function(_) {
  7446. if (!arguments.length) return padAngle;
  7447. padAngle = _;
  7448. return pie;
  7449. };
  7450. return pie;
  7451. };
  7452. var d3_layout_pieSortByValue = {};
  7453. d3.layout.stack = function() {
  7454. var values = d3_identity, order = d3_layout_stackOrderDefault, offset = d3_layout_stackOffsetZero, out = d3_layout_stackOut, x = d3_layout_stackX, y = d3_layout_stackY;
  7455. function stack(data, index) {
  7456. if (!(n = data.length)) return data;
  7457. var series = data.map(function(d, i) {
  7458. return values.call(stack, d, i);
  7459. });
  7460. var points = series.map(function(d) {
  7461. return d.map(function(v, i) {
  7462. return [ x.call(stack, v, i), y.call(stack, v, i) ];
  7463. });
  7464. });
  7465. var orders = order.call(stack, points, index);
  7466. series = d3.permute(series, orders);
  7467. points = d3.permute(points, orders);
  7468. var offsets = offset.call(stack, points, index);
  7469. var m = series[0].length, n, i, j, o;
  7470. for (j = 0; j < m; ++j) {
  7471. out.call(stack, series[0][j], o = offsets[j], points[0][j][1]);
  7472. for (i = 1; i < n; ++i) {
  7473. out.call(stack, series[i][j], o += points[i - 1][j][1], points[i][j][1]);
  7474. }
  7475. }
  7476. return data;
  7477. }
  7478. stack.values = function(x) {
  7479. if (!arguments.length) return values;
  7480. values = x;
  7481. return stack;
  7482. };
  7483. stack.order = function(x) {
  7484. if (!arguments.length) return order;
  7485. order = typeof x === "function" ? x : d3_layout_stackOrders.get(x) || d3_layout_stackOrderDefault;
  7486. return stack;
  7487. };
  7488. stack.offset = function(x) {
  7489. if (!arguments.length) return offset;
  7490. offset = typeof x === "function" ? x : d3_layout_stackOffsets.get(x) || d3_layout_stackOffsetZero;
  7491. return stack;
  7492. };
  7493. stack.x = function(z) {
  7494. if (!arguments.length) return x;
  7495. x = z;
  7496. return stack;
  7497. };
  7498. stack.y = function(z) {
  7499. if (!arguments.length) return y;
  7500. y = z;
  7501. return stack;
  7502. };
  7503. stack.out = function(z) {
  7504. if (!arguments.length) return out;
  7505. out = z;
  7506. return stack;
  7507. };
  7508. return stack;
  7509. };
  7510. function d3_layout_stackX(d) {
  7511. return d.x;
  7512. }
  7513. function d3_layout_stackY(d) {
  7514. return d.y;
  7515. }
  7516. function d3_layout_stackOut(d, y0, y) {
  7517. d.y0 = y0;
  7518. d.y = y;
  7519. }
  7520. var d3_layout_stackOrders = d3.map({
  7521. "inside-out": function(data) {
  7522. var n = data.length, i, j, max = data.map(d3_layout_stackMaxIndex), sums = data.map(d3_layout_stackReduceSum), index = d3.range(n).sort(function(a, b) {
  7523. return max[a] - max[b];
  7524. }), top = 0, bottom = 0, tops = [], bottoms = [];
  7525. for (i = 0; i < n; ++i) {
  7526. j = index[i];
  7527. if (top < bottom) {
  7528. top += sums[j];
  7529. tops.push(j);
  7530. } else {
  7531. bottom += sums[j];
  7532. bottoms.push(j);
  7533. }
  7534. }
  7535. return bottoms.reverse().concat(tops);
  7536. },
  7537. reverse: function(data) {
  7538. return d3.range(data.length).reverse();
  7539. },
  7540. "default": d3_layout_stackOrderDefault
  7541. });
  7542. var d3_layout_stackOffsets = d3.map({
  7543. silhouette: function(data) {
  7544. var n = data.length, m = data[0].length, sums = [], max = 0, i, j, o, y0 = [];
  7545. for (j = 0; j < m; ++j) {
  7546. for (i = 0, o = 0; i < n; i++) o += data[i][j][1];
  7547. if (o > max) max = o;
  7548. sums.push(o);
  7549. }
  7550. for (j = 0; j < m; ++j) {
  7551. y0[j] = (max - sums[j]) / 2;
  7552. }
  7553. return y0;
  7554. },
  7555. wiggle: function(data) {
  7556. var n = data.length, x = data[0], m = x.length, i, j, k, s1, s2, s3, dx, o, o0, y0 = [];
  7557. y0[0] = o = o0 = 0;
  7558. for (j = 1; j < m; ++j) {
  7559. for (i = 0, s1 = 0; i < n; ++i) s1 += data[i][j][1];
  7560. for (i = 0, s2 = 0, dx = x[j][0] - x[j - 1][0]; i < n; ++i) {
  7561. for (k = 0, s3 = (data[i][j][1] - data[i][j - 1][1]) / (2 * dx); k < i; ++k) {
  7562. s3 += (data[k][j][1] - data[k][j - 1][1]) / dx;
  7563. }
  7564. s2 += s3 * data[i][j][1];
  7565. }
  7566. y0[j] = o -= s1 ? s2 / s1 * dx : 0;
  7567. if (o < o0) o0 = o;
  7568. }
  7569. for (j = 0; j < m; ++j) y0[j] -= o0;
  7570. return y0;
  7571. },
  7572. expand: function(data) {
  7573. var n = data.length, m = data[0].length, k = 1 / n, i, j, o, y0 = [];
  7574. for (j = 0; j < m; ++j) {
  7575. for (i = 0, o = 0; i < n; i++) o += data[i][j][1];
  7576. if (o) for (i = 0; i < n; i++) data[i][j][1] /= o; else for (i = 0; i < n; i++) data[i][j][1] = k;
  7577. }
  7578. for (j = 0; j < m; ++j) y0[j] = 0;
  7579. return y0;
  7580. },
  7581. zero: d3_layout_stackOffsetZero
  7582. });
  7583. function d3_layout_stackOrderDefault(data) {
  7584. return d3.range(data.length);
  7585. }
  7586. function d3_layout_stackOffsetZero(data) {
  7587. var j = -1, m = data[0].length, y0 = [];
  7588. while (++j < m) y0[j] = 0;
  7589. return y0;
  7590. }
  7591. function d3_layout_stackMaxIndex(array) {
  7592. var i = 1, j = 0, v = array[0][1], k, n = array.length;
  7593. for (;i < n; ++i) {
  7594. if ((k = array[i][1]) > v) {
  7595. j = i;
  7596. v = k;
  7597. }
  7598. }
  7599. return j;
  7600. }
  7601. function d3_layout_stackReduceSum(d) {
  7602. return d.reduce(d3_layout_stackSum, 0);
  7603. }
  7604. function d3_layout_stackSum(p, d) {
  7605. return p + d[1];
  7606. }
  7607. d3.layout.histogram = function() {
  7608. var frequency = true, valuer = Number, ranger = d3_layout_histogramRange, binner = d3_layout_histogramBinSturges;
  7609. function histogram(data, i) {
  7610. var bins = [], values = data.map(valuer, this), range = ranger.call(this, values, i), thresholds = binner.call(this, range, values, i), bin, i = -1, n = values.length, m = thresholds.length - 1, k = frequency ? 1 : 1 / n, x;
  7611. while (++i < m) {
  7612. bin = bins[i] = [];
  7613. bin.dx = thresholds[i + 1] - (bin.x = thresholds[i]);
  7614. bin.y = 0;
  7615. }
  7616. if (m > 0) {
  7617. i = -1;
  7618. while (++i < n) {
  7619. x = values[i];
  7620. if (x >= range[0] && x <= range[1]) {
  7621. bin = bins[d3.bisect(thresholds, x, 1, m) - 1];
  7622. bin.y += k;
  7623. bin.push(data[i]);
  7624. }
  7625. }
  7626. }
  7627. return bins;
  7628. }
  7629. histogram.value = function(x) {
  7630. if (!arguments.length) return valuer;
  7631. valuer = x;
  7632. return histogram;
  7633. };
  7634. histogram.range = function(x) {
  7635. if (!arguments.length) return ranger;
  7636. ranger = d3_functor(x);
  7637. return histogram;
  7638. };
  7639. histogram.bins = function(x) {
  7640. if (!arguments.length) return binner;
  7641. binner = typeof x === "number" ? function(range) {
  7642. return d3_layout_histogramBinFixed(range, x);
  7643. } : d3_functor(x);
  7644. return histogram;
  7645. };
  7646. histogram.frequency = function(x) {
  7647. if (!arguments.length) return frequency;
  7648. frequency = !!x;
  7649. return histogram;
  7650. };
  7651. return histogram;
  7652. };
  7653. function d3_layout_histogramBinSturges(range, values) {
  7654. return d3_layout_histogramBinFixed(range, Math.ceil(Math.log(values.length) / Math.LN2 + 1));
  7655. }
  7656. function d3_layout_histogramBinFixed(range, n) {
  7657. var x = -1, b = +range[0], m = (range[1] - b) / n, f = [];
  7658. while (++x <= n) f[x] = m * x + b;
  7659. return f;
  7660. }
  7661. function d3_layout_histogramRange(values) {
  7662. return [ d3.min(values), d3.max(values) ];
  7663. }
  7664. d3.layout.pack = function() {
  7665. var hierarchy = d3.layout.hierarchy().sort(d3_layout_packSort), padding = 0, size = [ 1, 1 ], radius;
  7666. function pack(d, i) {
  7667. var nodes = hierarchy.call(this, d, i), root = nodes[0], w = size[0], h = size[1], r = radius == null ? Math.sqrt : typeof radius === "function" ? radius : function() {
  7668. return radius;
  7669. };
  7670. root.x = root.y = 0;
  7671. d3_layout_hierarchyVisitAfter(root, function(d) {
  7672. d.r = +r(d.value);
  7673. });
  7674. d3_layout_hierarchyVisitAfter(root, d3_layout_packSiblings);
  7675. if (padding) {
  7676. var dr = padding * (radius ? 1 : Math.max(2 * root.r / w, 2 * root.r / h)) / 2;
  7677. d3_layout_hierarchyVisitAfter(root, function(d) {
  7678. d.r += dr;
  7679. });
  7680. d3_layout_hierarchyVisitAfter(root, d3_layout_packSiblings);
  7681. d3_layout_hierarchyVisitAfter(root, function(d) {
  7682. d.r -= dr;
  7683. });
  7684. }
  7685. d3_layout_packTransform(root, w / 2, h / 2, radius ? 1 : 1 / Math.max(2 * root.r / w, 2 * root.r / h));
  7686. return nodes;
  7687. }
  7688. pack.size = function(_) {
  7689. if (!arguments.length) return size;
  7690. size = _;
  7691. return pack;
  7692. };
  7693. pack.radius = function(_) {
  7694. if (!arguments.length) return radius;
  7695. radius = _ == null || typeof _ === "function" ? _ : +_;
  7696. return pack;
  7697. };
  7698. pack.padding = function(_) {
  7699. if (!arguments.length) return padding;
  7700. padding = +_;
  7701. return pack;
  7702. };
  7703. return d3_layout_hierarchyRebind(pack, hierarchy);
  7704. };
  7705. function d3_layout_packSort(a, b) {
  7706. return a.value - b.value;
  7707. }
  7708. function d3_layout_packInsert(a, b) {
  7709. var c = a._pack_next;
  7710. a._pack_next = b;
  7711. b._pack_prev = a;
  7712. b._pack_next = c;
  7713. c._pack_prev = b;
  7714. }
  7715. function d3_layout_packSplice(a, b) {
  7716. a._pack_next = b;
  7717. b._pack_prev = a;
  7718. }
  7719. function d3_layout_packIntersects(a, b) {
  7720. var dx = b.x - a.x, dy = b.y - a.y, dr = a.r + b.r;
  7721. return .999 * dr * dr > dx * dx + dy * dy;
  7722. }
  7723. function d3_layout_packSiblings(node) {
  7724. if (!(nodes = node.children) || !(n = nodes.length)) return;
  7725. var nodes, xMin = Infinity, xMax = -Infinity, yMin = Infinity, yMax = -Infinity, a, b, c, i, j, k, n;
  7726. function bound(node) {
  7727. xMin = Math.min(node.x - node.r, xMin);
  7728. xMax = Math.max(node.x + node.r, xMax);
  7729. yMin = Math.min(node.y - node.r, yMin);
  7730. yMax = Math.max(node.y + node.r, yMax);
  7731. }
  7732. nodes.forEach(d3_layout_packLink);
  7733. a = nodes[0];
  7734. a.x = -a.r;
  7735. a.y = 0;
  7736. bound(a);
  7737. if (n > 1) {
  7738. b = nodes[1];
  7739. b.x = b.r;
  7740. b.y = 0;
  7741. bound(b);
  7742. if (n > 2) {
  7743. c = nodes[2];
  7744. d3_layout_packPlace(a, b, c);
  7745. bound(c);
  7746. d3_layout_packInsert(a, c);
  7747. a._pack_prev = c;
  7748. d3_layout_packInsert(c, b);
  7749. b = a._pack_next;
  7750. for (i = 3; i < n; i++) {
  7751. d3_layout_packPlace(a, b, c = nodes[i]);
  7752. var isect = 0, s1 = 1, s2 = 1;
  7753. for (j = b._pack_next; j !== b; j = j._pack_next, s1++) {
  7754. if (d3_layout_packIntersects(j, c)) {
  7755. isect = 1;
  7756. break;
  7757. }
  7758. }
  7759. if (isect == 1) {
  7760. for (k = a._pack_prev; k !== j._pack_prev; k = k._pack_prev, s2++) {
  7761. if (d3_layout_packIntersects(k, c)) {
  7762. break;
  7763. }
  7764. }
  7765. }
  7766. if (isect) {
  7767. if (s1 < s2 || s1 == s2 && b.r < a.r) d3_layout_packSplice(a, b = j); else d3_layout_packSplice(a = k, b);
  7768. i--;
  7769. } else {
  7770. d3_layout_packInsert(a, c);
  7771. b = c;
  7772. bound(c);
  7773. }
  7774. }
  7775. }
  7776. }
  7777. var cx = (xMin + xMax) / 2, cy = (yMin + yMax) / 2, cr = 0;
  7778. for (i = 0; i < n; i++) {
  7779. c = nodes[i];
  7780. c.x -= cx;
  7781. c.y -= cy;
  7782. cr = Math.max(cr, c.r + Math.sqrt(c.x * c.x + c.y * c.y));
  7783. }
  7784. node.r = cr;
  7785. nodes.forEach(d3_layout_packUnlink);
  7786. }
  7787. function d3_layout_packLink(node) {
  7788. node._pack_next = node._pack_prev = node;
  7789. }
  7790. function d3_layout_packUnlink(node) {
  7791. delete node._pack_next;
  7792. delete node._pack_prev;
  7793. }
  7794. function d3_layout_packTransform(node, x, y, k) {
  7795. var children = node.children;
  7796. node.x = x += k * node.x;
  7797. node.y = y += k * node.y;
  7798. node.r *= k;
  7799. if (children) {
  7800. var i = -1, n = children.length;
  7801. while (++i < n) d3_layout_packTransform(children[i], x, y, k);
  7802. }
  7803. }
  7804. function d3_layout_packPlace(a, b, c) {
  7805. var db = a.r + c.r, dx = b.x - a.x, dy = b.y - a.y;
  7806. if (db && (dx || dy)) {
  7807. var da = b.r + c.r, dc = dx * dx + dy * dy;
  7808. da *= da;
  7809. db *= db;
  7810. var x = .5 + (db - da) / (2 * dc), y = Math.sqrt(Math.max(0, 2 * da * (db + dc) - (db -= dc) * db - da * da)) / (2 * dc);
  7811. c.x = a.x + x * dx + y * dy;
  7812. c.y = a.y + x * dy - y * dx;
  7813. } else {
  7814. c.x = a.x + db;
  7815. c.y = a.y;
  7816. }
  7817. }
  7818. d3.layout.tree = function() {
  7819. var hierarchy = d3.layout.hierarchy().sort(null).value(null), separation = d3_layout_treeSeparation, size = [ 1, 1 ], nodeSize = null;
  7820. function tree(d, i) {
  7821. var nodes = hierarchy.call(this, d, i), root0 = nodes[0], root1 = wrapTree(root0);
  7822. d3_layout_hierarchyVisitAfter(root1, firstWalk), root1.parent.m = -root1.z;
  7823. d3_layout_hierarchyVisitBefore(root1, secondWalk);
  7824. if (nodeSize) d3_layout_hierarchyVisitBefore(root0, sizeNode); else {
  7825. var left = root0, right = root0, bottom = root0;
  7826. d3_layout_hierarchyVisitBefore(root0, function(node) {
  7827. if (node.x < left.x) left = node;
  7828. if (node.x > right.x) right = node;
  7829. if (node.depth > bottom.depth) bottom = node;
  7830. });
  7831. var tx = separation(left, right) / 2 - left.x, kx = size[0] / (right.x + separation(right, left) / 2 + tx), ky = size[1] / (bottom.depth || 1);
  7832. d3_layout_hierarchyVisitBefore(root0, function(node) {
  7833. node.x = (node.x + tx) * kx;
  7834. node.y = node.depth * ky;
  7835. });
  7836. }
  7837. return nodes;
  7838. }
  7839. function wrapTree(root0) {
  7840. var root1 = {
  7841. A: null,
  7842. children: [ root0 ]
  7843. }, queue = [ root1 ], node1;
  7844. while ((node1 = queue.pop()) != null) {
  7845. for (var children = node1.children, child, i = 0, n = children.length; i < n; ++i) {
  7846. queue.push((children[i] = child = {
  7847. _: children[i],
  7848. parent: node1,
  7849. children: (child = children[i].children) && child.slice() || [],
  7850. A: null,
  7851. a: null,
  7852. z: 0,
  7853. m: 0,
  7854. c: 0,
  7855. s: 0,
  7856. t: null,
  7857. i: i
  7858. }).a = child);
  7859. }
  7860. }
  7861. return root1.children[0];
  7862. }
  7863. function firstWalk(v) {
  7864. var children = v.children, siblings = v.parent.children, w = v.i ? siblings[v.i - 1] : null;
  7865. if (children.length) {
  7866. d3_layout_treeShift(v);
  7867. var midpoint = (children[0].z + children[children.length - 1].z) / 2;
  7868. if (w) {
  7869. v.z = w.z + separation(v._, w._);
  7870. v.m = v.z - midpoint;
  7871. } else {
  7872. v.z = midpoint;
  7873. }
  7874. } else if (w) {
  7875. v.z = w.z + separation(v._, w._);
  7876. }
  7877. v.parent.A = apportion(v, w, v.parent.A || siblings[0]);
  7878. }
  7879. function secondWalk(v) {
  7880. v._.x = v.z + v.parent.m;
  7881. v.m += v.parent.m;
  7882. }
  7883. function apportion(v, w, ancestor) {
  7884. if (w) {
  7885. var vip = v, vop = v, vim = w, vom = vip.parent.children[0], sip = vip.m, sop = vop.m, sim = vim.m, som = vom.m, shift;
  7886. while (vim = d3_layout_treeRight(vim), vip = d3_layout_treeLeft(vip), vim && vip) {
  7887. vom = d3_layout_treeLeft(vom);
  7888. vop = d3_layout_treeRight(vop);
  7889. vop.a = v;
  7890. shift = vim.z + sim - vip.z - sip + separation(vim._, vip._);
  7891. if (shift > 0) {
  7892. d3_layout_treeMove(d3_layout_treeAncestor(vim, v, ancestor), v, shift);
  7893. sip += shift;
  7894. sop += shift;
  7895. }
  7896. sim += vim.m;
  7897. sip += vip.m;
  7898. som += vom.m;
  7899. sop += vop.m;
  7900. }
  7901. if (vim && !d3_layout_treeRight(vop)) {
  7902. vop.t = vim;
  7903. vop.m += sim - sop;
  7904. }
  7905. if (vip && !d3_layout_treeLeft(vom)) {
  7906. vom.t = vip;
  7907. vom.m += sip - som;
  7908. ancestor = v;
  7909. }
  7910. }
  7911. return ancestor;
  7912. }
  7913. function sizeNode(node) {
  7914. node.x *= size[0];
  7915. node.y = node.depth * size[1];
  7916. }
  7917. tree.separation = function(x) {
  7918. if (!arguments.length) return separation;
  7919. separation = x;
  7920. return tree;
  7921. };
  7922. tree.size = function(x) {
  7923. if (!arguments.length) return nodeSize ? null : size;
  7924. nodeSize = (size = x) == null ? sizeNode : null;
  7925. return tree;
  7926. };
  7927. tree.nodeSize = function(x) {
  7928. if (!arguments.length) return nodeSize ? size : null;
  7929. nodeSize = (size = x) == null ? null : sizeNode;
  7930. return tree;
  7931. };
  7932. return d3_layout_hierarchyRebind(tree, hierarchy);
  7933. };
  7934. function d3_layout_treeSeparation(a, b) {
  7935. return a.parent == b.parent ? 1 : 2;
  7936. }
  7937. function d3_layout_treeLeft(v) {
  7938. var children = v.children;
  7939. return children.length ? children[0] : v.t;
  7940. }
  7941. function d3_layout_treeRight(v) {
  7942. var children = v.children, n;
  7943. return (n = children.length) ? children[n - 1] : v.t;
  7944. }
  7945. function d3_layout_treeMove(wm, wp, shift) {
  7946. var change = shift / (wp.i - wm.i);
  7947. wp.c -= change;
  7948. wp.s += shift;
  7949. wm.c += change;
  7950. wp.z += shift;
  7951. wp.m += shift;
  7952. }
  7953. function d3_layout_treeShift(v) {
  7954. var shift = 0, change = 0, children = v.children, i = children.length, w;
  7955. while (--i >= 0) {
  7956. w = children[i];
  7957. w.z += shift;
  7958. w.m += shift;
  7959. shift += w.s + (change += w.c);
  7960. }
  7961. }
  7962. function d3_layout_treeAncestor(vim, v, ancestor) {
  7963. return vim.a.parent === v.parent ? vim.a : ancestor;
  7964. }
  7965. d3.layout.cluster = function() {
  7966. var hierarchy = d3.layout.hierarchy().sort(null).value(null), separation = d3_layout_treeSeparation, size = [ 1, 1 ], nodeSize = false;
  7967. function cluster(d, i) {
  7968. var nodes = hierarchy.call(this, d, i), root = nodes[0], previousNode, x = 0;
  7969. d3_layout_hierarchyVisitAfter(root, function(node) {
  7970. var children = node.children;
  7971. if (children && children.length) {
  7972. node.x = d3_layout_clusterX(children);
  7973. node.y = d3_layout_clusterY(children);
  7974. } else {
  7975. node.x = previousNode ? x += separation(node, previousNode) : 0;
  7976. node.y = 0;
  7977. previousNode = node;
  7978. }
  7979. });
  7980. var left = d3_layout_clusterLeft(root), right = d3_layout_clusterRight(root), x0 = left.x - separation(left, right) / 2, x1 = right.x + separation(right, left) / 2;
  7981. d3_layout_hierarchyVisitAfter(root, nodeSize ? function(node) {
  7982. node.x = (node.x - root.x) * size[0];
  7983. node.y = (root.y - node.y) * size[1];
  7984. } : function(node) {
  7985. node.x = (node.x - x0) / (x1 - x0) * size[0];
  7986. node.y = (1 - (root.y ? node.y / root.y : 1)) * size[1];
  7987. });
  7988. return nodes;
  7989. }
  7990. cluster.separation = function(x) {
  7991. if (!arguments.length) return separation;
  7992. separation = x;
  7993. return cluster;
  7994. };
  7995. cluster.size = function(x) {
  7996. if (!arguments.length) return nodeSize ? null : size;
  7997. nodeSize = (size = x) == null;
  7998. return cluster;
  7999. };
  8000. cluster.nodeSize = function(x) {
  8001. if (!arguments.length) return nodeSize ? size : null;
  8002. nodeSize = (size = x) != null;
  8003. return cluster;
  8004. };
  8005. return d3_layout_hierarchyRebind(cluster, hierarchy);
  8006. };
  8007. function d3_layout_clusterY(children) {
  8008. return 1 + d3.max(children, function(child) {
  8009. return child.y;
  8010. });
  8011. }
  8012. function d3_layout_clusterX(children) {
  8013. return children.reduce(function(x, child) {
  8014. return x + child.x;
  8015. }, 0) / children.length;
  8016. }
  8017. function d3_layout_clusterLeft(node) {
  8018. var children = node.children;
  8019. return children && children.length ? d3_layout_clusterLeft(children[0]) : node;
  8020. }
  8021. function d3_layout_clusterRight(node) {
  8022. var children = node.children, n;
  8023. return children && (n = children.length) ? d3_layout_clusterRight(children[n - 1]) : node;
  8024. }
  8025. d3.layout.treemap = function() {
  8026. var hierarchy = d3.layout.hierarchy(), round = Math.round, size = [ 1, 1 ], padding = null, pad = d3_layout_treemapPadNull, sticky = false, stickies, mode = "squarify", ratio = .5 * (1 + Math.sqrt(5));
  8027. function scale(children, k) {
  8028. var i = -1, n = children.length, child, area;
  8029. while (++i < n) {
  8030. area = (child = children[i]).value * (k < 0 ? 0 : k);
  8031. child.area = isNaN(area) || area <= 0 ? 0 : area;
  8032. }
  8033. }
  8034. function squarify(node) {
  8035. var children = node.children;
  8036. if (children && children.length) {
  8037. var rect = pad(node), row = [], remaining = children.slice(), child, best = Infinity, score, u = mode === "slice" ? rect.dx : mode === "dice" ? rect.dy : mode === "slice-dice" ? node.depth & 1 ? rect.dy : rect.dx : Math.min(rect.dx, rect.dy), n;
  8038. scale(remaining, rect.dx * rect.dy / node.value);
  8039. row.area = 0;
  8040. while ((n = remaining.length) > 0) {
  8041. row.push(child = remaining[n - 1]);
  8042. row.area += child.area;
  8043. if (mode !== "squarify" || (score = worst(row, u)) <= best) {
  8044. remaining.pop();
  8045. best = score;
  8046. } else {
  8047. row.area -= row.pop().area;
  8048. position(row, u, rect, false);
  8049. u = Math.min(rect.dx, rect.dy);
  8050. row.length = row.area = 0;
  8051. best = Infinity;
  8052. }
  8053. }
  8054. if (row.length) {
  8055. position(row, u, rect, true);
  8056. row.length = row.area = 0;
  8057. }
  8058. children.forEach(squarify);
  8059. }
  8060. }
  8061. function stickify(node) {
  8062. var children = node.children;
  8063. if (children && children.length) {
  8064. var rect = pad(node), remaining = children.slice(), child, row = [];
  8065. scale(remaining, rect.dx * rect.dy / node.value);
  8066. row.area = 0;
  8067. while (child = remaining.pop()) {
  8068. row.push(child);
  8069. row.area += child.area;
  8070. if (child.z != null) {
  8071. position(row, child.z ? rect.dx : rect.dy, rect, !remaining.length);
  8072. row.length = row.area = 0;
  8073. }
  8074. }
  8075. children.forEach(stickify);
  8076. }
  8077. }
  8078. function worst(row, u) {
  8079. var s = row.area, r, rmax = 0, rmin = Infinity, i = -1, n = row.length;
  8080. while (++i < n) {
  8081. if (!(r = row[i].area)) continue;
  8082. if (r < rmin) rmin = r;
  8083. if (r > rmax) rmax = r;
  8084. }
  8085. s *= s;
  8086. u *= u;
  8087. return s ? Math.max(u * rmax * ratio / s, s / (u * rmin * ratio)) : Infinity;
  8088. }
  8089. function position(row, u, rect, flush) {
  8090. var i = -1, n = row.length, x = rect.x, y = rect.y, v = u ? round(row.area / u) : 0, o;
  8091. if (u == rect.dx) {
  8092. if (flush || v > rect.dy) v = rect.dy;
  8093. while (++i < n) {
  8094. o = row[i];
  8095. o.x = x;
  8096. o.y = y;
  8097. o.dy = v;
  8098. x += o.dx = Math.min(rect.x + rect.dx - x, v ? round(o.area / v) : 0);
  8099. }
  8100. o.z = true;
  8101. o.dx += rect.x + rect.dx - x;
  8102. rect.y += v;
  8103. rect.dy -= v;
  8104. } else {
  8105. if (flush || v > rect.dx) v = rect.dx;
  8106. while (++i < n) {
  8107. o = row[i];
  8108. o.x = x;
  8109. o.y = y;
  8110. o.dx = v;
  8111. y += o.dy = Math.min(rect.y + rect.dy - y, v ? round(o.area / v) : 0);
  8112. }
  8113. o.z = false;
  8114. o.dy += rect.y + rect.dy - y;
  8115. rect.x += v;
  8116. rect.dx -= v;
  8117. }
  8118. }
  8119. function treemap(d) {
  8120. var nodes = stickies || hierarchy(d), root = nodes[0];
  8121. root.x = root.y = 0;
  8122. if (root.value) root.dx = size[0], root.dy = size[1]; else root.dx = root.dy = 0;
  8123. if (stickies) hierarchy.revalue(root);
  8124. scale([ root ], root.dx * root.dy / root.value);
  8125. (stickies ? stickify : squarify)(root);
  8126. if (sticky) stickies = nodes;
  8127. return nodes;
  8128. }
  8129. treemap.size = function(x) {
  8130. if (!arguments.length) return size;
  8131. size = x;
  8132. return treemap;
  8133. };
  8134. treemap.padding = function(x) {
  8135. if (!arguments.length) return padding;
  8136. function padFunction(node) {
  8137. var p = x.call(treemap, node, node.depth);
  8138. return p == null ? d3_layout_treemapPadNull(node) : d3_layout_treemapPad(node, typeof p === "number" ? [ p, p, p, p ] : p);
  8139. }
  8140. function padConstant(node) {
  8141. return d3_layout_treemapPad(node, x);
  8142. }
  8143. var type;
  8144. pad = (padding = x) == null ? d3_layout_treemapPadNull : (type = typeof x) === "function" ? padFunction : type === "number" ? (x = [ x, x, x, x ],
  8145. padConstant) : padConstant;
  8146. return treemap;
  8147. };
  8148. treemap.round = function(x) {
  8149. if (!arguments.length) return round != Number;
  8150. round = x ? Math.round : Number;
  8151. return treemap;
  8152. };
  8153. treemap.sticky = function(x) {
  8154. if (!arguments.length) return sticky;
  8155. sticky = x;
  8156. stickies = null;
  8157. return treemap;
  8158. };
  8159. treemap.ratio = function(x) {
  8160. if (!arguments.length) return ratio;
  8161. ratio = x;
  8162. return treemap;
  8163. };
  8164. treemap.mode = function(x) {
  8165. if (!arguments.length) return mode;
  8166. mode = x + "";
  8167. return treemap;
  8168. };
  8169. return d3_layout_hierarchyRebind(treemap, hierarchy);
  8170. };
  8171. function d3_layout_treemapPadNull(node) {
  8172. return {
  8173. x: node.x,
  8174. y: node.y,
  8175. dx: node.dx,
  8176. dy: node.dy
  8177. };
  8178. }
  8179. function d3_layout_treemapPad(node, padding) {
  8180. var x = node.x + padding[3], y = node.y + padding[0], dx = node.dx - padding[1] - padding[3], dy = node.dy - padding[0] - padding[2];
  8181. if (dx < 0) {
  8182. x += dx / 2;
  8183. dx = 0;
  8184. }
  8185. if (dy < 0) {
  8186. y += dy / 2;
  8187. dy = 0;
  8188. }
  8189. return {
  8190. x: x,
  8191. y: y,
  8192. dx: dx,
  8193. dy: dy
  8194. };
  8195. }
  8196. d3.random = {
  8197. normal: function(µ, σ) {
  8198. var n = arguments.length;
  8199. if (n < 2) σ = 1;
  8200. if (n < 1) µ = 0;
  8201. return function() {
  8202. var x, y, r;
  8203. do {
  8204. x = Math.random() * 2 - 1;
  8205. y = Math.random() * 2 - 1;
  8206. r = x * x + y * y;
  8207. } while (!r || r > 1);
  8208. return µ + σ * x * Math.sqrt(-2 * Math.log(r) / r);
  8209. };
  8210. },
  8211. logNormal: function() {
  8212. var random = d3.random.normal.apply(d3, arguments);
  8213. return function() {
  8214. return Math.exp(random());
  8215. };
  8216. },
  8217. bates: function(m) {
  8218. var random = d3.random.irwinHall(m);
  8219. return function() {
  8220. return random() / m;
  8221. };
  8222. },
  8223. irwinHall: function(m) {
  8224. return function() {
  8225. for (var s = 0, j = 0; j < m; j++) s += Math.random();
  8226. return s;
  8227. };
  8228. }
  8229. };
  8230. d3.scale = {};
  8231. function d3_scaleExtent(domain) {
  8232. var start = domain[0], stop = domain[domain.length - 1];
  8233. return start < stop ? [ start, stop ] : [ stop, start ];
  8234. }
  8235. function d3_scaleRange(scale) {
  8236. return scale.rangeExtent ? scale.rangeExtent() : d3_scaleExtent(scale.range());
  8237. }
  8238. function d3_scale_bilinear(domain, range, uninterpolate, interpolate) {
  8239. var u = uninterpolate(domain[0], domain[1]), i = interpolate(range[0], range[1]);
  8240. return function(x) {
  8241. return i(u(x));
  8242. };
  8243. }
  8244. function d3_scale_nice(domain, nice) {
  8245. var i0 = 0, i1 = domain.length - 1, x0 = domain[i0], x1 = domain[i1], dx;
  8246. if (x1 < x0) {
  8247. dx = i0, i0 = i1, i1 = dx;
  8248. dx = x0, x0 = x1, x1 = dx;
  8249. }
  8250. domain[i0] = nice.floor(x0);
  8251. domain[i1] = nice.ceil(x1);
  8252. return domain;
  8253. }
  8254. function d3_scale_niceStep(step) {
  8255. return step ? {
  8256. floor: function(x) {
  8257. return Math.floor(x / step) * step;
  8258. },
  8259. ceil: function(x) {
  8260. return Math.ceil(x / step) * step;
  8261. }
  8262. } : d3_scale_niceIdentity;
  8263. }
  8264. var d3_scale_niceIdentity = {
  8265. floor: d3_identity,
  8266. ceil: d3_identity
  8267. };
  8268. function d3_scale_polylinear(domain, range, uninterpolate, interpolate) {
  8269. var u = [], i = [], j = 0, k = Math.min(domain.length, range.length) - 1;
  8270. if (domain[k] < domain[0]) {
  8271. domain = domain.slice().reverse();
  8272. range = range.slice().reverse();
  8273. }
  8274. while (++j <= k) {
  8275. u.push(uninterpolate(domain[j - 1], domain[j]));
  8276. i.push(interpolate(range[j - 1], range[j]));
  8277. }
  8278. return function(x) {
  8279. var j = d3.bisect(domain, x, 1, k) - 1;
  8280. return i[j](u[j](x));
  8281. };
  8282. }
  8283. d3.scale.linear = function() {
  8284. return d3_scale_linear([ 0, 1 ], [ 0, 1 ], d3_interpolate, false);
  8285. };
  8286. function d3_scale_linear(domain, range, interpolate, clamp) {
  8287. var output, input;
  8288. function rescale() {
  8289. var linear = Math.min(domain.length, range.length) > 2 ? d3_scale_polylinear : d3_scale_bilinear, uninterpolate = clamp ? d3_uninterpolateClamp : d3_uninterpolateNumber;
  8290. output = linear(domain, range, uninterpolate, interpolate);
  8291. input = linear(range, domain, uninterpolate, d3_interpolate);
  8292. return scale;
  8293. }
  8294. function scale(x) {
  8295. return output(x);
  8296. }
  8297. scale.invert = function(y) {
  8298. return input(y);
  8299. };
  8300. scale.domain = function(x) {
  8301. if (!arguments.length) return domain;
  8302. domain = x.map(Number);
  8303. return rescale();
  8304. };
  8305. scale.range = function(x) {
  8306. if (!arguments.length) return range;
  8307. range = x;
  8308. return rescale();
  8309. };
  8310. scale.rangeRound = function(x) {
  8311. return scale.range(x).interpolate(d3_interpolateRound);
  8312. };
  8313. scale.clamp = function(x) {
  8314. if (!arguments.length) return clamp;
  8315. clamp = x;
  8316. return rescale();
  8317. };
  8318. scale.interpolate = function(x) {
  8319. if (!arguments.length) return interpolate;
  8320. interpolate = x;
  8321. return rescale();
  8322. };
  8323. scale.ticks = function(m) {
  8324. return d3_scale_linearTicks(domain, m);
  8325. };
  8326. scale.tickFormat = function(m, format) {
  8327. return d3_scale_linearTickFormat(domain, m, format);
  8328. };
  8329. scale.nice = function(m) {
  8330. d3_scale_linearNice(domain, m);
  8331. return rescale();
  8332. };
  8333. scale.copy = function() {
  8334. return d3_scale_linear(domain, range, interpolate, clamp);
  8335. };
  8336. return rescale();
  8337. }
  8338. function d3_scale_linearRebind(scale, linear) {
  8339. return d3.rebind(scale, linear, "range", "rangeRound", "interpolate", "clamp");
  8340. }
  8341. function d3_scale_linearNice(domain, m) {
  8342. d3_scale_nice(domain, d3_scale_niceStep(d3_scale_linearTickRange(domain, m)[2]));
  8343. d3_scale_nice(domain, d3_scale_niceStep(d3_scale_linearTickRange(domain, m)[2]));
  8344. return domain;
  8345. }
  8346. function d3_scale_linearTickRange(domain, m) {
  8347. if (m == null) m = 10;
  8348. var extent = d3_scaleExtent(domain), span = extent[1] - extent[0], step = Math.pow(10, Math.floor(Math.log(span / m) / Math.LN10)), err = m / span * step;
  8349. if (err <= .15) step *= 10; else if (err <= .35) step *= 5; else if (err <= .75) step *= 2;
  8350. extent[0] = Math.ceil(extent[0] / step) * step;
  8351. extent[1] = Math.floor(extent[1] / step) * step + step * .5;
  8352. extent[2] = step;
  8353. return extent;
  8354. }
  8355. function d3_scale_linearTicks(domain, m) {
  8356. return d3.range.apply(d3, d3_scale_linearTickRange(domain, m));
  8357. }
  8358. function d3_scale_linearTickFormat(domain, m, format) {
  8359. var range = d3_scale_linearTickRange(domain, m);
  8360. if (format) {
  8361. var match = d3_format_re.exec(format);
  8362. match.shift();
  8363. if (match[8] === "s") {
  8364. var prefix = d3.formatPrefix(Math.max(abs(range[0]), abs(range[1])));
  8365. if (!match[7]) match[7] = "." + d3_scale_linearPrecision(prefix.scale(range[2]));
  8366. match[8] = "f";
  8367. format = d3.format(match.join(""));
  8368. return function(d) {
  8369. return format(prefix.scale(d)) + prefix.symbol;
  8370. };
  8371. }
  8372. if (!match[7]) match[7] = "." + d3_scale_linearFormatPrecision(match[8], range);
  8373. format = match.join("");
  8374. } else {
  8375. format = ",." + d3_scale_linearPrecision(range[2]) + "f";
  8376. }
  8377. return d3.format(format);
  8378. }
  8379. var d3_scale_linearFormatSignificant = {
  8380. s: 1,
  8381. g: 1,
  8382. p: 1,
  8383. r: 1,
  8384. e: 1
  8385. };
  8386. function d3_scale_linearPrecision(value) {
  8387. return -Math.floor(Math.log(value) / Math.LN10 + .01);
  8388. }
  8389. function d3_scale_linearFormatPrecision(type, range) {
  8390. var p = d3_scale_linearPrecision(range[2]);
  8391. return type in d3_scale_linearFormatSignificant ? Math.abs(p - d3_scale_linearPrecision(Math.max(abs(range[0]), abs(range[1])))) + +(type !== "e") : p - (type === "%") * 2;
  8392. }
  8393. d3.scale.log = function() {
  8394. return d3_scale_log(d3.scale.linear().domain([ 0, 1 ]), 10, true, [ 1, 10 ]);
  8395. };
  8396. function d3_scale_log(linear, base, positive, domain) {
  8397. function log(x) {
  8398. return (positive ? Math.log(x < 0 ? 0 : x) : -Math.log(x > 0 ? 0 : -x)) / Math.log(base);
  8399. }
  8400. function pow(x) {
  8401. return positive ? Math.pow(base, x) : -Math.pow(base, -x);
  8402. }
  8403. function scale(x) {
  8404. return linear(log(x));
  8405. }
  8406. scale.invert = function(x) {
  8407. return pow(linear.invert(x));
  8408. };
  8409. scale.domain = function(x) {
  8410. if (!arguments.length) return domain;
  8411. positive = x[0] >= 0;
  8412. linear.domain((domain = x.map(Number)).map(log));
  8413. return scale;
  8414. };
  8415. scale.base = function(_) {
  8416. if (!arguments.length) return base;
  8417. base = +_;
  8418. linear.domain(domain.map(log));
  8419. return scale;
  8420. };
  8421. scale.nice = function() {
  8422. var niced = d3_scale_nice(domain.map(log), positive ? Math : d3_scale_logNiceNegative);
  8423. linear.domain(niced);
  8424. domain = niced.map(pow);
  8425. return scale;
  8426. };
  8427. scale.ticks = function() {
  8428. var extent = d3_scaleExtent(domain), ticks = [], u = extent[0], v = extent[1], i = Math.floor(log(u)), j = Math.ceil(log(v)), n = base % 1 ? 2 : base;
  8429. if (isFinite(j - i)) {
  8430. if (positive) {
  8431. for (;i < j; i++) for (var k = 1; k < n; k++) ticks.push(pow(i) * k);
  8432. ticks.push(pow(i));
  8433. } else {
  8434. ticks.push(pow(i));
  8435. for (;i++ < j; ) for (var k = n - 1; k > 0; k--) ticks.push(pow(i) * k);
  8436. }
  8437. for (i = 0; ticks[i] < u; i++) {}
  8438. for (j = ticks.length; ticks[j - 1] > v; j--) {}
  8439. ticks = ticks.slice(i, j);
  8440. }
  8441. return ticks;
  8442. };
  8443. scale.tickFormat = function(n, format) {
  8444. if (!arguments.length) return d3_scale_logFormat;
  8445. if (arguments.length < 2) format = d3_scale_logFormat; else if (typeof format !== "function") format = d3.format(format);
  8446. var k = Math.max(1, base * n / scale.ticks().length);
  8447. return function(d) {
  8448. var i = d / pow(Math.round(log(d)));
  8449. if (i * base < base - .5) i *= base;
  8450. return i <= k ? format(d) : "";
  8451. };
  8452. };
  8453. scale.copy = function() {
  8454. return d3_scale_log(linear.copy(), base, positive, domain);
  8455. };
  8456. return d3_scale_linearRebind(scale, linear);
  8457. }
  8458. var d3_scale_logFormat = d3.format(".0e"), d3_scale_logNiceNegative = {
  8459. floor: function(x) {
  8460. return -Math.ceil(-x);
  8461. },
  8462. ceil: function(x) {
  8463. return -Math.floor(-x);
  8464. }
  8465. };
  8466. d3.scale.pow = function() {
  8467. return d3_scale_pow(d3.scale.linear(), 1, [ 0, 1 ]);
  8468. };
  8469. function d3_scale_pow(linear, exponent, domain) {
  8470. var powp = d3_scale_powPow(exponent), powb = d3_scale_powPow(1 / exponent);
  8471. function scale(x) {
  8472. return linear(powp(x));
  8473. }
  8474. scale.invert = function(x) {
  8475. return powb(linear.invert(x));
  8476. };
  8477. scale.domain = function(x) {
  8478. if (!arguments.length) return domain;
  8479. linear.domain((domain = x.map(Number)).map(powp));
  8480. return scale;
  8481. };
  8482. scale.ticks = function(m) {
  8483. return d3_scale_linearTicks(domain, m);
  8484. };
  8485. scale.tickFormat = function(m, format) {
  8486. return d3_scale_linearTickFormat(domain, m, format);
  8487. };
  8488. scale.nice = function(m) {
  8489. return scale.domain(d3_scale_linearNice(domain, m));
  8490. };
  8491. scale.exponent = function(x) {
  8492. if (!arguments.length) return exponent;
  8493. powp = d3_scale_powPow(exponent = x);
  8494. powb = d3_scale_powPow(1 / exponent);
  8495. linear.domain(domain.map(powp));
  8496. return scale;
  8497. };
  8498. scale.copy = function() {
  8499. return d3_scale_pow(linear.copy(), exponent, domain);
  8500. };
  8501. return d3_scale_linearRebind(scale, linear);
  8502. }
  8503. function d3_scale_powPow(e) {
  8504. return function(x) {
  8505. return x < 0 ? -Math.pow(-x, e) : Math.pow(x, e);
  8506. };
  8507. }
  8508. d3.scale.sqrt = function() {
  8509. return d3.scale.pow().exponent(.5);
  8510. };
  8511. d3.scale.ordinal = function() {
  8512. return d3_scale_ordinal([], {
  8513. t: "range",
  8514. a: [ [] ]
  8515. });
  8516. };
  8517. function d3_scale_ordinal(domain, ranger) {
  8518. var index, range, rangeBand;
  8519. function scale(x) {
  8520. return range[((index.get(x) || (ranger.t === "range" ? index.set(x, domain.push(x)) : NaN)) - 1) % range.length];
  8521. }
  8522. function steps(start, step) {
  8523. return d3.range(domain.length).map(function(i) {
  8524. return start + step * i;
  8525. });
  8526. }
  8527. scale.domain = function(x) {
  8528. if (!arguments.length) return domain;
  8529. domain = [];
  8530. index = new d3_Map();
  8531. var i = -1, n = x.length, xi;
  8532. while (++i < n) if (!index.has(xi = x[i])) index.set(xi, domain.push(xi));
  8533. return scale[ranger.t].apply(scale, ranger.a);
  8534. };
  8535. scale.range = function(x) {
  8536. if (!arguments.length) return range;
  8537. range = x;
  8538. rangeBand = 0;
  8539. ranger = {
  8540. t: "range",
  8541. a: arguments
  8542. };
  8543. return scale;
  8544. };
  8545. scale.rangePoints = function(x, padding) {
  8546. if (arguments.length < 2) padding = 0;
  8547. var start = x[0], stop = x[1], step = domain.length < 2 ? (start = (start + stop) / 2,
  8548. 0) : (stop - start) / (domain.length - 1 + padding);
  8549. range = steps(start + step * padding / 2, step);
  8550. rangeBand = 0;
  8551. ranger = {
  8552. t: "rangePoints",
  8553. a: arguments
  8554. };
  8555. return scale;
  8556. };
  8557. scale.rangeRoundPoints = function(x, padding) {
  8558. if (arguments.length < 2) padding = 0;
  8559. var start = x[0], stop = x[1], step = domain.length < 2 ? (start = stop = Math.round((start + stop) / 2),
  8560. 0) : (stop - start) / (domain.length - 1 + padding) | 0;
  8561. range = steps(start + Math.round(step * padding / 2 + (stop - start - (domain.length - 1 + padding) * step) / 2), step);
  8562. rangeBand = 0;
  8563. ranger = {
  8564. t: "rangeRoundPoints",
  8565. a: arguments
  8566. };
  8567. return scale;
  8568. };
  8569. scale.rangeBands = function(x, padding, outerPadding) {
  8570. if (arguments.length < 2) padding = 0;
  8571. if (arguments.length < 3) outerPadding = padding;
  8572. var reverse = x[1] < x[0], start = x[reverse - 0], stop = x[1 - reverse], step = (stop - start) / (domain.length - padding + 2 * outerPadding);
  8573. range = steps(start + step * outerPadding, step);
  8574. if (reverse) range.reverse();
  8575. rangeBand = step * (1 - padding);
  8576. ranger = {
  8577. t: "rangeBands",
  8578. a: arguments
  8579. };
  8580. return scale;
  8581. };
  8582. scale.rangeRoundBands = function(x, padding, outerPadding) {
  8583. if (arguments.length < 2) padding = 0;
  8584. if (arguments.length < 3) outerPadding = padding;
  8585. var reverse = x[1] < x[0], start = x[reverse - 0], stop = x[1 - reverse], step = Math.floor((stop - start) / (domain.length - padding + 2 * outerPadding));
  8586. range = steps(start + Math.round((stop - start - (domain.length - padding) * step) / 2), step);
  8587. if (reverse) range.reverse();
  8588. rangeBand = Math.round(step * (1 - padding));
  8589. ranger = {
  8590. t: "rangeRoundBands",
  8591. a: arguments
  8592. };
  8593. return scale;
  8594. };
  8595. scale.rangeBand = function() {
  8596. return rangeBand;
  8597. };
  8598. scale.rangeExtent = function() {
  8599. return d3_scaleExtent(ranger.a[0]);
  8600. };
  8601. scale.copy = function() {
  8602. return d3_scale_ordinal(domain, ranger);
  8603. };
  8604. return scale.domain(domain);
  8605. }
  8606. d3.scale.category10 = function() {
  8607. return d3.scale.ordinal().range(d3_category10);
  8608. };
  8609. d3.scale.category20 = function() {
  8610. return d3.scale.ordinal().range(d3_category20);
  8611. };
  8612. d3.scale.category20b = function() {
  8613. return d3.scale.ordinal().range(d3_category20b);
  8614. };
  8615. d3.scale.category20c = function() {
  8616. return d3.scale.ordinal().range(d3_category20c);
  8617. };
  8618. var d3_category10 = [ 2062260, 16744206, 2924588, 14034728, 9725885, 9197131, 14907330, 8355711, 12369186, 1556175 ].map(d3_rgbString);
  8619. var d3_category20 = [ 2062260, 11454440, 16744206, 16759672, 2924588, 10018698, 14034728, 16750742, 9725885, 12955861, 9197131, 12885140, 14907330, 16234194, 8355711, 13092807, 12369186, 14408589, 1556175, 10410725 ].map(d3_rgbString);
  8620. var d3_category20b = [ 3750777, 5395619, 7040719, 10264286, 6519097, 9216594, 11915115, 13556636, 9202993, 12426809, 15186514, 15190932, 8666169, 11356490, 14049643, 15177372, 8077683, 10834324, 13528509, 14589654 ].map(d3_rgbString);
  8621. var d3_category20c = [ 3244733, 7057110, 10406625, 13032431, 15095053, 16616764, 16625259, 16634018, 3253076, 7652470, 10607003, 13101504, 7695281, 10394312, 12369372, 14342891, 6513507, 9868950, 12434877, 14277081 ].map(d3_rgbString);
  8622. d3.scale.quantile = function() {
  8623. return d3_scale_quantile([], []);
  8624. };
  8625. function d3_scale_quantile(domain, range) {
  8626. var thresholds;
  8627. function rescale() {
  8628. var k = 0, q = range.length;
  8629. thresholds = [];
  8630. while (++k < q) thresholds[k - 1] = d3.quantile(domain, k / q);
  8631. return scale;
  8632. }
  8633. function scale(x) {
  8634. if (!isNaN(x = +x)) return range[d3.bisect(thresholds, x)];
  8635. }
  8636. scale.domain = function(x) {
  8637. if (!arguments.length) return domain;
  8638. domain = x.map(d3_number).filter(d3_numeric).sort(d3_ascending);
  8639. return rescale();
  8640. };
  8641. scale.range = function(x) {
  8642. if (!arguments.length) return range;
  8643. range = x;
  8644. return rescale();
  8645. };
  8646. scale.quantiles = function() {
  8647. return thresholds;
  8648. };
  8649. scale.invertExtent = function(y) {
  8650. y = range.indexOf(y);
  8651. return y < 0 ? [ NaN, NaN ] : [ y > 0 ? thresholds[y - 1] : domain[0], y < thresholds.length ? thresholds[y] : domain[domain.length - 1] ];
  8652. };
  8653. scale.copy = function() {
  8654. return d3_scale_quantile(domain, range);
  8655. };
  8656. return rescale();
  8657. }
  8658. d3.scale.quantize = function() {
  8659. return d3_scale_quantize(0, 1, [ 0, 1 ]);
  8660. };
  8661. function d3_scale_quantize(x0, x1, range) {
  8662. var kx, i;
  8663. function scale(x) {
  8664. return range[Math.max(0, Math.min(i, Math.floor(kx * (x - x0))))];
  8665. }
  8666. function rescale() {
  8667. kx = range.length / (x1 - x0);
  8668. i = range.length - 1;
  8669. return scale;
  8670. }
  8671. scale.domain = function(x) {
  8672. if (!arguments.length) return [ x0, x1 ];
  8673. x0 = +x[0];
  8674. x1 = +x[x.length - 1];
  8675. return rescale();
  8676. };
  8677. scale.range = function(x) {
  8678. if (!arguments.length) return range;
  8679. range = x;
  8680. return rescale();
  8681. };
  8682. scale.invertExtent = function(y) {
  8683. y = range.indexOf(y);
  8684. y = y < 0 ? NaN : y / kx + x0;
  8685. return [ y, y + 1 / kx ];
  8686. };
  8687. scale.copy = function() {
  8688. return d3_scale_quantize(x0, x1, range);
  8689. };
  8690. return rescale();
  8691. }
  8692. d3.scale.threshold = function() {
  8693. return d3_scale_threshold([ .5 ], [ 0, 1 ]);
  8694. };
  8695. function d3_scale_threshold(domain, range) {
  8696. function scale(x) {
  8697. if (x <= x) return range[d3.bisect(domain, x)];
  8698. }
  8699. scale.domain = function(_) {
  8700. if (!arguments.length) return domain;
  8701. domain = _;
  8702. return scale;
  8703. };
  8704. scale.range = function(_) {
  8705. if (!arguments.length) return range;
  8706. range = _;
  8707. return scale;
  8708. };
  8709. scale.invertExtent = function(y) {
  8710. y = range.indexOf(y);
  8711. return [ domain[y - 1], domain[y] ];
  8712. };
  8713. scale.copy = function() {
  8714. return d3_scale_threshold(domain, range);
  8715. };
  8716. return scale;
  8717. }
  8718. d3.scale.identity = function() {
  8719. return d3_scale_identity([ 0, 1 ]);
  8720. };
  8721. function d3_scale_identity(domain) {
  8722. function identity(x) {
  8723. return +x;
  8724. }
  8725. identity.invert = identity;
  8726. identity.domain = identity.range = function(x) {
  8727. if (!arguments.length) return domain;
  8728. domain = x.map(identity);
  8729. return identity;
  8730. };
  8731. identity.ticks = function(m) {
  8732. return d3_scale_linearTicks(domain, m);
  8733. };
  8734. identity.tickFormat = function(m, format) {
  8735. return d3_scale_linearTickFormat(domain, m, format);
  8736. };
  8737. identity.copy = function() {
  8738. return d3_scale_identity(domain);
  8739. };
  8740. return identity;
  8741. }
  8742. d3.svg = {};
  8743. function d3_zero() {
  8744. return 0;
  8745. }
  8746. d3.svg.arc = function() {
  8747. var innerRadius = d3_svg_arcInnerRadius, outerRadius = d3_svg_arcOuterRadius, cornerRadius = d3_zero, padRadius = d3_svg_arcAuto, startAngle = d3_svg_arcStartAngle, endAngle = d3_svg_arcEndAngle, padAngle = d3_svg_arcPadAngle;
  8748. function arc() {
  8749. var r0 = Math.max(0, +innerRadius.apply(this, arguments)), r1 = Math.max(0, +outerRadius.apply(this, arguments)), a0 = startAngle.apply(this, arguments) - halfπ, a1 = endAngle.apply(this, arguments) - halfπ, da = Math.abs(a1 - a0), cw = a0 > a1 ? 0 : 1;
  8750. if (r1 < r0) rc = r1, r1 = r0, r0 = rc;
  8751. if (da >= τε) return circleSegment(r1, cw) + (r0 ? circleSegment(r0, 1 - cw) : "") + "Z";
  8752. var rc, cr, rp, ap, p0 = 0, p1 = 0, x0, y0, x1, y1, x2, y2, x3, y3, path = [];
  8753. if (ap = (+padAngle.apply(this, arguments) || 0) / 2) {
  8754. rp = padRadius === d3_svg_arcAuto ? Math.sqrt(r0 * r0 + r1 * r1) : +padRadius.apply(this, arguments);
  8755. if (!cw) p1 *= -1;
  8756. if (r1) p1 = d3_asin(rp / r1 * Math.sin(ap));
  8757. if (r0) p0 = d3_asin(rp / r0 * Math.sin(ap));
  8758. }
  8759. if (r1) {
  8760. x0 = r1 * Math.cos(a0 + p1);
  8761. y0 = r1 * Math.sin(a0 + p1);
  8762. x1 = r1 * Math.cos(a1 - p1);
  8763. y1 = r1 * Math.sin(a1 - p1);
  8764. var l1 = Math.abs(a1 - a0 - 2 * p1) <= π ? 0 : 1;
  8765. if (p1 && d3_svg_arcSweep(x0, y0, x1, y1) === cw ^ l1) {
  8766. var h1 = (a0 + a1) / 2;
  8767. x0 = r1 * Math.cos(h1);
  8768. y0 = r1 * Math.sin(h1);
  8769. x1 = y1 = null;
  8770. }
  8771. } else {
  8772. x0 = y0 = 0;
  8773. }
  8774. if (r0) {
  8775. x2 = r0 * Math.cos(a1 - p0);
  8776. y2 = r0 * Math.sin(a1 - p0);
  8777. x3 = r0 * Math.cos(a0 + p0);
  8778. y3 = r0 * Math.sin(a0 + p0);
  8779. var l0 = Math.abs(a0 - a1 + 2 * p0) <= π ? 0 : 1;
  8780. if (p0 && d3_svg_arcSweep(x2, y2, x3, y3) === 1 - cw ^ l0) {
  8781. var h0 = (a0 + a1) / 2;
  8782. x2 = r0 * Math.cos(h0);
  8783. y2 = r0 * Math.sin(h0);
  8784. x3 = y3 = null;
  8785. }
  8786. } else {
  8787. x2 = y2 = 0;
  8788. }
  8789. if (da > ε && (rc = Math.min(Math.abs(r1 - r0) / 2, +cornerRadius.apply(this, arguments))) > .001) {
  8790. cr = r0 < r1 ^ cw ? 0 : 1;
  8791. var rc1 = rc, rc0 = rc;
  8792. if (da < π) {
  8793. var oc = x3 == null ? [ x2, y2 ] : x1 == null ? [ x0, y0 ] : d3_geom_polygonIntersect([ x0, y0 ], [ x3, y3 ], [ x1, y1 ], [ x2, y2 ]), ax = x0 - oc[0], ay = y0 - oc[1], bx = x1 - oc[0], by = y1 - oc[1], kc = 1 / Math.sin(Math.acos((ax * bx + ay * by) / (Math.sqrt(ax * ax + ay * ay) * Math.sqrt(bx * bx + by * by))) / 2), lc = Math.sqrt(oc[0] * oc[0] + oc[1] * oc[1]);
  8794. rc0 = Math.min(rc, (r0 - lc) / (kc - 1));
  8795. rc1 = Math.min(rc, (r1 - lc) / (kc + 1));
  8796. }
  8797. if (x1 != null) {
  8798. var t30 = d3_svg_arcCornerTangents(x3 == null ? [ x2, y2 ] : [ x3, y3 ], [ x0, y0 ], r1, rc1, cw), t12 = d3_svg_arcCornerTangents([ x1, y1 ], [ x2, y2 ], r1, rc1, cw);
  8799. if (rc === rc1) {
  8800. path.push("M", t30[0], "A", rc1, ",", rc1, " 0 0,", cr, " ", t30[1], "A", r1, ",", r1, " 0 ", 1 - cw ^ d3_svg_arcSweep(t30[1][0], t30[1][1], t12[1][0], t12[1][1]), ",", cw, " ", t12[1], "A", rc1, ",", rc1, " 0 0,", cr, " ", t12[0]);
  8801. } else {
  8802. path.push("M", t30[0], "A", rc1, ",", rc1, " 0 1,", cr, " ", t12[0]);
  8803. }
  8804. } else {
  8805. path.push("M", x0, ",", y0);
  8806. }
  8807. if (x3 != null) {
  8808. var t03 = d3_svg_arcCornerTangents([ x0, y0 ], [ x3, y3 ], r0, -rc0, cw), t21 = d3_svg_arcCornerTangents([ x2, y2 ], x1 == null ? [ x0, y0 ] : [ x1, y1 ], r0, -rc0, cw);
  8809. if (rc === rc0) {
  8810. path.push("L", t21[0], "A", rc0, ",", rc0, " 0 0,", cr, " ", t21[1], "A", r0, ",", r0, " 0 ", cw ^ d3_svg_arcSweep(t21[1][0], t21[1][1], t03[1][0], t03[1][1]), ",", 1 - cw, " ", t03[1], "A", rc0, ",", rc0, " 0 0,", cr, " ", t03[0]);
  8811. } else {
  8812. path.push("L", t21[0], "A", rc0, ",", rc0, " 0 0,", cr, " ", t03[0]);
  8813. }
  8814. } else {
  8815. path.push("L", x2, ",", y2);
  8816. }
  8817. } else {
  8818. path.push("M", x0, ",", y0);
  8819. if (x1 != null) path.push("A", r1, ",", r1, " 0 ", l1, ",", cw, " ", x1, ",", y1);
  8820. path.push("L", x2, ",", y2);
  8821. if (x3 != null) path.push("A", r0, ",", r0, " 0 ", l0, ",", 1 - cw, " ", x3, ",", y3);
  8822. }
  8823. path.push("Z");
  8824. return path.join("");
  8825. }
  8826. function circleSegment(r1, cw) {
  8827. return "M0," + r1 + "A" + r1 + "," + r1 + " 0 1," + cw + " 0," + -r1 + "A" + r1 + "," + r1 + " 0 1," + cw + " 0," + r1;
  8828. }
  8829. arc.innerRadius = function(v) {
  8830. if (!arguments.length) return innerRadius;
  8831. innerRadius = d3_functor(v);
  8832. return arc;
  8833. };
  8834. arc.outerRadius = function(v) {
  8835. if (!arguments.length) return outerRadius;
  8836. outerRadius = d3_functor(v);
  8837. return arc;
  8838. };
  8839. arc.cornerRadius = function(v) {
  8840. if (!arguments.length) return cornerRadius;
  8841. cornerRadius = d3_functor(v);
  8842. return arc;
  8843. };
  8844. arc.padRadius = function(v) {
  8845. if (!arguments.length) return padRadius;
  8846. padRadius = v == d3_svg_arcAuto ? d3_svg_arcAuto : d3_functor(v);
  8847. return arc;
  8848. };
  8849. arc.startAngle = function(v) {
  8850. if (!arguments.length) return startAngle;
  8851. startAngle = d3_functor(v);
  8852. return arc;
  8853. };
  8854. arc.endAngle = function(v) {
  8855. if (!arguments.length) return endAngle;
  8856. endAngle = d3_functor(v);
  8857. return arc;
  8858. };
  8859. arc.padAngle = function(v) {
  8860. if (!arguments.length) return padAngle;
  8861. padAngle = d3_functor(v);
  8862. return arc;
  8863. };
  8864. arc.centroid = function() {
  8865. var r = (+innerRadius.apply(this, arguments) + +outerRadius.apply(this, arguments)) / 2, a = (+startAngle.apply(this, arguments) + +endAngle.apply(this, arguments)) / 2 - halfπ;
  8866. return [ Math.cos(a) * r, Math.sin(a) * r ];
  8867. };
  8868. return arc;
  8869. };
  8870. var d3_svg_arcAuto = "auto";
  8871. function d3_svg_arcInnerRadius(d) {
  8872. return d.innerRadius;
  8873. }
  8874. function d3_svg_arcOuterRadius(d) {
  8875. return d.outerRadius;
  8876. }
  8877. function d3_svg_arcStartAngle(d) {
  8878. return d.startAngle;
  8879. }
  8880. function d3_svg_arcEndAngle(d) {
  8881. return d.endAngle;
  8882. }
  8883. function d3_svg_arcPadAngle(d) {
  8884. return d && d.padAngle;
  8885. }
  8886. function d3_svg_arcSweep(x0, y0, x1, y1) {
  8887. return (x0 - x1) * y0 - (y0 - y1) * x0 > 0 ? 0 : 1;
  8888. }
  8889. function d3_svg_arcCornerTangents(p0, p1, r1, rc, cw) {
  8890. var x01 = p0[0] - p1[0], y01 = p0[1] - p1[1], lo = (cw ? rc : -rc) / Math.sqrt(x01 * x01 + y01 * y01), ox = lo * y01, oy = -lo * x01, x1 = p0[0] + ox, y1 = p0[1] + oy, x2 = p1[0] + ox, y2 = p1[1] + oy, x3 = (x1 + x2) / 2, y3 = (y1 + y2) / 2, dx = x2 - x1, dy = y2 - y1, d2 = dx * dx + dy * dy, r = r1 - rc, D = x1 * y2 - x2 * y1, d = (dy < 0 ? -1 : 1) * Math.sqrt(Math.max(0, r * r * d2 - D * D)), cx0 = (D * dy - dx * d) / d2, cy0 = (-D * dx - dy * d) / d2, cx1 = (D * dy + dx * d) / d2, cy1 = (-D * dx + dy * d) / d2, dx0 = cx0 - x3, dy0 = cy0 - y3, dx1 = cx1 - x3, dy1 = cy1 - y3;
  8891. if (dx0 * dx0 + dy0 * dy0 > dx1 * dx1 + dy1 * dy1) cx0 = cx1, cy0 = cy1;
  8892. return [ [ cx0 - ox, cy0 - oy ], [ cx0 * r1 / r, cy0 * r1 / r ] ];
  8893. }
  8894. function d3_svg_line(projection) {
  8895. var x = d3_geom_pointX, y = d3_geom_pointY, defined = d3_true, interpolate = d3_svg_lineLinear, interpolateKey = interpolate.key, tension = .7;
  8896. function line(data) {
  8897. var segments = [], points = [], i = -1, n = data.length, d, fx = d3_functor(x), fy = d3_functor(y);
  8898. function segment() {
  8899. segments.push("M", interpolate(projection(points), tension));
  8900. }
  8901. while (++i < n) {
  8902. if (defined.call(this, d = data[i], i)) {
  8903. points.push([ +fx.call(this, d, i), +fy.call(this, d, i) ]);
  8904. } else if (points.length) {
  8905. segment();
  8906. points = [];
  8907. }
  8908. }
  8909. if (points.length) segment();
  8910. return segments.length ? segments.join("") : null;
  8911. }
  8912. line.x = function(_) {
  8913. if (!arguments.length) return x;
  8914. x = _;
  8915. return line;
  8916. };
  8917. line.y = function(_) {
  8918. if (!arguments.length) return y;
  8919. y = _;
  8920. return line;
  8921. };
  8922. line.defined = function(_) {
  8923. if (!arguments.length) return defined;
  8924. defined = _;
  8925. return line;
  8926. };
  8927. line.interpolate = function(_) {
  8928. if (!arguments.length) return interpolateKey;
  8929. if (typeof _ === "function") interpolateKey = interpolate = _; else interpolateKey = (interpolate = d3_svg_lineInterpolators.get(_) || d3_svg_lineLinear).key;
  8930. return line;
  8931. };
  8932. line.tension = function(_) {
  8933. if (!arguments.length) return tension;
  8934. tension = _;
  8935. return line;
  8936. };
  8937. return line;
  8938. }
  8939. d3.svg.line = function() {
  8940. return d3_svg_line(d3_identity);
  8941. };
  8942. var d3_svg_lineInterpolators = d3.map({
  8943. linear: d3_svg_lineLinear,
  8944. "linear-closed": d3_svg_lineLinearClosed,
  8945. step: d3_svg_lineStep,
  8946. "step-before": d3_svg_lineStepBefore,
  8947. "step-after": d3_svg_lineStepAfter,
  8948. basis: d3_svg_lineBasis,
  8949. "basis-open": d3_svg_lineBasisOpen,
  8950. "basis-closed": d3_svg_lineBasisClosed,
  8951. bundle: d3_svg_lineBundle,
  8952. cardinal: d3_svg_lineCardinal,
  8953. "cardinal-open": d3_svg_lineCardinalOpen,
  8954. "cardinal-closed": d3_svg_lineCardinalClosed,
  8955. monotone: d3_svg_lineMonotone
  8956. });
  8957. d3_svg_lineInterpolators.forEach(function(key, value) {
  8958. value.key = key;
  8959. value.closed = /-closed$/.test(key);
  8960. });
  8961. function d3_svg_lineLinear(points) {
  8962. return points.length > 1 ? points.join("L") : points + "Z";
  8963. }
  8964. function d3_svg_lineLinearClosed(points) {
  8965. return points.join("L") + "Z";
  8966. }
  8967. function d3_svg_lineStep(points) {
  8968. var i = 0, n = points.length, p = points[0], path = [ p[0], ",", p[1] ];
  8969. while (++i < n) path.push("H", (p[0] + (p = points[i])[0]) / 2, "V", p[1]);
  8970. if (n > 1) path.push("H", p[0]);
  8971. return path.join("");
  8972. }
  8973. function d3_svg_lineStepBefore(points) {
  8974. var i = 0, n = points.length, p = points[0], path = [ p[0], ",", p[1] ];
  8975. while (++i < n) path.push("V", (p = points[i])[1], "H", p[0]);
  8976. return path.join("");
  8977. }
  8978. function d3_svg_lineStepAfter(points) {
  8979. var i = 0, n = points.length, p = points[0], path = [ p[0], ",", p[1] ];
  8980. while (++i < n) path.push("H", (p = points[i])[0], "V", p[1]);
  8981. return path.join("");
  8982. }
  8983. function d3_svg_lineCardinalOpen(points, tension) {
  8984. return points.length < 4 ? d3_svg_lineLinear(points) : points[1] + d3_svg_lineHermite(points.slice(1, -1), d3_svg_lineCardinalTangents(points, tension));
  8985. }
  8986. function d3_svg_lineCardinalClosed(points, tension) {
  8987. return points.length < 3 ? d3_svg_lineLinearClosed(points) : points[0] + d3_svg_lineHermite((points.push(points[0]),
  8988. points), d3_svg_lineCardinalTangents([ points[points.length - 2] ].concat(points, [ points[1] ]), tension));
  8989. }
  8990. function d3_svg_lineCardinal(points, tension) {
  8991. return points.length < 3 ? d3_svg_lineLinear(points) : points[0] + d3_svg_lineHermite(points, d3_svg_lineCardinalTangents(points, tension));
  8992. }
  8993. function d3_svg_lineHermite(points, tangents) {
  8994. if (tangents.length < 1 || points.length != tangents.length && points.length != tangents.length + 2) {
  8995. return d3_svg_lineLinear(points);
  8996. }
  8997. var quad = points.length != tangents.length, path = "", p0 = points[0], p = points[1], t0 = tangents[0], t = t0, pi = 1;
  8998. if (quad) {
  8999. path += "Q" + (p[0] - t0[0] * 2 / 3) + "," + (p[1] - t0[1] * 2 / 3) + "," + p[0] + "," + p[1];
  9000. p0 = points[1];
  9001. pi = 2;
  9002. }
  9003. if (tangents.length > 1) {
  9004. t = tangents[1];
  9005. p = points[pi];
  9006. pi++;
  9007. path += "C" + (p0[0] + t0[0]) + "," + (p0[1] + t0[1]) + "," + (p[0] - t[0]) + "," + (p[1] - t[1]) + "," + p[0] + "," + p[1];
  9008. for (var i = 2; i < tangents.length; i++, pi++) {
  9009. p = points[pi];
  9010. t = tangents[i];
  9011. path += "S" + (p[0] - t[0]) + "," + (p[1] - t[1]) + "," + p[0] + "," + p[1];
  9012. }
  9013. }
  9014. if (quad) {
  9015. var lp = points[pi];
  9016. path += "Q" + (p[0] + t[0] * 2 / 3) + "," + (p[1] + t[1] * 2 / 3) + "," + lp[0] + "," + lp[1];
  9017. }
  9018. return path;
  9019. }
  9020. function d3_svg_lineCardinalTangents(points, tension) {
  9021. var tangents = [], a = (1 - tension) / 2, p0, p1 = points[0], p2 = points[1], i = 1, n = points.length;
  9022. while (++i < n) {
  9023. p0 = p1;
  9024. p1 = p2;
  9025. p2 = points[i];
  9026. tangents.push([ a * (p2[0] - p0[0]), a * (p2[1] - p0[1]) ]);
  9027. }
  9028. return tangents;
  9029. }
  9030. function d3_svg_lineBasis(points) {
  9031. if (points.length < 3) return d3_svg_lineLinear(points);
  9032. var i = 1, n = points.length, pi = points[0], x0 = pi[0], y0 = pi[1], px = [ x0, x0, x0, (pi = points[1])[0] ], py = [ y0, y0, y0, pi[1] ], path = [ x0, ",", y0, "L", d3_svg_lineDot4(d3_svg_lineBasisBezier3, px), ",", d3_svg_lineDot4(d3_svg_lineBasisBezier3, py) ];
  9033. points.push(points[n - 1]);
  9034. while (++i <= n) {
  9035. pi = points[i];
  9036. px.shift();
  9037. px.push(pi[0]);
  9038. py.shift();
  9039. py.push(pi[1]);
  9040. d3_svg_lineBasisBezier(path, px, py);
  9041. }
  9042. points.pop();
  9043. path.push("L", pi);
  9044. return path.join("");
  9045. }
  9046. function d3_svg_lineBasisOpen(points) {
  9047. if (points.length < 4) return d3_svg_lineLinear(points);
  9048. var path = [], i = -1, n = points.length, pi, px = [ 0 ], py = [ 0 ];
  9049. while (++i < 3) {
  9050. pi = points[i];
  9051. px.push(pi[0]);
  9052. py.push(pi[1]);
  9053. }
  9054. path.push(d3_svg_lineDot4(d3_svg_lineBasisBezier3, px) + "," + d3_svg_lineDot4(d3_svg_lineBasisBezier3, py));
  9055. --i;
  9056. while (++i < n) {
  9057. pi = points[i];
  9058. px.shift();
  9059. px.push(pi[0]);
  9060. py.shift();
  9061. py.push(pi[1]);
  9062. d3_svg_lineBasisBezier(path, px, py);
  9063. }
  9064. return path.join("");
  9065. }
  9066. function d3_svg_lineBasisClosed(points) {
  9067. var path, i = -1, n = points.length, m = n + 4, pi, px = [], py = [];
  9068. while (++i < 4) {
  9069. pi = points[i % n];
  9070. px.push(pi[0]);
  9071. py.push(pi[1]);
  9072. }
  9073. path = [ d3_svg_lineDot4(d3_svg_lineBasisBezier3, px), ",", d3_svg_lineDot4(d3_svg_lineBasisBezier3, py) ];
  9074. --i;
  9075. while (++i < m) {
  9076. pi = points[i % n];
  9077. px.shift();
  9078. px.push(pi[0]);
  9079. py.shift();
  9080. py.push(pi[1]);
  9081. d3_svg_lineBasisBezier(path, px, py);
  9082. }
  9083. return path.join("");
  9084. }
  9085. function d3_svg_lineBundle(points, tension) {
  9086. var n = points.length - 1;
  9087. if (n) {
  9088. var x0 = points[0][0], y0 = points[0][1], dx = points[n][0] - x0, dy = points[n][1] - y0, i = -1, p, t;
  9089. while (++i <= n) {
  9090. p = points[i];
  9091. t = i / n;
  9092. p[0] = tension * p[0] + (1 - tension) * (x0 + t * dx);
  9093. p[1] = tension * p[1] + (1 - tension) * (y0 + t * dy);
  9094. }
  9095. }
  9096. return d3_svg_lineBasis(points);
  9097. }
  9098. function d3_svg_lineDot4(a, b) {
  9099. return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3];
  9100. }
  9101. var d3_svg_lineBasisBezier1 = [ 0, 2 / 3, 1 / 3, 0 ], d3_svg_lineBasisBezier2 = [ 0, 1 / 3, 2 / 3, 0 ], d3_svg_lineBasisBezier3 = [ 0, 1 / 6, 2 / 3, 1 / 6 ];
  9102. function d3_svg_lineBasisBezier(path, x, y) {
  9103. path.push("C", d3_svg_lineDot4(d3_svg_lineBasisBezier1, x), ",", d3_svg_lineDot4(d3_svg_lineBasisBezier1, y), ",", d3_svg_lineDot4(d3_svg_lineBasisBezier2, x), ",", d3_svg_lineDot4(d3_svg_lineBasisBezier2, y), ",", d3_svg_lineDot4(d3_svg_lineBasisBezier3, x), ",", d3_svg_lineDot4(d3_svg_lineBasisBezier3, y));
  9104. }
  9105. function d3_svg_lineSlope(p0, p1) {
  9106. return (p1[1] - p0[1]) / (p1[0] - p0[0]);
  9107. }
  9108. function d3_svg_lineFiniteDifferences(points) {
  9109. var i = 0, j = points.length - 1, m = [], p0 = points[0], p1 = points[1], d = m[0] = d3_svg_lineSlope(p0, p1);
  9110. while (++i < j) {
  9111. m[i] = (d + (d = d3_svg_lineSlope(p0 = p1, p1 = points[i + 1]))) / 2;
  9112. }
  9113. m[i] = d;
  9114. return m;
  9115. }
  9116. function d3_svg_lineMonotoneTangents(points) {
  9117. var tangents = [], d, a, b, s, m = d3_svg_lineFiniteDifferences(points), i = -1, j = points.length - 1;
  9118. while (++i < j) {
  9119. d = d3_svg_lineSlope(points[i], points[i + 1]);
  9120. if (abs(d) < ε) {
  9121. m[i] = m[i + 1] = 0;
  9122. } else {
  9123. a = m[i] / d;
  9124. b = m[i + 1] / d;
  9125. s = a * a + b * b;
  9126. if (s > 9) {
  9127. s = d * 3 / Math.sqrt(s);
  9128. m[i] = s * a;
  9129. m[i + 1] = s * b;
  9130. }
  9131. }
  9132. }
  9133. i = -1;
  9134. while (++i <= j) {
  9135. s = (points[Math.min(j, i + 1)][0] - points[Math.max(0, i - 1)][0]) / (6 * (1 + m[i] * m[i]));
  9136. tangents.push([ s || 0, m[i] * s || 0 ]);
  9137. }
  9138. return tangents;
  9139. }
  9140. function d3_svg_lineMonotone(points) {
  9141. return points.length < 3 ? d3_svg_lineLinear(points) : points[0] + d3_svg_lineHermite(points, d3_svg_lineMonotoneTangents(points));
  9142. }
  9143. d3.svg.line.radial = function() {
  9144. var line = d3_svg_line(d3_svg_lineRadial);
  9145. line.radius = line.x, delete line.x;
  9146. line.angle = line.y, delete line.y;
  9147. return line;
  9148. };
  9149. function d3_svg_lineRadial(points) {
  9150. var point, i = -1, n = points.length, r, a;
  9151. while (++i < n) {
  9152. point = points[i];
  9153. r = point[0];
  9154. a = point[1] - halfπ;
  9155. point[0] = r * Math.cos(a);
  9156. point[1] = r * Math.sin(a);
  9157. }
  9158. return points;
  9159. }
  9160. function d3_svg_area(projection) {
  9161. var x0 = d3_geom_pointX, x1 = d3_geom_pointX, y0 = 0, y1 = d3_geom_pointY, defined = d3_true, interpolate = d3_svg_lineLinear, interpolateKey = interpolate.key, interpolateReverse = interpolate, L = "L", tension = .7;
  9162. function area(data) {
  9163. var segments = [], points0 = [], points1 = [], i = -1, n = data.length, d, fx0 = d3_functor(x0), fy0 = d3_functor(y0), fx1 = x0 === x1 ? function() {
  9164. return x;
  9165. } : d3_functor(x1), fy1 = y0 === y1 ? function() {
  9166. return y;
  9167. } : d3_functor(y1), x, y;
  9168. function segment() {
  9169. segments.push("M", interpolate(projection(points1), tension), L, interpolateReverse(projection(points0.reverse()), tension), "Z");
  9170. }
  9171. while (++i < n) {
  9172. if (defined.call(this, d = data[i], i)) {
  9173. points0.push([ x = +fx0.call(this, d, i), y = +fy0.call(this, d, i) ]);
  9174. points1.push([ +fx1.call(this, d, i), +fy1.call(this, d, i) ]);
  9175. } else if (points0.length) {
  9176. segment();
  9177. points0 = [];
  9178. points1 = [];
  9179. }
  9180. }
  9181. if (points0.length) segment();
  9182. return segments.length ? segments.join("") : null;
  9183. }
  9184. area.x = function(_) {
  9185. if (!arguments.length) return x1;
  9186. x0 = x1 = _;
  9187. return area;
  9188. };
  9189. area.x0 = function(_) {
  9190. if (!arguments.length) return x0;
  9191. x0 = _;
  9192. return area;
  9193. };
  9194. area.x1 = function(_) {
  9195. if (!arguments.length) return x1;
  9196. x1 = _;
  9197. return area;
  9198. };
  9199. area.y = function(_) {
  9200. if (!arguments.length) return y1;
  9201. y0 = y1 = _;
  9202. return area;
  9203. };
  9204. area.y0 = function(_) {
  9205. if (!arguments.length) return y0;
  9206. y0 = _;
  9207. return area;
  9208. };
  9209. area.y1 = function(_) {
  9210. if (!arguments.length) return y1;
  9211. y1 = _;
  9212. return area;
  9213. };
  9214. area.defined = function(_) {
  9215. if (!arguments.length) return defined;
  9216. defined = _;
  9217. return area;
  9218. };
  9219. area.interpolate = function(_) {
  9220. if (!arguments.length) return interpolateKey;
  9221. if (typeof _ === "function") interpolateKey = interpolate = _; else interpolateKey = (interpolate = d3_svg_lineInterpolators.get(_) || d3_svg_lineLinear).key;
  9222. interpolateReverse = interpolate.reverse || interpolate;
  9223. L = interpolate.closed ? "M" : "L";
  9224. return area;
  9225. };
  9226. area.tension = function(_) {
  9227. if (!arguments.length) return tension;
  9228. tension = _;
  9229. return area;
  9230. };
  9231. return area;
  9232. }
  9233. d3_svg_lineStepBefore.reverse = d3_svg_lineStepAfter;
  9234. d3_svg_lineStepAfter.reverse = d3_svg_lineStepBefore;
  9235. d3.svg.area = function() {
  9236. return d3_svg_area(d3_identity);
  9237. };
  9238. d3.svg.area.radial = function() {
  9239. var area = d3_svg_area(d3_svg_lineRadial);
  9240. area.radius = area.x, delete area.x;
  9241. area.innerRadius = area.x0, delete area.x0;
  9242. area.outerRadius = area.x1, delete area.x1;
  9243. area.angle = area.y, delete area.y;
  9244. area.startAngle = area.y0, delete area.y0;
  9245. area.endAngle = area.y1, delete area.y1;
  9246. return area;
  9247. };
  9248. d3.svg.chord = function() {
  9249. var source = d3_source, target = d3_target, radius = d3_svg_chordRadius, startAngle = d3_svg_arcStartAngle, endAngle = d3_svg_arcEndAngle;
  9250. function chord(d, i) {
  9251. var s = subgroup(this, source, d, i), t = subgroup(this, target, d, i);
  9252. return "M" + s.p0 + arc(s.r, s.p1, s.a1 - s.a0) + (equals(s, t) ? curve(s.r, s.p1, s.r, s.p0) : curve(s.r, s.p1, t.r, t.p0) + arc(t.r, t.p1, t.a1 - t.a0) + curve(t.r, t.p1, s.r, s.p0)) + "Z";
  9253. }
  9254. function subgroup(self, f, d, i) {
  9255. var subgroup = f.call(self, d, i), r = radius.call(self, subgroup, i), a0 = startAngle.call(self, subgroup, i) - halfπ, a1 = endAngle.call(self, subgroup, i) - halfπ;
  9256. return {
  9257. r: r,
  9258. a0: a0,
  9259. a1: a1,
  9260. p0: [ r * Math.cos(a0), r * Math.sin(a0) ],
  9261. p1: [ r * Math.cos(a1), r * Math.sin(a1) ]
  9262. };
  9263. }
  9264. function equals(a, b) {
  9265. return a.a0 == b.a0 && a.a1 == b.a1;
  9266. }
  9267. function arc(r, p, a) {
  9268. return "A" + r + "," + r + " 0 " + +(a > π) + ",1 " + p;
  9269. }
  9270. function curve(r0, p0, r1, p1) {
  9271. return "Q 0,0 " + p1;
  9272. }
  9273. chord.radius = function(v) {
  9274. if (!arguments.length) return radius;
  9275. radius = d3_functor(v);
  9276. return chord;
  9277. };
  9278. chord.source = function(v) {
  9279. if (!arguments.length) return source;
  9280. source = d3_functor(v);
  9281. return chord;
  9282. };
  9283. chord.target = function(v) {
  9284. if (!arguments.length) return target;
  9285. target = d3_functor(v);
  9286. return chord;
  9287. };
  9288. chord.startAngle = function(v) {
  9289. if (!arguments.length) return startAngle;
  9290. startAngle = d3_functor(v);
  9291. return chord;
  9292. };
  9293. chord.endAngle = function(v) {
  9294. if (!arguments.length) return endAngle;
  9295. endAngle = d3_functor(v);
  9296. return chord;
  9297. };
  9298. return chord;
  9299. };
  9300. function d3_svg_chordRadius(d) {
  9301. return d.radius;
  9302. }
  9303. d3.svg.diagonal = function() {
  9304. var source = d3_source, target = d3_target, projection = d3_svg_diagonalProjection;
  9305. function diagonal(d, i) {
  9306. var p0 = source.call(this, d, i), p3 = target.call(this, d, i), m = (p0.y + p3.y) / 2, p = [ p0, {
  9307. x: p0.x,
  9308. y: m
  9309. }, {
  9310. x: p3.x,
  9311. y: m
  9312. }, p3 ];
  9313. p = p.map(projection);
  9314. return "M" + p[0] + "C" + p[1] + " " + p[2] + " " + p[3];
  9315. }
  9316. diagonal.source = function(x) {
  9317. if (!arguments.length) return source;
  9318. source = d3_functor(x);
  9319. return diagonal;
  9320. };
  9321. diagonal.target = function(x) {
  9322. if (!arguments.length) return target;
  9323. target = d3_functor(x);
  9324. return diagonal;
  9325. };
  9326. diagonal.projection = function(x) {
  9327. if (!arguments.length) return projection;
  9328. projection = x;
  9329. return diagonal;
  9330. };
  9331. return diagonal;
  9332. };
  9333. function d3_svg_diagonalProjection(d) {
  9334. return [ d.x, d.y ];
  9335. }
  9336. d3.svg.diagonal.radial = function() {
  9337. var diagonal = d3.svg.diagonal(), projection = d3_svg_diagonalProjection, projection_ = diagonal.projection;
  9338. diagonal.projection = function(x) {
  9339. return arguments.length ? projection_(d3_svg_diagonalRadialProjection(projection = x)) : projection;
  9340. };
  9341. return diagonal;
  9342. };
  9343. function d3_svg_diagonalRadialProjection(projection) {
  9344. return function() {
  9345. var d = projection.apply(this, arguments), r = d[0], a = d[1] - halfπ;
  9346. return [ r * Math.cos(a), r * Math.sin(a) ];
  9347. };
  9348. }
  9349. d3.svg.symbol = function() {
  9350. var type = d3_svg_symbolType, size = d3_svg_symbolSize;
  9351. function symbol(d, i) {
  9352. return (d3_svg_symbols.get(type.call(this, d, i)) || d3_svg_symbolCircle)(size.call(this, d, i));
  9353. }
  9354. symbol.type = function(x) {
  9355. if (!arguments.length) return type;
  9356. type = d3_functor(x);
  9357. return symbol;
  9358. };
  9359. symbol.size = function(x) {
  9360. if (!arguments.length) return size;
  9361. size = d3_functor(x);
  9362. return symbol;
  9363. };
  9364. return symbol;
  9365. };
  9366. function d3_svg_symbolSize() {
  9367. return 64;
  9368. }
  9369. function d3_svg_symbolType() {
  9370. return "circle";
  9371. }
  9372. function d3_svg_symbolCircle(size) {
  9373. var r = Math.sqrt(size / π);
  9374. return "M0," + r + "A" + r + "," + r + " 0 1,1 0," + -r + "A" + r + "," + r + " 0 1,1 0," + r + "Z";
  9375. }
  9376. var d3_svg_symbols = d3.map({
  9377. circle: d3_svg_symbolCircle,
  9378. cross: function(size) {
  9379. var r = Math.sqrt(size / 5) / 2;
  9380. return "M" + -3 * r + "," + -r + "H" + -r + "V" + -3 * r + "H" + r + "V" + -r + "H" + 3 * r + "V" + r + "H" + r + "V" + 3 * r + "H" + -r + "V" + r + "H" + -3 * r + "Z";
  9381. },
  9382. diamond: function(size) {
  9383. var ry = Math.sqrt(size / (2 * d3_svg_symbolTan30)), rx = ry * d3_svg_symbolTan30;
  9384. return "M0," + -ry + "L" + rx + ",0" + " 0," + ry + " " + -rx + ",0" + "Z";
  9385. },
  9386. square: function(size) {
  9387. var r = Math.sqrt(size) / 2;
  9388. return "M" + -r + "," + -r + "L" + r + "," + -r + " " + r + "," + r + " " + -r + "," + r + "Z";
  9389. },
  9390. "triangle-down": function(size) {
  9391. var rx = Math.sqrt(size / d3_svg_symbolSqrt3), ry = rx * d3_svg_symbolSqrt3 / 2;
  9392. return "M0," + ry + "L" + rx + "," + -ry + " " + -rx + "," + -ry + "Z";
  9393. },
  9394. "triangle-up": function(size) {
  9395. var rx = Math.sqrt(size / d3_svg_symbolSqrt3), ry = rx * d3_svg_symbolSqrt3 / 2;
  9396. return "M0," + -ry + "L" + rx + "," + ry + " " + -rx + "," + ry + "Z";
  9397. }
  9398. });
  9399. d3.svg.symbolTypes = d3_svg_symbols.keys();
  9400. var d3_svg_symbolSqrt3 = Math.sqrt(3), d3_svg_symbolTan30 = Math.tan(30 * d3_radians);
  9401. d3_selectionPrototype.transition = function(name) {
  9402. var id = d3_transitionInheritId || ++d3_transitionId, ns = d3_transitionNamespace(name), subgroups = [], subgroup, node, transition = d3_transitionInherit || {
  9403. time: Date.now(),
  9404. ease: d3_ease_cubicInOut,
  9405. delay: 0,
  9406. duration: 250
  9407. };
  9408. for (var j = -1, m = this.length; ++j < m; ) {
  9409. subgroups.push(subgroup = []);
  9410. for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
  9411. if (node = group[i]) d3_transitionNode(node, i, ns, id, transition);
  9412. subgroup.push(node);
  9413. }
  9414. }
  9415. return d3_transition(subgroups, ns, id);
  9416. };
  9417. d3_selectionPrototype.interrupt = function(name) {
  9418. return this.each(name == null ? d3_selection_interrupt : d3_selection_interruptNS(d3_transitionNamespace(name)));
  9419. };
  9420. var d3_selection_interrupt = d3_selection_interruptNS(d3_transitionNamespace());
  9421. function d3_selection_interruptNS(ns) {
  9422. return function() {
  9423. var lock, activeId, active;
  9424. if ((lock = this[ns]) && (active = lock[activeId = lock.active])) {
  9425. active.timer.c = null;
  9426. active.timer.t = NaN;
  9427. if (--lock.count) delete lock[activeId]; else delete this[ns];
  9428. lock.active += .5;
  9429. active.event && active.event.interrupt.call(this, this.__data__, active.index);
  9430. }
  9431. };
  9432. }
  9433. function d3_transition(groups, ns, id) {
  9434. d3_subclass(groups, d3_transitionPrototype);
  9435. groups.namespace = ns;
  9436. groups.id = id;
  9437. return groups;
  9438. }
  9439. var d3_transitionPrototype = [], d3_transitionId = 0, d3_transitionInheritId, d3_transitionInherit;
  9440. d3_transitionPrototype.call = d3_selectionPrototype.call;
  9441. d3_transitionPrototype.empty = d3_selectionPrototype.empty;
  9442. d3_transitionPrototype.node = d3_selectionPrototype.node;
  9443. d3_transitionPrototype.size = d3_selectionPrototype.size;
  9444. d3.transition = function(selection, name) {
  9445. return selection && selection.transition ? d3_transitionInheritId ? selection.transition(name) : selection : d3.selection().transition(selection);
  9446. };
  9447. d3.transition.prototype = d3_transitionPrototype;
  9448. d3_transitionPrototype.select = function(selector) {
  9449. var id = this.id, ns = this.namespace, subgroups = [], subgroup, subnode, node;
  9450. selector = d3_selection_selector(selector);
  9451. for (var j = -1, m = this.length; ++j < m; ) {
  9452. subgroups.push(subgroup = []);
  9453. for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
  9454. if ((node = group[i]) && (subnode = selector.call(node, node.__data__, i, j))) {
  9455. if ("__data__" in node) subnode.__data__ = node.__data__;
  9456. d3_transitionNode(subnode, i, ns, id, node[ns][id]);
  9457. subgroup.push(subnode);
  9458. } else {
  9459. subgroup.push(null);
  9460. }
  9461. }
  9462. }
  9463. return d3_transition(subgroups, ns, id);
  9464. };
  9465. d3_transitionPrototype.selectAll = function(selector) {
  9466. var id = this.id, ns = this.namespace, subgroups = [], subgroup, subnodes, node, subnode, transition;
  9467. selector = d3_selection_selectorAll(selector);
  9468. for (var j = -1, m = this.length; ++j < m; ) {
  9469. for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
  9470. if (node = group[i]) {
  9471. transition = node[ns][id];
  9472. subnodes = selector.call(node, node.__data__, i, j);
  9473. subgroups.push(subgroup = []);
  9474. for (var k = -1, o = subnodes.length; ++k < o; ) {
  9475. if (subnode = subnodes[k]) d3_transitionNode(subnode, k, ns, id, transition);
  9476. subgroup.push(subnode);
  9477. }
  9478. }
  9479. }
  9480. }
  9481. return d3_transition(subgroups, ns, id);
  9482. };
  9483. d3_transitionPrototype.filter = function(filter) {
  9484. var subgroups = [], subgroup, group, node;
  9485. if (typeof filter !== "function") filter = d3_selection_filter(filter);
  9486. for (var j = 0, m = this.length; j < m; j++) {
  9487. subgroups.push(subgroup = []);
  9488. for (var group = this[j], i = 0, n = group.length; i < n; i++) {
  9489. if ((node = group[i]) && filter.call(node, node.__data__, i, j)) {
  9490. subgroup.push(node);
  9491. }
  9492. }
  9493. }
  9494. return d3_transition(subgroups, this.namespace, this.id);
  9495. };
  9496. d3_transitionPrototype.tween = function(name, tween) {
  9497. var id = this.id, ns = this.namespace;
  9498. if (arguments.length < 2) return this.node()[ns][id].tween.get(name);
  9499. return d3_selection_each(this, tween == null ? function(node) {
  9500. node[ns][id].tween.remove(name);
  9501. } : function(node) {
  9502. node[ns][id].tween.set(name, tween);
  9503. });
  9504. };
  9505. function d3_transition_tween(groups, name, value, tween) {
  9506. var id = groups.id, ns = groups.namespace;
  9507. return d3_selection_each(groups, typeof value === "function" ? function(node, i, j) {
  9508. node[ns][id].tween.set(name, tween(value.call(node, node.__data__, i, j)));
  9509. } : (value = tween(value), function(node) {
  9510. node[ns][id].tween.set(name, value);
  9511. }));
  9512. }
  9513. d3_transitionPrototype.attr = function(nameNS, value) {
  9514. if (arguments.length < 2) {
  9515. for (value in nameNS) this.attr(value, nameNS[value]);
  9516. return this;
  9517. }
  9518. var interpolate = nameNS == "transform" ? d3_interpolateTransform : d3_interpolate, name = d3.ns.qualify(nameNS);
  9519. function attrNull() {
  9520. this.removeAttribute(name);
  9521. }
  9522. function attrNullNS() {
  9523. this.removeAttributeNS(name.space, name.local);
  9524. }
  9525. function attrTween(b) {
  9526. return b == null ? attrNull : (b += "", function() {
  9527. var a = this.getAttribute(name), i;
  9528. return a !== b && (i = interpolate(a, b), function(t) {
  9529. this.setAttribute(name, i(t));
  9530. });
  9531. });
  9532. }
  9533. function attrTweenNS(b) {
  9534. return b == null ? attrNullNS : (b += "", function() {
  9535. var a = this.getAttributeNS(name.space, name.local), i;
  9536. return a !== b && (i = interpolate(a, b), function(t) {
  9537. this.setAttributeNS(name.space, name.local, i(t));
  9538. });
  9539. });
  9540. }
  9541. return d3_transition_tween(this, "attr." + nameNS, value, name.local ? attrTweenNS : attrTween);
  9542. };
  9543. d3_transitionPrototype.attrTween = function(nameNS, tween) {
  9544. var name = d3.ns.qualify(nameNS);
  9545. function attrTween(d, i) {
  9546. var f = tween.call(this, d, i, this.getAttribute(name));
  9547. return f && function(t) {
  9548. this.setAttribute(name, f(t));
  9549. };
  9550. }
  9551. function attrTweenNS(d, i) {
  9552. var f = tween.call(this, d, i, this.getAttributeNS(name.space, name.local));
  9553. return f && function(t) {
  9554. this.setAttributeNS(name.space, name.local, f(t));
  9555. };
  9556. }
  9557. return this.tween("attr." + nameNS, name.local ? attrTweenNS : attrTween);
  9558. };
  9559. d3_transitionPrototype.style = function(name, value, priority) {
  9560. var n = arguments.length;
  9561. if (n < 3) {
  9562. if (typeof name !== "string") {
  9563. if (n < 2) value = "";
  9564. for (priority in name) this.style(priority, name[priority], value);
  9565. return this;
  9566. }
  9567. priority = "";
  9568. }
  9569. function styleNull() {
  9570. this.style.removeProperty(name);
  9571. }
  9572. function styleString(b) {
  9573. return b == null ? styleNull : (b += "", function() {
  9574. var a = d3_window(this).getComputedStyle(this, null).getPropertyValue(name), i;
  9575. return a !== b && (i = d3_interpolate(a, b), function(t) {
  9576. this.style.setProperty(name, i(t), priority);
  9577. });
  9578. });
  9579. }
  9580. return d3_transition_tween(this, "style." + name, value, styleString);
  9581. };
  9582. d3_transitionPrototype.styleTween = function(name, tween, priority) {
  9583. if (arguments.length < 3) priority = "";
  9584. function styleTween(d, i) {
  9585. var f = tween.call(this, d, i, d3_window(this).getComputedStyle(this, null).getPropertyValue(name));
  9586. return f && function(t) {
  9587. this.style.setProperty(name, f(t), priority);
  9588. };
  9589. }
  9590. return this.tween("style." + name, styleTween);
  9591. };
  9592. d3_transitionPrototype.text = function(value) {
  9593. return d3_transition_tween(this, "text", value, d3_transition_text);
  9594. };
  9595. function d3_transition_text(b) {
  9596. if (b == null) b = "";
  9597. return function() {
  9598. this.textContent = b;
  9599. };
  9600. }
  9601. d3_transitionPrototype.remove = function() {
  9602. var ns = this.namespace;
  9603. return this.each("end.transition", function() {
  9604. var p;
  9605. if (this[ns].count < 2 && (p = this.parentNode)) p.removeChild(this);
  9606. });
  9607. };
  9608. d3_transitionPrototype.ease = function(value) {
  9609. var id = this.id, ns = this.namespace;
  9610. if (arguments.length < 1) return this.node()[ns][id].ease;
  9611. if (typeof value !== "function") value = d3.ease.apply(d3, arguments);
  9612. return d3_selection_each(this, function(node) {
  9613. node[ns][id].ease = value;
  9614. });
  9615. };
  9616. d3_transitionPrototype.delay = function(value) {
  9617. var id = this.id, ns = this.namespace;
  9618. if (arguments.length < 1) return this.node()[ns][id].delay;
  9619. return d3_selection_each(this, typeof value === "function" ? function(node, i, j) {
  9620. node[ns][id].delay = +value.call(node, node.__data__, i, j);
  9621. } : (value = +value, function(node) {
  9622. node[ns][id].delay = value;
  9623. }));
  9624. };
  9625. d3_transitionPrototype.duration = function(value) {
  9626. var id = this.id, ns = this.namespace;
  9627. if (arguments.length < 1) return this.node()[ns][id].duration;
  9628. return d3_selection_each(this, typeof value === "function" ? function(node, i, j) {
  9629. node[ns][id].duration = Math.max(1, value.call(node, node.__data__, i, j));
  9630. } : (value = Math.max(1, value), function(node) {
  9631. node[ns][id].duration = value;
  9632. }));
  9633. };
  9634. d3_transitionPrototype.each = function(type, listener) {
  9635. var id = this.id, ns = this.namespace;
  9636. if (arguments.length < 2) {
  9637. var inherit = d3_transitionInherit, inheritId = d3_transitionInheritId;
  9638. try {
  9639. d3_transitionInheritId = id;
  9640. d3_selection_each(this, function(node, i, j) {
  9641. d3_transitionInherit = node[ns][id];
  9642. type.call(node, node.__data__, i, j);
  9643. });
  9644. } finally {
  9645. d3_transitionInherit = inherit;
  9646. d3_transitionInheritId = inheritId;
  9647. }
  9648. } else {
  9649. d3_selection_each(this, function(node) {
  9650. var transition = node[ns][id];
  9651. (transition.event || (transition.event = d3.dispatch("start", "end", "interrupt"))).on(type, listener);
  9652. });
  9653. }
  9654. return this;
  9655. };
  9656. d3_transitionPrototype.transition = function() {
  9657. var id0 = this.id, id1 = ++d3_transitionId, ns = this.namespace, subgroups = [], subgroup, group, node, transition;
  9658. for (var j = 0, m = this.length; j < m; j++) {
  9659. subgroups.push(subgroup = []);
  9660. for (var group = this[j], i = 0, n = group.length; i < n; i++) {
  9661. if (node = group[i]) {
  9662. transition = node[ns][id0];
  9663. d3_transitionNode(node, i, ns, id1, {
  9664. time: transition.time,
  9665. ease: transition.ease,
  9666. delay: transition.delay + transition.duration,
  9667. duration: transition.duration
  9668. });
  9669. }
  9670. subgroup.push(node);
  9671. }
  9672. }
  9673. return d3_transition(subgroups, ns, id1);
  9674. };
  9675. function d3_transitionNamespace(name) {
  9676. return name == null ? "__transition__" : "__transition_" + name + "__";
  9677. }
  9678. function d3_transitionNode(node, i, ns, id, inherit) {
  9679. var lock = node[ns] || (node[ns] = {
  9680. active: 0,
  9681. count: 0
  9682. }), transition = lock[id], time, timer, duration, ease, tweens;
  9683. function schedule(elapsed) {
  9684. var delay = transition.delay;
  9685. timer.t = delay + time;
  9686. if (delay <= elapsed) return start(elapsed - delay);
  9687. timer.c = start;
  9688. }
  9689. function start(elapsed) {
  9690. var activeId = lock.active, active = lock[activeId];
  9691. if (active) {
  9692. active.timer.c = null;
  9693. active.timer.t = NaN;
  9694. --lock.count;
  9695. delete lock[activeId];
  9696. active.event && active.event.interrupt.call(node, node.__data__, active.index);
  9697. }
  9698. for (var cancelId in lock) {
  9699. if (+cancelId < id) {
  9700. var cancel = lock[cancelId];
  9701. cancel.timer.c = null;
  9702. cancel.timer.t = NaN;
  9703. --lock.count;
  9704. delete lock[cancelId];
  9705. }
  9706. }
  9707. timer.c = tick;
  9708. d3_timer(function() {
  9709. if (timer.c && tick(elapsed || 1)) {
  9710. timer.c = null;
  9711. timer.t = NaN;
  9712. }
  9713. return 1;
  9714. }, 0, time);
  9715. lock.active = id;
  9716. transition.event && transition.event.start.call(node, node.__data__, i);
  9717. tweens = [];
  9718. transition.tween.forEach(function(key, value) {
  9719. if (value = value.call(node, node.__data__, i)) {
  9720. tweens.push(value);
  9721. }
  9722. });
  9723. ease = transition.ease;
  9724. duration = transition.duration;
  9725. }
  9726. function tick(elapsed) {
  9727. var t = elapsed / duration, e = ease(t), n = tweens.length;
  9728. while (n > 0) {
  9729. tweens[--n].call(node, e);
  9730. }
  9731. if (t >= 1) {
  9732. transition.event && transition.event.end.call(node, node.__data__, i);
  9733. if (--lock.count) delete lock[id]; else delete node[ns];
  9734. return 1;
  9735. }
  9736. }
  9737. if (!transition) {
  9738. time = inherit.time;
  9739. timer = d3_timer(schedule, 0, time);
  9740. transition = lock[id] = {
  9741. tween: new d3_Map(),
  9742. time: time,
  9743. timer: timer,
  9744. delay: inherit.delay,
  9745. duration: inherit.duration,
  9746. ease: inherit.ease,
  9747. index: i
  9748. };
  9749. inherit = null;
  9750. ++lock.count;
  9751. }
  9752. }
  9753. d3.svg.axis = function() {
  9754. var scale = d3.scale.linear(), orient = d3_svg_axisDefaultOrient, innerTickSize = 6, outerTickSize = 6, tickPadding = 3, tickArguments_ = [ 10 ], tickValues = null, tickFormat_;
  9755. function axis(g) {
  9756. g.each(function() {
  9757. var g = d3.select(this);
  9758. var scale0 = this.__chart__ || scale, scale1 = this.__chart__ = scale.copy();
  9759. var ticks = tickValues == null ? scale1.ticks ? scale1.ticks.apply(scale1, tickArguments_) : scale1.domain() : tickValues, tickFormat = tickFormat_ == null ? scale1.tickFormat ? scale1.tickFormat.apply(scale1, tickArguments_) : d3_identity : tickFormat_, tick = g.selectAll(".tick").data(ticks, scale1), tickEnter = tick.enter().insert("g", ".domain").attr("class", "tick").style("opacity", ε), tickExit = d3.transition(tick.exit()).style("opacity", ε).remove(), tickUpdate = d3.transition(tick.order()).style("opacity", 1), tickSpacing = Math.max(innerTickSize, 0) + tickPadding, tickTransform;
  9760. var range = d3_scaleRange(scale1), path = g.selectAll(".domain").data([ 0 ]), pathUpdate = (path.enter().append("path").attr("class", "domain"),
  9761. d3.transition(path));
  9762. tickEnter.append("line");
  9763. tickEnter.append("text");
  9764. var lineEnter = tickEnter.select("line"), lineUpdate = tickUpdate.select("line"), text = tick.select("text").text(tickFormat), textEnter = tickEnter.select("text"), textUpdate = tickUpdate.select("text"), sign = orient === "top" || orient === "left" ? -1 : 1, x1, x2, y1, y2;
  9765. if (orient === "bottom" || orient === "top") {
  9766. tickTransform = d3_svg_axisX, x1 = "x", y1 = "y", x2 = "x2", y2 = "y2";
  9767. text.attr("dy", sign < 0 ? "0em" : ".71em").style("text-anchor", "middle");
  9768. pathUpdate.attr("d", "M" + range[0] + "," + sign * outerTickSize + "V0H" + range[1] + "V" + sign * outerTickSize);
  9769. } else {
  9770. tickTransform = d3_svg_axisY, x1 = "y", y1 = "x", x2 = "y2", y2 = "x2";
  9771. text.attr("dy", ".32em").style("text-anchor", sign < 0 ? "end" : "start");
  9772. pathUpdate.attr("d", "M" + sign * outerTickSize + "," + range[0] + "H0V" + range[1] + "H" + sign * outerTickSize);
  9773. }
  9774. lineEnter.attr(y2, sign * innerTickSize);
  9775. textEnter.attr(y1, sign * tickSpacing);
  9776. lineUpdate.attr(x2, 0).attr(y2, sign * innerTickSize);
  9777. textUpdate.attr(x1, 0).attr(y1, sign * tickSpacing);
  9778. if (scale1.rangeBand) {
  9779. var x = scale1, dx = x.rangeBand() / 2;
  9780. scale0 = scale1 = function(d) {
  9781. return x(d) + dx;
  9782. };
  9783. } else if (scale0.rangeBand) {
  9784. scale0 = scale1;
  9785. } else {
  9786. tickExit.call(tickTransform, scale1, scale0);
  9787. }
  9788. tickEnter.call(tickTransform, scale0, scale1);
  9789. tickUpdate.call(tickTransform, scale1, scale1);
  9790. });
  9791. }
  9792. axis.scale = function(x) {
  9793. if (!arguments.length) return scale;
  9794. scale = x;
  9795. return axis;
  9796. };
  9797. axis.orient = function(x) {
  9798. if (!arguments.length) return orient;
  9799. orient = x in d3_svg_axisOrients ? x + "" : d3_svg_axisDefaultOrient;
  9800. return axis;
  9801. };
  9802. axis.ticks = function() {
  9803. if (!arguments.length) return tickArguments_;
  9804. tickArguments_ = d3_array(arguments);
  9805. return axis;
  9806. };
  9807. axis.tickValues = function(x) {
  9808. if (!arguments.length) return tickValues;
  9809. tickValues = x;
  9810. return axis;
  9811. };
  9812. axis.tickFormat = function(x) {
  9813. if (!arguments.length) return tickFormat_;
  9814. tickFormat_ = x;
  9815. return axis;
  9816. };
  9817. axis.tickSize = function(x) {
  9818. var n = arguments.length;
  9819. if (!n) return innerTickSize;
  9820. innerTickSize = +x;
  9821. outerTickSize = +arguments[n - 1];
  9822. return axis;
  9823. };
  9824. axis.innerTickSize = function(x) {
  9825. if (!arguments.length) return innerTickSize;
  9826. innerTickSize = +x;
  9827. return axis;
  9828. };
  9829. axis.outerTickSize = function(x) {
  9830. if (!arguments.length) return outerTickSize;
  9831. outerTickSize = +x;
  9832. return axis;
  9833. };
  9834. axis.tickPadding = function(x) {
  9835. if (!arguments.length) return tickPadding;
  9836. tickPadding = +x;
  9837. return axis;
  9838. };
  9839. axis.tickSubdivide = function() {
  9840. return arguments.length && axis;
  9841. };
  9842. return axis;
  9843. };
  9844. var d3_svg_axisDefaultOrient = "bottom", d3_svg_axisOrients = {
  9845. top: 1,
  9846. right: 1,
  9847. bottom: 1,
  9848. left: 1
  9849. };
  9850. function d3_svg_axisX(selection, x0, x1) {
  9851. selection.attr("transform", function(d) {
  9852. var v0 = x0(d);
  9853. return "translate(" + (isFinite(v0) ? v0 : x1(d)) + ",0)";
  9854. });
  9855. }
  9856. function d3_svg_axisY(selection, y0, y1) {
  9857. selection.attr("transform", function(d) {
  9858. var v0 = y0(d);
  9859. return "translate(0," + (isFinite(v0) ? v0 : y1(d)) + ")";
  9860. });
  9861. }
  9862. d3.svg.brush = function() {
  9863. var event = d3_eventDispatch(brush, "brushstart", "brush", "brushend"), x = null, y = null, xExtent = [ 0, 0 ], yExtent = [ 0, 0 ], xExtentDomain, yExtentDomain, xClamp = true, yClamp = true, resizes = d3_svg_brushResizes[0];
  9864. function brush(g) {
  9865. g.each(function() {
  9866. var g = d3.select(this).style("pointer-events", "all").style("-webkit-tap-highlight-color", "rgba(0,0,0,0)").on("mousedown.brush", brushstart).on("touchstart.brush", brushstart);
  9867. var background = g.selectAll(".background").data([ 0 ]);
  9868. background.enter().append("rect").attr("class", "background").style("visibility", "hidden").style("cursor", "crosshair");
  9869. g.selectAll(".extent").data([ 0 ]).enter().append("rect").attr("class", "extent").style("cursor", "move");
  9870. var resize = g.selectAll(".resize").data(resizes, d3_identity);
  9871. resize.exit().remove();
  9872. resize.enter().append("g").attr("class", function(d) {
  9873. return "resize " + d;
  9874. }).style("cursor", function(d) {
  9875. return d3_svg_brushCursor[d];
  9876. }).append("rect").attr("x", function(d) {
  9877. return /[ew]$/.test(d) ? -3 : null;
  9878. }).attr("y", function(d) {
  9879. return /^[ns]/.test(d) ? -3 : null;
  9880. }).attr("width", 6).attr("height", 6).style("visibility", "hidden");
  9881. resize.style("display", brush.empty() ? "none" : null);
  9882. var gUpdate = d3.transition(g), backgroundUpdate = d3.transition(background), range;
  9883. if (x) {
  9884. range = d3_scaleRange(x);
  9885. backgroundUpdate.attr("x", range[0]).attr("width", range[1] - range[0]);
  9886. redrawX(gUpdate);
  9887. }
  9888. if (y) {
  9889. range = d3_scaleRange(y);
  9890. backgroundUpdate.attr("y", range[0]).attr("height", range[1] - range[0]);
  9891. redrawY(gUpdate);
  9892. }
  9893. redraw(gUpdate);
  9894. });
  9895. }
  9896. brush.event = function(g) {
  9897. g.each(function() {
  9898. var event_ = event.of(this, arguments), extent1 = {
  9899. x: xExtent,
  9900. y: yExtent,
  9901. i: xExtentDomain,
  9902. j: yExtentDomain
  9903. }, extent0 = this.__chart__ || extent1;
  9904. this.__chart__ = extent1;
  9905. if (d3_transitionInheritId) {
  9906. d3.select(this).transition().each("start.brush", function() {
  9907. xExtentDomain = extent0.i;
  9908. yExtentDomain = extent0.j;
  9909. xExtent = extent0.x;
  9910. yExtent = extent0.y;
  9911. event_({
  9912. type: "brushstart"
  9913. });
  9914. }).tween("brush:brush", function() {
  9915. var xi = d3_interpolateArray(xExtent, extent1.x), yi = d3_interpolateArray(yExtent, extent1.y);
  9916. xExtentDomain = yExtentDomain = null;
  9917. return function(t) {
  9918. xExtent = extent1.x = xi(t);
  9919. yExtent = extent1.y = yi(t);
  9920. event_({
  9921. type: "brush",
  9922. mode: "resize"
  9923. });
  9924. };
  9925. }).each("end.brush", function() {
  9926. xExtentDomain = extent1.i;
  9927. yExtentDomain = extent1.j;
  9928. event_({
  9929. type: "brush",
  9930. mode: "resize"
  9931. });
  9932. event_({
  9933. type: "brushend"
  9934. });
  9935. });
  9936. } else {
  9937. event_({
  9938. type: "brushstart"
  9939. });
  9940. event_({
  9941. type: "brush",
  9942. mode: "resize"
  9943. });
  9944. event_({
  9945. type: "brushend"
  9946. });
  9947. }
  9948. });
  9949. };
  9950. function redraw(g) {
  9951. g.selectAll(".resize").attr("transform", function(d) {
  9952. return "translate(" + xExtent[+/e$/.test(d)] + "," + yExtent[+/^s/.test(d)] + ")";
  9953. });
  9954. }
  9955. function redrawX(g) {
  9956. g.select(".extent").attr("x", xExtent[0]);
  9957. g.selectAll(".extent,.n>rect,.s>rect").attr("width", xExtent[1] - xExtent[0]);
  9958. }
  9959. function redrawY(g) {
  9960. g.select(".extent").attr("y", yExtent[0]);
  9961. g.selectAll(".extent,.e>rect,.w>rect").attr("height", yExtent[1] - yExtent[0]);
  9962. }
  9963. function brushstart() {
  9964. var target = this, eventTarget = d3.select(d3.event.target), event_ = event.of(target, arguments), g = d3.select(target), resizing = eventTarget.datum(), resizingX = !/^(n|s)$/.test(resizing) && x, resizingY = !/^(e|w)$/.test(resizing) && y, dragging = eventTarget.classed("extent"), dragRestore = d3_event_dragSuppress(target), center, origin = d3.mouse(target), offset;
  9965. var w = d3.select(d3_window(target)).on("keydown.brush", keydown).on("keyup.brush", keyup);
  9966. if (d3.event.changedTouches) {
  9967. w.on("touchmove.brush", brushmove).on("touchend.brush", brushend);
  9968. } else {
  9969. w.on("mousemove.brush", brushmove).on("mouseup.brush", brushend);
  9970. }
  9971. g.interrupt().selectAll("*").interrupt();
  9972. if (dragging) {
  9973. origin[0] = xExtent[0] - origin[0];
  9974. origin[1] = yExtent[0] - origin[1];
  9975. } else if (resizing) {
  9976. var ex = +/w$/.test(resizing), ey = +/^n/.test(resizing);
  9977. offset = [ xExtent[1 - ex] - origin[0], yExtent[1 - ey] - origin[1] ];
  9978. origin[0] = xExtent[ex];
  9979. origin[1] = yExtent[ey];
  9980. } else if (d3.event.altKey) center = origin.slice();
  9981. g.style("pointer-events", "none").selectAll(".resize").style("display", null);
  9982. d3.select("body").style("cursor", eventTarget.style("cursor"));
  9983. event_({
  9984. type: "brushstart"
  9985. });
  9986. brushmove();
  9987. function keydown() {
  9988. if (d3.event.keyCode == 32) {
  9989. if (!dragging) {
  9990. center = null;
  9991. origin[0] -= xExtent[1];
  9992. origin[1] -= yExtent[1];
  9993. dragging = 2;
  9994. }
  9995. d3_eventPreventDefault();
  9996. }
  9997. }
  9998. function keyup() {
  9999. if (d3.event.keyCode == 32 && dragging == 2) {
  10000. origin[0] += xExtent[1];
  10001. origin[1] += yExtent[1];
  10002. dragging = 0;
  10003. d3_eventPreventDefault();
  10004. }
  10005. }
  10006. function brushmove() {
  10007. var point = d3.mouse(target), moved = false;
  10008. if (offset) {
  10009. point[0] += offset[0];
  10010. point[1] += offset[1];
  10011. }
  10012. if (!dragging) {
  10013. if (d3.event.altKey) {
  10014. if (!center) center = [ (xExtent[0] + xExtent[1]) / 2, (yExtent[0] + yExtent[1]) / 2 ];
  10015. origin[0] = xExtent[+(point[0] < center[0])];
  10016. origin[1] = yExtent[+(point[1] < center[1])];
  10017. } else center = null;
  10018. }
  10019. if (resizingX && move1(point, x, 0)) {
  10020. redrawX(g);
  10021. moved = true;
  10022. }
  10023. if (resizingY && move1(point, y, 1)) {
  10024. redrawY(g);
  10025. moved = true;
  10026. }
  10027. if (moved) {
  10028. redraw(g);
  10029. event_({
  10030. type: "brush",
  10031. mode: dragging ? "move" : "resize"
  10032. });
  10033. }
  10034. }
  10035. function move1(point, scale, i) {
  10036. var range = d3_scaleRange(scale), r0 = range[0], r1 = range[1], position = origin[i], extent = i ? yExtent : xExtent, size = extent[1] - extent[0], min, max;
  10037. if (dragging) {
  10038. r0 -= position;
  10039. r1 -= size + position;
  10040. }
  10041. min = (i ? yClamp : xClamp) ? Math.max(r0, Math.min(r1, point[i])) : point[i];
  10042. if (dragging) {
  10043. max = (min += position) + size;
  10044. } else {
  10045. if (center) position = Math.max(r0, Math.min(r1, 2 * center[i] - min));
  10046. if (position < min) {
  10047. max = min;
  10048. min = position;
  10049. } else {
  10050. max = position;
  10051. }
  10052. }
  10053. if (extent[0] != min || extent[1] != max) {
  10054. if (i) yExtentDomain = null; else xExtentDomain = null;
  10055. extent[0] = min;
  10056. extent[1] = max;
  10057. return true;
  10058. }
  10059. }
  10060. function brushend() {
  10061. brushmove();
  10062. g.style("pointer-events", "all").selectAll(".resize").style("display", brush.empty() ? "none" : null);
  10063. d3.select("body").style("cursor", null);
  10064. w.on("mousemove.brush", null).on("mouseup.brush", null).on("touchmove.brush", null).on("touchend.brush", null).on("keydown.brush", null).on("keyup.brush", null);
  10065. dragRestore();
  10066. event_({
  10067. type: "brushend"
  10068. });
  10069. }
  10070. }
  10071. brush.x = function(z) {
  10072. if (!arguments.length) return x;
  10073. x = z;
  10074. resizes = d3_svg_brushResizes[!x << 1 | !y];
  10075. return brush;
  10076. };
  10077. brush.y = function(z) {
  10078. if (!arguments.length) return y;
  10079. y = z;
  10080. resizes = d3_svg_brushResizes[!x << 1 | !y];
  10081. return brush;
  10082. };
  10083. brush.clamp = function(z) {
  10084. if (!arguments.length) return x && y ? [ xClamp, yClamp ] : x ? xClamp : y ? yClamp : null;
  10085. if (x && y) xClamp = !!z[0], yClamp = !!z[1]; else if (x) xClamp = !!z; else if (y) yClamp = !!z;
  10086. return brush;
  10087. };
  10088. brush.extent = function(z) {
  10089. var x0, x1, y0, y1, t;
  10090. if (!arguments.length) {
  10091. if (x) {
  10092. if (xExtentDomain) {
  10093. x0 = xExtentDomain[0], x1 = xExtentDomain[1];
  10094. } else {
  10095. x0 = xExtent[0], x1 = xExtent[1];
  10096. if (x.invert) x0 = x.invert(x0), x1 = x.invert(x1);
  10097. if (x1 < x0) t = x0, x0 = x1, x1 = t;
  10098. }
  10099. }
  10100. if (y) {
  10101. if (yExtentDomain) {
  10102. y0 = yExtentDomain[0], y1 = yExtentDomain[1];
  10103. } else {
  10104. y0 = yExtent[0], y1 = yExtent[1];
  10105. if (y.invert) y0 = y.invert(y0), y1 = y.invert(y1);
  10106. if (y1 < y0) t = y0, y0 = y1, y1 = t;
  10107. }
  10108. }
  10109. return x && y ? [ [ x0, y0 ], [ x1, y1 ] ] : x ? [ x0, x1 ] : y && [ y0, y1 ];
  10110. }
  10111. if (x) {
  10112. x0 = z[0], x1 = z[1];
  10113. if (y) x0 = x0[0], x1 = x1[0];
  10114. xExtentDomain = [ x0, x1 ];
  10115. if (x.invert) x0 = x(x0), x1 = x(x1);
  10116. if (x1 < x0) t = x0, x0 = x1, x1 = t;
  10117. if (x0 != xExtent[0] || x1 != xExtent[1]) xExtent = [ x0, x1 ];
  10118. }
  10119. if (y) {
  10120. y0 = z[0], y1 = z[1];
  10121. if (x) y0 = y0[1], y1 = y1[1];
  10122. yExtentDomain = [ y0, y1 ];
  10123. if (y.invert) y0 = y(y0), y1 = y(y1);
  10124. if (y1 < y0) t = y0, y0 = y1, y1 = t;
  10125. if (y0 != yExtent[0] || y1 != yExtent[1]) yExtent = [ y0, y1 ];
  10126. }
  10127. return brush;
  10128. };
  10129. brush.clear = function() {
  10130. if (!brush.empty()) {
  10131. xExtent = [ 0, 0 ], yExtent = [ 0, 0 ];
  10132. xExtentDomain = yExtentDomain = null;
  10133. }
  10134. return brush;
  10135. };
  10136. brush.empty = function() {
  10137. return !!x && xExtent[0] == xExtent[1] || !!y && yExtent[0] == yExtent[1];
  10138. };
  10139. return d3.rebind(brush, event, "on");
  10140. };
  10141. var d3_svg_brushCursor = {
  10142. n: "ns-resize",
  10143. e: "ew-resize",
  10144. s: "ns-resize",
  10145. w: "ew-resize",
  10146. nw: "nwse-resize",
  10147. ne: "nesw-resize",
  10148. se: "nwse-resize",
  10149. sw: "nesw-resize"
  10150. };
  10151. var d3_svg_brushResizes = [ [ "n", "e", "s", "w", "nw", "ne", "se", "sw" ], [ "e", "w" ], [ "n", "s" ], [] ];
  10152. var d3_time_format = d3_time.format = d3_locale_enUS.timeFormat;
  10153. var d3_time_formatUtc = d3_time_format.utc;
  10154. var d3_time_formatIso = d3_time_formatUtc("%Y-%m-%dT%H:%M:%S.%LZ");
  10155. d3_time_format.iso = Date.prototype.toISOString && +new Date("2000-01-01T00:00:00.000Z") ? d3_time_formatIsoNative : d3_time_formatIso;
  10156. function d3_time_formatIsoNative(date) {
  10157. return date.toISOString();
  10158. }
  10159. d3_time_formatIsoNative.parse = function(string) {
  10160. var date = new Date(string);
  10161. return isNaN(date) ? null : date;
  10162. };
  10163. d3_time_formatIsoNative.toString = d3_time_formatIso.toString;
  10164. d3_time.second = d3_time_interval(function(date) {
  10165. return new d3_date(Math.floor(date / 1e3) * 1e3);
  10166. }, function(date, offset) {
  10167. date.setTime(date.getTime() + Math.floor(offset) * 1e3);
  10168. }, function(date) {
  10169. return date.getSeconds();
  10170. });
  10171. d3_time.seconds = d3_time.second.range;
  10172. d3_time.seconds.utc = d3_time.second.utc.range;
  10173. d3_time.minute = d3_time_interval(function(date) {
  10174. return new d3_date(Math.floor(date / 6e4) * 6e4);
  10175. }, function(date, offset) {
  10176. date.setTime(date.getTime() + Math.floor(offset) * 6e4);
  10177. }, function(date) {
  10178. return date.getMinutes();
  10179. });
  10180. d3_time.minutes = d3_time.minute.range;
  10181. d3_time.minutes.utc = d3_time.minute.utc.range;
  10182. d3_time.hour = d3_time_interval(function(date) {
  10183. var timezone = date.getTimezoneOffset() / 60;
  10184. return new d3_date((Math.floor(date / 36e5 - timezone) + timezone) * 36e5);
  10185. }, function(date, offset) {
  10186. date.setTime(date.getTime() + Math.floor(offset) * 36e5);
  10187. }, function(date) {
  10188. return date.getHours();
  10189. });
  10190. d3_time.hours = d3_time.hour.range;
  10191. d3_time.hours.utc = d3_time.hour.utc.range;
  10192. d3_time.month = d3_time_interval(function(date) {
  10193. date = d3_time.day(date);
  10194. date.setDate(1);
  10195. return date;
  10196. }, function(date, offset) {
  10197. date.setMonth(date.getMonth() + offset);
  10198. }, function(date) {
  10199. return date.getMonth();
  10200. });
  10201. d3_time.months = d3_time.month.range;
  10202. d3_time.months.utc = d3_time.month.utc.range;
  10203. function d3_time_scale(linear, methods, format) {
  10204. function scale(x) {
  10205. return linear(x);
  10206. }
  10207. scale.invert = function(x) {
  10208. return d3_time_scaleDate(linear.invert(x));
  10209. };
  10210. scale.domain = function(x) {
  10211. if (!arguments.length) return linear.domain().map(d3_time_scaleDate);
  10212. linear.domain(x);
  10213. return scale;
  10214. };
  10215. function tickMethod(extent, count) {
  10216. var span = extent[1] - extent[0], target = span / count, i = d3.bisect(d3_time_scaleSteps, target);
  10217. return i == d3_time_scaleSteps.length ? [ methods.year, d3_scale_linearTickRange(extent.map(function(d) {
  10218. return d / 31536e6;
  10219. }), count)[2] ] : !i ? [ d3_time_scaleMilliseconds, d3_scale_linearTickRange(extent, count)[2] ] : methods[target / d3_time_scaleSteps[i - 1] < d3_time_scaleSteps[i] / target ? i - 1 : i];
  10220. }
  10221. scale.nice = function(interval, skip) {
  10222. var domain = scale.domain(), extent = d3_scaleExtent(domain), method = interval == null ? tickMethod(extent, 10) : typeof interval === "number" && tickMethod(extent, interval);
  10223. if (method) interval = method[0], skip = method[1];
  10224. function skipped(date) {
  10225. return !isNaN(date) && !interval.range(date, d3_time_scaleDate(+date + 1), skip).length;
  10226. }
  10227. return scale.domain(d3_scale_nice(domain, skip > 1 ? {
  10228. floor: function(date) {
  10229. while (skipped(date = interval.floor(date))) date = d3_time_scaleDate(date - 1);
  10230. return date;
  10231. },
  10232. ceil: function(date) {
  10233. while (skipped(date = interval.ceil(date))) date = d3_time_scaleDate(+date + 1);
  10234. return date;
  10235. }
  10236. } : interval));
  10237. };
  10238. scale.ticks = function(interval, skip) {
  10239. var extent = d3_scaleExtent(scale.domain()), method = interval == null ? tickMethod(extent, 10) : typeof interval === "number" ? tickMethod(extent, interval) : !interval.range && [ {
  10240. range: interval
  10241. }, skip ];
  10242. if (method) interval = method[0], skip = method[1];
  10243. return interval.range(extent[0], d3_time_scaleDate(+extent[1] + 1), skip < 1 ? 1 : skip);
  10244. };
  10245. scale.tickFormat = function() {
  10246. return format;
  10247. };
  10248. scale.copy = function() {
  10249. return d3_time_scale(linear.copy(), methods, format);
  10250. };
  10251. return d3_scale_linearRebind(scale, linear);
  10252. }
  10253. function d3_time_scaleDate(t) {
  10254. return new Date(t);
  10255. }
  10256. var d3_time_scaleSteps = [ 1e3, 5e3, 15e3, 3e4, 6e4, 3e5, 9e5, 18e5, 36e5, 108e5, 216e5, 432e5, 864e5, 1728e5, 6048e5, 2592e6, 7776e6, 31536e6 ];
  10257. var d3_time_scaleLocalMethods = [ [ d3_time.second, 1 ], [ d3_time.second, 5 ], [ d3_time.second, 15 ], [ d3_time.second, 30 ], [ d3_time.minute, 1 ], [ d3_time.minute, 5 ], [ d3_time.minute, 15 ], [ d3_time.minute, 30 ], [ d3_time.hour, 1 ], [ d3_time.hour, 3 ], [ d3_time.hour, 6 ], [ d3_time.hour, 12 ], [ d3_time.day, 1 ], [ d3_time.day, 2 ], [ d3_time.week, 1 ], [ d3_time.month, 1 ], [ d3_time.month, 3 ], [ d3_time.year, 1 ] ];
  10258. var d3_time_scaleLocalFormat = d3_time_format.multi([ [ ".%L", function(d) {
  10259. return d.getMilliseconds();
  10260. } ], [ ":%S", function(d) {
  10261. return d.getSeconds();
  10262. } ], [ "%I:%M", function(d) {
  10263. return d.getMinutes();
  10264. } ], [ "%I %p", function(d) {
  10265. return d.getHours();
  10266. } ], [ "%a %d", function(d) {
  10267. return d.getDay() && d.getDate() != 1;
  10268. } ], [ "%b %d", function(d) {
  10269. return d.getDate() != 1;
  10270. } ], [ "%B", function(d) {
  10271. return d.getMonth();
  10272. } ], [ "%Y", d3_true ] ]);
  10273. var d3_time_scaleMilliseconds = {
  10274. range: function(start, stop, step) {
  10275. return d3.range(Math.ceil(start / step) * step, +stop, step).map(d3_time_scaleDate);
  10276. },
  10277. floor: d3_identity,
  10278. ceil: d3_identity
  10279. };
  10280. d3_time_scaleLocalMethods.year = d3_time.year;
  10281. d3_time.scale = function() {
  10282. return d3_time_scale(d3.scale.linear(), d3_time_scaleLocalMethods, d3_time_scaleLocalFormat);
  10283. };
  10284. var d3_time_scaleUtcMethods = d3_time_scaleLocalMethods.map(function(m) {
  10285. return [ m[0].utc, m[1] ];
  10286. });
  10287. var d3_time_scaleUtcFormat = d3_time_formatUtc.multi([ [ ".%L", function(d) {
  10288. return d.getUTCMilliseconds();
  10289. } ], [ ":%S", function(d) {
  10290. return d.getUTCSeconds();
  10291. } ], [ "%I:%M", function(d) {
  10292. return d.getUTCMinutes();
  10293. } ], [ "%I %p", function(d) {
  10294. return d.getUTCHours();
  10295. } ], [ "%a %d", function(d) {
  10296. return d.getUTCDay() && d.getUTCDate() != 1;
  10297. } ], [ "%b %d", function(d) {
  10298. return d.getUTCDate() != 1;
  10299. } ], [ "%B", function(d) {
  10300. return d.getUTCMonth();
  10301. } ], [ "%Y", d3_true ] ]);
  10302. d3_time_scaleUtcMethods.year = d3_time.year.utc;
  10303. d3_time.scale.utc = function() {
  10304. return d3_time_scale(d3.scale.linear(), d3_time_scaleUtcMethods, d3_time_scaleUtcFormat);
  10305. };
  10306. d3.text = d3_xhrType(function(request) {
  10307. return request.responseText;
  10308. });
  10309. d3.json = function(url, callback) {
  10310. return d3_xhr(url, "application/json", d3_json, callback);
  10311. };
  10312. function d3_json(request) {
  10313. return JSON.parse(request.responseText);
  10314. }
  10315. d3.html = function(url, callback) {
  10316. return d3_xhr(url, "text/html", d3_html, callback);
  10317. };
  10318. function d3_html(request) {
  10319. var range = d3_document.createRange();
  10320. range.selectNode(d3_document.body);
  10321. return range.createContextualFragment(request.responseText);
  10322. }
  10323. d3.xml = d3_xhrType(function(request) {
  10324. return request.responseXML;
  10325. });
  10326. if (typeof define === "function" && define.amd) this.d3 = d3, define(d3); else if (typeof module === "object" && module.exports) module.exports = d3; else this.d3 = d3;
  10327. }();
  10328. },{}],17:[function(_dereq_,module,exports){
  10329. (function (process,global){
  10330. /*!
  10331. * @overview es6-promise - a tiny implementation of Promises/A+.
  10332. * @copyright Copyright (c) 2014 Yehuda Katz, Tom Dale, Stefan Penner and contributors (Conversion to ES6 API by Jake Archibald)
  10333. * @license Licensed under MIT license
  10334. * See https://raw.githubusercontent.com/stefanpenner/es6-promise/master/LICENSE
  10335. * @version 3.3.1
  10336. */
  10337. (function (global, factory) {
  10338. typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
  10339. typeof define === 'function' && define.amd ? define(factory) :
  10340. (global.ES6Promise = factory());
  10341. }(this, (function () { 'use strict';
  10342. function objectOrFunction(x) {
  10343. return typeof x === 'function' || typeof x === 'object' && x !== null;
  10344. }
  10345. function isFunction(x) {
  10346. return typeof x === 'function';
  10347. }
  10348. var _isArray = undefined;
  10349. if (!Array.isArray) {
  10350. _isArray = function (x) {
  10351. return Object.prototype.toString.call(x) === '[object Array]';
  10352. };
  10353. } else {
  10354. _isArray = Array.isArray;
  10355. }
  10356. var isArray = _isArray;
  10357. var len = 0;
  10358. var vertxNext = undefined;
  10359. var customSchedulerFn = undefined;
  10360. var asap = function asap(callback, arg) {
  10361. queue[len] = callback;
  10362. queue[len + 1] = arg;
  10363. len += 2;
  10364. if (len === 2) {
  10365. // If len is 2, that means that we need to schedule an async flush.
  10366. // If additional callbacks are queued before the queue is flushed, they
  10367. // will be processed by this flush that we are scheduling.
  10368. if (customSchedulerFn) {
  10369. customSchedulerFn(flush);
  10370. } else {
  10371. scheduleFlush();
  10372. }
  10373. }
  10374. };
  10375. function setScheduler(scheduleFn) {
  10376. customSchedulerFn = scheduleFn;
  10377. }
  10378. function setAsap(asapFn) {
  10379. asap = asapFn;
  10380. }
  10381. var browserWindow = typeof window !== 'undefined' ? window : undefined;
  10382. var browserGlobal = browserWindow || {};
  10383. var BrowserMutationObserver = browserGlobal.MutationObserver || browserGlobal.WebKitMutationObserver;
  10384. var isNode = typeof self === 'undefined' && typeof process !== 'undefined' && ({}).toString.call(process) === '[object process]';
  10385. // test for web worker but not in IE10
  10386. var isWorker = typeof Uint8ClampedArray !== 'undefined' && typeof importScripts !== 'undefined' && typeof MessageChannel !== 'undefined';
  10387. // node
  10388. function useNextTick() {
  10389. // node version 0.10.x displays a deprecation warning when nextTick is used recursively
  10390. // see https://github.com/cujojs/when/issues/410 for details
  10391. return function () {
  10392. return process.nextTick(flush);
  10393. };
  10394. }
  10395. // vertx
  10396. function useVertxTimer() {
  10397. return function () {
  10398. vertxNext(flush);
  10399. };
  10400. }
  10401. function useMutationObserver() {
  10402. var iterations = 0;
  10403. var observer = new BrowserMutationObserver(flush);
  10404. var node = document.createTextNode('');
  10405. observer.observe(node, { characterData: true });
  10406. return function () {
  10407. node.data = iterations = ++iterations % 2;
  10408. };
  10409. }
  10410. // web worker
  10411. function useMessageChannel() {
  10412. var channel = new MessageChannel();
  10413. channel.port1.onmessage = flush;
  10414. return function () {
  10415. return channel.port2.postMessage(0);
  10416. };
  10417. }
  10418. function useSetTimeout() {
  10419. // Store setTimeout reference so es6-promise will be unaffected by
  10420. // other code modifying setTimeout (like sinon.useFakeTimers())
  10421. var globalSetTimeout = setTimeout;
  10422. return function () {
  10423. return globalSetTimeout(flush, 1);
  10424. };
  10425. }
  10426. var queue = new Array(1000);
  10427. function flush() {
  10428. for (var i = 0; i < len; i += 2) {
  10429. var callback = queue[i];
  10430. var arg = queue[i + 1];
  10431. callback(arg);
  10432. queue[i] = undefined;
  10433. queue[i + 1] = undefined;
  10434. }
  10435. len = 0;
  10436. }
  10437. function attemptVertx() {
  10438. try {
  10439. var r = _dereq_;
  10440. var vertx = r('vertx');
  10441. vertxNext = vertx.runOnLoop || vertx.runOnContext;
  10442. return useVertxTimer();
  10443. } catch (e) {
  10444. return useSetTimeout();
  10445. }
  10446. }
  10447. var scheduleFlush = undefined;
  10448. // Decide what async method to use to triggering processing of queued callbacks:
  10449. if (isNode) {
  10450. scheduleFlush = useNextTick();
  10451. } else if (BrowserMutationObserver) {
  10452. scheduleFlush = useMutationObserver();
  10453. } else if (isWorker) {
  10454. scheduleFlush = useMessageChannel();
  10455. } else if (browserWindow === undefined && typeof _dereq_ === 'function') {
  10456. scheduleFlush = attemptVertx();
  10457. } else {
  10458. scheduleFlush = useSetTimeout();
  10459. }
  10460. function then(onFulfillment, onRejection) {
  10461. var _arguments = arguments;
  10462. var parent = this;
  10463. var child = new this.constructor(noop);
  10464. if (child[PROMISE_ID] === undefined) {
  10465. makePromise(child);
  10466. }
  10467. var _state = parent._state;
  10468. if (_state) {
  10469. (function () {
  10470. var callback = _arguments[_state - 1];
  10471. asap(function () {
  10472. return invokeCallback(_state, child, callback, parent._result);
  10473. });
  10474. })();
  10475. } else {
  10476. subscribe(parent, child, onFulfillment, onRejection);
  10477. }
  10478. return child;
  10479. }
  10480. /**
  10481. `Promise.resolve` returns a promise that will become resolved with the
  10482. passed `value`. It is shorthand for the following:
  10483. ```javascript
  10484. let promise = new Promise(function(resolve, reject){
  10485. resolve(1);
  10486. });
  10487. promise.then(function(value){
  10488. // value === 1
  10489. });
  10490. ```
  10491. Instead of writing the above, your code now simply becomes the following:
  10492. ```javascript
  10493. let promise = Promise.resolve(1);
  10494. promise.then(function(value){
  10495. // value === 1
  10496. });
  10497. ```
  10498. @method resolve
  10499. @static
  10500. @param {Any} value value that the returned promise will be resolved with
  10501. Useful for tooling.
  10502. @return {Promise} a promise that will become fulfilled with the given
  10503. `value`
  10504. */
  10505. function resolve(object) {
  10506. /*jshint validthis:true */
  10507. var Constructor = this;
  10508. if (object && typeof object === 'object' && object.constructor === Constructor) {
  10509. return object;
  10510. }
  10511. var promise = new Constructor(noop);
  10512. _resolve(promise, object);
  10513. return promise;
  10514. }
  10515. var PROMISE_ID = Math.random().toString(36).substring(16);
  10516. function noop() {}
  10517. var PENDING = void 0;
  10518. var FULFILLED = 1;
  10519. var REJECTED = 2;
  10520. var GET_THEN_ERROR = new ErrorObject();
  10521. function selfFulfillment() {
  10522. return new TypeError("You cannot resolve a promise with itself");
  10523. }
  10524. function cannotReturnOwn() {
  10525. return new TypeError('A promises callback cannot return that same promise.');
  10526. }
  10527. function getThen(promise) {
  10528. try {
  10529. return promise.then;
  10530. } catch (error) {
  10531. GET_THEN_ERROR.error = error;
  10532. return GET_THEN_ERROR;
  10533. }
  10534. }
  10535. function tryThen(then, value, fulfillmentHandler, rejectionHandler) {
  10536. try {
  10537. then.call(value, fulfillmentHandler, rejectionHandler);
  10538. } catch (e) {
  10539. return e;
  10540. }
  10541. }
  10542. function handleForeignThenable(promise, thenable, then) {
  10543. asap(function (promise) {
  10544. var sealed = false;
  10545. var error = tryThen(then, thenable, function (value) {
  10546. if (sealed) {
  10547. return;
  10548. }
  10549. sealed = true;
  10550. if (thenable !== value) {
  10551. _resolve(promise, value);
  10552. } else {
  10553. fulfill(promise, value);
  10554. }
  10555. }, function (reason) {
  10556. if (sealed) {
  10557. return;
  10558. }
  10559. sealed = true;
  10560. _reject(promise, reason);
  10561. }, 'Settle: ' + (promise._label || ' unknown promise'));
  10562. if (!sealed && error) {
  10563. sealed = true;
  10564. _reject(promise, error);
  10565. }
  10566. }, promise);
  10567. }
  10568. function handleOwnThenable(promise, thenable) {
  10569. if (thenable._state === FULFILLED) {
  10570. fulfill(promise, thenable._result);
  10571. } else if (thenable._state === REJECTED) {
  10572. _reject(promise, thenable._result);
  10573. } else {
  10574. subscribe(thenable, undefined, function (value) {
  10575. return _resolve(promise, value);
  10576. }, function (reason) {
  10577. return _reject(promise, reason);
  10578. });
  10579. }
  10580. }
  10581. function handleMaybeThenable(promise, maybeThenable, then$$) {
  10582. if (maybeThenable.constructor === promise.constructor && then$$ === then && maybeThenable.constructor.resolve === resolve) {
  10583. handleOwnThenable(promise, maybeThenable);
  10584. } else {
  10585. if (then$$ === GET_THEN_ERROR) {
  10586. _reject(promise, GET_THEN_ERROR.error);
  10587. } else if (then$$ === undefined) {
  10588. fulfill(promise, maybeThenable);
  10589. } else if (isFunction(then$$)) {
  10590. handleForeignThenable(promise, maybeThenable, then$$);
  10591. } else {
  10592. fulfill(promise, maybeThenable);
  10593. }
  10594. }
  10595. }
  10596. function _resolve(promise, value) {
  10597. if (promise === value) {
  10598. _reject(promise, selfFulfillment());
  10599. } else if (objectOrFunction(value)) {
  10600. handleMaybeThenable(promise, value, getThen(value));
  10601. } else {
  10602. fulfill(promise, value);
  10603. }
  10604. }
  10605. function publishRejection(promise) {
  10606. if (promise._onerror) {
  10607. promise._onerror(promise._result);
  10608. }
  10609. publish(promise);
  10610. }
  10611. function fulfill(promise, value) {
  10612. if (promise._state !== PENDING) {
  10613. return;
  10614. }
  10615. promise._result = value;
  10616. promise._state = FULFILLED;
  10617. if (promise._subscribers.length !== 0) {
  10618. asap(publish, promise);
  10619. }
  10620. }
  10621. function _reject(promise, reason) {
  10622. if (promise._state !== PENDING) {
  10623. return;
  10624. }
  10625. promise._state = REJECTED;
  10626. promise._result = reason;
  10627. asap(publishRejection, promise);
  10628. }
  10629. function subscribe(parent, child, onFulfillment, onRejection) {
  10630. var _subscribers = parent._subscribers;
  10631. var length = _subscribers.length;
  10632. parent._onerror = null;
  10633. _subscribers[length] = child;
  10634. _subscribers[length + FULFILLED] = onFulfillment;
  10635. _subscribers[length + REJECTED] = onRejection;
  10636. if (length === 0 && parent._state) {
  10637. asap(publish, parent);
  10638. }
  10639. }
  10640. function publish(promise) {
  10641. var subscribers = promise._subscribers;
  10642. var settled = promise._state;
  10643. if (subscribers.length === 0) {
  10644. return;
  10645. }
  10646. var child = undefined,
  10647. callback = undefined,
  10648. detail = promise._result;
  10649. for (var i = 0; i < subscribers.length; i += 3) {
  10650. child = subscribers[i];
  10651. callback = subscribers[i + settled];
  10652. if (child) {
  10653. invokeCallback(settled, child, callback, detail);
  10654. } else {
  10655. callback(detail);
  10656. }
  10657. }
  10658. promise._subscribers.length = 0;
  10659. }
  10660. function ErrorObject() {
  10661. this.error = null;
  10662. }
  10663. var TRY_CATCH_ERROR = new ErrorObject();
  10664. function tryCatch(callback, detail) {
  10665. try {
  10666. return callback(detail);
  10667. } catch (e) {
  10668. TRY_CATCH_ERROR.error = e;
  10669. return TRY_CATCH_ERROR;
  10670. }
  10671. }
  10672. function invokeCallback(settled, promise, callback, detail) {
  10673. var hasCallback = isFunction(callback),
  10674. value = undefined,
  10675. error = undefined,
  10676. succeeded = undefined,
  10677. failed = undefined;
  10678. if (hasCallback) {
  10679. value = tryCatch(callback, detail);
  10680. if (value === TRY_CATCH_ERROR) {
  10681. failed = true;
  10682. error = value.error;
  10683. value = null;
  10684. } else {
  10685. succeeded = true;
  10686. }
  10687. if (promise === value) {
  10688. _reject(promise, cannotReturnOwn());
  10689. return;
  10690. }
  10691. } else {
  10692. value = detail;
  10693. succeeded = true;
  10694. }
  10695. if (promise._state !== PENDING) {
  10696. // noop
  10697. } else if (hasCallback && succeeded) {
  10698. _resolve(promise, value);
  10699. } else if (failed) {
  10700. _reject(promise, error);
  10701. } else if (settled === FULFILLED) {
  10702. fulfill(promise, value);
  10703. } else if (settled === REJECTED) {
  10704. _reject(promise, value);
  10705. }
  10706. }
  10707. function initializePromise(promise, resolver) {
  10708. try {
  10709. resolver(function resolvePromise(value) {
  10710. _resolve(promise, value);
  10711. }, function rejectPromise(reason) {
  10712. _reject(promise, reason);
  10713. });
  10714. } catch (e) {
  10715. _reject(promise, e);
  10716. }
  10717. }
  10718. var id = 0;
  10719. function nextId() {
  10720. return id++;
  10721. }
  10722. function makePromise(promise) {
  10723. promise[PROMISE_ID] = id++;
  10724. promise._state = undefined;
  10725. promise._result = undefined;
  10726. promise._subscribers = [];
  10727. }
  10728. function Enumerator(Constructor, input) {
  10729. this._instanceConstructor = Constructor;
  10730. this.promise = new Constructor(noop);
  10731. if (!this.promise[PROMISE_ID]) {
  10732. makePromise(this.promise);
  10733. }
  10734. if (isArray(input)) {
  10735. this._input = input;
  10736. this.length = input.length;
  10737. this._remaining = input.length;
  10738. this._result = new Array(this.length);
  10739. if (this.length === 0) {
  10740. fulfill(this.promise, this._result);
  10741. } else {
  10742. this.length = this.length || 0;
  10743. this._enumerate();
  10744. if (this._remaining === 0) {
  10745. fulfill(this.promise, this._result);
  10746. }
  10747. }
  10748. } else {
  10749. _reject(this.promise, validationError());
  10750. }
  10751. }
  10752. function validationError() {
  10753. return new Error('Array Methods must be provided an Array');
  10754. };
  10755. Enumerator.prototype._enumerate = function () {
  10756. var length = this.length;
  10757. var _input = this._input;
  10758. for (var i = 0; this._state === PENDING && i < length; i++) {
  10759. this._eachEntry(_input[i], i);
  10760. }
  10761. };
  10762. Enumerator.prototype._eachEntry = function (entry, i) {
  10763. var c = this._instanceConstructor;
  10764. var resolve$$ = c.resolve;
  10765. if (resolve$$ === resolve) {
  10766. var _then = getThen(entry);
  10767. if (_then === then && entry._state !== PENDING) {
  10768. this._settledAt(entry._state, i, entry._result);
  10769. } else if (typeof _then !== 'function') {
  10770. this._remaining--;
  10771. this._result[i] = entry;
  10772. } else if (c === Promise) {
  10773. var promise = new c(noop);
  10774. handleMaybeThenable(promise, entry, _then);
  10775. this._willSettleAt(promise, i);
  10776. } else {
  10777. this._willSettleAt(new c(function (resolve$$) {
  10778. return resolve$$(entry);
  10779. }), i);
  10780. }
  10781. } else {
  10782. this._willSettleAt(resolve$$(entry), i);
  10783. }
  10784. };
  10785. Enumerator.prototype._settledAt = function (state, i, value) {
  10786. var promise = this.promise;
  10787. if (promise._state === PENDING) {
  10788. this._remaining--;
  10789. if (state === REJECTED) {
  10790. _reject(promise, value);
  10791. } else {
  10792. this._result[i] = value;
  10793. }
  10794. }
  10795. if (this._remaining === 0) {
  10796. fulfill(promise, this._result);
  10797. }
  10798. };
  10799. Enumerator.prototype._willSettleAt = function (promise, i) {
  10800. var enumerator = this;
  10801. subscribe(promise, undefined, function (value) {
  10802. return enumerator._settledAt(FULFILLED, i, value);
  10803. }, function (reason) {
  10804. return enumerator._settledAt(REJECTED, i, reason);
  10805. });
  10806. };
  10807. /**
  10808. `Promise.all` accepts an array of promises, and returns a new promise which
  10809. is fulfilled with an array of fulfillment values for the passed promises, or
  10810. rejected with the reason of the first passed promise to be rejected. It casts all
  10811. elements of the passed iterable to promises as it runs this algorithm.
  10812. Example:
  10813. ```javascript
  10814. let promise1 = resolve(1);
  10815. let promise2 = resolve(2);
  10816. let promise3 = resolve(3);
  10817. let promises = [ promise1, promise2, promise3 ];
  10818. Promise.all(promises).then(function(array){
  10819. // The array here would be [ 1, 2, 3 ];
  10820. });
  10821. ```
  10822. If any of the `promises` given to `all` are rejected, the first promise
  10823. that is rejected will be given as an argument to the returned promises's
  10824. rejection handler. For example:
  10825. Example:
  10826. ```javascript
  10827. let promise1 = resolve(1);
  10828. let promise2 = reject(new Error("2"));
  10829. let promise3 = reject(new Error("3"));
  10830. let promises = [ promise1, promise2, promise3 ];
  10831. Promise.all(promises).then(function(array){
  10832. // Code here never runs because there are rejected promises!
  10833. }, function(error) {
  10834. // error.message === "2"
  10835. });
  10836. ```
  10837. @method all
  10838. @static
  10839. @param {Array} entries array of promises
  10840. @param {String} label optional string for labeling the promise.
  10841. Useful for tooling.
  10842. @return {Promise} promise that is fulfilled when all `promises` have been
  10843. fulfilled, or rejected if any of them become rejected.
  10844. @static
  10845. */
  10846. function all(entries) {
  10847. return new Enumerator(this, entries).promise;
  10848. }
  10849. /**
  10850. `Promise.race` returns a new promise which is settled in the same way as the
  10851. first passed promise to settle.
  10852. Example:
  10853. ```javascript
  10854. let promise1 = new Promise(function(resolve, reject){
  10855. setTimeout(function(){
  10856. resolve('promise 1');
  10857. }, 200);
  10858. });
  10859. let promise2 = new Promise(function(resolve, reject){
  10860. setTimeout(function(){
  10861. resolve('promise 2');
  10862. }, 100);
  10863. });
  10864. Promise.race([promise1, promise2]).then(function(result){
  10865. // result === 'promise 2' because it was resolved before promise1
  10866. // was resolved.
  10867. });
  10868. ```
  10869. `Promise.race` is deterministic in that only the state of the first
  10870. settled promise matters. For example, even if other promises given to the
  10871. `promises` array argument are resolved, but the first settled promise has
  10872. become rejected before the other promises became fulfilled, the returned
  10873. promise will become rejected:
  10874. ```javascript
  10875. let promise1 = new Promise(function(resolve, reject){
  10876. setTimeout(function(){
  10877. resolve('promise 1');
  10878. }, 200);
  10879. });
  10880. let promise2 = new Promise(function(resolve, reject){
  10881. setTimeout(function(){
  10882. reject(new Error('promise 2'));
  10883. }, 100);
  10884. });
  10885. Promise.race([promise1, promise2]).then(function(result){
  10886. // Code here never runs
  10887. }, function(reason){
  10888. // reason.message === 'promise 2' because promise 2 became rejected before
  10889. // promise 1 became fulfilled
  10890. });
  10891. ```
  10892. An example real-world use case is implementing timeouts:
  10893. ```javascript
  10894. Promise.race([ajax('foo.json'), timeout(5000)])
  10895. ```
  10896. @method race
  10897. @static
  10898. @param {Array} promises array of promises to observe
  10899. Useful for tooling.
  10900. @return {Promise} a promise which settles in the same way as the first passed
  10901. promise to settle.
  10902. */
  10903. function race(entries) {
  10904. /*jshint validthis:true */
  10905. var Constructor = this;
  10906. if (!isArray(entries)) {
  10907. return new Constructor(function (_, reject) {
  10908. return reject(new TypeError('You must pass an array to race.'));
  10909. });
  10910. } else {
  10911. return new Constructor(function (resolve, reject) {
  10912. var length = entries.length;
  10913. for (var i = 0; i < length; i++) {
  10914. Constructor.resolve(entries[i]).then(resolve, reject);
  10915. }
  10916. });
  10917. }
  10918. }
  10919. /**
  10920. `Promise.reject` returns a promise rejected with the passed `reason`.
  10921. It is shorthand for the following:
  10922. ```javascript
  10923. let promise = new Promise(function(resolve, reject){
  10924. reject(new Error('WHOOPS'));
  10925. });
  10926. promise.then(function(value){
  10927. // Code here doesn't run because the promise is rejected!
  10928. }, function(reason){
  10929. // reason.message === 'WHOOPS'
  10930. });
  10931. ```
  10932. Instead of writing the above, your code now simply becomes the following:
  10933. ```javascript
  10934. let promise = Promise.reject(new Error('WHOOPS'));
  10935. promise.then(function(value){
  10936. // Code here doesn't run because the promise is rejected!
  10937. }, function(reason){
  10938. // reason.message === 'WHOOPS'
  10939. });
  10940. ```
  10941. @method reject
  10942. @static
  10943. @param {Any} reason value that the returned promise will be rejected with.
  10944. Useful for tooling.
  10945. @return {Promise} a promise rejected with the given `reason`.
  10946. */
  10947. function reject(reason) {
  10948. /*jshint validthis:true */
  10949. var Constructor = this;
  10950. var promise = new Constructor(noop);
  10951. _reject(promise, reason);
  10952. return promise;
  10953. }
  10954. function needsResolver() {
  10955. throw new TypeError('You must pass a resolver function as the first argument to the promise constructor');
  10956. }
  10957. function needsNew() {
  10958. throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.");
  10959. }
  10960. /**
  10961. Promise objects represent the eventual result of an asynchronous operation. The
  10962. primary way of interacting with a promise is through its `then` method, which
  10963. registers callbacks to receive either a promise's eventual value or the reason
  10964. why the promise cannot be fulfilled.
  10965. Terminology
  10966. -----------
  10967. - `promise` is an object or function with a `then` method whose behavior conforms to this specification.
  10968. - `thenable` is an object or function that defines a `then` method.
  10969. - `value` is any legal JavaScript value (including undefined, a thenable, or a promise).
  10970. - `exception` is a value that is thrown using the throw statement.
  10971. - `reason` is a value that indicates why a promise was rejected.
  10972. - `settled` the final resting state of a promise, fulfilled or rejected.
  10973. A promise can be in one of three states: pending, fulfilled, or rejected.
  10974. Promises that are fulfilled have a fulfillment value and are in the fulfilled
  10975. state. Promises that are rejected have a rejection reason and are in the
  10976. rejected state. A fulfillment value is never a thenable.
  10977. Promises can also be said to *resolve* a value. If this value is also a
  10978. promise, then the original promise's settled state will match the value's
  10979. settled state. So a promise that *resolves* a promise that rejects will
  10980. itself reject, and a promise that *resolves* a promise that fulfills will
  10981. itself fulfill.
  10982. Basic Usage:
  10983. ------------
  10984. ```js
  10985. let promise = new Promise(function(resolve, reject) {
  10986. // on success
  10987. resolve(value);
  10988. // on failure
  10989. reject(reason);
  10990. });
  10991. promise.then(function(value) {
  10992. // on fulfillment
  10993. }, function(reason) {
  10994. // on rejection
  10995. });
  10996. ```
  10997. Advanced Usage:
  10998. ---------------
  10999. Promises shine when abstracting away asynchronous interactions such as
  11000. `XMLHttpRequest`s.
  11001. ```js
  11002. function getJSON(url) {
  11003. return new Promise(function(resolve, reject){
  11004. let xhr = new XMLHttpRequest();
  11005. xhr.open('GET', url);
  11006. xhr.onreadystatechange = handler;
  11007. xhr.responseType = 'json';
  11008. xhr.setRequestHeader('Accept', 'application/json');
  11009. xhr.send();
  11010. function handler() {
  11011. if (this.readyState === this.DONE) {
  11012. if (this.status === 200) {
  11013. resolve(this.response);
  11014. } else {
  11015. reject(new Error('getJSON: `' + url + '` failed with status: [' + this.status + ']'));
  11016. }
  11017. }
  11018. };
  11019. });
  11020. }
  11021. getJSON('/posts.json').then(function(json) {
  11022. // on fulfillment
  11023. }, function(reason) {
  11024. // on rejection
  11025. });
  11026. ```
  11027. Unlike callbacks, promises are great composable primitives.
  11028. ```js
  11029. Promise.all([
  11030. getJSON('/posts'),
  11031. getJSON('/comments')
  11032. ]).then(function(values){
  11033. values[0] // => postsJSON
  11034. values[1] // => commentsJSON
  11035. return values;
  11036. });
  11037. ```
  11038. @class Promise
  11039. @param {function} resolver
  11040. Useful for tooling.
  11041. @constructor
  11042. */
  11043. function Promise(resolver) {
  11044. this[PROMISE_ID] = nextId();
  11045. this._result = this._state = undefined;
  11046. this._subscribers = [];
  11047. if (noop !== resolver) {
  11048. typeof resolver !== 'function' && needsResolver();
  11049. this instanceof Promise ? initializePromise(this, resolver) : needsNew();
  11050. }
  11051. }
  11052. Promise.all = all;
  11053. Promise.race = race;
  11054. Promise.resolve = resolve;
  11055. Promise.reject = reject;
  11056. Promise._setScheduler = setScheduler;
  11057. Promise._setAsap = setAsap;
  11058. Promise._asap = asap;
  11059. Promise.prototype = {
  11060. constructor: Promise,
  11061. /**
  11062. The primary way of interacting with a promise is through its `then` method,
  11063. which registers callbacks to receive either a promise's eventual value or the
  11064. reason why the promise cannot be fulfilled.
  11065. ```js
  11066. findUser().then(function(user){
  11067. // user is available
  11068. }, function(reason){
  11069. // user is unavailable, and you are given the reason why
  11070. });
  11071. ```
  11072. Chaining
  11073. --------
  11074. The return value of `then` is itself a promise. This second, 'downstream'
  11075. promise is resolved with the return value of the first promise's fulfillment
  11076. or rejection handler, or rejected if the handler throws an exception.
  11077. ```js
  11078. findUser().then(function (user) {
  11079. return user.name;
  11080. }, function (reason) {
  11081. return 'default name';
  11082. }).then(function (userName) {
  11083. // If `findUser` fulfilled, `userName` will be the user's name, otherwise it
  11084. // will be `'default name'`
  11085. });
  11086. findUser().then(function (user) {
  11087. throw new Error('Found user, but still unhappy');
  11088. }, function (reason) {
  11089. throw new Error('`findUser` rejected and we're unhappy');
  11090. }).then(function (value) {
  11091. // never reached
  11092. }, function (reason) {
  11093. // if `findUser` fulfilled, `reason` will be 'Found user, but still unhappy'.
  11094. // If `findUser` rejected, `reason` will be '`findUser` rejected and we're unhappy'.
  11095. });
  11096. ```
  11097. If the downstream promise does not specify a rejection handler, rejection reasons will be propagated further downstream.
  11098. ```js
  11099. findUser().then(function (user) {
  11100. throw new PedagogicalException('Upstream error');
  11101. }).then(function (value) {
  11102. // never reached
  11103. }).then(function (value) {
  11104. // never reached
  11105. }, function (reason) {
  11106. // The `PedgagocialException` is propagated all the way down to here
  11107. });
  11108. ```
  11109. Assimilation
  11110. ------------
  11111. Sometimes the value you want to propagate to a downstream promise can only be
  11112. retrieved asynchronously. This can be achieved by returning a promise in the
  11113. fulfillment or rejection handler. The downstream promise will then be pending
  11114. until the returned promise is settled. This is called *assimilation*.
  11115. ```js
  11116. findUser().then(function (user) {
  11117. return findCommentsByAuthor(user);
  11118. }).then(function (comments) {
  11119. // The user's comments are now available
  11120. });
  11121. ```
  11122. If the assimliated promise rejects, then the downstream promise will also reject.
  11123. ```js
  11124. findUser().then(function (user) {
  11125. return findCommentsByAuthor(user);
  11126. }).then(function (comments) {
  11127. // If `findCommentsByAuthor` fulfills, we'll have the value here
  11128. }, function (reason) {
  11129. // If `findCommentsByAuthor` rejects, we'll have the reason here
  11130. });
  11131. ```
  11132. Simple Example
  11133. --------------
  11134. Synchronous Example
  11135. ```javascript
  11136. let result;
  11137. try {
  11138. result = findResult();
  11139. // success
  11140. } catch(reason) {
  11141. // failure
  11142. }
  11143. ```
  11144. Errback Example
  11145. ```js
  11146. findResult(function(result, err){
  11147. if (err) {
  11148. // failure
  11149. } else {
  11150. // success
  11151. }
  11152. });
  11153. ```
  11154. Promise Example;
  11155. ```javascript
  11156. findResult().then(function(result){
  11157. // success
  11158. }, function(reason){
  11159. // failure
  11160. });
  11161. ```
  11162. Advanced Example
  11163. --------------
  11164. Synchronous Example
  11165. ```javascript
  11166. let author, books;
  11167. try {
  11168. author = findAuthor();
  11169. books = findBooksByAuthor(author);
  11170. // success
  11171. } catch(reason) {
  11172. // failure
  11173. }
  11174. ```
  11175. Errback Example
  11176. ```js
  11177. function foundBooks(books) {
  11178. }
  11179. function failure(reason) {
  11180. }
  11181. findAuthor(function(author, err){
  11182. if (err) {
  11183. failure(err);
  11184. // failure
  11185. } else {
  11186. try {
  11187. findBoooksByAuthor(author, function(books, err) {
  11188. if (err) {
  11189. failure(err);
  11190. } else {
  11191. try {
  11192. foundBooks(books);
  11193. } catch(reason) {
  11194. failure(reason);
  11195. }
  11196. }
  11197. });
  11198. } catch(error) {
  11199. failure(err);
  11200. }
  11201. // success
  11202. }
  11203. });
  11204. ```
  11205. Promise Example;
  11206. ```javascript
  11207. findAuthor().
  11208. then(findBooksByAuthor).
  11209. then(function(books){
  11210. // found books
  11211. }).catch(function(reason){
  11212. // something went wrong
  11213. });
  11214. ```
  11215. @method then
  11216. @param {Function} onFulfilled
  11217. @param {Function} onRejected
  11218. Useful for tooling.
  11219. @return {Promise}
  11220. */
  11221. then: then,
  11222. /**
  11223. `catch` is simply sugar for `then(undefined, onRejection)` which makes it the same
  11224. as the catch block of a try/catch statement.
  11225. ```js
  11226. function findAuthor(){
  11227. throw new Error('couldn't find that author');
  11228. }
  11229. // synchronous
  11230. try {
  11231. findAuthor();
  11232. } catch(reason) {
  11233. // something went wrong
  11234. }
  11235. // async with promises
  11236. findAuthor().catch(function(reason){
  11237. // something went wrong
  11238. });
  11239. ```
  11240. @method catch
  11241. @param {Function} onRejection
  11242. Useful for tooling.
  11243. @return {Promise}
  11244. */
  11245. 'catch': function _catch(onRejection) {
  11246. return this.then(null, onRejection);
  11247. }
  11248. };
  11249. function polyfill() {
  11250. var local = undefined;
  11251. if (typeof global !== 'undefined') {
  11252. local = global;
  11253. } else if (typeof self !== 'undefined') {
  11254. local = self;
  11255. } else {
  11256. try {
  11257. local = Function('return this')();
  11258. } catch (e) {
  11259. throw new Error('polyfill failed because global object is unavailable in this environment');
  11260. }
  11261. }
  11262. var P = local.Promise;
  11263. if (P) {
  11264. var promiseToString = null;
  11265. try {
  11266. promiseToString = Object.prototype.toString.call(P.resolve());
  11267. } catch (e) {
  11268. // silently ignored
  11269. }
  11270. if (promiseToString === '[object Promise]' && !P.cast) {
  11271. return;
  11272. }
  11273. }
  11274. local.Promise = Promise;
  11275. }
  11276. polyfill();
  11277. // Strange compat..
  11278. Promise.polyfill = polyfill;
  11279. Promise.Promise = Promise;
  11280. return Promise;
  11281. })));
  11282. }).call(this,_dereq_('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  11283. },{"_process":32}],18:[function(_dereq_,module,exports){
  11284. /**
  11285. * inspired by is-number <https://github.com/jonschlinkert/is-number>
  11286. * but significantly simplified and sped up by ignoring number and string constructors
  11287. * ie these return false:
  11288. * new Number(1)
  11289. * new String('1')
  11290. */
  11291. 'use strict';
  11292. /**
  11293. * Is this string all whitespace?
  11294. * This solution kind of makes my brain hurt, but it's significantly faster
  11295. * than !str.trim() or any other solution I could find.
  11296. *
  11297. * whitespace codes from: http://en.wikipedia.org/wiki/Whitespace_character
  11298. * and verified with:
  11299. *
  11300. * for(var i = 0; i < 65536; i++) {
  11301. * var s = String.fromCharCode(i);
  11302. * if(+s===0 && !s.trim()) console.log(i, s);
  11303. * }
  11304. *
  11305. * which counts a couple of these as *not* whitespace, but finds nothing else
  11306. * that *is* whitespace. Note that charCodeAt stops at 16 bits, but it appears
  11307. * that there are no whitespace characters above this, and code points above
  11308. * this do not map onto white space characters.
  11309. */
  11310. function allBlankCharCodes(str){
  11311. var l = str.length,
  11312. a;
  11313. for(var i = 0; i < l; i++) {
  11314. a = str.charCodeAt(i);
  11315. if((a < 9 || a > 13) && (a !== 32) && (a !== 133) && (a !== 160) &&
  11316. (a !== 5760) && (a !== 6158) && (a < 8192 || a > 8205) &&
  11317. (a !== 8232) && (a !== 8233) && (a !== 8239) && (a !== 8287) &&
  11318. (a !== 8288) && (a !== 12288) && (a !== 65279)) {
  11319. return false;
  11320. }
  11321. }
  11322. return true;
  11323. }
  11324. module.exports = function(n) {
  11325. var type = typeof n;
  11326. if(type === 'string') {
  11327. var original = n;
  11328. n = +n;
  11329. // whitespace strings cast to zero - filter them out
  11330. if(n===0 && allBlankCharCodes(original)) return false;
  11331. }
  11332. else if(type !== 'number') return false;
  11333. return n - n < 1;
  11334. };
  11335. },{}],19:[function(_dereq_,module,exports){
  11336. module.exports = fromQuat;
  11337. /**
  11338. * Creates a matrix from a quaternion rotation.
  11339. *
  11340. * @param {mat4} out mat4 receiving operation result
  11341. * @param {quat4} q Rotation quaternion
  11342. * @returns {mat4} out
  11343. */
  11344. function fromQuat(out, q) {
  11345. var x = q[0], y = q[1], z = q[2], w = q[3],
  11346. x2 = x + x,
  11347. y2 = y + y,
  11348. z2 = z + z,
  11349. xx = x * x2,
  11350. yx = y * x2,
  11351. yy = y * y2,
  11352. zx = z * x2,
  11353. zy = z * y2,
  11354. zz = z * z2,
  11355. wx = w * x2,
  11356. wy = w * y2,
  11357. wz = w * z2;
  11358. out[0] = 1 - yy - zz;
  11359. out[1] = yx + wz;
  11360. out[2] = zx - wy;
  11361. out[3] = 0;
  11362. out[4] = yx - wz;
  11363. out[5] = 1 - xx - zz;
  11364. out[6] = zy + wx;
  11365. out[7] = 0;
  11366. out[8] = zx + wy;
  11367. out[9] = zy - wx;
  11368. out[10] = 1 - xx - yy;
  11369. out[11] = 0;
  11370. out[12] = 0;
  11371. out[13] = 0;
  11372. out[14] = 0;
  11373. out[15] = 1;
  11374. return out;
  11375. };
  11376. },{}],20:[function(_dereq_,module,exports){
  11377. (function (global){
  11378. 'use strict'
  11379. var isBrowser = _dereq_('is-browser')
  11380. var hasHover
  11381. if (typeof global.matchMedia === 'function') {
  11382. hasHover = !global.matchMedia('(hover: none)').matches
  11383. }
  11384. else {
  11385. hasHover = isBrowser
  11386. }
  11387. module.exports = hasHover
  11388. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  11389. },{"is-browser":22}],21:[function(_dereq_,module,exports){
  11390. 'use strict'
  11391. var isBrowser = _dereq_('is-browser')
  11392. function detect() {
  11393. var supported = false
  11394. try {
  11395. var opts = Object.defineProperty({}, 'passive', {
  11396. get: function() {
  11397. supported = true
  11398. }
  11399. })
  11400. window.addEventListener('test', null, opts)
  11401. window.removeEventListener('test', null, opts)
  11402. } catch(e) {
  11403. supported = false
  11404. }
  11405. return supported
  11406. }
  11407. module.exports = isBrowser && detect()
  11408. },{"is-browser":22}],22:[function(_dereq_,module,exports){
  11409. module.exports = true;
  11410. },{}],23:[function(_dereq_,module,exports){
  11411. var rootPosition = { left: 0, top: 0 }
  11412. module.exports = mouseEventOffset
  11413. function mouseEventOffset (ev, target, out) {
  11414. target = target || ev.currentTarget || ev.srcElement
  11415. if (!Array.isArray(out)) {
  11416. out = [ 0, 0 ]
  11417. }
  11418. var cx = ev.clientX || 0
  11419. var cy = ev.clientY || 0
  11420. var rect = getBoundingClientOffset(target)
  11421. out[0] = cx - rect.left
  11422. out[1] = cy - rect.top
  11423. return out
  11424. }
  11425. function getBoundingClientOffset (element) {
  11426. if (element === window ||
  11427. element === document ||
  11428. element === document.body) {
  11429. return rootPosition
  11430. } else {
  11431. return element.getBoundingClientRect()
  11432. }
  11433. }
  11434. },{}],24:[function(_dereq_,module,exports){
  11435. /*
  11436. * @copyright 2016 Sean Connelly (@voidqk), http://syntheti.cc
  11437. * @license MIT
  11438. * @preserve Project Home: https://github.com/voidqk/polybooljs
  11439. */
  11440. var BuildLog = _dereq_('./lib/build-log');
  11441. var Epsilon = _dereq_('./lib/epsilon');
  11442. var Intersecter = _dereq_('./lib/intersecter');
  11443. var SegmentChainer = _dereq_('./lib/segment-chainer');
  11444. var SegmentSelector = _dereq_('./lib/segment-selector');
  11445. var GeoJSON = _dereq_('./lib/geojson');
  11446. var buildLog = false;
  11447. var epsilon = Epsilon();
  11448. var PolyBool;
  11449. PolyBool = {
  11450. // getter/setter for buildLog
  11451. buildLog: function(bl){
  11452. if (bl === true)
  11453. buildLog = BuildLog();
  11454. else if (bl === false)
  11455. buildLog = false;
  11456. return buildLog === false ? false : buildLog.list;
  11457. },
  11458. // getter/setter for epsilon
  11459. epsilon: function(v){
  11460. return epsilon.epsilon(v);
  11461. },
  11462. // core API
  11463. segments: function(poly){
  11464. var i = Intersecter(true, epsilon, buildLog);
  11465. poly.regions.forEach(i.addRegion);
  11466. return {
  11467. segments: i.calculate(poly.inverted),
  11468. inverted: poly.inverted
  11469. };
  11470. },
  11471. combine: function(segments1, segments2){
  11472. var i3 = Intersecter(false, epsilon, buildLog);
  11473. return {
  11474. combined: i3.calculate(
  11475. segments1.segments, segments1.inverted,
  11476. segments2.segments, segments2.inverted
  11477. ),
  11478. inverted1: segments1.inverted,
  11479. inverted2: segments2.inverted
  11480. };
  11481. },
  11482. selectUnion: function(combined){
  11483. return {
  11484. segments: SegmentSelector.union(combined.combined, buildLog),
  11485. inverted: combined.inverted1 || combined.inverted2
  11486. }
  11487. },
  11488. selectIntersect: function(combined){
  11489. return {
  11490. segments: SegmentSelector.intersect(combined.combined, buildLog),
  11491. inverted: combined.inverted1 && combined.inverted2
  11492. }
  11493. },
  11494. selectDifference: function(combined){
  11495. return {
  11496. segments: SegmentSelector.difference(combined.combined, buildLog),
  11497. inverted: combined.inverted1 && !combined.inverted2
  11498. }
  11499. },
  11500. selectDifferenceRev: function(combined){
  11501. return {
  11502. segments: SegmentSelector.differenceRev(combined.combined, buildLog),
  11503. inverted: !combined.inverted1 && combined.inverted2
  11504. }
  11505. },
  11506. selectXor: function(combined){
  11507. return {
  11508. segments: SegmentSelector.xor(combined.combined, buildLog),
  11509. inverted: combined.inverted1 !== combined.inverted2
  11510. }
  11511. },
  11512. polygon: function(segments){
  11513. return {
  11514. regions: SegmentChainer(segments.segments, epsilon, buildLog),
  11515. inverted: segments.inverted
  11516. };
  11517. },
  11518. // GeoJSON converters
  11519. polygonFromGeoJSON: function(geojson){
  11520. return GeoJSON.toPolygon(PolyBool, geojson);
  11521. },
  11522. polygonToGeoJSON: function(poly){
  11523. return GeoJSON.fromPolygon(PolyBool, epsilon, poly);
  11524. },
  11525. // helper functions for common operations
  11526. union: function(poly1, poly2){
  11527. return operate(poly1, poly2, PolyBool.selectUnion);
  11528. },
  11529. intersect: function(poly1, poly2){
  11530. return operate(poly1, poly2, PolyBool.selectIntersect);
  11531. },
  11532. difference: function(poly1, poly2){
  11533. return operate(poly1, poly2, PolyBool.selectDifference);
  11534. },
  11535. differenceRev: function(poly1, poly2){
  11536. return operate(poly1, poly2, PolyBool.selectDifferenceRev);
  11537. },
  11538. xor: function(poly1, poly2){
  11539. return operate(poly1, poly2, PolyBool.selectXor);
  11540. }
  11541. };
  11542. function operate(poly1, poly2, selector){
  11543. var seg1 = PolyBool.segments(poly1);
  11544. var seg2 = PolyBool.segments(poly2);
  11545. var comb = PolyBool.combine(seg1, seg2);
  11546. var seg3 = selector(comb);
  11547. return PolyBool.polygon(seg3);
  11548. }
  11549. if (typeof window === 'object')
  11550. window.PolyBool = PolyBool;
  11551. module.exports = PolyBool;
  11552. },{"./lib/build-log":25,"./lib/epsilon":26,"./lib/geojson":27,"./lib/intersecter":28,"./lib/segment-chainer":30,"./lib/segment-selector":31}],25:[function(_dereq_,module,exports){
  11553. // (c) Copyright 2016, Sean Connelly (@voidqk), http://syntheti.cc
  11554. // MIT License
  11555. // Project Home: https://github.com/voidqk/polybooljs
  11556. //
  11557. // used strictly for logging the processing of the algorithm... only useful if you intend on
  11558. // looking under the covers (for pretty UI's or debugging)
  11559. //
  11560. function BuildLog(){
  11561. var my;
  11562. var nextSegmentId = 0;
  11563. var curVert = false;
  11564. function push(type, data){
  11565. my.list.push({
  11566. type: type,
  11567. data: data ? JSON.parse(JSON.stringify(data)) : void 0
  11568. });
  11569. return my;
  11570. }
  11571. my = {
  11572. list: [],
  11573. segmentId: function(){
  11574. return nextSegmentId++;
  11575. },
  11576. checkIntersection: function(seg1, seg2){
  11577. return push('check', { seg1: seg1, seg2: seg2 });
  11578. },
  11579. segmentChop: function(seg, end){
  11580. push('div_seg', { seg: seg, pt: end });
  11581. return push('chop', { seg: seg, pt: end });
  11582. },
  11583. statusRemove: function(seg){
  11584. return push('pop_seg', { seg: seg });
  11585. },
  11586. segmentUpdate: function(seg){
  11587. return push('seg_update', { seg: seg });
  11588. },
  11589. segmentNew: function(seg, primary){
  11590. return push('new_seg', { seg: seg, primary: primary });
  11591. },
  11592. segmentRemove: function(seg){
  11593. return push('rem_seg', { seg: seg });
  11594. },
  11595. tempStatus: function(seg, above, below){
  11596. return push('temp_status', { seg: seg, above: above, below: below });
  11597. },
  11598. rewind: function(seg){
  11599. return push('rewind', { seg: seg });
  11600. },
  11601. status: function(seg, above, below){
  11602. return push('status', { seg: seg, above: above, below: below });
  11603. },
  11604. vert: function(x){
  11605. if (x === curVert)
  11606. return my;
  11607. curVert = x;
  11608. return push('vert', { x: x });
  11609. },
  11610. log: function(data){
  11611. if (typeof data !== 'string')
  11612. data = JSON.stringify(data, false, ' ');
  11613. return push('log', { txt: data });
  11614. },
  11615. reset: function(){
  11616. return push('reset');
  11617. },
  11618. selected: function(segs){
  11619. return push('selected', { segs: segs });
  11620. },
  11621. chainStart: function(seg){
  11622. return push('chain_start', { seg: seg });
  11623. },
  11624. chainRemoveHead: function(index, pt){
  11625. return push('chain_rem_head', { index: index, pt: pt });
  11626. },
  11627. chainRemoveTail: function(index, pt){
  11628. return push('chain_rem_tail', { index: index, pt: pt });
  11629. },
  11630. chainNew: function(pt1, pt2){
  11631. return push('chain_new', { pt1: pt1, pt2: pt2 });
  11632. },
  11633. chainMatch: function(index){
  11634. return push('chain_match', { index: index });
  11635. },
  11636. chainClose: function(index){
  11637. return push('chain_close', { index: index });
  11638. },
  11639. chainAddHead: function(index, pt){
  11640. return push('chain_add_head', { index: index, pt: pt });
  11641. },
  11642. chainAddTail: function(index, pt){
  11643. return push('chain_add_tail', { index: index, pt: pt, });
  11644. },
  11645. chainConnect: function(index1, index2){
  11646. return push('chain_con', { index1: index1, index2: index2 });
  11647. },
  11648. chainReverse: function(index){
  11649. return push('chain_rev', { index: index });
  11650. },
  11651. chainJoin: function(index1, index2){
  11652. return push('chain_join', { index1: index1, index2: index2 });
  11653. },
  11654. done: function(){
  11655. return push('done');
  11656. }
  11657. };
  11658. return my;
  11659. }
  11660. module.exports = BuildLog;
  11661. },{}],26:[function(_dereq_,module,exports){
  11662. // (c) Copyright 2016, Sean Connelly (@voidqk), http://syntheti.cc
  11663. // MIT License
  11664. // Project Home: https://github.com/voidqk/polybooljs
  11665. //
  11666. // provides the raw computation functions that takes epsilon into account
  11667. //
  11668. // zero is defined to be between (-epsilon, epsilon) exclusive
  11669. //
  11670. function Epsilon(eps){
  11671. if (typeof eps !== 'number')
  11672. eps = 0.0000000001; // sane default? sure why not
  11673. var my = {
  11674. epsilon: function(v){
  11675. if (typeof v === 'number')
  11676. eps = v;
  11677. return eps;
  11678. },
  11679. pointAboveOrOnLine: function(pt, left, right){
  11680. var Ax = left[0];
  11681. var Ay = left[1];
  11682. var Bx = right[0];
  11683. var By = right[1];
  11684. var Cx = pt[0];
  11685. var Cy = pt[1];
  11686. return (Bx - Ax) * (Cy - Ay) - (By - Ay) * (Cx - Ax) >= -eps;
  11687. },
  11688. pointBetween: function(p, left, right){
  11689. // p must be collinear with left->right
  11690. // returns false if p == left, p == right, or left == right
  11691. var d_py_ly = p[1] - left[1];
  11692. var d_rx_lx = right[0] - left[0];
  11693. var d_px_lx = p[0] - left[0];
  11694. var d_ry_ly = right[1] - left[1];
  11695. var dot = d_px_lx * d_rx_lx + d_py_ly * d_ry_ly;
  11696. // if `dot` is 0, then `p` == `left` or `left` == `right` (reject)
  11697. // if `dot` is less than 0, then `p` is to the left of `left` (reject)
  11698. if (dot < eps)
  11699. return false;
  11700. var sqlen = d_rx_lx * d_rx_lx + d_ry_ly * d_ry_ly;
  11701. // if `dot` > `sqlen`, then `p` is to the right of `right` (reject)
  11702. // therefore, if `dot - sqlen` is greater than 0, then `p` is to the right of `right` (reject)
  11703. if (dot - sqlen > -eps)
  11704. return false;
  11705. return true;
  11706. },
  11707. pointsSameX: function(p1, p2){
  11708. return Math.abs(p1[0] - p2[0]) < eps;
  11709. },
  11710. pointsSameY: function(p1, p2){
  11711. return Math.abs(p1[1] - p2[1]) < eps;
  11712. },
  11713. pointsSame: function(p1, p2){
  11714. return my.pointsSameX(p1, p2) && my.pointsSameY(p1, p2);
  11715. },
  11716. pointsCompare: function(p1, p2){
  11717. // returns -1 if p1 is smaller, 1 if p2 is smaller, 0 if equal
  11718. if (my.pointsSameX(p1, p2))
  11719. return my.pointsSameY(p1, p2) ? 0 : (p1[1] < p2[1] ? -1 : 1);
  11720. return p1[0] < p2[0] ? -1 : 1;
  11721. },
  11722. pointsCollinear: function(pt1, pt2, pt3){
  11723. // does pt1->pt2->pt3 make a straight line?
  11724. // essentially this is just checking to see if the slope(pt1->pt2) === slope(pt2->pt3)
  11725. // if slopes are equal, then they must be collinear, because they share pt2
  11726. var dx1 = pt1[0] - pt2[0];
  11727. var dy1 = pt1[1] - pt2[1];
  11728. var dx2 = pt2[0] - pt3[0];
  11729. var dy2 = pt2[1] - pt3[1];
  11730. return Math.abs(dx1 * dy2 - dx2 * dy1) < eps;
  11731. },
  11732. linesIntersect: function(a0, a1, b0, b1){
  11733. // returns false if the lines are coincident (e.g., parallel or on top of each other)
  11734. //
  11735. // returns an object if the lines intersect:
  11736. // {
  11737. // pt: [x, y], where the intersection point is at
  11738. // alongA: where intersection point is along A,
  11739. // alongB: where intersection point is along B
  11740. // }
  11741. //
  11742. // alongA and alongB will each be one of: -2, -1, 0, 1, 2
  11743. //
  11744. // with the following meaning:
  11745. //
  11746. // -2 intersection point is before segment's first point
  11747. // -1 intersection point is directly on segment's first point
  11748. // 0 intersection point is between segment's first and second points (exclusive)
  11749. // 1 intersection point is directly on segment's second point
  11750. // 2 intersection point is after segment's second point
  11751. var adx = a1[0] - a0[0];
  11752. var ady = a1[1] - a0[1];
  11753. var bdx = b1[0] - b0[0];
  11754. var bdy = b1[1] - b0[1];
  11755. var axb = adx * bdy - ady * bdx;
  11756. if (Math.abs(axb) < eps)
  11757. return false; // lines are coincident
  11758. var dx = a0[0] - b0[0];
  11759. var dy = a0[1] - b0[1];
  11760. var A = (bdx * dy - bdy * dx) / axb;
  11761. var B = (adx * dy - ady * dx) / axb;
  11762. var ret = {
  11763. alongA: 0,
  11764. alongB: 0,
  11765. pt: [
  11766. a0[0] + A * adx,
  11767. a0[1] + A * ady
  11768. ]
  11769. };
  11770. // categorize where intersection point is along A and B
  11771. if (A <= -eps)
  11772. ret.alongA = -2;
  11773. else if (A < eps)
  11774. ret.alongA = -1;
  11775. else if (A - 1 <= -eps)
  11776. ret.alongA = 0;
  11777. else if (A - 1 < eps)
  11778. ret.alongA = 1;
  11779. else
  11780. ret.alongA = 2;
  11781. if (B <= -eps)
  11782. ret.alongB = -2;
  11783. else if (B < eps)
  11784. ret.alongB = -1;
  11785. else if (B - 1 <= -eps)
  11786. ret.alongB = 0;
  11787. else if (B - 1 < eps)
  11788. ret.alongB = 1;
  11789. else
  11790. ret.alongB = 2;
  11791. return ret;
  11792. },
  11793. pointInsideRegion: function(pt, region){
  11794. var x = pt[0];
  11795. var y = pt[1];
  11796. var last_x = region[region.length - 1][0];
  11797. var last_y = region[region.length - 1][1];
  11798. var inside = false;
  11799. for (var i = 0; i < region.length; i++){
  11800. var curr_x = region[i][0];
  11801. var curr_y = region[i][1];
  11802. // if y is between curr_y and last_y, and
  11803. // x is to the right of the boundary created by the line
  11804. if ((curr_y - y > eps) != (last_y - y > eps) &&
  11805. (last_x - curr_x) * (y - curr_y) / (last_y - curr_y) + curr_x - x > eps)
  11806. inside = !inside
  11807. last_x = curr_x;
  11808. last_y = curr_y;
  11809. }
  11810. return inside;
  11811. }
  11812. };
  11813. return my;
  11814. }
  11815. module.exports = Epsilon;
  11816. },{}],27:[function(_dereq_,module,exports){
  11817. // (c) Copyright 2017, Sean Connelly (@voidqk), http://syntheti.cc
  11818. // MIT License
  11819. // Project Home: https://github.com/voidqk/polybooljs
  11820. //
  11821. // convert between PolyBool polygon format and GeoJSON formats (Polygon and MultiPolygon)
  11822. //
  11823. var GeoJSON = {
  11824. // convert a GeoJSON object to a PolyBool polygon
  11825. toPolygon: function(PolyBool, geojson){
  11826. // converts list of LineString's to segments
  11827. function GeoPoly(coords){
  11828. // check for empty coords
  11829. if (coords.length <= 0)
  11830. return PolyBool.segments({ inverted: false, regions: [] });
  11831. // convert LineString to segments
  11832. function LineString(ls){
  11833. // remove tail which should be the same as head
  11834. var reg = ls.slice(0, ls.length - 1);
  11835. return PolyBool.segments({ inverted: false, regions: [reg] });
  11836. }
  11837. // the first LineString is considered the outside
  11838. var out = LineString(coords[0]);
  11839. // the rest of the LineStrings are considered interior holes, so subtract them from the
  11840. // current result
  11841. for (var i = 1; i < coords.length; i++)
  11842. out = PolyBool.selectDifference(PolyBool.combine(out, LineString(coords[i])));
  11843. return out;
  11844. }
  11845. if (geojson.type === 'Polygon'){
  11846. // single polygon, so just convert it and we're done
  11847. return PolyBool.polygon(GeoPoly(geojson.coordinates));
  11848. }
  11849. else if (geojson.type === 'MultiPolygon'){
  11850. // multiple polygons, so union all the polygons together
  11851. var out = PolyBool.segments({ inverted: false, regions: [] });
  11852. for (var i = 0; i < geojson.coordinates.length; i++)
  11853. out = PolyBool.selectUnion(PolyBool.combine(out, GeoPoly(geojson.coordinates[i])));
  11854. return PolyBool.polygon(out);
  11855. }
  11856. throw new Error('PolyBool: Cannot convert GeoJSON object to PolyBool polygon');
  11857. },
  11858. // convert a PolyBool polygon to a GeoJSON object
  11859. fromPolygon: function(PolyBool, eps, poly){
  11860. // make sure out polygon is clean
  11861. poly = PolyBool.polygon(PolyBool.segments(poly));
  11862. // test if r1 is inside r2
  11863. function regionInsideRegion(r1, r2){
  11864. // we're guaranteed no lines intersect (because the polygon is clean), but a vertex
  11865. // could be on the edge -- so we just average pt[0] and pt[1] to produce a point on the
  11866. // edge of the first line, which cannot be on an edge
  11867. return eps.pointInsideRegion([
  11868. (r1[0][0] + r1[1][0]) * 0.5,
  11869. (r1[0][1] + r1[1][1]) * 0.5
  11870. ], r2);
  11871. }
  11872. // calculate inside heirarchy
  11873. //
  11874. // _____________________ _______ roots -> A -> F
  11875. // | A | | F | | |
  11876. // | _______ _______ | | ___ | +-- B +-- G
  11877. // | | B | | C | | | | | | | |
  11878. // | | ___ | | ___ | | | | | | | +-- D
  11879. // | | | D | | | | E | | | | | G | | |
  11880. // | | |___| | | |___| | | | | | | +-- C
  11881. // | |_______| |_______| | | |___| | |
  11882. // |_____________________| |_______| +-- E
  11883. function newNode(region){
  11884. return {
  11885. region: region,
  11886. children: []
  11887. };
  11888. }
  11889. var roots = newNode(null);
  11890. function addChild(root, region){
  11891. // first check if we're inside any children
  11892. for (var i = 0; i < root.children.length; i++){
  11893. var child = root.children[i];
  11894. if (regionInsideRegion(region, child.region)){
  11895. // we are, so insert inside them instead
  11896. addChild(child, region);
  11897. return;
  11898. }
  11899. }
  11900. // not inside any children, so check to see if any children are inside us
  11901. var node = newNode(region);
  11902. for (var i = 0; i < root.children.length; i++){
  11903. var child = root.children[i];
  11904. if (regionInsideRegion(child.region, region)){
  11905. // oops... move the child beneath us, and remove them from root
  11906. node.children.push(child);
  11907. root.children.splice(i, 1);
  11908. i--;
  11909. }
  11910. }
  11911. // now we can add ourselves
  11912. root.children.push(node);
  11913. }
  11914. // add all regions to the root
  11915. for (var i = 0; i < poly.regions.length; i++){
  11916. var region = poly.regions[i];
  11917. if (region.length < 3) // regions must have at least 3 points (sanity check)
  11918. continue;
  11919. addChild(roots, region);
  11920. }
  11921. // with our heirarchy, we can distinguish between exterior borders, and interior holes
  11922. // the root nodes are exterior, children are interior, children's children are exterior,
  11923. // children's children's children are interior, etc
  11924. // while we're at it, exteriors are counter-clockwise, and interiors are clockwise
  11925. function forceWinding(region, clockwise){
  11926. // first, see if we're clockwise or counter-clockwise
  11927. // https://en.wikipedia.org/wiki/Shoelace_formula
  11928. var winding = 0;
  11929. var last_x = region[region.length - 1][0];
  11930. var last_y = region[region.length - 1][1];
  11931. var copy = [];
  11932. for (var i = 0; i < region.length; i++){
  11933. var curr_x = region[i][0];
  11934. var curr_y = region[i][1];
  11935. copy.push([curr_x, curr_y]); // create a copy while we're at it
  11936. winding += curr_y * last_x - curr_x * last_y;
  11937. last_x = curr_x;
  11938. last_y = curr_y;
  11939. }
  11940. // this assumes Cartesian coordinates (Y is positive going up)
  11941. var isclockwise = winding < 0;
  11942. if (isclockwise !== clockwise)
  11943. copy.reverse();
  11944. // while we're here, the last point must be the first point...
  11945. copy.push([copy[0][0], copy[0][1]]);
  11946. return copy;
  11947. }
  11948. var geopolys = [];
  11949. function addExterior(node){
  11950. var poly = [forceWinding(node.region, false)];
  11951. geopolys.push(poly);
  11952. // children of exteriors are interior
  11953. for (var i = 0; i < node.children.length; i++)
  11954. poly.push(getInterior(node.children[i]));
  11955. }
  11956. function getInterior(node){
  11957. // children of interiors are exterior
  11958. for (var i = 0; i < node.children.length; i++)
  11959. addExterior(node.children[i]);
  11960. // return the clockwise interior
  11961. return forceWinding(node.region, true);
  11962. }
  11963. // root nodes are exterior
  11964. for (var i = 0; i < roots.children.length; i++)
  11965. addExterior(roots.children[i]);
  11966. // lastly, construct the approrpriate GeoJSON object
  11967. if (geopolys.length <= 0) // empty GeoJSON Polygon
  11968. return { type: 'Polygon', coordinates: [] };
  11969. if (geopolys.length == 1) // use a GeoJSON Polygon
  11970. return { type: 'Polygon', coordinates: geopolys[0] };
  11971. return { // otherwise, use a GeoJSON MultiPolygon
  11972. type: 'MultiPolygon',
  11973. coordinates: geopolys
  11974. };
  11975. }
  11976. };
  11977. module.exports = GeoJSON;
  11978. },{}],28:[function(_dereq_,module,exports){
  11979. // (c) Copyright 2016, Sean Connelly (@voidqk), http://syntheti.cc
  11980. // MIT License
  11981. // Project Home: https://github.com/voidqk/polybooljs
  11982. //
  11983. // this is the core work-horse
  11984. //
  11985. var LinkedList = _dereq_('./linked-list');
  11986. function Intersecter(selfIntersection, eps, buildLog){
  11987. // selfIntersection is true/false depending on the phase of the overall algorithm
  11988. //
  11989. // segment creation
  11990. //
  11991. function segmentNew(start, end){
  11992. return {
  11993. id: buildLog ? buildLog.segmentId() : -1,
  11994. start: start,
  11995. end: end,
  11996. myFill: {
  11997. above: null, // is there fill above us?
  11998. below: null // is there fill below us?
  11999. },
  12000. otherFill: null
  12001. };
  12002. }
  12003. function segmentCopy(start, end, seg){
  12004. return {
  12005. id: buildLog ? buildLog.segmentId() : -1,
  12006. start: start,
  12007. end: end,
  12008. myFill: {
  12009. above: seg.myFill.above,
  12010. below: seg.myFill.below
  12011. },
  12012. otherFill: null
  12013. };
  12014. }
  12015. //
  12016. // event logic
  12017. //
  12018. var event_root = LinkedList.create();
  12019. function eventCompare(p1_isStart, p1_1, p1_2, p2_isStart, p2_1, p2_2){
  12020. // compare the selected points first
  12021. var comp = eps.pointsCompare(p1_1, p2_1);
  12022. if (comp !== 0)
  12023. return comp;
  12024. // the selected points are the same
  12025. if (eps.pointsSame(p1_2, p2_2)) // if the non-selected points are the same too...
  12026. return 0; // then the segments are equal
  12027. if (p1_isStart !== p2_isStart) // if one is a start and the other isn't...
  12028. return p1_isStart ? 1 : -1; // favor the one that isn't the start
  12029. // otherwise, we'll have to calculate which one is below the other manually
  12030. return eps.pointAboveOrOnLine(p1_2,
  12031. p2_isStart ? p2_1 : p2_2, // order matters
  12032. p2_isStart ? p2_2 : p2_1
  12033. ) ? 1 : -1;
  12034. }
  12035. function eventAdd(ev, other_pt){
  12036. event_root.insertBefore(ev, function(here){
  12037. // should ev be inserted before here?
  12038. var comp = eventCompare(
  12039. ev .isStart, ev .pt, other_pt,
  12040. here.isStart, here.pt, here.other.pt
  12041. );
  12042. return comp < 0;
  12043. });
  12044. }
  12045. function eventAddSegmentStart(seg, primary){
  12046. var ev_start = LinkedList.node({
  12047. isStart: true,
  12048. pt: seg.start,
  12049. seg: seg,
  12050. primary: primary,
  12051. other: null,
  12052. status: null
  12053. });
  12054. eventAdd(ev_start, seg.end);
  12055. return ev_start;
  12056. }
  12057. function eventAddSegmentEnd(ev_start, seg, primary){
  12058. var ev_end = LinkedList.node({
  12059. isStart: false,
  12060. pt: seg.end,
  12061. seg: seg,
  12062. primary: primary,
  12063. other: ev_start,
  12064. status: null
  12065. });
  12066. ev_start.other = ev_end;
  12067. eventAdd(ev_end, ev_start.pt);
  12068. }
  12069. function eventAddSegment(seg, primary){
  12070. var ev_start = eventAddSegmentStart(seg, primary);
  12071. eventAddSegmentEnd(ev_start, seg, primary);
  12072. return ev_start;
  12073. }
  12074. function eventUpdateEnd(ev, end){
  12075. // slides an end backwards
  12076. // (start)------------(end) to:
  12077. // (start)---(end)
  12078. if (buildLog)
  12079. buildLog.segmentChop(ev.seg, end);
  12080. ev.other.remove();
  12081. ev.seg.end = end;
  12082. ev.other.pt = end;
  12083. eventAdd(ev.other, ev.pt);
  12084. }
  12085. function eventDivide(ev, pt){
  12086. var ns = segmentCopy(pt, ev.seg.end, ev.seg);
  12087. eventUpdateEnd(ev, pt);
  12088. return eventAddSegment(ns, ev.primary);
  12089. }
  12090. function calculate(primaryPolyInverted, secondaryPolyInverted){
  12091. // if selfIntersection is true then there is no secondary polygon, so that isn't used
  12092. //
  12093. // status logic
  12094. //
  12095. var status_root = LinkedList.create();
  12096. function statusCompare(ev1, ev2){
  12097. var a1 = ev1.seg.start;
  12098. var a2 = ev1.seg.end;
  12099. var b1 = ev2.seg.start;
  12100. var b2 = ev2.seg.end;
  12101. if (eps.pointsCollinear(a1, b1, b2)){
  12102. if (eps.pointsCollinear(a2, b1, b2))
  12103. return 1;//eventCompare(true, a1, a2, true, b1, b2);
  12104. return eps.pointAboveOrOnLine(a2, b1, b2) ? 1 : -1;
  12105. }
  12106. return eps.pointAboveOrOnLine(a1, b1, b2) ? 1 : -1;
  12107. }
  12108. function statusFindSurrounding(ev){
  12109. return status_root.findTransition(function(here){
  12110. var comp = statusCompare(ev, here.ev);
  12111. return comp > 0;
  12112. });
  12113. }
  12114. function checkIntersection(ev1, ev2){
  12115. // returns the segment equal to ev1, or false if nothing equal
  12116. var seg1 = ev1.seg;
  12117. var seg2 = ev2.seg;
  12118. var a1 = seg1.start;
  12119. var a2 = seg1.end;
  12120. var b1 = seg2.start;
  12121. var b2 = seg2.end;
  12122. if (buildLog)
  12123. buildLog.checkIntersection(seg1, seg2);
  12124. var i = eps.linesIntersect(a1, a2, b1, b2);
  12125. if (i === false){
  12126. // segments are parallel or coincident
  12127. // if points aren't collinear, then the segments are parallel, so no intersections
  12128. if (!eps.pointsCollinear(a1, a2, b1))
  12129. return false;
  12130. // otherwise, segments are on top of each other somehow (aka coincident)
  12131. if (eps.pointsSame(a1, b2) || eps.pointsSame(a2, b1))
  12132. return false; // segments touch at endpoints... no intersection
  12133. var a1_equ_b1 = eps.pointsSame(a1, b1);
  12134. var a2_equ_b2 = eps.pointsSame(a2, b2);
  12135. if (a1_equ_b1 && a2_equ_b2)
  12136. return ev2; // segments are exactly equal
  12137. var a1_between = !a1_equ_b1 && eps.pointBetween(a1, b1, b2);
  12138. var a2_between = !a2_equ_b2 && eps.pointBetween(a2, b1, b2);
  12139. // handy for debugging:
  12140. // buildLog.log({
  12141. // a1_equ_b1: a1_equ_b1,
  12142. // a2_equ_b2: a2_equ_b2,
  12143. // a1_between: a1_between,
  12144. // a2_between: a2_between
  12145. // });
  12146. if (a1_equ_b1){
  12147. if (a2_between){
  12148. // (a1)---(a2)
  12149. // (b1)----------(b2)
  12150. eventDivide(ev2, a2);
  12151. }
  12152. else{
  12153. // (a1)----------(a2)
  12154. // (b1)---(b2)
  12155. eventDivide(ev1, b2);
  12156. }
  12157. return ev2;
  12158. }
  12159. else if (a1_between){
  12160. if (!a2_equ_b2){
  12161. // make a2 equal to b2
  12162. if (a2_between){
  12163. // (a1)---(a2)
  12164. // (b1)-----------------(b2)
  12165. eventDivide(ev2, a2);
  12166. }
  12167. else{
  12168. // (a1)----------(a2)
  12169. // (b1)----------(b2)
  12170. eventDivide(ev1, b2);
  12171. }
  12172. }
  12173. // (a1)---(a2)
  12174. // (b1)----------(b2)
  12175. eventDivide(ev2, a1);
  12176. }
  12177. }
  12178. else{
  12179. // otherwise, lines intersect at i.pt, which may or may not be between the endpoints
  12180. // is A divided between its endpoints? (exclusive)
  12181. if (i.alongA === 0){
  12182. if (i.alongB === -1) // yes, at exactly b1
  12183. eventDivide(ev1, b1);
  12184. else if (i.alongB === 0) // yes, somewhere between B's endpoints
  12185. eventDivide(ev1, i.pt);
  12186. else if (i.alongB === 1) // yes, at exactly b2
  12187. eventDivide(ev1, b2);
  12188. }
  12189. // is B divided between its endpoints? (exclusive)
  12190. if (i.alongB === 0){
  12191. if (i.alongA === -1) // yes, at exactly a1
  12192. eventDivide(ev2, a1);
  12193. else if (i.alongA === 0) // yes, somewhere between A's endpoints (exclusive)
  12194. eventDivide(ev2, i.pt);
  12195. else if (i.alongA === 1) // yes, at exactly a2
  12196. eventDivide(ev2, a2);
  12197. }
  12198. }
  12199. return false;
  12200. }
  12201. //
  12202. // main event loop
  12203. //
  12204. var segments = [];
  12205. while (!event_root.isEmpty()){
  12206. var ev = event_root.getHead();
  12207. if (buildLog)
  12208. buildLog.vert(ev.pt[0]);
  12209. if (ev.isStart){
  12210. if (buildLog)
  12211. buildLog.segmentNew(ev.seg, ev.primary);
  12212. var surrounding = statusFindSurrounding(ev);
  12213. var above = surrounding.before ? surrounding.before.ev : null;
  12214. var below = surrounding.after ? surrounding.after.ev : null;
  12215. if (buildLog){
  12216. buildLog.tempStatus(
  12217. ev.seg,
  12218. above ? above.seg : false,
  12219. below ? below.seg : false
  12220. );
  12221. }
  12222. function checkBothIntersections(){
  12223. if (above){
  12224. var eve = checkIntersection(ev, above);
  12225. if (eve)
  12226. return eve;
  12227. }
  12228. if (below)
  12229. return checkIntersection(ev, below);
  12230. return false;
  12231. }
  12232. var eve = checkBothIntersections();
  12233. if (eve){
  12234. // ev and eve are equal
  12235. // we'll keep eve and throw away ev
  12236. // merge ev.seg's fill information into eve.seg
  12237. if (selfIntersection){
  12238. var toggle; // are we a toggling edge?
  12239. if (ev.seg.myFill.below === null)
  12240. toggle = true;
  12241. else
  12242. toggle = ev.seg.myFill.above !== ev.seg.myFill.below;
  12243. // merge two segments that belong to the same polygon
  12244. // think of this as sandwiching two segments together, where `eve.seg` is
  12245. // the bottom -- this will cause the above fill flag to toggle
  12246. if (toggle)
  12247. eve.seg.myFill.above = !eve.seg.myFill.above;
  12248. }
  12249. else{
  12250. // merge two segments that belong to different polygons
  12251. // each segment has distinct knowledge, so no special logic is needed
  12252. // note that this can only happen once per segment in this phase, because we
  12253. // are guaranteed that all self-intersections are gone
  12254. eve.seg.otherFill = ev.seg.myFill;
  12255. }
  12256. if (buildLog)
  12257. buildLog.segmentUpdate(eve.seg);
  12258. ev.other.remove();
  12259. ev.remove();
  12260. }
  12261. if (event_root.getHead() !== ev){
  12262. // something was inserted before us in the event queue, so loop back around and
  12263. // process it before continuing
  12264. if (buildLog)
  12265. buildLog.rewind(ev.seg);
  12266. continue;
  12267. }
  12268. //
  12269. // calculate fill flags
  12270. //
  12271. if (selfIntersection){
  12272. var toggle; // are we a toggling edge?
  12273. if (ev.seg.myFill.below === null) // if we are a new segment...
  12274. toggle = true; // then we toggle
  12275. else // we are a segment that has previous knowledge from a division
  12276. toggle = ev.seg.myFill.above !== ev.seg.myFill.below; // calculate toggle
  12277. // next, calculate whether we are filled below us
  12278. if (!below){ // if nothing is below us...
  12279. // we are filled below us if the polygon is inverted
  12280. ev.seg.myFill.below = primaryPolyInverted;
  12281. }
  12282. else{
  12283. // otherwise, we know the answer -- it's the same if whatever is below
  12284. // us is filled above it
  12285. ev.seg.myFill.below = below.seg.myFill.above;
  12286. }
  12287. // since now we know if we're filled below us, we can calculate whether
  12288. // we're filled above us by applying toggle to whatever is below us
  12289. if (toggle)
  12290. ev.seg.myFill.above = !ev.seg.myFill.below;
  12291. else
  12292. ev.seg.myFill.above = ev.seg.myFill.below;
  12293. }
  12294. else{
  12295. // now we fill in any missing transition information, since we are all-knowing
  12296. // at this point
  12297. if (ev.seg.otherFill === null){
  12298. // if we don't have other information, then we need to figure out if we're
  12299. // inside the other polygon
  12300. var inside;
  12301. if (!below){
  12302. // if nothing is below us, then we're inside if the other polygon is
  12303. // inverted
  12304. inside =
  12305. ev.primary ? secondaryPolyInverted : primaryPolyInverted;
  12306. }
  12307. else{ // otherwise, something is below us
  12308. // so copy the below segment's other polygon's above
  12309. if (ev.primary === below.primary)
  12310. inside = below.seg.otherFill.above;
  12311. else
  12312. inside = below.seg.myFill.above;
  12313. }
  12314. ev.seg.otherFill = {
  12315. above: inside,
  12316. below: inside
  12317. };
  12318. }
  12319. }
  12320. if (buildLog){
  12321. buildLog.status(
  12322. ev.seg,
  12323. above ? above.seg : false,
  12324. below ? below.seg : false
  12325. );
  12326. }
  12327. // insert the status and remember it for later removal
  12328. ev.other.status = surrounding.insert(LinkedList.node({ ev: ev }));
  12329. }
  12330. else{
  12331. var st = ev.status;
  12332. if (st === null){
  12333. throw new Error('PolyBool: Zero-length segment detected; your epsilon is ' +
  12334. 'probably too small or too large');
  12335. }
  12336. // removing the status will create two new adjacent edges, so we'll need to check
  12337. // for those
  12338. if (status_root.exists(st.prev) && status_root.exists(st.next))
  12339. checkIntersection(st.prev.ev, st.next.ev);
  12340. if (buildLog)
  12341. buildLog.statusRemove(st.ev.seg);
  12342. // remove the status
  12343. st.remove();
  12344. // if we've reached this point, we've calculated everything there is to know, so
  12345. // save the segment for reporting
  12346. if (!ev.primary){
  12347. // make sure `seg.myFill` actually points to the primary polygon though
  12348. var s = ev.seg.myFill;
  12349. ev.seg.myFill = ev.seg.otherFill;
  12350. ev.seg.otherFill = s;
  12351. }
  12352. segments.push(ev.seg);
  12353. }
  12354. // remove the event and continue
  12355. event_root.getHead().remove();
  12356. }
  12357. if (buildLog)
  12358. buildLog.done();
  12359. return segments;
  12360. }
  12361. // return the appropriate API depending on what we're doing
  12362. if (!selfIntersection){
  12363. // performing combination of polygons, so only deal with already-processed segments
  12364. return {
  12365. calculate: function(segments1, inverted1, segments2, inverted2){
  12366. // segmentsX come from the self-intersection API, or this API
  12367. // invertedX is whether we treat that list of segments as an inverted polygon or not
  12368. // returns segments that can be used for further operations
  12369. segments1.forEach(function(seg){
  12370. eventAddSegment(segmentCopy(seg.start, seg.end, seg), true);
  12371. });
  12372. segments2.forEach(function(seg){
  12373. eventAddSegment(segmentCopy(seg.start, seg.end, seg), false);
  12374. });
  12375. return calculate(inverted1, inverted2);
  12376. }
  12377. };
  12378. }
  12379. // otherwise, performing self-intersection, so deal with regions
  12380. return {
  12381. addRegion: function(region){
  12382. // regions are a list of points:
  12383. // [ [0, 0], [100, 0], [50, 100] ]
  12384. // you can add multiple regions before running calculate
  12385. var pt1;
  12386. var pt2 = region[region.length - 1];
  12387. for (var i = 0; i < region.length; i++){
  12388. pt1 = pt2;
  12389. pt2 = region[i];
  12390. var forward = eps.pointsCompare(pt1, pt2);
  12391. if (forward === 0) // points are equal, so we have a zero-length segment
  12392. continue; // just skip it
  12393. eventAddSegment(
  12394. segmentNew(
  12395. forward < 0 ? pt1 : pt2,
  12396. forward < 0 ? pt2 : pt1
  12397. ),
  12398. true
  12399. );
  12400. }
  12401. },
  12402. calculate: function(inverted){
  12403. // is the polygon inverted?
  12404. // returns segments
  12405. return calculate(inverted, false);
  12406. }
  12407. };
  12408. }
  12409. module.exports = Intersecter;
  12410. },{"./linked-list":29}],29:[function(_dereq_,module,exports){
  12411. // (c) Copyright 2016, Sean Connelly (@voidqk), http://syntheti.cc
  12412. // MIT License
  12413. // Project Home: https://github.com/voidqk/polybooljs
  12414. //
  12415. // simple linked list implementation that allows you to traverse down nodes and save positions
  12416. //
  12417. var LinkedList = {
  12418. create: function(){
  12419. var my = {
  12420. root: { root: true, next: null },
  12421. exists: function(node){
  12422. if (node === null || node === my.root)
  12423. return false;
  12424. return true;
  12425. },
  12426. isEmpty: function(){
  12427. return my.root.next === null;
  12428. },
  12429. getHead: function(){
  12430. return my.root.next;
  12431. },
  12432. insertBefore: function(node, check){
  12433. var last = my.root;
  12434. var here = my.root.next;
  12435. while (here !== null){
  12436. if (check(here)){
  12437. node.prev = here.prev;
  12438. node.next = here;
  12439. here.prev.next = node;
  12440. here.prev = node;
  12441. return;
  12442. }
  12443. last = here;
  12444. here = here.next;
  12445. }
  12446. last.next = node;
  12447. node.prev = last;
  12448. node.next = null;
  12449. },
  12450. findTransition: function(check){
  12451. var prev = my.root;
  12452. var here = my.root.next;
  12453. while (here !== null){
  12454. if (check(here))
  12455. break;
  12456. prev = here;
  12457. here = here.next;
  12458. }
  12459. return {
  12460. before: prev === my.root ? null : prev,
  12461. after: here,
  12462. insert: function(node){
  12463. node.prev = prev;
  12464. node.next = here;
  12465. prev.next = node;
  12466. if (here !== null)
  12467. here.prev = node;
  12468. return node;
  12469. }
  12470. };
  12471. }
  12472. };
  12473. return my;
  12474. },
  12475. node: function(data){
  12476. data.prev = null;
  12477. data.next = null;
  12478. data.remove = function(){
  12479. data.prev.next = data.next;
  12480. if (data.next)
  12481. data.next.prev = data.prev;
  12482. data.prev = null;
  12483. data.next = null;
  12484. };
  12485. return data;
  12486. }
  12487. };
  12488. module.exports = LinkedList;
  12489. },{}],30:[function(_dereq_,module,exports){
  12490. // (c) Copyright 2016, Sean Connelly (@voidqk), http://syntheti.cc
  12491. // MIT License
  12492. // Project Home: https://github.com/voidqk/polybooljs
  12493. //
  12494. // converts a list of segments into a list of regions, while also removing unnecessary verticies
  12495. //
  12496. function SegmentChainer(segments, eps, buildLog){
  12497. var chains = [];
  12498. var regions = [];
  12499. segments.forEach(function(seg){
  12500. var pt1 = seg.start;
  12501. var pt2 = seg.end;
  12502. if (eps.pointsSame(pt1, pt2)){
  12503. console.warn('PolyBool: Warning: Zero-length segment detected; your epsilon is ' +
  12504. 'probably too small or too large');
  12505. return;
  12506. }
  12507. if (buildLog)
  12508. buildLog.chainStart(seg);
  12509. // search for two chains that this segment matches
  12510. var first_match = {
  12511. index: 0,
  12512. matches_head: false,
  12513. matches_pt1: false
  12514. };
  12515. var second_match = {
  12516. index: 0,
  12517. matches_head: false,
  12518. matches_pt1: false
  12519. };
  12520. var next_match = first_match;
  12521. function setMatch(index, matches_head, matches_pt1){
  12522. // return true if we've matched twice
  12523. next_match.index = index;
  12524. next_match.matches_head = matches_head;
  12525. next_match.matches_pt1 = matches_pt1;
  12526. if (next_match === first_match){
  12527. next_match = second_match;
  12528. return false;
  12529. }
  12530. next_match = null;
  12531. return true; // we've matched twice, we're done here
  12532. }
  12533. for (var i = 0; i < chains.length; i++){
  12534. var chain = chains[i];
  12535. var head = chain[0];
  12536. var head2 = chain[1];
  12537. var tail = chain[chain.length - 1];
  12538. var tail2 = chain[chain.length - 2];
  12539. if (eps.pointsSame(head, pt1)){
  12540. if (setMatch(i, true, true))
  12541. break;
  12542. }
  12543. else if (eps.pointsSame(head, pt2)){
  12544. if (setMatch(i, true, false))
  12545. break;
  12546. }
  12547. else if (eps.pointsSame(tail, pt1)){
  12548. if (setMatch(i, false, true))
  12549. break;
  12550. }
  12551. else if (eps.pointsSame(tail, pt2)){
  12552. if (setMatch(i, false, false))
  12553. break;
  12554. }
  12555. }
  12556. if (next_match === first_match){
  12557. // we didn't match anything, so create a new chain
  12558. chains.push([ pt1, pt2 ]);
  12559. if (buildLog)
  12560. buildLog.chainNew(pt1, pt2);
  12561. return;
  12562. }
  12563. if (next_match === second_match){
  12564. // we matched a single chain
  12565. if (buildLog)
  12566. buildLog.chainMatch(first_match.index);
  12567. // add the other point to the apporpriate end, and check to see if we've closed the
  12568. // chain into a loop
  12569. var index = first_match.index;
  12570. var pt = first_match.matches_pt1 ? pt2 : pt1; // if we matched pt1, then we add pt2, etc
  12571. var addToHead = first_match.matches_head; // if we matched at head, then add to the head
  12572. var chain = chains[index];
  12573. var grow = addToHead ? chain[0] : chain[chain.length - 1];
  12574. var grow2 = addToHead ? chain[1] : chain[chain.length - 2];
  12575. var oppo = addToHead ? chain[chain.length - 1] : chain[0];
  12576. var oppo2 = addToHead ? chain[chain.length - 2] : chain[1];
  12577. if (eps.pointsCollinear(grow2, grow, pt)){
  12578. // grow isn't needed because it's directly between grow2 and pt:
  12579. // grow2 ---grow---> pt
  12580. if (addToHead){
  12581. if (buildLog)
  12582. buildLog.chainRemoveHead(first_match.index, pt);
  12583. chain.shift();
  12584. }
  12585. else{
  12586. if (buildLog)
  12587. buildLog.chainRemoveTail(first_match.index, pt);
  12588. chain.pop();
  12589. }
  12590. grow = grow2; // old grow is gone... new grow is what grow2 was
  12591. }
  12592. if (eps.pointsSame(oppo, pt)){
  12593. // we're closing the loop, so remove chain from chains
  12594. chains.splice(index, 1);
  12595. if (eps.pointsCollinear(oppo2, oppo, grow)){
  12596. // oppo isn't needed because it's directly between oppo2 and grow:
  12597. // oppo2 ---oppo--->grow
  12598. if (addToHead){
  12599. if (buildLog)
  12600. buildLog.chainRemoveTail(first_match.index, grow);
  12601. chain.pop();
  12602. }
  12603. else{
  12604. if (buildLog)
  12605. buildLog.chainRemoveHead(first_match.index, grow);
  12606. chain.shift();
  12607. }
  12608. }
  12609. if (buildLog)
  12610. buildLog.chainClose(first_match.index);
  12611. // we have a closed chain!
  12612. regions.push(chain);
  12613. return;
  12614. }
  12615. // not closing a loop, so just add it to the apporpriate side
  12616. if (addToHead){
  12617. if (buildLog)
  12618. buildLog.chainAddHead(first_match.index, pt);
  12619. chain.unshift(pt);
  12620. }
  12621. else{
  12622. if (buildLog)
  12623. buildLog.chainAddTail(first_match.index, pt);
  12624. chain.push(pt);
  12625. }
  12626. return;
  12627. }
  12628. // otherwise, we matched two chains, so we need to combine those chains together
  12629. function reverseChain(index){
  12630. if (buildLog)
  12631. buildLog.chainReverse(index);
  12632. chains[index].reverse(); // gee, that's easy
  12633. }
  12634. function appendChain(index1, index2){
  12635. // index1 gets index2 appended to it, and index2 is removed
  12636. var chain1 = chains[index1];
  12637. var chain2 = chains[index2];
  12638. var tail = chain1[chain1.length - 1];
  12639. var tail2 = chain1[chain1.length - 2];
  12640. var head = chain2[0];
  12641. var head2 = chain2[1];
  12642. if (eps.pointsCollinear(tail2, tail, head)){
  12643. // tail isn't needed because it's directly between tail2 and head
  12644. // tail2 ---tail---> head
  12645. if (buildLog)
  12646. buildLog.chainRemoveTail(index1, tail);
  12647. chain1.pop();
  12648. tail = tail2; // old tail is gone... new tail is what tail2 was
  12649. }
  12650. if (eps.pointsCollinear(tail, head, head2)){
  12651. // head isn't needed because it's directly between tail and head2
  12652. // tail ---head---> head2
  12653. if (buildLog)
  12654. buildLog.chainRemoveHead(index2, head);
  12655. chain2.shift();
  12656. }
  12657. if (buildLog)
  12658. buildLog.chainJoin(index1, index2);
  12659. chains[index1] = chain1.concat(chain2);
  12660. chains.splice(index2, 1);
  12661. }
  12662. var F = first_match.index;
  12663. var S = second_match.index;
  12664. if (buildLog)
  12665. buildLog.chainConnect(F, S);
  12666. var reverseF = chains[F].length < chains[S].length; // reverse the shorter chain, if needed
  12667. if (first_match.matches_head){
  12668. if (second_match.matches_head){
  12669. if (reverseF){
  12670. // <<<< F <<<< --- >>>> S >>>>
  12671. reverseChain(F);
  12672. // >>>> F >>>> --- >>>> S >>>>
  12673. appendChain(F, S);
  12674. }
  12675. else{
  12676. // <<<< F <<<< --- >>>> S >>>>
  12677. reverseChain(S);
  12678. // <<<< F <<<< --- <<<< S <<<< logically same as:
  12679. // >>>> S >>>> --- >>>> F >>>>
  12680. appendChain(S, F);
  12681. }
  12682. }
  12683. else{
  12684. // <<<< F <<<< --- <<<< S <<<< logically same as:
  12685. // >>>> S >>>> --- >>>> F >>>>
  12686. appendChain(S, F);
  12687. }
  12688. }
  12689. else{
  12690. if (second_match.matches_head){
  12691. // >>>> F >>>> --- >>>> S >>>>
  12692. appendChain(F, S);
  12693. }
  12694. else{
  12695. if (reverseF){
  12696. // >>>> F >>>> --- <<<< S <<<<
  12697. reverseChain(F);
  12698. // <<<< F <<<< --- <<<< S <<<< logically same as:
  12699. // >>>> S >>>> --- >>>> F >>>>
  12700. appendChain(S, F);
  12701. }
  12702. else{
  12703. // >>>> F >>>> --- <<<< S <<<<
  12704. reverseChain(S);
  12705. // >>>> F >>>> --- >>>> S >>>>
  12706. appendChain(F, S);
  12707. }
  12708. }
  12709. }
  12710. });
  12711. return regions;
  12712. }
  12713. module.exports = SegmentChainer;
  12714. },{}],31:[function(_dereq_,module,exports){
  12715. // (c) Copyright 2016, Sean Connelly (@voidqk), http://syntheti.cc
  12716. // MIT License
  12717. // Project Home: https://github.com/voidqk/polybooljs
  12718. //
  12719. // filter a list of segments based on boolean operations
  12720. //
  12721. function select(segments, selection, buildLog){
  12722. var result = [];
  12723. segments.forEach(function(seg){
  12724. var index =
  12725. (seg.myFill.above ? 8 : 0) +
  12726. (seg.myFill.below ? 4 : 0) +
  12727. ((seg.otherFill && seg.otherFill.above) ? 2 : 0) +
  12728. ((seg.otherFill && seg.otherFill.below) ? 1 : 0);
  12729. if (selection[index] !== 0){
  12730. // copy the segment to the results, while also calculating the fill status
  12731. result.push({
  12732. id: buildLog ? buildLog.segmentId() : -1,
  12733. start: seg.start,
  12734. end: seg.end,
  12735. myFill: {
  12736. above: selection[index] === 1, // 1 if filled above
  12737. below: selection[index] === 2 // 2 if filled below
  12738. },
  12739. otherFill: null
  12740. });
  12741. }
  12742. });
  12743. if (buildLog)
  12744. buildLog.selected(result);
  12745. return result;
  12746. }
  12747. var SegmentSelector = {
  12748. union: function(segments, buildLog){ // primary | secondary
  12749. // above1 below1 above2 below2 Keep? Value
  12750. // 0 0 0 0 => no 0
  12751. // 0 0 0 1 => yes filled below 2
  12752. // 0 0 1 0 => yes filled above 1
  12753. // 0 0 1 1 => no 0
  12754. // 0 1 0 0 => yes filled below 2
  12755. // 0 1 0 1 => yes filled below 2
  12756. // 0 1 1 0 => no 0
  12757. // 0 1 1 1 => no 0
  12758. // 1 0 0 0 => yes filled above 1
  12759. // 1 0 0 1 => no 0
  12760. // 1 0 1 0 => yes filled above 1
  12761. // 1 0 1 1 => no 0
  12762. // 1 1 0 0 => no 0
  12763. // 1 1 0 1 => no 0
  12764. // 1 1 1 0 => no 0
  12765. // 1 1 1 1 => no 0
  12766. return select(segments, [
  12767. 0, 2, 1, 0,
  12768. 2, 2, 0, 0,
  12769. 1, 0, 1, 0,
  12770. 0, 0, 0, 0
  12771. ], buildLog);
  12772. },
  12773. intersect: function(segments, buildLog){ // primary & secondary
  12774. // above1 below1 above2 below2 Keep? Value
  12775. // 0 0 0 0 => no 0
  12776. // 0 0 0 1 => no 0
  12777. // 0 0 1 0 => no 0
  12778. // 0 0 1 1 => no 0
  12779. // 0 1 0 0 => no 0
  12780. // 0 1 0 1 => yes filled below 2
  12781. // 0 1 1 0 => no 0
  12782. // 0 1 1 1 => yes filled below 2
  12783. // 1 0 0 0 => no 0
  12784. // 1 0 0 1 => no 0
  12785. // 1 0 1 0 => yes filled above 1
  12786. // 1 0 1 1 => yes filled above 1
  12787. // 1 1 0 0 => no 0
  12788. // 1 1 0 1 => yes filled below 2
  12789. // 1 1 1 0 => yes filled above 1
  12790. // 1 1 1 1 => no 0
  12791. return select(segments, [
  12792. 0, 0, 0, 0,
  12793. 0, 2, 0, 2,
  12794. 0, 0, 1, 1,
  12795. 0, 2, 1, 0
  12796. ], buildLog);
  12797. },
  12798. difference: function(segments, buildLog){ // primary - secondary
  12799. // above1 below1 above2 below2 Keep? Value
  12800. // 0 0 0 0 => no 0
  12801. // 0 0 0 1 => no 0
  12802. // 0 0 1 0 => no 0
  12803. // 0 0 1 1 => no 0
  12804. // 0 1 0 0 => yes filled below 2
  12805. // 0 1 0 1 => no 0
  12806. // 0 1 1 0 => yes filled below 2
  12807. // 0 1 1 1 => no 0
  12808. // 1 0 0 0 => yes filled above 1
  12809. // 1 0 0 1 => yes filled above 1
  12810. // 1 0 1 0 => no 0
  12811. // 1 0 1 1 => no 0
  12812. // 1 1 0 0 => no 0
  12813. // 1 1 0 1 => yes filled above 1
  12814. // 1 1 1 0 => yes filled below 2
  12815. // 1 1 1 1 => no 0
  12816. return select(segments, [
  12817. 0, 0, 0, 0,
  12818. 2, 0, 2, 0,
  12819. 1, 1, 0, 0,
  12820. 0, 1, 2, 0
  12821. ], buildLog);
  12822. },
  12823. differenceRev: function(segments, buildLog){ // secondary - primary
  12824. // above1 below1 above2 below2 Keep? Value
  12825. // 0 0 0 0 => no 0
  12826. // 0 0 0 1 => yes filled below 2
  12827. // 0 0 1 0 => yes filled above 1
  12828. // 0 0 1 1 => no 0
  12829. // 0 1 0 0 => no 0
  12830. // 0 1 0 1 => no 0
  12831. // 0 1 1 0 => yes filled above 1
  12832. // 0 1 1 1 => yes filled above 1
  12833. // 1 0 0 0 => no 0
  12834. // 1 0 0 1 => yes filled below 2
  12835. // 1 0 1 0 => no 0
  12836. // 1 0 1 1 => yes filled below 2
  12837. // 1 1 0 0 => no 0
  12838. // 1 1 0 1 => no 0
  12839. // 1 1 1 0 => no 0
  12840. // 1 1 1 1 => no 0
  12841. return select(segments, [
  12842. 0, 2, 1, 0,
  12843. 0, 0, 1, 1,
  12844. 0, 2, 0, 2,
  12845. 0, 0, 0, 0
  12846. ], buildLog);
  12847. },
  12848. xor: function(segments, buildLog){ // primary ^ secondary
  12849. // above1 below1 above2 below2 Keep? Value
  12850. // 0 0 0 0 => no 0
  12851. // 0 0 0 1 => yes filled below 2
  12852. // 0 0 1 0 => yes filled above 1
  12853. // 0 0 1 1 => no 0
  12854. // 0 1 0 0 => yes filled below 2
  12855. // 0 1 0 1 => no 0
  12856. // 0 1 1 0 => no 0
  12857. // 0 1 1 1 => yes filled above 1
  12858. // 1 0 0 0 => yes filled above 1
  12859. // 1 0 0 1 => no 0
  12860. // 1 0 1 0 => no 0
  12861. // 1 0 1 1 => yes filled below 2
  12862. // 1 1 0 0 => no 0
  12863. // 1 1 0 1 => yes filled above 1
  12864. // 1 1 1 0 => yes filled below 2
  12865. // 1 1 1 1 => no 0
  12866. return select(segments, [
  12867. 0, 2, 1, 0,
  12868. 2, 0, 0, 1,
  12869. 1, 0, 0, 2,
  12870. 0, 1, 2, 0
  12871. ], buildLog);
  12872. }
  12873. };
  12874. module.exports = SegmentSelector;
  12875. },{}],32:[function(_dereq_,module,exports){
  12876. // shim for using process in browser
  12877. var process = module.exports = {};
  12878. // cached from whatever global is present so that test runners that stub it
  12879. // don't break things. But we need to wrap it in a try catch in case it is
  12880. // wrapped in strict mode code which doesn't define any globals. It's inside a
  12881. // function because try/catches deoptimize in certain engines.
  12882. var cachedSetTimeout;
  12883. var cachedClearTimeout;
  12884. function defaultSetTimout() {
  12885. throw new Error('setTimeout has not been defined');
  12886. }
  12887. function defaultClearTimeout () {
  12888. throw new Error('clearTimeout has not been defined');
  12889. }
  12890. (function () {
  12891. try {
  12892. if (typeof setTimeout === 'function') {
  12893. cachedSetTimeout = setTimeout;
  12894. } else {
  12895. cachedSetTimeout = defaultSetTimout;
  12896. }
  12897. } catch (e) {
  12898. cachedSetTimeout = defaultSetTimout;
  12899. }
  12900. try {
  12901. if (typeof clearTimeout === 'function') {
  12902. cachedClearTimeout = clearTimeout;
  12903. } else {
  12904. cachedClearTimeout = defaultClearTimeout;
  12905. }
  12906. } catch (e) {
  12907. cachedClearTimeout = defaultClearTimeout;
  12908. }
  12909. } ())
  12910. function runTimeout(fun) {
  12911. if (cachedSetTimeout === setTimeout) {
  12912. //normal enviroments in sane situations
  12913. return setTimeout(fun, 0);
  12914. }
  12915. // if setTimeout wasn't available but was latter defined
  12916. if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
  12917. cachedSetTimeout = setTimeout;
  12918. return setTimeout(fun, 0);
  12919. }
  12920. try {
  12921. // when when somebody has screwed with setTimeout but no I.E. maddness
  12922. return cachedSetTimeout(fun, 0);
  12923. } catch(e){
  12924. try {
  12925. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  12926. return cachedSetTimeout.call(null, fun, 0);
  12927. } catch(e){
  12928. // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
  12929. return cachedSetTimeout.call(this, fun, 0);
  12930. }
  12931. }
  12932. }
  12933. function runClearTimeout(marker) {
  12934. if (cachedClearTimeout === clearTimeout) {
  12935. //normal enviroments in sane situations
  12936. return clearTimeout(marker);
  12937. }
  12938. // if clearTimeout wasn't available but was latter defined
  12939. if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
  12940. cachedClearTimeout = clearTimeout;
  12941. return clearTimeout(marker);
  12942. }
  12943. try {
  12944. // when when somebody has screwed with setTimeout but no I.E. maddness
  12945. return cachedClearTimeout(marker);
  12946. } catch (e){
  12947. try {
  12948. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  12949. return cachedClearTimeout.call(null, marker);
  12950. } catch (e){
  12951. // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
  12952. // Some versions of I.E. have different rules for clearTimeout vs setTimeout
  12953. return cachedClearTimeout.call(this, marker);
  12954. }
  12955. }
  12956. }
  12957. var queue = [];
  12958. var draining = false;
  12959. var currentQueue;
  12960. var queueIndex = -1;
  12961. function cleanUpNextTick() {
  12962. if (!draining || !currentQueue) {
  12963. return;
  12964. }
  12965. draining = false;
  12966. if (currentQueue.length) {
  12967. queue = currentQueue.concat(queue);
  12968. } else {
  12969. queueIndex = -1;
  12970. }
  12971. if (queue.length) {
  12972. drainQueue();
  12973. }
  12974. }
  12975. function drainQueue() {
  12976. if (draining) {
  12977. return;
  12978. }
  12979. var timeout = runTimeout(cleanUpNextTick);
  12980. draining = true;
  12981. var len = queue.length;
  12982. while(len) {
  12983. currentQueue = queue;
  12984. queue = [];
  12985. while (++queueIndex < len) {
  12986. if (currentQueue) {
  12987. currentQueue[queueIndex].run();
  12988. }
  12989. }
  12990. queueIndex = -1;
  12991. len = queue.length;
  12992. }
  12993. currentQueue = null;
  12994. draining = false;
  12995. runClearTimeout(timeout);
  12996. }
  12997. process.nextTick = function (fun) {
  12998. var args = new Array(arguments.length - 1);
  12999. if (arguments.length > 1) {
  13000. for (var i = 1; i < arguments.length; i++) {
  13001. args[i - 1] = arguments[i];
  13002. }
  13003. }
  13004. queue.push(new Item(fun, args));
  13005. if (queue.length === 1 && !draining) {
  13006. runTimeout(drainQueue);
  13007. }
  13008. };
  13009. // v8 likes predictible objects
  13010. function Item(fun, array) {
  13011. this.fun = fun;
  13012. this.array = array;
  13013. }
  13014. Item.prototype.run = function () {
  13015. this.fun.apply(null, this.array);
  13016. };
  13017. process.title = 'browser';
  13018. process.browser = true;
  13019. process.env = {};
  13020. process.argv = [];
  13021. process.version = ''; // empty string to avoid regexp issues
  13022. process.versions = {};
  13023. function noop() {}
  13024. process.on = noop;
  13025. process.addListener = noop;
  13026. process.once = noop;
  13027. process.off = noop;
  13028. process.removeListener = noop;
  13029. process.removeAllListeners = noop;
  13030. process.emit = noop;
  13031. process.prependListener = noop;
  13032. process.prependOnceListener = noop;
  13033. process.listeners = function (name) { return [] }
  13034. process.binding = function (name) {
  13035. throw new Error('process.binding is not supported');
  13036. };
  13037. process.cwd = function () { return '/' };
  13038. process.chdir = function (dir) {
  13039. throw new Error('process.chdir is not supported');
  13040. };
  13041. process.umask = function() { return 0; };
  13042. },{}],33:[function(_dereq_,module,exports){
  13043. // TinyColor v1.4.1
  13044. // https://github.com/bgrins/TinyColor
  13045. // Brian Grinstead, MIT License
  13046. (function(Math) {
  13047. var trimLeft = /^\s+/,
  13048. trimRight = /\s+$/,
  13049. tinyCounter = 0,
  13050. mathRound = Math.round,
  13051. mathMin = Math.min,
  13052. mathMax = Math.max,
  13053. mathRandom = Math.random;
  13054. function tinycolor (color, opts) {
  13055. color = (color) ? color : '';
  13056. opts = opts || { };
  13057. // If input is already a tinycolor, return itself
  13058. if (color instanceof tinycolor) {
  13059. return color;
  13060. }
  13061. // If we are called as a function, call using new instead
  13062. if (!(this instanceof tinycolor)) {
  13063. return new tinycolor(color, opts);
  13064. }
  13065. var rgb = inputToRGB(color);
  13066. this._originalInput = color,
  13067. this._r = rgb.r,
  13068. this._g = rgb.g,
  13069. this._b = rgb.b,
  13070. this._a = rgb.a,
  13071. this._roundA = mathRound(100*this._a) / 100,
  13072. this._format = opts.format || rgb.format;
  13073. this._gradientType = opts.gradientType;
  13074. // Don't let the range of [0,255] come back in [0,1].
  13075. // Potentially lose a little bit of precision here, but will fix issues where
  13076. // .5 gets interpreted as half of the total, instead of half of 1
  13077. // If it was supposed to be 128, this was already taken care of by `inputToRgb`
  13078. if (this._r < 1) { this._r = mathRound(this._r); }
  13079. if (this._g < 1) { this._g = mathRound(this._g); }
  13080. if (this._b < 1) { this._b = mathRound(this._b); }
  13081. this._ok = rgb.ok;
  13082. this._tc_id = tinyCounter++;
  13083. }
  13084. tinycolor.prototype = {
  13085. isDark: function() {
  13086. return this.getBrightness() < 128;
  13087. },
  13088. isLight: function() {
  13089. return !this.isDark();
  13090. },
  13091. isValid: function() {
  13092. return this._ok;
  13093. },
  13094. getOriginalInput: function() {
  13095. return this._originalInput;
  13096. },
  13097. getFormat: function() {
  13098. return this._format;
  13099. },
  13100. getAlpha: function() {
  13101. return this._a;
  13102. },
  13103. getBrightness: function() {
  13104. //http://www.w3.org/TR/AERT#color-contrast
  13105. var rgb = this.toRgb();
  13106. return (rgb.r * 299 + rgb.g * 587 + rgb.b * 114) / 1000;
  13107. },
  13108. getLuminance: function() {
  13109. //http://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef
  13110. var rgb = this.toRgb();
  13111. var RsRGB, GsRGB, BsRGB, R, G, B;
  13112. RsRGB = rgb.r/255;
  13113. GsRGB = rgb.g/255;
  13114. BsRGB = rgb.b/255;
  13115. if (RsRGB <= 0.03928) {R = RsRGB / 12.92;} else {R = Math.pow(((RsRGB + 0.055) / 1.055), 2.4);}
  13116. if (GsRGB <= 0.03928) {G = GsRGB / 12.92;} else {G = Math.pow(((GsRGB + 0.055) / 1.055), 2.4);}
  13117. if (BsRGB <= 0.03928) {B = BsRGB / 12.92;} else {B = Math.pow(((BsRGB + 0.055) / 1.055), 2.4);}
  13118. return (0.2126 * R) + (0.7152 * G) + (0.0722 * B);
  13119. },
  13120. setAlpha: function(value) {
  13121. this._a = boundAlpha(value);
  13122. this._roundA = mathRound(100*this._a) / 100;
  13123. return this;
  13124. },
  13125. toHsv: function() {
  13126. var hsv = rgbToHsv(this._r, this._g, this._b);
  13127. return { h: hsv.h * 360, s: hsv.s, v: hsv.v, a: this._a };
  13128. },
  13129. toHsvString: function() {
  13130. var hsv = rgbToHsv(this._r, this._g, this._b);
  13131. var h = mathRound(hsv.h * 360), s = mathRound(hsv.s * 100), v = mathRound(hsv.v * 100);
  13132. return (this._a == 1) ?
  13133. "hsv(" + h + ", " + s + "%, " + v + "%)" :
  13134. "hsva(" + h + ", " + s + "%, " + v + "%, "+ this._roundA + ")";
  13135. },
  13136. toHsl: function() {
  13137. var hsl = rgbToHsl(this._r, this._g, this._b);
  13138. return { h: hsl.h * 360, s: hsl.s, l: hsl.l, a: this._a };
  13139. },
  13140. toHslString: function() {
  13141. var hsl = rgbToHsl(this._r, this._g, this._b);
  13142. var h = mathRound(hsl.h * 360), s = mathRound(hsl.s * 100), l = mathRound(hsl.l * 100);
  13143. return (this._a == 1) ?
  13144. "hsl(" + h + ", " + s + "%, " + l + "%)" :
  13145. "hsla(" + h + ", " + s + "%, " + l + "%, "+ this._roundA + ")";
  13146. },
  13147. toHex: function(allow3Char) {
  13148. return rgbToHex(this._r, this._g, this._b, allow3Char);
  13149. },
  13150. toHexString: function(allow3Char) {
  13151. return '#' + this.toHex(allow3Char);
  13152. },
  13153. toHex8: function(allow4Char) {
  13154. return rgbaToHex(this._r, this._g, this._b, this._a, allow4Char);
  13155. },
  13156. toHex8String: function(allow4Char) {
  13157. return '#' + this.toHex8(allow4Char);
  13158. },
  13159. toRgb: function() {
  13160. return { r: mathRound(this._r), g: mathRound(this._g), b: mathRound(this._b), a: this._a };
  13161. },
  13162. toRgbString: function() {
  13163. return (this._a == 1) ?
  13164. "rgb(" + mathRound(this._r) + ", " + mathRound(this._g) + ", " + mathRound(this._b) + ")" :
  13165. "rgba(" + mathRound(this._r) + ", " + mathRound(this._g) + ", " + mathRound(this._b) + ", " + this._roundA + ")";
  13166. },
  13167. toPercentageRgb: function() {
  13168. return { r: mathRound(bound01(this._r, 255) * 100) + "%", g: mathRound(bound01(this._g, 255) * 100) + "%", b: mathRound(bound01(this._b, 255) * 100) + "%", a: this._a };
  13169. },
  13170. toPercentageRgbString: function() {
  13171. return (this._a == 1) ?
  13172. "rgb(" + mathRound(bound01(this._r, 255) * 100) + "%, " + mathRound(bound01(this._g, 255) * 100) + "%, " + mathRound(bound01(this._b, 255) * 100) + "%)" :
  13173. "rgba(" + mathRound(bound01(this._r, 255) * 100) + "%, " + mathRound(bound01(this._g, 255) * 100) + "%, " + mathRound(bound01(this._b, 255) * 100) + "%, " + this._roundA + ")";
  13174. },
  13175. toName: function() {
  13176. if (this._a === 0) {
  13177. return "transparent";
  13178. }
  13179. if (this._a < 1) {
  13180. return false;
  13181. }
  13182. return hexNames[rgbToHex(this._r, this._g, this._b, true)] || false;
  13183. },
  13184. toFilter: function(secondColor) {
  13185. var hex8String = '#' + rgbaToArgbHex(this._r, this._g, this._b, this._a);
  13186. var secondHex8String = hex8String;
  13187. var gradientType = this._gradientType ? "GradientType = 1, " : "";
  13188. if (secondColor) {
  13189. var s = tinycolor(secondColor);
  13190. secondHex8String = '#' + rgbaToArgbHex(s._r, s._g, s._b, s._a);
  13191. }
  13192. return "progid:DXImageTransform.Microsoft.gradient("+gradientType+"startColorstr="+hex8String+",endColorstr="+secondHex8String+")";
  13193. },
  13194. toString: function(format) {
  13195. var formatSet = !!format;
  13196. format = format || this._format;
  13197. var formattedString = false;
  13198. var hasAlpha = this._a < 1 && this._a >= 0;
  13199. var needsAlphaFormat = !formatSet && hasAlpha && (format === "hex" || format === "hex6" || format === "hex3" || format === "hex4" || format === "hex8" || format === "name");
  13200. if (needsAlphaFormat) {
  13201. // Special case for "transparent", all other non-alpha formats
  13202. // will return rgba when there is transparency.
  13203. if (format === "name" && this._a === 0) {
  13204. return this.toName();
  13205. }
  13206. return this.toRgbString();
  13207. }
  13208. if (format === "rgb") {
  13209. formattedString = this.toRgbString();
  13210. }
  13211. if (format === "prgb") {
  13212. formattedString = this.toPercentageRgbString();
  13213. }
  13214. if (format === "hex" || format === "hex6") {
  13215. formattedString = this.toHexString();
  13216. }
  13217. if (format === "hex3") {
  13218. formattedString = this.toHexString(true);
  13219. }
  13220. if (format === "hex4") {
  13221. formattedString = this.toHex8String(true);
  13222. }
  13223. if (format === "hex8") {
  13224. formattedString = this.toHex8String();
  13225. }
  13226. if (format === "name") {
  13227. formattedString = this.toName();
  13228. }
  13229. if (format === "hsl") {
  13230. formattedString = this.toHslString();
  13231. }
  13232. if (format === "hsv") {
  13233. formattedString = this.toHsvString();
  13234. }
  13235. return formattedString || this.toHexString();
  13236. },
  13237. clone: function() {
  13238. return tinycolor(this.toString());
  13239. },
  13240. _applyModification: function(fn, args) {
  13241. var color = fn.apply(null, [this].concat([].slice.call(args)));
  13242. this._r = color._r;
  13243. this._g = color._g;
  13244. this._b = color._b;
  13245. this.setAlpha(color._a);
  13246. return this;
  13247. },
  13248. lighten: function() {
  13249. return this._applyModification(lighten, arguments);
  13250. },
  13251. brighten: function() {
  13252. return this._applyModification(brighten, arguments);
  13253. },
  13254. darken: function() {
  13255. return this._applyModification(darken, arguments);
  13256. },
  13257. desaturate: function() {
  13258. return this._applyModification(desaturate, arguments);
  13259. },
  13260. saturate: function() {
  13261. return this._applyModification(saturate, arguments);
  13262. },
  13263. greyscale: function() {
  13264. return this._applyModification(greyscale, arguments);
  13265. },
  13266. spin: function() {
  13267. return this._applyModification(spin, arguments);
  13268. },
  13269. _applyCombination: function(fn, args) {
  13270. return fn.apply(null, [this].concat([].slice.call(args)));
  13271. },
  13272. analogous: function() {
  13273. return this._applyCombination(analogous, arguments);
  13274. },
  13275. complement: function() {
  13276. return this._applyCombination(complement, arguments);
  13277. },
  13278. monochromatic: function() {
  13279. return this._applyCombination(monochromatic, arguments);
  13280. },
  13281. splitcomplement: function() {
  13282. return this._applyCombination(splitcomplement, arguments);
  13283. },
  13284. triad: function() {
  13285. return this._applyCombination(triad, arguments);
  13286. },
  13287. tetrad: function() {
  13288. return this._applyCombination(tetrad, arguments);
  13289. }
  13290. };
  13291. // If input is an object, force 1 into "1.0" to handle ratios properly
  13292. // String input requires "1.0" as input, so 1 will be treated as 1
  13293. tinycolor.fromRatio = function(color, opts) {
  13294. if (typeof color == "object") {
  13295. var newColor = {};
  13296. for (var i in color) {
  13297. if (color.hasOwnProperty(i)) {
  13298. if (i === "a") {
  13299. newColor[i] = color[i];
  13300. }
  13301. else {
  13302. newColor[i] = convertToPercentage(color[i]);
  13303. }
  13304. }
  13305. }
  13306. color = newColor;
  13307. }
  13308. return tinycolor(color, opts);
  13309. };
  13310. // Given a string or object, convert that input to RGB
  13311. // Possible string inputs:
  13312. //
  13313. // "red"
  13314. // "#f00" or "f00"
  13315. // "#ff0000" or "ff0000"
  13316. // "#ff000000" or "ff000000"
  13317. // "rgb 255 0 0" or "rgb (255, 0, 0)"
  13318. // "rgb 1.0 0 0" or "rgb (1, 0, 0)"
  13319. // "rgba (255, 0, 0, 1)" or "rgba 255, 0, 0, 1"
  13320. // "rgba (1.0, 0, 0, 1)" or "rgba 1.0, 0, 0, 1"
  13321. // "hsl(0, 100%, 50%)" or "hsl 0 100% 50%"
  13322. // "hsla(0, 100%, 50%, 1)" or "hsla 0 100% 50%, 1"
  13323. // "hsv(0, 100%, 100%)" or "hsv 0 100% 100%"
  13324. //
  13325. function inputToRGB(color) {
  13326. var rgb = { r: 0, g: 0, b: 0 };
  13327. var a = 1;
  13328. var s = null;
  13329. var v = null;
  13330. var l = null;
  13331. var ok = false;
  13332. var format = false;
  13333. if (typeof color == "string") {
  13334. color = stringInputToObject(color);
  13335. }
  13336. if (typeof color == "object") {
  13337. if (isValidCSSUnit(color.r) && isValidCSSUnit(color.g) && isValidCSSUnit(color.b)) {
  13338. rgb = rgbToRgb(color.r, color.g, color.b);
  13339. ok = true;
  13340. format = String(color.r).substr(-1) === "%" ? "prgb" : "rgb";
  13341. }
  13342. else if (isValidCSSUnit(color.h) && isValidCSSUnit(color.s) && isValidCSSUnit(color.v)) {
  13343. s = convertToPercentage(color.s);
  13344. v = convertToPercentage(color.v);
  13345. rgb = hsvToRgb(color.h, s, v);
  13346. ok = true;
  13347. format = "hsv";
  13348. }
  13349. else if (isValidCSSUnit(color.h) && isValidCSSUnit(color.s) && isValidCSSUnit(color.l)) {
  13350. s = convertToPercentage(color.s);
  13351. l = convertToPercentage(color.l);
  13352. rgb = hslToRgb(color.h, s, l);
  13353. ok = true;
  13354. format = "hsl";
  13355. }
  13356. if (color.hasOwnProperty("a")) {
  13357. a = color.a;
  13358. }
  13359. }
  13360. a = boundAlpha(a);
  13361. return {
  13362. ok: ok,
  13363. format: color.format || format,
  13364. r: mathMin(255, mathMax(rgb.r, 0)),
  13365. g: mathMin(255, mathMax(rgb.g, 0)),
  13366. b: mathMin(255, mathMax(rgb.b, 0)),
  13367. a: a
  13368. };
  13369. }
  13370. // Conversion Functions
  13371. // --------------------
  13372. // `rgbToHsl`, `rgbToHsv`, `hslToRgb`, `hsvToRgb` modified from:
  13373. // <http://mjijackson.com/2008/02/rgb-to-hsl-and-rgb-to-hsv-color-model-conversion-algorithms-in-javascript>
  13374. // `rgbToRgb`
  13375. // Handle bounds / percentage checking to conform to CSS color spec
  13376. // <http://www.w3.org/TR/css3-color/>
  13377. // *Assumes:* r, g, b in [0, 255] or [0, 1]
  13378. // *Returns:* { r, g, b } in [0, 255]
  13379. function rgbToRgb(r, g, b){
  13380. return {
  13381. r: bound01(r, 255) * 255,
  13382. g: bound01(g, 255) * 255,
  13383. b: bound01(b, 255) * 255
  13384. };
  13385. }
  13386. // `rgbToHsl`
  13387. // Converts an RGB color value to HSL.
  13388. // *Assumes:* r, g, and b are contained in [0, 255] or [0, 1]
  13389. // *Returns:* { h, s, l } in [0,1]
  13390. function rgbToHsl(r, g, b) {
  13391. r = bound01(r, 255);
  13392. g = bound01(g, 255);
  13393. b = bound01(b, 255);
  13394. var max = mathMax(r, g, b), min = mathMin(r, g, b);
  13395. var h, s, l = (max + min) / 2;
  13396. if(max == min) {
  13397. h = s = 0; // achromatic
  13398. }
  13399. else {
  13400. var d = max - min;
  13401. s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
  13402. switch(max) {
  13403. case r: h = (g - b) / d + (g < b ? 6 : 0); break;
  13404. case g: h = (b - r) / d + 2; break;
  13405. case b: h = (r - g) / d + 4; break;
  13406. }
  13407. h /= 6;
  13408. }
  13409. return { h: h, s: s, l: l };
  13410. }
  13411. // `hslToRgb`
  13412. // Converts an HSL color value to RGB.
  13413. // *Assumes:* h is contained in [0, 1] or [0, 360] and s and l are contained [0, 1] or [0, 100]
  13414. // *Returns:* { r, g, b } in the set [0, 255]
  13415. function hslToRgb(h, s, l) {
  13416. var r, g, b;
  13417. h = bound01(h, 360);
  13418. s = bound01(s, 100);
  13419. l = bound01(l, 100);
  13420. function hue2rgb(p, q, t) {
  13421. if(t < 0) t += 1;
  13422. if(t > 1) t -= 1;
  13423. if(t < 1/6) return p + (q - p) * 6 * t;
  13424. if(t < 1/2) return q;
  13425. if(t < 2/3) return p + (q - p) * (2/3 - t) * 6;
  13426. return p;
  13427. }
  13428. if(s === 0) {
  13429. r = g = b = l; // achromatic
  13430. }
  13431. else {
  13432. var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
  13433. var p = 2 * l - q;
  13434. r = hue2rgb(p, q, h + 1/3);
  13435. g = hue2rgb(p, q, h);
  13436. b = hue2rgb(p, q, h - 1/3);
  13437. }
  13438. return { r: r * 255, g: g * 255, b: b * 255 };
  13439. }
  13440. // `rgbToHsv`
  13441. // Converts an RGB color value to HSV
  13442. // *Assumes:* r, g, and b are contained in the set [0, 255] or [0, 1]
  13443. // *Returns:* { h, s, v } in [0,1]
  13444. function rgbToHsv(r, g, b) {
  13445. r = bound01(r, 255);
  13446. g = bound01(g, 255);
  13447. b = bound01(b, 255);
  13448. var max = mathMax(r, g, b), min = mathMin(r, g, b);
  13449. var h, s, v = max;
  13450. var d = max - min;
  13451. s = max === 0 ? 0 : d / max;
  13452. if(max == min) {
  13453. h = 0; // achromatic
  13454. }
  13455. else {
  13456. switch(max) {
  13457. case r: h = (g - b) / d + (g < b ? 6 : 0); break;
  13458. case g: h = (b - r) / d + 2; break;
  13459. case b: h = (r - g) / d + 4; break;
  13460. }
  13461. h /= 6;
  13462. }
  13463. return { h: h, s: s, v: v };
  13464. }
  13465. // `hsvToRgb`
  13466. // Converts an HSV color value to RGB.
  13467. // *Assumes:* h is contained in [0, 1] or [0, 360] and s and v are contained in [0, 1] or [0, 100]
  13468. // *Returns:* { r, g, b } in the set [0, 255]
  13469. function hsvToRgb(h, s, v) {
  13470. h = bound01(h, 360) * 6;
  13471. s = bound01(s, 100);
  13472. v = bound01(v, 100);
  13473. var i = Math.floor(h),
  13474. f = h - i,
  13475. p = v * (1 - s),
  13476. q = v * (1 - f * s),
  13477. t = v * (1 - (1 - f) * s),
  13478. mod = i % 6,
  13479. r = [v, q, p, p, t, v][mod],
  13480. g = [t, v, v, q, p, p][mod],
  13481. b = [p, p, t, v, v, q][mod];
  13482. return { r: r * 255, g: g * 255, b: b * 255 };
  13483. }
  13484. // `rgbToHex`
  13485. // Converts an RGB color to hex
  13486. // Assumes r, g, and b are contained in the set [0, 255]
  13487. // Returns a 3 or 6 character hex
  13488. function rgbToHex(r, g, b, allow3Char) {
  13489. var hex = [
  13490. pad2(mathRound(r).toString(16)),
  13491. pad2(mathRound(g).toString(16)),
  13492. pad2(mathRound(b).toString(16))
  13493. ];
  13494. // Return a 3 character hex if possible
  13495. if (allow3Char && hex[0].charAt(0) == hex[0].charAt(1) && hex[1].charAt(0) == hex[1].charAt(1) && hex[2].charAt(0) == hex[2].charAt(1)) {
  13496. return hex[0].charAt(0) + hex[1].charAt(0) + hex[2].charAt(0);
  13497. }
  13498. return hex.join("");
  13499. }
  13500. // `rgbaToHex`
  13501. // Converts an RGBA color plus alpha transparency to hex
  13502. // Assumes r, g, b are contained in the set [0, 255] and
  13503. // a in [0, 1]. Returns a 4 or 8 character rgba hex
  13504. function rgbaToHex(r, g, b, a, allow4Char) {
  13505. var hex = [
  13506. pad2(mathRound(r).toString(16)),
  13507. pad2(mathRound(g).toString(16)),
  13508. pad2(mathRound(b).toString(16)),
  13509. pad2(convertDecimalToHex(a))
  13510. ];
  13511. // Return a 4 character hex if possible
  13512. if (allow4Char && hex[0].charAt(0) == hex[0].charAt(1) && hex[1].charAt(0) == hex[1].charAt(1) && hex[2].charAt(0) == hex[2].charAt(1) && hex[3].charAt(0) == hex[3].charAt(1)) {
  13513. return hex[0].charAt(0) + hex[1].charAt(0) + hex[2].charAt(0) + hex[3].charAt(0);
  13514. }
  13515. return hex.join("");
  13516. }
  13517. // `rgbaToArgbHex`
  13518. // Converts an RGBA color to an ARGB Hex8 string
  13519. // Rarely used, but required for "toFilter()"
  13520. function rgbaToArgbHex(r, g, b, a) {
  13521. var hex = [
  13522. pad2(convertDecimalToHex(a)),
  13523. pad2(mathRound(r).toString(16)),
  13524. pad2(mathRound(g).toString(16)),
  13525. pad2(mathRound(b).toString(16))
  13526. ];
  13527. return hex.join("");
  13528. }
  13529. // `equals`
  13530. // Can be called with any tinycolor input
  13531. tinycolor.equals = function (color1, color2) {
  13532. if (!color1 || !color2) { return false; }
  13533. return tinycolor(color1).toRgbString() == tinycolor(color2).toRgbString();
  13534. };
  13535. tinycolor.random = function() {
  13536. return tinycolor.fromRatio({
  13537. r: mathRandom(),
  13538. g: mathRandom(),
  13539. b: mathRandom()
  13540. });
  13541. };
  13542. // Modification Functions
  13543. // ----------------------
  13544. // Thanks to less.js for some of the basics here
  13545. // <https://github.com/cloudhead/less.js/blob/master/lib/less/functions.js>
  13546. function desaturate(color, amount) {
  13547. amount = (amount === 0) ? 0 : (amount || 10);
  13548. var hsl = tinycolor(color).toHsl();
  13549. hsl.s -= amount / 100;
  13550. hsl.s = clamp01(hsl.s);
  13551. return tinycolor(hsl);
  13552. }
  13553. function saturate(color, amount) {
  13554. amount = (amount === 0) ? 0 : (amount || 10);
  13555. var hsl = tinycolor(color).toHsl();
  13556. hsl.s += amount / 100;
  13557. hsl.s = clamp01(hsl.s);
  13558. return tinycolor(hsl);
  13559. }
  13560. function greyscale(color) {
  13561. return tinycolor(color).desaturate(100);
  13562. }
  13563. function lighten (color, amount) {
  13564. amount = (amount === 0) ? 0 : (amount || 10);
  13565. var hsl = tinycolor(color).toHsl();
  13566. hsl.l += amount / 100;
  13567. hsl.l = clamp01(hsl.l);
  13568. return tinycolor(hsl);
  13569. }
  13570. function brighten(color, amount) {
  13571. amount = (amount === 0) ? 0 : (amount || 10);
  13572. var rgb = tinycolor(color).toRgb();
  13573. rgb.r = mathMax(0, mathMin(255, rgb.r - mathRound(255 * - (amount / 100))));
  13574. rgb.g = mathMax(0, mathMin(255, rgb.g - mathRound(255 * - (amount / 100))));
  13575. rgb.b = mathMax(0, mathMin(255, rgb.b - mathRound(255 * - (amount / 100))));
  13576. return tinycolor(rgb);
  13577. }
  13578. function darken (color, amount) {
  13579. amount = (amount === 0) ? 0 : (amount || 10);
  13580. var hsl = tinycolor(color).toHsl();
  13581. hsl.l -= amount / 100;
  13582. hsl.l = clamp01(hsl.l);
  13583. return tinycolor(hsl);
  13584. }
  13585. // Spin takes a positive or negative amount within [-360, 360] indicating the change of hue.
  13586. // Values outside of this range will be wrapped into this range.
  13587. function spin(color, amount) {
  13588. var hsl = tinycolor(color).toHsl();
  13589. var hue = (hsl.h + amount) % 360;
  13590. hsl.h = hue < 0 ? 360 + hue : hue;
  13591. return tinycolor(hsl);
  13592. }
  13593. // Combination Functions
  13594. // ---------------------
  13595. // Thanks to jQuery xColor for some of the ideas behind these
  13596. // <https://github.com/infusion/jQuery-xcolor/blob/master/jquery.xcolor.js>
  13597. function complement(color) {
  13598. var hsl = tinycolor(color).toHsl();
  13599. hsl.h = (hsl.h + 180) % 360;
  13600. return tinycolor(hsl);
  13601. }
  13602. function triad(color) {
  13603. var hsl = tinycolor(color).toHsl();
  13604. var h = hsl.h;
  13605. return [
  13606. tinycolor(color),
  13607. tinycolor({ h: (h + 120) % 360, s: hsl.s, l: hsl.l }),
  13608. tinycolor({ h: (h + 240) % 360, s: hsl.s, l: hsl.l })
  13609. ];
  13610. }
  13611. function tetrad(color) {
  13612. var hsl = tinycolor(color).toHsl();
  13613. var h = hsl.h;
  13614. return [
  13615. tinycolor(color),
  13616. tinycolor({ h: (h + 90) % 360, s: hsl.s, l: hsl.l }),
  13617. tinycolor({ h: (h + 180) % 360, s: hsl.s, l: hsl.l }),
  13618. tinycolor({ h: (h + 270) % 360, s: hsl.s, l: hsl.l })
  13619. ];
  13620. }
  13621. function splitcomplement(color) {
  13622. var hsl = tinycolor(color).toHsl();
  13623. var h = hsl.h;
  13624. return [
  13625. tinycolor(color),
  13626. tinycolor({ h: (h + 72) % 360, s: hsl.s, l: hsl.l}),
  13627. tinycolor({ h: (h + 216) % 360, s: hsl.s, l: hsl.l})
  13628. ];
  13629. }
  13630. function analogous(color, results, slices) {
  13631. results = results || 6;
  13632. slices = slices || 30;
  13633. var hsl = tinycolor(color).toHsl();
  13634. var part = 360 / slices;
  13635. var ret = [tinycolor(color)];
  13636. for (hsl.h = ((hsl.h - (part * results >> 1)) + 720) % 360; --results; ) {
  13637. hsl.h = (hsl.h + part) % 360;
  13638. ret.push(tinycolor(hsl));
  13639. }
  13640. return ret;
  13641. }
  13642. function monochromatic(color, results) {
  13643. results = results || 6;
  13644. var hsv = tinycolor(color).toHsv();
  13645. var h = hsv.h, s = hsv.s, v = hsv.v;
  13646. var ret = [];
  13647. var modification = 1 / results;
  13648. while (results--) {
  13649. ret.push(tinycolor({ h: h, s: s, v: v}));
  13650. v = (v + modification) % 1;
  13651. }
  13652. return ret;
  13653. }
  13654. // Utility Functions
  13655. // ---------------------
  13656. tinycolor.mix = function(color1, color2, amount) {
  13657. amount = (amount === 0) ? 0 : (amount || 50);
  13658. var rgb1 = tinycolor(color1).toRgb();
  13659. var rgb2 = tinycolor(color2).toRgb();
  13660. var p = amount / 100;
  13661. var rgba = {
  13662. r: ((rgb2.r - rgb1.r) * p) + rgb1.r,
  13663. g: ((rgb2.g - rgb1.g) * p) + rgb1.g,
  13664. b: ((rgb2.b - rgb1.b) * p) + rgb1.b,
  13665. a: ((rgb2.a - rgb1.a) * p) + rgb1.a
  13666. };
  13667. return tinycolor(rgba);
  13668. };
  13669. // Readability Functions
  13670. // ---------------------
  13671. // <http://www.w3.org/TR/2008/REC-WCAG20-20081211/#contrast-ratiodef (WCAG Version 2)
  13672. // `contrast`
  13673. // Analyze the 2 colors and returns the color contrast defined by (WCAG Version 2)
  13674. tinycolor.readability = function(color1, color2) {
  13675. var c1 = tinycolor(color1);
  13676. var c2 = tinycolor(color2);
  13677. return (Math.max(c1.getLuminance(),c2.getLuminance())+0.05) / (Math.min(c1.getLuminance(),c2.getLuminance())+0.05);
  13678. };
  13679. // `isReadable`
  13680. // Ensure that foreground and background color combinations meet WCAG2 guidelines.
  13681. // The third argument is an optional Object.
  13682. // the 'level' property states 'AA' or 'AAA' - if missing or invalid, it defaults to 'AA';
  13683. // the 'size' property states 'large' or 'small' - if missing or invalid, it defaults to 'small'.
  13684. // If the entire object is absent, isReadable defaults to {level:"AA",size:"small"}.
  13685. // *Example*
  13686. // tinycolor.isReadable("#000", "#111") => false
  13687. // tinycolor.isReadable("#000", "#111",{level:"AA",size:"large"}) => false
  13688. tinycolor.isReadable = function(color1, color2, wcag2) {
  13689. var readability = tinycolor.readability(color1, color2);
  13690. var wcag2Parms, out;
  13691. out = false;
  13692. wcag2Parms = validateWCAG2Parms(wcag2);
  13693. switch (wcag2Parms.level + wcag2Parms.size) {
  13694. case "AAsmall":
  13695. case "AAAlarge":
  13696. out = readability >= 4.5;
  13697. break;
  13698. case "AAlarge":
  13699. out = readability >= 3;
  13700. break;
  13701. case "AAAsmall":
  13702. out = readability >= 7;
  13703. break;
  13704. }
  13705. return out;
  13706. };
  13707. // `mostReadable`
  13708. // Given a base color and a list of possible foreground or background
  13709. // colors for that base, returns the most readable color.
  13710. // Optionally returns Black or White if the most readable color is unreadable.
  13711. // *Example*
  13712. // tinycolor.mostReadable(tinycolor.mostReadable("#123", ["#124", "#125"],{includeFallbackColors:false}).toHexString(); // "#112255"
  13713. // tinycolor.mostReadable(tinycolor.mostReadable("#123", ["#124", "#125"],{includeFallbackColors:true}).toHexString(); // "#ffffff"
  13714. // tinycolor.mostReadable("#a8015a", ["#faf3f3"],{includeFallbackColors:true,level:"AAA",size:"large"}).toHexString(); // "#faf3f3"
  13715. // tinycolor.mostReadable("#a8015a", ["#faf3f3"],{includeFallbackColors:true,level:"AAA",size:"small"}).toHexString(); // "#ffffff"
  13716. tinycolor.mostReadable = function(baseColor, colorList, args) {
  13717. var bestColor = null;
  13718. var bestScore = 0;
  13719. var readability;
  13720. var includeFallbackColors, level, size ;
  13721. args = args || {};
  13722. includeFallbackColors = args.includeFallbackColors ;
  13723. level = args.level;
  13724. size = args.size;
  13725. for (var i= 0; i < colorList.length ; i++) {
  13726. readability = tinycolor.readability(baseColor, colorList[i]);
  13727. if (readability > bestScore) {
  13728. bestScore = readability;
  13729. bestColor = tinycolor(colorList[i]);
  13730. }
  13731. }
  13732. if (tinycolor.isReadable(baseColor, bestColor, {"level":level,"size":size}) || !includeFallbackColors) {
  13733. return bestColor;
  13734. }
  13735. else {
  13736. args.includeFallbackColors=false;
  13737. return tinycolor.mostReadable(baseColor,["#fff", "#000"],args);
  13738. }
  13739. };
  13740. // Big List of Colors
  13741. // ------------------
  13742. // <http://www.w3.org/TR/css3-color/#svg-color>
  13743. var names = tinycolor.names = {
  13744. aliceblue: "f0f8ff",
  13745. antiquewhite: "faebd7",
  13746. aqua: "0ff",
  13747. aquamarine: "7fffd4",
  13748. azure: "f0ffff",
  13749. beige: "f5f5dc",
  13750. bisque: "ffe4c4",
  13751. black: "000",
  13752. blanchedalmond: "ffebcd",
  13753. blue: "00f",
  13754. blueviolet: "8a2be2",
  13755. brown: "a52a2a",
  13756. burlywood: "deb887",
  13757. burntsienna: "ea7e5d",
  13758. cadetblue: "5f9ea0",
  13759. chartreuse: "7fff00",
  13760. chocolate: "d2691e",
  13761. coral: "ff7f50",
  13762. cornflowerblue: "6495ed",
  13763. cornsilk: "fff8dc",
  13764. crimson: "dc143c",
  13765. cyan: "0ff",
  13766. darkblue: "00008b",
  13767. darkcyan: "008b8b",
  13768. darkgoldenrod: "b8860b",
  13769. darkgray: "a9a9a9",
  13770. darkgreen: "006400",
  13771. darkgrey: "a9a9a9",
  13772. darkkhaki: "bdb76b",
  13773. darkmagenta: "8b008b",
  13774. darkolivegreen: "556b2f",
  13775. darkorange: "ff8c00",
  13776. darkorchid: "9932cc",
  13777. darkred: "8b0000",
  13778. darksalmon: "e9967a",
  13779. darkseagreen: "8fbc8f",
  13780. darkslateblue: "483d8b",
  13781. darkslategray: "2f4f4f",
  13782. darkslategrey: "2f4f4f",
  13783. darkturquoise: "00ced1",
  13784. darkviolet: "9400d3",
  13785. deeppink: "ff1493",
  13786. deepskyblue: "00bfff",
  13787. dimgray: "696969",
  13788. dimgrey: "696969",
  13789. dodgerblue: "1e90ff",
  13790. firebrick: "b22222",
  13791. floralwhite: "fffaf0",
  13792. forestgreen: "228b22",
  13793. fuchsia: "f0f",
  13794. gainsboro: "dcdcdc",
  13795. ghostwhite: "f8f8ff",
  13796. gold: "ffd700",
  13797. goldenrod: "daa520",
  13798. gray: "808080",
  13799. green: "008000",
  13800. greenyellow: "adff2f",
  13801. grey: "808080",
  13802. honeydew: "f0fff0",
  13803. hotpink: "ff69b4",
  13804. indianred: "cd5c5c",
  13805. indigo: "4b0082",
  13806. ivory: "fffff0",
  13807. khaki: "f0e68c",
  13808. lavender: "e6e6fa",
  13809. lavenderblush: "fff0f5",
  13810. lawngreen: "7cfc00",
  13811. lemonchiffon: "fffacd",
  13812. lightblue: "add8e6",
  13813. lightcoral: "f08080",
  13814. lightcyan: "e0ffff",
  13815. lightgoldenrodyellow: "fafad2",
  13816. lightgray: "d3d3d3",
  13817. lightgreen: "90ee90",
  13818. lightgrey: "d3d3d3",
  13819. lightpink: "ffb6c1",
  13820. lightsalmon: "ffa07a",
  13821. lightseagreen: "20b2aa",
  13822. lightskyblue: "87cefa",
  13823. lightslategray: "789",
  13824. lightslategrey: "789",
  13825. lightsteelblue: "b0c4de",
  13826. lightyellow: "ffffe0",
  13827. lime: "0f0",
  13828. limegreen: "32cd32",
  13829. linen: "faf0e6",
  13830. magenta: "f0f",
  13831. maroon: "800000",
  13832. mediumaquamarine: "66cdaa",
  13833. mediumblue: "0000cd",
  13834. mediumorchid: "ba55d3",
  13835. mediumpurple: "9370db",
  13836. mediumseagreen: "3cb371",
  13837. mediumslateblue: "7b68ee",
  13838. mediumspringgreen: "00fa9a",
  13839. mediumturquoise: "48d1cc",
  13840. mediumvioletred: "c71585",
  13841. midnightblue: "191970",
  13842. mintcream: "f5fffa",
  13843. mistyrose: "ffe4e1",
  13844. moccasin: "ffe4b5",
  13845. navajowhite: "ffdead",
  13846. navy: "000080",
  13847. oldlace: "fdf5e6",
  13848. olive: "808000",
  13849. olivedrab: "6b8e23",
  13850. orange: "ffa500",
  13851. orangered: "ff4500",
  13852. orchid: "da70d6",
  13853. palegoldenrod: "eee8aa",
  13854. palegreen: "98fb98",
  13855. paleturquoise: "afeeee",
  13856. palevioletred: "db7093",
  13857. papayawhip: "ffefd5",
  13858. peachpuff: "ffdab9",
  13859. peru: "cd853f",
  13860. pink: "ffc0cb",
  13861. plum: "dda0dd",
  13862. powderblue: "b0e0e6",
  13863. purple: "800080",
  13864. rebeccapurple: "663399",
  13865. red: "f00",
  13866. rosybrown: "bc8f8f",
  13867. royalblue: "4169e1",
  13868. saddlebrown: "8b4513",
  13869. salmon: "fa8072",
  13870. sandybrown: "f4a460",
  13871. seagreen: "2e8b57",
  13872. seashell: "fff5ee",
  13873. sienna: "a0522d",
  13874. silver: "c0c0c0",
  13875. skyblue: "87ceeb",
  13876. slateblue: "6a5acd",
  13877. slategray: "708090",
  13878. slategrey: "708090",
  13879. snow: "fffafa",
  13880. springgreen: "00ff7f",
  13881. steelblue: "4682b4",
  13882. tan: "d2b48c",
  13883. teal: "008080",
  13884. thistle: "d8bfd8",
  13885. tomato: "ff6347",
  13886. turquoise: "40e0d0",
  13887. violet: "ee82ee",
  13888. wheat: "f5deb3",
  13889. white: "fff",
  13890. whitesmoke: "f5f5f5",
  13891. yellow: "ff0",
  13892. yellowgreen: "9acd32"
  13893. };
  13894. // Make it easy to access colors via `hexNames[hex]`
  13895. var hexNames = tinycolor.hexNames = flip(names);
  13896. // Utilities
  13897. // ---------
  13898. // `{ 'name1': 'val1' }` becomes `{ 'val1': 'name1' }`
  13899. function flip(o) {
  13900. var flipped = { };
  13901. for (var i in o) {
  13902. if (o.hasOwnProperty(i)) {
  13903. flipped[o[i]] = i;
  13904. }
  13905. }
  13906. return flipped;
  13907. }
  13908. // Return a valid alpha value [0,1] with all invalid values being set to 1
  13909. function boundAlpha(a) {
  13910. a = parseFloat(a);
  13911. if (isNaN(a) || a < 0 || a > 1) {
  13912. a = 1;
  13913. }
  13914. return a;
  13915. }
  13916. // Take input from [0, n] and return it as [0, 1]
  13917. function bound01(n, max) {
  13918. if (isOnePointZero(n)) { n = "100%"; }
  13919. var processPercent = isPercentage(n);
  13920. n = mathMin(max, mathMax(0, parseFloat(n)));
  13921. // Automatically convert percentage into number
  13922. if (processPercent) {
  13923. n = parseInt(n * max, 10) / 100;
  13924. }
  13925. // Handle floating point rounding errors
  13926. if ((Math.abs(n - max) < 0.000001)) {
  13927. return 1;
  13928. }
  13929. // Convert into [0, 1] range if it isn't already
  13930. return (n % max) / parseFloat(max);
  13931. }
  13932. // Force a number between 0 and 1
  13933. function clamp01(val) {
  13934. return mathMin(1, mathMax(0, val));
  13935. }
  13936. // Parse a base-16 hex value into a base-10 integer
  13937. function parseIntFromHex(val) {
  13938. return parseInt(val, 16);
  13939. }
  13940. // Need to handle 1.0 as 100%, since once it is a number, there is no difference between it and 1
  13941. // <http://stackoverflow.com/questions/7422072/javascript-how-to-detect-number-as-a-decimal-including-1-0>
  13942. function isOnePointZero(n) {
  13943. return typeof n == "string" && n.indexOf('.') != -1 && parseFloat(n) === 1;
  13944. }
  13945. // Check to see if string passed in is a percentage
  13946. function isPercentage(n) {
  13947. return typeof n === "string" && n.indexOf('%') != -1;
  13948. }
  13949. // Force a hex value to have 2 characters
  13950. function pad2(c) {
  13951. return c.length == 1 ? '0' + c : '' + c;
  13952. }
  13953. // Replace a decimal with it's percentage value
  13954. function convertToPercentage(n) {
  13955. if (n <= 1) {
  13956. n = (n * 100) + "%";
  13957. }
  13958. return n;
  13959. }
  13960. // Converts a decimal to a hex value
  13961. function convertDecimalToHex(d) {
  13962. return Math.round(parseFloat(d) * 255).toString(16);
  13963. }
  13964. // Converts a hex value to a decimal
  13965. function convertHexToDecimal(h) {
  13966. return (parseIntFromHex(h) / 255);
  13967. }
  13968. var matchers = (function() {
  13969. // <http://www.w3.org/TR/css3-values/#integers>
  13970. var CSS_INTEGER = "[-\\+]?\\d+%?";
  13971. // <http://www.w3.org/TR/css3-values/#number-value>
  13972. var CSS_NUMBER = "[-\\+]?\\d*\\.\\d+%?";
  13973. // Allow positive/negative integer/number. Don't capture the either/or, just the entire outcome.
  13974. var CSS_UNIT = "(?:" + CSS_NUMBER + ")|(?:" + CSS_INTEGER + ")";
  13975. // Actual matching.
  13976. // Parentheses and commas are optional, but not required.
  13977. // Whitespace can take the place of commas or opening paren
  13978. var PERMISSIVE_MATCH3 = "[\\s|\\(]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")\\s*\\)?";
  13979. var PERMISSIVE_MATCH4 = "[\\s|\\(]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")\\s*\\)?";
  13980. return {
  13981. CSS_UNIT: new RegExp(CSS_UNIT),
  13982. rgb: new RegExp("rgb" + PERMISSIVE_MATCH3),
  13983. rgba: new RegExp("rgba" + PERMISSIVE_MATCH4),
  13984. hsl: new RegExp("hsl" + PERMISSIVE_MATCH3),
  13985. hsla: new RegExp("hsla" + PERMISSIVE_MATCH4),
  13986. hsv: new RegExp("hsv" + PERMISSIVE_MATCH3),
  13987. hsva: new RegExp("hsva" + PERMISSIVE_MATCH4),
  13988. hex3: /^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
  13989. hex6: /^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/,
  13990. hex4: /^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
  13991. hex8: /^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/
  13992. };
  13993. })();
  13994. // `isValidCSSUnit`
  13995. // Take in a single string / number and check to see if it looks like a CSS unit
  13996. // (see `matchers` above for definition).
  13997. function isValidCSSUnit(color) {
  13998. return !!matchers.CSS_UNIT.exec(color);
  13999. }
  14000. // `stringInputToObject`
  14001. // Permissive string parsing. Take in a number of formats, and output an object
  14002. // based on detected format. Returns `{ r, g, b }` or `{ h, s, l }` or `{ h, s, v}`
  14003. function stringInputToObject(color) {
  14004. color = color.replace(trimLeft,'').replace(trimRight, '').toLowerCase();
  14005. var named = false;
  14006. if (names[color]) {
  14007. color = names[color];
  14008. named = true;
  14009. }
  14010. else if (color == 'transparent') {
  14011. return { r: 0, g: 0, b: 0, a: 0, format: "name" };
  14012. }
  14013. // Try to match string input using regular expressions.
  14014. // Keep most of the number bounding out of this function - don't worry about [0,1] or [0,100] or [0,360]
  14015. // Just return an object and let the conversion functions handle that.
  14016. // This way the result will be the same whether the tinycolor is initialized with string or object.
  14017. var match;
  14018. if ((match = matchers.rgb.exec(color))) {
  14019. return { r: match[1], g: match[2], b: match[3] };
  14020. }
  14021. if ((match = matchers.rgba.exec(color))) {
  14022. return { r: match[1], g: match[2], b: match[3], a: match[4] };
  14023. }
  14024. if ((match = matchers.hsl.exec(color))) {
  14025. return { h: match[1], s: match[2], l: match[3] };
  14026. }
  14027. if ((match = matchers.hsla.exec(color))) {
  14028. return { h: match[1], s: match[2], l: match[3], a: match[4] };
  14029. }
  14030. if ((match = matchers.hsv.exec(color))) {
  14031. return { h: match[1], s: match[2], v: match[3] };
  14032. }
  14033. if ((match = matchers.hsva.exec(color))) {
  14034. return { h: match[1], s: match[2], v: match[3], a: match[4] };
  14035. }
  14036. if ((match = matchers.hex8.exec(color))) {
  14037. return {
  14038. r: parseIntFromHex(match[1]),
  14039. g: parseIntFromHex(match[2]),
  14040. b: parseIntFromHex(match[3]),
  14041. a: convertHexToDecimal(match[4]),
  14042. format: named ? "name" : "hex8"
  14043. };
  14044. }
  14045. if ((match = matchers.hex6.exec(color))) {
  14046. return {
  14047. r: parseIntFromHex(match[1]),
  14048. g: parseIntFromHex(match[2]),
  14049. b: parseIntFromHex(match[3]),
  14050. format: named ? "name" : "hex"
  14051. };
  14052. }
  14053. if ((match = matchers.hex4.exec(color))) {
  14054. return {
  14055. r: parseIntFromHex(match[1] + '' + match[1]),
  14056. g: parseIntFromHex(match[2] + '' + match[2]),
  14057. b: parseIntFromHex(match[3] + '' + match[3]),
  14058. a: convertHexToDecimal(match[4] + '' + match[4]),
  14059. format: named ? "name" : "hex8"
  14060. };
  14061. }
  14062. if ((match = matchers.hex3.exec(color))) {
  14063. return {
  14064. r: parseIntFromHex(match[1] + '' + match[1]),
  14065. g: parseIntFromHex(match[2] + '' + match[2]),
  14066. b: parseIntFromHex(match[3] + '' + match[3]),
  14067. format: named ? "name" : "hex"
  14068. };
  14069. }
  14070. return false;
  14071. }
  14072. function validateWCAG2Parms(parms) {
  14073. // return valid WCAG2 parms for isReadable.
  14074. // If input parms are invalid, return {"level":"AA", "size":"small"}
  14075. var level, size;
  14076. parms = parms || {"level":"AA", "size":"small"};
  14077. level = (parms.level || "AA").toUpperCase();
  14078. size = (parms.size || "small").toLowerCase();
  14079. if (level !== "AA" && level !== "AAA") {
  14080. level = "AA";
  14081. }
  14082. if (size !== "small" && size !== "large") {
  14083. size = "small";
  14084. }
  14085. return {"level":level, "size":size};
  14086. }
  14087. // Node: Export function
  14088. if (typeof module !== "undefined" && module.exports) {
  14089. module.exports = tinycolor;
  14090. }
  14091. // AMD/requirejs: Define the module
  14092. else if (typeof define === 'function' && define.amd) {
  14093. define(function () {return tinycolor;});
  14094. }
  14095. // Browser: Expose to window
  14096. else {
  14097. window.tinycolor = tinycolor;
  14098. }
  14099. })(Math);
  14100. },{}],34:[function(_dereq_,module,exports){
  14101. /**
  14102. * Copyright 2012-2018, Plotly, Inc.
  14103. * All rights reserved.
  14104. *
  14105. * This source code is licensed under the MIT license found in the
  14106. * LICENSE file in the root directory of this source tree.
  14107. */
  14108. 'use strict';
  14109. /**
  14110. * All paths are tuned for maximum scalability of the arrowhead,
  14111. * ie throughout arrowwidth=0.3..3 the head is joined smoothly
  14112. * to the line, with the line coming from the left and ending at (0, 0).
  14113. *
  14114. * `backoff` is the distance to move the arrowhead and the end of the line,
  14115. * in order that the arrowhead points to the desired place, either at
  14116. * the tip of the arrow or (in the case of circle or square)
  14117. * the center of the symbol.
  14118. *
  14119. * `noRotate`, if truthy, says that this arrowhead should not rotate with the
  14120. * arrow. That's the case for squares, which should always be straight, and
  14121. * circles, for which it's irrelevant.
  14122. */
  14123. module.exports = [
  14124. // no arrow
  14125. {
  14126. path: '',
  14127. backoff: 0
  14128. },
  14129. // wide with flat back
  14130. {
  14131. path: 'M-2.4,-3V3L0.6,0Z',
  14132. backoff: 0.6
  14133. },
  14134. // narrower with flat back
  14135. {
  14136. path: 'M-3.7,-2.5V2.5L1.3,0Z',
  14137. backoff: 1.3
  14138. },
  14139. // barbed
  14140. {
  14141. path: 'M-4.45,-3L-1.65,-0.2V0.2L-4.45,3L1.55,0Z',
  14142. backoff: 1.55
  14143. },
  14144. // wide line-drawn
  14145. {
  14146. path: 'M-2.2,-2.2L-0.2,-0.2V0.2L-2.2,2.2L-1.4,3L1.6,0L-1.4,-3Z',
  14147. backoff: 1.6
  14148. },
  14149. // narrower line-drawn
  14150. {
  14151. path: 'M-4.4,-2.1L-0.6,-0.2V0.2L-4.4,2.1L-4,3L2,0L-4,-3Z',
  14152. backoff: 2
  14153. },
  14154. // circle
  14155. {
  14156. path: 'M2,0A2,2 0 1,1 0,-2A2,2 0 0,1 2,0Z',
  14157. backoff: 0,
  14158. noRotate: true
  14159. },
  14160. // square
  14161. {
  14162. path: 'M2,2V-2H-2V2Z',
  14163. backoff: 0,
  14164. noRotate: true
  14165. }
  14166. ];
  14167. },{}],35:[function(_dereq_,module,exports){
  14168. /**
  14169. * Copyright 2012-2018, Plotly, Inc.
  14170. * All rights reserved.
  14171. *
  14172. * This source code is licensed under the MIT license found in the
  14173. * LICENSE file in the root directory of this source tree.
  14174. */
  14175. 'use strict';
  14176. var ARROWPATHS = _dereq_('./arrow_paths');
  14177. var fontAttrs = _dereq_('../../plots/font_attributes');
  14178. var cartesianConstants = _dereq_('../../plots/cartesian/constants');
  14179. var templatedArray = _dereq_('../../plot_api/plot_template').templatedArray;
  14180. module.exports = templatedArray('annotation', {
  14181. visible: {
  14182. valType: 'boolean',
  14183. dflt: true,
  14184. editType: 'calc+arraydraw',
  14185. },
  14186. text: {
  14187. valType: 'string',
  14188. editType: 'calc+arraydraw',
  14189. },
  14190. textangle: {
  14191. valType: 'angle',
  14192. dflt: 0,
  14193. editType: 'calc+arraydraw',
  14194. },
  14195. font: fontAttrs({
  14196. editType: 'calc+arraydraw',
  14197. colorEditType: 'arraydraw',
  14198. }),
  14199. width: {
  14200. valType: 'number',
  14201. min: 1,
  14202. dflt: null,
  14203. editType: 'calc+arraydraw',
  14204. },
  14205. height: {
  14206. valType: 'number',
  14207. min: 1,
  14208. dflt: null,
  14209. editType: 'calc+arraydraw',
  14210. },
  14211. opacity: {
  14212. valType: 'number',
  14213. min: 0,
  14214. max: 1,
  14215. dflt: 1,
  14216. editType: 'arraydraw',
  14217. },
  14218. align: {
  14219. valType: 'enumerated',
  14220. values: ['left', 'center', 'right'],
  14221. dflt: 'center',
  14222. editType: 'arraydraw',
  14223. },
  14224. valign: {
  14225. valType: 'enumerated',
  14226. values: ['top', 'middle', 'bottom'],
  14227. dflt: 'middle',
  14228. editType: 'arraydraw',
  14229. },
  14230. bgcolor: {
  14231. valType: 'color',
  14232. dflt: 'rgba(0,0,0,0)',
  14233. editType: 'arraydraw',
  14234. },
  14235. bordercolor: {
  14236. valType: 'color',
  14237. dflt: 'rgba(0,0,0,0)',
  14238. editType: 'arraydraw',
  14239. },
  14240. borderpad: {
  14241. valType: 'number',
  14242. min: 0,
  14243. dflt: 1,
  14244. editType: 'calc+arraydraw',
  14245. },
  14246. borderwidth: {
  14247. valType: 'number',
  14248. min: 0,
  14249. dflt: 1,
  14250. editType: 'calc+arraydraw',
  14251. },
  14252. // arrow
  14253. showarrow: {
  14254. valType: 'boolean',
  14255. dflt: true,
  14256. editType: 'calc+arraydraw',
  14257. },
  14258. arrowcolor: {
  14259. valType: 'color',
  14260. editType: 'arraydraw',
  14261. },
  14262. arrowhead: {
  14263. valType: 'integer',
  14264. min: 0,
  14265. max: ARROWPATHS.length,
  14266. dflt: 1,
  14267. editType: 'arraydraw',
  14268. },
  14269. startarrowhead: {
  14270. valType: 'integer',
  14271. min: 0,
  14272. max: ARROWPATHS.length,
  14273. dflt: 1,
  14274. editType: 'arraydraw',
  14275. },
  14276. arrowside: {
  14277. valType: 'flaglist',
  14278. flags: ['end', 'start'],
  14279. extras: ['none'],
  14280. dflt: 'end',
  14281. editType: 'arraydraw',
  14282. },
  14283. arrowsize: {
  14284. valType: 'number',
  14285. min: 0.3,
  14286. dflt: 1,
  14287. editType: 'calc+arraydraw',
  14288. },
  14289. startarrowsize: {
  14290. valType: 'number',
  14291. min: 0.3,
  14292. dflt: 1,
  14293. editType: 'calc+arraydraw',
  14294. },
  14295. arrowwidth: {
  14296. valType: 'number',
  14297. min: 0.1,
  14298. editType: 'calc+arraydraw',
  14299. },
  14300. standoff: {
  14301. valType: 'number',
  14302. min: 0,
  14303. dflt: 0,
  14304. editType: 'calc+arraydraw',
  14305. },
  14306. startstandoff: {
  14307. valType: 'number',
  14308. min: 0,
  14309. dflt: 0,
  14310. editType: 'calc+arraydraw',
  14311. },
  14312. ax: {
  14313. valType: 'any',
  14314. editType: 'calc+arraydraw',
  14315. },
  14316. ay: {
  14317. valType: 'any',
  14318. editType: 'calc+arraydraw',
  14319. },
  14320. axref: {
  14321. valType: 'enumerated',
  14322. dflt: 'pixel',
  14323. values: [
  14324. 'pixel',
  14325. cartesianConstants.idRegex.x.toString()
  14326. ],
  14327. editType: 'calc',
  14328. },
  14329. ayref: {
  14330. valType: 'enumerated',
  14331. dflt: 'pixel',
  14332. values: [
  14333. 'pixel',
  14334. cartesianConstants.idRegex.y.toString()
  14335. ],
  14336. editType: 'calc',
  14337. },
  14338. // positioning
  14339. xref: {
  14340. valType: 'enumerated',
  14341. values: [
  14342. 'paper',
  14343. cartesianConstants.idRegex.x.toString()
  14344. ],
  14345. editType: 'calc',
  14346. },
  14347. x: {
  14348. valType: 'any',
  14349. editType: 'calc+arraydraw',
  14350. },
  14351. xanchor: {
  14352. valType: 'enumerated',
  14353. values: ['auto', 'left', 'center', 'right'],
  14354. dflt: 'auto',
  14355. editType: 'calc+arraydraw',
  14356. },
  14357. xshift: {
  14358. valType: 'number',
  14359. dflt: 0,
  14360. editType: 'calc+arraydraw',
  14361. },
  14362. yref: {
  14363. valType: 'enumerated',
  14364. values: [
  14365. 'paper',
  14366. cartesianConstants.idRegex.y.toString()
  14367. ],
  14368. editType: 'calc',
  14369. },
  14370. y: {
  14371. valType: 'any',
  14372. editType: 'calc+arraydraw',
  14373. },
  14374. yanchor: {
  14375. valType: 'enumerated',
  14376. values: ['auto', 'top', 'middle', 'bottom'],
  14377. dflt: 'auto',
  14378. editType: 'calc+arraydraw',
  14379. },
  14380. yshift: {
  14381. valType: 'number',
  14382. dflt: 0,
  14383. editType: 'calc+arraydraw',
  14384. },
  14385. clicktoshow: {
  14386. valType: 'enumerated',
  14387. values: [false, 'onoff', 'onout'],
  14388. dflt: false,
  14389. editType: 'arraydraw',
  14390. },
  14391. xclick: {
  14392. valType: 'any',
  14393. editType: 'arraydraw',
  14394. },
  14395. yclick: {
  14396. valType: 'any',
  14397. editType: 'arraydraw',
  14398. },
  14399. hovertext: {
  14400. valType: 'string',
  14401. editType: 'arraydraw',
  14402. },
  14403. hoverlabel: {
  14404. bgcolor: {
  14405. valType: 'color',
  14406. editType: 'arraydraw',
  14407. },
  14408. bordercolor: {
  14409. valType: 'color',
  14410. editType: 'arraydraw',
  14411. },
  14412. font: fontAttrs({
  14413. editType: 'arraydraw',
  14414. }),
  14415. editType: 'arraydraw'
  14416. },
  14417. captureevents: {
  14418. valType: 'boolean',
  14419. editType: 'arraydraw',
  14420. },
  14421. editType: 'calc',
  14422. _deprecated: {
  14423. ref: {
  14424. valType: 'string',
  14425. editType: 'calc',
  14426. }
  14427. }
  14428. });
  14429. },{"../../plot_api/plot_template":204,"../../plots/cartesian/constants":219,"../../plots/font_attributes":240,"./arrow_paths":34}],36:[function(_dereq_,module,exports){
  14430. /**
  14431. * Copyright 2012-2018, Plotly, Inc.
  14432. * All rights reserved.
  14433. *
  14434. * This source code is licensed under the MIT license found in the
  14435. * LICENSE file in the root directory of this source tree.
  14436. */
  14437. 'use strict';
  14438. var Lib = _dereq_('../../lib');
  14439. var Axes = _dereq_('../../plots/cartesian/axes');
  14440. var draw = _dereq_('./draw').draw;
  14441. module.exports = function calcAutorange(gd) {
  14442. var fullLayout = gd._fullLayout;
  14443. var annotationList = Lib.filterVisible(fullLayout.annotations);
  14444. if(annotationList.length && gd._fullData.length) {
  14445. return Lib.syncOrAsync([draw, annAutorange], gd);
  14446. }
  14447. };
  14448. function annAutorange(gd) {
  14449. var fullLayout = gd._fullLayout;
  14450. // find the bounding boxes for each of these annotations'
  14451. // relative to their anchor points
  14452. // use the arrow and the text bg rectangle,
  14453. // as the whole anno may include hidden text in its bbox
  14454. Lib.filterVisible(fullLayout.annotations).forEach(function(ann) {
  14455. var xa = Axes.getFromId(gd, ann.xref);
  14456. var ya = Axes.getFromId(gd, ann.yref);
  14457. ann._extremes = {};
  14458. if(xa) calcAxisExpansion(ann, xa);
  14459. if(ya) calcAxisExpansion(ann, ya);
  14460. });
  14461. }
  14462. function calcAxisExpansion(ann, ax) {
  14463. var axId = ax._id;
  14464. var letter = axId.charAt(0);
  14465. var pos = ann[letter];
  14466. var apos = ann['a' + letter];
  14467. var ref = ann[letter + 'ref'];
  14468. var aref = ann['a' + letter + 'ref'];
  14469. var padplus = ann['_' + letter + 'padplus'];
  14470. var padminus = ann['_' + letter + 'padminus'];
  14471. var shift = {x: 1, y: -1}[letter] * ann[letter + 'shift'];
  14472. var headSize = 3 * ann.arrowsize * ann.arrowwidth || 0;
  14473. var headPlus = headSize + shift;
  14474. var headMinus = headSize - shift;
  14475. var startHeadSize = 3 * ann.startarrowsize * ann.arrowwidth || 0;
  14476. var startHeadPlus = startHeadSize + shift;
  14477. var startHeadMinus = startHeadSize - shift;
  14478. var extremes;
  14479. if(aref === ref) {
  14480. // expand for the arrowhead (padded by arrowhead)
  14481. var extremeArrowHead = Axes.findExtremes(ax, [ax.r2c(pos)], {
  14482. ppadplus: headPlus,
  14483. ppadminus: headMinus
  14484. });
  14485. // again for the textbox (padded by textbox)
  14486. var extremeText = Axes.findExtremes(ax, [ax.r2c(apos)], {
  14487. ppadplus: Math.max(padplus, startHeadPlus),
  14488. ppadminus: Math.max(padminus, startHeadMinus)
  14489. });
  14490. extremes = {
  14491. min: [extremeArrowHead.min[0], extremeText.min[0]],
  14492. max: [extremeArrowHead.max[0], extremeText.max[0]]
  14493. };
  14494. } else {
  14495. startHeadPlus = apos ? startHeadPlus + apos : startHeadPlus;
  14496. startHeadMinus = apos ? startHeadMinus - apos : startHeadMinus;
  14497. extremes = Axes.findExtremes(ax, [ax.r2c(pos)], {
  14498. ppadplus: Math.max(padplus, headPlus, startHeadPlus),
  14499. ppadminus: Math.max(padminus, headMinus, startHeadMinus)
  14500. });
  14501. }
  14502. ann._extremes[axId] = extremes;
  14503. }
  14504. },{"../../lib":169,"../../plots/cartesian/axes":214,"./draw":41}],37:[function(_dereq_,module,exports){
  14505. /**
  14506. * Copyright 2012-2018, Plotly, Inc.
  14507. * All rights reserved.
  14508. *
  14509. * This source code is licensed under the MIT license found in the
  14510. * LICENSE file in the root directory of this source tree.
  14511. */
  14512. 'use strict';
  14513. var Lib = _dereq_('../../lib');
  14514. var Registry = _dereq_('../../registry');
  14515. var arrayEditor = _dereq_('../../plot_api/plot_template').arrayEditor;
  14516. module.exports = {
  14517. hasClickToShow: hasClickToShow,
  14518. onClick: onClick
  14519. };
  14520. /*
  14521. * hasClickToShow: does the given hoverData have ANY annotations which will
  14522. * turn ON if we click here? (used by hover events to set cursor)
  14523. *
  14524. * gd: graphDiv
  14525. * hoverData: a hoverData array, as included with the *plotly_hover* or
  14526. * *plotly_click* events in the `points` attribute
  14527. *
  14528. * returns: boolean
  14529. */
  14530. function hasClickToShow(gd, hoverData) {
  14531. var sets = getToggleSets(gd, hoverData);
  14532. return sets.on.length > 0 || sets.explicitOff.length > 0;
  14533. }
  14534. /*
  14535. * onClick: perform the toggling (via Plotly.update) implied by clicking
  14536. * at this hoverData
  14537. *
  14538. * gd: graphDiv
  14539. * hoverData: a hoverData array, as included with the *plotly_hover* or
  14540. * *plotly_click* events in the `points` attribute
  14541. *
  14542. * returns: Promise that the update is complete
  14543. */
  14544. function onClick(gd, hoverData) {
  14545. var toggleSets = getToggleSets(gd, hoverData);
  14546. var onSet = toggleSets.on;
  14547. var offSet = toggleSets.off.concat(toggleSets.explicitOff);
  14548. var update = {};
  14549. var annotationsOut = gd._fullLayout.annotations;
  14550. var i, editHelpers;
  14551. if(!(onSet.length || offSet.length)) return;
  14552. for(i = 0; i < onSet.length; i++) {
  14553. editHelpers = arrayEditor(gd.layout, 'annotations', annotationsOut[onSet[i]]);
  14554. editHelpers.modifyItem('visible', true);
  14555. Lib.extendFlat(update, editHelpers.getUpdateObj());
  14556. }
  14557. for(i = 0; i < offSet.length; i++) {
  14558. editHelpers = arrayEditor(gd.layout, 'annotations', annotationsOut[offSet[i]]);
  14559. editHelpers.modifyItem('visible', false);
  14560. Lib.extendFlat(update, editHelpers.getUpdateObj());
  14561. }
  14562. return Registry.call('update', gd, {}, update);
  14563. }
  14564. /*
  14565. * getToggleSets: find the annotations which will turn on or off at this
  14566. * hoverData
  14567. *
  14568. * gd: graphDiv
  14569. * hoverData: a hoverData array, as included with the *plotly_hover* or
  14570. * *plotly_click* events in the `points` attribute
  14571. *
  14572. * returns: {
  14573. * on: Array (indices of annotations to turn on),
  14574. * off: Array (indices to turn off because you're not hovering on them),
  14575. * explicitOff: Array (indices to turn off because you *are* hovering on them)
  14576. * }
  14577. */
  14578. function getToggleSets(gd, hoverData) {
  14579. var annotations = gd._fullLayout.annotations,
  14580. onSet = [],
  14581. offSet = [],
  14582. explicitOffSet = [],
  14583. hoverLen = (hoverData || []).length;
  14584. var i, j, anni, showMode, pointj, xa, ya, toggleType;
  14585. for(i = 0; i < annotations.length; i++) {
  14586. anni = annotations[i];
  14587. showMode = anni.clicktoshow;
  14588. if(showMode) {
  14589. for(j = 0; j < hoverLen; j++) {
  14590. pointj = hoverData[j];
  14591. xa = pointj.xaxis;
  14592. ya = pointj.yaxis;
  14593. if(xa._id === anni.xref &&
  14594. ya._id === anni.yref &&
  14595. xa.d2r(pointj.x) === clickData2r(anni._xclick, xa) &&
  14596. ya.d2r(pointj.y) === clickData2r(anni._yclick, ya)
  14597. ) {
  14598. // match! toggle this annotation
  14599. // regardless of its clicktoshow mode
  14600. // but if it's onout mode, off is implicit
  14601. if(anni.visible) {
  14602. if(showMode === 'onout') toggleType = offSet;
  14603. else toggleType = explicitOffSet;
  14604. }
  14605. else {
  14606. toggleType = onSet;
  14607. }
  14608. toggleType.push(i);
  14609. break;
  14610. }
  14611. }
  14612. if(j === hoverLen) {
  14613. // no match - only turn this annotation OFF, and only if
  14614. // showmode is 'onout'
  14615. if(anni.visible && showMode === 'onout') offSet.push(i);
  14616. }
  14617. }
  14618. }
  14619. return {on: onSet, off: offSet, explicitOff: explicitOffSet};
  14620. }
  14621. // to handle log axes until v2
  14622. function clickData2r(d, ax) {
  14623. return ax.type === 'log' ? ax.l2r(d) : ax.d2r(d);
  14624. }
  14625. },{"../../lib":169,"../../plot_api/plot_template":204,"../../registry":259}],38:[function(_dereq_,module,exports){
  14626. /**
  14627. * Copyright 2012-2018, Plotly, Inc.
  14628. * All rights reserved.
  14629. *
  14630. * This source code is licensed under the MIT license found in the
  14631. * LICENSE file in the root directory of this source tree.
  14632. */
  14633. 'use strict';
  14634. var Lib = _dereq_('../../lib');
  14635. var Color = _dereq_('../color');
  14636. // defaults common to 'annotations' and 'annotations3d'
  14637. module.exports = function handleAnnotationCommonDefaults(annIn, annOut, fullLayout, coerce) {
  14638. coerce('opacity');
  14639. var bgColor = coerce('bgcolor');
  14640. var borderColor = coerce('bordercolor');
  14641. var borderOpacity = Color.opacity(borderColor);
  14642. coerce('borderpad');
  14643. var borderWidth = coerce('borderwidth');
  14644. var showArrow = coerce('showarrow');
  14645. coerce('text', showArrow ? ' ' : fullLayout._dfltTitle.annotation);
  14646. coerce('textangle');
  14647. Lib.coerceFont(coerce, 'font', fullLayout.font);
  14648. coerce('width');
  14649. coerce('align');
  14650. var h = coerce('height');
  14651. if(h) coerce('valign');
  14652. if(showArrow) {
  14653. var arrowside = coerce('arrowside');
  14654. var arrowhead;
  14655. var arrowsize;
  14656. if(arrowside.indexOf('end') !== -1) {
  14657. arrowhead = coerce('arrowhead');
  14658. arrowsize = coerce('arrowsize');
  14659. }
  14660. if(arrowside.indexOf('start') !== -1) {
  14661. coerce('startarrowhead', arrowhead);
  14662. coerce('startarrowsize', arrowsize);
  14663. }
  14664. coerce('arrowcolor', borderOpacity ? annOut.bordercolor : Color.defaultLine);
  14665. coerce('arrowwidth', ((borderOpacity && borderWidth) || 1) * 2);
  14666. coerce('standoff');
  14667. coerce('startstandoff');
  14668. }
  14669. var hoverText = coerce('hovertext');
  14670. var globalHoverLabel = fullLayout.hoverlabel || {};
  14671. if(hoverText) {
  14672. var hoverBG = coerce('hoverlabel.bgcolor', globalHoverLabel.bgcolor ||
  14673. (Color.opacity(bgColor) ? Color.rgb(bgColor) : Color.defaultLine)
  14674. );
  14675. var hoverBorder = coerce('hoverlabel.bordercolor', globalHoverLabel.bordercolor ||
  14676. Color.contrast(hoverBG)
  14677. );
  14678. Lib.coerceFont(coerce, 'hoverlabel.font', {
  14679. family: globalHoverLabel.font.family,
  14680. size: globalHoverLabel.font.size,
  14681. color: globalHoverLabel.font.color || hoverBorder
  14682. });
  14683. }
  14684. coerce('captureevents', !!hoverText);
  14685. };
  14686. },{"../../lib":169,"../color":50}],39:[function(_dereq_,module,exports){
  14687. /**
  14688. * Copyright 2012-2018, Plotly, Inc.
  14689. * All rights reserved.
  14690. *
  14691. * This source code is licensed under the MIT license found in the
  14692. * LICENSE file in the root directory of this source tree.
  14693. */
  14694. 'use strict';
  14695. var isNumeric = _dereq_('fast-isnumeric');
  14696. var toLogRange = _dereq_('../../lib/to_log_range');
  14697. /*
  14698. * convertCoords: when converting an axis between log and linear
  14699. * you need to alter any annotations on that axis to keep them
  14700. * pointing at the same data point.
  14701. * In v2.0 this will become obsolete
  14702. *
  14703. * gd: the plot div
  14704. * ax: the axis being changed
  14705. * newType: the type it's getting
  14706. * doExtra: function(attr, val) from inside relayout that sets the attribute.
  14707. * Use this to make the changes as it's aware if any other changes in the
  14708. * same relayout call should override this conversion.
  14709. */
  14710. module.exports = function convertCoords(gd, ax, newType, doExtra) {
  14711. ax = ax || {};
  14712. var toLog = (newType === 'log') && (ax.type === 'linear'),
  14713. fromLog = (newType === 'linear') && (ax.type === 'log');
  14714. if(!(toLog || fromLog)) return;
  14715. var annotations = gd._fullLayout.annotations,
  14716. axLetter = ax._id.charAt(0),
  14717. ann,
  14718. attrPrefix;
  14719. function convert(attr) {
  14720. var currentVal = ann[attr],
  14721. newVal = null;
  14722. if(toLog) newVal = toLogRange(currentVal, ax.range);
  14723. else newVal = Math.pow(10, currentVal);
  14724. // if conversion failed, delete the value so it gets a default value
  14725. if(!isNumeric(newVal)) newVal = null;
  14726. doExtra(attrPrefix + attr, newVal);
  14727. }
  14728. for(var i = 0; i < annotations.length; i++) {
  14729. ann = annotations[i];
  14730. attrPrefix = 'annotations[' + i + '].';
  14731. if(ann[axLetter + 'ref'] === ax._id) convert(axLetter);
  14732. if(ann['a' + axLetter + 'ref'] === ax._id) convert('a' + axLetter);
  14733. }
  14734. };
  14735. },{"../../lib/to_log_range":193,"fast-isnumeric":18}],40:[function(_dereq_,module,exports){
  14736. /**
  14737. * Copyright 2012-2018, Plotly, Inc.
  14738. * All rights reserved.
  14739. *
  14740. * This source code is licensed under the MIT license found in the
  14741. * LICENSE file in the root directory of this source tree.
  14742. */
  14743. 'use strict';
  14744. var Lib = _dereq_('../../lib');
  14745. var Axes = _dereq_('../../plots/cartesian/axes');
  14746. var handleArrayContainerDefaults = _dereq_('../../plots/array_container_defaults');
  14747. var handleAnnotationCommonDefaults = _dereq_('./common_defaults');
  14748. var attributes = _dereq_('./attributes');
  14749. module.exports = function supplyLayoutDefaults(layoutIn, layoutOut) {
  14750. handleArrayContainerDefaults(layoutIn, layoutOut, {
  14751. name: 'annotations',
  14752. handleItemDefaults: handleAnnotationDefaults
  14753. });
  14754. };
  14755. function handleAnnotationDefaults(annIn, annOut, fullLayout) {
  14756. function coerce(attr, dflt) {
  14757. return Lib.coerce(annIn, annOut, attributes, attr, dflt);
  14758. }
  14759. var visible = coerce('visible');
  14760. var clickToShow = coerce('clicktoshow');
  14761. if(!(visible || clickToShow)) return;
  14762. handleAnnotationCommonDefaults(annIn, annOut, fullLayout, coerce);
  14763. var showArrow = annOut.showarrow;
  14764. // positioning
  14765. var axLetters = ['x', 'y'],
  14766. arrowPosDflt = [-10, -30],
  14767. gdMock = {_fullLayout: fullLayout};
  14768. for(var i = 0; i < 2; i++) {
  14769. var axLetter = axLetters[i];
  14770. // xref, yref
  14771. var axRef = Axes.coerceRef(annIn, annOut, gdMock, axLetter, '', 'paper');
  14772. if(axRef !== 'paper') {
  14773. var ax = Axes.getFromId(gdMock, axRef);
  14774. ax._annIndices.push(annOut._index);
  14775. }
  14776. // x, y
  14777. Axes.coercePosition(annOut, gdMock, coerce, axRef, axLetter, 0.5);
  14778. if(showArrow) {
  14779. var arrowPosAttr = 'a' + axLetter,
  14780. // axref, ayref
  14781. aaxRef = Axes.coerceRef(annIn, annOut, gdMock, arrowPosAttr, 'pixel');
  14782. // for now the arrow can only be on the same axis or specified as pixels
  14783. // TODO: sometime it might be interesting to allow it to be on *any* axis
  14784. // but that would require updates to drawing & autorange code and maybe more
  14785. if(aaxRef !== 'pixel' && aaxRef !== axRef) {
  14786. aaxRef = annOut[arrowPosAttr] = 'pixel';
  14787. }
  14788. // ax, ay
  14789. var aDflt = (aaxRef === 'pixel') ? arrowPosDflt[i] : 0.4;
  14790. Axes.coercePosition(annOut, gdMock, coerce, aaxRef, arrowPosAttr, aDflt);
  14791. }
  14792. // xanchor, yanchor
  14793. coerce(axLetter + 'anchor');
  14794. // xshift, yshift
  14795. coerce(axLetter + 'shift');
  14796. }
  14797. // if you have one coordinate you should have both
  14798. Lib.noneOrAll(annIn, annOut, ['x', 'y']);
  14799. // if you have one part of arrow length you should have both
  14800. if(showArrow) {
  14801. Lib.noneOrAll(annIn, annOut, ['ax', 'ay']);
  14802. }
  14803. if(clickToShow) {
  14804. var xClick = coerce('xclick');
  14805. var yClick = coerce('yclick');
  14806. // put the actual click data to bind to into private attributes
  14807. // so we don't have to do this little bit of logic on every hover event
  14808. annOut._xclick = (xClick === undefined) ?
  14809. annOut.x :
  14810. Axes.cleanPosition(xClick, gdMock, annOut.xref);
  14811. annOut._yclick = (yClick === undefined) ?
  14812. annOut.y :
  14813. Axes.cleanPosition(yClick, gdMock, annOut.yref);
  14814. }
  14815. }
  14816. },{"../../lib":169,"../../plots/array_container_defaults":210,"../../plots/cartesian/axes":214,"./attributes":35,"./common_defaults":38}],41:[function(_dereq_,module,exports){
  14817. /**
  14818. * Copyright 2012-2018, Plotly, Inc.
  14819. * All rights reserved.
  14820. *
  14821. * This source code is licensed under the MIT license found in the
  14822. * LICENSE file in the root directory of this source tree.
  14823. */
  14824. 'use strict';
  14825. var d3 = _dereq_('d3');
  14826. var Registry = _dereq_('../../registry');
  14827. var Plots = _dereq_('../../plots/plots');
  14828. var Lib = _dereq_('../../lib');
  14829. var Axes = _dereq_('../../plots/cartesian/axes');
  14830. var Color = _dereq_('../color');
  14831. var Drawing = _dereq_('../drawing');
  14832. var Fx = _dereq_('../fx');
  14833. var svgTextUtils = _dereq_('../../lib/svg_text_utils');
  14834. var setCursor = _dereq_('../../lib/setcursor');
  14835. var dragElement = _dereq_('../dragelement');
  14836. var arrayEditor = _dereq_('../../plot_api/plot_template').arrayEditor;
  14837. var drawArrowHead = _dereq_('./draw_arrow_head');
  14838. // Annotations are stored in gd.layout.annotations, an array of objects
  14839. // index can point to one item in this array,
  14840. // or non-numeric to simply add a new one
  14841. // or -1 to modify all existing
  14842. // opt can be the full options object, or one key (to be set to value)
  14843. // or undefined to simply redraw
  14844. // if opt is blank, val can be 'add' or a full options object to add a new
  14845. // annotation at that point in the array, or 'remove' to delete this one
  14846. module.exports = {
  14847. draw: draw,
  14848. drawOne: drawOne,
  14849. drawRaw: drawRaw
  14850. };
  14851. /*
  14852. * draw: draw all annotations without any new modifications
  14853. */
  14854. function draw(gd) {
  14855. var fullLayout = gd._fullLayout;
  14856. fullLayout._infolayer.selectAll('.annotation').remove();
  14857. for(var i = 0; i < fullLayout.annotations.length; i++) {
  14858. if(fullLayout.annotations[i].visible) {
  14859. drawOne(gd, i);
  14860. }
  14861. }
  14862. return Plots.previousPromises(gd);
  14863. }
  14864. /*
  14865. * drawOne: draw a single cartesian or paper-ref annotation, potentially with modifications
  14866. *
  14867. * index (int): the annotation to draw
  14868. */
  14869. function drawOne(gd, index) {
  14870. var fullLayout = gd._fullLayout;
  14871. var options = fullLayout.annotations[index] || {};
  14872. var xa = Axes.getFromId(gd, options.xref);
  14873. var ya = Axes.getFromId(gd, options.yref);
  14874. drawRaw(gd, options, index, false, xa, ya);
  14875. }
  14876. /**
  14877. * drawRaw: draw a single annotation, potentially with modifications
  14878. *
  14879. * @param {DOM element} gd
  14880. * @param {object} options : this annotation's fullLayout options
  14881. * @param {integer} index : index in 'annotations' container of the annotation to draw
  14882. * @param {string} subplotId : id of the annotation's subplot
  14883. * - use false for 2d (i.e. cartesian or paper-ref) annotations
  14884. * @param {object | undefined} xa : full x-axis object to compute subplot pos-to-px
  14885. * @param {object | undefined} ya : ... y-axis
  14886. */
  14887. function drawRaw(gd, options, index, subplotId, xa, ya) {
  14888. var fullLayout = gd._fullLayout;
  14889. var gs = gd._fullLayout._size;
  14890. var edits = gd._context.edits;
  14891. var className, containerStr;
  14892. if(subplotId) {
  14893. className = 'annotation-' + subplotId;
  14894. containerStr = subplotId + '.annotations';
  14895. } else {
  14896. className = 'annotation';
  14897. containerStr = 'annotations';
  14898. }
  14899. var editHelpers = arrayEditor(gd.layout, containerStr, options);
  14900. var modifyBase = editHelpers.modifyBase;
  14901. var modifyItem = editHelpers.modifyItem;
  14902. var getUpdateObj = editHelpers.getUpdateObj;
  14903. // remove the existing annotation if there is one
  14904. fullLayout._infolayer
  14905. .selectAll('.' + className + '[data-index="' + index + '"]')
  14906. .remove();
  14907. var annClipID = 'clip' + fullLayout._uid + '_ann' + index;
  14908. // this annotation is gone - quit now after deleting it
  14909. // TODO: use d3 idioms instead of deleting and redrawing every time
  14910. if(!options._input || options.visible === false) {
  14911. d3.selectAll('#' + annClipID).remove();
  14912. return;
  14913. }
  14914. // calculated pixel positions
  14915. // x & y each will get text, head, and tail as appropriate
  14916. var annPosPx = {x: {}, y: {}},
  14917. textangle = +options.textangle || 0;
  14918. // create the components
  14919. // made a single group to contain all, so opacity can work right
  14920. // with border/arrow together this could handle a whole bunch of
  14921. // cleanup at this point, but works for now
  14922. var annGroup = fullLayout._infolayer.append('g')
  14923. .classed(className, true)
  14924. .attr('data-index', String(index))
  14925. .style('opacity', options.opacity);
  14926. // another group for text+background so that they can rotate together
  14927. var annTextGroup = annGroup.append('g')
  14928. .classed('annotation-text-g', true);
  14929. var editTextPosition = edits[options.showarrow ? 'annotationTail' : 'annotationPosition'];
  14930. var textEvents = options.captureevents || edits.annotationText || editTextPosition;
  14931. var annTextGroupInner = annTextGroup.append('g')
  14932. .style('pointer-events', textEvents ? 'all' : null)
  14933. .call(setCursor, 'pointer')
  14934. .on('click', function() {
  14935. gd._dragging = false;
  14936. var eventData = {
  14937. index: index,
  14938. annotation: options._input,
  14939. fullAnnotation: options,
  14940. event: d3.event
  14941. };
  14942. if(subplotId) {
  14943. eventData.subplotId = subplotId;
  14944. }
  14945. gd.emit('plotly_clickannotation', eventData);
  14946. });
  14947. if(options.hovertext) {
  14948. annTextGroupInner
  14949. .on('mouseover', function() {
  14950. var hoverOptions = options.hoverlabel;
  14951. var hoverFont = hoverOptions.font;
  14952. var bBox = this.getBoundingClientRect();
  14953. var bBoxRef = gd.getBoundingClientRect();
  14954. Fx.loneHover({
  14955. x0: bBox.left - bBoxRef.left,
  14956. x1: bBox.right - bBoxRef.left,
  14957. y: (bBox.top + bBox.bottom) / 2 - bBoxRef.top,
  14958. text: options.hovertext,
  14959. color: hoverOptions.bgcolor,
  14960. borderColor: hoverOptions.bordercolor,
  14961. fontFamily: hoverFont.family,
  14962. fontSize: hoverFont.size,
  14963. fontColor: hoverFont.color
  14964. }, {
  14965. container: fullLayout._hoverlayer.node(),
  14966. outerContainer: fullLayout._paper.node(),
  14967. gd: gd
  14968. });
  14969. })
  14970. .on('mouseout', function() {
  14971. Fx.loneUnhover(fullLayout._hoverlayer.node());
  14972. });
  14973. }
  14974. var borderwidth = options.borderwidth,
  14975. borderpad = options.borderpad,
  14976. borderfull = borderwidth + borderpad;
  14977. var annTextBG = annTextGroupInner.append('rect')
  14978. .attr('class', 'bg')
  14979. .style('stroke-width', borderwidth + 'px')
  14980. .call(Color.stroke, options.bordercolor)
  14981. .call(Color.fill, options.bgcolor);
  14982. var isSizeConstrained = options.width || options.height;
  14983. var annTextClip = fullLayout._topclips
  14984. .selectAll('#' + annClipID)
  14985. .data(isSizeConstrained ? [0] : []);
  14986. annTextClip.enter().append('clipPath')
  14987. .classed('annclip', true)
  14988. .attr('id', annClipID)
  14989. .append('rect');
  14990. annTextClip.exit().remove();
  14991. var font = options.font;
  14992. var annText = annTextGroupInner.append('text')
  14993. .classed('annotation-text', true)
  14994. .text(options.text);
  14995. function textLayout(s) {
  14996. s.call(Drawing.font, font)
  14997. .attr({
  14998. 'text-anchor': {
  14999. left: 'start',
  15000. right: 'end'
  15001. }[options.align] || 'middle'
  15002. });
  15003. svgTextUtils.convertToTspans(s, gd, drawGraphicalElements);
  15004. return s;
  15005. }
  15006. function drawGraphicalElements() {
  15007. // if the text has *only* a link, make the whole box into a link
  15008. var anchor3 = annText.selectAll('a');
  15009. if(anchor3.size() === 1 && anchor3.text() === annText.text()) {
  15010. var wholeLink = annTextGroupInner.insert('a', ':first-child').attr({
  15011. 'xlink:xlink:href': anchor3.attr('xlink:href'),
  15012. 'xlink:xlink:show': anchor3.attr('xlink:show')
  15013. })
  15014. .style({cursor: 'pointer'});
  15015. wholeLink.node().appendChild(annTextBG.node());
  15016. }
  15017. var mathjaxGroup = annTextGroupInner.select('.annotation-text-math-group');
  15018. var hasMathjax = !mathjaxGroup.empty();
  15019. var anntextBB = Drawing.bBox(
  15020. (hasMathjax ? mathjaxGroup : annText).node());
  15021. var textWidth = anntextBB.width;
  15022. var textHeight = anntextBB.height;
  15023. var annWidth = options.width || textWidth;
  15024. var annHeight = options.height || textHeight;
  15025. var outerWidth = Math.round(annWidth + 2 * borderfull);
  15026. var outerHeight = Math.round(annHeight + 2 * borderfull);
  15027. function shiftFraction(v, anchor) {
  15028. if(anchor === 'auto') {
  15029. if(v < 1 / 3) anchor = 'left';
  15030. else if(v > 2 / 3) anchor = 'right';
  15031. else anchor = 'center';
  15032. }
  15033. return {
  15034. center: 0,
  15035. middle: 0,
  15036. left: 0.5,
  15037. bottom: -0.5,
  15038. right: -0.5,
  15039. top: 0.5
  15040. }[anchor];
  15041. }
  15042. var annotationIsOffscreen = false;
  15043. var letters = ['x', 'y'];
  15044. for(var i = 0; i < letters.length; i++) {
  15045. var axLetter = letters[i],
  15046. axRef = options[axLetter + 'ref'] || axLetter,
  15047. tailRef = options['a' + axLetter + 'ref'],
  15048. ax = {x: xa, y: ya}[axLetter],
  15049. dimAngle = (textangle + (axLetter === 'x' ? 0 : -90)) * Math.PI / 180,
  15050. // note that these two can be either positive or negative
  15051. annSizeFromWidth = outerWidth * Math.cos(dimAngle),
  15052. annSizeFromHeight = outerHeight * Math.sin(dimAngle),
  15053. // but this one is the positive total size
  15054. annSize = Math.abs(annSizeFromWidth) + Math.abs(annSizeFromHeight),
  15055. anchor = options[axLetter + 'anchor'],
  15056. overallShift = options[axLetter + 'shift'] * (axLetter === 'x' ? 1 : -1),
  15057. posPx = annPosPx[axLetter],
  15058. basePx,
  15059. textPadShift,
  15060. alignPosition,
  15061. autoAlignFraction,
  15062. textShift;
  15063. /*
  15064. * calculate the *primary* pixel position
  15065. * which is the arrowhead if there is one,
  15066. * otherwise the text anchor point
  15067. */
  15068. if(ax) {
  15069. // check if annotation is off screen, to bypass DOM manipulations
  15070. var posFraction = ax.r2fraction(options[axLetter]);
  15071. if(posFraction < 0 || posFraction > 1) {
  15072. if(tailRef === axRef) {
  15073. posFraction = ax.r2fraction(options['a' + axLetter]);
  15074. if(posFraction < 0 || posFraction > 1) {
  15075. annotationIsOffscreen = true;
  15076. }
  15077. } else {
  15078. annotationIsOffscreen = true;
  15079. }
  15080. }
  15081. basePx = ax._offset + ax.r2p(options[axLetter]);
  15082. autoAlignFraction = 0.5;
  15083. }
  15084. else {
  15085. if(axLetter === 'x') {
  15086. alignPosition = options[axLetter];
  15087. basePx = gs.l + gs.w * alignPosition;
  15088. }
  15089. else {
  15090. alignPosition = 1 - options[axLetter];
  15091. basePx = gs.t + gs.h * alignPosition;
  15092. }
  15093. autoAlignFraction = options.showarrow ? 0.5 : alignPosition;
  15094. }
  15095. // now translate this into pixel positions of head, tail, and text
  15096. // as well as paddings for autorange
  15097. if(options.showarrow) {
  15098. posPx.head = basePx;
  15099. var arrowLength = options['a' + axLetter];
  15100. // with an arrow, the text rotates around the anchor point
  15101. textShift = annSizeFromWidth * shiftFraction(0.5, options.xanchor) -
  15102. annSizeFromHeight * shiftFraction(0.5, options.yanchor);
  15103. if(tailRef === axRef) {
  15104. posPx.tail = ax._offset + ax.r2p(arrowLength);
  15105. // tail is data-referenced: autorange pads the text in px from the tail
  15106. textPadShift = textShift;
  15107. }
  15108. else {
  15109. posPx.tail = basePx + arrowLength;
  15110. // tail is specified in px from head, so autorange also pads vs head
  15111. textPadShift = textShift + arrowLength;
  15112. }
  15113. posPx.text = posPx.tail + textShift;
  15114. // constrain pixel/paper referenced so the draggers are at least
  15115. // partially visible
  15116. var maxPx = fullLayout[(axLetter === 'x') ? 'width' : 'height'];
  15117. if(axRef === 'paper') {
  15118. posPx.head = Lib.constrain(posPx.head, 1, maxPx - 1);
  15119. }
  15120. if(tailRef === 'pixel') {
  15121. var shiftPlus = -Math.max(posPx.tail - 3, posPx.text),
  15122. shiftMinus = Math.min(posPx.tail + 3, posPx.text) - maxPx;
  15123. if(shiftPlus > 0) {
  15124. posPx.tail += shiftPlus;
  15125. posPx.text += shiftPlus;
  15126. }
  15127. else if(shiftMinus > 0) {
  15128. posPx.tail -= shiftMinus;
  15129. posPx.text -= shiftMinus;
  15130. }
  15131. }
  15132. posPx.tail += overallShift;
  15133. posPx.head += overallShift;
  15134. }
  15135. else {
  15136. // with no arrow, the text rotates and *then* we put the anchor
  15137. // relative to the new bounding box
  15138. textShift = annSize * shiftFraction(autoAlignFraction, anchor);
  15139. textPadShift = textShift;
  15140. posPx.text = basePx + textShift;
  15141. }
  15142. posPx.text += overallShift;
  15143. textShift += overallShift;
  15144. textPadShift += overallShift;
  15145. // padplus/minus are used by autorange
  15146. options['_' + axLetter + 'padplus'] = (annSize / 2) + textPadShift;
  15147. options['_' + axLetter + 'padminus'] = (annSize / 2) - textPadShift;
  15148. // size/shift are used during dragging
  15149. options['_' + axLetter + 'size'] = annSize;
  15150. options['_' + axLetter + 'shift'] = textShift;
  15151. }
  15152. // We have everything we need for calcAutorange at this point,
  15153. // we can safely exit - unless we're currently dragging the plot
  15154. if(!gd._dragging && annotationIsOffscreen) {
  15155. annTextGroupInner.remove();
  15156. return;
  15157. }
  15158. var xShift = 0;
  15159. var yShift = 0;
  15160. if(options.align !== 'left') {
  15161. xShift = (annWidth - textWidth) * (options.align === 'center' ? 0.5 : 1);
  15162. }
  15163. if(options.valign !== 'top') {
  15164. yShift = (annHeight - textHeight) * (options.valign === 'middle' ? 0.5 : 1);
  15165. }
  15166. if(hasMathjax) {
  15167. mathjaxGroup.select('svg').attr({
  15168. x: borderfull + xShift - 1,
  15169. y: borderfull + yShift
  15170. })
  15171. .call(Drawing.setClipUrl, isSizeConstrained ? annClipID : null);
  15172. }
  15173. else {
  15174. var texty = borderfull + yShift - anntextBB.top;
  15175. var textx = borderfull + xShift - anntextBB.left;
  15176. annText.call(svgTextUtils.positionText, textx, texty)
  15177. .call(Drawing.setClipUrl, isSizeConstrained ? annClipID : null);
  15178. }
  15179. annTextClip.select('rect').call(Drawing.setRect, borderfull, borderfull,
  15180. annWidth, annHeight);
  15181. annTextBG.call(Drawing.setRect, borderwidth / 2, borderwidth / 2,
  15182. outerWidth - borderwidth, outerHeight - borderwidth);
  15183. annTextGroupInner.call(Drawing.setTranslate,
  15184. Math.round(annPosPx.x.text - outerWidth / 2),
  15185. Math.round(annPosPx.y.text - outerHeight / 2));
  15186. /*
  15187. * rotate text and background
  15188. * we already calculated the text center position *as rotated*
  15189. * because we needed that for autoranging anyway, so now whether
  15190. * we have an arrow or not, we rotate about the text center.
  15191. */
  15192. annTextGroup.attr({transform: 'rotate(' + textangle + ',' +
  15193. annPosPx.x.text + ',' + annPosPx.y.text + ')'});
  15194. /*
  15195. * add the arrow
  15196. * uses options[arrowwidth,arrowcolor,arrowhead] for styling
  15197. * dx and dy are normally zero, but when you are dragging the textbox
  15198. * while the head stays put, dx and dy are the pixel offsets
  15199. */
  15200. var drawArrow = function(dx, dy) {
  15201. annGroup
  15202. .selectAll('.annotation-arrow-g')
  15203. .remove();
  15204. var headX = annPosPx.x.head,
  15205. headY = annPosPx.y.head,
  15206. tailX = annPosPx.x.tail + dx,
  15207. tailY = annPosPx.y.tail + dy,
  15208. textX = annPosPx.x.text + dx,
  15209. textY = annPosPx.y.text + dy,
  15210. // find the edge of the text box, where we'll start the arrow:
  15211. // create transform matrix to rotate the text box corners
  15212. transform = Lib.rotationXYMatrix(textangle, textX, textY),
  15213. applyTransform = Lib.apply2DTransform(transform),
  15214. applyTransform2 = Lib.apply2DTransform2(transform),
  15215. // calculate and transform bounding box
  15216. width = +annTextBG.attr('width'),
  15217. height = +annTextBG.attr('height'),
  15218. xLeft = textX - 0.5 * width,
  15219. xRight = xLeft + width,
  15220. yTop = textY - 0.5 * height,
  15221. yBottom = yTop + height,
  15222. edges = [
  15223. [xLeft, yTop, xLeft, yBottom],
  15224. [xLeft, yBottom, xRight, yBottom],
  15225. [xRight, yBottom, xRight, yTop],
  15226. [xRight, yTop, xLeft, yTop]
  15227. ].map(applyTransform2);
  15228. // Remove the line if it ends inside the box. Use ray
  15229. // casting for rotated boxes: see which edges intersect a
  15230. // line from the arrowhead to far away and reduce with xor
  15231. // to get the parity of the number of intersections.
  15232. if(edges.reduce(function(a, x) {
  15233. return a ^
  15234. !!Lib.segmentsIntersect(headX, headY, headX + 1e6, headY + 1e6,
  15235. x[0], x[1], x[2], x[3]);
  15236. }, false)) {
  15237. // no line or arrow - so quit drawArrow now
  15238. return;
  15239. }
  15240. edges.forEach(function(x) {
  15241. var p = Lib.segmentsIntersect(tailX, tailY, headX, headY,
  15242. x[0], x[1], x[2], x[3]);
  15243. if(p) {
  15244. tailX = p.x;
  15245. tailY = p.y;
  15246. }
  15247. });
  15248. var strokewidth = options.arrowwidth,
  15249. arrowColor = options.arrowcolor,
  15250. arrowSide = options.arrowside;
  15251. var arrowGroup = annGroup.append('g')
  15252. .style({opacity: Color.opacity(arrowColor)})
  15253. .classed('annotation-arrow-g', true);
  15254. var arrow = arrowGroup.append('path')
  15255. .attr('d', 'M' + tailX + ',' + tailY + 'L' + headX + ',' + headY)
  15256. .style('stroke-width', strokewidth + 'px')
  15257. .call(Color.stroke, Color.rgb(arrowColor));
  15258. drawArrowHead(arrow, arrowSide, options);
  15259. // the arrow dragger is a small square right at the head, then a line to the tail,
  15260. // all expanded by a stroke width of 6px plus the arrow line width
  15261. if(edits.annotationPosition && arrow.node().parentNode && !subplotId) {
  15262. var arrowDragHeadX = headX;
  15263. var arrowDragHeadY = headY;
  15264. if(options.standoff) {
  15265. var arrowLength = Math.sqrt(Math.pow(headX - tailX, 2) + Math.pow(headY - tailY, 2));
  15266. arrowDragHeadX += options.standoff * (tailX - headX) / arrowLength;
  15267. arrowDragHeadY += options.standoff * (tailY - headY) / arrowLength;
  15268. }
  15269. var arrowDrag = arrowGroup.append('path')
  15270. .classed('annotation-arrow', true)
  15271. .classed('anndrag', true)
  15272. .classed('cursor-move', true)
  15273. .attr({
  15274. d: 'M3,3H-3V-3H3ZM0,0L' + (tailX - arrowDragHeadX) + ',' + (tailY - arrowDragHeadY),
  15275. transform: 'translate(' + arrowDragHeadX + ',' + arrowDragHeadY + ')'
  15276. })
  15277. .style('stroke-width', (strokewidth + 6) + 'px')
  15278. .call(Color.stroke, 'rgba(0,0,0,0)')
  15279. .call(Color.fill, 'rgba(0,0,0,0)');
  15280. var annx0, anny0;
  15281. // dragger for the arrow & head: translates the whole thing
  15282. // (head/tail/text) all together
  15283. dragElement.init({
  15284. element: arrowDrag.node(),
  15285. gd: gd,
  15286. prepFn: function() {
  15287. var pos = Drawing.getTranslate(annTextGroupInner);
  15288. annx0 = pos.x;
  15289. anny0 = pos.y;
  15290. if(xa && xa.autorange) {
  15291. modifyBase(xa._name + '.autorange', true);
  15292. }
  15293. if(ya && ya.autorange) {
  15294. modifyBase(ya._name + '.autorange', true);
  15295. }
  15296. },
  15297. moveFn: function(dx, dy) {
  15298. var annxy0 = applyTransform(annx0, anny0),
  15299. xcenter = annxy0[0] + dx,
  15300. ycenter = annxy0[1] + dy;
  15301. annTextGroupInner.call(Drawing.setTranslate, xcenter, ycenter);
  15302. modifyItem('x', xa ?
  15303. xa.p2r(xa.r2p(options.x) + dx) :
  15304. (options.x + (dx / gs.w)));
  15305. modifyItem('y', ya ?
  15306. ya.p2r(ya.r2p(options.y) + dy) :
  15307. (options.y - (dy / gs.h)));
  15308. if(options.axref === options.xref) {
  15309. modifyItem('ax', xa.p2r(xa.r2p(options.ax) + dx));
  15310. }
  15311. if(options.ayref === options.yref) {
  15312. modifyItem('ay', ya.p2r(ya.r2p(options.ay) + dy));
  15313. }
  15314. arrowGroup.attr('transform', 'translate(' + dx + ',' + dy + ')');
  15315. annTextGroup.attr({
  15316. transform: 'rotate(' + textangle + ',' +
  15317. xcenter + ',' + ycenter + ')'
  15318. });
  15319. },
  15320. doneFn: function() {
  15321. Registry.call('relayout', gd, getUpdateObj());
  15322. var notesBox = document.querySelector('.js-notes-box-panel');
  15323. if(notesBox) notesBox.redraw(notesBox.selectedObj);
  15324. }
  15325. });
  15326. }
  15327. };
  15328. if(options.showarrow) drawArrow(0, 0);
  15329. // user dragging the annotation (text, not arrow)
  15330. if(editTextPosition) {
  15331. var baseTextTransform;
  15332. // dragger for the textbox: if there's an arrow, just drag the
  15333. // textbox and tail, leave the head untouched
  15334. dragElement.init({
  15335. element: annTextGroupInner.node(),
  15336. gd: gd,
  15337. prepFn: function() {
  15338. baseTextTransform = annTextGroup.attr('transform');
  15339. },
  15340. moveFn: function(dx, dy) {
  15341. var csr = 'pointer';
  15342. if(options.showarrow) {
  15343. if(options.axref === options.xref) {
  15344. modifyItem('ax', xa.p2r(xa.r2p(options.ax) + dx));
  15345. } else {
  15346. modifyItem('ax', options.ax + dx);
  15347. }
  15348. if(options.ayref === options.yref) {
  15349. modifyItem('ay', ya.p2r(ya.r2p(options.ay) + dy));
  15350. } else {
  15351. modifyItem('ay', options.ay + dy);
  15352. }
  15353. drawArrow(dx, dy);
  15354. }
  15355. else if(!subplotId) {
  15356. var xUpdate, yUpdate;
  15357. if(xa) {
  15358. xUpdate = xa.p2r(xa.r2p(options.x) + dx);
  15359. } else {
  15360. var widthFraction = options._xsize / gs.w,
  15361. xLeft = options.x + (options._xshift - options.xshift) / gs.w -
  15362. widthFraction / 2;
  15363. xUpdate = dragElement.align(xLeft + dx / gs.w,
  15364. widthFraction, 0, 1, options.xanchor);
  15365. }
  15366. if(ya) {
  15367. yUpdate = ya.p2r(ya.r2p(options.y) + dy);
  15368. } else {
  15369. var heightFraction = options._ysize / gs.h,
  15370. yBottom = options.y - (options._yshift + options.yshift) / gs.h -
  15371. heightFraction / 2;
  15372. yUpdate = dragElement.align(yBottom - dy / gs.h,
  15373. heightFraction, 0, 1, options.yanchor);
  15374. }
  15375. modifyItem('x', xUpdate);
  15376. modifyItem('y', yUpdate);
  15377. if(!xa || !ya) {
  15378. csr = dragElement.getCursor(
  15379. xa ? 0.5 : xUpdate,
  15380. ya ? 0.5 : yUpdate,
  15381. options.xanchor, options.yanchor
  15382. );
  15383. }
  15384. }
  15385. else return;
  15386. annTextGroup.attr({
  15387. transform: 'translate(' + dx + ',' + dy + ')' + baseTextTransform
  15388. });
  15389. setCursor(annTextGroupInner, csr);
  15390. },
  15391. doneFn: function() {
  15392. setCursor(annTextGroupInner);
  15393. Registry.call('relayout', gd, getUpdateObj());
  15394. var notesBox = document.querySelector('.js-notes-box-panel');
  15395. if(notesBox) notesBox.redraw(notesBox.selectedObj);
  15396. }
  15397. });
  15398. }
  15399. }
  15400. if(edits.annotationText) {
  15401. annText.call(svgTextUtils.makeEditable, {delegate: annTextGroupInner, gd: gd})
  15402. .call(textLayout)
  15403. .on('edit', function(_text) {
  15404. options.text = _text;
  15405. this.call(textLayout);
  15406. modifyItem('text', _text);
  15407. if(xa && xa.autorange) {
  15408. modifyBase(xa._name + '.autorange', true);
  15409. }
  15410. if(ya && ya.autorange) {
  15411. modifyBase(ya._name + '.autorange', true);
  15412. }
  15413. Registry.call('relayout', gd, getUpdateObj());
  15414. });
  15415. }
  15416. else annText.call(textLayout);
  15417. }
  15418. },{"../../lib":169,"../../lib/setcursor":189,"../../lib/svg_text_utils":191,"../../plot_api/plot_template":204,"../../plots/cartesian/axes":214,"../../plots/plots":246,"../../registry":259,"../color":50,"../dragelement":72,"../drawing":75,"../fx":92,"./draw_arrow_head":42,"d3":16}],42:[function(_dereq_,module,exports){
  15419. /**
  15420. * Copyright 2012-2018, Plotly, Inc.
  15421. * All rights reserved.
  15422. *
  15423. * This source code is licensed under the MIT license found in the
  15424. * LICENSE file in the root directory of this source tree.
  15425. */
  15426. 'use strict';
  15427. var d3 = _dereq_('d3');
  15428. var Color = _dereq_('../color');
  15429. var ARROWPATHS = _dereq_('./arrow_paths');
  15430. /**
  15431. * Add arrowhead(s) to a path or line element
  15432. *
  15433. * @param {d3.selection} el3: a d3-selected line or path element
  15434. *
  15435. * @param {string} ends: 'none', 'start', 'end', or 'start+end' for which ends get arrowheads
  15436. *
  15437. * @param {object} options: style information. Must have all the following:
  15438. * @param {number} options.arrowhead: end head style - see ./arrow_paths
  15439. * @param {number} options.startarrowhead: start head style - see ./arrow_paths
  15440. * @param {number} options.arrowsize: relative size of the end head vs line width
  15441. * @param {number} options.startarrowsize: relative size of the start head vs line width
  15442. * @param {number} options.standoff: distance in px to move the end arrow point from its target
  15443. * @param {number} options.startstandoff: distance in px to move the start arrow point from its target
  15444. * @param {number} options.arrowwidth: width of the arrow line
  15445. * @param {string} options.arrowcolor: color of the arrow line, for the head to match
  15446. * Note that the opacity of this color is ignored, as it's assumed the container
  15447. * of both the line and head has opacity applied to it so there isn't greater opacity
  15448. * where they overlap.
  15449. */
  15450. module.exports = function drawArrowHead(el3, ends, options) {
  15451. var el = el3.node();
  15452. var headStyle = ARROWPATHS[options.arrowhead || 0];
  15453. var startHeadStyle = ARROWPATHS[options.startarrowhead || 0];
  15454. var scale = (options.arrowwidth || 1) * (options.arrowsize || 1);
  15455. var startScale = (options.arrowwidth || 1) * (options.startarrowsize || 1);
  15456. var doStart = ends.indexOf('start') >= 0;
  15457. var doEnd = ends.indexOf('end') >= 0;
  15458. var backOff = headStyle.backoff * scale + options.standoff;
  15459. var startBackOff = startHeadStyle.backoff * startScale + options.startstandoff;
  15460. var start, end, startRot, endRot;
  15461. if(el.nodeName === 'line') {
  15462. start = {x: +el3.attr('x1'), y: +el3.attr('y1')};
  15463. end = {x: +el3.attr('x2'), y: +el3.attr('y2')};
  15464. var dx = start.x - end.x;
  15465. var dy = start.y - end.y;
  15466. startRot = Math.atan2(dy, dx);
  15467. endRot = startRot + Math.PI;
  15468. if(backOff && startBackOff) {
  15469. if(backOff + startBackOff > Math.sqrt(dx * dx + dy * dy)) {
  15470. hideLine();
  15471. return;
  15472. }
  15473. }
  15474. if(backOff) {
  15475. if(backOff * backOff > dx * dx + dy * dy) {
  15476. hideLine();
  15477. return;
  15478. }
  15479. var backOffX = backOff * Math.cos(startRot),
  15480. backOffY = backOff * Math.sin(startRot);
  15481. end.x += backOffX;
  15482. end.y += backOffY;
  15483. el3.attr({x2: end.x, y2: end.y});
  15484. }
  15485. if(startBackOff) {
  15486. if(startBackOff * startBackOff > dx * dx + dy * dy) {
  15487. hideLine();
  15488. return;
  15489. }
  15490. var startBackOffX = startBackOff * Math.cos(startRot),
  15491. startbackOffY = startBackOff * Math.sin(startRot);
  15492. start.x -= startBackOffX;
  15493. start.y -= startbackOffY;
  15494. el3.attr({x1: start.x, y1: start.y});
  15495. }
  15496. }
  15497. else if(el.nodeName === 'path') {
  15498. var pathlen = el.getTotalLength(),
  15499. // using dash to hide the backOff region of the path.
  15500. // if we ever allow dash for the arrow we'll have to
  15501. // do better than this hack... maybe just manually
  15502. // combine the two
  15503. dashArray = '';
  15504. if(pathlen < backOff + startBackOff) {
  15505. hideLine();
  15506. return;
  15507. }
  15508. var start0 = el.getPointAtLength(0);
  15509. var dstart = el.getPointAtLength(0.1);
  15510. startRot = Math.atan2(start0.y - dstart.y, start0.x - dstart.x);
  15511. start = el.getPointAtLength(Math.min(startBackOff, pathlen));
  15512. dashArray = '0px,' + startBackOff + 'px,';
  15513. var end0 = el.getPointAtLength(pathlen);
  15514. var dend = el.getPointAtLength(pathlen - 0.1);
  15515. endRot = Math.atan2(end0.y - dend.y, end0.x - dend.x);
  15516. end = el.getPointAtLength(Math.max(0, pathlen - backOff));
  15517. var shortening = dashArray ? startBackOff + backOff : backOff;
  15518. dashArray += (pathlen - shortening) + 'px,' + pathlen + 'px';
  15519. el3.style('stroke-dasharray', dashArray);
  15520. }
  15521. function hideLine() { el3.style('stroke-dasharray', '0px,100px'); }
  15522. function drawhead(arrowHeadStyle, p, rot, arrowScale) {
  15523. if(!arrowHeadStyle.path) return;
  15524. if(arrowHeadStyle.noRotate) rot = 0;
  15525. d3.select(el.parentNode).append('path')
  15526. .attr({
  15527. 'class': el3.attr('class'),
  15528. d: arrowHeadStyle.path,
  15529. transform:
  15530. 'translate(' + p.x + ',' + p.y + ')' +
  15531. (rot ? 'rotate(' + (rot * 180 / Math.PI) + ')' : '') +
  15532. 'scale(' + arrowScale + ')'
  15533. })
  15534. .style({
  15535. fill: Color.rgb(options.arrowcolor),
  15536. 'stroke-width': 0
  15537. });
  15538. }
  15539. if(doStart) drawhead(startHeadStyle, start, startRot, startScale);
  15540. if(doEnd) drawhead(headStyle, end, endRot, scale);
  15541. };
  15542. },{"../color":50,"./arrow_paths":34,"d3":16}],43:[function(_dereq_,module,exports){
  15543. /**
  15544. * Copyright 2012-2018, Plotly, Inc.
  15545. * All rights reserved.
  15546. *
  15547. * This source code is licensed under the MIT license found in the
  15548. * LICENSE file in the root directory of this source tree.
  15549. */
  15550. 'use strict';
  15551. var drawModule = _dereq_('./draw');
  15552. var clickModule = _dereq_('./click');
  15553. module.exports = {
  15554. moduleType: 'component',
  15555. name: 'annotations',
  15556. layoutAttributes: _dereq_('./attributes'),
  15557. supplyLayoutDefaults: _dereq_('./defaults'),
  15558. includeBasePlot: _dereq_('../../plots/cartesian/include_components')('annotations'),
  15559. calcAutorange: _dereq_('./calc_autorange'),
  15560. draw: drawModule.draw,
  15561. drawOne: drawModule.drawOne,
  15562. drawRaw: drawModule.drawRaw,
  15563. hasClickToShow: clickModule.hasClickToShow,
  15564. onClick: clickModule.onClick,
  15565. convertCoords: _dereq_('./convert_coords')
  15566. };
  15567. },{"../../plots/cartesian/include_components":224,"./attributes":35,"./calc_autorange":36,"./click":37,"./convert_coords":39,"./defaults":40,"./draw":41}],44:[function(_dereq_,module,exports){
  15568. /**
  15569. * Copyright 2012-2018, Plotly, Inc.
  15570. * All rights reserved.
  15571. *
  15572. * This source code is licensed under the MIT license found in the
  15573. * LICENSE file in the root directory of this source tree.
  15574. */
  15575. 'use strict';
  15576. var annAtts = _dereq_('../annotations/attributes');
  15577. var overrideAll = _dereq_('../../plot_api/edit_types').overrideAll;
  15578. var templatedArray = _dereq_('../../plot_api/plot_template').templatedArray;
  15579. module.exports = overrideAll(templatedArray('annotation', {
  15580. visible: annAtts.visible,
  15581. x: {
  15582. valType: 'any',
  15583. },
  15584. y: {
  15585. valType: 'any',
  15586. },
  15587. z: {
  15588. valType: 'any',
  15589. },
  15590. ax: {
  15591. valType: 'number',
  15592. },
  15593. ay: {
  15594. valType: 'number',
  15595. },
  15596. xanchor: annAtts.xanchor,
  15597. xshift: annAtts.xshift,
  15598. yanchor: annAtts.yanchor,
  15599. yshift: annAtts.yshift,
  15600. text: annAtts.text,
  15601. textangle: annAtts.textangle,
  15602. font: annAtts.font,
  15603. width: annAtts.width,
  15604. height: annAtts.height,
  15605. opacity: annAtts.opacity,
  15606. align: annAtts.align,
  15607. valign: annAtts.valign,
  15608. bgcolor: annAtts.bgcolor,
  15609. bordercolor: annAtts.bordercolor,
  15610. borderpad: annAtts.borderpad,
  15611. borderwidth: annAtts.borderwidth,
  15612. showarrow: annAtts.showarrow,
  15613. arrowcolor: annAtts.arrowcolor,
  15614. arrowhead: annAtts.arrowhead,
  15615. startarrowhead: annAtts.startarrowhead,
  15616. arrowside: annAtts.arrowside,
  15617. arrowsize: annAtts.arrowsize,
  15618. startarrowsize: annAtts.startarrowsize,
  15619. arrowwidth: annAtts.arrowwidth,
  15620. standoff: annAtts.standoff,
  15621. startstandoff: annAtts.startstandoff,
  15622. hovertext: annAtts.hovertext,
  15623. hoverlabel: annAtts.hoverlabel,
  15624. captureevents: annAtts.captureevents,
  15625. // maybes later?
  15626. // clicktoshow: annAtts.clicktoshow,
  15627. // xclick: annAtts.xclick,
  15628. // yclick: annAtts.yclick,
  15629. // not needed!
  15630. // axref: 'pixel'
  15631. // ayref: 'pixel'
  15632. // xref: 'x'
  15633. // yref: 'y
  15634. // zref: 'z'
  15635. }), 'calc', 'from-root');
  15636. },{"../../plot_api/edit_types":197,"../../plot_api/plot_template":204,"../annotations/attributes":35}],45:[function(_dereq_,module,exports){
  15637. /**
  15638. * Copyright 2012-2018, Plotly, Inc.
  15639. * All rights reserved.
  15640. *
  15641. * This source code is licensed under the MIT license found in the
  15642. * LICENSE file in the root directory of this source tree.
  15643. */
  15644. 'use strict';
  15645. var Lib = _dereq_('../../lib');
  15646. var Axes = _dereq_('../../plots/cartesian/axes');
  15647. module.exports = function convert(scene) {
  15648. var fullSceneLayout = scene.fullSceneLayout;
  15649. var anns = fullSceneLayout.annotations;
  15650. for(var i = 0; i < anns.length; i++) {
  15651. mockAnnAxes(anns[i], scene);
  15652. }
  15653. scene.fullLayout._infolayer
  15654. .selectAll('.annotation-' + scene.id)
  15655. .remove();
  15656. };
  15657. function mockAnnAxes(ann, scene) {
  15658. var fullSceneLayout = scene.fullSceneLayout;
  15659. var domain = fullSceneLayout.domain;
  15660. var size = scene.fullLayout._size;
  15661. var base = {
  15662. // this gets fill in on render
  15663. pdata: null,
  15664. // to get setConvert to not execute cleanly
  15665. type: 'linear',
  15666. // don't try to update them on `editable: true`
  15667. autorange: false,
  15668. // set infinite range so that annotation draw routine
  15669. // does not try to remove 'outside-range' annotations,
  15670. // this case is handled in the render loop
  15671. range: [-Infinity, Infinity]
  15672. };
  15673. ann._xa = {};
  15674. Lib.extendFlat(ann._xa, base);
  15675. Axes.setConvert(ann._xa);
  15676. ann._xa._offset = size.l + domain.x[0] * size.w;
  15677. ann._xa.l2p = function() {
  15678. return 0.5 * (1 + ann._pdata[0] / ann._pdata[3]) * size.w * (domain.x[1] - domain.x[0]);
  15679. };
  15680. ann._ya = {};
  15681. Lib.extendFlat(ann._ya, base);
  15682. Axes.setConvert(ann._ya);
  15683. ann._ya._offset = size.t + (1 - domain.y[1]) * size.h;
  15684. ann._ya.l2p = function() {
  15685. return 0.5 * (1 - ann._pdata[1] / ann._pdata[3]) * size.h * (domain.y[1] - domain.y[0]);
  15686. };
  15687. }
  15688. },{"../../lib":169,"../../plots/cartesian/axes":214}],46:[function(_dereq_,module,exports){
  15689. /**
  15690. * Copyright 2012-2018, Plotly, Inc.
  15691. * All rights reserved.
  15692. *
  15693. * This source code is licensed under the MIT license found in the
  15694. * LICENSE file in the root directory of this source tree.
  15695. */
  15696. 'use strict';
  15697. var Lib = _dereq_('../../lib');
  15698. var Axes = _dereq_('../../plots/cartesian/axes');
  15699. var handleArrayContainerDefaults = _dereq_('../../plots/array_container_defaults');
  15700. var handleAnnotationCommonDefaults = _dereq_('../annotations/common_defaults');
  15701. var attributes = _dereq_('./attributes');
  15702. module.exports = function handleDefaults(sceneLayoutIn, sceneLayoutOut, opts) {
  15703. handleArrayContainerDefaults(sceneLayoutIn, sceneLayoutOut, {
  15704. name: 'annotations',
  15705. handleItemDefaults: handleAnnotationDefaults,
  15706. fullLayout: opts.fullLayout
  15707. });
  15708. };
  15709. function handleAnnotationDefaults(annIn, annOut, sceneLayout, opts) {
  15710. function coerce(attr, dflt) {
  15711. return Lib.coerce(annIn, annOut, attributes, attr, dflt);
  15712. }
  15713. function coercePosition(axLetter) {
  15714. var axName = axLetter + 'axis';
  15715. // mock in such way that getFromId grabs correct 3D axis
  15716. var gdMock = { _fullLayout: {} };
  15717. gdMock._fullLayout[axName] = sceneLayout[axName];
  15718. return Axes.coercePosition(annOut, gdMock, coerce, axLetter, axLetter, 0.5);
  15719. }
  15720. var visible = coerce('visible');
  15721. if(!visible) return;
  15722. handleAnnotationCommonDefaults(annIn, annOut, opts.fullLayout, coerce);
  15723. coercePosition('x');
  15724. coercePosition('y');
  15725. coercePosition('z');
  15726. // if you have one coordinate you should all three
  15727. Lib.noneOrAll(annIn, annOut, ['x', 'y', 'z']);
  15728. // hard-set here for completeness
  15729. annOut.xref = 'x';
  15730. annOut.yref = 'y';
  15731. annOut.zref = 'z';
  15732. coerce('xanchor');
  15733. coerce('yanchor');
  15734. coerce('xshift');
  15735. coerce('yshift');
  15736. if(annOut.showarrow) {
  15737. annOut.axref = 'pixel';
  15738. annOut.ayref = 'pixel';
  15739. // TODO maybe default values should be bigger than the 2D case?
  15740. coerce('ax', -10);
  15741. coerce('ay', -30);
  15742. // if you have one part of arrow length you should have both
  15743. Lib.noneOrAll(annIn, annOut, ['ax', 'ay']);
  15744. }
  15745. }
  15746. },{"../../lib":169,"../../plots/array_container_defaults":210,"../../plots/cartesian/axes":214,"../annotations/common_defaults":38,"./attributes":44}],47:[function(_dereq_,module,exports){
  15747. /**
  15748. * Copyright 2012-2018, Plotly, Inc.
  15749. * All rights reserved.
  15750. *
  15751. * This source code is licensed under the MIT license found in the
  15752. * LICENSE file in the root directory of this source tree.
  15753. */
  15754. 'use strict';
  15755. var drawRaw = _dereq_('../annotations/draw').drawRaw;
  15756. var project = _dereq_('../../plots/gl3d/project');
  15757. var axLetters = ['x', 'y', 'z'];
  15758. module.exports = function draw(scene) {
  15759. var fullSceneLayout = scene.fullSceneLayout;
  15760. var dataScale = scene.dataScale;
  15761. var anns = fullSceneLayout.annotations;
  15762. for(var i = 0; i < anns.length; i++) {
  15763. var ann = anns[i];
  15764. var annotationIsOffscreen = false;
  15765. for(var j = 0; j < 3; j++) {
  15766. var axLetter = axLetters[j];
  15767. var pos = ann[axLetter];
  15768. var ax = fullSceneLayout[axLetter + 'axis'];
  15769. var posFraction = ax.r2fraction(pos);
  15770. if(posFraction < 0 || posFraction > 1) {
  15771. annotationIsOffscreen = true;
  15772. break;
  15773. }
  15774. }
  15775. if(annotationIsOffscreen) {
  15776. scene.fullLayout._infolayer
  15777. .select('.annotation-' + scene.id + '[data-index="' + i + '"]')
  15778. .remove();
  15779. } else {
  15780. ann._pdata = project(scene.glplot.cameraParams, [
  15781. fullSceneLayout.xaxis.r2l(ann.x) * dataScale[0],
  15782. fullSceneLayout.yaxis.r2l(ann.y) * dataScale[1],
  15783. fullSceneLayout.zaxis.r2l(ann.z) * dataScale[2]
  15784. ]);
  15785. drawRaw(scene.graphDiv, ann, i, scene.id, ann._xa, ann._ya);
  15786. }
  15787. }
  15788. };
  15789. },{"../../plots/gl3d/project":243,"../annotations/draw":41}],48:[function(_dereq_,module,exports){
  15790. /**
  15791. * Copyright 2012-2018, Plotly, Inc.
  15792. * All rights reserved.
  15793. *
  15794. * This source code is licensed under the MIT license found in the
  15795. * LICENSE file in the root directory of this source tree.
  15796. */
  15797. 'use strict';
  15798. var Registry = _dereq_('../../registry');
  15799. var Lib = _dereq_('../../lib');
  15800. module.exports = {
  15801. moduleType: 'component',
  15802. name: 'annotations3d',
  15803. schema: {
  15804. subplots: {
  15805. scene: {annotations: _dereq_('./attributes')}
  15806. }
  15807. },
  15808. layoutAttributes: _dereq_('./attributes'),
  15809. handleDefaults: _dereq_('./defaults'),
  15810. includeBasePlot: includeGL3D,
  15811. convert: _dereq_('./convert'),
  15812. draw: _dereq_('./draw')
  15813. };
  15814. function includeGL3D(layoutIn, layoutOut) {
  15815. var GL3D = Registry.subplotsRegistry.gl3d;
  15816. if(!GL3D) return;
  15817. var attrRegex = GL3D.attrRegex;
  15818. var keys = Object.keys(layoutIn);
  15819. for(var i = 0; i < keys.length; i++) {
  15820. var k = keys[i];
  15821. if(attrRegex.test(k) && (layoutIn[k].annotations || []).length) {
  15822. Lib.pushUnique(layoutOut._basePlotModules, GL3D);
  15823. Lib.pushUnique(layoutOut._subplots.gl3d, k);
  15824. }
  15825. }
  15826. }
  15827. },{"../../lib":169,"../../registry":259,"./attributes":44,"./convert":45,"./defaults":46,"./draw":47}],49:[function(_dereq_,module,exports){
  15828. /**
  15829. * Copyright 2012-2018, Plotly, Inc.
  15830. * All rights reserved.
  15831. *
  15832. * This source code is licensed under the MIT license found in the
  15833. * LICENSE file in the root directory of this source tree.
  15834. */
  15835. 'use strict';
  15836. // IMPORTANT - default colors should be in hex for compatibility
  15837. exports.defaults = [
  15838. '#1f77b4', // muted blue
  15839. '#ff7f0e', // safety orange
  15840. '#2ca02c', // cooked asparagus green
  15841. '#d62728', // brick red
  15842. '#9467bd', // muted purple
  15843. '#8c564b', // chestnut brown
  15844. '#e377c2', // raspberry yogurt pink
  15845. '#7f7f7f', // middle gray
  15846. '#bcbd22', // curry yellow-green
  15847. '#17becf' // blue-teal
  15848. ];
  15849. exports.defaultLine = '#444';
  15850. exports.lightLine = '#eee';
  15851. exports.background = '#fff';
  15852. exports.borderLine = '#BEC8D9';
  15853. // with axis.color and Color.interp we aren't using lightLine
  15854. // itself anymore, instead interpolating between axis.color
  15855. // and the background color using tinycolor.mix. lightFraction
  15856. // gives back exactly lightLine if the other colors are defaults.
  15857. exports.lightFraction = 100 * (0xe - 0x4) / (0xf - 0x4);
  15858. },{}],50:[function(_dereq_,module,exports){
  15859. /**
  15860. * Copyright 2012-2018, Plotly, Inc.
  15861. * All rights reserved.
  15862. *
  15863. * This source code is licensed under the MIT license found in the
  15864. * LICENSE file in the root directory of this source tree.
  15865. */
  15866. 'use strict';
  15867. var tinycolor = _dereq_('tinycolor2');
  15868. var isNumeric = _dereq_('fast-isnumeric');
  15869. var color = module.exports = {};
  15870. var colorAttrs = _dereq_('./attributes');
  15871. color.defaults = colorAttrs.defaults;
  15872. var defaultLine = color.defaultLine = colorAttrs.defaultLine;
  15873. color.lightLine = colorAttrs.lightLine;
  15874. var background = color.background = colorAttrs.background;
  15875. /*
  15876. * tinyRGB: turn a tinycolor into an rgb string, but
  15877. * unlike the built-in tinycolor.toRgbString this never includes alpha
  15878. */
  15879. color.tinyRGB = function(tc) {
  15880. var c = tc.toRgb();
  15881. return 'rgb(' + Math.round(c.r) + ', ' +
  15882. Math.round(c.g) + ', ' + Math.round(c.b) + ')';
  15883. };
  15884. color.rgb = function(cstr) { return color.tinyRGB(tinycolor(cstr)); };
  15885. color.opacity = function(cstr) { return cstr ? tinycolor(cstr).getAlpha() : 0; };
  15886. color.addOpacity = function(cstr, op) {
  15887. var c = tinycolor(cstr).toRgb();
  15888. return 'rgba(' + Math.round(c.r) + ', ' +
  15889. Math.round(c.g) + ', ' + Math.round(c.b) + ', ' + op + ')';
  15890. };
  15891. // combine two colors into one apparent color
  15892. // if back has transparency or is missing,
  15893. // color.background is assumed behind it
  15894. color.combine = function(front, back) {
  15895. var fc = tinycolor(front).toRgb();
  15896. if(fc.a === 1) return tinycolor(front).toRgbString();
  15897. var bc = tinycolor(back || background).toRgb(),
  15898. bcflat = bc.a === 1 ? bc : {
  15899. r: 255 * (1 - bc.a) + bc.r * bc.a,
  15900. g: 255 * (1 - bc.a) + bc.g * bc.a,
  15901. b: 255 * (1 - bc.a) + bc.b * bc.a
  15902. },
  15903. fcflat = {
  15904. r: bcflat.r * (1 - fc.a) + fc.r * fc.a,
  15905. g: bcflat.g * (1 - fc.a) + fc.g * fc.a,
  15906. b: bcflat.b * (1 - fc.a) + fc.b * fc.a
  15907. };
  15908. return tinycolor(fcflat).toRgbString();
  15909. };
  15910. /*
  15911. * Create a color that contrasts with cstr.
  15912. *
  15913. * If cstr is a dark color, we lighten it; if it's light, we darken.
  15914. *
  15915. * If lightAmount / darkAmount are used, we adjust by these percentages,
  15916. * otherwise we go all the way to white or black.
  15917. */
  15918. color.contrast = function(cstr, lightAmount, darkAmount) {
  15919. var tc = tinycolor(cstr);
  15920. if(tc.getAlpha() !== 1) tc = tinycolor(color.combine(cstr, background));
  15921. var newColor = tc.isDark() ?
  15922. (lightAmount ? tc.lighten(lightAmount) : background) :
  15923. (darkAmount ? tc.darken(darkAmount) : defaultLine);
  15924. return newColor.toString();
  15925. };
  15926. color.stroke = function(s, c) {
  15927. var tc = tinycolor(c);
  15928. s.style({'stroke': color.tinyRGB(tc), 'stroke-opacity': tc.getAlpha()});
  15929. };
  15930. color.fill = function(s, c) {
  15931. var tc = tinycolor(c);
  15932. s.style({
  15933. 'fill': color.tinyRGB(tc),
  15934. 'fill-opacity': tc.getAlpha()
  15935. });
  15936. };
  15937. // search container for colors with the deprecated rgb(fractions) format
  15938. // and convert them to rgb(0-255 values)
  15939. color.clean = function(container) {
  15940. if(!container || typeof container !== 'object') return;
  15941. var keys = Object.keys(container),
  15942. i,
  15943. j,
  15944. key,
  15945. val;
  15946. for(i = 0; i < keys.length; i++) {
  15947. key = keys[i];
  15948. val = container[key];
  15949. // only sanitize keys that end in "color" or "colorscale"
  15950. if(key.substr(key.length - 5) === 'color') {
  15951. if(Array.isArray(val)) {
  15952. for(j = 0; j < val.length; j++) val[j] = cleanOne(val[j]);
  15953. }
  15954. else container[key] = cleanOne(val);
  15955. }
  15956. else if(key.substr(key.length - 10) === 'colorscale' && Array.isArray(val)) {
  15957. // colorscales have the format [[0, color1], [frac, color2], ... [1, colorN]]
  15958. for(j = 0; j < val.length; j++) {
  15959. if(Array.isArray(val[j])) val[j][1] = cleanOne(val[j][1]);
  15960. }
  15961. }
  15962. // recurse into arrays of objects, and plain objects
  15963. else if(Array.isArray(val)) {
  15964. var el0 = val[0];
  15965. if(!Array.isArray(el0) && el0 && typeof el0 === 'object') {
  15966. for(j = 0; j < val.length; j++) color.clean(val[j]);
  15967. }
  15968. }
  15969. else if(val && typeof val === 'object') color.clean(val);
  15970. }
  15971. };
  15972. function cleanOne(val) {
  15973. if(isNumeric(val) || typeof val !== 'string') return val;
  15974. var valTrim = val.trim();
  15975. if(valTrim.substr(0, 3) !== 'rgb') return val;
  15976. var match = valTrim.match(/^rgba?\s*\(([^()]*)\)$/);
  15977. if(!match) return val;
  15978. var parts = match[1].trim().split(/\s*[\s,]\s*/),
  15979. rgba = valTrim.charAt(3) === 'a' && parts.length === 4;
  15980. if(!rgba && parts.length !== 3) return val;
  15981. for(var i = 0; i < parts.length; i++) {
  15982. if(!parts[i].length) return val;
  15983. parts[i] = Number(parts[i]);
  15984. // all parts must be non-negative numbers
  15985. if(!(parts[i] >= 0)) return val;
  15986. // alpha>1 gets clipped to 1
  15987. if(i === 3) {
  15988. if(parts[i] > 1) parts[i] = 1;
  15989. }
  15990. // r, g, b must be < 1 (ie 1 itself is not allowed)
  15991. else if(parts[i] >= 1) return val;
  15992. }
  15993. var rgbStr = Math.round(parts[0] * 255) + ', ' +
  15994. Math.round(parts[1] * 255) + ', ' +
  15995. Math.round(parts[2] * 255);
  15996. if(rgba) return 'rgba(' + rgbStr + ', ' + parts[3] + ')';
  15997. return 'rgb(' + rgbStr + ')';
  15998. }
  15999. },{"./attributes":49,"fast-isnumeric":18,"tinycolor2":33}],51:[function(_dereq_,module,exports){
  16000. /**
  16001. * Copyright 2012-2018, Plotly, Inc.
  16002. * All rights reserved.
  16003. *
  16004. * This source code is licensed under the MIT license found in the
  16005. * LICENSE file in the root directory of this source tree.
  16006. */
  16007. 'use strict';
  16008. var axesAttrs = _dereq_('../../plots/cartesian/layout_attributes');
  16009. var fontAttrs = _dereq_('../../plots/font_attributes');
  16010. var extendFlat = _dereq_('../../lib/extend').extendFlat;
  16011. var overrideAll = _dereq_('../../plot_api/edit_types').overrideAll;
  16012. module.exports = overrideAll({
  16013. // TODO: only right is supported currently
  16014. // orient: {
  16015. // valType: 'enumerated',
  16016. //
  16017. // values: ['left', 'right', 'top', 'bottom'],
  16018. // dflt: 'right',
  16019. //
  16020. // },
  16021. thicknessmode: {
  16022. valType: 'enumerated',
  16023. values: ['fraction', 'pixels'],
  16024. dflt: 'pixels',
  16025. },
  16026. thickness: {
  16027. valType: 'number',
  16028. min: 0,
  16029. dflt: 30,
  16030. },
  16031. lenmode: {
  16032. valType: 'enumerated',
  16033. values: ['fraction', 'pixels'],
  16034. dflt: 'fraction',
  16035. },
  16036. len: {
  16037. valType: 'number',
  16038. min: 0,
  16039. dflt: 1,
  16040. },
  16041. x: {
  16042. valType: 'number',
  16043. dflt: 1.02,
  16044. min: -2,
  16045. max: 3,
  16046. },
  16047. xanchor: {
  16048. valType: 'enumerated',
  16049. values: ['left', 'center', 'right'],
  16050. dflt: 'left',
  16051. },
  16052. xpad: {
  16053. valType: 'number',
  16054. min: 0,
  16055. dflt: 10,
  16056. },
  16057. y: {
  16058. valType: 'number',
  16059. dflt: 0.5,
  16060. min: -2,
  16061. max: 3,
  16062. },
  16063. yanchor: {
  16064. valType: 'enumerated',
  16065. values: ['top', 'middle', 'bottom'],
  16066. dflt: 'middle',
  16067. },
  16068. ypad: {
  16069. valType: 'number',
  16070. min: 0,
  16071. dflt: 10,
  16072. },
  16073. // a possible line around the bar itself
  16074. outlinecolor: axesAttrs.linecolor,
  16075. outlinewidth: axesAttrs.linewidth,
  16076. // Should outlinewidth have {dflt: 0} ?
  16077. // another possible line outside the padding and tick labels
  16078. bordercolor: axesAttrs.linecolor,
  16079. borderwidth: {
  16080. valType: 'number',
  16081. min: 0,
  16082. dflt: 0,
  16083. },
  16084. bgcolor: {
  16085. valType: 'color',
  16086. dflt: 'rgba(0,0,0,0)',
  16087. },
  16088. // tick and title properties named and function exactly as in axes
  16089. tickmode: axesAttrs.tickmode,
  16090. nticks: axesAttrs.nticks,
  16091. tick0: axesAttrs.tick0,
  16092. dtick: axesAttrs.dtick,
  16093. tickvals: axesAttrs.tickvals,
  16094. ticktext: axesAttrs.ticktext,
  16095. ticks: extendFlat({}, axesAttrs.ticks, {dflt: ''}),
  16096. ticklen: axesAttrs.ticklen,
  16097. tickwidth: axesAttrs.tickwidth,
  16098. tickcolor: axesAttrs.tickcolor,
  16099. showticklabels: axesAttrs.showticklabels,
  16100. tickfont: fontAttrs({
  16101. }),
  16102. tickangle: axesAttrs.tickangle,
  16103. tickformat: axesAttrs.tickformat,
  16104. tickformatstops: axesAttrs.tickformatstops,
  16105. tickprefix: axesAttrs.tickprefix,
  16106. showtickprefix: axesAttrs.showtickprefix,
  16107. ticksuffix: axesAttrs.ticksuffix,
  16108. showticksuffix: axesAttrs.showticksuffix,
  16109. separatethousands: axesAttrs.separatethousands,
  16110. exponentformat: axesAttrs.exponentformat,
  16111. showexponent: axesAttrs.showexponent,
  16112. title: {
  16113. valType: 'string',
  16114. },
  16115. titlefont: fontAttrs({
  16116. }),
  16117. titleside: {
  16118. valType: 'enumerated',
  16119. values: ['right', 'top', 'bottom'],
  16120. dflt: 'top',
  16121. }
  16122. }, 'colorbars', 'from-root');
  16123. },{"../../lib/extend":163,"../../plot_api/edit_types":197,"../../plots/cartesian/layout_attributes":226,"../../plots/font_attributes":240}],52:[function(_dereq_,module,exports){
  16124. /**
  16125. * Copyright 2012-2018, Plotly, Inc.
  16126. * All rights reserved.
  16127. *
  16128. * This source code is licensed under the MIT license found in the
  16129. * LICENSE file in the root directory of this source tree.
  16130. */
  16131. 'use strict';
  16132. var drawColorbar = _dereq_('./draw');
  16133. /**
  16134. * connectColorbar: create a colorbar from a trace, using its module to
  16135. * describe the connection.
  16136. *
  16137. * @param {DOM element} gd
  16138. *
  16139. * @param {Array} cd
  16140. * calcdata entry for this trace. cd[0].trace is the trace itself, and the
  16141. * colorbar object will be stashed in cd[0].t.cb
  16142. *
  16143. * @param {object|function} moduleOpts
  16144. * may be a function(gd, cd) to override the standard handling below. If
  16145. * an object, should have these keys:
  16146. * @param {Optional(string)} moduleOpts.container
  16147. * name of the container inside the trace where the colorbar and colorscale
  16148. * attributes live (ie 'marker', 'line') - omit if they're at the trace root.
  16149. * @param {string} moduleOpts.min
  16150. * name of the attribute holding the value of the minimum color
  16151. * @param {string} moduleOpts.max
  16152. * name of the attribute holding the value of the maximum color
  16153. * @param {Optional(string)} moduleOpts.vals
  16154. * name of the attribute holding the (numeric) color data
  16155. * used only if min/max fail. May be omitted if these are always
  16156. * pre-calculated.
  16157. */
  16158. module.exports = function connectColorbar(gd, cd, moduleOpts) {
  16159. if(typeof moduleOpts === 'function') return moduleOpts(gd, cd);
  16160. var trace = cd[0].trace;
  16161. var cbId = 'cb' + trace.uid;
  16162. var containerName = moduleOpts.container;
  16163. var container = containerName ? trace[containerName] : trace;
  16164. gd._fullLayout._infolayer.selectAll('.' + cbId).remove();
  16165. if(!container || !container.showscale) return;
  16166. var cb = cd[0].t.cb = drawColorbar(gd, cbId);
  16167. cb.fillgradient(container.colorscale)
  16168. .zrange([container[moduleOpts.min], container[moduleOpts.max]])
  16169. .options(container.colorbar)();
  16170. };
  16171. },{"./draw":55}],53:[function(_dereq_,module,exports){
  16172. /**
  16173. * Copyright 2012-2018, Plotly, Inc.
  16174. * All rights reserved.
  16175. *
  16176. * This source code is licensed under the MIT license found in the
  16177. * LICENSE file in the root directory of this source tree.
  16178. */
  16179. 'use strict';
  16180. module.exports = {
  16181. cn: {
  16182. colorbar: 'colorbar',
  16183. cbbg: 'cbbg',
  16184. cbfill: 'cbfill',
  16185. cbfills: 'cbfills',
  16186. cbline: 'cbline',
  16187. cblines: 'cblines',
  16188. cbaxis: 'cbaxis',
  16189. cbtitleunshift: 'cbtitleunshift',
  16190. cbtitle: 'cbtitle',
  16191. cboutline: 'cboutline',
  16192. crisp: 'crisp',
  16193. jsPlaceholder: 'js-placeholder'
  16194. }
  16195. };
  16196. },{}],54:[function(_dereq_,module,exports){
  16197. /**
  16198. * Copyright 2012-2018, Plotly, Inc.
  16199. * All rights reserved.
  16200. *
  16201. * This source code is licensed under the MIT license found in the
  16202. * LICENSE file in the root directory of this source tree.
  16203. */
  16204. 'use strict';
  16205. var Lib = _dereq_('../../lib');
  16206. var Template = _dereq_('../../plot_api/plot_template');
  16207. var handleTickValueDefaults = _dereq_('../../plots/cartesian/tick_value_defaults');
  16208. var handleTickMarkDefaults = _dereq_('../../plots/cartesian/tick_mark_defaults');
  16209. var handleTickLabelDefaults = _dereq_('../../plots/cartesian/tick_label_defaults');
  16210. var attributes = _dereq_('./attributes');
  16211. module.exports = function colorbarDefaults(containerIn, containerOut, layout) {
  16212. var colorbarOut = Template.newContainer(containerOut, 'colorbar'),
  16213. colorbarIn = containerIn.colorbar || {};
  16214. function coerce(attr, dflt) {
  16215. return Lib.coerce(colorbarIn, colorbarOut, attributes, attr, dflt);
  16216. }
  16217. var thicknessmode = coerce('thicknessmode');
  16218. coerce('thickness', (thicknessmode === 'fraction') ?
  16219. 30 / (layout.width - layout.margin.l - layout.margin.r) :
  16220. 30
  16221. );
  16222. var lenmode = coerce('lenmode');
  16223. coerce('len', (lenmode === 'fraction') ?
  16224. 1 :
  16225. layout.height - layout.margin.t - layout.margin.b
  16226. );
  16227. coerce('x');
  16228. coerce('xanchor');
  16229. coerce('xpad');
  16230. coerce('y');
  16231. coerce('yanchor');
  16232. coerce('ypad');
  16233. Lib.noneOrAll(colorbarIn, colorbarOut, ['x', 'y']);
  16234. coerce('outlinecolor');
  16235. coerce('outlinewidth');
  16236. coerce('bordercolor');
  16237. coerce('borderwidth');
  16238. coerce('bgcolor');
  16239. handleTickValueDefaults(colorbarIn, colorbarOut, coerce, 'linear');
  16240. var opts = {outerTicks: false, font: layout.font};
  16241. handleTickLabelDefaults(colorbarIn, colorbarOut, coerce, 'linear', opts);
  16242. handleTickMarkDefaults(colorbarIn, colorbarOut, coerce, 'linear', opts);
  16243. coerce('title', layout._dfltTitle.colorbar);
  16244. Lib.coerceFont(coerce, 'titlefont', layout.font);
  16245. coerce('titleside');
  16246. };
  16247. },{"../../lib":169,"../../plot_api/plot_template":204,"../../plots/cartesian/tick_label_defaults":233,"../../plots/cartesian/tick_mark_defaults":234,"../../plots/cartesian/tick_value_defaults":235,"./attributes":51}],55:[function(_dereq_,module,exports){
  16248. /**
  16249. * Copyright 2012-2018, Plotly, Inc.
  16250. * All rights reserved.
  16251. *
  16252. * This source code is licensed under the MIT license found in the
  16253. * LICENSE file in the root directory of this source tree.
  16254. */
  16255. 'use strict';
  16256. var d3 = _dereq_('d3');
  16257. var tinycolor = _dereq_('tinycolor2');
  16258. var Plots = _dereq_('../../plots/plots');
  16259. var Registry = _dereq_('../../registry');
  16260. var Axes = _dereq_('../../plots/cartesian/axes');
  16261. var dragElement = _dereq_('../dragelement');
  16262. var Lib = _dereq_('../../lib');
  16263. var extendFlat = _dereq_('../../lib/extend').extendFlat;
  16264. var setCursor = _dereq_('../../lib/setcursor');
  16265. var Drawing = _dereq_('../drawing');
  16266. var Color = _dereq_('../color');
  16267. var Titles = _dereq_('../titles');
  16268. var svgTextUtils = _dereq_('../../lib/svg_text_utils');
  16269. var alignmentConstants = _dereq_('../../constants/alignment');
  16270. var LINE_SPACING = alignmentConstants.LINE_SPACING;
  16271. var FROM_TL = alignmentConstants.FROM_TL;
  16272. var FROM_BR = alignmentConstants.FROM_BR;
  16273. var handleAxisDefaults = _dereq_('../../plots/cartesian/axis_defaults');
  16274. var handleAxisPositionDefaults = _dereq_('../../plots/cartesian/position_defaults');
  16275. var axisLayoutAttrs = _dereq_('../../plots/cartesian/layout_attributes');
  16276. var attributes = _dereq_('./attributes');
  16277. var cn = _dereq_('./constants').cn;
  16278. module.exports = function draw(gd, id) {
  16279. // opts: options object, containing everything from attributes
  16280. // plus a few others that are the equivalent of the colorbar "data"
  16281. var opts = {};
  16282. for(var k in attributes) {
  16283. opts[k] = null;
  16284. }
  16285. // fillcolor can be a d3 scale, domain is z values, range is colors
  16286. // or leave it out for no fill,
  16287. // or set to a string constant for single-color fill
  16288. opts.fillcolor = null;
  16289. // line.color has the same options as fillcolor
  16290. opts.line = {color: null, width: null, dash: null};
  16291. // levels of lines to draw.
  16292. // note that this DOES NOT determine the extent of the bar
  16293. // that's given by the domain of fillcolor
  16294. // (or line.color if no fillcolor domain)
  16295. opts.levels = {start: null, end: null, size: null};
  16296. // separate fill levels (for example, heatmap coloring of a
  16297. // contour map) if this is omitted, fillcolors will be
  16298. // evaluated halfway between levels
  16299. opts.filllevels = null;
  16300. // for continuous colorscales: fill with a gradient instead of explicit levels
  16301. // value should be the colorscale [[0, c0], [v1, c1], ..., [1, cEnd]]
  16302. opts.fillgradient = null;
  16303. // when using a gradient, we need the data range specified separately
  16304. opts.zrange = null;
  16305. function component() {
  16306. var fullLayout = gd._fullLayout,
  16307. gs = fullLayout._size;
  16308. if((typeof opts.fillcolor !== 'function') &&
  16309. (typeof opts.line.color !== 'function') &&
  16310. !opts.fillgradient) {
  16311. fullLayout._infolayer.selectAll('g.' + id).remove();
  16312. return;
  16313. }
  16314. var zrange = opts.zrange || (d3.extent(((typeof opts.fillcolor === 'function') ?
  16315. opts.fillcolor : opts.line.color).domain()));
  16316. var linelevels = [];
  16317. var filllevels = [];
  16318. var linecolormap = typeof opts.line.color === 'function' ?
  16319. opts.line.color : function() { return opts.line.color; };
  16320. var fillcolormap = typeof opts.fillcolor === 'function' ?
  16321. opts.fillcolor : function() { return opts.fillcolor; };
  16322. var l;
  16323. var i;
  16324. var l0 = opts.levels.end + opts.levels.size / 100,
  16325. ls = opts.levels.size,
  16326. zr0 = (1.001 * zrange[0] - 0.001 * zrange[1]),
  16327. zr1 = (1.001 * zrange[1] - 0.001 * zrange[0]);
  16328. for(i = 0; i < 1e5; i++) {
  16329. l = opts.levels.start + i * ls;
  16330. if(ls > 0 ? (l >= l0) : (l <= l0)) break;
  16331. if(l > zr0 && l < zr1) linelevels.push(l);
  16332. }
  16333. if(opts.fillgradient) {
  16334. filllevels = [0];
  16335. }
  16336. else if(typeof opts.fillcolor === 'function') {
  16337. if(opts.filllevels) {
  16338. l0 = opts.filllevels.end + opts.filllevels.size / 100;
  16339. ls = opts.filllevels.size;
  16340. for(i = 0; i < 1e5; i++) {
  16341. l = opts.filllevels.start + i * ls;
  16342. if(ls > 0 ? (l >= l0) : (l <= l0)) break;
  16343. if(l > zrange[0] && l < zrange[1]) filllevels.push(l);
  16344. }
  16345. }
  16346. else {
  16347. filllevels = linelevels.map(function(v) {
  16348. return v - opts.levels.size / 2;
  16349. });
  16350. filllevels.push(filllevels[filllevels.length - 1] +
  16351. opts.levels.size);
  16352. }
  16353. }
  16354. else if(opts.fillcolor && typeof opts.fillcolor === 'string') {
  16355. // doesn't matter what this value is, with a single value
  16356. // we'll make a single fill rect covering the whole bar
  16357. filllevels = [0];
  16358. }
  16359. if(opts.levels.size < 0) {
  16360. linelevels.reverse();
  16361. filllevels.reverse();
  16362. }
  16363. // now make a Plotly Axes object to scale with and draw ticks
  16364. // TODO: does not support orientation other than right
  16365. // we calculate pixel sizes based on the specified graph size,
  16366. // not the actual (in case something pushed the margins around)
  16367. // which is a little odd but avoids an odd iterative effect
  16368. // when the colorbar itself is pushing the margins.
  16369. // but then the fractional size is calculated based on the
  16370. // actual graph size, so that the axes will size correctly.
  16371. var plotHeight = gs.h,
  16372. plotWidth = gs.w,
  16373. thickPx = Math.round(opts.thickness *
  16374. (opts.thicknessmode === 'fraction' ? plotWidth : 1)),
  16375. thickFrac = thickPx / gs.w,
  16376. lenPx = Math.round(opts.len *
  16377. (opts.lenmode === 'fraction' ? plotHeight : 1)),
  16378. lenFrac = lenPx / gs.h,
  16379. xpadFrac = opts.xpad / gs.w,
  16380. yExtraPx = (opts.borderwidth + opts.outlinewidth) / 2,
  16381. ypadFrac = opts.ypad / gs.h,
  16382. // x positioning: do it initially just for left anchor,
  16383. // then fix at the end (since we don't know the width yet)
  16384. xLeft = Math.round(opts.x * gs.w + opts.xpad),
  16385. // for dragging... this is getting a little muddled...
  16386. xLeftFrac = opts.x - thickFrac *
  16387. ({middle: 0.5, right: 1}[opts.xanchor]||0),
  16388. // y positioning we can do correctly from the start
  16389. yBottomFrac = opts.y + lenFrac *
  16390. (({top: -0.5, bottom: 0.5}[opts.yanchor] || 0) - 0.5),
  16391. yBottomPx = Math.round(gs.h * (1 - yBottomFrac)),
  16392. yTopPx = yBottomPx - lenPx,
  16393. titleEl,
  16394. cbAxisIn = {
  16395. type: 'linear',
  16396. range: zrange,
  16397. tickmode: opts.tickmode,
  16398. nticks: opts.nticks,
  16399. tick0: opts.tick0,
  16400. dtick: opts.dtick,
  16401. tickvals: opts.tickvals,
  16402. ticktext: opts.ticktext,
  16403. ticks: opts.ticks,
  16404. ticklen: opts.ticklen,
  16405. tickwidth: opts.tickwidth,
  16406. tickcolor: opts.tickcolor,
  16407. showticklabels: opts.showticklabels,
  16408. tickfont: opts.tickfont,
  16409. tickangle: opts.tickangle,
  16410. tickformat: opts.tickformat,
  16411. exponentformat: opts.exponentformat,
  16412. separatethousands: opts.separatethousands,
  16413. showexponent: opts.showexponent,
  16414. showtickprefix: opts.showtickprefix,
  16415. tickprefix: opts.tickprefix,
  16416. showticksuffix: opts.showticksuffix,
  16417. ticksuffix: opts.ticksuffix,
  16418. title: opts.title,
  16419. titlefont: opts.titlefont,
  16420. showline: true,
  16421. anchor: 'free',
  16422. position: 1
  16423. },
  16424. cbAxisOut = {
  16425. type: 'linear',
  16426. _id: 'y' + id
  16427. },
  16428. axisOptions = {
  16429. letter: 'y',
  16430. font: fullLayout.font,
  16431. noHover: true,
  16432. calendar: fullLayout.calendar // not really necessary (yet?)
  16433. };
  16434. // Coerce w.r.t. Axes layoutAttributes:
  16435. // re-use axes.js logic without updating _fullData
  16436. function coerce(attr, dflt) {
  16437. return Lib.coerce(cbAxisIn, cbAxisOut, axisLayoutAttrs, attr, dflt);
  16438. }
  16439. // Prepare the Plotly axis object
  16440. handleAxisDefaults(cbAxisIn, cbAxisOut, coerce, axisOptions, fullLayout);
  16441. handleAxisPositionDefaults(cbAxisIn, cbAxisOut, coerce, axisOptions);
  16442. // position can't go in through supplyDefaults
  16443. // because that restricts it to [0,1]
  16444. cbAxisOut.position = opts.x + xpadFrac + thickFrac;
  16445. // save for other callers to access this axis
  16446. component.axis = cbAxisOut;
  16447. if(['top', 'bottom'].indexOf(opts.titleside) !== -1) {
  16448. cbAxisOut.titleside = opts.titleside;
  16449. cbAxisOut.titlex = opts.x + xpadFrac;
  16450. cbAxisOut.titley = yBottomFrac +
  16451. (opts.titleside === 'top' ? lenFrac - ypadFrac : ypadFrac);
  16452. }
  16453. if(opts.line.color && opts.tickmode === 'auto') {
  16454. cbAxisOut.tickmode = 'linear';
  16455. cbAxisOut.tick0 = opts.levels.start;
  16456. var dtick = opts.levels.size;
  16457. // expand if too many contours, so we don't get too many ticks
  16458. var autoNtick = Lib.constrain(
  16459. (yBottomPx - yTopPx) / 50, 4, 15) + 1,
  16460. dtFactor = (zrange[1] - zrange[0]) /
  16461. ((opts.nticks || autoNtick) * dtick);
  16462. if(dtFactor > 1) {
  16463. var dtexp = Math.pow(10, Math.floor(
  16464. Math.log(dtFactor) / Math.LN10));
  16465. dtick *= dtexp * Lib.roundUp(dtFactor / dtexp, [2, 5, 10]);
  16466. // if the contours are at round multiples, reset tick0
  16467. // so they're still at round multiples. Otherwise,
  16468. // keep the first label on the first contour level
  16469. if((Math.abs(opts.levels.start) /
  16470. opts.levels.size + 1e-6) % 1 < 2e-6) {
  16471. cbAxisOut.tick0 = 0;
  16472. }
  16473. }
  16474. cbAxisOut.dtick = dtick;
  16475. }
  16476. // set domain after init, because we may want to
  16477. // allow it outside [0,1]
  16478. cbAxisOut.domain = [
  16479. yBottomFrac + ypadFrac,
  16480. yBottomFrac + lenFrac - ypadFrac
  16481. ];
  16482. cbAxisOut.setScale();
  16483. // now draw the elements
  16484. var container = Lib.ensureSingle(fullLayout._infolayer, 'g', id, function(s) {
  16485. s.classed(cn.colorbar, true)
  16486. .each(function() {
  16487. var s = d3.select(this);
  16488. s.append('rect').classed(cn.cbbg, true);
  16489. s.append('g').classed(cn.cbfills, true);
  16490. s.append('g').classed(cn.cblines, true);
  16491. s.append('g').classed(cn.cbaxis, true).classed(cn.crisp, true);
  16492. s.append('g').classed(cn.cbtitleunshift, true)
  16493. .append('g').classed(cn.cbtitle, true);
  16494. s.append('rect').classed(cn.cboutline, true);
  16495. s.select('.cbtitle').datum(0);
  16496. });
  16497. });
  16498. container.attr('transform', 'translate(' + Math.round(gs.l) +
  16499. ',' + Math.round(gs.t) + ')');
  16500. // TODO: this opposite transform is a hack until we make it
  16501. // more rational which items get this offset
  16502. var titleCont = container.select('.cbtitleunshift')
  16503. .attr('transform', 'translate(-' +
  16504. Math.round(gs.l) + ',-' +
  16505. Math.round(gs.t) + ')');
  16506. cbAxisOut._axislayer = container.select('.cbaxis');
  16507. var titleHeight = 0;
  16508. if(['top', 'bottom'].indexOf(opts.titleside) !== -1) {
  16509. // draw the title so we know how much room it needs
  16510. // when we squish the axis. This one only applies to
  16511. // top or bottom titles, not right side.
  16512. var x = gs.l + (opts.x + xpadFrac) * gs.w,
  16513. fontSize = cbAxisOut.titlefont.size,
  16514. y;
  16515. if(opts.titleside === 'top') {
  16516. y = (1 - (yBottomFrac + lenFrac - ypadFrac)) * gs.h +
  16517. gs.t + 3 + fontSize * 0.75;
  16518. }
  16519. else {
  16520. y = (1 - (yBottomFrac + ypadFrac)) * gs.h +
  16521. gs.t - 3 - fontSize * 0.25;
  16522. }
  16523. drawTitle(cbAxisOut._id + 'title', {
  16524. attributes: {x: x, y: y, 'text-anchor': 'start'}
  16525. });
  16526. }
  16527. function drawAxis() {
  16528. if(['top', 'bottom'].indexOf(opts.titleside) !== -1) {
  16529. // squish the axis top to make room for the title
  16530. var titleGroup = container.select('.cbtitle'),
  16531. titleText = titleGroup.select('text'),
  16532. titleTrans =
  16533. [-opts.outlinewidth / 2, opts.outlinewidth / 2],
  16534. mathJaxNode = titleGroup
  16535. .select('.h' + cbAxisOut._id + 'title-math-group')
  16536. .node(),
  16537. lineSize = 15.6;
  16538. if(titleText.node()) {
  16539. lineSize =
  16540. parseInt(titleText.node().style.fontSize, 10) * LINE_SPACING;
  16541. }
  16542. if(mathJaxNode) {
  16543. titleHeight = Drawing.bBox(mathJaxNode).height;
  16544. if(titleHeight > lineSize) {
  16545. // not entirely sure how mathjax is doing
  16546. // vertical alignment, but this seems to work.
  16547. titleTrans[1] -= (titleHeight - lineSize) / 2;
  16548. }
  16549. }
  16550. else if(titleText.node() &&
  16551. !titleText.classed(cn.jsPlaceholder)) {
  16552. titleHeight = Drawing.bBox(titleText.node()).height;
  16553. }
  16554. if(titleHeight) {
  16555. // buffer btwn colorbar and title
  16556. // TODO: configurable
  16557. titleHeight += 5;
  16558. if(opts.titleside === 'top') {
  16559. cbAxisOut.domain[1] -= titleHeight / gs.h;
  16560. titleTrans[1] *= -1;
  16561. }
  16562. else {
  16563. cbAxisOut.domain[0] += titleHeight / gs.h;
  16564. var nlines = svgTextUtils.lineCount(titleText);
  16565. titleTrans[1] += (1 - nlines) * lineSize;
  16566. }
  16567. titleGroup.attr('transform',
  16568. 'translate(' + titleTrans + ')');
  16569. cbAxisOut.setScale();
  16570. }
  16571. }
  16572. container.selectAll('.cbfills,.cblines')
  16573. .attr('transform', 'translate(0,' +
  16574. Math.round(gs.h * (1 - cbAxisOut.domain[1])) + ')');
  16575. cbAxisOut._axislayer.attr('transform', 'translate(0,' +
  16576. Math.round(-gs.t) + ')');
  16577. var fills = container.select('.cbfills')
  16578. .selectAll('rect.cbfill')
  16579. .data(filllevels);
  16580. fills.enter().append('rect')
  16581. .classed(cn.cbfill, true)
  16582. .style('stroke', 'none');
  16583. fills.exit().remove();
  16584. var zBounds = zrange
  16585. .map(cbAxisOut.c2p)
  16586. .map(Math.round)
  16587. .sort(function(a, b) { return a - b; });
  16588. fills.each(function(d, i) {
  16589. var z = [
  16590. (i === 0) ? zrange[0] :
  16591. (filllevels[i] + filllevels[i - 1]) / 2,
  16592. (i === filllevels.length - 1) ? zrange[1] :
  16593. (filllevels[i] + filllevels[i + 1]) / 2
  16594. ]
  16595. .map(cbAxisOut.c2p)
  16596. .map(Math.round);
  16597. // offset the side adjoining the next rectangle so they
  16598. // overlap, to prevent antialiasing gaps
  16599. z[1] = Lib.constrain(z[1] + (z[1] > z[0]) ? 1 : -1, zBounds[0], zBounds[1]);
  16600. // Colorbar cannot currently support opacities so we
  16601. // use an opaque fill even when alpha channels present
  16602. var fillEl = d3.select(this).attr({
  16603. x: xLeft,
  16604. width: Math.max(thickPx, 2),
  16605. y: d3.min(z),
  16606. height: Math.max(d3.max(z) - d3.min(z), 2),
  16607. });
  16608. if(opts.fillgradient) {
  16609. Drawing.gradient(fillEl, gd, id, 'vertical',
  16610. opts.fillgradient, 'fill');
  16611. }
  16612. else {
  16613. // Tinycolor can't handle exponents and
  16614. // at this scale, removing it makes no difference.
  16615. var colorString = fillcolormap(d).replace('e-', '');
  16616. fillEl.attr('fill', tinycolor(colorString).toHexString());
  16617. }
  16618. });
  16619. var lines = container.select('.cblines')
  16620. .selectAll('path.cbline')
  16621. .data(opts.line.color && opts.line.width ?
  16622. linelevels : []);
  16623. lines.enter().append('path')
  16624. .classed(cn.cbline, true);
  16625. lines.exit().remove();
  16626. lines.each(function(d) {
  16627. d3.select(this)
  16628. .attr('d', 'M' + xLeft + ',' +
  16629. (Math.round(cbAxisOut.c2p(d)) + (opts.line.width / 2) % 1) +
  16630. 'h' + thickPx)
  16631. .call(Drawing.lineGroupStyle,
  16632. opts.line.width, linecolormap(d), opts.line.dash);
  16633. });
  16634. // force full redraw of labels and ticks
  16635. cbAxisOut._axislayer.selectAll('g.' + cbAxisOut._id + 'tick,path')
  16636. .remove();
  16637. cbAxisOut._pos = xLeft + thickPx +
  16638. (opts.outlinewidth||0) / 2 - (opts.ticks === 'outside' ? 1 : 0);
  16639. cbAxisOut.side = 'right';
  16640. // separate out axis and title drawing,
  16641. // so we don't need such complicated logic in Titles.draw
  16642. // if title is on the top or bottom, we've already drawn it
  16643. // this title call only handles side=right
  16644. return Lib.syncOrAsync([
  16645. function() {
  16646. return Axes.doTicksSingle(gd, cbAxisOut, true);
  16647. },
  16648. function() {
  16649. if(['top', 'bottom'].indexOf(opts.titleside) === -1) {
  16650. var fontSize = cbAxisOut.titlefont.size,
  16651. y = cbAxisOut._offset + cbAxisOut._length / 2,
  16652. x = gs.l + (cbAxisOut.position || 0) * gs.w + ((cbAxisOut.side === 'right') ?
  16653. 10 + fontSize * ((cbAxisOut.showticklabels ? 1 : 0.5)) :
  16654. -10 - fontSize * ((cbAxisOut.showticklabels ? 0.5 : 0)));
  16655. // the 'h' + is a hack to get around the fact that
  16656. // convertToTspans rotates any 'y...' class by 90 degrees.
  16657. // TODO: find a better way to control this.
  16658. drawTitle('h' + cbAxisOut._id + 'title', {
  16659. avoid: {
  16660. selection: d3.select(gd).selectAll('g.' + cbAxisOut._id + 'tick'),
  16661. side: opts.titleside,
  16662. offsetLeft: gs.l,
  16663. offsetTop: 0,
  16664. maxShift: fullLayout.width
  16665. },
  16666. attributes: {x: x, y: y, 'text-anchor': 'middle'},
  16667. transform: {rotate: '-90', offset: 0}
  16668. });
  16669. }
  16670. }]);
  16671. }
  16672. function drawTitle(titleClass, titleOpts) {
  16673. var trace = getTrace();
  16674. var propName = 'colorbar.title';
  16675. var containerName = trace._module.colorbar.container;
  16676. if(containerName) propName = containerName + '.' + propName;
  16677. var dfltTitleOpts = {
  16678. propContainer: cbAxisOut,
  16679. propName: propName,
  16680. traceIndex: trace.index,
  16681. placeholder: fullLayout._dfltTitle.colorbar,
  16682. containerGroup: container.select('.cbtitle')
  16683. };
  16684. // this class-to-rotate thing with convertToTspans is
  16685. // getting hackier and hackier... delete groups with the
  16686. // wrong class (in case earlier the colorbar was drawn on
  16687. // a different side, I think?)
  16688. var otherClass = titleClass.charAt(0) === 'h' ?
  16689. titleClass.substr(1) : ('h' + titleClass);
  16690. container.selectAll('.' + otherClass + ',.' + otherClass + '-math-group')
  16691. .remove();
  16692. Titles.draw(gd, titleClass,
  16693. extendFlat(dfltTitleOpts, titleOpts || {}));
  16694. }
  16695. function positionCB() {
  16696. // wait for the axis & title to finish rendering before
  16697. // continuing positioning
  16698. // TODO: why are we redrawing multiple times now with this?
  16699. // I guess autoMargin doesn't like being post-promise?
  16700. var innerWidth = thickPx + opts.outlinewidth / 2 +
  16701. Drawing.bBox(cbAxisOut._axislayer.node()).width;
  16702. titleEl = titleCont.select('text');
  16703. if(titleEl.node() && !titleEl.classed(cn.jsPlaceholder)) {
  16704. var mathJaxNode = titleCont
  16705. .select('.h' + cbAxisOut._id + 'title-math-group')
  16706. .node(),
  16707. titleWidth;
  16708. if(mathJaxNode &&
  16709. ['top', 'bottom'].indexOf(opts.titleside) !== -1) {
  16710. titleWidth = Drawing.bBox(mathJaxNode).width;
  16711. }
  16712. else {
  16713. // note: the formula below works for all titlesides,
  16714. // (except for top/bottom mathjax, above)
  16715. // but the weird gs.l is because the titleunshift
  16716. // transform gets removed by Drawing.bBox
  16717. titleWidth =
  16718. Drawing.bBox(titleCont.node()).right -
  16719. xLeft - gs.l;
  16720. }
  16721. innerWidth = Math.max(innerWidth, titleWidth);
  16722. }
  16723. var outerwidth = 2 * opts.xpad + innerWidth +
  16724. opts.borderwidth + opts.outlinewidth / 2,
  16725. outerheight = yBottomPx - yTopPx;
  16726. container.select('.cbbg').attr({
  16727. x: xLeft - opts.xpad -
  16728. (opts.borderwidth + opts.outlinewidth) / 2,
  16729. y: yTopPx - yExtraPx,
  16730. width: Math.max(outerwidth, 2),
  16731. height: Math.max(outerheight + 2 * yExtraPx, 2)
  16732. })
  16733. .call(Color.fill, opts.bgcolor)
  16734. .call(Color.stroke, opts.bordercolor)
  16735. .style({'stroke-width': opts.borderwidth});
  16736. container.selectAll('.cboutline').attr({
  16737. x: xLeft,
  16738. y: yTopPx + opts.ypad +
  16739. (opts.titleside === 'top' ? titleHeight : 0),
  16740. width: Math.max(thickPx, 2),
  16741. height: Math.max(outerheight - 2 * opts.ypad - titleHeight, 2)
  16742. })
  16743. .call(Color.stroke, opts.outlinecolor)
  16744. .style({
  16745. fill: 'None',
  16746. 'stroke-width': opts.outlinewidth
  16747. });
  16748. // fix positioning for xanchor!='left'
  16749. var xoffset = ({center: 0.5, right: 1}[opts.xanchor] || 0) *
  16750. outerwidth;
  16751. container.attr('transform',
  16752. 'translate(' + (gs.l - xoffset) + ',' + gs.t + ')');
  16753. // auto margin adjustment
  16754. var marginOpts = {};
  16755. var tFrac = FROM_TL[opts.yanchor];
  16756. var bFrac = FROM_BR[opts.yanchor];
  16757. if(opts.lenmode === 'pixels') {
  16758. marginOpts.y = opts.y;
  16759. marginOpts.t = outerheight * tFrac;
  16760. marginOpts.b = outerheight * bFrac;
  16761. }
  16762. else {
  16763. marginOpts.t = marginOpts.b = 0;
  16764. marginOpts.yt = opts.y + opts.len * tFrac;
  16765. marginOpts.yb = opts.y - opts.len * bFrac;
  16766. }
  16767. var lFrac = FROM_TL[opts.xanchor];
  16768. var rFrac = FROM_BR[opts.xanchor];
  16769. if(opts.thicknessmode === 'pixels') {
  16770. marginOpts.x = opts.x;
  16771. marginOpts.l = outerwidth * lFrac;
  16772. marginOpts.r = outerwidth * rFrac;
  16773. }
  16774. else {
  16775. var extraThickness = outerwidth - thickPx;
  16776. marginOpts.l = extraThickness * lFrac;
  16777. marginOpts.r = extraThickness * rFrac;
  16778. marginOpts.xl = opts.x - opts.thickness * lFrac;
  16779. marginOpts.xr = opts.x + opts.thickness * rFrac;
  16780. }
  16781. Plots.autoMargin(gd, id, marginOpts);
  16782. }
  16783. var cbDone = Lib.syncOrAsync([
  16784. Plots.previousPromises,
  16785. drawAxis,
  16786. Plots.previousPromises,
  16787. positionCB
  16788. ], gd);
  16789. if(cbDone && cbDone.then) (gd._promises || []).push(cbDone);
  16790. // dragging...
  16791. if(gd._context.edits.colorbarPosition) {
  16792. var t0,
  16793. xf,
  16794. yf;
  16795. dragElement.init({
  16796. element: container.node(),
  16797. gd: gd,
  16798. prepFn: function() {
  16799. t0 = container.attr('transform');
  16800. setCursor(container);
  16801. },
  16802. moveFn: function(dx, dy) {
  16803. container.attr('transform',
  16804. t0 + ' ' + 'translate(' + dx + ',' + dy + ')');
  16805. xf = dragElement.align(xLeftFrac + (dx / gs.w), thickFrac,
  16806. 0, 1, opts.xanchor);
  16807. yf = dragElement.align(yBottomFrac - (dy / gs.h), lenFrac,
  16808. 0, 1, opts.yanchor);
  16809. var csr = dragElement.getCursor(xf, yf,
  16810. opts.xanchor, opts.yanchor);
  16811. setCursor(container, csr);
  16812. },
  16813. doneFn: function() {
  16814. setCursor(container);
  16815. if(xf !== undefined && yf !== undefined) {
  16816. Registry.call('restyle',
  16817. gd,
  16818. {'colorbar.x': xf, 'colorbar.y': yf},
  16819. getTrace().index
  16820. );
  16821. }
  16822. }
  16823. });
  16824. }
  16825. return cbDone;
  16826. }
  16827. function getTrace() {
  16828. var idNum = id.substr(2),
  16829. i,
  16830. trace;
  16831. for(i = 0; i < gd._fullData.length; i++) {
  16832. trace = gd._fullData[i];
  16833. if(trace.uid === idNum) return trace;
  16834. }
  16835. }
  16836. // setter/getters for every item defined in opts
  16837. Object.keys(opts).forEach(function(name) {
  16838. component[name] = function(v) {
  16839. // getter
  16840. if(!arguments.length) return opts[name];
  16841. // setter - for multi-part properties,
  16842. // set only the parts that are provided
  16843. opts[name] = Lib.isPlainObject(opts[name]) ?
  16844. Lib.extendFlat(opts[name], v) :
  16845. v;
  16846. return component;
  16847. };
  16848. });
  16849. // or use .options to set multiple options at once via a dictionary
  16850. component.options = function(o) {
  16851. for(var name in o) {
  16852. // in case something random comes through
  16853. // that's not an option, ignore it
  16854. if(typeof component[name] === 'function') {
  16855. component[name](o[name]);
  16856. }
  16857. }
  16858. return component;
  16859. };
  16860. component._opts = opts;
  16861. return component;
  16862. };
  16863. },{"../../constants/alignment":148,"../../lib":169,"../../lib/extend":163,"../../lib/setcursor":189,"../../lib/svg_text_utils":191,"../../plots/cartesian/axes":214,"../../plots/cartesian/axis_defaults":216,"../../plots/cartesian/layout_attributes":226,"../../plots/cartesian/position_defaults":229,"../../plots/plots":246,"../../registry":259,"../color":50,"../dragelement":72,"../drawing":75,"../titles":141,"./attributes":51,"./constants":53,"d3":16,"tinycolor2":33}],56:[function(_dereq_,module,exports){
  16864. /**
  16865. * Copyright 2012-2018, Plotly, Inc.
  16866. * All rights reserved.
  16867. *
  16868. * This source code is licensed under the MIT license found in the
  16869. * LICENSE file in the root directory of this source tree.
  16870. */
  16871. 'use strict';
  16872. var Lib = _dereq_('../../lib');
  16873. module.exports = function hasColorbar(container) {
  16874. return Lib.isPlainObject(container.colorbar);
  16875. };
  16876. },{"../../lib":169}],57:[function(_dereq_,module,exports){
  16877. /**
  16878. * Copyright 2012-2018, Plotly, Inc.
  16879. * All rights reserved.
  16880. *
  16881. * This source code is licensed under the MIT license found in the
  16882. * LICENSE file in the root directory of this source tree.
  16883. */
  16884. 'use strict';
  16885. var palettes = _dereq_('./scales.js');
  16886. var paletteStr = Object.keys(palettes);
  16887. function code(s) {
  16888. return '`' + s + '`';
  16889. }
  16890. /**
  16891. * Make colorscale attribute declarations for
  16892. *
  16893. * - colorscale,
  16894. * - (c|z)auto, (c|z)min, (c|z)max,
  16895. * - autocolorscale, reversescale,
  16896. * - showscale (optionally)
  16897. * - color (optionally)
  16898. *
  16899. * @param {string} context (dflt: '', i.e. from trace root):
  16900. * the container this is in ('', *marker*, *marker.line* etc)
  16901. *
  16902. * @param {object} opts:
  16903. * - cLetter {string} (dflt: 'c'):
  16904. * leading letter for 'min', 'max and 'auto' attribute (either 'z' or 'c')
  16905. *
  16906. * - colorAttr {string} (dflt: 'z' if `cLetter: 'z'`, 'color' if `cLetter: 'c'`):
  16907. * (for descriptions) sets the name of the color attribute that maps to the colorscale.
  16908. *
  16909. * N.B. if `colorAttr: 'color'`, we include the `color` declaration here.
  16910. *
  16911. * - onlyIfNumerical {string} (dflt: false' if `cLetter: 'z'`, true if `cLetter: 'c'`):
  16912. * (for descriptions) set to true if colorscale attribute only
  16913. *
  16914. * - colorscaleDflt {string}:
  16915. * overrides the colorscale dflt
  16916. *
  16917. * - autoColorDflt {boolean} (dflt true):
  16918. * normally autocolorscale.dflt is `true`, but pass `false` to override
  16919. *
  16920. * - noScale {boolean} (dflt: true if `context: 'marker.line'`, false otherwise):
  16921. * set to `false` to not include showscale attribute (e.g. for 'marker.line')
  16922. *
  16923. * - showScaleDflt {boolean} (dflt: true if `cLetter: 'z'`, false otherwise)
  16924. *
  16925. * - editTypeOverride {boolean} (dflt: ''):
  16926. * most of these attributes already require a recalc, but the ones that do not
  16927. * have editType *style* or *plot* unless you override (presumably with *calc*)
  16928. *
  16929. * @return {object}
  16930. */
  16931. module.exports = function colorScaleAttrs(context, opts) {
  16932. context = context || '';
  16933. opts = opts || {};
  16934. var cLetter = opts.cLetter || 'c';
  16935. var onlyIfNumerical = ('onlyIfNumerical' in opts) ? opts.onlyIfNumerical : Boolean(context);
  16936. var noScale = ('noScale' in opts) ? opts.noScale : context === 'marker.line';
  16937. var showScaleDflt = ('showScaleDflt' in opts) ? opts.showScaleDflt : cLetter === 'z';
  16938. var colorscaleDflt = typeof opts.colorscaleDflt === 'string' ? palettes[opts.colorscaleDflt] : null;
  16939. var editTypeOverride = opts.editTypeOverride || '';
  16940. var contextHead = context ? (context + '.') : '';
  16941. var colorAttr, colorAttrFull;
  16942. if('colorAttr' in opts) {
  16943. colorAttr = opts.colorAttr;
  16944. colorAttrFull = opts.colorAttr;
  16945. } else {
  16946. colorAttr = {z: 'z', c: 'color'}[cLetter];
  16947. colorAttrFull = 'in ' + code(contextHead + colorAttr);
  16948. }
  16949. var effectDesc = onlyIfNumerical ?
  16950. ' Has an effect only if ' + colorAttrFull + 'is set to a numerical array.' :
  16951. '';
  16952. var auto = cLetter + 'auto';
  16953. var min = cLetter + 'min';
  16954. var max = cLetter + 'max';
  16955. var minFull = code(contextHead + min);
  16956. var maxFull = code(contextHead + max);
  16957. var minmaxFull = minFull + ' and ' + maxFull;
  16958. var autoImpliedEdits = {};
  16959. autoImpliedEdits[min] = autoImpliedEdits[max] = undefined;
  16960. var minmaxImpliedEdits = {};
  16961. minmaxImpliedEdits[auto] = false;
  16962. var attrs = {};
  16963. if(colorAttr === 'color') {
  16964. attrs.color = {
  16965. valType: 'color',
  16966. arrayOk: true,
  16967. editType: editTypeOverride || 'style',
  16968. };
  16969. }
  16970. attrs[auto] = {
  16971. valType: 'boolean',
  16972. dflt: true,
  16973. editType: 'calc',
  16974. impliedEdits: autoImpliedEdits,
  16975. };
  16976. attrs[min] = {
  16977. valType: 'number',
  16978. dflt: null,
  16979. editType: editTypeOverride || 'plot',
  16980. impliedEdits: minmaxImpliedEdits,
  16981. };
  16982. attrs[max] = {
  16983. valType: 'number',
  16984. dflt: null,
  16985. editType: editTypeOverride || 'plot',
  16986. impliedEdits: minmaxImpliedEdits,
  16987. };
  16988. attrs.colorscale = {
  16989. valType: 'colorscale',
  16990. editType: 'calc',
  16991. dflt: colorscaleDflt,
  16992. impliedEdits: {autocolorscale: false},
  16993. };
  16994. attrs.autocolorscale = {
  16995. valType: 'boolean',
  16996. // gets overrode in 'heatmap' & 'surface' for backwards comp.
  16997. dflt: opts.autoColorDflt === false ? false : true,
  16998. editType: 'calc',
  16999. impliedEdits: {colorscale: undefined},
  17000. };
  17001. attrs.reversescale = {
  17002. valType: 'boolean',
  17003. dflt: false,
  17004. editType: 'calc',
  17005. };
  17006. if(!noScale) {
  17007. attrs.showscale = {
  17008. valType: 'boolean',
  17009. dflt: showScaleDflt,
  17010. editType: 'calc',
  17011. };
  17012. }
  17013. return attrs;
  17014. };
  17015. },{"./scales.js":69}],58:[function(_dereq_,module,exports){
  17016. /**
  17017. * Copyright 2012-2018, Plotly, Inc.
  17018. * All rights reserved.
  17019. *
  17020. * This source code is licensed under the MIT license found in the
  17021. * LICENSE file in the root directory of this source tree.
  17022. */
  17023. 'use strict';
  17024. var Lib = _dereq_('../../lib');
  17025. var scales = _dereq_('./scales');
  17026. var flipScale = _dereq_('./flip_scale');
  17027. module.exports = function calc(trace, vals, containerStr, cLetter) {
  17028. var container = trace;
  17029. var inputContainer = trace._input;
  17030. var fullInputContainer = trace._fullInput;
  17031. // set by traces with groupby transforms
  17032. var updateStyle = trace.updateStyle;
  17033. function doUpdate(attr, inputVal, fullVal) {
  17034. if(fullVal === undefined) fullVal = inputVal;
  17035. if(updateStyle) {
  17036. updateStyle(trace._input, containerStr ? (containerStr + '.' + attr) : attr, inputVal);
  17037. }
  17038. else {
  17039. inputContainer[attr] = inputVal;
  17040. }
  17041. container[attr] = fullVal;
  17042. if(fullInputContainer && (trace !== trace._fullInput)) {
  17043. if(updateStyle) {
  17044. updateStyle(trace._fullInput, containerStr ? (containerStr + '.' + attr) : attr, fullVal);
  17045. }
  17046. else {
  17047. fullInputContainer[attr] = fullVal;
  17048. }
  17049. }
  17050. }
  17051. if(containerStr) {
  17052. container = Lib.nestedProperty(container, containerStr).get();
  17053. inputContainer = Lib.nestedProperty(inputContainer, containerStr).get();
  17054. fullInputContainer = Lib.nestedProperty(fullInputContainer, containerStr).get() || {};
  17055. }
  17056. var autoAttr = cLetter + 'auto';
  17057. var minAttr = cLetter + 'min';
  17058. var maxAttr = cLetter + 'max';
  17059. var auto = container[autoAttr];
  17060. var min = container[minAttr];
  17061. var max = container[maxAttr];
  17062. var scl = container.colorscale;
  17063. if(auto !== false || min === undefined) {
  17064. min = Lib.aggNums(Math.min, null, vals);
  17065. }
  17066. if(auto !== false || max === undefined) {
  17067. max = Lib.aggNums(Math.max, null, vals);
  17068. }
  17069. if(min === max) {
  17070. min -= 0.5;
  17071. max += 0.5;
  17072. }
  17073. doUpdate(minAttr, min);
  17074. doUpdate(maxAttr, max);
  17075. /*
  17076. * If auto was explicitly false but min or max was missing,
  17077. * we filled in the missing piece here but later the trace does
  17078. * not look auto.
  17079. * Otherwise make sure the trace still looks auto as far as later
  17080. * changes are concerned.
  17081. */
  17082. doUpdate(autoAttr, (auto !== false || (min === undefined && max === undefined)));
  17083. if(container.autocolorscale) {
  17084. if(min * max < 0) scl = scales.RdBu;
  17085. else if(min >= 0) scl = scales.Reds;
  17086. else scl = scales.Blues;
  17087. // reversescale is handled at the containerOut level
  17088. doUpdate('colorscale', scl, container.reversescale ? flipScale(scl) : scl);
  17089. // We pushed a colorscale back to input, which will change the default autocolorscale next time
  17090. // to avoid spurious redraws from Plotly.react, update resulting autocolorscale now
  17091. // This is a conscious decision so that changing the data later does not unexpectedly
  17092. // give you a new colorscale
  17093. if(!inputContainer.autocolorscale) {
  17094. doUpdate('autocolorscale', false);
  17095. }
  17096. }
  17097. };
  17098. },{"../../lib":169,"./flip_scale":62,"./scales":69}],59:[function(_dereq_,module,exports){
  17099. /**
  17100. * Copyright 2012-2018, Plotly, Inc.
  17101. * All rights reserved.
  17102. *
  17103. * This source code is licensed under the MIT license found in the
  17104. * LICENSE file in the root directory of this source tree.
  17105. */
  17106. 'use strict';
  17107. var scales = _dereq_('./scales');
  17108. module.exports = scales.RdBu;
  17109. },{"./scales":69}],60:[function(_dereq_,module,exports){
  17110. /**
  17111. * Copyright 2012-2018, Plotly, Inc.
  17112. * All rights reserved.
  17113. *
  17114. * This source code is licensed under the MIT license found in the
  17115. * LICENSE file in the root directory of this source tree.
  17116. */
  17117. 'use strict';
  17118. var isNumeric = _dereq_('fast-isnumeric');
  17119. var Lib = _dereq_('../../lib');
  17120. var hasColorbar = _dereq_('../colorbar/has_colorbar');
  17121. var colorbarDefaults = _dereq_('../colorbar/defaults');
  17122. var isValidScale = _dereq_('./is_valid_scale');
  17123. var flipScale = _dereq_('./flip_scale');
  17124. module.exports = function colorScaleDefaults(traceIn, traceOut, layout, coerce, opts) {
  17125. var prefix = opts.prefix,
  17126. cLetter = opts.cLetter,
  17127. containerStr = prefix.slice(0, prefix.length - 1),
  17128. containerIn = prefix ?
  17129. Lib.nestedProperty(traceIn, containerStr).get() || {} :
  17130. traceIn,
  17131. containerOut = prefix ?
  17132. Lib.nestedProperty(traceOut, containerStr).get() || {} :
  17133. traceOut,
  17134. minIn = containerIn[cLetter + 'min'],
  17135. maxIn = containerIn[cLetter + 'max'],
  17136. sclIn = containerIn.colorscale;
  17137. var validMinMax = isNumeric(minIn) && isNumeric(maxIn) && (minIn < maxIn);
  17138. coerce(prefix + cLetter + 'auto', !validMinMax);
  17139. coerce(prefix + cLetter + 'min');
  17140. coerce(prefix + cLetter + 'max');
  17141. // handles both the trace case (autocolorscale is false by default) and
  17142. // the marker and marker.line case (autocolorscale is true by default)
  17143. var autoColorscaleDflt;
  17144. if(sclIn !== undefined) autoColorscaleDflt = !isValidScale(sclIn);
  17145. coerce(prefix + 'autocolorscale', autoColorscaleDflt);
  17146. var sclOut = coerce(prefix + 'colorscale');
  17147. // reversescale is handled at the containerOut level
  17148. var reverseScale = coerce(prefix + 'reversescale');
  17149. if(reverseScale) containerOut.colorscale = flipScale(sclOut);
  17150. // ... until Scatter.colorbar can handle marker line colorbars
  17151. if(prefix === 'marker.line.') return;
  17152. if(!opts.noScale) {
  17153. // handles both the trace case where the dflt is listed in attributes and
  17154. // the marker case where the dflt is determined by hasColorbar
  17155. var showScaleDflt;
  17156. if(prefix) showScaleDflt = hasColorbar(containerIn);
  17157. var showScale = coerce(prefix + 'showscale', showScaleDflt);
  17158. if(showScale) colorbarDefaults(containerIn, containerOut, layout);
  17159. }
  17160. };
  17161. },{"../../lib":169,"../colorbar/defaults":54,"../colorbar/has_colorbar":56,"./flip_scale":62,"./is_valid_scale":66,"fast-isnumeric":18}],61:[function(_dereq_,module,exports){
  17162. /**
  17163. * Copyright 2012-2018, Plotly, Inc.
  17164. * All rights reserved.
  17165. *
  17166. * This source code is licensed under the MIT license found in the
  17167. * LICENSE file in the root directory of this source tree.
  17168. */
  17169. 'use strict';
  17170. /**
  17171. * Extract colorscale into numeric domain and color range.
  17172. *
  17173. * @param {array} scl colorscale array of arrays
  17174. * @param {number} cmin minimum color value (used to clamp scale)
  17175. * @param {number} cmax maximum color value (used to clamp scale)
  17176. */
  17177. module.exports = function extractScale(scl, cmin, cmax) {
  17178. var N = scl.length,
  17179. domain = new Array(N),
  17180. range = new Array(N);
  17181. for(var i = 0; i < N; i++) {
  17182. var si = scl[i];
  17183. domain[i] = cmin + si[0] * (cmax - cmin);
  17184. range[i] = si[1];
  17185. }
  17186. return {
  17187. domain: domain,
  17188. range: range
  17189. };
  17190. };
  17191. },{}],62:[function(_dereq_,module,exports){
  17192. /**
  17193. * Copyright 2012-2018, Plotly, Inc.
  17194. * All rights reserved.
  17195. *
  17196. * This source code is licensed under the MIT license found in the
  17197. * LICENSE file in the root directory of this source tree.
  17198. */
  17199. 'use strict';
  17200. module.exports = function flipScale(scl) {
  17201. var N = scl.length,
  17202. sclNew = new Array(N),
  17203. si;
  17204. for(var i = N - 1, j = 0; i >= 0; i--, j++) {
  17205. si = scl[i];
  17206. sclNew[j] = [1 - si[0], si[1]];
  17207. }
  17208. return sclNew;
  17209. };
  17210. },{}],63:[function(_dereq_,module,exports){
  17211. /**
  17212. * Copyright 2012-2018, Plotly, Inc.
  17213. * All rights reserved.
  17214. *
  17215. * This source code is licensed under the MIT license found in the
  17216. * LICENSE file in the root directory of this source tree.
  17217. */
  17218. 'use strict';
  17219. var scales = _dereq_('./scales');
  17220. var defaultScale = _dereq_('./default_scale');
  17221. var isValidScaleArray = _dereq_('./is_valid_scale_array');
  17222. module.exports = function getScale(scl, dflt) {
  17223. if(!dflt) dflt = defaultScale;
  17224. if(!scl) return dflt;
  17225. function parseScale() {
  17226. try {
  17227. scl = scales[scl] || JSON.parse(scl);
  17228. }
  17229. catch(e) {
  17230. scl = dflt;
  17231. }
  17232. }
  17233. if(typeof scl === 'string') {
  17234. parseScale();
  17235. // occasionally scl is double-JSON encoded...
  17236. if(typeof scl === 'string') parseScale();
  17237. }
  17238. if(!isValidScaleArray(scl)) return dflt;
  17239. return scl;
  17240. };
  17241. },{"./default_scale":59,"./is_valid_scale_array":67,"./scales":69}],64:[function(_dereq_,module,exports){
  17242. /**
  17243. * Copyright 2012-2018, Plotly, Inc.
  17244. * All rights reserved.
  17245. *
  17246. * This source code is licensed under the MIT license found in the
  17247. * LICENSE file in the root directory of this source tree.
  17248. */
  17249. 'use strict';
  17250. var isNumeric = _dereq_('fast-isnumeric');
  17251. var Lib = _dereq_('../../lib');
  17252. var isValidScale = _dereq_('./is_valid_scale');
  17253. module.exports = function hasColorscale(trace, containerStr) {
  17254. var container = containerStr ?
  17255. Lib.nestedProperty(trace, containerStr).get() || {} :
  17256. trace;
  17257. var color = container.color;
  17258. var isArrayWithOneNumber = false;
  17259. if(Lib.isArrayOrTypedArray(color)) {
  17260. for(var i = 0; i < color.length; i++) {
  17261. if(isNumeric(color[i])) {
  17262. isArrayWithOneNumber = true;
  17263. break;
  17264. }
  17265. }
  17266. }
  17267. return (
  17268. Lib.isPlainObject(container) && (
  17269. isArrayWithOneNumber ||
  17270. container.showscale === true ||
  17271. (isNumeric(container.cmin) && isNumeric(container.cmax)) ||
  17272. isValidScale(container.colorscale) ||
  17273. Lib.isPlainObject(container.colorbar)
  17274. )
  17275. );
  17276. };
  17277. },{"../../lib":169,"./is_valid_scale":66,"fast-isnumeric":18}],65:[function(_dereq_,module,exports){
  17278. /**
  17279. * Copyright 2012-2018, Plotly, Inc.
  17280. * All rights reserved.
  17281. *
  17282. * This source code is licensed under the MIT license found in the
  17283. * LICENSE file in the root directory of this source tree.
  17284. */
  17285. 'use strict';
  17286. exports.scales = _dereq_('./scales');
  17287. exports.defaultScale = _dereq_('./default_scale');
  17288. exports.attributes = _dereq_('./attributes');
  17289. exports.handleDefaults = _dereq_('./defaults');
  17290. exports.calc = _dereq_('./calc');
  17291. exports.hasColorscale = _dereq_('./has_colorscale');
  17292. exports.isValidScale = _dereq_('./is_valid_scale');
  17293. exports.getScale = _dereq_('./get_scale');
  17294. exports.flipScale = _dereq_('./flip_scale');
  17295. exports.extractScale = _dereq_('./extract_scale');
  17296. exports.makeColorScaleFunc = _dereq_('./make_color_scale_func');
  17297. },{"./attributes":57,"./calc":58,"./default_scale":59,"./defaults":60,"./extract_scale":61,"./flip_scale":62,"./get_scale":63,"./has_colorscale":64,"./is_valid_scale":66,"./make_color_scale_func":68,"./scales":69}],66:[function(_dereq_,module,exports){
  17298. /**
  17299. * Copyright 2012-2018, Plotly, Inc.
  17300. * All rights reserved.
  17301. *
  17302. * This source code is licensed under the MIT license found in the
  17303. * LICENSE file in the root directory of this source tree.
  17304. */
  17305. 'use strict';
  17306. var scales = _dereq_('./scales');
  17307. var isValidScaleArray = _dereq_('./is_valid_scale_array');
  17308. module.exports = function isValidScale(scl) {
  17309. if(scales[scl] !== undefined) return true;
  17310. else return isValidScaleArray(scl);
  17311. };
  17312. },{"./is_valid_scale_array":67,"./scales":69}],67:[function(_dereq_,module,exports){
  17313. /**
  17314. * Copyright 2012-2018, Plotly, Inc.
  17315. * All rights reserved.
  17316. *
  17317. * This source code is licensed under the MIT license found in the
  17318. * LICENSE file in the root directory of this source tree.
  17319. */
  17320. 'use strict';
  17321. var tinycolor = _dereq_('tinycolor2');
  17322. module.exports = function isValidScaleArray(scl) {
  17323. var highestVal = 0;
  17324. if(!Array.isArray(scl) || scl.length < 2) return false;
  17325. if(!scl[0] || !scl[scl.length - 1]) return false;
  17326. if(+scl[0][0] !== 0 || +scl[scl.length - 1][0] !== 1) return false;
  17327. for(var i = 0; i < scl.length; i++) {
  17328. var si = scl[i];
  17329. if(si.length !== 2 || +si[0] < highestVal || !tinycolor(si[1]).isValid()) {
  17330. return false;
  17331. }
  17332. highestVal = +si[0];
  17333. }
  17334. return true;
  17335. };
  17336. },{"tinycolor2":33}],68:[function(_dereq_,module,exports){
  17337. /**
  17338. * Copyright 2012-2018, Plotly, Inc.
  17339. * All rights reserved.
  17340. *
  17341. * This source code is licensed under the MIT license found in the
  17342. * LICENSE file in the root directory of this source tree.
  17343. */
  17344. 'use strict';
  17345. var d3 = _dereq_('d3');
  17346. var tinycolor = _dereq_('tinycolor2');
  17347. var isNumeric = _dereq_('fast-isnumeric');
  17348. var Color = _dereq_('../color');
  17349. /**
  17350. * General colorscale function generator.
  17351. *
  17352. * @param {object} specs output of Colorscale.extractScale or precomputed domain, range.
  17353. * - domain {array}
  17354. * - range {array}
  17355. *
  17356. * @param {object} opts
  17357. * - noNumericCheck {boolean} if true, scale func bypasses numeric checks
  17358. * - returnArray {boolean} if true, scale func return 4-item array instead of color strings
  17359. *
  17360. * @return {function}
  17361. */
  17362. module.exports = function makeColorScaleFunc(specs, opts) {
  17363. opts = opts || {};
  17364. var domain = specs.domain,
  17365. range = specs.range,
  17366. N = range.length,
  17367. _range = new Array(N);
  17368. for(var i = 0; i < N; i++) {
  17369. var rgba = tinycolor(range[i]).toRgb();
  17370. _range[i] = [rgba.r, rgba.g, rgba.b, rgba.a];
  17371. }
  17372. var _sclFunc = d3.scale.linear()
  17373. .domain(domain)
  17374. .range(_range)
  17375. .clamp(true);
  17376. var noNumericCheck = opts.noNumericCheck,
  17377. returnArray = opts.returnArray,
  17378. sclFunc;
  17379. if(noNumericCheck && returnArray) {
  17380. sclFunc = _sclFunc;
  17381. }
  17382. else if(noNumericCheck) {
  17383. sclFunc = function(v) {
  17384. return colorArray2rbga(_sclFunc(v));
  17385. };
  17386. }
  17387. else if(returnArray) {
  17388. sclFunc = function(v) {
  17389. if(isNumeric(v)) return _sclFunc(v);
  17390. else if(tinycolor(v).isValid()) return v;
  17391. else return Color.defaultLine;
  17392. };
  17393. }
  17394. else {
  17395. sclFunc = function(v) {
  17396. if(isNumeric(v)) return colorArray2rbga(_sclFunc(v));
  17397. else if(tinycolor(v).isValid()) return v;
  17398. else return Color.defaultLine;
  17399. };
  17400. }
  17401. // colorbar draw looks into the d3 scale closure for domain and range
  17402. sclFunc.domain = _sclFunc.domain;
  17403. sclFunc.range = function() { return range; };
  17404. return sclFunc;
  17405. };
  17406. function colorArray2rbga(colorArray) {
  17407. var colorObj = {
  17408. r: colorArray[0],
  17409. g: colorArray[1],
  17410. b: colorArray[2],
  17411. a: colorArray[3]
  17412. };
  17413. return tinycolor(colorObj).toRgbString();
  17414. }
  17415. },{"../color":50,"d3":16,"fast-isnumeric":18,"tinycolor2":33}],69:[function(_dereq_,module,exports){
  17416. /**
  17417. * Copyright 2012-2018, Plotly, Inc.
  17418. * All rights reserved.
  17419. *
  17420. * This source code is licensed under the MIT license found in the
  17421. * LICENSE file in the root directory of this source tree.
  17422. */
  17423. 'use strict';
  17424. module.exports = {
  17425. 'Greys': [
  17426. [0, 'rgb(0,0,0)'], [1, 'rgb(255,255,255)']
  17427. ],
  17428. 'YlGnBu': [
  17429. [0, 'rgb(8,29,88)'], [0.125, 'rgb(37,52,148)'],
  17430. [0.25, 'rgb(34,94,168)'], [0.375, 'rgb(29,145,192)'],
  17431. [0.5, 'rgb(65,182,196)'], [0.625, 'rgb(127,205,187)'],
  17432. [0.75, 'rgb(199,233,180)'], [0.875, 'rgb(237,248,217)'],
  17433. [1, 'rgb(255,255,217)']
  17434. ],
  17435. 'Greens': [
  17436. [0, 'rgb(0,68,27)'], [0.125, 'rgb(0,109,44)'],
  17437. [0.25, 'rgb(35,139,69)'], [0.375, 'rgb(65,171,93)'],
  17438. [0.5, 'rgb(116,196,118)'], [0.625, 'rgb(161,217,155)'],
  17439. [0.75, 'rgb(199,233,192)'], [0.875, 'rgb(229,245,224)'],
  17440. [1, 'rgb(247,252,245)']
  17441. ],
  17442. 'YlOrRd': [
  17443. [0, 'rgb(128,0,38)'], [0.125, 'rgb(189,0,38)'],
  17444. [0.25, 'rgb(227,26,28)'], [0.375, 'rgb(252,78,42)'],
  17445. [0.5, 'rgb(253,141,60)'], [0.625, 'rgb(254,178,76)'],
  17446. [0.75, 'rgb(254,217,118)'], [0.875, 'rgb(255,237,160)'],
  17447. [1, 'rgb(255,255,204)']
  17448. ],
  17449. 'Bluered': [
  17450. [0, 'rgb(0,0,255)'], [1, 'rgb(255,0,0)']
  17451. ],
  17452. // modified RdBu based on
  17453. // www.sandia.gov/~kmorel/documents/ColorMaps/ColorMapsExpanded.pdf
  17454. 'RdBu': [
  17455. [0, 'rgb(5,10,172)'], [0.35, 'rgb(106,137,247)'],
  17456. [0.5, 'rgb(190,190,190)'], [0.6, 'rgb(220,170,132)'],
  17457. [0.7, 'rgb(230,145,90)'], [1, 'rgb(178,10,28)']
  17458. ],
  17459. // Scale for non-negative numeric values
  17460. 'Reds': [
  17461. [0, 'rgb(220,220,220)'], [0.2, 'rgb(245,195,157)'],
  17462. [0.4, 'rgb(245,160,105)'], [1, 'rgb(178,10,28)']
  17463. ],
  17464. // Scale for non-positive numeric values
  17465. 'Blues': [
  17466. [0, 'rgb(5,10,172)'], [0.35, 'rgb(40,60,190)'],
  17467. [0.5, 'rgb(70,100,245)'], [0.6, 'rgb(90,120,245)'],
  17468. [0.7, 'rgb(106,137,247)'], [1, 'rgb(220,220,220)']
  17469. ],
  17470. 'Picnic': [
  17471. [0, 'rgb(0,0,255)'], [0.1, 'rgb(51,153,255)'],
  17472. [0.2, 'rgb(102,204,255)'], [0.3, 'rgb(153,204,255)'],
  17473. [0.4, 'rgb(204,204,255)'], [0.5, 'rgb(255,255,255)'],
  17474. [0.6, 'rgb(255,204,255)'], [0.7, 'rgb(255,153,255)'],
  17475. [0.8, 'rgb(255,102,204)'], [0.9, 'rgb(255,102,102)'],
  17476. [1, 'rgb(255,0,0)']
  17477. ],
  17478. 'Rainbow': [
  17479. [0, 'rgb(150,0,90)'], [0.125, 'rgb(0,0,200)'],
  17480. [0.25, 'rgb(0,25,255)'], [0.375, 'rgb(0,152,255)'],
  17481. [0.5, 'rgb(44,255,150)'], [0.625, 'rgb(151,255,0)'],
  17482. [0.75, 'rgb(255,234,0)'], [0.875, 'rgb(255,111,0)'],
  17483. [1, 'rgb(255,0,0)']
  17484. ],
  17485. 'Portland': [
  17486. [0, 'rgb(12,51,131)'], [0.25, 'rgb(10,136,186)'],
  17487. [0.5, 'rgb(242,211,56)'], [0.75, 'rgb(242,143,56)'],
  17488. [1, 'rgb(217,30,30)']
  17489. ],
  17490. 'Jet': [
  17491. [0, 'rgb(0,0,131)'], [0.125, 'rgb(0,60,170)'],
  17492. [0.375, 'rgb(5,255,255)'], [0.625, 'rgb(255,255,0)'],
  17493. [0.875, 'rgb(250,0,0)'], [1, 'rgb(128,0,0)']
  17494. ],
  17495. 'Hot': [
  17496. [0, 'rgb(0,0,0)'], [0.3, 'rgb(230,0,0)'],
  17497. [0.6, 'rgb(255,210,0)'], [1, 'rgb(255,255,255)']
  17498. ],
  17499. 'Blackbody': [
  17500. [0, 'rgb(0,0,0)'], [0.2, 'rgb(230,0,0)'],
  17501. [0.4, 'rgb(230,210,0)'], [0.7, 'rgb(255,255,255)'],
  17502. [1, 'rgb(160,200,255)']
  17503. ],
  17504. 'Earth': [
  17505. [0, 'rgb(0,0,130)'], [0.1, 'rgb(0,180,180)'],
  17506. [0.2, 'rgb(40,210,40)'], [0.4, 'rgb(230,230,50)'],
  17507. [0.6, 'rgb(120,70,20)'], [1, 'rgb(255,255,255)']
  17508. ],
  17509. 'Electric': [
  17510. [0, 'rgb(0,0,0)'], [0.15, 'rgb(30,0,100)'],
  17511. [0.4, 'rgb(120,0,100)'], [0.6, 'rgb(160,90,0)'],
  17512. [0.8, 'rgb(230,200,0)'], [1, 'rgb(255,250,220)']
  17513. ],
  17514. 'Viridis': [
  17515. [0, '#440154'], [0.06274509803921569, '#48186a'],
  17516. [0.12549019607843137, '#472d7b'], [0.18823529411764706, '#424086'],
  17517. [0.25098039215686274, '#3b528b'], [0.3137254901960784, '#33638d'],
  17518. [0.3764705882352941, '#2c728e'], [0.4392156862745098, '#26828e'],
  17519. [0.5019607843137255, '#21918c'], [0.5647058823529412, '#1fa088'],
  17520. [0.6274509803921569, '#28ae80'], [0.6901960784313725, '#3fbc73'],
  17521. [0.7529411764705882, '#5ec962'], [0.8156862745098039, '#84d44b'],
  17522. [0.8784313725490196, '#addc30'], [0.9411764705882353, '#d8e219'],
  17523. [1, '#fde725']
  17524. ],
  17525. 'Cividis': [
  17526. [0.000000, 'rgb(0,32,76)'], [0.058824, 'rgb(0,42,102)'],
  17527. [0.117647, 'rgb(0,52,110)'], [0.176471, 'rgb(39,63,108)'],
  17528. [0.235294, 'rgb(60,74,107)'], [0.294118, 'rgb(76,85,107)'],
  17529. [0.352941, 'rgb(91,95,109)'], [0.411765, 'rgb(104,106,112)'],
  17530. [0.470588, 'rgb(117,117,117)'], [0.529412, 'rgb(131,129,120)'],
  17531. [0.588235, 'rgb(146,140,120)'], [0.647059, 'rgb(161,152,118)'],
  17532. [0.705882, 'rgb(176,165,114)'], [0.764706, 'rgb(192,177,109)'],
  17533. [0.823529, 'rgb(209,191,102)'], [0.882353, 'rgb(225,204,92)'],
  17534. [0.941176, 'rgb(243,219,79)'], [1.000000, 'rgb(255,233,69)']
  17535. ]
  17536. };
  17537. },{}],70:[function(_dereq_,module,exports){
  17538. /**
  17539. * Copyright 2012-2018, Plotly, Inc.
  17540. * All rights reserved.
  17541. *
  17542. * This source code is licensed under the MIT license found in the
  17543. * LICENSE file in the root directory of this source tree.
  17544. */
  17545. 'use strict';
  17546. // for automatic alignment on dragging, <1/3 means left align,
  17547. // >2/3 means right, and between is center. Pick the right fraction
  17548. // based on where you are, and return the fraction corresponding to
  17549. // that position on the object
  17550. module.exports = function align(v, dv, v0, v1, anchor) {
  17551. var vmin = (v - v0) / (v1 - v0),
  17552. vmax = vmin + dv / (v1 - v0),
  17553. vc = (vmin + vmax) / 2;
  17554. // explicitly specified anchor
  17555. if(anchor === 'left' || anchor === 'bottom') return vmin;
  17556. if(anchor === 'center' || anchor === 'middle') return vc;
  17557. if(anchor === 'right' || anchor === 'top') return vmax;
  17558. // automatic based on position
  17559. if(vmin < (2 / 3) - vc) return vmin;
  17560. if(vmax > (4 / 3) - vc) return vmax;
  17561. return vc;
  17562. };
  17563. },{}],71:[function(_dereq_,module,exports){
  17564. /**
  17565. * Copyright 2012-2018, Plotly, Inc.
  17566. * All rights reserved.
  17567. *
  17568. * This source code is licensed under the MIT license found in the
  17569. * LICENSE file in the root directory of this source tree.
  17570. */
  17571. 'use strict';
  17572. var Lib = _dereq_('../../lib');
  17573. // set cursors pointing toward the closest corner/side,
  17574. // to indicate alignment
  17575. // x and y are 0-1, fractions of the plot area
  17576. var cursorset = [
  17577. ['sw-resize', 's-resize', 'se-resize'],
  17578. ['w-resize', 'move', 'e-resize'],
  17579. ['nw-resize', 'n-resize', 'ne-resize']
  17580. ];
  17581. module.exports = function getCursor(x, y, xanchor, yanchor) {
  17582. if(xanchor === 'left') x = 0;
  17583. else if(xanchor === 'center') x = 1;
  17584. else if(xanchor === 'right') x = 2;
  17585. else x = Lib.constrain(Math.floor(x * 3), 0, 2);
  17586. if(yanchor === 'bottom') y = 0;
  17587. else if(yanchor === 'middle') y = 1;
  17588. else if(yanchor === 'top') y = 2;
  17589. else y = Lib.constrain(Math.floor(y * 3), 0, 2);
  17590. return cursorset[y][x];
  17591. };
  17592. },{"../../lib":169}],72:[function(_dereq_,module,exports){
  17593. /**
  17594. * Copyright 2012-2018, Plotly, Inc.
  17595. * All rights reserved.
  17596. *
  17597. * This source code is licensed under the MIT license found in the
  17598. * LICENSE file in the root directory of this source tree.
  17599. */
  17600. 'use strict';
  17601. var mouseOffset = _dereq_('mouse-event-offset');
  17602. var hasHover = _dereq_('has-hover');
  17603. var supportsPassive = _dereq_('has-passive-events');
  17604. var Registry = _dereq_('../../registry');
  17605. var Lib = _dereq_('../../lib');
  17606. var constants = _dereq_('../../plots/cartesian/constants');
  17607. var interactConstants = _dereq_('../../constants/interactions');
  17608. var dragElement = module.exports = {};
  17609. dragElement.align = _dereq_('./align');
  17610. dragElement.getCursor = _dereq_('./cursor');
  17611. var unhover = _dereq_('./unhover');
  17612. dragElement.unhover = unhover.wrapped;
  17613. dragElement.unhoverRaw = unhover.raw;
  17614. /**
  17615. * Abstracts click & drag interactions
  17616. *
  17617. * During the interaction, a "coverSlip" element - a transparent
  17618. * div covering the whole page - is created, which has two key effects:
  17619. * - Lets you drag beyond the boundaries of the plot itself without
  17620. * dropping (but if you drag all the way out of the browser window the
  17621. * interaction will end)
  17622. * - Freezes the cursor: whatever mouse cursor the drag element had when the
  17623. * interaction started gets copied to the coverSlip for use until mouseup
  17624. *
  17625. * If the user executes a drag bigger than MINDRAG, callbacks will fire as:
  17626. * prepFn, moveFn (1 or more times), doneFn
  17627. * If the user does not drag enough, prepFn and clickFn will fire.
  17628. *
  17629. * Note: If you cancel contextmenu, clickFn will fire even with a right click
  17630. * (unlike native events) so you'll get a `plotly_click` event. Cancel context eg:
  17631. * gd.addEventListener('contextmenu', function(e) { e.preventDefault(); });
  17632. * TODO: we should probably turn this into a `config` parameter, so we can fix it
  17633. * such that if you *don't* cancel contextmenu, we can prevent partial drags, which
  17634. * put you in a weird state.
  17635. *
  17636. * If the user clicks multiple times quickly, clickFn will fire each time
  17637. * but numClicks will increase to help you recognize doubleclicks.
  17638. *
  17639. * @param {object} options with keys:
  17640. * element (required) the DOM element to drag
  17641. * prepFn (optional) function(event, startX, startY)
  17642. * executed on mousedown
  17643. * startX and startY are the clientX and clientY pixel position
  17644. * of the mousedown event
  17645. * moveFn (optional) function(dx, dy)
  17646. * executed on move, ONLY after we've exceeded MINDRAG
  17647. * (we keep executing moveFn if you move back to where you started)
  17648. * dx and dy are the net pixel offset of the drag,
  17649. * dragged is true/false, has the mouse moved enough to
  17650. * constitute a drag
  17651. * doneFn (optional) function(e)
  17652. * executed on mouseup, ONLY if we exceeded MINDRAG (so you can be
  17653. * sure that moveFn has been called at least once)
  17654. * numClicks is how many clicks we've registered within
  17655. * a doubleclick time
  17656. * e is the original mouseup event
  17657. * clickFn (optional) function(numClicks, e)
  17658. * executed on mouseup if we have NOT exceeded MINDRAG (ie moveFn
  17659. * has not been called at all)
  17660. * numClicks is how many clicks we've registered within
  17661. * a doubleclick time
  17662. * e is the original mousedown event
  17663. * clampFn (optional, function(dx, dy) return [dx2, dy2])
  17664. * Provide custom clamping function for small displacements.
  17665. * By default, clamping is done using `minDrag` to x and y displacements
  17666. * independently.
  17667. */
  17668. dragElement.init = function init(options) {
  17669. var gd = options.gd;
  17670. var numClicks = 1;
  17671. var DBLCLICKDELAY = interactConstants.DBLCLICKDELAY;
  17672. var element = options.element;
  17673. var startX,
  17674. startY,
  17675. newMouseDownTime,
  17676. cursor,
  17677. dragCover,
  17678. initialEvent,
  17679. initialTarget,
  17680. rightClick;
  17681. if(!gd._mouseDownTime) gd._mouseDownTime = 0;
  17682. element.style.pointerEvents = 'all';
  17683. element.onmousedown = onStart;
  17684. if(!supportsPassive) {
  17685. element.ontouchstart = onStart;
  17686. }
  17687. else {
  17688. if(element._ontouchstart) {
  17689. element.removeEventListener('touchstart', element._ontouchstart);
  17690. }
  17691. element._ontouchstart = onStart;
  17692. element.addEventListener('touchstart', onStart, {passive: false});
  17693. }
  17694. function _clampFn(dx, dy, minDrag) {
  17695. if(Math.abs(dx) < minDrag) dx = 0;
  17696. if(Math.abs(dy) < minDrag) dy = 0;
  17697. return [dx, dy];
  17698. }
  17699. var clampFn = options.clampFn || _clampFn;
  17700. function onStart(e) {
  17701. e.preventDefault();
  17702. // make dragging and dragged into properties of gd
  17703. // so that others can look at and modify them
  17704. gd._dragged = false;
  17705. gd._dragging = true;
  17706. var offset = pointerOffset(e);
  17707. startX = offset[0];
  17708. startY = offset[1];
  17709. initialTarget = e.target;
  17710. initialEvent = e;
  17711. rightClick = e.buttons === 2 || e.ctrlKey;
  17712. // fix Fx.hover for touch events
  17713. if(typeof e.clientX === 'undefined' && typeof e.clientY === 'undefined') {
  17714. e.clientX = startX;
  17715. e.clientY = startY;
  17716. }
  17717. newMouseDownTime = (new Date()).getTime();
  17718. if(newMouseDownTime - gd._mouseDownTime < DBLCLICKDELAY) {
  17719. // in a click train
  17720. numClicks += 1;
  17721. }
  17722. else {
  17723. // new click train
  17724. numClicks = 1;
  17725. gd._mouseDownTime = newMouseDownTime;
  17726. }
  17727. if(options.prepFn) options.prepFn(e, startX, startY);
  17728. if(hasHover && !rightClick) {
  17729. dragCover = coverSlip();
  17730. dragCover.style.cursor = window.getComputedStyle(element).cursor;
  17731. }
  17732. else if(!hasHover) {
  17733. // document acts as a dragcover for mobile, bc we can't create dragcover dynamically
  17734. dragCover = document;
  17735. cursor = window.getComputedStyle(document.documentElement).cursor;
  17736. document.documentElement.style.cursor = window.getComputedStyle(element).cursor;
  17737. }
  17738. document.addEventListener('mousemove', onMove);
  17739. document.addEventListener('mouseup', onDone);
  17740. document.addEventListener('touchmove', onMove);
  17741. document.addEventListener('touchend', onDone);
  17742. return;
  17743. }
  17744. function onMove(e) {
  17745. e.preventDefault();
  17746. var offset = pointerOffset(e);
  17747. var minDrag = options.minDrag || constants.MINDRAG;
  17748. var dxdy = clampFn(offset[0] - startX, offset[1] - startY, minDrag);
  17749. var dx = dxdy[0];
  17750. var dy = dxdy[1];
  17751. if(dx || dy) {
  17752. gd._dragged = true;
  17753. dragElement.unhover(gd);
  17754. }
  17755. if(gd._dragged && options.moveFn && !rightClick) options.moveFn(dx, dy);
  17756. return;
  17757. }
  17758. function onDone(e) {
  17759. document.removeEventListener('mousemove', onMove);
  17760. document.removeEventListener('mouseup', onDone);
  17761. document.removeEventListener('touchmove', onMove);
  17762. document.removeEventListener('touchend', onDone);
  17763. e.preventDefault();
  17764. if(hasHover) {
  17765. Lib.removeElement(dragCover);
  17766. }
  17767. else if(cursor) {
  17768. dragCover.documentElement.style.cursor = cursor;
  17769. cursor = null;
  17770. }
  17771. if(!gd._dragging) {
  17772. gd._dragged = false;
  17773. return;
  17774. }
  17775. gd._dragging = false;
  17776. // don't count as a dblClick unless the mouseUp is also within
  17777. // the dblclick delay
  17778. if((new Date()).getTime() - gd._mouseDownTime > DBLCLICKDELAY) {
  17779. numClicks = Math.max(numClicks - 1, 1);
  17780. }
  17781. if(gd._dragged) {
  17782. if(options.doneFn) options.doneFn();
  17783. }
  17784. else {
  17785. if(options.clickFn) options.clickFn(numClicks, initialEvent);
  17786. // If we haven't dragged, this should be a click. But because of the
  17787. // coverSlip changing the element, the natural system might not generate one,
  17788. // so we need to make our own. But right clicks don't normally generate
  17789. // click events, only contextmenu events, which happen on mousedown.
  17790. if(!rightClick) {
  17791. var e2;
  17792. try {
  17793. e2 = new MouseEvent('click', e);
  17794. }
  17795. catch(err) {
  17796. var offset = pointerOffset(e);
  17797. e2 = document.createEvent('MouseEvents');
  17798. e2.initMouseEvent('click',
  17799. e.bubbles, e.cancelable,
  17800. e.view, e.detail,
  17801. e.screenX, e.screenY,
  17802. offset[0], offset[1],
  17803. e.ctrlKey, e.altKey, e.shiftKey, e.metaKey,
  17804. e.button, e.relatedTarget);
  17805. }
  17806. initialTarget.dispatchEvent(e2);
  17807. }
  17808. }
  17809. finishDrag(gd);
  17810. gd._dragged = false;
  17811. return;
  17812. }
  17813. };
  17814. function coverSlip() {
  17815. var cover = document.createElement('div');
  17816. cover.className = 'dragcover';
  17817. var cStyle = cover.style;
  17818. cStyle.position = 'fixed';
  17819. cStyle.left = 0;
  17820. cStyle.right = 0;
  17821. cStyle.top = 0;
  17822. cStyle.bottom = 0;
  17823. cStyle.zIndex = 999999999;
  17824. cStyle.background = 'none';
  17825. document.body.appendChild(cover);
  17826. return cover;
  17827. }
  17828. dragElement.coverSlip = coverSlip;
  17829. function finishDrag(gd) {
  17830. gd._dragging = false;
  17831. if(gd._replotPending) Registry.call('plot', gd);
  17832. }
  17833. function pointerOffset(e) {
  17834. return mouseOffset(
  17835. e.changedTouches ? e.changedTouches[0] : e,
  17836. document.body
  17837. );
  17838. }
  17839. },{"../../constants/interactions":150,"../../lib":169,"../../plots/cartesian/constants":219,"../../registry":259,"./align":70,"./cursor":71,"./unhover":73,"has-hover":20,"has-passive-events":21,"mouse-event-offset":23}],73:[function(_dereq_,module,exports){
  17840. /**
  17841. * Copyright 2012-2018, Plotly, Inc.
  17842. * All rights reserved.
  17843. *
  17844. * This source code is licensed under the MIT license found in the
  17845. * LICENSE file in the root directory of this source tree.
  17846. */
  17847. 'use strict';
  17848. var Events = _dereq_('../../lib/events');
  17849. var throttle = _dereq_('../../lib/throttle');
  17850. var getGraphDiv = _dereq_('../../lib/get_graph_div');
  17851. var hoverConstants = _dereq_('../fx/constants');
  17852. var unhover = module.exports = {};
  17853. unhover.wrapped = function(gd, evt, subplot) {
  17854. gd = getGraphDiv(gd);
  17855. // Important, clear any queued hovers
  17856. if(gd._fullLayout) {
  17857. throttle.clear(gd._fullLayout._uid + hoverConstants.HOVERID);
  17858. }
  17859. unhover.raw(gd, evt, subplot);
  17860. };
  17861. // remove hover effects on mouse out, and emit unhover event
  17862. unhover.raw = function unhoverRaw(gd, evt) {
  17863. var fullLayout = gd._fullLayout;
  17864. var oldhoverdata = gd._hoverdata;
  17865. if(!evt) evt = {};
  17866. if(evt.target &&
  17867. Events.triggerHandler(gd, 'plotly_beforehover', evt) === false) {
  17868. return;
  17869. }
  17870. fullLayout._hoverlayer.selectAll('g').remove();
  17871. fullLayout._hoverlayer.selectAll('line').remove();
  17872. fullLayout._hoverlayer.selectAll('circle').remove();
  17873. gd._hoverdata = undefined;
  17874. if(evt.target && oldhoverdata) {
  17875. gd.emit('plotly_unhover', {
  17876. event: evt,
  17877. points: oldhoverdata
  17878. });
  17879. }
  17880. };
  17881. },{"../../lib/events":162,"../../lib/get_graph_div":167,"../../lib/throttle":192,"../fx/constants":87}],74:[function(_dereq_,module,exports){
  17882. /**
  17883. * Copyright 2012-2018, Plotly, Inc.
  17884. * All rights reserved.
  17885. *
  17886. * This source code is licensed under the MIT license found in the
  17887. * LICENSE file in the root directory of this source tree.
  17888. */
  17889. 'use strict';
  17890. exports.dash = {
  17891. valType: 'string',
  17892. // string type usually doesn't take values... this one should really be
  17893. // a special type or at least a special coercion function, from the GUI
  17894. // you only get these values but elsewhere the user can supply a list of
  17895. // dash lengths in px, and it will be honored
  17896. values: ['solid', 'dot', 'dash', 'longdash', 'dashdot', 'longdashdot'],
  17897. dflt: 'solid',
  17898. editType: 'style',
  17899. };
  17900. },{}],75:[function(_dereq_,module,exports){
  17901. /**
  17902. * Copyright 2012-2018, Plotly, Inc.
  17903. * All rights reserved.
  17904. *
  17905. * This source code is licensed under the MIT license found in the
  17906. * LICENSE file in the root directory of this source tree.
  17907. */
  17908. 'use strict';
  17909. var d3 = _dereq_('d3');
  17910. var isNumeric = _dereq_('fast-isnumeric');
  17911. var tinycolor = _dereq_('tinycolor2');
  17912. var Registry = _dereq_('../../registry');
  17913. var Color = _dereq_('../color');
  17914. var Colorscale = _dereq_('../colorscale');
  17915. var Lib = _dereq_('../../lib');
  17916. var svgTextUtils = _dereq_('../../lib/svg_text_utils');
  17917. var xmlnsNamespaces = _dereq_('../../constants/xmlns_namespaces');
  17918. var alignment = _dereq_('../../constants/alignment');
  17919. var LINE_SPACING = alignment.LINE_SPACING;
  17920. var DESELECTDIM = _dereq_('../../constants/interactions').DESELECTDIM;
  17921. var subTypes = _dereq_('../../traces/scatter/subtypes');
  17922. var makeBubbleSizeFn = _dereq_('../../traces/scatter/make_bubble_size_func');
  17923. var drawing = module.exports = {};
  17924. // -----------------------------------------------------
  17925. // styling functions for plot elements
  17926. // -----------------------------------------------------
  17927. drawing.font = function(s, family, size, color) {
  17928. // also allow the form font(s, {family, size, color})
  17929. if(Lib.isPlainObject(family)) {
  17930. color = family.color;
  17931. size = family.size;
  17932. family = family.family;
  17933. }
  17934. if(family) s.style('font-family', family);
  17935. if(size + 1) s.style('font-size', size + 'px');
  17936. if(color) s.call(Color.fill, color);
  17937. };
  17938. /*
  17939. * Positioning helpers
  17940. * Note: do not use `setPosition` with <text> nodes modified by
  17941. * `svgTextUtils.convertToTspans`. Use `svgTextUtils.positionText`
  17942. * instead, so that <tspan.line> elements get updated to match.
  17943. */
  17944. drawing.setPosition = function(s, x, y) { s.attr('x', x).attr('y', y); };
  17945. drawing.setSize = function(s, w, h) { s.attr('width', w).attr('height', h); };
  17946. drawing.setRect = function(s, x, y, w, h) {
  17947. s.call(drawing.setPosition, x, y).call(drawing.setSize, w, h);
  17948. };
  17949. /** Translate node
  17950. *
  17951. * @param {object} d : calcdata point item
  17952. * @param {sel} sel : d3 selction of node to translate
  17953. * @param {object} xa : corresponding full xaxis object
  17954. * @param {object} ya : corresponding full yaxis object
  17955. *
  17956. * @return {boolean} :
  17957. * true if selection got translated
  17958. * false if selection could not get translated
  17959. */
  17960. drawing.translatePoint = function(d, sel, xa, ya) {
  17961. var x = xa.c2p(d.x);
  17962. var y = ya.c2p(d.y);
  17963. if(isNumeric(x) && isNumeric(y) && sel.node()) {
  17964. // for multiline text this works better
  17965. if(sel.node().nodeName === 'text') {
  17966. sel.attr('x', x).attr('y', y);
  17967. } else {
  17968. sel.attr('transform', 'translate(' + x + ',' + y + ')');
  17969. }
  17970. } else {
  17971. return false;
  17972. }
  17973. return true;
  17974. };
  17975. drawing.translatePoints = function(s, xa, ya) {
  17976. s.each(function(d) {
  17977. var sel = d3.select(this);
  17978. drawing.translatePoint(d, sel, xa, ya);
  17979. });
  17980. };
  17981. drawing.hideOutsideRangePoint = function(d, sel, xa, ya, xcalendar, ycalendar) {
  17982. sel.attr(
  17983. 'display',
  17984. (xa.isPtWithinRange(d, xcalendar) && ya.isPtWithinRange(d, ycalendar)) ? null : 'none'
  17985. );
  17986. };
  17987. drawing.hideOutsideRangePoints = function(traceGroups, subplot) {
  17988. if(!subplot._hasClipOnAxisFalse) return;
  17989. var xa = subplot.xaxis;
  17990. var ya = subplot.yaxis;
  17991. traceGroups.each(function(d) {
  17992. var trace = d[0].trace;
  17993. var xcalendar = trace.xcalendar;
  17994. var ycalendar = trace.ycalendar;
  17995. var selector = trace.type === 'bar' ? '.bartext' : '.point,.textpoint';
  17996. traceGroups.selectAll(selector).each(function(d) {
  17997. drawing.hideOutsideRangePoint(d, d3.select(this), xa, ya, xcalendar, ycalendar);
  17998. });
  17999. });
  18000. };
  18001. drawing.crispRound = function(gd, lineWidth, dflt) {
  18002. // for lines that disable antialiasing we want to
  18003. // make sure the width is an integer, and at least 1 if it's nonzero
  18004. if(!lineWidth || !isNumeric(lineWidth)) return dflt || 0;
  18005. // but not for static plots - these don't get antialiased anyway.
  18006. if(gd._context.staticPlot) return lineWidth;
  18007. if(lineWidth < 1) return 1;
  18008. return Math.round(lineWidth);
  18009. };
  18010. drawing.singleLineStyle = function(d, s, lw, lc, ld) {
  18011. s.style('fill', 'none');
  18012. var line = (((d || [])[0] || {}).trace || {}).line || {},
  18013. lw1 = lw || line.width||0,
  18014. dash = ld || line.dash || '';
  18015. Color.stroke(s, lc || line.color);
  18016. drawing.dashLine(s, dash, lw1);
  18017. };
  18018. drawing.lineGroupStyle = function(s, lw, lc, ld) {
  18019. s.style('fill', 'none')
  18020. .each(function(d) {
  18021. var line = (((d || [])[0] || {}).trace || {}).line || {},
  18022. lw1 = lw || line.width||0,
  18023. dash = ld || line.dash || '';
  18024. d3.select(this)
  18025. .call(Color.stroke, lc || line.color)
  18026. .call(drawing.dashLine, dash, lw1);
  18027. });
  18028. };
  18029. drawing.dashLine = function(s, dash, lineWidth) {
  18030. lineWidth = +lineWidth || 0;
  18031. dash = drawing.dashStyle(dash, lineWidth);
  18032. s.style({
  18033. 'stroke-dasharray': dash,
  18034. 'stroke-width': lineWidth + 'px'
  18035. });
  18036. };
  18037. drawing.dashStyle = function(dash, lineWidth) {
  18038. lineWidth = +lineWidth || 1;
  18039. var dlw = Math.max(lineWidth, 3);
  18040. if(dash === 'solid') dash = '';
  18041. else if(dash === 'dot') dash = dlw + 'px,' + dlw + 'px';
  18042. else if(dash === 'dash') dash = (3 * dlw) + 'px,' + (3 * dlw) + 'px';
  18043. else if(dash === 'longdash') dash = (5 * dlw) + 'px,' + (5 * dlw) + 'px';
  18044. else if(dash === 'dashdot') {
  18045. dash = (3 * dlw) + 'px,' + dlw + 'px,' + dlw + 'px,' + dlw + 'px';
  18046. }
  18047. else if(dash === 'longdashdot') {
  18048. dash = (5 * dlw) + 'px,' + (2 * dlw) + 'px,' + dlw + 'px,' + (2 * dlw) + 'px';
  18049. }
  18050. // otherwise user wrote the dasharray themselves - leave it be
  18051. return dash;
  18052. };
  18053. // Same as fillGroupStyle, except in this case the selection may be a transition
  18054. drawing.singleFillStyle = function(sel) {
  18055. var node = d3.select(sel.node());
  18056. var data = node.data();
  18057. var fillcolor = (((data[0] || [])[0] || {}).trace || {}).fillcolor;
  18058. if(fillcolor) {
  18059. sel.call(Color.fill, fillcolor);
  18060. }
  18061. };
  18062. drawing.fillGroupStyle = function(s) {
  18063. s.style('stroke-width', 0)
  18064. .each(function(d) {
  18065. var shape = d3.select(this);
  18066. try {
  18067. shape.call(Color.fill, d[0].trace.fillcolor);
  18068. }
  18069. catch(e) {
  18070. Lib.error(e, s);
  18071. shape.remove();
  18072. }
  18073. });
  18074. };
  18075. var SYMBOLDEFS = _dereq_('./symbol_defs');
  18076. drawing.symbolNames = [];
  18077. drawing.symbolFuncs = [];
  18078. drawing.symbolNeedLines = {};
  18079. drawing.symbolNoDot = {};
  18080. drawing.symbolNoFill = {};
  18081. drawing.symbolList = [];
  18082. Object.keys(SYMBOLDEFS).forEach(function(k) {
  18083. var symDef = SYMBOLDEFS[k];
  18084. drawing.symbolList = drawing.symbolList.concat(
  18085. [symDef.n, k, symDef.n + 100, k + '-open']);
  18086. drawing.symbolNames[symDef.n] = k;
  18087. drawing.symbolFuncs[symDef.n] = symDef.f;
  18088. if(symDef.needLine) {
  18089. drawing.symbolNeedLines[symDef.n] = true;
  18090. }
  18091. if(symDef.noDot) {
  18092. drawing.symbolNoDot[symDef.n] = true;
  18093. }
  18094. else {
  18095. drawing.symbolList = drawing.symbolList.concat(
  18096. [symDef.n + 200, k + '-dot', symDef.n + 300, k + '-open-dot']);
  18097. }
  18098. if(symDef.noFill) {
  18099. drawing.symbolNoFill[symDef.n] = true;
  18100. }
  18101. });
  18102. var MAXSYMBOL = drawing.symbolNames.length,
  18103. // add a dot in the middle of the symbol
  18104. DOTPATH = 'M0,0.5L0.5,0L0,-0.5L-0.5,0Z';
  18105. drawing.symbolNumber = function(v) {
  18106. if(typeof v === 'string') {
  18107. var vbase = 0;
  18108. if(v.indexOf('-open') > 0) {
  18109. vbase = 100;
  18110. v = v.replace('-open', '');
  18111. }
  18112. if(v.indexOf('-dot') > 0) {
  18113. vbase += 200;
  18114. v = v.replace('-dot', '');
  18115. }
  18116. v = drawing.symbolNames.indexOf(v);
  18117. if(v >= 0) { v += vbase; }
  18118. }
  18119. if((v % 100 >= MAXSYMBOL) || v >= 400) { return 0; }
  18120. return Math.floor(Math.max(v, 0));
  18121. };
  18122. function makePointPath(symbolNumber, r) {
  18123. var base = symbolNumber % 100;
  18124. return drawing.symbolFuncs[base](r) + (symbolNumber >= 200 ? DOTPATH : '');
  18125. }
  18126. var HORZGRADIENT = {x1: 1, x2: 0, y1: 0, y2: 0};
  18127. var VERTGRADIENT = {x1: 0, x2: 0, y1: 1, y2: 0};
  18128. var stopFormatter = d3.format('~.1f');
  18129. var gradientInfo = {
  18130. radial: {node: 'radialGradient'},
  18131. radialreversed: {node: 'radialGradient', reversed: true},
  18132. horizontal: {node: 'linearGradient', attrs: HORZGRADIENT},
  18133. horizontalreversed: {node: 'linearGradient', attrs: HORZGRADIENT, reversed: true},
  18134. vertical: {node: 'linearGradient', attrs: VERTGRADIENT},
  18135. verticalreversed: {node: 'linearGradient', attrs: VERTGRADIENT, reversed: true}
  18136. };
  18137. /**
  18138. * gradient: create and apply a gradient fill
  18139. *
  18140. * @param {object} sel: d3 selection to apply this gradient to
  18141. * You can use `selection.call(Drawing.gradient, ...)`
  18142. * @param {DOM element} gd: the graph div `sel` is part of
  18143. * @param {string} gradientID: a unique (within this plot) identifier
  18144. * for this gradient, so that we don't create unnecessary definitions
  18145. * @param {string} type: 'radial', 'horizontal', or 'vertical', optionally with
  18146. * 'reversed' at the end. Normally radial goes center to edge,
  18147. * horizontal goes right to left, and vertical goes bottom to top
  18148. * @param {array} colorscale: as in attribute values, [[fraction, color], ...]
  18149. * @param {string} prop: the property to apply to, 'fill' or 'stroke'
  18150. */
  18151. drawing.gradient = function(sel, gd, gradientID, type, colorscale, prop) {
  18152. var len = colorscale.length;
  18153. var info = gradientInfo[type];
  18154. var colorStops = new Array(len);
  18155. for(var i = 0; i < len; i++) {
  18156. if(info.reversed) {
  18157. colorStops[len - 1 - i] = [stopFormatter((1 - colorscale[i][0]) * 100), colorscale[i][1]];
  18158. }
  18159. else {
  18160. colorStops[i] = [stopFormatter(colorscale[i][0] * 100), colorscale[i][1]];
  18161. }
  18162. }
  18163. var fullID = 'g' + gd._fullLayout._uid + '-' + gradientID;
  18164. var gradient = gd._fullLayout._defs.select('.gradients')
  18165. .selectAll('#' + fullID)
  18166. .data([type + colorStops.join(';')], Lib.identity);
  18167. gradient.exit().remove();
  18168. gradient.enter()
  18169. .append(info.node)
  18170. .each(function() {
  18171. var el = d3.select(this);
  18172. if(info.attrs) el.attr(info.attrs);
  18173. el.attr('id', fullID);
  18174. var stops = el.selectAll('stop')
  18175. .data(colorStops);
  18176. stops.exit().remove();
  18177. stops.enter().append('stop');
  18178. stops.each(function(d) {
  18179. var tc = tinycolor(d[1]);
  18180. d3.select(this).attr({
  18181. offset: d[0] + '%',
  18182. 'stop-color': Color.tinyRGB(tc),
  18183. 'stop-opacity': tc.getAlpha()
  18184. });
  18185. });
  18186. });
  18187. sel.style(prop, 'url(#' + fullID + ')')
  18188. .style(prop + '-opacity', null);
  18189. };
  18190. /*
  18191. * Make the gradients container and clear out any previous gradients.
  18192. * We never collect all the gradients we need in one place,
  18193. * so we can't ever remove gradients that have stopped being useful,
  18194. * except all at once before a full redraw.
  18195. * The upside of this is arbitrary points can share gradient defs
  18196. */
  18197. drawing.initGradients = function(gd) {
  18198. var gradientsGroup = Lib.ensureSingle(gd._fullLayout._defs, 'g', 'gradients');
  18199. gradientsGroup.selectAll('linearGradient,radialGradient').remove();
  18200. };
  18201. drawing.pointStyle = function(s, trace, gd) {
  18202. if(!s.size()) return;
  18203. var fns = drawing.makePointStyleFns(trace);
  18204. s.each(function(d) {
  18205. drawing.singlePointStyle(d, d3.select(this), trace, fns, gd);
  18206. });
  18207. };
  18208. drawing.singlePointStyle = function(d, sel, trace, fns, gd) {
  18209. var marker = trace.marker;
  18210. var markerLine = marker.line;
  18211. sel.style('opacity',
  18212. fns.selectedOpacityFn ? fns.selectedOpacityFn(d) :
  18213. (d.mo === undefined ? marker.opacity : d.mo)
  18214. );
  18215. if(fns.ms2mrc) {
  18216. var r;
  18217. // handle multi-trace graph edit case
  18218. if(d.ms === 'various' || marker.size === 'various') {
  18219. r = 3;
  18220. } else {
  18221. r = fns.ms2mrc(d.ms);
  18222. }
  18223. // store the calculated size so hover can use it
  18224. d.mrc = r;
  18225. if(fns.selectedSizeFn) {
  18226. r = d.mrc = fns.selectedSizeFn(d);
  18227. }
  18228. // turn the symbol into a sanitized number
  18229. var x = drawing.symbolNumber(d.mx || marker.symbol) || 0;
  18230. // save if this marker is open
  18231. // because that impacts how to handle colors
  18232. d.om = x % 200 >= 100;
  18233. sel.attr('d', makePointPath(x, r));
  18234. }
  18235. var perPointGradient = false;
  18236. var fillColor, lineColor, lineWidth;
  18237. // 'so' is suspected outliers, for box plots
  18238. if(d.so) {
  18239. lineWidth = markerLine.outlierwidth;
  18240. lineColor = markerLine.outliercolor;
  18241. fillColor = marker.outliercolor;
  18242. } else {
  18243. var markerLineWidth = (markerLine || {}).width;
  18244. lineWidth = (
  18245. d.mlw + 1 ||
  18246. markerLineWidth + 1 ||
  18247. // TODO: we need the latter for legends... can we get rid of it?
  18248. (d.trace ? (d.trace.marker.line || {}).width : 0) + 1
  18249. ) - 1 || 0;
  18250. if('mlc' in d) lineColor = d.mlcc = fns.lineScale(d.mlc);
  18251. // weird case: array wasn't long enough to apply to every point
  18252. else if(Lib.isArrayOrTypedArray(markerLine.color)) lineColor = Color.defaultLine;
  18253. else lineColor = markerLine.color;
  18254. if(Lib.isArrayOrTypedArray(marker.color)) {
  18255. fillColor = Color.defaultLine;
  18256. perPointGradient = true;
  18257. }
  18258. if('mc' in d) {
  18259. fillColor = d.mcc = fns.markerScale(d.mc);
  18260. } else {
  18261. fillColor = marker.color || 'rgba(0,0,0,0)';
  18262. }
  18263. if(fns.selectedColorFn) {
  18264. fillColor = fns.selectedColorFn(d);
  18265. }
  18266. }
  18267. if(d.om) {
  18268. // open markers can't have zero linewidth, default to 1px,
  18269. // and use fill color as stroke color
  18270. sel.call(Color.stroke, fillColor)
  18271. .style({
  18272. 'stroke-width': (lineWidth || 1) + 'px',
  18273. fill: 'none'
  18274. });
  18275. } else {
  18276. sel.style('stroke-width', lineWidth + 'px');
  18277. var markerGradient = marker.gradient;
  18278. var gradientType = d.mgt;
  18279. if(gradientType) perPointGradient = true;
  18280. else gradientType = markerGradient && markerGradient.type;
  18281. // for legend - arrays will propagate through here, but we don't need
  18282. // to treat it as per-point.
  18283. if(Array.isArray(gradientType)) {
  18284. gradientType = gradientType[0];
  18285. if(!gradientInfo[gradientType]) gradientType = 0;
  18286. }
  18287. if(gradientType && gradientType !== 'none') {
  18288. var gradientColor = d.mgc;
  18289. if(gradientColor) perPointGradient = true;
  18290. else gradientColor = markerGradient.color;
  18291. var gradientID = trace.uid;
  18292. if(perPointGradient) gradientID += '-' + d.i;
  18293. drawing.gradient(sel, gd, gradientID, gradientType,
  18294. [[0, gradientColor], [1, fillColor]], 'fill');
  18295. } else {
  18296. Color.fill(sel, fillColor);
  18297. }
  18298. if(lineWidth) {
  18299. Color.stroke(sel, lineColor);
  18300. }
  18301. }
  18302. };
  18303. drawing.makePointStyleFns = function(trace) {
  18304. var out = {};
  18305. var marker = trace.marker;
  18306. // allow array marker and marker line colors to be
  18307. // scaled by given max and min to colorscales
  18308. out.markerScale = drawing.tryColorscale(marker, '');
  18309. out.lineScale = drawing.tryColorscale(marker, 'line');
  18310. if(Registry.traceIs(trace, 'symbols')) {
  18311. out.ms2mrc = subTypes.isBubble(trace) ?
  18312. makeBubbleSizeFn(trace) :
  18313. function() { return (marker.size || 6) / 2; };
  18314. }
  18315. if(trace.selectedpoints) {
  18316. Lib.extendFlat(out, drawing.makeSelectedPointStyleFns(trace));
  18317. }
  18318. return out;
  18319. };
  18320. drawing.makeSelectedPointStyleFns = function(trace) {
  18321. var out = {};
  18322. var selectedAttrs = trace.selected || {};
  18323. var unselectedAttrs = trace.unselected || {};
  18324. var marker = trace.marker || {};
  18325. var selectedMarker = selectedAttrs.marker || {};
  18326. var unselectedMarker = unselectedAttrs.marker || {};
  18327. var mo = marker.opacity;
  18328. var smo = selectedMarker.opacity;
  18329. var usmo = unselectedMarker.opacity;
  18330. var smoIsDefined = smo !== undefined;
  18331. var usmoIsDefined = usmo !== undefined;
  18332. if(Lib.isArrayOrTypedArray(mo) || smoIsDefined || usmoIsDefined) {
  18333. out.selectedOpacityFn = function(d) {
  18334. var base = d.mo === undefined ? marker.opacity : d.mo;
  18335. if(d.selected) {
  18336. return smoIsDefined ? smo : base;
  18337. } else {
  18338. return usmoIsDefined ? usmo : DESELECTDIM * base;
  18339. }
  18340. };
  18341. }
  18342. var mc = marker.color;
  18343. var smc = selectedMarker.color;
  18344. var usmc = unselectedMarker.color;
  18345. if(smc || usmc) {
  18346. out.selectedColorFn = function(d) {
  18347. var base = d.mcc || mc;
  18348. if(d.selected) {
  18349. return smc || base;
  18350. } else {
  18351. return usmc || base;
  18352. }
  18353. };
  18354. }
  18355. var ms = marker.size;
  18356. var sms = selectedMarker.size;
  18357. var usms = unselectedMarker.size;
  18358. var smsIsDefined = sms !== undefined;
  18359. var usmsIsDefined = usms !== undefined;
  18360. if(Registry.traceIs(trace, 'symbols') && (smsIsDefined || usmsIsDefined)) {
  18361. out.selectedSizeFn = function(d) {
  18362. var base = d.mrc || ms / 2;
  18363. if(d.selected) {
  18364. return smsIsDefined ? sms / 2 : base;
  18365. } else {
  18366. return usmsIsDefined ? usms / 2 : base;
  18367. }
  18368. };
  18369. }
  18370. return out;
  18371. };
  18372. drawing.makeSelectedTextStyleFns = function(trace) {
  18373. var out = {};
  18374. var selectedAttrs = trace.selected || {};
  18375. var unselectedAttrs = trace.unselected || {};
  18376. var textFont = trace.textfont || {};
  18377. var selectedTextFont = selectedAttrs.textfont || {};
  18378. var unselectedTextFont = unselectedAttrs.textfont || {};
  18379. var tc = textFont.color;
  18380. var stc = selectedTextFont.color;
  18381. var utc = unselectedTextFont.color;
  18382. out.selectedTextColorFn = function(d) {
  18383. var base = d.tc || tc;
  18384. if(d.selected) {
  18385. return stc || base;
  18386. } else {
  18387. if(utc) return utc;
  18388. else return stc ? base : Color.addOpacity(base, DESELECTDIM);
  18389. }
  18390. };
  18391. return out;
  18392. };
  18393. drawing.selectedPointStyle = function(s, trace) {
  18394. if(!s.size() || !trace.selectedpoints) return;
  18395. var fns = drawing.makeSelectedPointStyleFns(trace);
  18396. var marker = trace.marker || {};
  18397. var seq = [];
  18398. if(fns.selectedOpacityFn) {
  18399. seq.push(function(pt, d) {
  18400. pt.style('opacity', fns.selectedOpacityFn(d));
  18401. });
  18402. }
  18403. if(fns.selectedColorFn) {
  18404. seq.push(function(pt, d) {
  18405. Color.fill(pt, fns.selectedColorFn(d));
  18406. });
  18407. }
  18408. if(fns.selectedSizeFn) {
  18409. seq.push(function(pt, d) {
  18410. var mx = d.mx || marker.symbol || 0;
  18411. var mrc2 = fns.selectedSizeFn(d);
  18412. pt.attr('d', makePointPath(drawing.symbolNumber(mx), mrc2));
  18413. // save for Drawing.selectedTextStyle
  18414. d.mrc2 = mrc2;
  18415. });
  18416. }
  18417. if(seq.length) {
  18418. s.each(function(d) {
  18419. var pt = d3.select(this);
  18420. for(var i = 0; i < seq.length; i++) {
  18421. seq[i](pt, d);
  18422. }
  18423. });
  18424. }
  18425. };
  18426. drawing.tryColorscale = function(marker, prefix) {
  18427. var cont = prefix ? Lib.nestedProperty(marker, prefix).get() : marker;
  18428. if(cont) {
  18429. var scl = cont.colorscale;
  18430. var colorArray = cont.color;
  18431. if(scl && Lib.isArrayOrTypedArray(colorArray)) {
  18432. return Colorscale.makeColorScaleFunc(
  18433. Colorscale.extractScale(scl, cont.cmin, cont.cmax)
  18434. );
  18435. }
  18436. }
  18437. return Lib.identity;
  18438. };
  18439. var TEXTOFFSETSIGN = {
  18440. start: 1, end: -1, middle: 0, bottom: 1, top: -1
  18441. };
  18442. function textPointPosition(s, textPosition, fontSize, markerRadius) {
  18443. var group = d3.select(s.node().parentNode);
  18444. var v = textPosition.indexOf('top') !== -1 ?
  18445. 'top' :
  18446. textPosition.indexOf('bottom') !== -1 ? 'bottom' : 'middle';
  18447. var h = textPosition.indexOf('left') !== -1 ?
  18448. 'end' :
  18449. textPosition.indexOf('right') !== -1 ? 'start' : 'middle';
  18450. // if markers are shown, offset a little more than
  18451. // the nominal marker size
  18452. // ie 2/1.6 * nominal, bcs some markers are a bit bigger
  18453. var r = markerRadius ? markerRadius / 0.8 + 1 : 0;
  18454. var numLines = (svgTextUtils.lineCount(s) - 1) * LINE_SPACING + 1;
  18455. var dx = TEXTOFFSETSIGN[h] * r;
  18456. var dy = fontSize * 0.75 + TEXTOFFSETSIGN[v] * r +
  18457. (TEXTOFFSETSIGN[v] - 1) * numLines * fontSize / 2;
  18458. // fix the overall text group position
  18459. s.attr('text-anchor', h);
  18460. group.attr('transform', 'translate(' + dx + ',' + dy + ')');
  18461. }
  18462. function extracTextFontSize(d, trace) {
  18463. var fontSize = d.ts || trace.textfont.size;
  18464. return (isNumeric(fontSize) && fontSize > 0) ? fontSize : 0;
  18465. }
  18466. // draw text at points
  18467. drawing.textPointStyle = function(s, trace, gd) {
  18468. if(!s.size()) return;
  18469. var selectedTextColorFn;
  18470. if(trace.selectedpoints) {
  18471. var fns = drawing.makeSelectedTextStyleFns(trace);
  18472. selectedTextColorFn = fns.selectedTextColorFn;
  18473. }
  18474. s.each(function(d) {
  18475. var p = d3.select(this);
  18476. var text = Lib.extractOption(d, trace, 'tx', 'text');
  18477. if(!text && text !== 0) {
  18478. p.remove();
  18479. return;
  18480. }
  18481. var pos = d.tp || trace.textposition;
  18482. var fontSize = extracTextFontSize(d, trace);
  18483. var fontColor = selectedTextColorFn ?
  18484. selectedTextColorFn(d) :
  18485. (d.tc || trace.textfont.color);
  18486. p.call(drawing.font,
  18487. d.tf || trace.textfont.family,
  18488. fontSize,
  18489. fontColor)
  18490. .text(text)
  18491. .call(svgTextUtils.convertToTspans, gd)
  18492. .call(textPointPosition, pos, fontSize, d.mrc);
  18493. });
  18494. };
  18495. drawing.selectedTextStyle = function(s, trace) {
  18496. if(!s.size() || !trace.selectedpoints) return;
  18497. var fns = drawing.makeSelectedTextStyleFns(trace);
  18498. s.each(function(d) {
  18499. var tx = d3.select(this);
  18500. var tc = fns.selectedTextColorFn(d);
  18501. var tp = d.tp || trace.textposition;
  18502. var fontSize = extracTextFontSize(d, trace);
  18503. Color.fill(tx, tc);
  18504. textPointPosition(tx, tp, fontSize, d.mrc2 || d.mrc);
  18505. });
  18506. };
  18507. // generalized Catmull-Rom splines, per
  18508. // http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf
  18509. var CatmullRomExp = 0.5;
  18510. drawing.smoothopen = function(pts, smoothness) {
  18511. if(pts.length < 3) { return 'M' + pts.join('L');}
  18512. var path = 'M' + pts[0],
  18513. tangents = [], i;
  18514. for(i = 1; i < pts.length - 1; i++) {
  18515. tangents.push(makeTangent(pts[i - 1], pts[i], pts[i + 1], smoothness));
  18516. }
  18517. path += 'Q' + tangents[0][0] + ' ' + pts[1];
  18518. for(i = 2; i < pts.length - 1; i++) {
  18519. path += 'C' + tangents[i - 2][1] + ' ' + tangents[i - 1][0] + ' ' + pts[i];
  18520. }
  18521. path += 'Q' + tangents[pts.length - 3][1] + ' ' + pts[pts.length - 1];
  18522. return path;
  18523. };
  18524. drawing.smoothclosed = function(pts, smoothness) {
  18525. if(pts.length < 3) { return 'M' + pts.join('L') + 'Z'; }
  18526. var path = 'M' + pts[0],
  18527. pLast = pts.length - 1,
  18528. tangents = [makeTangent(pts[pLast],
  18529. pts[0], pts[1], smoothness)],
  18530. i;
  18531. for(i = 1; i < pLast; i++) {
  18532. tangents.push(makeTangent(pts[i - 1], pts[i], pts[i + 1], smoothness));
  18533. }
  18534. tangents.push(
  18535. makeTangent(pts[pLast - 1], pts[pLast], pts[0], smoothness)
  18536. );
  18537. for(i = 1; i <= pLast; i++) {
  18538. path += 'C' + tangents[i - 1][1] + ' ' + tangents[i][0] + ' ' + pts[i];
  18539. }
  18540. path += 'C' + tangents[pLast][1] + ' ' + tangents[0][0] + ' ' + pts[0] + 'Z';
  18541. return path;
  18542. };
  18543. function makeTangent(prevpt, thispt, nextpt, smoothness) {
  18544. var d1x = prevpt[0] - thispt[0],
  18545. d1y = prevpt[1] - thispt[1],
  18546. d2x = nextpt[0] - thispt[0],
  18547. d2y = nextpt[1] - thispt[1],
  18548. d1a = Math.pow(d1x * d1x + d1y * d1y, CatmullRomExp / 2),
  18549. d2a = Math.pow(d2x * d2x + d2y * d2y, CatmullRomExp / 2),
  18550. numx = (d2a * d2a * d1x - d1a * d1a * d2x) * smoothness,
  18551. numy = (d2a * d2a * d1y - d1a * d1a * d2y) * smoothness,
  18552. denom1 = 3 * d2a * (d1a + d2a),
  18553. denom2 = 3 * d1a * (d1a + d2a);
  18554. return [
  18555. [
  18556. d3.round(thispt[0] + (denom1 && numx / denom1), 2),
  18557. d3.round(thispt[1] + (denom1 && numy / denom1), 2)
  18558. ], [
  18559. d3.round(thispt[0] - (denom2 && numx / denom2), 2),
  18560. d3.round(thispt[1] - (denom2 && numy / denom2), 2)
  18561. ]
  18562. ];
  18563. }
  18564. // step paths - returns a generator function for paths
  18565. // with the given step shape
  18566. var STEPPATH = {
  18567. hv: function(p0, p1) {
  18568. return 'H' + d3.round(p1[0], 2) + 'V' + d3.round(p1[1], 2);
  18569. },
  18570. vh: function(p0, p1) {
  18571. return 'V' + d3.round(p1[1], 2) + 'H' + d3.round(p1[0], 2);
  18572. },
  18573. hvh: function(p0, p1) {
  18574. return 'H' + d3.round((p0[0] + p1[0]) / 2, 2) + 'V' +
  18575. d3.round(p1[1], 2) + 'H' + d3.round(p1[0], 2);
  18576. },
  18577. vhv: function(p0, p1) {
  18578. return 'V' + d3.round((p0[1] + p1[1]) / 2, 2) + 'H' +
  18579. d3.round(p1[0], 2) + 'V' + d3.round(p1[1], 2);
  18580. }
  18581. };
  18582. var STEPLINEAR = function(p0, p1) {
  18583. return 'L' + d3.round(p1[0], 2) + ',' + d3.round(p1[1], 2);
  18584. };
  18585. drawing.steps = function(shape) {
  18586. var onestep = STEPPATH[shape] || STEPLINEAR;
  18587. return function(pts) {
  18588. var path = 'M' + d3.round(pts[0][0], 2) + ',' + d3.round(pts[0][1], 2);
  18589. for(var i = 1; i < pts.length; i++) {
  18590. path += onestep(pts[i - 1], pts[i]);
  18591. }
  18592. return path;
  18593. };
  18594. };
  18595. // off-screen svg render testing element, shared by the whole page
  18596. // uses the id 'js-plotly-tester' and stores it in drawing.tester
  18597. drawing.makeTester = function() {
  18598. var tester = Lib.ensureSingleById(d3.select('body'), 'svg', 'js-plotly-tester', function(s) {
  18599. s.attr(xmlnsNamespaces.svgAttrs)
  18600. .style({
  18601. position: 'absolute',
  18602. left: '-10000px',
  18603. top: '-10000px',
  18604. width: '9000px',
  18605. height: '9000px',
  18606. 'z-index': '1'
  18607. });
  18608. });
  18609. // browsers differ on how they describe the bounding rect of
  18610. // the svg if its contents spill over... so make a 1x1px
  18611. // reference point we can measure off of.
  18612. var testref = Lib.ensureSingle(tester, 'path', 'js-reference-point', function(s) {
  18613. s.attr('d', 'M0,0H1V1H0Z')
  18614. .style({
  18615. 'stroke-width': 0,
  18616. fill: 'black'
  18617. });
  18618. });
  18619. drawing.tester = tester;
  18620. drawing.testref = testref;
  18621. };
  18622. /*
  18623. * use our offscreen tester to get a clientRect for an element,
  18624. * in a reference frame where it isn't translated (or transformed) and
  18625. * its anchor point is at (0,0)
  18626. * always returns a copy of the bbox, so the caller can modify it safely
  18627. *
  18628. * @param {SVGElement} node: the element to measure. If possible this should be
  18629. * a <text> or MathJax <g> element that's already passed through
  18630. * `convertToTspans` because in that case we can cache the results, but it's
  18631. * possible to pass in any svg element.
  18632. *
  18633. * @param {boolean} inTester: is this element already in `drawing.tester`?
  18634. * If you are measuring a dummy element, rather than one you really intend
  18635. * to use on the plot, making it in `drawing.tester` in the first place
  18636. * allows us to test faster because it cuts out cloning and appending it.
  18637. *
  18638. * @param {string} hash: for internal use only, if we already know the cache key
  18639. * for this element beforehand.
  18640. *
  18641. * @return {object}: a plain object containing the width, height, left, right,
  18642. * top, and bottom of `node`
  18643. */
  18644. drawing.savedBBoxes = {};
  18645. var savedBBoxesCount = 0;
  18646. var maxSavedBBoxes = 10000;
  18647. drawing.bBox = function(node, inTester, hash) {
  18648. /*
  18649. * Cache elements we've already measured so we don't have to
  18650. * remeasure the same thing many times
  18651. * We have a few bBox callers though who pass a node larger than
  18652. * a <text> or a MathJax <g>, such as an axis group containing many labels.
  18653. * These will not generate a hash (unless we figure out an appropriate
  18654. * hash key for them) and thus we will not hash them.
  18655. */
  18656. if(!hash) hash = nodeHash(node);
  18657. var out;
  18658. if(hash) {
  18659. out = drawing.savedBBoxes[hash];
  18660. if(out) return Lib.extendFlat({}, out);
  18661. }
  18662. else if(node.childNodes.length === 1) {
  18663. /*
  18664. * If we have only one child element, which is itself hashable, make
  18665. * a new hash from this element plus its x,y,transform
  18666. * These bounding boxes *include* x,y,transform - mostly for use by
  18667. * callers trying to avoid overlaps (ie titles)
  18668. */
  18669. var innerNode = node.childNodes[0];
  18670. hash = nodeHash(innerNode);
  18671. if(hash) {
  18672. var x = +innerNode.getAttribute('x') || 0;
  18673. var y = +innerNode.getAttribute('y') || 0;
  18674. var transform = innerNode.getAttribute('transform');
  18675. if(!transform) {
  18676. // in this case, just varying x and y, don't bother caching
  18677. // the final bBox because the alteration is quick.
  18678. var innerBB = drawing.bBox(innerNode, false, hash);
  18679. if(x) {
  18680. innerBB.left += x;
  18681. innerBB.right += x;
  18682. }
  18683. if(y) {
  18684. innerBB.top += y;
  18685. innerBB.bottom += y;
  18686. }
  18687. return innerBB;
  18688. }
  18689. /*
  18690. * else we have a transform - rather than make a complicated
  18691. * (and error-prone and probably slow) transform parser/calculator,
  18692. * just continue on calculating the boundingClientRect of the group
  18693. * and use the new composite hash to cache it.
  18694. * That said, `innerNode.transform.baseVal` is an array of
  18695. * `SVGTransform` objects, that *do* seem to have a nice matrix
  18696. * multiplication interface that we could use to avoid making
  18697. * another getBoundingClientRect call...
  18698. */
  18699. hash += '~' + x + '~' + y + '~' + transform;
  18700. out = drawing.savedBBoxes[hash];
  18701. if(out) return Lib.extendFlat({}, out);
  18702. }
  18703. }
  18704. var testNode, tester;
  18705. if(inTester) {
  18706. testNode = node;
  18707. }
  18708. else {
  18709. tester = drawing.tester.node();
  18710. // copy the node to test into the tester
  18711. testNode = node.cloneNode(true);
  18712. tester.appendChild(testNode);
  18713. }
  18714. // standardize its position (and newline tspans if any)
  18715. d3.select(testNode)
  18716. .attr('transform', null)
  18717. .call(svgTextUtils.positionText, 0, 0);
  18718. var testRect = testNode.getBoundingClientRect();
  18719. var refRect = drawing.testref
  18720. .node()
  18721. .getBoundingClientRect();
  18722. if(!inTester) tester.removeChild(testNode);
  18723. var bb = {
  18724. height: testRect.height,
  18725. width: testRect.width,
  18726. left: testRect.left - refRect.left,
  18727. top: testRect.top - refRect.top,
  18728. right: testRect.right - refRect.left,
  18729. bottom: testRect.bottom - refRect.top
  18730. };
  18731. // make sure we don't have too many saved boxes,
  18732. // or a long session could overload on memory
  18733. // by saving boxes for long-gone elements
  18734. if(savedBBoxesCount >= maxSavedBBoxes) {
  18735. drawing.savedBBoxes = {};
  18736. savedBBoxesCount = 0;
  18737. }
  18738. // cache this bbox
  18739. if(hash) drawing.savedBBoxes[hash] = bb;
  18740. savedBBoxesCount++;
  18741. return Lib.extendFlat({}, bb);
  18742. };
  18743. // capture everything about a node (at least in our usage) that
  18744. // impacts its bounding box, given that bBox clears x, y, and transform
  18745. function nodeHash(node) {
  18746. var inputText = node.getAttribute('data-unformatted');
  18747. if(inputText === null) return;
  18748. return inputText +
  18749. node.getAttribute('data-math') +
  18750. node.getAttribute('text-anchor') +
  18751. node.getAttribute('style');
  18752. }
  18753. /*
  18754. * make a robust clipPath url from a local id
  18755. * note! We'd better not be exporting from a page
  18756. * with a <base> or the svg will not be portable!
  18757. */
  18758. drawing.setClipUrl = function(s, localId) {
  18759. if(!localId) {
  18760. s.attr('clip-path', null);
  18761. return;
  18762. }
  18763. if(drawing.baseUrl === undefined) {
  18764. var base = d3.select('base');
  18765. // Stash base url once and for all!
  18766. // We may have to stash this elsewhere when
  18767. // we'll try to support for child windows
  18768. // more info -> https://github.com/plotly/plotly.js/issues/702
  18769. if(base.size() && base.attr('href')) {
  18770. drawing.baseUrl = window.location.href.split('#')[0];
  18771. } else {
  18772. drawing.baseUrl = '';
  18773. }
  18774. }
  18775. s.attr('clip-path', 'url(' + drawing.baseUrl + '#' + localId + ')');
  18776. };
  18777. drawing.getTranslate = function(element) {
  18778. // Note the separator [^\d] between x and y in this regex
  18779. // We generally use ',' but IE will convert it to ' '
  18780. var re = /.*\btranslate\((-?\d*\.?\d*)[^-\d]*(-?\d*\.?\d*)[^\d].*/,
  18781. getter = element.attr ? 'attr' : 'getAttribute',
  18782. transform = element[getter]('transform') || '';
  18783. var translate = transform.replace(re, function(match, p1, p2) {
  18784. return [p1, p2].join(' ');
  18785. })
  18786. .split(' ');
  18787. return {
  18788. x: +translate[0] || 0,
  18789. y: +translate[1] || 0
  18790. };
  18791. };
  18792. drawing.setTranslate = function(element, x, y) {
  18793. var re = /(\btranslate\(.*?\);?)/,
  18794. getter = element.attr ? 'attr' : 'getAttribute',
  18795. setter = element.attr ? 'attr' : 'setAttribute',
  18796. transform = element[getter]('transform') || '';
  18797. x = x || 0;
  18798. y = y || 0;
  18799. transform = transform.replace(re, '').trim();
  18800. transform += ' translate(' + x + ', ' + y + ')';
  18801. transform = transform.trim();
  18802. element[setter]('transform', transform);
  18803. return transform;
  18804. };
  18805. drawing.getScale = function(element) {
  18806. var re = /.*\bscale\((\d*\.?\d*)[^\d]*(\d*\.?\d*)[^\d].*/,
  18807. getter = element.attr ? 'attr' : 'getAttribute',
  18808. transform = element[getter]('transform') || '';
  18809. var translate = transform.replace(re, function(match, p1, p2) {
  18810. return [p1, p2].join(' ');
  18811. })
  18812. .split(' ');
  18813. return {
  18814. x: +translate[0] || 1,
  18815. y: +translate[1] || 1
  18816. };
  18817. };
  18818. drawing.setScale = function(element, x, y) {
  18819. var re = /(\bscale\(.*?\);?)/,
  18820. getter = element.attr ? 'attr' : 'getAttribute',
  18821. setter = element.attr ? 'attr' : 'setAttribute',
  18822. transform = element[getter]('transform') || '';
  18823. x = x || 1;
  18824. y = y || 1;
  18825. transform = transform.replace(re, '').trim();
  18826. transform += ' scale(' + x + ', ' + y + ')';
  18827. transform = transform.trim();
  18828. element[setter]('transform', transform);
  18829. return transform;
  18830. };
  18831. var SCALE_RE = /\s*sc.*/;
  18832. drawing.setPointGroupScale = function(selection, xScale, yScale) {
  18833. xScale = xScale || 1;
  18834. yScale = yScale || 1;
  18835. if(!selection) return;
  18836. // The same scale transform for every point:
  18837. var scale = (xScale === 1 && yScale === 1) ?
  18838. '' :
  18839. ' scale(' + xScale + ',' + yScale + ')';
  18840. selection.each(function() {
  18841. var t = (this.getAttribute('transform') || '').replace(SCALE_RE, '');
  18842. t += scale;
  18843. t = t.trim();
  18844. this.setAttribute('transform', t);
  18845. });
  18846. };
  18847. var TEXT_POINT_LAST_TRANSLATION_RE = /translate\([^)]*\)\s*$/;
  18848. drawing.setTextPointsScale = function(selection, xScale, yScale) {
  18849. if(!selection) return;
  18850. selection.each(function() {
  18851. var transforms;
  18852. var el = d3.select(this);
  18853. var text = el.select('text');
  18854. if(!text.node()) return;
  18855. var x = parseFloat(text.attr('x') || 0);
  18856. var y = parseFloat(text.attr('y') || 0);
  18857. var existingTransform = (el.attr('transform') || '').match(TEXT_POINT_LAST_TRANSLATION_RE);
  18858. if(xScale === 1 && yScale === 1) {
  18859. transforms = [];
  18860. } else {
  18861. transforms = [
  18862. 'translate(' + x + ',' + y + ')',
  18863. 'scale(' + xScale + ',' + yScale + ')',
  18864. 'translate(' + (-x) + ',' + (-y) + ')',
  18865. ];
  18866. }
  18867. if(existingTransform) {
  18868. transforms.push(existingTransform);
  18869. }
  18870. el.attr('transform', transforms.join(' '));
  18871. });
  18872. };
  18873. },{"../../constants/alignment":148,"../../constants/interactions":150,"../../constants/xmlns_namespaces":152,"../../lib":169,"../../lib/svg_text_utils":191,"../../registry":259,"../../traces/scatter/make_bubble_size_func":383,"../../traces/scatter/subtypes":390,"../color":50,"../colorscale":65,"./symbol_defs":76,"d3":16,"fast-isnumeric":18,"tinycolor2":33}],76:[function(_dereq_,module,exports){
  18874. /**
  18875. * Copyright 2012-2018, Plotly, Inc.
  18876. * All rights reserved.
  18877. *
  18878. * This source code is licensed under the MIT license found in the
  18879. * LICENSE file in the root directory of this source tree.
  18880. */
  18881. 'use strict';
  18882. var d3 = _dereq_('d3');
  18883. /** Marker symbol definitions
  18884. * users can specify markers either by number or name
  18885. * add 100 (or '-open') and you get an open marker
  18886. * open markers have no fill and use line color as the stroke color
  18887. * add 200 (or '-dot') and you get a dot in the middle
  18888. * add both and you get both
  18889. */
  18890. module.exports = {
  18891. circle: {
  18892. n: 0,
  18893. f: function(r) {
  18894. var rs = d3.round(r, 2);
  18895. return 'M' + rs + ',0A' + rs + ',' + rs + ' 0 1,1 0,-' + rs +
  18896. 'A' + rs + ',' + rs + ' 0 0,1 ' + rs + ',0Z';
  18897. }
  18898. },
  18899. square: {
  18900. n: 1,
  18901. f: function(r) {
  18902. var rs = d3.round(r, 2);
  18903. return 'M' + rs + ',' + rs + 'H-' + rs + 'V-' + rs + 'H' + rs + 'Z';
  18904. }
  18905. },
  18906. diamond: {
  18907. n: 2,
  18908. f: function(r) {
  18909. var rd = d3.round(r * 1.3, 2);
  18910. return 'M' + rd + ',0L0,' + rd + 'L-' + rd + ',0L0,-' + rd + 'Z';
  18911. }
  18912. },
  18913. cross: {
  18914. n: 3,
  18915. f: function(r) {
  18916. var rc = d3.round(r * 0.4, 2),
  18917. rc2 = d3.round(r * 1.2, 2);
  18918. return 'M' + rc2 + ',' + rc + 'H' + rc + 'V' + rc2 + 'H-' + rc +
  18919. 'V' + rc + 'H-' + rc2 + 'V-' + rc + 'H-' + rc + 'V-' + rc2 +
  18920. 'H' + rc + 'V-' + rc + 'H' + rc2 + 'Z';
  18921. }
  18922. },
  18923. x: {
  18924. n: 4,
  18925. f: function(r) {
  18926. var rx = d3.round(r * 0.8 / Math.sqrt(2), 2),
  18927. ne = 'l' + rx + ',' + rx,
  18928. se = 'l' + rx + ',-' + rx,
  18929. sw = 'l-' + rx + ',-' + rx,
  18930. nw = 'l-' + rx + ',' + rx;
  18931. return 'M0,' + rx + ne + se + sw + se + sw + nw + sw + nw + ne + nw + ne + 'Z';
  18932. }
  18933. },
  18934. 'triangle-up': {
  18935. n: 5,
  18936. f: function(r) {
  18937. var rt = d3.round(r * 2 / Math.sqrt(3), 2),
  18938. r2 = d3.round(r / 2, 2),
  18939. rs = d3.round(r, 2);
  18940. return 'M-' + rt + ',' + r2 + 'H' + rt + 'L0,-' + rs + 'Z';
  18941. }
  18942. },
  18943. 'triangle-down': {
  18944. n: 6,
  18945. f: function(r) {
  18946. var rt = d3.round(r * 2 / Math.sqrt(3), 2),
  18947. r2 = d3.round(r / 2, 2),
  18948. rs = d3.round(r, 2);
  18949. return 'M-' + rt + ',-' + r2 + 'H' + rt + 'L0,' + rs + 'Z';
  18950. }
  18951. },
  18952. 'triangle-left': {
  18953. n: 7,
  18954. f: function(r) {
  18955. var rt = d3.round(r * 2 / Math.sqrt(3), 2),
  18956. r2 = d3.round(r / 2, 2),
  18957. rs = d3.round(r, 2);
  18958. return 'M' + r2 + ',-' + rt + 'V' + rt + 'L-' + rs + ',0Z';
  18959. }
  18960. },
  18961. 'triangle-right': {
  18962. n: 8,
  18963. f: function(r) {
  18964. var rt = d3.round(r * 2 / Math.sqrt(3), 2),
  18965. r2 = d3.round(r / 2, 2),
  18966. rs = d3.round(r, 2);
  18967. return 'M-' + r2 + ',-' + rt + 'V' + rt + 'L' + rs + ',0Z';
  18968. }
  18969. },
  18970. 'triangle-ne': {
  18971. n: 9,
  18972. f: function(r) {
  18973. var r1 = d3.round(r * 0.6, 2),
  18974. r2 = d3.round(r * 1.2, 2);
  18975. return 'M-' + r2 + ',-' + r1 + 'H' + r1 + 'V' + r2 + 'Z';
  18976. }
  18977. },
  18978. 'triangle-se': {
  18979. n: 10,
  18980. f: function(r) {
  18981. var r1 = d3.round(r * 0.6, 2),
  18982. r2 = d3.round(r * 1.2, 2);
  18983. return 'M' + r1 + ',-' + r2 + 'V' + r1 + 'H-' + r2 + 'Z';
  18984. }
  18985. },
  18986. 'triangle-sw': {
  18987. n: 11,
  18988. f: function(r) {
  18989. var r1 = d3.round(r * 0.6, 2),
  18990. r2 = d3.round(r * 1.2, 2);
  18991. return 'M' + r2 + ',' + r1 + 'H-' + r1 + 'V-' + r2 + 'Z';
  18992. }
  18993. },
  18994. 'triangle-nw': {
  18995. n: 12,
  18996. f: function(r) {
  18997. var r1 = d3.round(r * 0.6, 2),
  18998. r2 = d3.round(r * 1.2, 2);
  18999. return 'M-' + r1 + ',' + r2 + 'V-' + r1 + 'H' + r2 + 'Z';
  19000. }
  19001. },
  19002. pentagon: {
  19003. n: 13,
  19004. f: function(r) {
  19005. var x1 = d3.round(r * 0.951, 2),
  19006. x2 = d3.round(r * 0.588, 2),
  19007. y0 = d3.round(-r, 2),
  19008. y1 = d3.round(r * -0.309, 2),
  19009. y2 = d3.round(r * 0.809, 2);
  19010. return 'M' + x1 + ',' + y1 + 'L' + x2 + ',' + y2 + 'H-' + x2 +
  19011. 'L-' + x1 + ',' + y1 + 'L0,' + y0 + 'Z';
  19012. }
  19013. },
  19014. hexagon: {
  19015. n: 14,
  19016. f: function(r) {
  19017. var y0 = d3.round(r, 2),
  19018. y1 = d3.round(r / 2, 2),
  19019. x = d3.round(r * Math.sqrt(3) / 2, 2);
  19020. return 'M' + x + ',-' + y1 + 'V' + y1 + 'L0,' + y0 +
  19021. 'L-' + x + ',' + y1 + 'V-' + y1 + 'L0,-' + y0 + 'Z';
  19022. }
  19023. },
  19024. hexagon2: {
  19025. n: 15,
  19026. f: function(r) {
  19027. var x0 = d3.round(r, 2),
  19028. x1 = d3.round(r / 2, 2),
  19029. y = d3.round(r * Math.sqrt(3) / 2, 2);
  19030. return 'M-' + x1 + ',' + y + 'H' + x1 + 'L' + x0 +
  19031. ',0L' + x1 + ',-' + y + 'H-' + x1 + 'L-' + x0 + ',0Z';
  19032. }
  19033. },
  19034. octagon: {
  19035. n: 16,
  19036. f: function(r) {
  19037. var a = d3.round(r * 0.924, 2),
  19038. b = d3.round(r * 0.383, 2);
  19039. return 'M-' + b + ',-' + a + 'H' + b + 'L' + a + ',-' + b + 'V' + b +
  19040. 'L' + b + ',' + a + 'H-' + b + 'L-' + a + ',' + b + 'V-' + b + 'Z';
  19041. }
  19042. },
  19043. star: {
  19044. n: 17,
  19045. f: function(r) {
  19046. var rs = r * 1.4,
  19047. x1 = d3.round(rs * 0.225, 2),
  19048. x2 = d3.round(rs * 0.951, 2),
  19049. x3 = d3.round(rs * 0.363, 2),
  19050. x4 = d3.round(rs * 0.588, 2),
  19051. y0 = d3.round(-rs, 2),
  19052. y1 = d3.round(rs * -0.309, 2),
  19053. y3 = d3.round(rs * 0.118, 2),
  19054. y4 = d3.round(rs * 0.809, 2),
  19055. y5 = d3.round(rs * 0.382, 2);
  19056. return 'M' + x1 + ',' + y1 + 'H' + x2 + 'L' + x3 + ',' + y3 +
  19057. 'L' + x4 + ',' + y4 + 'L0,' + y5 + 'L-' + x4 + ',' + y4 +
  19058. 'L-' + x3 + ',' + y3 + 'L-' + x2 + ',' + y1 + 'H-' + x1 +
  19059. 'L0,' + y0 + 'Z';
  19060. }
  19061. },
  19062. hexagram: {
  19063. n: 18,
  19064. f: function(r) {
  19065. var y = d3.round(r * 0.66, 2),
  19066. x1 = d3.round(r * 0.38, 2),
  19067. x2 = d3.round(r * 0.76, 2);
  19068. return 'M-' + x2 + ',0l-' + x1 + ',-' + y + 'h' + x2 +
  19069. 'l' + x1 + ',-' + y + 'l' + x1 + ',' + y + 'h' + x2 +
  19070. 'l-' + x1 + ',' + y + 'l' + x1 + ',' + y + 'h-' + x2 +
  19071. 'l-' + x1 + ',' + y + 'l-' + x1 + ',-' + y + 'h-' + x2 + 'Z';
  19072. }
  19073. },
  19074. 'star-triangle-up': {
  19075. n: 19,
  19076. f: function(r) {
  19077. var x = d3.round(r * Math.sqrt(3) * 0.8, 2),
  19078. y1 = d3.round(r * 0.8, 2),
  19079. y2 = d3.round(r * 1.6, 2),
  19080. rc = d3.round(r * 4, 2),
  19081. aPart = 'A ' + rc + ',' + rc + ' 0 0 1 ';
  19082. return 'M-' + x + ',' + y1 + aPart + x + ',' + y1 +
  19083. aPart + '0,-' + y2 + aPart + '-' + x + ',' + y1 + 'Z';
  19084. }
  19085. },
  19086. 'star-triangle-down': {
  19087. n: 20,
  19088. f: function(r) {
  19089. var x = d3.round(r * Math.sqrt(3) * 0.8, 2),
  19090. y1 = d3.round(r * 0.8, 2),
  19091. y2 = d3.round(r * 1.6, 2),
  19092. rc = d3.round(r * 4, 2),
  19093. aPart = 'A ' + rc + ',' + rc + ' 0 0 1 ';
  19094. return 'M' + x + ',-' + y1 + aPart + '-' + x + ',-' + y1 +
  19095. aPart + '0,' + y2 + aPart + x + ',-' + y1 + 'Z';
  19096. }
  19097. },
  19098. 'star-square': {
  19099. n: 21,
  19100. f: function(r) {
  19101. var rp = d3.round(r * 1.1, 2),
  19102. rc = d3.round(r * 2, 2),
  19103. aPart = 'A ' + rc + ',' + rc + ' 0 0 1 ';
  19104. return 'M-' + rp + ',-' + rp + aPart + '-' + rp + ',' + rp +
  19105. aPart + rp + ',' + rp + aPart + rp + ',-' + rp +
  19106. aPart + '-' + rp + ',-' + rp + 'Z';
  19107. }
  19108. },
  19109. 'star-diamond': {
  19110. n: 22,
  19111. f: function(r) {
  19112. var rp = d3.round(r * 1.4, 2),
  19113. rc = d3.round(r * 1.9, 2),
  19114. aPart = 'A ' + rc + ',' + rc + ' 0 0 1 ';
  19115. return 'M-' + rp + ',0' + aPart + '0,' + rp +
  19116. aPart + rp + ',0' + aPart + '0,-' + rp +
  19117. aPart + '-' + rp + ',0' + 'Z';
  19118. }
  19119. },
  19120. 'diamond-tall': {
  19121. n: 23,
  19122. f: function(r) {
  19123. var x = d3.round(r * 0.7, 2),
  19124. y = d3.round(r * 1.4, 2);
  19125. return 'M0,' + y + 'L' + x + ',0L0,-' + y + 'L-' + x + ',0Z';
  19126. }
  19127. },
  19128. 'diamond-wide': {
  19129. n: 24,
  19130. f: function(r) {
  19131. var x = d3.round(r * 1.4, 2),
  19132. y = d3.round(r * 0.7, 2);
  19133. return 'M0,' + y + 'L' + x + ',0L0,-' + y + 'L-' + x + ',0Z';
  19134. }
  19135. },
  19136. hourglass: {
  19137. n: 25,
  19138. f: function(r) {
  19139. var rs = d3.round(r, 2);
  19140. return 'M' + rs + ',' + rs + 'H-' + rs + 'L' + rs + ',-' + rs + 'H-' + rs + 'Z';
  19141. },
  19142. noDot: true
  19143. },
  19144. bowtie: {
  19145. n: 26,
  19146. f: function(r) {
  19147. var rs = d3.round(r, 2);
  19148. return 'M' + rs + ',' + rs + 'V-' + rs + 'L-' + rs + ',' + rs + 'V-' + rs + 'Z';
  19149. },
  19150. noDot: true
  19151. },
  19152. 'circle-cross': {
  19153. n: 27,
  19154. f: function(r) {
  19155. var rs = d3.round(r, 2);
  19156. return 'M0,' + rs + 'V-' + rs + 'M' + rs + ',0H-' + rs +
  19157. 'M' + rs + ',0A' + rs + ',' + rs + ' 0 1,1 0,-' + rs +
  19158. 'A' + rs + ',' + rs + ' 0 0,1 ' + rs + ',0Z';
  19159. },
  19160. needLine: true,
  19161. noDot: true
  19162. },
  19163. 'circle-x': {
  19164. n: 28,
  19165. f: function(r) {
  19166. var rs = d3.round(r, 2),
  19167. rc = d3.round(r / Math.sqrt(2), 2);
  19168. return 'M' + rc + ',' + rc + 'L-' + rc + ',-' + rc +
  19169. 'M' + rc + ',-' + rc + 'L-' + rc + ',' + rc +
  19170. 'M' + rs + ',0A' + rs + ',' + rs + ' 0 1,1 0,-' + rs +
  19171. 'A' + rs + ',' + rs + ' 0 0,1 ' + rs + ',0Z';
  19172. },
  19173. needLine: true,
  19174. noDot: true
  19175. },
  19176. 'square-cross': {
  19177. n: 29,
  19178. f: function(r) {
  19179. var rs = d3.round(r, 2);
  19180. return 'M0,' + rs + 'V-' + rs + 'M' + rs + ',0H-' + rs +
  19181. 'M' + rs + ',' + rs + 'H-' + rs + 'V-' + rs + 'H' + rs + 'Z';
  19182. },
  19183. needLine: true,
  19184. noDot: true
  19185. },
  19186. 'square-x': {
  19187. n: 30,
  19188. f: function(r) {
  19189. var rs = d3.round(r, 2);
  19190. return 'M' + rs + ',' + rs + 'L-' + rs + ',-' + rs +
  19191. 'M' + rs + ',-' + rs + 'L-' + rs + ',' + rs +
  19192. 'M' + rs + ',' + rs + 'H-' + rs + 'V-' + rs + 'H' + rs + 'Z';
  19193. },
  19194. needLine: true,
  19195. noDot: true
  19196. },
  19197. 'diamond-cross': {
  19198. n: 31,
  19199. f: function(r) {
  19200. var rd = d3.round(r * 1.3, 2);
  19201. return 'M' + rd + ',0L0,' + rd + 'L-' + rd + ',0L0,-' + rd + 'Z' +
  19202. 'M0,-' + rd + 'V' + rd + 'M-' + rd + ',0H' + rd;
  19203. },
  19204. needLine: true,
  19205. noDot: true
  19206. },
  19207. 'diamond-x': {
  19208. n: 32,
  19209. f: function(r) {
  19210. var rd = d3.round(r * 1.3, 2),
  19211. r2 = d3.round(r * 0.65, 2);
  19212. return 'M' + rd + ',0L0,' + rd + 'L-' + rd + ',0L0,-' + rd + 'Z' +
  19213. 'M-' + r2 + ',-' + r2 + 'L' + r2 + ',' + r2 +
  19214. 'M-' + r2 + ',' + r2 + 'L' + r2 + ',-' + r2;
  19215. },
  19216. needLine: true,
  19217. noDot: true
  19218. },
  19219. 'cross-thin': {
  19220. n: 33,
  19221. f: function(r) {
  19222. var rc = d3.round(r * 1.4, 2);
  19223. return 'M0,' + rc + 'V-' + rc + 'M' + rc + ',0H-' + rc;
  19224. },
  19225. needLine: true,
  19226. noDot: true,
  19227. noFill: true
  19228. },
  19229. 'x-thin': {
  19230. n: 34,
  19231. f: function(r) {
  19232. var rx = d3.round(r, 2);
  19233. return 'M' + rx + ',' + rx + 'L-' + rx + ',-' + rx +
  19234. 'M' + rx + ',-' + rx + 'L-' + rx + ',' + rx;
  19235. },
  19236. needLine: true,
  19237. noDot: true,
  19238. noFill: true
  19239. },
  19240. asterisk: {
  19241. n: 35,
  19242. f: function(r) {
  19243. var rc = d3.round(r * 1.2, 2);
  19244. var rs = d3.round(r * 0.85, 2);
  19245. return 'M0,' + rc + 'V-' + rc + 'M' + rc + ',0H-' + rc +
  19246. 'M' + rs + ',' + rs + 'L-' + rs + ',-' + rs +
  19247. 'M' + rs + ',-' + rs + 'L-' + rs + ',' + rs;
  19248. },
  19249. needLine: true,
  19250. noDot: true,
  19251. noFill: true
  19252. },
  19253. hash: {
  19254. n: 36,
  19255. f: function(r) {
  19256. var r1 = d3.round(r / 2, 2),
  19257. r2 = d3.round(r, 2);
  19258. return 'M' + r1 + ',' + r2 + 'V-' + r2 +
  19259. 'm-' + r2 + ',0V' + r2 +
  19260. 'M' + r2 + ',' + r1 + 'H-' + r2 +
  19261. 'm0,-' + r2 + 'H' + r2;
  19262. },
  19263. needLine: true,
  19264. noFill: true
  19265. },
  19266. 'y-up': {
  19267. n: 37,
  19268. f: function(r) {
  19269. var x = d3.round(r * 1.2, 2),
  19270. y0 = d3.round(r * 1.6, 2),
  19271. y1 = d3.round(r * 0.8, 2);
  19272. return 'M-' + x + ',' + y1 + 'L0,0M' + x + ',' + y1 + 'L0,0M0,-' + y0 + 'L0,0';
  19273. },
  19274. needLine: true,
  19275. noDot: true,
  19276. noFill: true
  19277. },
  19278. 'y-down': {
  19279. n: 38,
  19280. f: function(r) {
  19281. var x = d3.round(r * 1.2, 2),
  19282. y0 = d3.round(r * 1.6, 2),
  19283. y1 = d3.round(r * 0.8, 2);
  19284. return 'M-' + x + ',-' + y1 + 'L0,0M' + x + ',-' + y1 + 'L0,0M0,' + y0 + 'L0,0';
  19285. },
  19286. needLine: true,
  19287. noDot: true,
  19288. noFill: true
  19289. },
  19290. 'y-left': {
  19291. n: 39,
  19292. f: function(r) {
  19293. var y = d3.round(r * 1.2, 2),
  19294. x0 = d3.round(r * 1.6, 2),
  19295. x1 = d3.round(r * 0.8, 2);
  19296. return 'M' + x1 + ',' + y + 'L0,0M' + x1 + ',-' + y + 'L0,0M-' + x0 + ',0L0,0';
  19297. },
  19298. needLine: true,
  19299. noDot: true,
  19300. noFill: true
  19301. },
  19302. 'y-right': {
  19303. n: 40,
  19304. f: function(r) {
  19305. var y = d3.round(r * 1.2, 2),
  19306. x0 = d3.round(r * 1.6, 2),
  19307. x1 = d3.round(r * 0.8, 2);
  19308. return 'M-' + x1 + ',' + y + 'L0,0M-' + x1 + ',-' + y + 'L0,0M' + x0 + ',0L0,0';
  19309. },
  19310. needLine: true,
  19311. noDot: true,
  19312. noFill: true
  19313. },
  19314. 'line-ew': {
  19315. n: 41,
  19316. f: function(r) {
  19317. var rc = d3.round(r * 1.4, 2);
  19318. return 'M' + rc + ',0H-' + rc;
  19319. },
  19320. needLine: true,
  19321. noDot: true,
  19322. noFill: true
  19323. },
  19324. 'line-ns': {
  19325. n: 42,
  19326. f: function(r) {
  19327. var rc = d3.round(r * 1.4, 2);
  19328. return 'M0,' + rc + 'V-' + rc;
  19329. },
  19330. needLine: true,
  19331. noDot: true,
  19332. noFill: true
  19333. },
  19334. 'line-ne': {
  19335. n: 43,
  19336. f: function(r) {
  19337. var rx = d3.round(r, 2);
  19338. return 'M' + rx + ',-' + rx + 'L-' + rx + ',' + rx;
  19339. },
  19340. needLine: true,
  19341. noDot: true,
  19342. noFill: true
  19343. },
  19344. 'line-nw': {
  19345. n: 44,
  19346. f: function(r) {
  19347. var rx = d3.round(r, 2);
  19348. return 'M' + rx + ',' + rx + 'L-' + rx + ',-' + rx;
  19349. },
  19350. needLine: true,
  19351. noDot: true,
  19352. noFill: true
  19353. }
  19354. };
  19355. },{"d3":16}],77:[function(_dereq_,module,exports){
  19356. /**
  19357. * Copyright 2012-2018, Plotly, Inc.
  19358. * All rights reserved.
  19359. *
  19360. * This source code is licensed under the MIT license found in the
  19361. * LICENSE file in the root directory of this source tree.
  19362. */
  19363. 'use strict';
  19364. module.exports = {
  19365. visible: {
  19366. valType: 'boolean',
  19367. editType: 'calc',
  19368. },
  19369. type: {
  19370. valType: 'enumerated',
  19371. values: ['percent', 'constant', 'sqrt', 'data'],
  19372. editType: 'calc',
  19373. },
  19374. symmetric: {
  19375. valType: 'boolean',
  19376. editType: 'calc',
  19377. },
  19378. array: {
  19379. valType: 'data_array',
  19380. editType: 'calc',
  19381. },
  19382. arrayminus: {
  19383. valType: 'data_array',
  19384. editType: 'calc',
  19385. },
  19386. value: {
  19387. valType: 'number',
  19388. min: 0,
  19389. dflt: 10,
  19390. editType: 'calc',
  19391. },
  19392. valueminus: {
  19393. valType: 'number',
  19394. min: 0,
  19395. dflt: 10,
  19396. editType: 'calc',
  19397. },
  19398. traceref: {
  19399. valType: 'integer',
  19400. min: 0,
  19401. dflt: 0,
  19402. editType: 'style'
  19403. },
  19404. tracerefminus: {
  19405. valType: 'integer',
  19406. min: 0,
  19407. dflt: 0,
  19408. editType: 'style'
  19409. },
  19410. copy_ystyle: {
  19411. valType: 'boolean',
  19412. editType: 'plot'
  19413. },
  19414. copy_zstyle: {
  19415. valType: 'boolean',
  19416. editType: 'style'
  19417. },
  19418. color: {
  19419. valType: 'color',
  19420. editType: 'style',
  19421. },
  19422. thickness: {
  19423. valType: 'number',
  19424. min: 0,
  19425. dflt: 2,
  19426. editType: 'style',
  19427. },
  19428. width: {
  19429. valType: 'number',
  19430. min: 0,
  19431. editType: 'plot',
  19432. },
  19433. editType: 'calc',
  19434. _deprecated: {
  19435. opacity: {
  19436. valType: 'number',
  19437. editType: 'style',
  19438. }
  19439. }
  19440. };
  19441. },{}],78:[function(_dereq_,module,exports){
  19442. /**
  19443. * Copyright 2012-2018, Plotly, Inc.
  19444. * All rights reserved.
  19445. *
  19446. * This source code is licensed under the MIT license found in the
  19447. * LICENSE file in the root directory of this source tree.
  19448. */
  19449. 'use strict';
  19450. var isNumeric = _dereq_('fast-isnumeric');
  19451. var Registry = _dereq_('../../registry');
  19452. var Axes = _dereq_('../../plots/cartesian/axes');
  19453. var makeComputeError = _dereq_('./compute_error');
  19454. module.exports = function calc(gd) {
  19455. var calcdata = gd.calcdata;
  19456. for(var i = 0; i < calcdata.length; i++) {
  19457. var calcTrace = calcdata[i];
  19458. var trace = calcTrace[0].trace;
  19459. if(trace.visible === true && Registry.traceIs(trace, 'errorBarsOK')) {
  19460. var xa = Axes.getFromId(gd, trace.xaxis);
  19461. var ya = Axes.getFromId(gd, trace.yaxis);
  19462. calcOneAxis(calcTrace, trace, xa, 'x');
  19463. calcOneAxis(calcTrace, trace, ya, 'y');
  19464. }
  19465. }
  19466. };
  19467. function calcOneAxis(calcTrace, trace, axis, coord) {
  19468. var opts = trace['error_' + coord] || {},
  19469. isVisible = (opts.visible && ['linear', 'log'].indexOf(axis.type) !== -1),
  19470. vals = [];
  19471. if(!isVisible) return;
  19472. var computeError = makeComputeError(opts);
  19473. for(var i = 0; i < calcTrace.length; i++) {
  19474. var calcPt = calcTrace[i];
  19475. var iIn = calcPt.i;
  19476. // for types that don't include `i` in each calcdata point
  19477. if(iIn === undefined) iIn = i;
  19478. // for stacked area inserted points
  19479. // TODO: errorbars have been tested cursorily with stacked area,
  19480. // but not thoroughly. It's not even really clear what you want to do:
  19481. // Should it just be calculated based on that trace's size data?
  19482. // Should you add errors from below in quadrature?
  19483. // And what about normalization, where in principle the errors shrink
  19484. // again when you get up to the top end?
  19485. // One option would be to forbid errorbars with stacking until we
  19486. // decide how to handle these questions.
  19487. else if(iIn === null) continue;
  19488. var calcCoord = calcPt[coord];
  19489. if(!isNumeric(axis.c2l(calcCoord))) continue;
  19490. var errors = computeError(calcCoord, iIn);
  19491. if(isNumeric(errors[0]) && isNumeric(errors[1])) {
  19492. var shoe = calcPt[coord + 's'] = calcCoord - errors[0],
  19493. hat = calcPt[coord + 'h'] = calcCoord + errors[1];
  19494. vals.push(shoe, hat);
  19495. }
  19496. }
  19497. var extremes = Axes.findExtremes(axis, vals, {padded: true});
  19498. var axId = axis._id;
  19499. trace._extremes[axId].min = trace._extremes[axId].min.concat(extremes.min);
  19500. trace._extremes[axId].max = trace._extremes[axId].max.concat(extremes.max);
  19501. }
  19502. },{"../../plots/cartesian/axes":214,"../../registry":259,"./compute_error":79,"fast-isnumeric":18}],79:[function(_dereq_,module,exports){
  19503. /**
  19504. * Copyright 2012-2018, Plotly, Inc.
  19505. * All rights reserved.
  19506. *
  19507. * This source code is licensed under the MIT license found in the
  19508. * LICENSE file in the root directory of this source tree.
  19509. */
  19510. 'use strict';
  19511. /**
  19512. * Error bar computing function generator
  19513. *
  19514. * N.B. The generated function does not clean the dataPt entries. Non-numeric
  19515. * entries result in undefined error magnitudes.
  19516. *
  19517. * @param {object} opts error bar attributes
  19518. *
  19519. * @return {function} :
  19520. * @param {numeric} dataPt data point from where to compute the error magnitude
  19521. * @param {number} index index of dataPt in its corresponding data array
  19522. * @return {array}
  19523. * - error[0] : error magnitude in the negative direction
  19524. * - error[1] : " " " " positive "
  19525. */
  19526. module.exports = function makeComputeError(opts) {
  19527. var type = opts.type,
  19528. symmetric = opts.symmetric;
  19529. if(type === 'data') {
  19530. var array = opts.array || [];
  19531. if(symmetric) {
  19532. return function computeError(dataPt, index) {
  19533. var val = +(array[index]);
  19534. return [val, val];
  19535. };
  19536. }
  19537. else {
  19538. var arrayminus = opts.arrayminus || [];
  19539. return function computeError(dataPt, index) {
  19540. var val = +array[index];
  19541. var valMinus = +arrayminus[index];
  19542. // in case one is present and the other is missing, fill in 0
  19543. // so we still see the present one. Mostly useful during manual
  19544. // data entry.
  19545. if(!isNaN(val) || !isNaN(valMinus)) {
  19546. return [valMinus || 0, val || 0];
  19547. }
  19548. return [NaN, NaN];
  19549. };
  19550. }
  19551. }
  19552. else {
  19553. var computeErrorValue = makeComputeErrorValue(type, opts.value),
  19554. computeErrorValueMinus = makeComputeErrorValue(type, opts.valueminus);
  19555. if(symmetric || opts.valueminus === undefined) {
  19556. return function computeError(dataPt) {
  19557. var val = computeErrorValue(dataPt);
  19558. return [val, val];
  19559. };
  19560. }
  19561. else {
  19562. return function computeError(dataPt) {
  19563. return [
  19564. computeErrorValueMinus(dataPt),
  19565. computeErrorValue(dataPt)
  19566. ];
  19567. };
  19568. }
  19569. }
  19570. };
  19571. /**
  19572. * Compute error bar magnitude (for all types except data)
  19573. *
  19574. * @param {string} type error bar type
  19575. * @param {numeric} value error bar value
  19576. *
  19577. * @return {function} :
  19578. * @param {numeric} dataPt
  19579. */
  19580. function makeComputeErrorValue(type, value) {
  19581. if(type === 'percent') {
  19582. return function(dataPt) {
  19583. return Math.abs(dataPt * value / 100);
  19584. };
  19585. }
  19586. if(type === 'constant') {
  19587. return function() {
  19588. return Math.abs(value);
  19589. };
  19590. }
  19591. if(type === 'sqrt') {
  19592. return function(dataPt) {
  19593. return Math.sqrt(Math.abs(dataPt));
  19594. };
  19595. }
  19596. }
  19597. },{}],80:[function(_dereq_,module,exports){
  19598. /**
  19599. * Copyright 2012-2018, Plotly, Inc.
  19600. * All rights reserved.
  19601. *
  19602. * This source code is licensed under the MIT license found in the
  19603. * LICENSE file in the root directory of this source tree.
  19604. */
  19605. 'use strict';
  19606. var isNumeric = _dereq_('fast-isnumeric');
  19607. var Registry = _dereq_('../../registry');
  19608. var Lib = _dereq_('../../lib');
  19609. var Template = _dereq_('../../plot_api/plot_template');
  19610. var attributes = _dereq_('./attributes');
  19611. module.exports = function(traceIn, traceOut, defaultColor, opts) {
  19612. var objName = 'error_' + opts.axis;
  19613. var containerOut = Template.newContainer(traceOut, objName);
  19614. var containerIn = traceIn[objName] || {};
  19615. function coerce(attr, dflt) {
  19616. return Lib.coerce(containerIn, containerOut, attributes, attr, dflt);
  19617. }
  19618. var hasErrorBars = (
  19619. containerIn.array !== undefined ||
  19620. containerIn.value !== undefined ||
  19621. containerIn.type === 'sqrt'
  19622. );
  19623. var visible = coerce('visible', hasErrorBars);
  19624. if(visible === false) return;
  19625. var type = coerce('type', 'array' in containerIn ? 'data' : 'percent'),
  19626. symmetric = true;
  19627. if(type !== 'sqrt') {
  19628. symmetric = coerce('symmetric',
  19629. !((type === 'data' ? 'arrayminus' : 'valueminus') in containerIn));
  19630. }
  19631. if(type === 'data') {
  19632. coerce('array');
  19633. coerce('traceref');
  19634. if(!symmetric) {
  19635. coerce('arrayminus');
  19636. coerce('tracerefminus');
  19637. }
  19638. }
  19639. else if(type === 'percent' || type === 'constant') {
  19640. coerce('value');
  19641. if(!symmetric) coerce('valueminus');
  19642. }
  19643. var copyAttr = 'copy_' + opts.inherit + 'style';
  19644. if(opts.inherit) {
  19645. var inheritObj = traceOut['error_' + opts.inherit];
  19646. if((inheritObj || {}).visible) {
  19647. coerce(copyAttr, !(containerIn.color ||
  19648. isNumeric(containerIn.thickness) ||
  19649. isNumeric(containerIn.width)));
  19650. }
  19651. }
  19652. if(!opts.inherit || !containerOut[copyAttr]) {
  19653. coerce('color', defaultColor);
  19654. coerce('thickness');
  19655. coerce('width', Registry.traceIs(traceOut, 'gl3d') ? 0 : 4);
  19656. }
  19657. };
  19658. },{"../../lib":169,"../../plot_api/plot_template":204,"../../registry":259,"./attributes":77,"fast-isnumeric":18}],81:[function(_dereq_,module,exports){
  19659. /**
  19660. * Copyright 2012-2018, Plotly, Inc.
  19661. * All rights reserved.
  19662. *
  19663. * This source code is licensed under the MIT license found in the
  19664. * LICENSE file in the root directory of this source tree.
  19665. */
  19666. 'use strict';
  19667. var Lib = _dereq_('../../lib');
  19668. var overrideAll = _dereq_('../../plot_api/edit_types').overrideAll;
  19669. var attributes = _dereq_('./attributes');
  19670. var xyAttrs = {
  19671. error_x: Lib.extendFlat({}, attributes),
  19672. error_y: Lib.extendFlat({}, attributes)
  19673. };
  19674. delete xyAttrs.error_x.copy_zstyle;
  19675. delete xyAttrs.error_y.copy_zstyle;
  19676. delete xyAttrs.error_y.copy_ystyle;
  19677. var xyzAttrs = {
  19678. error_x: Lib.extendFlat({}, attributes),
  19679. error_y: Lib.extendFlat({}, attributes),
  19680. error_z: Lib.extendFlat({}, attributes)
  19681. };
  19682. delete xyzAttrs.error_x.copy_ystyle;
  19683. delete xyzAttrs.error_y.copy_ystyle;
  19684. delete xyzAttrs.error_z.copy_ystyle;
  19685. delete xyzAttrs.error_z.copy_zstyle;
  19686. module.exports = {
  19687. moduleType: 'component',
  19688. name: 'errorbars',
  19689. schema: {
  19690. traces: {
  19691. scatter: xyAttrs,
  19692. bar: xyAttrs,
  19693. histogram: xyAttrs,
  19694. scatter3d: overrideAll(xyzAttrs, 'calc', 'nested'),
  19695. scattergl: overrideAll(xyAttrs, 'calc', 'nested')
  19696. }
  19697. },
  19698. supplyDefaults: _dereq_('./defaults'),
  19699. calc: _dereq_('./calc'),
  19700. makeComputeError: _dereq_('./compute_error'),
  19701. plot: _dereq_('./plot'),
  19702. style: _dereq_('./style'),
  19703. hoverInfo: hoverInfo
  19704. };
  19705. function hoverInfo(calcPoint, trace, hoverPoint) {
  19706. if((trace.error_y || {}).visible) {
  19707. hoverPoint.yerr = calcPoint.yh - calcPoint.y;
  19708. if(!trace.error_y.symmetric) hoverPoint.yerrneg = calcPoint.y - calcPoint.ys;
  19709. }
  19710. if((trace.error_x || {}).visible) {
  19711. hoverPoint.xerr = calcPoint.xh - calcPoint.x;
  19712. if(!trace.error_x.symmetric) hoverPoint.xerrneg = calcPoint.x - calcPoint.xs;
  19713. }
  19714. }
  19715. },{"../../lib":169,"../../plot_api/edit_types":197,"./attributes":77,"./calc":78,"./compute_error":79,"./defaults":80,"./plot":82,"./style":83}],82:[function(_dereq_,module,exports){
  19716. /**
  19717. * Copyright 2012-2018, Plotly, Inc.
  19718. * All rights reserved.
  19719. *
  19720. * This source code is licensed under the MIT license found in the
  19721. * LICENSE file in the root directory of this source tree.
  19722. */
  19723. 'use strict';
  19724. var d3 = _dereq_('d3');
  19725. var isNumeric = _dereq_('fast-isnumeric');
  19726. var Drawing = _dereq_('../drawing');
  19727. var subTypes = _dereq_('../../traces/scatter/subtypes');
  19728. module.exports = function plot(traces, plotinfo, transitionOpts) {
  19729. var isNew;
  19730. var xa = plotinfo.xaxis;
  19731. var ya = plotinfo.yaxis;
  19732. var hasAnimation = transitionOpts && transitionOpts.duration > 0;
  19733. traces.each(function(d) {
  19734. var trace = d[0].trace,
  19735. // || {} is in case the trace (specifically scatterternary)
  19736. // doesn't support error bars at all, but does go through
  19737. // the scatter.plot mechanics, which calls ErrorBars.plot
  19738. // internally
  19739. xObj = trace.error_x || {},
  19740. yObj = trace.error_y || {};
  19741. var keyFunc;
  19742. if(trace.ids) {
  19743. keyFunc = function(d) {return d.id;};
  19744. }
  19745. var sparse = (
  19746. subTypes.hasMarkers(trace) &&
  19747. trace.marker.maxdisplayed > 0
  19748. );
  19749. if(!yObj.visible && !xObj.visible) d = [];
  19750. var errorbars = d3.select(this).selectAll('g.errorbar')
  19751. .data(d, keyFunc);
  19752. errorbars.exit().remove();
  19753. if(!d.length) return;
  19754. if(!xObj.visible) errorbars.selectAll('path.xerror').remove();
  19755. if(!yObj.visible) errorbars.selectAll('path.yerror').remove();
  19756. errorbars.style('opacity', 1);
  19757. var enter = errorbars.enter().append('g')
  19758. .classed('errorbar', true);
  19759. if(hasAnimation) {
  19760. enter.style('opacity', 0).transition()
  19761. .duration(transitionOpts.duration)
  19762. .style('opacity', 1);
  19763. }
  19764. Drawing.setClipUrl(errorbars, plotinfo.layerClipId);
  19765. errorbars.each(function(d) {
  19766. var errorbar = d3.select(this);
  19767. var coords = errorCoords(d, xa, ya);
  19768. if(sparse && !d.vis) return;
  19769. var path;
  19770. var yerror = errorbar.select('path.yerror');
  19771. if(yObj.visible && isNumeric(coords.x) &&
  19772. isNumeric(coords.yh) &&
  19773. isNumeric(coords.ys)) {
  19774. var yw = yObj.width;
  19775. path = 'M' + (coords.x - yw) + ',' +
  19776. coords.yh + 'h' + (2 * yw) + // hat
  19777. 'm-' + yw + ',0V' + coords.ys; // bar
  19778. if(!coords.noYS) path += 'm-' + yw + ',0h' + (2 * yw); // shoe
  19779. isNew = !yerror.size();
  19780. if(isNew) {
  19781. yerror = errorbar.append('path')
  19782. .style('vector-effect', 'non-scaling-stroke')
  19783. .classed('yerror', true);
  19784. } else if(hasAnimation) {
  19785. yerror = yerror
  19786. .transition()
  19787. .duration(transitionOpts.duration)
  19788. .ease(transitionOpts.easing);
  19789. }
  19790. yerror.attr('d', path);
  19791. }
  19792. else yerror.remove();
  19793. var xerror = errorbar.select('path.xerror');
  19794. if(xObj.visible && isNumeric(coords.y) &&
  19795. isNumeric(coords.xh) &&
  19796. isNumeric(coords.xs)) {
  19797. var xw = (xObj.copy_ystyle ? yObj : xObj).width;
  19798. path = 'M' + coords.xh + ',' +
  19799. (coords.y - xw) + 'v' + (2 * xw) + // hat
  19800. 'm0,-' + xw + 'H' + coords.xs; // bar
  19801. if(!coords.noXS) path += 'm0,-' + xw + 'v' + (2 * xw); // shoe
  19802. isNew = !xerror.size();
  19803. if(isNew) {
  19804. xerror = errorbar.append('path')
  19805. .style('vector-effect', 'non-scaling-stroke')
  19806. .classed('xerror', true);
  19807. } else if(hasAnimation) {
  19808. xerror = xerror
  19809. .transition()
  19810. .duration(transitionOpts.duration)
  19811. .ease(transitionOpts.easing);
  19812. }
  19813. xerror.attr('d', path);
  19814. }
  19815. else xerror.remove();
  19816. });
  19817. });
  19818. };
  19819. // compute the coordinates of the error-bar objects
  19820. function errorCoords(d, xa, ya) {
  19821. var out = {
  19822. x: xa.c2p(d.x),
  19823. y: ya.c2p(d.y)
  19824. };
  19825. // calculate the error bar size and hat and shoe locations
  19826. if(d.yh !== undefined) {
  19827. out.yh = ya.c2p(d.yh);
  19828. out.ys = ya.c2p(d.ys);
  19829. // if the shoes go off-scale (ie log scale, error bars past zero)
  19830. // clip the bar and hide the shoes
  19831. if(!isNumeric(out.ys)) {
  19832. out.noYS = true;
  19833. out.ys = ya.c2p(d.ys, true);
  19834. }
  19835. }
  19836. if(d.xh !== undefined) {
  19837. out.xh = xa.c2p(d.xh);
  19838. out.xs = xa.c2p(d.xs);
  19839. if(!isNumeric(out.xs)) {
  19840. out.noXS = true;
  19841. out.xs = xa.c2p(d.xs, true);
  19842. }
  19843. }
  19844. return out;
  19845. }
  19846. },{"../../traces/scatter/subtypes":390,"../drawing":75,"d3":16,"fast-isnumeric":18}],83:[function(_dereq_,module,exports){
  19847. /**
  19848. * Copyright 2012-2018, Plotly, Inc.
  19849. * All rights reserved.
  19850. *
  19851. * This source code is licensed under the MIT license found in the
  19852. * LICENSE file in the root directory of this source tree.
  19853. */
  19854. 'use strict';
  19855. var d3 = _dereq_('d3');
  19856. var Color = _dereq_('../color');
  19857. module.exports = function style(traces) {
  19858. traces.each(function(d) {
  19859. var trace = d[0].trace,
  19860. yObj = trace.error_y || {},
  19861. xObj = trace.error_x || {};
  19862. var s = d3.select(this);
  19863. s.selectAll('path.yerror')
  19864. .style('stroke-width', yObj.thickness + 'px')
  19865. .call(Color.stroke, yObj.color);
  19866. if(xObj.copy_ystyle) xObj = yObj;
  19867. s.selectAll('path.xerror')
  19868. .style('stroke-width', xObj.thickness + 'px')
  19869. .call(Color.stroke, xObj.color);
  19870. });
  19871. };
  19872. },{"../color":50,"d3":16}],84:[function(_dereq_,module,exports){
  19873. /**
  19874. * Copyright 2012-2018, Plotly, Inc.
  19875. * All rights reserved.
  19876. *
  19877. * This source code is licensed under the MIT license found in the
  19878. * LICENSE file in the root directory of this source tree.
  19879. */
  19880. 'use strict';
  19881. var fontAttrs = _dereq_('../../plots/font_attributes');
  19882. module.exports = {
  19883. hoverlabel: {
  19884. bgcolor: {
  19885. valType: 'color',
  19886. arrayOk: true,
  19887. editType: 'none',
  19888. },
  19889. bordercolor: {
  19890. valType: 'color',
  19891. arrayOk: true,
  19892. editType: 'none',
  19893. },
  19894. font: fontAttrs({
  19895. arrayOk: true,
  19896. editType: 'none',
  19897. }),
  19898. namelength: {
  19899. valType: 'integer',
  19900. min: -1,
  19901. arrayOk: true,
  19902. editType: 'none',
  19903. },
  19904. editType: 'calc'
  19905. }
  19906. };
  19907. },{"../../plots/font_attributes":240}],85:[function(_dereq_,module,exports){
  19908. /**
  19909. * Copyright 2012-2018, Plotly, Inc.
  19910. * All rights reserved.
  19911. *
  19912. * This source code is licensed under the MIT license found in the
  19913. * LICENSE file in the root directory of this source tree.
  19914. */
  19915. 'use strict';
  19916. var Lib = _dereq_('../../lib');
  19917. var Registry = _dereq_('../../registry');
  19918. module.exports = function calc(gd) {
  19919. var calcdata = gd.calcdata;
  19920. var fullLayout = gd._fullLayout;
  19921. function makeCoerceHoverInfo(trace) {
  19922. return function(val) {
  19923. return Lib.coerceHoverinfo({hoverinfo: val}, {_module: trace._module}, fullLayout);
  19924. };
  19925. }
  19926. for(var i = 0; i < calcdata.length; i++) {
  19927. var cd = calcdata[i];
  19928. var trace = cd[0].trace;
  19929. // don't include hover calc fields for pie traces
  19930. // as calcdata items might be sorted by value and
  19931. // won't match the data array order.
  19932. if(Registry.traceIs(trace, 'pie')) continue;
  19933. var fillFn = Registry.traceIs(trace, '2dMap') ? paste : Lib.fillArray;
  19934. fillFn(trace.hoverinfo, cd, 'hi', makeCoerceHoverInfo(trace));
  19935. if(!trace.hoverlabel) continue;
  19936. fillFn(trace.hoverlabel.bgcolor, cd, 'hbg');
  19937. fillFn(trace.hoverlabel.bordercolor, cd, 'hbc');
  19938. fillFn(trace.hoverlabel.font.size, cd, 'hts');
  19939. fillFn(trace.hoverlabel.font.color, cd, 'htc');
  19940. fillFn(trace.hoverlabel.font.family, cd, 'htf');
  19941. fillFn(trace.hoverlabel.namelength, cd, 'hnl');
  19942. }
  19943. };
  19944. function paste(traceAttr, cd, cdAttr, fn) {
  19945. fn = fn || Lib.identity;
  19946. if(Array.isArray(traceAttr)) {
  19947. cd[0][cdAttr] = fn(traceAttr);
  19948. }
  19949. }
  19950. },{"../../lib":169,"../../registry":259}],86:[function(_dereq_,module,exports){
  19951. /**
  19952. * Copyright 2012-2018, Plotly, Inc.
  19953. * All rights reserved.
  19954. *
  19955. * This source code is licensed under the MIT license found in the
  19956. * LICENSE file in the root directory of this source tree.
  19957. */
  19958. 'use strict';
  19959. var Registry = _dereq_('../../registry');
  19960. var hover = _dereq_('./hover').hover;
  19961. module.exports = function click(gd, evt, subplot) {
  19962. var annotationsDone = Registry.getComponentMethod('annotations', 'onClick')(gd, gd._hoverdata);
  19963. // fallback to fail-safe in case the plot type's hover method doesn't pass the subplot.
  19964. // Ternary, for example, didn't, but it was caught because tested.
  19965. if(subplot !== undefined) {
  19966. // The true flag at the end causes it to re-run the hover computation to figure out *which*
  19967. // point is being clicked. Without this, clicking is somewhat unreliable.
  19968. hover(gd, evt, subplot, true);
  19969. }
  19970. function emitClick() { gd.emit('plotly_click', {points: gd._hoverdata, event: evt}); }
  19971. if(gd._hoverdata && evt && evt.target) {
  19972. if(annotationsDone && annotationsDone.then) {
  19973. annotationsDone.then(emitClick);
  19974. }
  19975. else emitClick();
  19976. // why do we get a double event without this???
  19977. if(evt.stopImmediatePropagation) evt.stopImmediatePropagation();
  19978. }
  19979. };
  19980. },{"../../registry":259,"./hover":90}],87:[function(_dereq_,module,exports){
  19981. /**
  19982. * Copyright 2012-2018, Plotly, Inc.
  19983. * All rights reserved.
  19984. *
  19985. * This source code is licensed under the MIT license found in the
  19986. * LICENSE file in the root directory of this source tree.
  19987. */
  19988. 'use strict';
  19989. module.exports = {
  19990. // hover labels for multiple horizontal bars get tilted by this angle
  19991. YANGLE: 60,
  19992. // size and display constants for hover text
  19993. // pixel size of hover arrows
  19994. HOVERARROWSIZE: 6,
  19995. // pixels padding around text
  19996. HOVERTEXTPAD: 3,
  19997. // hover font
  19998. HOVERFONTSIZE: 13,
  19999. HOVERFONT: 'Arial, sans-serif',
  20000. // minimum time (msec) between hover calls
  20001. HOVERMINTIME: 50,
  20002. // ID suffix (with fullLayout._uid) for hover events in the throttle cache
  20003. HOVERID: '-hover'
  20004. };
  20005. },{}],88:[function(_dereq_,module,exports){
  20006. /**
  20007. * Copyright 2012-2018, Plotly, Inc.
  20008. * All rights reserved.
  20009. *
  20010. * This source code is licensed under the MIT license found in the
  20011. * LICENSE file in the root directory of this source tree.
  20012. */
  20013. 'use strict';
  20014. var Lib = _dereq_('../../lib');
  20015. var attributes = _dereq_('./attributes');
  20016. var handleHoverLabelDefaults = _dereq_('./hoverlabel_defaults');
  20017. module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout) {
  20018. function coerce(attr, dflt) {
  20019. return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);
  20020. }
  20021. handleHoverLabelDefaults(traceIn, traceOut, coerce, layout.hoverlabel);
  20022. };
  20023. },{"../../lib":169,"./attributes":84,"./hoverlabel_defaults":91}],89:[function(_dereq_,module,exports){
  20024. /**
  20025. * Copyright 2012-2018, Plotly, Inc.
  20026. * All rights reserved.
  20027. *
  20028. * This source code is licensed under the MIT license found in the
  20029. * LICENSE file in the root directory of this source tree.
  20030. */
  20031. 'use strict';
  20032. var Lib = _dereq_('../../lib');
  20033. // look for either subplot or xaxis and yaxis attributes
  20034. // does not handle splom case
  20035. exports.getSubplot = function getSubplot(trace) {
  20036. return trace.subplot || (trace.xaxis + trace.yaxis) || trace.geo;
  20037. };
  20038. // is trace in given list of subplots?
  20039. // does handle splom case
  20040. exports.isTraceInSubplots = function isTraceInSubplot(trace, subplots) {
  20041. if(trace.type === 'splom') {
  20042. var xaxes = trace.xaxes || [];
  20043. var yaxes = trace.yaxes || [];
  20044. for(var i = 0; i < xaxes.length; i++) {
  20045. for(var j = 0; j < yaxes.length; j++) {
  20046. if(subplots.indexOf(xaxes[i] + yaxes[j]) !== -1) {
  20047. return true;
  20048. }
  20049. }
  20050. }
  20051. return false;
  20052. }
  20053. return subplots.indexOf(exports.getSubplot(trace)) !== -1;
  20054. };
  20055. // convenience functions for mapping all relevant axes
  20056. exports.flat = function flat(subplots, v) {
  20057. var out = new Array(subplots.length);
  20058. for(var i = 0; i < subplots.length; i++) {
  20059. out[i] = v;
  20060. }
  20061. return out;
  20062. };
  20063. exports.p2c = function p2c(axArray, v) {
  20064. var out = new Array(axArray.length);
  20065. for(var i = 0; i < axArray.length; i++) {
  20066. out[i] = axArray[i].p2c(v);
  20067. }
  20068. return out;
  20069. };
  20070. exports.getDistanceFunction = function getDistanceFunction(mode, dx, dy, dxy) {
  20071. if(mode === 'closest') return dxy || exports.quadrature(dx, dy);
  20072. return mode === 'x' ? dx : dy;
  20073. };
  20074. exports.getClosest = function getClosest(cd, distfn, pointData) {
  20075. // do we already have a point number? (array mode only)
  20076. if(pointData.index !== false) {
  20077. if(pointData.index >= 0 && pointData.index < cd.length) {
  20078. pointData.distance = 0;
  20079. }
  20080. else pointData.index = false;
  20081. }
  20082. else {
  20083. // apply the distance function to each data point
  20084. // this is the longest loop... if this bogs down, we may need
  20085. // to create pre-sorted data (by x or y), not sure how to
  20086. // do this for 'closest'
  20087. for(var i = 0; i < cd.length; i++) {
  20088. var newDistance = distfn(cd[i]);
  20089. if(newDistance <= pointData.distance) {
  20090. pointData.index = i;
  20091. pointData.distance = newDistance;
  20092. }
  20093. }
  20094. }
  20095. return pointData;
  20096. };
  20097. /*
  20098. * pseudo-distance function for hover effects on areas: inside the region
  20099. * distance is finite (`passVal`), outside it's Infinity.
  20100. *
  20101. * @param {number} v0: signed difference between the current position and the left edge
  20102. * @param {number} v1: signed difference between the current position and the right edge
  20103. * @param {number} passVal: the value to return on success
  20104. */
  20105. exports.inbox = function inbox(v0, v1, passVal) {
  20106. return (v0 * v1 < 0 || v0 === 0) ? passVal : Infinity;
  20107. };
  20108. exports.quadrature = function quadrature(dx, dy) {
  20109. return function(di) {
  20110. var x = dx(di),
  20111. y = dy(di);
  20112. return Math.sqrt(x * x + y * y);
  20113. };
  20114. };
  20115. /** Fill event data point object for hover and selection.
  20116. * Invokes _module.eventData if present.
  20117. *
  20118. * N.B. note that point 'index' corresponds to input data array index
  20119. * whereas 'number' is its post-transform version.
  20120. *
  20121. * If the hovered/selected pt corresponds to an multiple input points
  20122. * (e.g. for histogram and transformed traces), 'pointNumbers` and 'pointIndices'
  20123. * are include in the event data.
  20124. *
  20125. * @param {object} pt
  20126. * @param {object} trace
  20127. * @param {object} cd
  20128. * @return {object}
  20129. */
  20130. exports.makeEventData = function makeEventData(pt, trace, cd) {
  20131. // hover uses 'index', select uses 'pointNumber'
  20132. var pointNumber = 'index' in pt ? pt.index : pt.pointNumber;
  20133. var out = {
  20134. data: trace._input,
  20135. fullData: trace,
  20136. curveNumber: trace.index,
  20137. pointNumber: pointNumber
  20138. };
  20139. if(trace._indexToPoints) {
  20140. var pointIndices = trace._indexToPoints[pointNumber];
  20141. if(pointIndices.length === 1) {
  20142. out.pointIndex = pointIndices[0];
  20143. } else {
  20144. out.pointIndices = pointIndices;
  20145. }
  20146. } else {
  20147. out.pointIndex = pointNumber;
  20148. }
  20149. if(trace._module.eventData) {
  20150. out = trace._module.eventData(out, pt, trace, cd, pointNumber);
  20151. } else {
  20152. if('xVal' in pt) out.x = pt.xVal;
  20153. else if('x' in pt) out.x = pt.x;
  20154. if('yVal' in pt) out.y = pt.yVal;
  20155. else if('y' in pt) out.y = pt.y;
  20156. if(pt.xa) out.xaxis = pt.xa;
  20157. if(pt.ya) out.yaxis = pt.ya;
  20158. if(pt.zLabelVal !== undefined) out.z = pt.zLabelVal;
  20159. }
  20160. exports.appendArrayPointValue(out, trace, pointNumber);
  20161. return out;
  20162. };
  20163. /** Appends values inside array attributes corresponding to given point number
  20164. *
  20165. * @param {object} pointData : point data object (gets mutated here)
  20166. * @param {object} trace : full trace object
  20167. * @param {number|Array(number)} pointNumber : point number. May be a length-2 array
  20168. * [row, col] to dig into 2D arrays
  20169. */
  20170. exports.appendArrayPointValue = function(pointData, trace, pointNumber) {
  20171. var arrayAttrs = trace._arrayAttrs;
  20172. if(!arrayAttrs) {
  20173. return;
  20174. }
  20175. for(var i = 0; i < arrayAttrs.length; i++) {
  20176. var astr = arrayAttrs[i];
  20177. var key = getPointKey(astr);
  20178. if(pointData[key] === undefined) {
  20179. var val = Lib.nestedProperty(trace, astr).get();
  20180. var pointVal = getPointData(val, pointNumber);
  20181. if(pointVal !== undefined) pointData[key] = pointVal;
  20182. }
  20183. }
  20184. };
  20185. /**
  20186. * Appends values inside array attributes corresponding to given point number array
  20187. * For use when pointData references a plot entity that arose (or potentially arose)
  20188. * from multiple points in the input data
  20189. *
  20190. * @param {object} pointData : point data object (gets mutated here)
  20191. * @param {object} trace : full trace object
  20192. * @param {Array(number)|Array(Array(number))} pointNumbers : Array of point numbers.
  20193. * Each entry in the array may itself be a length-2 array [row, col] to dig into 2D arrays
  20194. */
  20195. exports.appendArrayMultiPointValues = function(pointData, trace, pointNumbers) {
  20196. var arrayAttrs = trace._arrayAttrs;
  20197. if(!arrayAttrs) {
  20198. return;
  20199. }
  20200. for(var i = 0; i < arrayAttrs.length; i++) {
  20201. var astr = arrayAttrs[i];
  20202. var key = getPointKey(astr);
  20203. if(pointData[key] === undefined) {
  20204. var val = Lib.nestedProperty(trace, astr).get();
  20205. var keyVal = new Array(pointNumbers.length);
  20206. for(var j = 0; j < pointNumbers.length; j++) {
  20207. keyVal[j] = getPointData(val, pointNumbers[j]);
  20208. }
  20209. pointData[key] = keyVal;
  20210. }
  20211. }
  20212. };
  20213. var pointKeyMap = {
  20214. ids: 'id',
  20215. locations: 'location',
  20216. labels: 'label',
  20217. values: 'value',
  20218. 'marker.colors': 'color'
  20219. };
  20220. function getPointKey(astr) {
  20221. return pointKeyMap[astr] || astr;
  20222. }
  20223. function getPointData(val, pointNumber) {
  20224. if(Array.isArray(pointNumber)) {
  20225. if(Array.isArray(val) && Array.isArray(val[pointNumber[0]])) {
  20226. return val[pointNumber[0]][pointNumber[1]];
  20227. }
  20228. } else {
  20229. return val[pointNumber];
  20230. }
  20231. }
  20232. },{"../../lib":169}],90:[function(_dereq_,module,exports){
  20233. /**
  20234. * Copyright 2012-2018, Plotly, Inc.
  20235. * All rights reserved.
  20236. *
  20237. * This source code is licensed under the MIT license found in the
  20238. * LICENSE file in the root directory of this source tree.
  20239. */
  20240. 'use strict';
  20241. var d3 = _dereq_('d3');
  20242. var isNumeric = _dereq_('fast-isnumeric');
  20243. var tinycolor = _dereq_('tinycolor2');
  20244. var Lib = _dereq_('../../lib');
  20245. var Events = _dereq_('../../lib/events');
  20246. var svgTextUtils = _dereq_('../../lib/svg_text_utils');
  20247. var overrideCursor = _dereq_('../../lib/override_cursor');
  20248. var Drawing = _dereq_('../drawing');
  20249. var Color = _dereq_('../color');
  20250. var dragElement = _dereq_('../dragelement');
  20251. var Axes = _dereq_('../../plots/cartesian/axes');
  20252. var Registry = _dereq_('../../registry');
  20253. var helpers = _dereq_('./helpers');
  20254. var constants = _dereq_('./constants');
  20255. // hover labels for multiple horizontal bars get tilted by some angle,
  20256. // then need to be offset differently if they overlap
  20257. var YANGLE = constants.YANGLE;
  20258. var YA_RADIANS = Math.PI * YANGLE / 180;
  20259. // expansion of projected height
  20260. var YFACTOR = 1 / Math.sin(YA_RADIANS);
  20261. // to make the appropriate post-rotation x offset,
  20262. // you need both x and y offsets
  20263. var YSHIFTX = Math.cos(YA_RADIANS);
  20264. var YSHIFTY = Math.sin(YA_RADIANS);
  20265. // size and display constants for hover text
  20266. var HOVERARROWSIZE = constants.HOVERARROWSIZE;
  20267. var HOVERTEXTPAD = constants.HOVERTEXTPAD;
  20268. // fx.hover: highlight data on hover
  20269. // evt can be a mousemove event, or an object with data about what points
  20270. // to hover on
  20271. // {xpx,ypx[,hovermode]} - pixel locations from top left
  20272. // (with optional overriding hovermode)
  20273. // {xval,yval[,hovermode]} - data values
  20274. // [{curveNumber,(pointNumber|xval and/or yval)}] -
  20275. // array of specific points to highlight
  20276. // pointNumber is a single integer if gd.data[curveNumber] is 1D,
  20277. // or a two-element array if it's 2D
  20278. // xval and yval are data values,
  20279. // 1D data may specify either or both,
  20280. // 2D data must specify both
  20281. // subplot is an id string (default "xy")
  20282. // makes use of gl.hovermode, which can be:
  20283. // x (find the points with the closest x values, ie a column),
  20284. // closest (find the single closest point)
  20285. // internally there are two more that occasionally get used:
  20286. // y (pick out a row - only used for multiple horizontal bar charts)
  20287. // array (used when the user specifies an explicit
  20288. // array of points to hover on)
  20289. //
  20290. // We wrap the hovers in a timer, to limit their frequency.
  20291. // The actual rendering is done by private function _hover.
  20292. exports.hover = function hover(gd, evt, subplot, noHoverEvent) {
  20293. gd = Lib.getGraphDiv(gd);
  20294. Lib.throttle(
  20295. gd._fullLayout._uid + constants.HOVERID,
  20296. constants.HOVERMINTIME,
  20297. function() { _hover(gd, evt, subplot, noHoverEvent); }
  20298. );
  20299. };
  20300. /*
  20301. * Draw a single hover item in a pre-existing svg container somewhere
  20302. * hoverItem should have keys:
  20303. * - x and y (or x0, x1, y0, and y1):
  20304. * the pixel position to mark, relative to opts.container
  20305. * - xLabel, yLabel, zLabel, text, and name:
  20306. * info to go in the label
  20307. * - color:
  20308. * the background color for the label.
  20309. * - idealAlign (optional):
  20310. * 'left' or 'right' for which side of the x/y box to try to put this on first
  20311. * - borderColor (optional):
  20312. * color for the border, defaults to strongest contrast with color
  20313. * - fontFamily (optional):
  20314. * string, the font for this label, defaults to constants.HOVERFONT
  20315. * - fontSize (optional):
  20316. * the label font size, defaults to constants.HOVERFONTSIZE
  20317. * - fontColor (optional):
  20318. * defaults to borderColor
  20319. * opts should have keys:
  20320. * - bgColor:
  20321. * the background color this is against, used if the trace is
  20322. * non-opaque, and for the name, which goes outside the box
  20323. * - container:
  20324. * a <svg> or <g> element to add the hover label to
  20325. * - outerContainer:
  20326. * normally a parent of `container`, sets the bounding box to use to
  20327. * constrain the hover label and determine whether to show it on the left or right
  20328. */
  20329. exports.loneHover = function loneHover(hoverItem, opts) {
  20330. var pointData = {
  20331. color: hoverItem.color || Color.defaultLine,
  20332. x0: hoverItem.x0 || hoverItem.x || 0,
  20333. x1: hoverItem.x1 || hoverItem.x || 0,
  20334. y0: hoverItem.y0 || hoverItem.y || 0,
  20335. y1: hoverItem.y1 || hoverItem.y || 0,
  20336. xLabel: hoverItem.xLabel,
  20337. yLabel: hoverItem.yLabel,
  20338. zLabel: hoverItem.zLabel,
  20339. text: hoverItem.text,
  20340. name: hoverItem.name,
  20341. idealAlign: hoverItem.idealAlign,
  20342. // optional extra bits of styling
  20343. borderColor: hoverItem.borderColor,
  20344. fontFamily: hoverItem.fontFamily,
  20345. fontSize: hoverItem.fontSize,
  20346. fontColor: hoverItem.fontColor,
  20347. // filler to make createHoverText happy
  20348. trace: {
  20349. index: 0,
  20350. hoverinfo: ''
  20351. },
  20352. xa: {_offset: 0},
  20353. ya: {_offset: 0},
  20354. index: 0
  20355. };
  20356. var container3 = d3.select(opts.container);
  20357. var outerContainer3 = opts.outerContainer ?
  20358. d3.select(opts.outerContainer) : container3;
  20359. var fullOpts = {
  20360. hovermode: 'closest',
  20361. rotateLabels: false,
  20362. bgColor: opts.bgColor || Color.background,
  20363. container: container3,
  20364. outerContainer: outerContainer3
  20365. };
  20366. var hoverLabel = createHoverText([pointData], fullOpts, opts.gd);
  20367. alignHoverText(hoverLabel, fullOpts.rotateLabels);
  20368. return hoverLabel.node();
  20369. };
  20370. // The actual implementation is here:
  20371. function _hover(gd, evt, subplot, noHoverEvent) {
  20372. if(!subplot) subplot = 'xy';
  20373. // if the user passed in an array of subplots,
  20374. // use those instead of finding overlayed plots
  20375. var subplots = Array.isArray(subplot) ? subplot : [subplot];
  20376. var fullLayout = gd._fullLayout;
  20377. var plots = fullLayout._plots || [];
  20378. var plotinfo = plots[subplot];
  20379. var hasCartesian = fullLayout._has('cartesian');
  20380. // list of all overlaid subplots to look at
  20381. if(plotinfo) {
  20382. var overlayedSubplots = plotinfo.overlays.map(function(pi) {
  20383. return pi.id;
  20384. });
  20385. subplots = subplots.concat(overlayedSubplots);
  20386. }
  20387. var len = subplots.length;
  20388. var xaArray = new Array(len);
  20389. var yaArray = new Array(len);
  20390. var supportsCompare = false;
  20391. for(var i = 0; i < len; i++) {
  20392. var spId = subplots[i];
  20393. // 'cartesian' case
  20394. var plotObj = plots[spId];
  20395. if(plotObj) {
  20396. supportsCompare = true;
  20397. // TODO make sure that fullLayout_plots axis refs
  20398. // get updated properly so that we don't have
  20399. // to use Axes.getFromId in general.
  20400. xaArray[i] = Axes.getFromId(gd, plotObj.xaxis._id);
  20401. yaArray[i] = Axes.getFromId(gd, plotObj.yaxis._id);
  20402. continue;
  20403. }
  20404. // other subplot types
  20405. var _subplot = fullLayout[spId]._subplot;
  20406. xaArray[i] = _subplot.xaxis;
  20407. yaArray[i] = _subplot.yaxis;
  20408. }
  20409. var hovermode = evt.hovermode || fullLayout.hovermode;
  20410. if(hovermode && !supportsCompare) hovermode = 'closest';
  20411. if(['x', 'y', 'closest'].indexOf(hovermode) === -1 || !gd.calcdata ||
  20412. gd.querySelector('.zoombox') || gd._dragging) {
  20413. return dragElement.unhoverRaw(gd, evt);
  20414. }
  20415. var hoverdistance = fullLayout.hoverdistance === -1 ? Infinity : fullLayout.hoverdistance;
  20416. var spikedistance = fullLayout.spikedistance === -1 ? Infinity : fullLayout.spikedistance;
  20417. // hoverData: the set of candidate points we've found to highlight
  20418. var hoverData = [];
  20419. // searchData: the data to search in. Mostly this is just a copy of
  20420. // gd.calcdata, filtered to the subplot and overlays we're on
  20421. // but if a point array is supplied it will be a mapping
  20422. // of indicated curves
  20423. var searchData = [];
  20424. // [x|y]valArray: the axis values of the hover event
  20425. // mapped onto each of the currently selected overlaid subplots
  20426. var xvalArray, yvalArray;
  20427. var itemnum, curvenum, cd, trace, subplotId, subploti, mode,
  20428. xval, yval, pointData, closedataPreviousLength;
  20429. // spikePoints: the set of candidate points we've found to draw spikes to
  20430. var spikePoints = {
  20431. hLinePoint: null,
  20432. vLinePoint: null
  20433. };
  20434. // does subplot have one (or more) horizontal traces?
  20435. // This is used to determine whether we rotate the labels or not
  20436. var hasOneHorizontalTrace = false;
  20437. // Figure out what we're hovering on:
  20438. // mouse location or user-supplied data
  20439. if(Array.isArray(evt)) {
  20440. // user specified an array of points to highlight
  20441. hovermode = 'array';
  20442. for(itemnum = 0; itemnum < evt.length; itemnum++) {
  20443. cd = gd.calcdata[evt[itemnum].curveNumber||0];
  20444. trace = cd[0].trace;
  20445. if(cd[0].trace.hoverinfo !== 'skip') {
  20446. searchData.push(cd);
  20447. if(trace.orientation === 'h') {
  20448. hasOneHorizontalTrace = true;
  20449. }
  20450. }
  20451. }
  20452. }
  20453. else {
  20454. for(curvenum = 0; curvenum < gd.calcdata.length; curvenum++) {
  20455. cd = gd.calcdata[curvenum];
  20456. trace = cd[0].trace;
  20457. if(trace.hoverinfo !== 'skip' && helpers.isTraceInSubplots(trace, subplots)) {
  20458. searchData.push(cd);
  20459. if(trace.orientation === 'h') {
  20460. hasOneHorizontalTrace = true;
  20461. }
  20462. }
  20463. }
  20464. // [x|y]px: the pixels (from top left) of the mouse location
  20465. // on the currently selected plot area
  20466. // add pointerX|Y property for drawing the spikes in spikesnap 'cursor' situation
  20467. var hasUserCalledHover = !evt.target;
  20468. var xpx, ypx;
  20469. if(hasUserCalledHover) {
  20470. if('xpx' in evt) xpx = evt.xpx;
  20471. else xpx = xaArray[0]._length / 2;
  20472. if('ypx' in evt) ypx = evt.ypx;
  20473. else ypx = yaArray[0]._length / 2;
  20474. }
  20475. else {
  20476. // fire the beforehover event and quit if it returns false
  20477. // note that we're only calling this on real mouse events, so
  20478. // manual calls to fx.hover will always run.
  20479. if(Events.triggerHandler(gd, 'plotly_beforehover', evt) === false) {
  20480. return;
  20481. }
  20482. var dbb = evt.target.getBoundingClientRect();
  20483. xpx = evt.clientX - dbb.left;
  20484. ypx = evt.clientY - dbb.top;
  20485. // in case hover was called from mouseout into hovertext,
  20486. // it's possible you're not actually over the plot anymore
  20487. if(xpx < 0 || xpx > xaArray[0]._length || ypx < 0 || ypx > yaArray[0]._length) {
  20488. return dragElement.unhoverRaw(gd, evt);
  20489. }
  20490. }
  20491. evt.pointerX = xpx + xaArray[0]._offset;
  20492. evt.pointerY = ypx + yaArray[0]._offset;
  20493. if('xval' in evt) xvalArray = helpers.flat(subplots, evt.xval);
  20494. else xvalArray = helpers.p2c(xaArray, xpx);
  20495. if('yval' in evt) yvalArray = helpers.flat(subplots, evt.yval);
  20496. else yvalArray = helpers.p2c(yaArray, ypx);
  20497. if(!isNumeric(xvalArray[0]) || !isNumeric(yvalArray[0])) {
  20498. Lib.warn('Fx.hover failed', evt, gd);
  20499. return dragElement.unhoverRaw(gd, evt);
  20500. }
  20501. }
  20502. // the pixel distance to beat as a matching point
  20503. // in 'x' or 'y' mode this resets for each trace
  20504. var distance = Infinity;
  20505. // find the closest point in each trace
  20506. // this is minimum dx and/or dy, depending on mode
  20507. // and the pixel position for the label (labelXpx, labelYpx)
  20508. for(curvenum = 0; curvenum < searchData.length; curvenum++) {
  20509. cd = searchData[curvenum];
  20510. // filter out invisible or broken data
  20511. if(!cd || !cd[0] || !cd[0].trace || cd[0].trace.visible !== true) continue;
  20512. trace = cd[0].trace;
  20513. // Explicitly bail out for these two. I don't know how to otherwise prevent
  20514. // the rest of this function from running and failing
  20515. if(['carpet', 'contourcarpet'].indexOf(trace._module.name) !== -1) continue;
  20516. if(trace.type === 'splom') {
  20517. // splom traces do not generate overlay subplots,
  20518. // it is safe to assume here splom traces correspond to the 0th subplot
  20519. subploti = 0;
  20520. subplotId = subplots[subploti];
  20521. } else {
  20522. subplotId = helpers.getSubplot(trace);
  20523. subploti = subplots.indexOf(subplotId);
  20524. }
  20525. // within one trace mode can sometimes be overridden
  20526. mode = hovermode;
  20527. // container for new point, also used to pass info into module.hoverPoints
  20528. pointData = {
  20529. // trace properties
  20530. cd: cd,
  20531. trace: trace,
  20532. xa: xaArray[subploti],
  20533. ya: yaArray[subploti],
  20534. // max distances for hover and spikes - for points that want to show but do not
  20535. // want to override other points, set distance/spikeDistance equal to max*Distance
  20536. // and it will not get filtered out but it will be guaranteed to have a greater
  20537. // distance than any point that calculated a real distance.
  20538. maxHoverDistance: hoverdistance,
  20539. maxSpikeDistance: spikedistance,
  20540. // point properties - override all of these
  20541. index: false, // point index in trace - only used by plotly.js hoverdata consumers
  20542. distance: Math.min(distance, hoverdistance), // pixel distance or pseudo-distance
  20543. // distance/pseudo-distance for spikes. This distance should always be calculated
  20544. // as if in "closest" mode, and should only be set if this point should
  20545. // generate a spike.
  20546. spikeDistance: Infinity,
  20547. // in some cases the spikes have different positioning from the hover label
  20548. // they don't need x0/x1, just one position
  20549. xSpike: undefined,
  20550. ySpike: undefined,
  20551. // where and how to display the hover label
  20552. color: Color.defaultLine, // trace color
  20553. name: trace.name,
  20554. x0: undefined,
  20555. x1: undefined,
  20556. y0: undefined,
  20557. y1: undefined,
  20558. xLabelVal: undefined,
  20559. yLabelVal: undefined,
  20560. zLabelVal: undefined,
  20561. text: undefined
  20562. };
  20563. // add ref to subplot object (non-cartesian case)
  20564. if(fullLayout[subplotId]) {
  20565. pointData.subplot = fullLayout[subplotId]._subplot;
  20566. }
  20567. closedataPreviousLength = hoverData.length;
  20568. // for a highlighting array, figure out what
  20569. // we're searching for with this element
  20570. if(mode === 'array') {
  20571. var selection = evt[curvenum];
  20572. if('pointNumber' in selection) {
  20573. pointData.index = selection.pointNumber;
  20574. mode = 'closest';
  20575. }
  20576. else {
  20577. mode = '';
  20578. if('xval' in selection) {
  20579. xval = selection.xval;
  20580. mode = 'x';
  20581. }
  20582. if('yval' in selection) {
  20583. yval = selection.yval;
  20584. mode = mode ? 'closest' : 'y';
  20585. }
  20586. }
  20587. }
  20588. else {
  20589. xval = xvalArray[subploti];
  20590. yval = yvalArray[subploti];
  20591. }
  20592. // Now if there is range to look in, find the points to hover.
  20593. if(hoverdistance !== 0) {
  20594. if(trace._module && trace._module.hoverPoints) {
  20595. var newPoints = trace._module.hoverPoints(pointData, xval, yval, mode, fullLayout._hoverlayer);
  20596. if(newPoints) {
  20597. var newPoint;
  20598. for(var newPointNum = 0; newPointNum < newPoints.length; newPointNum++) {
  20599. newPoint = newPoints[newPointNum];
  20600. if(isNumeric(newPoint.x0) && isNumeric(newPoint.y0)) {
  20601. hoverData.push(cleanPoint(newPoint, hovermode));
  20602. }
  20603. }
  20604. }
  20605. }
  20606. else {
  20607. Lib.log('Unrecognized trace type in hover:', trace);
  20608. }
  20609. }
  20610. // in closest mode, remove any existing (farther) points
  20611. // and don't look any farther than this latest point (or points, some
  20612. // traces like box & violin make multiple hover labels at once)
  20613. if(hovermode === 'closest' && hoverData.length > closedataPreviousLength) {
  20614. hoverData.splice(0, closedataPreviousLength);
  20615. distance = hoverData[0].distance;
  20616. }
  20617. // Now if there is range to look in, find the points to draw the spikelines
  20618. // Do it only if there is no hoverData
  20619. if(hasCartesian && (spikedistance !== 0)) {
  20620. if(hoverData.length === 0) {
  20621. pointData.distance = spikedistance;
  20622. pointData.index = false;
  20623. var closestPoints = trace._module.hoverPoints(pointData, xval, yval, 'closest', fullLayout._hoverlayer);
  20624. if(closestPoints) {
  20625. closestPoints = closestPoints.filter(function(point) {
  20626. // some hover points, like scatter fills, do not allow spikes,
  20627. // so will generate a hover point but without a valid spikeDistance
  20628. return point.spikeDistance <= spikedistance;
  20629. });
  20630. }
  20631. if(closestPoints && closestPoints.length) {
  20632. var tmpPoint;
  20633. var closestVPoints = closestPoints.filter(function(point) {
  20634. return point.xa.showspikes;
  20635. });
  20636. if(closestVPoints.length) {
  20637. var closestVPt = closestVPoints[0];
  20638. if(isNumeric(closestVPt.x0) && isNumeric(closestVPt.y0)) {
  20639. tmpPoint = fillSpikePoint(closestVPt);
  20640. if(!spikePoints.vLinePoint || (spikePoints.vLinePoint.spikeDistance > tmpPoint.spikeDistance)) {
  20641. spikePoints.vLinePoint = tmpPoint;
  20642. }
  20643. }
  20644. }
  20645. var closestHPoints = closestPoints.filter(function(point) {
  20646. return point.ya.showspikes;
  20647. });
  20648. if(closestHPoints.length) {
  20649. var closestHPt = closestHPoints[0];
  20650. if(isNumeric(closestHPt.x0) && isNumeric(closestHPt.y0)) {
  20651. tmpPoint = fillSpikePoint(closestHPt);
  20652. if(!spikePoints.hLinePoint || (spikePoints.hLinePoint.spikeDistance > tmpPoint.spikeDistance)) {
  20653. spikePoints.hLinePoint = tmpPoint;
  20654. }
  20655. }
  20656. }
  20657. }
  20658. }
  20659. }
  20660. }
  20661. function selectClosestPoint(pointsData, spikedistance) {
  20662. var resultPoint = null;
  20663. var minDistance = Infinity;
  20664. var thisSpikeDistance;
  20665. for(var i = 0; i < pointsData.length; i++) {
  20666. thisSpikeDistance = pointsData[i].spikeDistance;
  20667. if(thisSpikeDistance < minDistance && thisSpikeDistance <= spikedistance) {
  20668. resultPoint = pointsData[i];
  20669. minDistance = thisSpikeDistance;
  20670. }
  20671. }
  20672. return resultPoint;
  20673. }
  20674. function fillSpikePoint(point) {
  20675. if(!point) return null;
  20676. return {
  20677. xa: point.xa,
  20678. ya: point.ya,
  20679. x: point.xSpike !== undefined ? point.xSpike : (point.x0 + point.x1) / 2,
  20680. y: point.ySpike !== undefined ? point.ySpike : (point.y0 + point.y1) / 2,
  20681. distance: point.distance,
  20682. spikeDistance: point.spikeDistance,
  20683. curveNumber: point.trace.index,
  20684. color: point.color,
  20685. pointNumber: point.index
  20686. };
  20687. }
  20688. var spikelineOpts = {
  20689. fullLayout: fullLayout,
  20690. container: fullLayout._hoverlayer,
  20691. outerContainer: fullLayout._paperdiv,
  20692. event: evt
  20693. };
  20694. var oldspikepoints = gd._spikepoints,
  20695. newspikepoints = {
  20696. vLinePoint: spikePoints.vLinePoint,
  20697. hLinePoint: spikePoints.hLinePoint
  20698. };
  20699. gd._spikepoints = newspikepoints;
  20700. // Now if it is not restricted by spikedistance option, set the points to draw the spikelines
  20701. if(hasCartesian && (spikedistance !== 0)) {
  20702. if(hoverData.length !== 0) {
  20703. var tmpHPointData = hoverData.filter(function(point) {
  20704. return point.ya.showspikes;
  20705. });
  20706. var tmpHPoint = selectClosestPoint(tmpHPointData, spikedistance);
  20707. spikePoints.hLinePoint = fillSpikePoint(tmpHPoint);
  20708. var tmpVPointData = hoverData.filter(function(point) {
  20709. return point.xa.showspikes;
  20710. });
  20711. var tmpVPoint = selectClosestPoint(tmpVPointData, spikedistance);
  20712. spikePoints.vLinePoint = fillSpikePoint(tmpVPoint);
  20713. }
  20714. }
  20715. // if hoverData is empty check for the spikes to draw and quit if there are none
  20716. if(hoverData.length === 0) {
  20717. var result = dragElement.unhoverRaw(gd, evt);
  20718. if(hasCartesian && ((spikePoints.hLinePoint !== null) || (spikePoints.vLinePoint !== null))) {
  20719. if(spikesChanged(oldspikepoints)) {
  20720. createSpikelines(spikePoints, spikelineOpts);
  20721. }
  20722. }
  20723. return result;
  20724. }
  20725. if(hasCartesian) {
  20726. if(spikesChanged(oldspikepoints)) {
  20727. createSpikelines(spikePoints, spikelineOpts);
  20728. }
  20729. }
  20730. hoverData.sort(function(d1, d2) { return d1.distance - d2.distance; });
  20731. // lastly, emit custom hover/unhover events
  20732. var oldhoverdata = gd._hoverdata;
  20733. var newhoverdata = [];
  20734. // pull out just the data that's useful to
  20735. // other people and send it to the event
  20736. for(itemnum = 0; itemnum < hoverData.length; itemnum++) {
  20737. var pt = hoverData[itemnum];
  20738. newhoverdata.push(helpers.makeEventData(pt, pt.trace, pt.cd));
  20739. }
  20740. gd._hoverdata = newhoverdata;
  20741. var rotateLabels = (
  20742. (hovermode === 'y' && (searchData.length > 1 || hoverData.length > 1)) ||
  20743. (hovermode === 'closest' && hasOneHorizontalTrace && hoverData.length > 1)
  20744. );
  20745. var bgColor = Color.combine(
  20746. fullLayout.plot_bgcolor || Color.background,
  20747. fullLayout.paper_bgcolor
  20748. );
  20749. var labelOpts = {
  20750. hovermode: hovermode,
  20751. rotateLabels: rotateLabels,
  20752. bgColor: bgColor,
  20753. container: fullLayout._hoverlayer,
  20754. outerContainer: fullLayout._paperdiv,
  20755. commonLabelOpts: fullLayout.hoverlabel,
  20756. hoverdistance: fullLayout.hoverdistance
  20757. };
  20758. var hoverLabels = createHoverText(hoverData, labelOpts, gd);
  20759. hoverAvoidOverlaps(hoverData, rotateLabels ? 'xa' : 'ya', fullLayout);
  20760. alignHoverText(hoverLabels, rotateLabels);
  20761. // TODO: tagName hack is needed to appease geo.js's hack of using evt.target=true
  20762. // we should improve the "fx" API so other plots can use it without these hack.
  20763. if(evt.target && evt.target.tagName) {
  20764. var hasClickToShow = Registry.getComponentMethod('annotations', 'hasClickToShow')(gd, newhoverdata);
  20765. overrideCursor(d3.select(evt.target), hasClickToShow ? 'pointer' : '');
  20766. }
  20767. // don't emit events if called manually
  20768. if(!evt.target || noHoverEvent || !hoverChanged(gd, evt, oldhoverdata)) return;
  20769. if(oldhoverdata) {
  20770. gd.emit('plotly_unhover', {
  20771. event: evt,
  20772. points: oldhoverdata
  20773. });
  20774. }
  20775. gd.emit('plotly_hover', {
  20776. event: evt,
  20777. points: gd._hoverdata,
  20778. xaxes: xaArray,
  20779. yaxes: yaArray,
  20780. xvals: xvalArray,
  20781. yvals: yvalArray
  20782. });
  20783. }
  20784. function createHoverText(hoverData, opts, gd) {
  20785. var hovermode = opts.hovermode;
  20786. var rotateLabels = opts.rotateLabels;
  20787. var bgColor = opts.bgColor;
  20788. var container = opts.container;
  20789. var outerContainer = opts.outerContainer;
  20790. var commonLabelOpts = opts.commonLabelOpts || {};
  20791. // opts.fontFamily/Size are used for the common label
  20792. // and as defaults for each hover label, though the individual labels
  20793. // can override this.
  20794. var fontFamily = opts.fontFamily || constants.HOVERFONT;
  20795. var fontSize = opts.fontSize || constants.HOVERFONTSIZE;
  20796. var c0 = hoverData[0];
  20797. var xa = c0.xa;
  20798. var ya = c0.ya;
  20799. var commonAttr = hovermode === 'y' ? 'yLabel' : 'xLabel';
  20800. var t0 = c0[commonAttr];
  20801. var t00 = (String(t0) || '').split(' ')[0];
  20802. var outerContainerBB = outerContainer.node().getBoundingClientRect();
  20803. var outerTop = outerContainerBB.top;
  20804. var outerWidth = outerContainerBB.width;
  20805. var outerHeight = outerContainerBB.height;
  20806. // show the common label, if any, on the axis
  20807. // never show a common label in array mode,
  20808. // even if sometimes there could be one
  20809. var showCommonLabel = (
  20810. (t0 !== undefined) &&
  20811. (c0.distance <= opts.hoverdistance) &&
  20812. (hovermode === 'x' || hovermode === 'y')
  20813. );
  20814. // all hover traces hoverinfo must contain the hovermode
  20815. // to have common labels
  20816. if(showCommonLabel) {
  20817. var allHaveZ = true;
  20818. var i, traceHoverinfo;
  20819. for(i = 0; i < hoverData.length; i++) {
  20820. if(allHaveZ && hoverData[i].zLabel === undefined) allHaveZ = false;
  20821. traceHoverinfo = hoverData[i].hoverinfo || hoverData[i].trace.hoverinfo;
  20822. var parts = Array.isArray(traceHoverinfo) ? traceHoverinfo : traceHoverinfo.split('+');
  20823. if(parts.indexOf('all') === -1 &&
  20824. parts.indexOf(hovermode) === -1) {
  20825. showCommonLabel = false;
  20826. break;
  20827. }
  20828. }
  20829. // xyz labels put all info in their main label, so have no need of a common label
  20830. if(allHaveZ) showCommonLabel = false;
  20831. }
  20832. var commonLabel = container.selectAll('g.axistext')
  20833. .data(showCommonLabel ? [0] : []);
  20834. commonLabel.enter().append('g')
  20835. .classed('axistext', true);
  20836. commonLabel.exit().remove();
  20837. commonLabel.each(function() {
  20838. var label = d3.select(this);
  20839. var lpath = Lib.ensureSingle(label, 'path', '', function(s) {
  20840. s.style({'stroke-width': '1px'});
  20841. });
  20842. var ltext = Lib.ensureSingle(label, 'text', '', function(s) {
  20843. // prohibit tex interpretation until we can handle
  20844. // tex and regular text together
  20845. s.attr('data-notex', 1);
  20846. });
  20847. var commonBgColor = commonLabelOpts.bgcolor || Color.defaultLine;
  20848. var commonStroke = commonLabelOpts.bordercolor || Color.contrast(commonBgColor);
  20849. var contrastColor = Color.contrast(commonBgColor);
  20850. lpath.style({
  20851. fill: commonBgColor,
  20852. stroke: commonStroke
  20853. });
  20854. ltext.text(t0)
  20855. .call(Drawing.font,
  20856. commonLabelOpts.font.family || fontFamily,
  20857. commonLabelOpts.font.size || fontSize,
  20858. commonLabelOpts.font.color || contrastColor
  20859. )
  20860. .call(svgTextUtils.positionText, 0, 0)
  20861. .call(svgTextUtils.convertToTspans, gd);
  20862. label.attr('transform', '');
  20863. var tbb = ltext.node().getBoundingClientRect();
  20864. if(hovermode === 'x') {
  20865. ltext.attr('text-anchor', 'middle')
  20866. .call(svgTextUtils.positionText, 0, (xa.side === 'top' ?
  20867. (outerTop - tbb.bottom - HOVERARROWSIZE - HOVERTEXTPAD) :
  20868. (outerTop - tbb.top + HOVERARROWSIZE + HOVERTEXTPAD)));
  20869. var topsign = xa.side === 'top' ? '-' : '';
  20870. lpath.attr('d', 'M0,0' +
  20871. 'L' + HOVERARROWSIZE + ',' + topsign + HOVERARROWSIZE +
  20872. 'H' + (HOVERTEXTPAD + tbb.width / 2) +
  20873. 'v' + topsign + (HOVERTEXTPAD * 2 + tbb.height) +
  20874. 'H-' + (HOVERTEXTPAD + tbb.width / 2) +
  20875. 'V' + topsign + HOVERARROWSIZE + 'H-' + HOVERARROWSIZE + 'Z');
  20876. label.attr('transform', 'translate(' +
  20877. (xa._offset + (c0.x0 + c0.x1) / 2) + ',' +
  20878. (ya._offset + (xa.side === 'top' ? 0 : ya._length)) + ')');
  20879. }
  20880. else {
  20881. ltext.attr('text-anchor', ya.side === 'right' ? 'start' : 'end')
  20882. .call(svgTextUtils.positionText,
  20883. (ya.side === 'right' ? 1 : -1) * (HOVERTEXTPAD + HOVERARROWSIZE),
  20884. outerTop - tbb.top - tbb.height / 2);
  20885. var leftsign = ya.side === 'right' ? '' : '-';
  20886. lpath.attr('d', 'M0,0' +
  20887. 'L' + leftsign + HOVERARROWSIZE + ',' + HOVERARROWSIZE +
  20888. 'V' + (HOVERTEXTPAD + tbb.height / 2) +
  20889. 'h' + leftsign + (HOVERTEXTPAD * 2 + tbb.width) +
  20890. 'V-' + (HOVERTEXTPAD + tbb.height / 2) +
  20891. 'H' + leftsign + HOVERARROWSIZE + 'V-' + HOVERARROWSIZE + 'Z');
  20892. label.attr('transform', 'translate(' +
  20893. (xa._offset + (ya.side === 'right' ? xa._length : 0)) + ',' +
  20894. (ya._offset + (c0.y0 + c0.y1) / 2) + ')');
  20895. }
  20896. // remove the "close but not quite" points
  20897. // because of error bars, only take up to a space
  20898. hoverData = hoverData.filter(function(d) {
  20899. return (d.zLabelVal !== undefined) ||
  20900. (d[commonAttr] || '').split(' ')[0] === t00;
  20901. });
  20902. });
  20903. // show all the individual labels
  20904. // first create the objects
  20905. var hoverLabels = container.selectAll('g.hovertext')
  20906. .data(hoverData, function(d) {
  20907. return [d.trace.index, d.index, d.x0, d.y0, d.name, d.attr, d.xa, d.ya || ''].join(',');
  20908. });
  20909. hoverLabels.enter().append('g')
  20910. .classed('hovertext', true)
  20911. .each(function() {
  20912. var g = d3.select(this);
  20913. // trace name label (rect and text.name)
  20914. g.append('rect')
  20915. .call(Color.fill, Color.addOpacity(bgColor, 0.8));
  20916. g.append('text').classed('name', true);
  20917. // trace data label (path and text.nums)
  20918. g.append('path')
  20919. .style('stroke-width', '1px');
  20920. g.append('text').classed('nums', true)
  20921. .call(Drawing.font, fontFamily, fontSize);
  20922. });
  20923. hoverLabels.exit().remove();
  20924. // then put the text in, position the pointer to the data,
  20925. // and figure out sizes
  20926. hoverLabels.each(function(d) {
  20927. var g = d3.select(this).attr('transform', '');
  20928. var name = '';
  20929. var text = '';
  20930. // combine possible non-opaque trace color with bgColor
  20931. var color0 = d.bgcolor || d.color;
  20932. // color for 'nums' part of the label
  20933. var numsColor = Color.combine(
  20934. Color.opacity(color0) ? color0 : Color.defaultLine,
  20935. bgColor
  20936. );
  20937. // color for 'name' part of the label
  20938. var nameColor = Color.combine(
  20939. Color.opacity(d.color) ? d.color : Color.defaultLine,
  20940. bgColor
  20941. );
  20942. // find a contrasting color for border and text
  20943. var contrastColor = d.borderColor || Color.contrast(numsColor);
  20944. // to get custom 'name' labels pass cleanPoint
  20945. if(d.nameOverride !== undefined) d.name = d.nameOverride;
  20946. if(d.name) {
  20947. // strip out our pseudo-html elements from d.name (if it exists at all)
  20948. name = svgTextUtils.plainText(d.name || '');
  20949. var nameLength = Math.round(d.nameLength);
  20950. if(nameLength > -1 && name.length > nameLength) {
  20951. if(nameLength > 3) name = name.substr(0, nameLength - 3) + '...';
  20952. else name = name.substr(0, nameLength);
  20953. }
  20954. }
  20955. if(d.zLabel !== undefined) {
  20956. if(d.xLabel !== undefined) text += 'x: ' + d.xLabel + '<br>';
  20957. if(d.yLabel !== undefined) text += 'y: ' + d.yLabel + '<br>';
  20958. text += (text ? 'z: ' : '') + d.zLabel;
  20959. }
  20960. else if(showCommonLabel && d[hovermode + 'Label'] === t0) {
  20961. text = d[(hovermode === 'x' ? 'y' : 'x') + 'Label'] || '';
  20962. }
  20963. else if(d.xLabel === undefined) {
  20964. if(d.yLabel !== undefined) text = d.yLabel;
  20965. }
  20966. else if(d.yLabel === undefined) text = d.xLabel;
  20967. else text = '(' + d.xLabel + ', ' + d.yLabel + ')';
  20968. if((d.text || d.text === 0) && !Array.isArray(d.text)) {
  20969. text += (text ? '<br>' : '') + d.text;
  20970. }
  20971. // used by other modules (initially just ternary) that
  20972. // manage their own hoverinfo independent of cleanPoint
  20973. // the rest of this will still apply, so such modules
  20974. // can still put things in (x|y|z)Label, text, and name
  20975. // and hoverinfo will still determine their visibility
  20976. if(d.extraText !== undefined) text += (text ? '<br>' : '') + d.extraText;
  20977. // if 'text' is empty at this point,
  20978. // put 'name' in main label and don't show secondary label
  20979. if(text === '') {
  20980. // if 'name' is also empty, remove entire label
  20981. if(name === '') g.remove();
  20982. text = name;
  20983. }
  20984. // main label
  20985. var tx = g.select('text.nums')
  20986. .call(Drawing.font,
  20987. d.fontFamily || fontFamily,
  20988. d.fontSize || fontSize,
  20989. d.fontColor || contrastColor)
  20990. .text(text)
  20991. .attr('data-notex', 1)
  20992. .call(svgTextUtils.positionText, 0, 0)
  20993. .call(svgTextUtils.convertToTspans, gd);
  20994. var tx2 = g.select('text.name');
  20995. var tx2width = 0;
  20996. // secondary label for non-empty 'name'
  20997. if(name && name !== text) {
  20998. tx2.call(Drawing.font,
  20999. d.fontFamily || fontFamily,
  21000. d.fontSize || fontSize,
  21001. nameColor)
  21002. .text(name)
  21003. .attr('data-notex', 1)
  21004. .call(svgTextUtils.positionText, 0, 0)
  21005. .call(svgTextUtils.convertToTspans, gd);
  21006. tx2width = tx2.node().getBoundingClientRect().width + 2 * HOVERTEXTPAD;
  21007. }
  21008. else {
  21009. tx2.remove();
  21010. g.select('rect').remove();
  21011. }
  21012. g.select('path')
  21013. .style({
  21014. fill: numsColor,
  21015. stroke: contrastColor
  21016. });
  21017. var tbb = tx.node().getBoundingClientRect();
  21018. var htx = d.xa._offset + (d.x0 + d.x1) / 2;
  21019. var hty = d.ya._offset + (d.y0 + d.y1) / 2;
  21020. var dx = Math.abs(d.x1 - d.x0);
  21021. var dy = Math.abs(d.y1 - d.y0);
  21022. var txTotalWidth = tbb.width + HOVERARROWSIZE + HOVERTEXTPAD + tx2width;
  21023. var anchorStartOK, anchorEndOK;
  21024. d.ty0 = outerTop - tbb.top;
  21025. d.bx = tbb.width + 2 * HOVERTEXTPAD;
  21026. d.by = tbb.height + 2 * HOVERTEXTPAD;
  21027. d.anchor = 'start';
  21028. d.txwidth = tbb.width;
  21029. d.tx2width = tx2width;
  21030. d.offset = 0;
  21031. if(rotateLabels) {
  21032. d.pos = htx;
  21033. anchorStartOK = hty + dy / 2 + txTotalWidth <= outerHeight;
  21034. anchorEndOK = hty - dy / 2 - txTotalWidth >= 0;
  21035. if((d.idealAlign === 'top' || !anchorStartOK) && anchorEndOK) {
  21036. hty -= dy / 2;
  21037. d.anchor = 'end';
  21038. } else if(anchorStartOK) {
  21039. hty += dy / 2;
  21040. d.anchor = 'start';
  21041. } else d.anchor = 'middle';
  21042. }
  21043. else {
  21044. d.pos = hty;
  21045. anchorStartOK = htx + dx / 2 + txTotalWidth <= outerWidth;
  21046. anchorEndOK = htx - dx / 2 - txTotalWidth >= 0;
  21047. if((d.idealAlign === 'left' || !anchorStartOK) && anchorEndOK) {
  21048. htx -= dx / 2;
  21049. d.anchor = 'end';
  21050. } else if(anchorStartOK) {
  21051. htx += dx / 2;
  21052. d.anchor = 'start';
  21053. } else d.anchor = 'middle';
  21054. }
  21055. tx.attr('text-anchor', d.anchor);
  21056. if(tx2width) tx2.attr('text-anchor', d.anchor);
  21057. g.attr('transform', 'translate(' + htx + ',' + hty + ')' +
  21058. (rotateLabels ? 'rotate(' + YANGLE + ')' : ''));
  21059. });
  21060. return hoverLabels;
  21061. }
  21062. // Make groups of touching points, and within each group
  21063. // move each point so that no labels overlap, but the average
  21064. // label position is the same as it was before moving. Indicentally,
  21065. // this is equivalent to saying all the labels are on equal linear
  21066. // springs about their initial position. Initially, each point is
  21067. // its own group, but as we find overlaps we will clump the points.
  21068. //
  21069. // Also, there are hard constraints at the edges of the graphs,
  21070. // that push all groups to the middle so they are visible. I don't
  21071. // know what happens if the group spans all the way from one edge to
  21072. // the other, though it hardly matters - there's just too much
  21073. // information then.
  21074. function hoverAvoidOverlaps(hoverData, ax, fullLayout) {
  21075. var nummoves = 0;
  21076. var axSign = 1;
  21077. // make groups of touching points
  21078. var pointgroups = hoverData.map(function(d, i) {
  21079. var axis = d[ax];
  21080. var axIsX = axis._id.charAt(0) === 'x';
  21081. var rng = axis.range;
  21082. if(!i && rng && ((rng[0] > rng[1]) !== axIsX)) axSign = -1;
  21083. return [{
  21084. i: i,
  21085. traceIndex: d.trace.index,
  21086. dp: 0,
  21087. pos: d.pos,
  21088. posref: d.posref,
  21089. size: d.by * (axIsX ? YFACTOR : 1) / 2,
  21090. pmin: 0,
  21091. pmax: (axIsX ? fullLayout.width : fullLayout.height)
  21092. }];
  21093. })
  21094. .sort(function(a, b) {
  21095. return (a[0].posref - b[0].posref) ||
  21096. // for equal positions, sort trace indices increasing or decreasing
  21097. // depending on whether the axis is reversed or not... so stacked
  21098. // traces will generally keep their order even if one trace adds
  21099. // nothing to the stack.
  21100. (axSign * (b[0].traceIndex - a[0].traceIndex));
  21101. });
  21102. var donepositioning, topOverlap, bottomOverlap, i, j, pti, sumdp;
  21103. function constrainGroup(grp) {
  21104. var minPt = grp[0];
  21105. var maxPt = grp[grp.length - 1];
  21106. // overlap with the top - positive vals are overlaps
  21107. topOverlap = minPt.pmin - minPt.pos - minPt.dp + minPt.size;
  21108. // overlap with the bottom - positive vals are overlaps
  21109. bottomOverlap = maxPt.pos + maxPt.dp + maxPt.size - minPt.pmax;
  21110. // check for min overlap first, so that we always
  21111. // see the largest labels
  21112. // allow for .01px overlap, so we don't get an
  21113. // infinite loop from rounding errors
  21114. if(topOverlap > 0.01) {
  21115. for(j = grp.length - 1; j >= 0; j--) grp[j].dp += topOverlap;
  21116. donepositioning = false;
  21117. }
  21118. if(bottomOverlap < 0.01) return;
  21119. if(topOverlap < -0.01) {
  21120. // make sure we're not pushing back and forth
  21121. for(j = grp.length - 1; j >= 0; j--) grp[j].dp -= bottomOverlap;
  21122. donepositioning = false;
  21123. }
  21124. if(!donepositioning) return;
  21125. // no room to fix positioning, delete off-screen points
  21126. // first see how many points we need to delete
  21127. var deleteCount = 0;
  21128. for(i = 0; i < grp.length; i++) {
  21129. pti = grp[i];
  21130. if(pti.pos + pti.dp + pti.size > minPt.pmax) deleteCount++;
  21131. }
  21132. // start by deleting points whose data is off screen
  21133. for(i = grp.length - 1; i >= 0; i--) {
  21134. if(deleteCount <= 0) break;
  21135. pti = grp[i];
  21136. // pos has already been constrained to [pmin,pmax]
  21137. // so look for points close to that to delete
  21138. if(pti.pos > minPt.pmax - 1) {
  21139. pti.del = true;
  21140. deleteCount--;
  21141. }
  21142. }
  21143. for(i = 0; i < grp.length; i++) {
  21144. if(deleteCount <= 0) break;
  21145. pti = grp[i];
  21146. // pos has already been constrained to [pmin,pmax]
  21147. // so look for points close to that to delete
  21148. if(pti.pos < minPt.pmin + 1) {
  21149. pti.del = true;
  21150. deleteCount--;
  21151. // shift the whole group minus into this new space
  21152. bottomOverlap = pti.size * 2;
  21153. for(j = grp.length - 1; j >= 0; j--) grp[j].dp -= bottomOverlap;
  21154. }
  21155. }
  21156. // then delete points that go off the bottom
  21157. for(i = grp.length - 1; i >= 0; i--) {
  21158. if(deleteCount <= 0) break;
  21159. pti = grp[i];
  21160. if(pti.pos + pti.dp + pti.size > minPt.pmax) {
  21161. pti.del = true;
  21162. deleteCount--;
  21163. }
  21164. }
  21165. }
  21166. // loop through groups, combining them if they overlap,
  21167. // until nothing moves
  21168. while(!donepositioning && nummoves <= hoverData.length) {
  21169. // to avoid infinite loops, don't move more times
  21170. // than there are traces
  21171. nummoves++;
  21172. // assume nothing will move in this iteration,
  21173. // reverse this if it does
  21174. donepositioning = true;
  21175. i = 0;
  21176. while(i < pointgroups.length - 1) {
  21177. // the higher (g0) and lower (g1) point group
  21178. var g0 = pointgroups[i];
  21179. var g1 = pointgroups[i + 1];
  21180. // the lowest point in the higher group (p0)
  21181. // the highest point in the lower group (p1)
  21182. var p0 = g0[g0.length - 1];
  21183. var p1 = g1[0];
  21184. topOverlap = p0.pos + p0.dp + p0.size - p1.pos - p1.dp + p1.size;
  21185. // Only group points that lie on the same axes
  21186. if(topOverlap > 0.01 && (p0.pmin === p1.pmin) && (p0.pmax === p1.pmax)) {
  21187. // push the new point(s) added to this group out of the way
  21188. for(j = g1.length - 1; j >= 0; j--) g1[j].dp += topOverlap;
  21189. // add them to the group
  21190. g0.push.apply(g0, g1);
  21191. pointgroups.splice(i + 1, 1);
  21192. // adjust for minimum average movement
  21193. sumdp = 0;
  21194. for(j = g0.length - 1; j >= 0; j--) sumdp += g0[j].dp;
  21195. bottomOverlap = sumdp / g0.length;
  21196. for(j = g0.length - 1; j >= 0; j--) g0[j].dp -= bottomOverlap;
  21197. donepositioning = false;
  21198. }
  21199. else i++;
  21200. }
  21201. // check if we're going off the plot on either side and fix
  21202. pointgroups.forEach(constrainGroup);
  21203. }
  21204. // now put these offsets into hoverData
  21205. for(i = pointgroups.length - 1; i >= 0; i--) {
  21206. var grp = pointgroups[i];
  21207. for(j = grp.length - 1; j >= 0; j--) {
  21208. var pt = grp[j];
  21209. var hoverPt = hoverData[pt.i];
  21210. hoverPt.offset = pt.dp;
  21211. hoverPt.del = pt.del;
  21212. }
  21213. }
  21214. }
  21215. function alignHoverText(hoverLabels, rotateLabels) {
  21216. // finally set the text positioning relative to the data and draw the
  21217. // box around it
  21218. hoverLabels.each(function(d) {
  21219. var g = d3.select(this);
  21220. if(d.del) {
  21221. g.remove();
  21222. return;
  21223. }
  21224. var horzSign = d.anchor === 'end' ? -1 : 1;
  21225. var tx = g.select('text.nums');
  21226. var alignShift = {start: 1, end: -1, middle: 0}[d.anchor];
  21227. var txx = alignShift * (HOVERARROWSIZE + HOVERTEXTPAD);
  21228. var tx2x = txx + alignShift * (d.txwidth + HOVERTEXTPAD);
  21229. var offsetX = 0;
  21230. var offsetY = d.offset;
  21231. if(d.anchor === 'middle') {
  21232. txx -= d.tx2width / 2;
  21233. tx2x += d.txwidth / 2 + HOVERTEXTPAD;
  21234. }
  21235. if(rotateLabels) {
  21236. offsetY *= -YSHIFTY;
  21237. offsetX = d.offset * YSHIFTX;
  21238. }
  21239. g.select('path').attr('d', d.anchor === 'middle' ?
  21240. // middle aligned: rect centered on data
  21241. ('M-' + (d.bx / 2 + d.tx2width / 2) + ',' + (offsetY - d.by / 2) +
  21242. 'h' + d.bx + 'v' + d.by + 'h-' + d.bx + 'Z') :
  21243. // left or right aligned: side rect with arrow to data
  21244. ('M0,0L' + (horzSign * HOVERARROWSIZE + offsetX) + ',' + (HOVERARROWSIZE + offsetY) +
  21245. 'v' + (d.by / 2 - HOVERARROWSIZE) +
  21246. 'h' + (horzSign * d.bx) +
  21247. 'v-' + d.by +
  21248. 'H' + (horzSign * HOVERARROWSIZE + offsetX) +
  21249. 'V' + (offsetY - HOVERARROWSIZE) +
  21250. 'Z'));
  21251. tx.call(svgTextUtils.positionText,
  21252. txx + offsetX, offsetY + d.ty0 - d.by / 2 + HOVERTEXTPAD);
  21253. if(d.tx2width) {
  21254. g.select('text.name')
  21255. .call(svgTextUtils.positionText,
  21256. tx2x + alignShift * HOVERTEXTPAD + offsetX,
  21257. offsetY + d.ty0 - d.by / 2 + HOVERTEXTPAD);
  21258. g.select('rect')
  21259. .call(Drawing.setRect,
  21260. tx2x + (alignShift - 1) * d.tx2width / 2 + offsetX,
  21261. offsetY - d.by / 2 - 1,
  21262. d.tx2width, d.by + 2);
  21263. }
  21264. });
  21265. }
  21266. function cleanPoint(d, hovermode) {
  21267. var index = d.index;
  21268. var trace = d.trace || {};
  21269. var cd0 = d.cd[0];
  21270. var cd = d.cd[index] || {};
  21271. var getVal = Array.isArray(index) ?
  21272. function(calcKey, traceKey) {
  21273. return Lib.castOption(cd0, index, calcKey) ||
  21274. Lib.extractOption({}, trace, '', traceKey);
  21275. } :
  21276. function(calcKey, traceKey) {
  21277. return Lib.extractOption(cd, trace, calcKey, traceKey);
  21278. };
  21279. function fill(key, calcKey, traceKey) {
  21280. var val = getVal(calcKey, traceKey);
  21281. if(val) d[key] = val;
  21282. }
  21283. fill('hoverinfo', 'hi', 'hoverinfo');
  21284. fill('bgcolor', 'hbg', 'hoverlabel.bgcolor');
  21285. fill('borderColor', 'hbc', 'hoverlabel.bordercolor');
  21286. fill('fontFamily', 'htf', 'hoverlabel.font.family');
  21287. fill('fontSize', 'hts', 'hoverlabel.font.size');
  21288. fill('fontColor', 'htc', 'hoverlabel.font.color');
  21289. fill('nameLength', 'hnl', 'hoverlabel.namelength');
  21290. d.posref = hovermode === 'y' ?
  21291. (d.xa._offset + (d.x0 + d.x1) / 2) :
  21292. (d.ya._offset + (d.y0 + d.y1) / 2);
  21293. // then constrain all the positions to be on the plot
  21294. d.x0 = Lib.constrain(d.x0, 0, d.xa._length);
  21295. d.x1 = Lib.constrain(d.x1, 0, d.xa._length);
  21296. d.y0 = Lib.constrain(d.y0, 0, d.ya._length);
  21297. d.y1 = Lib.constrain(d.y1, 0, d.ya._length);
  21298. // and convert the x and y label values into formatted text
  21299. if(d.xLabelVal !== undefined) {
  21300. d.xLabel = ('xLabel' in d) ? d.xLabel : Axes.hoverLabelText(d.xa, d.xLabelVal);
  21301. d.xVal = d.xa.c2d(d.xLabelVal);
  21302. }
  21303. if(d.yLabelVal !== undefined) {
  21304. d.yLabel = ('yLabel' in d) ? d.yLabel : Axes.hoverLabelText(d.ya, d.yLabelVal);
  21305. d.yVal = d.ya.c2d(d.yLabelVal);
  21306. }
  21307. // Traces like heatmaps generate the zLabel in their hoverPoints function
  21308. if(d.zLabelVal !== undefined && d.zLabel === undefined) {
  21309. d.zLabel = String(d.zLabelVal);
  21310. }
  21311. // for box means and error bars, add the range to the label
  21312. if(!isNaN(d.xerr) && !(d.xa.type === 'log' && d.xerr <= 0)) {
  21313. var xeText = Axes.tickText(d.xa, d.xa.c2l(d.xerr), 'hover').text;
  21314. if(d.xerrneg !== undefined) {
  21315. d.xLabel += ' +' + xeText + ' / -' +
  21316. Axes.tickText(d.xa, d.xa.c2l(d.xerrneg), 'hover').text;
  21317. }
  21318. else d.xLabel += ' ± ' + xeText;
  21319. // small distance penalty for error bars, so that if there are
  21320. // traces with errors and some without, the error bar label will
  21321. // hoist up to the point
  21322. if(hovermode === 'x') d.distance += 1;
  21323. }
  21324. if(!isNaN(d.yerr) && !(d.ya.type === 'log' && d.yerr <= 0)) {
  21325. var yeText = Axes.tickText(d.ya, d.ya.c2l(d.yerr), 'hover').text;
  21326. if(d.yerrneg !== undefined) {
  21327. d.yLabel += ' +' + yeText + ' / -' +
  21328. Axes.tickText(d.ya, d.ya.c2l(d.yerrneg), 'hover').text;
  21329. }
  21330. else d.yLabel += ' ± ' + yeText;
  21331. if(hovermode === 'y') d.distance += 1;
  21332. }
  21333. var infomode = d.hoverinfo || d.trace.hoverinfo;
  21334. if(infomode !== 'all') {
  21335. infomode = Array.isArray(infomode) ? infomode : infomode.split('+');
  21336. if(infomode.indexOf('x') === -1) d.xLabel = undefined;
  21337. if(infomode.indexOf('y') === -1) d.yLabel = undefined;
  21338. if(infomode.indexOf('z') === -1) d.zLabel = undefined;
  21339. if(infomode.indexOf('text') === -1) d.text = undefined;
  21340. if(infomode.indexOf('name') === -1) d.name = undefined;
  21341. }
  21342. return d;
  21343. }
  21344. function createSpikelines(closestPoints, opts) {
  21345. var container = opts.container;
  21346. var fullLayout = opts.fullLayout;
  21347. var evt = opts.event;
  21348. var showY = !!closestPoints.hLinePoint;
  21349. var showX = !!closestPoints.vLinePoint;
  21350. var xa, ya;
  21351. // Remove old spikeline items
  21352. container.selectAll('.spikeline').remove();
  21353. if(!(showX || showY)) return;
  21354. var contrastColor = Color.combine(fullLayout.plot_bgcolor, fullLayout.paper_bgcolor);
  21355. // Horizontal line (to y-axis)
  21356. if(showY) {
  21357. var hLinePoint = closestPoints.hLinePoint;
  21358. var hLinePointX, hLinePointY;
  21359. xa = hLinePoint && hLinePoint.xa;
  21360. ya = hLinePoint && hLinePoint.ya;
  21361. var ySnap = ya.spikesnap;
  21362. if(ySnap === 'cursor') {
  21363. hLinePointX = evt.pointerX;
  21364. hLinePointY = evt.pointerY;
  21365. } else {
  21366. hLinePointX = xa._offset + hLinePoint.x;
  21367. hLinePointY = ya._offset + hLinePoint.y;
  21368. }
  21369. var dfltHLineColor = tinycolor.readability(hLinePoint.color, contrastColor) < 1.5 ?
  21370. Color.contrast(contrastColor) : hLinePoint.color;
  21371. var yMode = ya.spikemode;
  21372. var yThickness = ya.spikethickness;
  21373. var yColor = ya.spikecolor || dfltHLineColor;
  21374. var yBB = ya._boundingBox;
  21375. var xEdge = ((yBB.left + yBB.right) / 2) < hLinePointX ? yBB.right : yBB.left;
  21376. var xBase, xEndSpike;
  21377. if(yMode.indexOf('toaxis') !== -1 || yMode.indexOf('across') !== -1) {
  21378. if(yMode.indexOf('toaxis') !== -1) {
  21379. xBase = xEdge;
  21380. xEndSpike = hLinePointX;
  21381. }
  21382. if(yMode.indexOf('across') !== -1) {
  21383. xBase = ya._counterSpan[0];
  21384. xEndSpike = ya._counterSpan[1];
  21385. }
  21386. // Foreground horizontal line (to y-axis)
  21387. container.insert('line', ':first-child')
  21388. .attr({
  21389. x1: xBase,
  21390. x2: xEndSpike,
  21391. y1: hLinePointY,
  21392. y2: hLinePointY,
  21393. 'stroke-width': yThickness,
  21394. stroke: yColor,
  21395. 'stroke-dasharray': Drawing.dashStyle(ya.spikedash, yThickness)
  21396. })
  21397. .classed('spikeline', true)
  21398. .classed('crisp', true);
  21399. // Background horizontal Line (to y-axis)
  21400. container.insert('line', ':first-child')
  21401. .attr({
  21402. x1: xBase,
  21403. x2: xEndSpike,
  21404. y1: hLinePointY,
  21405. y2: hLinePointY,
  21406. 'stroke-width': yThickness + 2,
  21407. stroke: contrastColor
  21408. })
  21409. .classed('spikeline', true)
  21410. .classed('crisp', true);
  21411. }
  21412. // Y axis marker
  21413. if(yMode.indexOf('marker') !== -1) {
  21414. container.insert('circle', ':first-child')
  21415. .attr({
  21416. cx: xEdge + (ya.side !== 'right' ? yThickness : -yThickness),
  21417. cy: hLinePointY,
  21418. r: yThickness,
  21419. fill: yColor
  21420. })
  21421. .classed('spikeline', true);
  21422. }
  21423. }
  21424. if(showX) {
  21425. var vLinePoint = closestPoints.vLinePoint;
  21426. var vLinePointX, vLinePointY;
  21427. xa = vLinePoint && vLinePoint.xa;
  21428. ya = vLinePoint && vLinePoint.ya;
  21429. var xSnap = xa.spikesnap;
  21430. if(xSnap === 'cursor') {
  21431. vLinePointX = evt.pointerX;
  21432. vLinePointY = evt.pointerY;
  21433. } else {
  21434. vLinePointX = xa._offset + vLinePoint.x;
  21435. vLinePointY = ya._offset + vLinePoint.y;
  21436. }
  21437. var dfltVLineColor = tinycolor.readability(vLinePoint.color, contrastColor) < 1.5 ?
  21438. Color.contrast(contrastColor) : vLinePoint.color;
  21439. var xMode = xa.spikemode;
  21440. var xThickness = xa.spikethickness;
  21441. var xColor = xa.spikecolor || dfltVLineColor;
  21442. var xBB = xa._boundingBox;
  21443. var yEdge = ((xBB.top + xBB.bottom) / 2) < vLinePointY ? xBB.bottom : xBB.top;
  21444. var yBase, yEndSpike;
  21445. if(xMode.indexOf('toaxis') !== -1 || xMode.indexOf('across') !== -1) {
  21446. if(xMode.indexOf('toaxis') !== -1) {
  21447. yBase = yEdge;
  21448. yEndSpike = vLinePointY;
  21449. }
  21450. if(xMode.indexOf('across') !== -1) {
  21451. yBase = xa._counterSpan[0];
  21452. yEndSpike = xa._counterSpan[1];
  21453. }
  21454. // Foreground vertical line (to x-axis)
  21455. container.insert('line', ':first-child')
  21456. .attr({
  21457. x1: vLinePointX,
  21458. x2: vLinePointX,
  21459. y1: yBase,
  21460. y2: yEndSpike,
  21461. 'stroke-width': xThickness,
  21462. stroke: xColor,
  21463. 'stroke-dasharray': Drawing.dashStyle(xa.spikedash, xThickness)
  21464. })
  21465. .classed('spikeline', true)
  21466. .classed('crisp', true);
  21467. // Background vertical line (to x-axis)
  21468. container.insert('line', ':first-child')
  21469. .attr({
  21470. x1: vLinePointX,
  21471. x2: vLinePointX,
  21472. y1: yBase,
  21473. y2: yEndSpike,
  21474. 'stroke-width': xThickness + 2,
  21475. stroke: contrastColor
  21476. })
  21477. .classed('spikeline', true)
  21478. .classed('crisp', true);
  21479. }
  21480. // X axis marker
  21481. if(xMode.indexOf('marker') !== -1) {
  21482. container.insert('circle', ':first-child')
  21483. .attr({
  21484. cx: vLinePointX,
  21485. cy: yEdge - (xa.side !== 'top' ? xThickness : -xThickness),
  21486. r: xThickness,
  21487. fill: xColor
  21488. })
  21489. .classed('spikeline', true);
  21490. }
  21491. }
  21492. }
  21493. function hoverChanged(gd, evt, oldhoverdata) {
  21494. // don't emit any events if nothing changed
  21495. if(!oldhoverdata || oldhoverdata.length !== gd._hoverdata.length) return true;
  21496. for(var i = oldhoverdata.length - 1; i >= 0; i--) {
  21497. var oldPt = oldhoverdata[i];
  21498. var newPt = gd._hoverdata[i];
  21499. if(oldPt.curveNumber !== newPt.curveNumber ||
  21500. String(oldPt.pointNumber) !== String(newPt.pointNumber)) {
  21501. return true;
  21502. }
  21503. }
  21504. return false;
  21505. }
  21506. function spikesChanged(gd, oldspikepoints) {
  21507. // don't relayout the plot because of new spikelines if spikelines points didn't change
  21508. if(!oldspikepoints) return true;
  21509. if(oldspikepoints.vLinePoint !== gd._spikepoints.vLinePoint ||
  21510. oldspikepoints.hLinePoint !== gd._spikepoints.hLinePoint
  21511. ) return true;
  21512. return false;
  21513. }
  21514. },{"../../lib":169,"../../lib/events":162,"../../lib/override_cursor":181,"../../lib/svg_text_utils":191,"../../plots/cartesian/axes":214,"../../registry":259,"../color":50,"../dragelement":72,"../drawing":75,"./constants":87,"./helpers":89,"d3":16,"fast-isnumeric":18,"tinycolor2":33}],91:[function(_dereq_,module,exports){
  21515. /**
  21516. * Copyright 2012-2018, Plotly, Inc.
  21517. * All rights reserved.
  21518. *
  21519. * This source code is licensed under the MIT license found in the
  21520. * LICENSE file in the root directory of this source tree.
  21521. */
  21522. 'use strict';
  21523. var Lib = _dereq_('../../lib');
  21524. module.exports = function handleHoverLabelDefaults(contIn, contOut, coerce, opts) {
  21525. opts = opts || {};
  21526. coerce('hoverlabel.bgcolor', opts.bgcolor);
  21527. coerce('hoverlabel.bordercolor', opts.bordercolor);
  21528. coerce('hoverlabel.namelength', opts.namelength);
  21529. Lib.coerceFont(coerce, 'hoverlabel.font', opts.font);
  21530. };
  21531. },{"../../lib":169}],92:[function(_dereq_,module,exports){
  21532. /**
  21533. * Copyright 2012-2018, Plotly, Inc.
  21534. * All rights reserved.
  21535. *
  21536. * This source code is licensed under the MIT license found in the
  21537. * LICENSE file in the root directory of this source tree.
  21538. */
  21539. 'use strict';
  21540. var d3 = _dereq_('d3');
  21541. var Lib = _dereq_('../../lib');
  21542. var dragElement = _dereq_('../dragelement');
  21543. var helpers = _dereq_('./helpers');
  21544. var layoutAttributes = _dereq_('./layout_attributes');
  21545. module.exports = {
  21546. moduleType: 'component',
  21547. name: 'fx',
  21548. constants: _dereq_('./constants'),
  21549. schema: {
  21550. layout: layoutAttributes
  21551. },
  21552. attributes: _dereq_('./attributes'),
  21553. layoutAttributes: layoutAttributes,
  21554. supplyLayoutGlobalDefaults: _dereq_('./layout_global_defaults'),
  21555. supplyDefaults: _dereq_('./defaults'),
  21556. supplyLayoutDefaults: _dereq_('./layout_defaults'),
  21557. calc: _dereq_('./calc'),
  21558. getDistanceFunction: helpers.getDistanceFunction,
  21559. getClosest: helpers.getClosest,
  21560. inbox: helpers.inbox,
  21561. quadrature: helpers.quadrature,
  21562. appendArrayPointValue: helpers.appendArrayPointValue,
  21563. castHoverOption: castHoverOption,
  21564. castHoverinfo: castHoverinfo,
  21565. hover: _dereq_('./hover').hover,
  21566. unhover: dragElement.unhover,
  21567. loneHover: _dereq_('./hover').loneHover,
  21568. loneUnhover: loneUnhover,
  21569. click: _dereq_('./click')
  21570. };
  21571. function loneUnhover(containerOrSelection) {
  21572. // duck type whether the arg is a d3 selection because ie9 doesn't
  21573. // handle instanceof like modern browsers do.
  21574. var selection = Lib.isD3Selection(containerOrSelection) ?
  21575. containerOrSelection :
  21576. d3.select(containerOrSelection);
  21577. selection.selectAll('g.hovertext').remove();
  21578. selection.selectAll('.spikeline').remove();
  21579. }
  21580. // helpers for traces that use Fx.loneHover
  21581. function castHoverOption(trace, ptNumber, attr) {
  21582. return Lib.castOption(trace, ptNumber, 'hoverlabel.' + attr);
  21583. }
  21584. function castHoverinfo(trace, fullLayout, ptNumber) {
  21585. function _coerce(val) {
  21586. return Lib.coerceHoverinfo({hoverinfo: val}, {_module: trace._module}, fullLayout);
  21587. }
  21588. return Lib.castOption(trace, ptNumber, 'hoverinfo', _coerce);
  21589. }
  21590. },{"../../lib":169,"../dragelement":72,"./attributes":84,"./calc":85,"./click":86,"./constants":87,"./defaults":88,"./helpers":89,"./hover":90,"./layout_attributes":93,"./layout_defaults":94,"./layout_global_defaults":95,"d3":16}],93:[function(_dereq_,module,exports){
  21591. /**
  21592. * Copyright 2012-2018, Plotly, Inc.
  21593. * All rights reserved.
  21594. *
  21595. * This source code is licensed under the MIT license found in the
  21596. * LICENSE file in the root directory of this source tree.
  21597. */
  21598. 'use strict';
  21599. var constants = _dereq_('./constants');
  21600. var fontAttrs = _dereq_('../../plots/font_attributes')({
  21601. editType: 'none',
  21602. });
  21603. fontAttrs.family.dflt = constants.HOVERFONT;
  21604. fontAttrs.size.dflt = constants.HOVERFONTSIZE;
  21605. module.exports = {
  21606. clickmode: {
  21607. valType: 'flaglist',
  21608. flags: ['event', 'select'],
  21609. dflt: 'event',
  21610. editType: 'plot',
  21611. extras: ['none'],
  21612. },
  21613. dragmode: {
  21614. valType: 'enumerated',
  21615. values: ['zoom', 'pan', 'select', 'lasso', 'orbit', 'turntable'],
  21616. dflt: 'zoom',
  21617. editType: 'modebar',
  21618. },
  21619. hovermode: {
  21620. valType: 'enumerated',
  21621. values: ['x', 'y', 'closest', false],
  21622. editType: 'modebar',
  21623. },
  21624. hoverdistance: {
  21625. valType: 'integer',
  21626. min: -1,
  21627. dflt: 20,
  21628. editType: 'none',
  21629. },
  21630. spikedistance: {
  21631. valType: 'integer',
  21632. min: -1,
  21633. dflt: 20,
  21634. editType: 'none',
  21635. },
  21636. hoverlabel: {
  21637. bgcolor: {
  21638. valType: 'color',
  21639. editType: 'none',
  21640. },
  21641. bordercolor: {
  21642. valType: 'color',
  21643. editType: 'none',
  21644. },
  21645. font: fontAttrs,
  21646. namelength: {
  21647. valType: 'integer',
  21648. min: -1,
  21649. dflt: 15,
  21650. editType: 'none',
  21651. },
  21652. editType: 'none'
  21653. },
  21654. selectdirection: {
  21655. valType: 'enumerated',
  21656. values: ['h', 'v', 'd', 'any'],
  21657. dflt: 'any',
  21658. editType: 'none'
  21659. }
  21660. };
  21661. },{"../../plots/font_attributes":240,"./constants":87}],94:[function(_dereq_,module,exports){
  21662. /**
  21663. * Copyright 2012-2018, Plotly, Inc.
  21664. * All rights reserved.
  21665. *
  21666. * This source code is licensed under the MIT license found in the
  21667. * LICENSE file in the root directory of this source tree.
  21668. */
  21669. 'use strict';
  21670. var Lib = _dereq_('../../lib');
  21671. var layoutAttributes = _dereq_('./layout_attributes');
  21672. module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {
  21673. function coerce(attr, dflt) {
  21674. return Lib.coerce(layoutIn, layoutOut, layoutAttributes, attr, dflt);
  21675. }
  21676. var clickmode = coerce('clickmode');
  21677. var dragMode = coerce('dragmode');
  21678. if(dragMode === 'select') coerce('selectdirection');
  21679. var hovermodeDflt;
  21680. if(layoutOut._has('cartesian')) {
  21681. if(clickmode.indexOf('select') > -1) {
  21682. hovermodeDflt = 'closest';
  21683. } else {
  21684. // flag for 'horizontal' plots:
  21685. // determines the state of the mode bar 'compare' hovermode button
  21686. layoutOut._isHoriz = isHoriz(fullData);
  21687. hovermodeDflt = layoutOut._isHoriz ? 'y' : 'x';
  21688. }
  21689. }
  21690. else hovermodeDflt = 'closest';
  21691. var hoverMode = coerce('hovermode', hovermodeDflt);
  21692. if(hoverMode) {
  21693. coerce('hoverdistance');
  21694. coerce('spikedistance');
  21695. }
  21696. // if only mapbox or geo subplots is present on graph,
  21697. // reset 'zoom' dragmode to 'pan' until 'zoom' is implemented,
  21698. // so that the correct modebar button is active
  21699. var hasMapbox = layoutOut._has('mapbox');
  21700. var hasGeo = layoutOut._has('geo');
  21701. var len = layoutOut._basePlotModules.length;
  21702. if(layoutOut.dragmode === 'zoom' && (
  21703. ((hasMapbox || hasGeo) && len === 1) ||
  21704. (hasMapbox && hasGeo && len === 2)
  21705. )) {
  21706. layoutOut.dragmode = 'pan';
  21707. }
  21708. };
  21709. function isHoriz(fullData) {
  21710. var out = true;
  21711. for(var i = 0; i < fullData.length; i++) {
  21712. var trace = fullData[i];
  21713. if(trace.orientation !== 'h') {
  21714. out = false;
  21715. break;
  21716. }
  21717. }
  21718. return out;
  21719. }
  21720. },{"../../lib":169,"./layout_attributes":93}],95:[function(_dereq_,module,exports){
  21721. /**
  21722. * Copyright 2012-2018, Plotly, Inc.
  21723. * All rights reserved.
  21724. *
  21725. * This source code is licensed under the MIT license found in the
  21726. * LICENSE file in the root directory of this source tree.
  21727. */
  21728. 'use strict';
  21729. var Lib = _dereq_('../../lib');
  21730. var handleHoverLabelDefaults = _dereq_('./hoverlabel_defaults');
  21731. var layoutAttributes = _dereq_('./layout_attributes');
  21732. module.exports = function supplyLayoutGlobalDefaults(layoutIn, layoutOut) {
  21733. function coerce(attr, dflt) {
  21734. return Lib.coerce(layoutIn, layoutOut, layoutAttributes, attr, dflt);
  21735. }
  21736. handleHoverLabelDefaults(layoutIn, layoutOut, coerce);
  21737. };
  21738. },{"../../lib":169,"./hoverlabel_defaults":91,"./layout_attributes":93}],96:[function(_dereq_,module,exports){
  21739. /**
  21740. * Copyright 2012-2018, Plotly, Inc.
  21741. * All rights reserved.
  21742. *
  21743. * This source code is licensed under the MIT license found in the
  21744. * LICENSE file in the root directory of this source tree.
  21745. */
  21746. 'use strict';
  21747. var Lib = _dereq_('../../lib');
  21748. var counterRegex = _dereq_('../../lib/regex').counter;
  21749. var domainAttrs = _dereq_('../../plots/domain').attributes;
  21750. var cartesianIdRegex = _dereq_('../../plots/cartesian/constants').idRegex;
  21751. var Template = _dereq_('../../plot_api/plot_template');
  21752. var gridAttrs = {
  21753. rows: {
  21754. valType: 'integer',
  21755. min: 1,
  21756. editType: 'plot',
  21757. },
  21758. roworder: {
  21759. valType: 'enumerated',
  21760. values: ['top to bottom', 'bottom to top'],
  21761. dflt: 'top to bottom',
  21762. editType: 'plot',
  21763. },
  21764. columns: {
  21765. valType: 'integer',
  21766. min: 1,
  21767. editType: 'plot',
  21768. },
  21769. subplots: {
  21770. valType: 'info_array',
  21771. freeLength: true,
  21772. dimensions: 2,
  21773. items: {valType: 'enumerated', values: [counterRegex('xy').toString(), ''], editType: 'plot'},
  21774. editType: 'plot',
  21775. },
  21776. xaxes: {
  21777. valType: 'info_array',
  21778. freeLength: true,
  21779. items: {valType: 'enumerated', values: [cartesianIdRegex.x.toString(), ''], editType: 'plot'},
  21780. editType: 'plot',
  21781. },
  21782. yaxes: {
  21783. valType: 'info_array',
  21784. freeLength: true,
  21785. items: {valType: 'enumerated', values: [cartesianIdRegex.y.toString(), ''], editType: 'plot'},
  21786. editType: 'plot',
  21787. },
  21788. pattern: {
  21789. valType: 'enumerated',
  21790. values: ['independent', 'coupled'],
  21791. dflt: 'coupled',
  21792. editType: 'plot',
  21793. },
  21794. xgap: {
  21795. valType: 'number',
  21796. min: 0,
  21797. max: 1,
  21798. editType: 'plot',
  21799. },
  21800. ygap: {
  21801. valType: 'number',
  21802. min: 0,
  21803. max: 1,
  21804. editType: 'plot',
  21805. },
  21806. domain: domainAttrs({name: 'grid', editType: 'plot', noGridCell: true}, {
  21807. }),
  21808. xside: {
  21809. valType: 'enumerated',
  21810. values: ['bottom', 'bottom plot', 'top plot', 'top'],
  21811. dflt: 'bottom plot',
  21812. editType: 'plot',
  21813. },
  21814. yside: {
  21815. valType: 'enumerated',
  21816. values: ['left', 'left plot', 'right plot', 'right'],
  21817. dflt: 'left plot',
  21818. editType: 'plot',
  21819. },
  21820. editType: 'plot'
  21821. };
  21822. function getAxes(layout, grid, axLetter) {
  21823. var gridVal = grid[axLetter + 'axes'];
  21824. var splomVal = Object.keys((layout._splomAxes || {})[axLetter] || {});
  21825. if(Array.isArray(gridVal)) return gridVal;
  21826. if(splomVal.length) return splomVal;
  21827. }
  21828. // the shape of the grid - this needs to be done BEFORE supplyDataDefaults
  21829. // so that non-subplot traces can place themselves in the grid
  21830. function sizeDefaults(layoutIn, layoutOut) {
  21831. var gridIn = layoutIn.grid || {};
  21832. var xAxes = getAxes(layoutOut, gridIn, 'x');
  21833. var yAxes = getAxes(layoutOut, gridIn, 'y');
  21834. if(!layoutIn.grid && !xAxes && !yAxes) return;
  21835. var hasSubplotGrid = Array.isArray(gridIn.subplots) && Array.isArray(gridIn.subplots[0]);
  21836. var hasXaxes = Array.isArray(xAxes);
  21837. var hasYaxes = Array.isArray(yAxes);
  21838. var isSplomGenerated = (
  21839. hasXaxes && xAxes !== gridIn.xaxes &&
  21840. hasYaxes && yAxes !== gridIn.yaxes
  21841. );
  21842. var dfltRows, dfltColumns;
  21843. if(hasSubplotGrid) {
  21844. dfltRows = gridIn.subplots.length;
  21845. dfltColumns = gridIn.subplots[0].length;
  21846. }
  21847. else {
  21848. if(hasYaxes) dfltRows = yAxes.length;
  21849. if(hasXaxes) dfltColumns = xAxes.length;
  21850. }
  21851. var gridOut = Template.newContainer(layoutOut, 'grid');
  21852. function coerce(attr, dflt) {
  21853. return Lib.coerce(gridIn, gridOut, gridAttrs, attr, dflt);
  21854. }
  21855. var rows = coerce('rows', dfltRows);
  21856. var columns = coerce('columns', dfltColumns);
  21857. if(!(rows * columns > 1)) {
  21858. delete layoutOut.grid;
  21859. return;
  21860. }
  21861. if(!hasSubplotGrid && !hasXaxes && !hasYaxes) {
  21862. var useDefaultSubplots = coerce('pattern') === 'independent';
  21863. if(useDefaultSubplots) hasSubplotGrid = true;
  21864. }
  21865. gridOut._hasSubplotGrid = hasSubplotGrid;
  21866. var rowOrder = coerce('roworder');
  21867. var reversed = rowOrder === 'top to bottom';
  21868. var dfltGapX = hasSubplotGrid ? 0.2 : 0.1;
  21869. var dfltGapY = hasSubplotGrid ? 0.3 : 0.1;
  21870. var dfltSideX, dfltSideY;
  21871. if(isSplomGenerated && layoutOut._splomGridDflt) {
  21872. dfltSideX = layoutOut._splomGridDflt.xside;
  21873. dfltSideY = layoutOut._splomGridDflt.yside;
  21874. }
  21875. gridOut._domains = {
  21876. x: fillGridPositions('x', coerce, dfltGapX, dfltSideX, columns),
  21877. y: fillGridPositions('y', coerce, dfltGapY, dfltSideY, rows, reversed)
  21878. };
  21879. }
  21880. // coerce x or y sizing attributes and return an array of domains for this direction
  21881. function fillGridPositions(axLetter, coerce, dfltGap, dfltSide, len, reversed) {
  21882. var dirGap = coerce(axLetter + 'gap', dfltGap);
  21883. var domain = coerce('domain.' + axLetter);
  21884. coerce(axLetter + 'side', dfltSide);
  21885. var out = new Array(len);
  21886. var start = domain[0];
  21887. var step = (domain[1] - start) / (len - dirGap);
  21888. var cellDomain = step * (1 - dirGap);
  21889. for(var i = 0; i < len; i++) {
  21890. var cellStart = start + step * i;
  21891. out[reversed ? (len - 1 - i) : i] = [cellStart, cellStart + cellDomain];
  21892. }
  21893. return out;
  21894. }
  21895. // the (cartesian) contents of the grid - this needs to happen AFTER supplyDataDefaults
  21896. // so that we know what cartesian subplots are available
  21897. function contentDefaults(layoutIn, layoutOut) {
  21898. var gridOut = layoutOut.grid;
  21899. // make sure we got to the end of handleGridSizing
  21900. if(!gridOut || !gridOut._domains) return;
  21901. var gridIn = layoutIn.grid || {};
  21902. var subplots = layoutOut._subplots;
  21903. var hasSubplotGrid = gridOut._hasSubplotGrid;
  21904. var rows = gridOut.rows;
  21905. var columns = gridOut.columns;
  21906. var useDefaultSubplots = gridOut.pattern === 'independent';
  21907. var i, j, xId, yId, subplotId, subplotsOut, yPos;
  21908. var axisMap = gridOut._axisMap = {};
  21909. if(hasSubplotGrid) {
  21910. var subplotsIn = gridIn.subplots || [];
  21911. subplotsOut = gridOut.subplots = new Array(rows);
  21912. var index = 1;
  21913. for(i = 0; i < rows; i++) {
  21914. var rowOut = subplotsOut[i] = new Array(columns);
  21915. var rowIn = subplotsIn[i] || [];
  21916. for(j = 0; j < columns; j++) {
  21917. if(useDefaultSubplots) {
  21918. subplotId = (index === 1) ? 'xy' : ('x' + index + 'y' + index);
  21919. index++;
  21920. }
  21921. else subplotId = rowIn[j];
  21922. rowOut[j] = '';
  21923. if(subplots.cartesian.indexOf(subplotId) !== -1) {
  21924. yPos = subplotId.indexOf('y');
  21925. xId = subplotId.slice(0, yPos);
  21926. yId = subplotId.slice(yPos);
  21927. if((axisMap[xId] !== undefined && axisMap[xId] !== j) ||
  21928. (axisMap[yId] !== undefined && axisMap[yId] !== i)
  21929. ) {
  21930. continue;
  21931. }
  21932. rowOut[j] = subplotId;
  21933. axisMap[xId] = j;
  21934. axisMap[yId] = i;
  21935. }
  21936. }
  21937. }
  21938. }
  21939. else {
  21940. var xAxes = getAxes(layoutOut, gridIn, 'x');
  21941. var yAxes = getAxes(layoutOut, gridIn, 'y');
  21942. gridOut.xaxes = fillGridAxes(xAxes, subplots.xaxis, columns, axisMap, 'x');
  21943. gridOut.yaxes = fillGridAxes(yAxes, subplots.yaxis, rows, axisMap, 'y');
  21944. }
  21945. var anchors = gridOut._anchors = {};
  21946. var reversed = gridOut.roworder === 'top to bottom';
  21947. for(var axisId in axisMap) {
  21948. var axLetter = axisId.charAt(0);
  21949. var side = gridOut[axLetter + 'side'];
  21950. var i0, inc, iFinal;
  21951. if(side.length < 8) {
  21952. // grid edge - ie not "* plot" - make these as free axes
  21953. // since we're not guaranteed to have a subplot there at all
  21954. anchors[axisId] = 'free';
  21955. }
  21956. else if(axLetter === 'x') {
  21957. if((side.charAt(0) === 't') === reversed) {
  21958. i0 = 0;
  21959. inc = 1;
  21960. iFinal = rows;
  21961. }
  21962. else {
  21963. i0 = rows - 1;
  21964. inc = -1;
  21965. iFinal = -1;
  21966. }
  21967. if(hasSubplotGrid) {
  21968. var column = axisMap[axisId];
  21969. for(i = i0; i !== iFinal; i += inc) {
  21970. subplotId = subplotsOut[i][column];
  21971. if(!subplotId) continue;
  21972. yPos = subplotId.indexOf('y');
  21973. if(subplotId.slice(0, yPos) === axisId) {
  21974. anchors[axisId] = subplotId.slice(yPos);
  21975. break;
  21976. }
  21977. }
  21978. }
  21979. else {
  21980. for(i = i0; i !== iFinal; i += inc) {
  21981. yId = gridOut.yaxes[i];
  21982. if(subplots.cartesian.indexOf(axisId + yId) !== -1) {
  21983. anchors[axisId] = yId;
  21984. break;
  21985. }
  21986. }
  21987. }
  21988. }
  21989. else {
  21990. if((side.charAt(0) === 'l')) {
  21991. i0 = 0;
  21992. inc = 1;
  21993. iFinal = columns;
  21994. }
  21995. else {
  21996. i0 = columns - 1;
  21997. inc = -1;
  21998. iFinal = -1;
  21999. }
  22000. if(hasSubplotGrid) {
  22001. var row = axisMap[axisId];
  22002. for(i = i0; i !== iFinal; i += inc) {
  22003. subplotId = subplotsOut[row][i];
  22004. if(!subplotId) continue;
  22005. yPos = subplotId.indexOf('y');
  22006. if(subplotId.slice(yPos) === axisId) {
  22007. anchors[axisId] = subplotId.slice(0, yPos);
  22008. break;
  22009. }
  22010. }
  22011. }
  22012. else {
  22013. for(i = i0; i !== iFinal; i += inc) {
  22014. xId = gridOut.xaxes[i];
  22015. if(subplots.cartesian.indexOf(xId + axisId) !== -1) {
  22016. anchors[axisId] = xId;
  22017. break;
  22018. }
  22019. }
  22020. }
  22021. }
  22022. }
  22023. }
  22024. function fillGridAxes(axesIn, axesAllowed, len, axisMap, axLetter) {
  22025. var out = new Array(len);
  22026. var i;
  22027. function fillOneAxis(i, axisId) {
  22028. if(axesAllowed.indexOf(axisId) !== -1 && axisMap[axisId] === undefined) {
  22029. out[i] = axisId;
  22030. axisMap[axisId] = i;
  22031. }
  22032. else out[i] = '';
  22033. }
  22034. if(Array.isArray(axesIn)) {
  22035. for(i = 0; i < len; i++) {
  22036. fillOneAxis(i, axesIn[i]);
  22037. }
  22038. }
  22039. else {
  22040. // default axis list is the first `len` axis ids
  22041. fillOneAxis(0, axLetter);
  22042. for(i = 1; i < len; i++) {
  22043. fillOneAxis(i, axLetter + (i + 1));
  22044. }
  22045. }
  22046. return out;
  22047. }
  22048. module.exports = {
  22049. moduleType: 'component',
  22050. name: 'grid',
  22051. schema: {
  22052. layout: {grid: gridAttrs}
  22053. },
  22054. layoutAttributes: gridAttrs,
  22055. sizeDefaults: sizeDefaults,
  22056. contentDefaults: contentDefaults
  22057. };
  22058. },{"../../lib":169,"../../lib/regex":185,"../../plot_api/plot_template":204,"../../plots/cartesian/constants":219,"../../plots/domain":239}],97:[function(_dereq_,module,exports){
  22059. /**
  22060. * Copyright 2012-2018, Plotly, Inc.
  22061. * All rights reserved.
  22062. *
  22063. * This source code is licensed under the MIT license found in the
  22064. * LICENSE file in the root directory of this source tree.
  22065. */
  22066. 'use strict';
  22067. var cartesianConstants = _dereq_('../../plots/cartesian/constants');
  22068. var templatedArray = _dereq_('../../plot_api/plot_template').templatedArray;
  22069. module.exports = templatedArray('image', {
  22070. visible: {
  22071. valType: 'boolean',
  22072. dflt: true,
  22073. editType: 'arraydraw',
  22074. },
  22075. source: {
  22076. valType: 'string',
  22077. editType: 'arraydraw',
  22078. },
  22079. layer: {
  22080. valType: 'enumerated',
  22081. values: ['below', 'above'],
  22082. dflt: 'above',
  22083. editType: 'arraydraw',
  22084. },
  22085. sizex: {
  22086. valType: 'number',
  22087. dflt: 0,
  22088. editType: 'arraydraw',
  22089. },
  22090. sizey: {
  22091. valType: 'number',
  22092. dflt: 0,
  22093. editType: 'arraydraw',
  22094. },
  22095. sizing: {
  22096. valType: 'enumerated',
  22097. values: ['fill', 'contain', 'stretch'],
  22098. dflt: 'contain',
  22099. editType: 'arraydraw',
  22100. },
  22101. opacity: {
  22102. valType: 'number',
  22103. min: 0,
  22104. max: 1,
  22105. dflt: 1,
  22106. editType: 'arraydraw',
  22107. },
  22108. x: {
  22109. valType: 'any',
  22110. dflt: 0,
  22111. editType: 'arraydraw',
  22112. },
  22113. y: {
  22114. valType: 'any',
  22115. dflt: 0,
  22116. editType: 'arraydraw',
  22117. },
  22118. xanchor: {
  22119. valType: 'enumerated',
  22120. values: ['left', 'center', 'right'],
  22121. dflt: 'left',
  22122. editType: 'arraydraw',
  22123. },
  22124. yanchor: {
  22125. valType: 'enumerated',
  22126. values: ['top', 'middle', 'bottom'],
  22127. dflt: 'top',
  22128. editType: 'arraydraw',
  22129. },
  22130. xref: {
  22131. valType: 'enumerated',
  22132. values: [
  22133. 'paper',
  22134. cartesianConstants.idRegex.x.toString()
  22135. ],
  22136. dflt: 'paper',
  22137. editType: 'arraydraw',
  22138. },
  22139. yref: {
  22140. valType: 'enumerated',
  22141. values: [
  22142. 'paper',
  22143. cartesianConstants.idRegex.y.toString()
  22144. ],
  22145. dflt: 'paper',
  22146. editType: 'arraydraw',
  22147. },
  22148. editType: 'arraydraw'
  22149. });
  22150. },{"../../plot_api/plot_template":204,"../../plots/cartesian/constants":219}],98:[function(_dereq_,module,exports){
  22151. /**
  22152. * Copyright 2012-2018, Plotly, Inc.
  22153. * All rights reserved.
  22154. *
  22155. * This source code is licensed under the MIT license found in the
  22156. * LICENSE file in the root directory of this source tree.
  22157. */
  22158. 'use strict';
  22159. var isNumeric = _dereq_('fast-isnumeric');
  22160. var toLogRange = _dereq_('../../lib/to_log_range');
  22161. /*
  22162. * convertCoords: when converting an axis between log and linear
  22163. * you need to alter any images on that axis to keep them
  22164. * pointing at the same data point.
  22165. * In v2.0 this will become obsolete (or perhaps size will still need conversion?)
  22166. * we convert size by declaring that the maximum extent *in data units* should be
  22167. * the same, assuming the image is anchored by its center (could remove that restriction
  22168. * if we think it's important) even though the actual left and right values will not be
  22169. * quite the same since the scale becomes nonlinear (and central anchor means the pixel
  22170. * center of the image, not the data units center)
  22171. *
  22172. * gd: the plot div
  22173. * ax: the axis being changed
  22174. * newType: the type it's getting
  22175. * doExtra: function(attr, val) from inside relayout that sets the attribute.
  22176. * Use this to make the changes as it's aware if any other changes in the
  22177. * same relayout call should override this conversion.
  22178. */
  22179. module.exports = function convertCoords(gd, ax, newType, doExtra) {
  22180. ax = ax || {};
  22181. var toLog = (newType === 'log') && (ax.type === 'linear'),
  22182. fromLog = (newType === 'linear') && (ax.type === 'log');
  22183. if(!(toLog || fromLog)) return;
  22184. var images = gd._fullLayout.images,
  22185. axLetter = ax._id.charAt(0),
  22186. image,
  22187. attrPrefix;
  22188. for(var i = 0; i < images.length; i++) {
  22189. image = images[i];
  22190. attrPrefix = 'images[' + i + '].';
  22191. if(image[axLetter + 'ref'] === ax._id) {
  22192. var currentPos = image[axLetter],
  22193. currentSize = image['size' + axLetter],
  22194. newPos = null,
  22195. newSize = null;
  22196. if(toLog) {
  22197. newPos = toLogRange(currentPos, ax.range);
  22198. // this is the inverse of the conversion we do in fromLog below
  22199. // so that the conversion is reversible (notice the fromLog conversion
  22200. // is like sinh, and this one looks like arcsinh)
  22201. var dx = currentSize / Math.pow(10, newPos) / 2;
  22202. newSize = 2 * Math.log(dx + Math.sqrt(1 + dx * dx)) / Math.LN10;
  22203. }
  22204. else {
  22205. newPos = Math.pow(10, currentPos);
  22206. newSize = newPos * (Math.pow(10, currentSize / 2) - Math.pow(10, -currentSize / 2));
  22207. }
  22208. // if conversion failed, delete the value so it can get a default later on
  22209. if(!isNumeric(newPos)) {
  22210. newPos = null;
  22211. newSize = null;
  22212. }
  22213. else if(!isNumeric(newSize)) newSize = null;
  22214. doExtra(attrPrefix + axLetter, newPos);
  22215. doExtra(attrPrefix + 'size' + axLetter, newSize);
  22216. }
  22217. }
  22218. };
  22219. },{"../../lib/to_log_range":193,"fast-isnumeric":18}],99:[function(_dereq_,module,exports){
  22220. /**
  22221. * Copyright 2012-2018, Plotly, Inc.
  22222. * All rights reserved.
  22223. *
  22224. * This source code is licensed under the MIT license found in the
  22225. * LICENSE file in the root directory of this source tree.
  22226. */
  22227. 'use strict';
  22228. var Lib = _dereq_('../../lib');
  22229. var Axes = _dereq_('../../plots/cartesian/axes');
  22230. var handleArrayContainerDefaults = _dereq_('../../plots/array_container_defaults');
  22231. var attributes = _dereq_('./attributes');
  22232. var name = 'images';
  22233. module.exports = function supplyLayoutDefaults(layoutIn, layoutOut) {
  22234. var opts = {
  22235. name: name,
  22236. handleItemDefaults: imageDefaults
  22237. };
  22238. handleArrayContainerDefaults(layoutIn, layoutOut, opts);
  22239. };
  22240. function imageDefaults(imageIn, imageOut, fullLayout) {
  22241. function coerce(attr, dflt) {
  22242. return Lib.coerce(imageIn, imageOut, attributes, attr, dflt);
  22243. }
  22244. var source = coerce('source');
  22245. var visible = coerce('visible', !!source);
  22246. if(!visible) return imageOut;
  22247. coerce('layer');
  22248. coerce('xanchor');
  22249. coerce('yanchor');
  22250. coerce('sizex');
  22251. coerce('sizey');
  22252. coerce('sizing');
  22253. coerce('opacity');
  22254. var gdMock = { _fullLayout: fullLayout },
  22255. axLetters = ['x', 'y'];
  22256. for(var i = 0; i < 2; i++) {
  22257. // 'paper' is the fallback axref
  22258. var axLetter = axLetters[i],
  22259. axRef = Axes.coerceRef(imageIn, imageOut, gdMock, axLetter, 'paper');
  22260. Axes.coercePosition(imageOut, gdMock, coerce, axRef, axLetter, 0);
  22261. }
  22262. return imageOut;
  22263. }
  22264. },{"../../lib":169,"../../plots/array_container_defaults":210,"../../plots/cartesian/axes":214,"./attributes":97}],100:[function(_dereq_,module,exports){
  22265. /**
  22266. * Copyright 2012-2018, Plotly, Inc.
  22267. * All rights reserved.
  22268. *
  22269. * This source code is licensed under the MIT license found in the
  22270. * LICENSE file in the root directory of this source tree.
  22271. */
  22272. 'use strict';
  22273. var d3 = _dereq_('d3');
  22274. var Drawing = _dereq_('../drawing');
  22275. var Axes = _dereq_('../../plots/cartesian/axes');
  22276. var xmlnsNamespaces = _dereq_('../../constants/xmlns_namespaces');
  22277. module.exports = function draw(gd) {
  22278. var fullLayout = gd._fullLayout,
  22279. imageDataAbove = [],
  22280. imageDataSubplot = {},
  22281. imageDataBelow = [],
  22282. subplot,
  22283. i;
  22284. // Sort into top, subplot, and bottom layers
  22285. for(i = 0; i < fullLayout.images.length; i++) {
  22286. var img = fullLayout.images[i];
  22287. if(img.visible) {
  22288. if(img.layer === 'below' && img.xref !== 'paper' && img.yref !== 'paper') {
  22289. subplot = img.xref + img.yref;
  22290. var plotinfo = fullLayout._plots[subplot];
  22291. if(!plotinfo) {
  22292. // Fall back to _imageLowerLayer in case the requested subplot doesn't exist.
  22293. // This can happen if you reference the image to an x / y axis combination
  22294. // that doesn't have any data on it (and layer is below)
  22295. imageDataBelow.push(img);
  22296. continue;
  22297. }
  22298. if(plotinfo.mainplot) {
  22299. subplot = plotinfo.mainplot.id;
  22300. }
  22301. if(!imageDataSubplot[subplot]) {
  22302. imageDataSubplot[subplot] = [];
  22303. }
  22304. imageDataSubplot[subplot].push(img);
  22305. } else if(img.layer === 'above') {
  22306. imageDataAbove.push(img);
  22307. } else {
  22308. imageDataBelow.push(img);
  22309. }
  22310. }
  22311. }
  22312. var anchors = {
  22313. x: {
  22314. left: { sizing: 'xMin', offset: 0 },
  22315. center: { sizing: 'xMid', offset: -1 / 2 },
  22316. right: { sizing: 'xMax', offset: -1 }
  22317. },
  22318. y: {
  22319. top: { sizing: 'YMin', offset: 0 },
  22320. middle: { sizing: 'YMid', offset: -1 / 2 },
  22321. bottom: { sizing: 'YMax', offset: -1 }
  22322. }
  22323. };
  22324. // Images must be converted to dataURL's for exporting.
  22325. function setImage(d) {
  22326. var thisImage = d3.select(this);
  22327. if(this.img && this.img.src === d.source) {
  22328. return;
  22329. }
  22330. thisImage.attr('xmlns', xmlnsNamespaces.svg);
  22331. var imagePromise = new Promise(function(resolve) {
  22332. var img = new Image();
  22333. this.img = img;
  22334. // If not set, a `tainted canvas` error is thrown
  22335. img.setAttribute('crossOrigin', 'anonymous');
  22336. img.onerror = errorHandler;
  22337. img.onload = function() {
  22338. var canvas = document.createElement('canvas');
  22339. canvas.width = this.width;
  22340. canvas.height = this.height;
  22341. var ctx = canvas.getContext('2d');
  22342. ctx.drawImage(this, 0, 0);
  22343. var dataURL = canvas.toDataURL('image/png');
  22344. thisImage.attr('xlink:href', dataURL);
  22345. // resolve promise in onload handler instead of on 'load' to support IE11
  22346. // see https://github.com/plotly/plotly.js/issues/1685
  22347. // for more details
  22348. resolve();
  22349. };
  22350. thisImage.on('error', errorHandler);
  22351. img.src = d.source;
  22352. function errorHandler() {
  22353. thisImage.remove();
  22354. resolve();
  22355. }
  22356. }.bind(this));
  22357. gd._promises.push(imagePromise);
  22358. }
  22359. function applyAttributes(d) {
  22360. var thisImage = d3.select(this);
  22361. // Axes if specified
  22362. var xa = Axes.getFromId(gd, d.xref),
  22363. ya = Axes.getFromId(gd, d.yref);
  22364. var size = fullLayout._size,
  22365. width = xa ? Math.abs(xa.l2p(d.sizex) - xa.l2p(0)) : d.sizex * size.w,
  22366. height = ya ? Math.abs(ya.l2p(d.sizey) - ya.l2p(0)) : d.sizey * size.h;
  22367. // Offsets for anchor positioning
  22368. var xOffset = width * anchors.x[d.xanchor].offset,
  22369. yOffset = height * anchors.y[d.yanchor].offset;
  22370. var sizing = anchors.x[d.xanchor].sizing + anchors.y[d.yanchor].sizing;
  22371. // Final positions
  22372. var xPos = (xa ? xa.r2p(d.x) + xa._offset : d.x * size.w + size.l) + xOffset,
  22373. yPos = (ya ? ya.r2p(d.y) + ya._offset : size.h - d.y * size.h + size.t) + yOffset;
  22374. // Construct the proper aspectRatio attribute
  22375. switch(d.sizing) {
  22376. case 'fill':
  22377. sizing += ' slice';
  22378. break;
  22379. case 'stretch':
  22380. sizing = 'none';
  22381. break;
  22382. }
  22383. thisImage.attr({
  22384. x: xPos,
  22385. y: yPos,
  22386. width: width,
  22387. height: height,
  22388. preserveAspectRatio: sizing,
  22389. opacity: d.opacity
  22390. });
  22391. // Set proper clipping on images
  22392. var xId = xa ? xa._id : '',
  22393. yId = ya ? ya._id : '',
  22394. clipAxes = xId + yId;
  22395. thisImage.call(Drawing.setClipUrl, clipAxes ?
  22396. ('clip' + fullLayout._uid + clipAxes) :
  22397. null
  22398. );
  22399. }
  22400. var imagesBelow = fullLayout._imageLowerLayer.selectAll('image')
  22401. .data(imageDataBelow),
  22402. imagesAbove = fullLayout._imageUpperLayer.selectAll('image')
  22403. .data(imageDataAbove);
  22404. imagesBelow.enter().append('image');
  22405. imagesAbove.enter().append('image');
  22406. imagesBelow.exit().remove();
  22407. imagesAbove.exit().remove();
  22408. imagesBelow.each(function(d) {
  22409. setImage.bind(this)(d);
  22410. applyAttributes.bind(this)(d);
  22411. });
  22412. imagesAbove.each(function(d) {
  22413. setImage.bind(this)(d);
  22414. applyAttributes.bind(this)(d);
  22415. });
  22416. var allSubplots = Object.keys(fullLayout._plots);
  22417. for(i = 0; i < allSubplots.length; i++) {
  22418. subplot = allSubplots[i];
  22419. var subplotObj = fullLayout._plots[subplot];
  22420. // filter out overlaid plots (which havd their images on the main plot)
  22421. // and gl2d plots (which don't support below images, at least not yet)
  22422. if(!subplotObj.imagelayer) continue;
  22423. var imagesOnSubplot = subplotObj.imagelayer.selectAll('image')
  22424. // even if there are no images on this subplot, we need to run
  22425. // enter and exit in case there were previously
  22426. .data(imageDataSubplot[subplot] || []);
  22427. imagesOnSubplot.enter().append('image');
  22428. imagesOnSubplot.exit().remove();
  22429. imagesOnSubplot.each(function(d) {
  22430. setImage.bind(this)(d);
  22431. applyAttributes.bind(this)(d);
  22432. });
  22433. }
  22434. };
  22435. },{"../../constants/xmlns_namespaces":152,"../../plots/cartesian/axes":214,"../drawing":75,"d3":16}],101:[function(_dereq_,module,exports){
  22436. /**
  22437. * Copyright 2012-2018, Plotly, Inc.
  22438. * All rights reserved.
  22439. *
  22440. * This source code is licensed under the MIT license found in the
  22441. * LICENSE file in the root directory of this source tree.
  22442. */
  22443. 'use strict';
  22444. module.exports = {
  22445. moduleType: 'component',
  22446. name: 'images',
  22447. layoutAttributes: _dereq_('./attributes'),
  22448. supplyLayoutDefaults: _dereq_('./defaults'),
  22449. includeBasePlot: _dereq_('../../plots/cartesian/include_components')('images'),
  22450. draw: _dereq_('./draw'),
  22451. convertCoords: _dereq_('./convert_coords')
  22452. };
  22453. },{"../../plots/cartesian/include_components":224,"./attributes":97,"./convert_coords":98,"./defaults":99,"./draw":100}],102:[function(_dereq_,module,exports){
  22454. /**
  22455. * Copyright 2012-2018, Plotly, Inc.
  22456. * All rights reserved.
  22457. *
  22458. * This source code is licensed under the MIT license found in the
  22459. * LICENSE file in the root directory of this source tree.
  22460. */
  22461. 'use strict';
  22462. /**
  22463. * Determine the position anchor property of x/y xanchor/yanchor components.
  22464. *
  22465. * - values < 1/3 align the low side at that fraction,
  22466. * - values [1/3, 2/3] align the center at that fraction,
  22467. * - values > 2/3 align the right at that fraction.
  22468. */
  22469. exports.isRightAnchor = function isRightAnchor(opts) {
  22470. return (
  22471. opts.xanchor === 'right' ||
  22472. (opts.xanchor === 'auto' && opts.x >= 2 / 3)
  22473. );
  22474. };
  22475. exports.isCenterAnchor = function isCenterAnchor(opts) {
  22476. return (
  22477. opts.xanchor === 'center' ||
  22478. (opts.xanchor === 'auto' && opts.x > 1 / 3 && opts.x < 2 / 3)
  22479. );
  22480. };
  22481. exports.isBottomAnchor = function isBottomAnchor(opts) {
  22482. return (
  22483. opts.yanchor === 'bottom' ||
  22484. (opts.yanchor === 'auto' && opts.y <= 1 / 3)
  22485. );
  22486. };
  22487. exports.isMiddleAnchor = function isMiddleAnchor(opts) {
  22488. return (
  22489. opts.yanchor === 'middle' ||
  22490. (opts.yanchor === 'auto' && opts.y > 1 / 3 && opts.y < 2 / 3)
  22491. );
  22492. };
  22493. },{}],103:[function(_dereq_,module,exports){
  22494. /**
  22495. * Copyright 2012-2018, Plotly, Inc.
  22496. * All rights reserved.
  22497. *
  22498. * This source code is licensed under the MIT license found in the
  22499. * LICENSE file in the root directory of this source tree.
  22500. */
  22501. 'use strict';
  22502. var fontAttrs = _dereq_('../../plots/font_attributes');
  22503. var colorAttrs = _dereq_('../color/attributes');
  22504. module.exports = {
  22505. bgcolor: {
  22506. valType: 'color',
  22507. editType: 'legend',
  22508. },
  22509. bordercolor: {
  22510. valType: 'color',
  22511. dflt: colorAttrs.defaultLine,
  22512. editType: 'legend',
  22513. },
  22514. borderwidth: {
  22515. valType: 'number',
  22516. min: 0,
  22517. dflt: 0,
  22518. editType: 'legend',
  22519. },
  22520. font: fontAttrs({
  22521. editType: 'legend',
  22522. }),
  22523. orientation: {
  22524. valType: 'enumerated',
  22525. values: ['v', 'h'],
  22526. dflt: 'v',
  22527. editType: 'legend',
  22528. },
  22529. traceorder: {
  22530. valType: 'flaglist',
  22531. flags: ['reversed', 'grouped'],
  22532. extras: ['normal'],
  22533. editType: 'legend',
  22534. },
  22535. tracegroupgap: {
  22536. valType: 'number',
  22537. min: 0,
  22538. dflt: 10,
  22539. editType: 'legend',
  22540. },
  22541. x: {
  22542. valType: 'number',
  22543. min: -2,
  22544. max: 3,
  22545. dflt: 1.02,
  22546. editType: 'legend',
  22547. },
  22548. xanchor: {
  22549. valType: 'enumerated',
  22550. values: ['auto', 'left', 'center', 'right'],
  22551. dflt: 'left',
  22552. editType: 'legend',
  22553. },
  22554. y: {
  22555. valType: 'number',
  22556. min: -2,
  22557. max: 3,
  22558. dflt: 1,
  22559. editType: 'legend',
  22560. },
  22561. yanchor: {
  22562. valType: 'enumerated',
  22563. values: ['auto', 'top', 'middle', 'bottom'],
  22564. dflt: 'auto',
  22565. editType: 'legend',
  22566. },
  22567. editType: 'legend'
  22568. };
  22569. },{"../../plots/font_attributes":240,"../color/attributes":49}],104:[function(_dereq_,module,exports){
  22570. /**
  22571. * Copyright 2012-2018, Plotly, Inc.
  22572. * All rights reserved.
  22573. *
  22574. * This source code is licensed under the MIT license found in the
  22575. * LICENSE file in the root directory of this source tree.
  22576. */
  22577. 'use strict';
  22578. module.exports = {
  22579. scrollBarWidth: 6,
  22580. scrollBarMinHeight: 20,
  22581. scrollBarColor: '#808BA4',
  22582. scrollBarMargin: 4,
  22583. textOffsetX: 40
  22584. };
  22585. },{}],105:[function(_dereq_,module,exports){
  22586. /**
  22587. * Copyright 2012-2018, Plotly, Inc.
  22588. * All rights reserved.
  22589. *
  22590. * This source code is licensed under the MIT license found in the
  22591. * LICENSE file in the root directory of this source tree.
  22592. */
  22593. 'use strict';
  22594. var Registry = _dereq_('../../registry');
  22595. var Lib = _dereq_('../../lib');
  22596. var Template = _dereq_('../../plot_api/plot_template');
  22597. var attributes = _dereq_('./attributes');
  22598. var basePlotLayoutAttributes = _dereq_('../../plots/layout_attributes');
  22599. var helpers = _dereq_('./helpers');
  22600. module.exports = function legendDefaults(layoutIn, layoutOut, fullData) {
  22601. var containerIn = layoutIn.legend || {};
  22602. var legendTraceCount = 0;
  22603. var legendReallyHasATrace = false;
  22604. var defaultOrder = 'normal';
  22605. var defaultX, defaultY, defaultXAnchor, defaultYAnchor;
  22606. for(var i = 0; i < fullData.length; i++) {
  22607. var trace = fullData[i];
  22608. if(!trace.visible) continue;
  22609. // Note that we explicitly count any trace that is either shown or
  22610. // *would* be shown by default, toward the two traces you need to
  22611. // ensure the legend is shown by default, because this can still help
  22612. // disambiguate.
  22613. if(trace.showlegend || trace._dfltShowLegend) {
  22614. legendTraceCount++;
  22615. if(trace.showlegend) {
  22616. legendReallyHasATrace = true;
  22617. // Always show the legend by default if there's a pie,
  22618. // or if there's only one trace but it's explicitly shown
  22619. if(Registry.traceIs(trace, 'pie') ||
  22620. trace._input.showlegend === true
  22621. ) {
  22622. legendTraceCount++;
  22623. }
  22624. }
  22625. }
  22626. if((Registry.traceIs(trace, 'bar') && layoutOut.barmode === 'stack') ||
  22627. ['tonextx', 'tonexty'].indexOf(trace.fill) !== -1) {
  22628. defaultOrder = helpers.isGrouped({traceorder: defaultOrder}) ?
  22629. 'grouped+reversed' : 'reversed';
  22630. }
  22631. if(trace.legendgroup !== undefined && trace.legendgroup !== '') {
  22632. defaultOrder = helpers.isReversed({traceorder: defaultOrder}) ?
  22633. 'reversed+grouped' : 'grouped';
  22634. }
  22635. }
  22636. var showLegend = Lib.coerce(layoutIn, layoutOut,
  22637. basePlotLayoutAttributes, 'showlegend',
  22638. legendReallyHasATrace && legendTraceCount > 1);
  22639. if(showLegend === false) return;
  22640. var containerOut = Template.newContainer(layoutOut, 'legend');
  22641. function coerce(attr, dflt) {
  22642. return Lib.coerce(containerIn, containerOut, attributes, attr, dflt);
  22643. }
  22644. coerce('bgcolor', layoutOut.paper_bgcolor);
  22645. coerce('bordercolor');
  22646. coerce('borderwidth');
  22647. Lib.coerceFont(coerce, 'font', layoutOut.font);
  22648. coerce('orientation');
  22649. if(containerOut.orientation === 'h') {
  22650. var xaxis = layoutIn.xaxis;
  22651. if(xaxis && xaxis.rangeslider && xaxis.rangeslider.visible) {
  22652. defaultX = 0;
  22653. defaultXAnchor = 'left';
  22654. defaultY = 1.1;
  22655. defaultYAnchor = 'bottom';
  22656. }
  22657. else {
  22658. defaultX = 0;
  22659. defaultXAnchor = 'left';
  22660. defaultY = -0.1;
  22661. defaultYAnchor = 'top';
  22662. }
  22663. }
  22664. coerce('traceorder', defaultOrder);
  22665. if(helpers.isGrouped(layoutOut.legend)) coerce('tracegroupgap');
  22666. coerce('x', defaultX);
  22667. coerce('xanchor', defaultXAnchor);
  22668. coerce('y', defaultY);
  22669. coerce('yanchor', defaultYAnchor);
  22670. Lib.noneOrAll(containerIn, containerOut, ['x', 'y']);
  22671. };
  22672. },{"../../lib":169,"../../plot_api/plot_template":204,"../../plots/layout_attributes":244,"../../registry":259,"./attributes":103,"./helpers":109}],106:[function(_dereq_,module,exports){
  22673. /**
  22674. * Copyright 2012-2018, Plotly, Inc.
  22675. * All rights reserved.
  22676. *
  22677. * This source code is licensed under the MIT license found in the
  22678. * LICENSE file in the root directory of this source tree.
  22679. */
  22680. 'use strict';
  22681. var d3 = _dereq_('d3');
  22682. var Lib = _dereq_('../../lib');
  22683. var Plots = _dereq_('../../plots/plots');
  22684. var Registry = _dereq_('../../registry');
  22685. var Events = _dereq_('../../lib/events');
  22686. var dragElement = _dereq_('../dragelement');
  22687. var Drawing = _dereq_('../drawing');
  22688. var Color = _dereq_('../color');
  22689. var svgTextUtils = _dereq_('../../lib/svg_text_utils');
  22690. var handleClick = _dereq_('./handle_click');
  22691. var constants = _dereq_('./constants');
  22692. var interactConstants = _dereq_('../../constants/interactions');
  22693. var alignmentConstants = _dereq_('../../constants/alignment');
  22694. var LINE_SPACING = alignmentConstants.LINE_SPACING;
  22695. var FROM_TL = alignmentConstants.FROM_TL;
  22696. var FROM_BR = alignmentConstants.FROM_BR;
  22697. var getLegendData = _dereq_('./get_legend_data');
  22698. var style = _dereq_('./style');
  22699. var helpers = _dereq_('./helpers');
  22700. var anchorUtils = _dereq_('./anchor_utils');
  22701. var DBLCLICKDELAY = interactConstants.DBLCLICKDELAY;
  22702. module.exports = function draw(gd) {
  22703. var fullLayout = gd._fullLayout;
  22704. var clipId = 'legend' + fullLayout._uid;
  22705. if(!fullLayout._infolayer || !gd.calcdata) return;
  22706. if(!gd._legendMouseDownTime) gd._legendMouseDownTime = 0;
  22707. var opts = fullLayout.legend;
  22708. var legendData = fullLayout.showlegend && getLegendData(gd.calcdata, opts);
  22709. var hiddenSlices = fullLayout.hiddenlabels || [];
  22710. if(!fullLayout.showlegend || !legendData.length) {
  22711. fullLayout._infolayer.selectAll('.legend').remove();
  22712. fullLayout._topdefs.select('#' + clipId).remove();
  22713. Plots.autoMargin(gd, 'legend');
  22714. return;
  22715. }
  22716. var maxLength = 0;
  22717. for(var i = 0; i < legendData.length; i++) {
  22718. for(var j = 0; j < legendData[i].length; j++) {
  22719. var item = legendData[i][j][0];
  22720. var trace = item.trace;
  22721. var isPie = Registry.traceIs(trace, 'pie');
  22722. var name = isPie ? item.label : trace.name;
  22723. maxLength = Math.max(maxLength, name && name.length || 0);
  22724. }
  22725. }
  22726. var firstRender = false;
  22727. var legend = Lib.ensureSingle(fullLayout._infolayer, 'g', 'legend', function(s) {
  22728. s.attr('pointer-events', 'all');
  22729. firstRender = true;
  22730. });
  22731. var clipPath = Lib.ensureSingleById(fullLayout._topdefs, 'clipPath', clipId, function(s) {
  22732. s.append('rect');
  22733. });
  22734. var bg = Lib.ensureSingle(legend, 'rect', 'bg', function(s) {
  22735. s.attr('shape-rendering', 'crispEdges');
  22736. });
  22737. bg.call(Color.stroke, opts.bordercolor)
  22738. .call(Color.fill, opts.bgcolor)
  22739. .style('stroke-width', opts.borderwidth + 'px');
  22740. var scrollBox = Lib.ensureSingle(legend, 'g', 'scrollbox');
  22741. var scrollBar = Lib.ensureSingle(legend, 'rect', 'scrollbar', function(s) {
  22742. s.attr({
  22743. rx: 20,
  22744. ry: 3,
  22745. width: 0,
  22746. height: 0
  22747. })
  22748. .call(Color.fill, '#808BA4');
  22749. });
  22750. var groups = scrollBox.selectAll('g.groups')
  22751. .data(legendData);
  22752. groups.enter().append('g')
  22753. .attr('class', 'groups');
  22754. groups.exit().remove();
  22755. var traces = groups.selectAll('g.traces')
  22756. .data(Lib.identity);
  22757. traces.enter().append('g').attr('class', 'traces');
  22758. traces.exit().remove();
  22759. traces.call(style, gd)
  22760. .style('opacity', function(d) {
  22761. var trace = d[0].trace;
  22762. if(Registry.traceIs(trace, 'pie')) {
  22763. return hiddenSlices.indexOf(d[0].label) !== -1 ? 0.5 : 1;
  22764. } else {
  22765. return trace.visible === 'legendonly' ? 0.5 : 1;
  22766. }
  22767. })
  22768. .each(function() {
  22769. d3.select(this)
  22770. .call(drawTexts, gd, maxLength)
  22771. .call(setupTraceToggle, gd);
  22772. });
  22773. Lib.syncOrAsync([Plots.previousPromises,
  22774. function() {
  22775. if(firstRender) {
  22776. computeLegendDimensions(gd, groups, traces);
  22777. expandMargin(gd);
  22778. }
  22779. // Position and size the legend
  22780. var lxMin = 0,
  22781. lxMax = fullLayout.width,
  22782. lyMin = 0,
  22783. lyMax = fullLayout.height;
  22784. computeLegendDimensions(gd, groups, traces);
  22785. if(opts._height > lyMax) {
  22786. // If the legend doesn't fit in the plot area,
  22787. // do not expand the vertical margins.
  22788. expandHorizontalMargin(gd);
  22789. } else {
  22790. expandMargin(gd);
  22791. }
  22792. // Scroll section must be executed after repositionLegend.
  22793. // It requires the legend width, height, x and y to position the scrollbox
  22794. // and these values are mutated in repositionLegend.
  22795. var gs = fullLayout._size,
  22796. lx = gs.l + gs.w * opts.x,
  22797. ly = gs.t + gs.h * (1 - opts.y);
  22798. if(anchorUtils.isRightAnchor(opts)) {
  22799. lx -= opts._width;
  22800. }
  22801. else if(anchorUtils.isCenterAnchor(opts)) {
  22802. lx -= opts._width / 2;
  22803. }
  22804. if(anchorUtils.isBottomAnchor(opts)) {
  22805. ly -= opts._height;
  22806. }
  22807. else if(anchorUtils.isMiddleAnchor(opts)) {
  22808. ly -= opts._height / 2;
  22809. }
  22810. // Make sure the legend left and right sides are visible
  22811. var legendWidth = opts._width,
  22812. legendWidthMax = gs.w;
  22813. if(legendWidth > legendWidthMax) {
  22814. lx = gs.l;
  22815. legendWidth = legendWidthMax;
  22816. }
  22817. else {
  22818. if(lx + legendWidth > lxMax) lx = lxMax - legendWidth;
  22819. if(lx < lxMin) lx = lxMin;
  22820. legendWidth = Math.min(lxMax - lx, opts._width);
  22821. }
  22822. // Make sure the legend top and bottom are visible
  22823. // (legends with a scroll bar are not allowed to stretch beyond the extended
  22824. // margins)
  22825. var legendHeight = opts._height,
  22826. legendHeightMax = gs.h;
  22827. if(legendHeight > legendHeightMax) {
  22828. ly = gs.t;
  22829. legendHeight = legendHeightMax;
  22830. }
  22831. else {
  22832. if(ly + legendHeight > lyMax) ly = lyMax - legendHeight;
  22833. if(ly < lyMin) ly = lyMin;
  22834. legendHeight = Math.min(lyMax - ly, opts._height);
  22835. }
  22836. // Set size and position of all the elements that make up a legend:
  22837. // legend, background and border, scroll box and scroll bar
  22838. Drawing.setTranslate(legend, lx, ly);
  22839. // to be safe, remove previous listeners
  22840. scrollBar.on('.drag', null);
  22841. legend.on('wheel', null);
  22842. if(opts._height <= legendHeight || gd._context.staticPlot) {
  22843. // if scrollbar should not be shown.
  22844. bg.attr({
  22845. width: legendWidth - opts.borderwidth,
  22846. height: legendHeight - opts.borderwidth,
  22847. x: opts.borderwidth / 2,
  22848. y: opts.borderwidth / 2
  22849. });
  22850. Drawing.setTranslate(scrollBox, 0, 0);
  22851. clipPath.select('rect').attr({
  22852. width: legendWidth - 2 * opts.borderwidth,
  22853. height: legendHeight - 2 * opts.borderwidth,
  22854. x: opts.borderwidth,
  22855. y: opts.borderwidth
  22856. });
  22857. Drawing.setClipUrl(scrollBox, clipId);
  22858. Drawing.setRect(scrollBar, 0, 0, 0, 0);
  22859. delete opts._scrollY;
  22860. }
  22861. else {
  22862. var scrollBarHeight = Math.max(constants.scrollBarMinHeight,
  22863. legendHeight * legendHeight / opts._height);
  22864. var scrollBarYMax = legendHeight -
  22865. scrollBarHeight -
  22866. 2 * constants.scrollBarMargin;
  22867. var scrollBoxYMax = opts._height - legendHeight;
  22868. var scrollRatio = scrollBarYMax / scrollBoxYMax;
  22869. var scrollBoxY = Math.min(opts._scrollY || 0, scrollBoxYMax);
  22870. // increase the background and clip-path width
  22871. // by the scrollbar width and margin
  22872. bg.attr({
  22873. width: legendWidth -
  22874. 2 * opts.borderwidth +
  22875. constants.scrollBarWidth +
  22876. constants.scrollBarMargin,
  22877. height: legendHeight - opts.borderwidth,
  22878. x: opts.borderwidth / 2,
  22879. y: opts.borderwidth / 2
  22880. });
  22881. clipPath.select('rect').attr({
  22882. width: legendWidth -
  22883. 2 * opts.borderwidth +
  22884. constants.scrollBarWidth +
  22885. constants.scrollBarMargin,
  22886. height: legendHeight - 2 * opts.borderwidth,
  22887. x: opts.borderwidth,
  22888. y: opts.borderwidth + scrollBoxY
  22889. });
  22890. Drawing.setClipUrl(scrollBox, clipId);
  22891. scrollHandler(scrollBoxY, scrollBarHeight, scrollRatio);
  22892. legend.on('wheel', function() {
  22893. scrollBoxY = Lib.constrain(
  22894. opts._scrollY +
  22895. d3.event.deltaY / scrollBarYMax * scrollBoxYMax,
  22896. 0, scrollBoxYMax);
  22897. scrollHandler(scrollBoxY, scrollBarHeight, scrollRatio);
  22898. if(scrollBoxY !== 0 && scrollBoxY !== scrollBoxYMax) {
  22899. d3.event.preventDefault();
  22900. }
  22901. });
  22902. var eventY0, scrollBoxY0;
  22903. var drag = d3.behavior.drag()
  22904. .on('dragstart', function() {
  22905. eventY0 = d3.event.sourceEvent.clientY;
  22906. scrollBoxY0 = scrollBoxY;
  22907. })
  22908. .on('drag', function() {
  22909. var e = d3.event.sourceEvent;
  22910. if(e.buttons === 2 || e.ctrlKey) return;
  22911. scrollBoxY = Lib.constrain(
  22912. (e.clientY - eventY0) / scrollRatio + scrollBoxY0,
  22913. 0, scrollBoxYMax);
  22914. scrollHandler(scrollBoxY, scrollBarHeight, scrollRatio);
  22915. });
  22916. scrollBar.call(drag);
  22917. }
  22918. function scrollHandler(scrollBoxY, scrollBarHeight, scrollRatio) {
  22919. opts._scrollY = gd._fullLayout.legend._scrollY = scrollBoxY;
  22920. Drawing.setTranslate(scrollBox, 0, -scrollBoxY);
  22921. Drawing.setRect(
  22922. scrollBar,
  22923. legendWidth,
  22924. constants.scrollBarMargin + scrollBoxY * scrollRatio,
  22925. constants.scrollBarWidth,
  22926. scrollBarHeight
  22927. );
  22928. clipPath.select('rect').attr({
  22929. y: opts.borderwidth + scrollBoxY
  22930. });
  22931. }
  22932. if(gd._context.edits.legendPosition) {
  22933. var xf, yf, x0, y0;
  22934. legend.classed('cursor-move', true);
  22935. dragElement.init({
  22936. element: legend.node(),
  22937. gd: gd,
  22938. prepFn: function() {
  22939. var transform = Drawing.getTranslate(legend);
  22940. x0 = transform.x;
  22941. y0 = transform.y;
  22942. },
  22943. moveFn: function(dx, dy) {
  22944. var newX = x0 + dx,
  22945. newY = y0 + dy;
  22946. Drawing.setTranslate(legend, newX, newY);
  22947. xf = dragElement.align(newX, 0, gs.l, gs.l + gs.w, opts.xanchor);
  22948. yf = dragElement.align(newY, 0, gs.t + gs.h, gs.t, opts.yanchor);
  22949. },
  22950. doneFn: function() {
  22951. if(xf !== undefined && yf !== undefined) {
  22952. Registry.call('relayout', gd, {'legend.x': xf, 'legend.y': yf});
  22953. }
  22954. },
  22955. clickFn: function(numClicks, e) {
  22956. var clickedTrace = fullLayout._infolayer.selectAll('g.traces').filter(function() {
  22957. var bbox = this.getBoundingClientRect();
  22958. return (
  22959. e.clientX >= bbox.left && e.clientX <= bbox.right &&
  22960. e.clientY >= bbox.top && e.clientY <= bbox.bottom
  22961. );
  22962. });
  22963. if(clickedTrace.size() > 0) {
  22964. clickOrDoubleClick(gd, legend, clickedTrace, numClicks, e);
  22965. }
  22966. }
  22967. });
  22968. }
  22969. }], gd);
  22970. };
  22971. function clickOrDoubleClick(gd, legend, legendItem, numClicks, evt) {
  22972. var trace = legendItem.data()[0][0].trace;
  22973. var evtData = {
  22974. event: evt,
  22975. node: legendItem.node(),
  22976. curveNumber: trace.index,
  22977. expandedIndex: trace._expandedIndex,
  22978. data: gd.data,
  22979. layout: gd.layout,
  22980. frames: gd._transitionData._frames,
  22981. config: gd._context,
  22982. fullData: gd._fullData,
  22983. fullLayout: gd._fullLayout
  22984. };
  22985. if(trace._group) {
  22986. evtData.group = trace._group;
  22987. }
  22988. if(trace.type === 'pie') {
  22989. evtData.label = legendItem.datum()[0].label;
  22990. }
  22991. var clickVal = Events.triggerHandler(gd, 'plotly_legendclick', evtData);
  22992. if(clickVal === false) return;
  22993. if(numClicks === 1) {
  22994. legend._clickTimeout = setTimeout(function() {
  22995. handleClick(legendItem, gd, numClicks);
  22996. }, DBLCLICKDELAY);
  22997. }
  22998. else if(numClicks === 2) {
  22999. if(legend._clickTimeout) clearTimeout(legend._clickTimeout);
  23000. gd._legendMouseDownTime = 0;
  23001. var dblClickVal = Events.triggerHandler(gd, 'plotly_legenddoubleclick', evtData);
  23002. if(dblClickVal !== false) handleClick(legendItem, gd, numClicks);
  23003. }
  23004. }
  23005. function drawTexts(g, gd, maxLength) {
  23006. var legendItem = g.data()[0][0];
  23007. var fullLayout = gd._fullLayout;
  23008. var trace = legendItem.trace;
  23009. var isPie = Registry.traceIs(trace, 'pie');
  23010. var traceIndex = trace.index;
  23011. var name = isPie ? legendItem.label : trace.name;
  23012. var isEditable = gd._context.edits.legendText && !isPie;
  23013. var textEl = Lib.ensureSingle(g, 'text', 'legendtext');
  23014. textEl.attr('text-anchor', 'start')
  23015. .classed('user-select-none', true)
  23016. .call(Drawing.font, fullLayout.legend.font)
  23017. .text(isEditable ? ensureLength(name, maxLength) : name);
  23018. svgTextUtils.positionText(textEl, constants.textOffsetX, 0);
  23019. function textLayout(s) {
  23020. svgTextUtils.convertToTspans(s, gd, function() {
  23021. computeTextDimensions(g, gd);
  23022. });
  23023. }
  23024. if(isEditable) {
  23025. textEl.call(svgTextUtils.makeEditable, {gd: gd, text: name})
  23026. .call(textLayout)
  23027. .on('edit', function(newName) {
  23028. this.text(ensureLength(newName, maxLength))
  23029. .call(textLayout);
  23030. var fullInput = legendItem.trace._fullInput || {};
  23031. var update = {};
  23032. if(Registry.hasTransform(fullInput, 'groupby')) {
  23033. var groupbyIndices = Registry.getTransformIndices(fullInput, 'groupby');
  23034. var index = groupbyIndices[groupbyIndices.length - 1];
  23035. var kcont = Lib.keyedContainer(fullInput, 'transforms[' + index + '].styles', 'target', 'value.name');
  23036. kcont.set(legendItem.trace._group, newName);
  23037. update = kcont.constructUpdate();
  23038. } else {
  23039. update.name = newName;
  23040. }
  23041. return Registry.call('restyle', gd, update, traceIndex);
  23042. });
  23043. } else {
  23044. textLayout(textEl);
  23045. }
  23046. }
  23047. /*
  23048. * Make sure we have a reasonably clickable region.
  23049. * If this string is missing or very short, pad it with spaces out to at least
  23050. * 4 characters, up to the max length of other labels, on the assumption that
  23051. * most characters are wider than spaces so a string of spaces will usually be
  23052. * no wider than the real labels.
  23053. */
  23054. function ensureLength(str, maxLength) {
  23055. var targetLength = Math.max(4, maxLength);
  23056. if(str && str.trim().length >= targetLength / 2) return str;
  23057. str = str || '';
  23058. for(var i = targetLength - str.length; i > 0; i--) str += ' ';
  23059. return str;
  23060. }
  23061. function setupTraceToggle(g, gd) {
  23062. var newMouseDownTime,
  23063. numClicks = 1;
  23064. var traceToggle = Lib.ensureSingle(g, 'rect', 'legendtoggle', function(s) {
  23065. s.style('cursor', 'pointer')
  23066. .attr('pointer-events', 'all')
  23067. .call(Color.fill, 'rgba(0,0,0,0)');
  23068. });
  23069. traceToggle.on('mousedown', function() {
  23070. newMouseDownTime = (new Date()).getTime();
  23071. if(newMouseDownTime - gd._legendMouseDownTime < DBLCLICKDELAY) {
  23072. // in a click train
  23073. numClicks += 1;
  23074. }
  23075. else {
  23076. // new click train
  23077. numClicks = 1;
  23078. gd._legendMouseDownTime = newMouseDownTime;
  23079. }
  23080. });
  23081. traceToggle.on('mouseup', function() {
  23082. if(gd._dragged || gd._editing) return;
  23083. var legend = gd._fullLayout.legend;
  23084. if((new Date()).getTime() - gd._legendMouseDownTime > DBLCLICKDELAY) {
  23085. numClicks = Math.max(numClicks - 1, 1);
  23086. }
  23087. clickOrDoubleClick(gd, legend, g, numClicks, d3.event);
  23088. });
  23089. }
  23090. function computeTextDimensions(g, gd) {
  23091. var legendItem = g.data()[0][0];
  23092. if(!legendItem.trace.showlegend) {
  23093. g.remove();
  23094. return;
  23095. }
  23096. var mathjaxGroup = g.select('g[class*=math-group]');
  23097. var mathjaxNode = mathjaxGroup.node();
  23098. var opts = gd._fullLayout.legend;
  23099. var lineHeight = opts.font.size * LINE_SPACING;
  23100. var height, width;
  23101. if(mathjaxNode) {
  23102. var mathjaxBB = Drawing.bBox(mathjaxNode);
  23103. height = mathjaxBB.height;
  23104. width = mathjaxBB.width;
  23105. Drawing.setTranslate(mathjaxGroup, 0, (height / 4));
  23106. }
  23107. else {
  23108. var text = g.select('.legendtext');
  23109. var textLines = svgTextUtils.lineCount(text);
  23110. var textNode = text.node();
  23111. height = lineHeight * textLines;
  23112. width = textNode ? Drawing.bBox(textNode).width : 0;
  23113. // approximation to height offset to center the font
  23114. // to avoid getBoundingClientRect
  23115. var textY = lineHeight * (0.3 + (1 - textLines) / 2);
  23116. svgTextUtils.positionText(text, constants.textOffsetX, textY);
  23117. }
  23118. height = Math.max(height, 16) + 3;
  23119. legendItem.height = height;
  23120. legendItem.width = width;
  23121. }
  23122. function computeLegendDimensions(gd, groups, traces) {
  23123. var fullLayout = gd._fullLayout;
  23124. var opts = fullLayout.legend;
  23125. var borderwidth = opts.borderwidth;
  23126. var isGrouped = helpers.isGrouped(opts);
  23127. var extraWidth = 0;
  23128. opts._width = 0;
  23129. opts._height = 0;
  23130. if(helpers.isVertical(opts)) {
  23131. if(isGrouped) {
  23132. groups.each(function(d, i) {
  23133. Drawing.setTranslate(this, 0, i * opts.tracegroupgap);
  23134. });
  23135. }
  23136. traces.each(function(d) {
  23137. var legendItem = d[0],
  23138. textHeight = legendItem.height,
  23139. textWidth = legendItem.width;
  23140. Drawing.setTranslate(this,
  23141. borderwidth,
  23142. (5 + borderwidth + opts._height + textHeight / 2));
  23143. opts._height += textHeight;
  23144. opts._width = Math.max(opts._width, textWidth);
  23145. });
  23146. opts._width += 45 + borderwidth * 2;
  23147. opts._height += 10 + borderwidth * 2;
  23148. if(isGrouped) {
  23149. opts._height += (opts._lgroupsLength - 1) * opts.tracegroupgap;
  23150. }
  23151. extraWidth = 40;
  23152. }
  23153. else if(isGrouped) {
  23154. var groupXOffsets = [opts._width],
  23155. groupData = groups.data();
  23156. for(var i = 0, n = groupData.length; i < n; i++) {
  23157. var textWidths = groupData[i].map(function(legendItemArray) {
  23158. return legendItemArray[0].width;
  23159. });
  23160. var groupWidth = 40 + Math.max.apply(null, textWidths);
  23161. opts._width += opts.tracegroupgap + groupWidth;
  23162. groupXOffsets.push(opts._width);
  23163. }
  23164. groups.each(function(d, i) {
  23165. Drawing.setTranslate(this, groupXOffsets[i], 0);
  23166. });
  23167. groups.each(function() {
  23168. var group = d3.select(this),
  23169. groupTraces = group.selectAll('g.traces'),
  23170. groupHeight = 0;
  23171. groupTraces.each(function(d) {
  23172. var legendItem = d[0],
  23173. textHeight = legendItem.height;
  23174. Drawing.setTranslate(this,
  23175. 0,
  23176. (5 + borderwidth + groupHeight + textHeight / 2));
  23177. groupHeight += textHeight;
  23178. });
  23179. opts._height = Math.max(opts._height, groupHeight);
  23180. });
  23181. opts._height += 10 + borderwidth * 2;
  23182. opts._width += borderwidth * 2;
  23183. }
  23184. else {
  23185. var rowHeight = 0,
  23186. maxTraceHeight = 0,
  23187. maxTraceWidth = 0,
  23188. offsetX = 0,
  23189. fullTracesWidth = 0,
  23190. traceGap = opts.tracegroupgap || 5,
  23191. oneRowLegend;
  23192. // calculate largest width for traces and use for width of all legend items
  23193. traces.each(function(d) {
  23194. maxTraceWidth = Math.max(40 + d[0].width, maxTraceWidth);
  23195. fullTracesWidth += 40 + d[0].width + traceGap;
  23196. });
  23197. // check if legend fits in one row
  23198. oneRowLegend = fullLayout._size.w > borderwidth + fullTracesWidth - traceGap;
  23199. traces.each(function(d) {
  23200. var legendItem = d[0],
  23201. traceWidth = oneRowLegend ? 40 + d[0].width : maxTraceWidth;
  23202. if((borderwidth + offsetX + traceGap + traceWidth) > fullLayout._size.w) {
  23203. offsetX = 0;
  23204. rowHeight = rowHeight + maxTraceHeight;
  23205. opts._height = opts._height + maxTraceHeight;
  23206. // reset for next row
  23207. maxTraceHeight = 0;
  23208. }
  23209. Drawing.setTranslate(this,
  23210. (borderwidth + offsetX),
  23211. (5 + borderwidth + legendItem.height / 2) + rowHeight);
  23212. opts._width += traceGap + traceWidth;
  23213. opts._height = Math.max(opts._height, legendItem.height);
  23214. // keep track of tallest trace in group
  23215. offsetX += traceGap + traceWidth;
  23216. maxTraceHeight = Math.max(legendItem.height, maxTraceHeight);
  23217. });
  23218. opts._width += borderwidth * 2;
  23219. opts._height += 10 + borderwidth * 2;
  23220. }
  23221. // make sure we're only getting full pixels
  23222. opts._width = Math.ceil(opts._width);
  23223. opts._height = Math.ceil(opts._height);
  23224. var isEditable = (
  23225. gd._context.edits.legendText ||
  23226. gd._context.edits.legendPosition
  23227. );
  23228. traces.each(function(d) {
  23229. var legendItem = d[0];
  23230. var bg = d3.select(this).select('.legendtoggle');
  23231. Drawing.setRect(bg,
  23232. 0,
  23233. -legendItem.height / 2,
  23234. (isEditable ? 0 : opts._width) + extraWidth,
  23235. legendItem.height
  23236. );
  23237. });
  23238. }
  23239. function expandMargin(gd) {
  23240. var fullLayout = gd._fullLayout,
  23241. opts = fullLayout.legend;
  23242. var xanchor = 'left';
  23243. if(anchorUtils.isRightAnchor(opts)) {
  23244. xanchor = 'right';
  23245. }
  23246. else if(anchorUtils.isCenterAnchor(opts)) {
  23247. xanchor = 'center';
  23248. }
  23249. var yanchor = 'top';
  23250. if(anchorUtils.isBottomAnchor(opts)) {
  23251. yanchor = 'bottom';
  23252. }
  23253. else if(anchorUtils.isMiddleAnchor(opts)) {
  23254. yanchor = 'middle';
  23255. }
  23256. // lastly check if the margin auto-expand has changed
  23257. Plots.autoMargin(gd, 'legend', {
  23258. x: opts.x,
  23259. y: opts.y,
  23260. l: opts._width * (FROM_TL[xanchor]),
  23261. r: opts._width * (FROM_BR[xanchor]),
  23262. b: opts._height * (FROM_BR[yanchor]),
  23263. t: opts._height * (FROM_TL[yanchor])
  23264. });
  23265. }
  23266. function expandHorizontalMargin(gd) {
  23267. var fullLayout = gd._fullLayout,
  23268. opts = fullLayout.legend;
  23269. var xanchor = 'left';
  23270. if(anchorUtils.isRightAnchor(opts)) {
  23271. xanchor = 'right';
  23272. }
  23273. else if(anchorUtils.isCenterAnchor(opts)) {
  23274. xanchor = 'center';
  23275. }
  23276. // lastly check if the margin auto-expand has changed
  23277. Plots.autoMargin(gd, 'legend', {
  23278. x: opts.x,
  23279. y: 0.5,
  23280. l: opts._width * (FROM_TL[xanchor]),
  23281. r: opts._width * (FROM_BR[xanchor]),
  23282. b: 0,
  23283. t: 0
  23284. });
  23285. }
  23286. },{"../../constants/alignment":148,"../../constants/interactions":150,"../../lib":169,"../../lib/events":162,"../../lib/svg_text_utils":191,"../../plots/plots":246,"../../registry":259,"../color":50,"../dragelement":72,"../drawing":75,"./anchor_utils":102,"./constants":104,"./get_legend_data":107,"./handle_click":108,"./helpers":109,"./style":111,"d3":16}],107:[function(_dereq_,module,exports){
  23287. /**
  23288. * Copyright 2012-2018, Plotly, Inc.
  23289. * All rights reserved.
  23290. *
  23291. * This source code is licensed under the MIT license found in the
  23292. * LICENSE file in the root directory of this source tree.
  23293. */
  23294. 'use strict';
  23295. var Registry = _dereq_('../../registry');
  23296. var helpers = _dereq_('./helpers');
  23297. module.exports = function getLegendData(calcdata, opts) {
  23298. var lgroupToTraces = {},
  23299. lgroups = [],
  23300. hasOneNonBlankGroup = false,
  23301. slicesShown = {},
  23302. lgroupi = 0;
  23303. var i, j;
  23304. function addOneItem(legendGroup, legendItem) {
  23305. // each '' legend group is treated as a separate group
  23306. if(legendGroup === '' || !helpers.isGrouped(opts)) {
  23307. var uniqueGroup = '~~i' + lgroupi; // TODO: check this against fullData legendgroups?
  23308. lgroups.push(uniqueGroup);
  23309. lgroupToTraces[uniqueGroup] = [[legendItem]];
  23310. lgroupi++;
  23311. }
  23312. else if(lgroups.indexOf(legendGroup) === -1) {
  23313. lgroups.push(legendGroup);
  23314. hasOneNonBlankGroup = true;
  23315. lgroupToTraces[legendGroup] = [[legendItem]];
  23316. }
  23317. else lgroupToTraces[legendGroup].push([legendItem]);
  23318. }
  23319. // build an { legendgroup: [cd0, cd0], ... } object
  23320. for(i = 0; i < calcdata.length; i++) {
  23321. var cd = calcdata[i];
  23322. var cd0 = cd[0];
  23323. var trace = cd0.trace;
  23324. var lgroup = trace.legendgroup;
  23325. if(!trace.visible || !trace.showlegend) continue;
  23326. if(Registry.traceIs(trace, 'pie')) {
  23327. if(!slicesShown[lgroup]) slicesShown[lgroup] = {};
  23328. for(j = 0; j < cd.length; j++) {
  23329. var labelj = cd[j].label;
  23330. if(!slicesShown[lgroup][labelj]) {
  23331. addOneItem(lgroup, {
  23332. label: labelj,
  23333. color: cd[j].color,
  23334. i: cd[j].i,
  23335. trace: trace,
  23336. pts: cd[j].pts
  23337. });
  23338. slicesShown[lgroup][labelj] = true;
  23339. }
  23340. }
  23341. }
  23342. else addOneItem(lgroup, cd0);
  23343. }
  23344. // won't draw a legend in this case
  23345. if(!lgroups.length) return [];
  23346. // rearrange lgroupToTraces into a d3-friendly array of arrays
  23347. var lgroupsLength = lgroups.length,
  23348. ltraces,
  23349. legendData;
  23350. if(hasOneNonBlankGroup && helpers.isGrouped(opts)) {
  23351. legendData = new Array(lgroupsLength);
  23352. for(i = 0; i < lgroupsLength; i++) {
  23353. ltraces = lgroupToTraces[lgroups[i]];
  23354. legendData[i] = helpers.isReversed(opts) ? ltraces.reverse() : ltraces;
  23355. }
  23356. }
  23357. else {
  23358. // collapse all groups into one if all groups are blank
  23359. legendData = [new Array(lgroupsLength)];
  23360. for(i = 0; i < lgroupsLength; i++) {
  23361. ltraces = lgroupToTraces[lgroups[i]][0];
  23362. legendData[0][helpers.isReversed(opts) ? lgroupsLength - i - 1 : i] = ltraces;
  23363. }
  23364. lgroupsLength = 1;
  23365. }
  23366. // needed in repositionLegend
  23367. opts._lgroupsLength = lgroupsLength;
  23368. return legendData;
  23369. };
  23370. },{"../../registry":259,"./helpers":109}],108:[function(_dereq_,module,exports){
  23371. /**
  23372. * Copyright 2012-2018, Plotly, Inc.
  23373. * All rights reserved.
  23374. *
  23375. * This source code is licensed under the MIT license found in the
  23376. * LICENSE file in the root directory of this source tree.
  23377. */
  23378. 'use strict';
  23379. var Lib = _dereq_('../../lib');
  23380. var Registry = _dereq_('../../registry');
  23381. var SHOWISOLATETIP = true;
  23382. module.exports = function handleClick(g, gd, numClicks) {
  23383. if(gd._dragged || gd._editing) return;
  23384. var hiddenSlices = gd._fullLayout.hiddenlabels ?
  23385. gd._fullLayout.hiddenlabels.slice() :
  23386. [];
  23387. var legendItem = g.data()[0][0];
  23388. var fullData = gd._fullData;
  23389. var fullTrace = legendItem.trace;
  23390. var legendgroup = fullTrace.legendgroup;
  23391. var i, j, kcont, key, keys, val;
  23392. var attrUpdate = {};
  23393. var attrIndices = [];
  23394. var carrs = [];
  23395. var carrIdx = [];
  23396. function insertUpdate(traceIndex, key, value) {
  23397. var attrIndex = attrIndices.indexOf(traceIndex);
  23398. var valueArray = attrUpdate[key];
  23399. if(!valueArray) {
  23400. valueArray = attrUpdate[key] = [];
  23401. }
  23402. if(attrIndices.indexOf(traceIndex) === -1) {
  23403. attrIndices.push(traceIndex);
  23404. attrIndex = attrIndices.length - 1;
  23405. }
  23406. valueArray[attrIndex] = value;
  23407. return attrIndex;
  23408. }
  23409. function setVisibility(fullTrace, visibility) {
  23410. var fullInput = fullTrace._fullInput;
  23411. if(Registry.hasTransform(fullInput, 'groupby')) {
  23412. var kcont = carrs[fullInput.index];
  23413. if(!kcont) {
  23414. var groupbyIndices = Registry.getTransformIndices(fullInput, 'groupby');
  23415. var lastGroupbyIndex = groupbyIndices[groupbyIndices.length - 1];
  23416. kcont = Lib.keyedContainer(fullInput, 'transforms[' + lastGroupbyIndex + '].styles', 'target', 'value.visible');
  23417. carrs[fullInput.index] = kcont;
  23418. }
  23419. var curState = kcont.get(fullTrace._group);
  23420. // If not specified, assume visible. This happens if there are other style
  23421. // properties set for a group but not the visibility. There are many similar
  23422. // ways to do this (e.g. why not just `curState = fullTrace.visible`??? The
  23423. // answer is: because it breaks other things like groupby trace names in
  23424. // subtle ways.)
  23425. if(curState === undefined) {
  23426. curState = true;
  23427. }
  23428. if(curState !== false) {
  23429. // true -> legendonly. All others toggle to true:
  23430. kcont.set(fullTrace._group, visibility);
  23431. }
  23432. carrIdx[fullInput.index] = insertUpdate(fullInput.index, 'visible', fullInput.visible === false ? false : true);
  23433. } else {
  23434. // false -> false (not possible since will not be visible in legend)
  23435. // true -> legendonly
  23436. // legendonly -> true
  23437. var nextVisibility = fullInput.visible === false ? false : visibility;
  23438. insertUpdate(fullInput.index, 'visible', nextVisibility);
  23439. }
  23440. }
  23441. if(numClicks === 1 && SHOWISOLATETIP && gd.data && gd._context.showTips) {
  23442. Lib.notifier(Lib._(gd, 'Double-click on legend to isolate one trace'), 'long');
  23443. SHOWISOLATETIP = false;
  23444. } else {
  23445. SHOWISOLATETIP = false;
  23446. }
  23447. if(Registry.traceIs(fullTrace, 'pie')) {
  23448. var thisLabel = legendItem.label,
  23449. thisLabelIndex = hiddenSlices.indexOf(thisLabel);
  23450. if(numClicks === 1) {
  23451. if(thisLabelIndex === -1) hiddenSlices.push(thisLabel);
  23452. else hiddenSlices.splice(thisLabelIndex, 1);
  23453. } else if(numClicks === 2) {
  23454. hiddenSlices = [];
  23455. gd.calcdata[0].forEach(function(d) {
  23456. if(thisLabel !== d.label) {
  23457. hiddenSlices.push(d.label);
  23458. }
  23459. });
  23460. if(gd._fullLayout.hiddenlabels && gd._fullLayout.hiddenlabels.length === hiddenSlices.length && thisLabelIndex === -1) {
  23461. hiddenSlices = [];
  23462. }
  23463. }
  23464. Registry.call('relayout', gd, 'hiddenlabels', hiddenSlices);
  23465. } else {
  23466. var hasLegendgroup = legendgroup && legendgroup.length;
  23467. var traceIndicesInGroup = [];
  23468. var tracei;
  23469. if(hasLegendgroup) {
  23470. for(i = 0; i < fullData.length; i++) {
  23471. tracei = fullData[i];
  23472. if(!tracei.visible) continue;
  23473. if(tracei.legendgroup === legendgroup) {
  23474. traceIndicesInGroup.push(i);
  23475. }
  23476. }
  23477. }
  23478. if(numClicks === 1) {
  23479. var nextVisibility;
  23480. switch(fullTrace.visible) {
  23481. case true:
  23482. nextVisibility = 'legendonly';
  23483. break;
  23484. case false:
  23485. nextVisibility = false;
  23486. break;
  23487. case 'legendonly':
  23488. nextVisibility = true;
  23489. break;
  23490. }
  23491. if(hasLegendgroup) {
  23492. for(i = 0; i < fullData.length; i++) {
  23493. if(fullData[i].visible !== false && fullData[i].legendgroup === legendgroup) {
  23494. setVisibility(fullData[i], nextVisibility);
  23495. }
  23496. }
  23497. } else {
  23498. setVisibility(fullTrace, nextVisibility);
  23499. }
  23500. } else if(numClicks === 2) {
  23501. // Compute the clicked index. expandedIndex does what we want for expanded traces
  23502. // but also culls hidden traces. That means we have some work to do.
  23503. var isClicked, isInGroup, otherState;
  23504. var isIsolated = true;
  23505. for(i = 0; i < fullData.length; i++) {
  23506. isClicked = fullData[i] === fullTrace;
  23507. if(isClicked) continue;
  23508. isInGroup = (hasLegendgroup && fullData[i].legendgroup === legendgroup);
  23509. if(!isInGroup && fullData[i].visible === true && !Registry.traceIs(fullData[i], 'notLegendIsolatable')) {
  23510. isIsolated = false;
  23511. break;
  23512. }
  23513. }
  23514. for(i = 0; i < fullData.length; i++) {
  23515. // False is sticky; we don't change it.
  23516. if(fullData[i].visible === false) continue;
  23517. if(Registry.traceIs(fullData[i], 'notLegendIsolatable')) {
  23518. continue;
  23519. }
  23520. switch(fullTrace.visible) {
  23521. case 'legendonly':
  23522. setVisibility(fullData[i], true);
  23523. break;
  23524. case true:
  23525. otherState = isIsolated ? true : 'legendonly';
  23526. isClicked = fullData[i] === fullTrace;
  23527. isInGroup = isClicked || (hasLegendgroup && fullData[i].legendgroup === legendgroup);
  23528. setVisibility(fullData[i], isInGroup ? true : otherState);
  23529. break;
  23530. }
  23531. }
  23532. }
  23533. for(i = 0; i < carrs.length; i++) {
  23534. kcont = carrs[i];
  23535. if(!kcont) continue;
  23536. var update = kcont.constructUpdate();
  23537. var updateKeys = Object.keys(update);
  23538. for(j = 0; j < updateKeys.length; j++) {
  23539. key = updateKeys[j];
  23540. val = attrUpdate[key] = attrUpdate[key] || [];
  23541. val[carrIdx[i]] = update[key];
  23542. }
  23543. }
  23544. // The length of the value arrays should be equal and any unspecified
  23545. // values should be explicitly undefined for them to get properly culled
  23546. // as updates and not accidentally reset to the default value. This fills
  23547. // out sparse arrays with the required number of undefined values:
  23548. keys = Object.keys(attrUpdate);
  23549. for(i = 0; i < keys.length; i++) {
  23550. key = keys[i];
  23551. for(j = 0; j < attrIndices.length; j++) {
  23552. // Use hasOwnPropety to protect against falsey values:
  23553. if(!attrUpdate[key].hasOwnProperty(j)) {
  23554. attrUpdate[key][j] = undefined;
  23555. }
  23556. }
  23557. }
  23558. Registry.call('restyle', gd, attrUpdate, attrIndices);
  23559. }
  23560. };
  23561. },{"../../lib":169,"../../registry":259}],109:[function(_dereq_,module,exports){
  23562. /**
  23563. * Copyright 2012-2018, Plotly, Inc.
  23564. * All rights reserved.
  23565. *
  23566. * This source code is licensed under the MIT license found in the
  23567. * LICENSE file in the root directory of this source tree.
  23568. */
  23569. 'use strict';
  23570. exports.isGrouped = function isGrouped(legendLayout) {
  23571. return (legendLayout.traceorder || '').indexOf('grouped') !== -1;
  23572. };
  23573. exports.isVertical = function isVertical(legendLayout) {
  23574. return legendLayout.orientation !== 'h';
  23575. };
  23576. exports.isReversed = function isReversed(legendLayout) {
  23577. return (legendLayout.traceorder || '').indexOf('reversed') !== -1;
  23578. };
  23579. },{}],110:[function(_dereq_,module,exports){
  23580. /**
  23581. * Copyright 2012-2018, Plotly, Inc.
  23582. * All rights reserved.
  23583. *
  23584. * This source code is licensed under the MIT license found in the
  23585. * LICENSE file in the root directory of this source tree.
  23586. */
  23587. 'use strict';
  23588. module.exports = {
  23589. moduleType: 'component',
  23590. name: 'legend',
  23591. layoutAttributes: _dereq_('./attributes'),
  23592. supplyLayoutDefaults: _dereq_('./defaults'),
  23593. draw: _dereq_('./draw'),
  23594. style: _dereq_('./style')
  23595. };
  23596. },{"./attributes":103,"./defaults":105,"./draw":106,"./style":111}],111:[function(_dereq_,module,exports){
  23597. /**
  23598. * Copyright 2012-2018, Plotly, Inc.
  23599. * All rights reserved.
  23600. *
  23601. * This source code is licensed under the MIT license found in the
  23602. * LICENSE file in the root directory of this source tree.
  23603. */
  23604. 'use strict';
  23605. var d3 = _dereq_('d3');
  23606. var Registry = _dereq_('../../registry');
  23607. var Lib = _dereq_('../../lib');
  23608. var Drawing = _dereq_('../drawing');
  23609. var Color = _dereq_('../color');
  23610. var subTypes = _dereq_('../../traces/scatter/subtypes');
  23611. var stylePie = _dereq_('../../traces/pie/style_one');
  23612. module.exports = function style(s, gd) {
  23613. s.each(function(d) {
  23614. var traceGroup = d3.select(this);
  23615. var layers = Lib.ensureSingle(traceGroup, 'g', 'layers');
  23616. layers.style('opacity', d[0].trace.opacity);
  23617. var fill = layers
  23618. .selectAll('g.legendfill')
  23619. .data([d]);
  23620. fill.enter().append('g')
  23621. .classed('legendfill', true);
  23622. var line = layers
  23623. .selectAll('g.legendlines')
  23624. .data([d]);
  23625. line.enter().append('g')
  23626. .classed('legendlines', true);
  23627. var symbol = layers
  23628. .selectAll('g.legendsymbols')
  23629. .data([d]);
  23630. symbol.enter().append('g')
  23631. .classed('legendsymbols', true);
  23632. symbol.selectAll('g.legendpoints')
  23633. .data([d])
  23634. .enter().append('g')
  23635. .classed('legendpoints', true);
  23636. })
  23637. .each(styleBars)
  23638. .each(styleBoxes)
  23639. .each(stylePies)
  23640. .each(styleLines)
  23641. .each(stylePoints)
  23642. .each(styleCandles)
  23643. .each(styleOHLC);
  23644. function styleLines(d) {
  23645. var trace = d[0].trace;
  23646. var showFill = trace.visible && trace.fill && trace.fill !== 'none';
  23647. var showLine = subTypes.hasLines(trace);
  23648. var contours = trace.contours;
  23649. var showGradientLine = false;
  23650. var showGradientFill = false;
  23651. if(contours) {
  23652. var coloring = contours.coloring;
  23653. if(coloring === 'lines') {
  23654. showGradientLine = true;
  23655. }
  23656. else {
  23657. showLine = coloring === 'none' || coloring === 'heatmap' ||
  23658. contours.showlines;
  23659. }
  23660. if(contours.type === 'constraint') {
  23661. showFill = contours._operation !== '=';
  23662. }
  23663. else if(coloring === 'fill' || coloring === 'heatmap') {
  23664. showGradientFill = true;
  23665. }
  23666. }
  23667. // with fill and no markers or text, move the line and fill up a bit
  23668. // so it's more centered
  23669. var markersOrText = subTypes.hasMarkers(trace) || subTypes.hasText(trace);
  23670. var anyFill = showFill || showGradientFill;
  23671. var anyLine = showLine || showGradientLine;
  23672. var pathStart = (markersOrText || !anyFill) ? 'M5,0' :
  23673. // with a line leave it slightly below center, to leave room for the
  23674. // line thickness and because the line is usually more prominent
  23675. anyLine ? 'M5,-2' : 'M5,-3';
  23676. var this3 = d3.select(this);
  23677. var fill = this3.select('.legendfill').selectAll('path')
  23678. .data(showFill || showGradientFill ? [d] : []);
  23679. fill.enter().append('path').classed('js-fill', true);
  23680. fill.exit().remove();
  23681. fill.attr('d', pathStart + 'h30v6h-30z')
  23682. .call(showFill ? Drawing.fillGroupStyle : fillGradient);
  23683. var line = this3.select('.legendlines').selectAll('path')
  23684. .data(showLine || showGradientLine ? [d] : []);
  23685. line.enter().append('path').classed('js-line', true);
  23686. line.exit().remove();
  23687. // this is ugly... but you can't apply a gradient to a perfectly
  23688. // horizontal or vertical line. Presumably because then
  23689. // the system doesn't know how to scale vertical variation, even
  23690. // though there *is* no vertical variation in this case.
  23691. // so add an invisibly small angle to the line
  23692. // This issue (and workaround) exist across (Mac) Chrome, FF, and Safari
  23693. line.attr('d', pathStart + (showGradientLine ? 'l30,0.0001' : 'h30'))
  23694. .call(showLine ? Drawing.lineGroupStyle : lineGradient);
  23695. function fillGradient(s) {
  23696. if(s.size()) {
  23697. var gradientID = 'legendfill-' + trace.uid;
  23698. Drawing.gradient(s, gd, gradientID, 'horizontalreversed',
  23699. trace.colorscale, 'fill');
  23700. }
  23701. }
  23702. function lineGradient(s) {
  23703. if(s.size()) {
  23704. var gradientID = 'legendline-' + trace.uid;
  23705. Drawing.lineGroupStyle(s);
  23706. Drawing.gradient(s, gd, gradientID, 'horizontalreversed',
  23707. trace.colorscale, 'stroke');
  23708. }
  23709. }
  23710. }
  23711. function stylePoints(d) {
  23712. var d0 = d[0];
  23713. var trace = d0.trace;
  23714. var showMarkers = subTypes.hasMarkers(trace);
  23715. var showText = subTypes.hasText(trace);
  23716. var showLines = subTypes.hasLines(trace);
  23717. var dMod, tMod;
  23718. // 'scatter3d' don't use gd.calcdata,
  23719. // use d0.trace to infer arrayOk attributes
  23720. function boundVal(attrIn, arrayToValFn, bounds) {
  23721. var valIn = Lib.nestedProperty(trace, attrIn).get();
  23722. var valToBound = (Array.isArray(valIn) && arrayToValFn) ?
  23723. arrayToValFn(valIn) :
  23724. valIn;
  23725. if(bounds) {
  23726. if(valToBound < bounds[0]) return bounds[0];
  23727. else if(valToBound > bounds[1]) return bounds[1];
  23728. }
  23729. return valToBound;
  23730. }
  23731. function pickFirst(array) { return array[0]; }
  23732. // constrain text, markers, etc so they'll fit on the legend
  23733. if(showMarkers || showText || showLines) {
  23734. var dEdit = {};
  23735. var tEdit = {};
  23736. if(showMarkers) {
  23737. dEdit.mc = boundVal('marker.color', pickFirst);
  23738. dEdit.mx = boundVal('marker.symbol', pickFirst);
  23739. dEdit.mo = boundVal('marker.opacity', Lib.mean, [0.2, 1]);
  23740. dEdit.mlc = boundVal('marker.line.color', pickFirst);
  23741. dEdit.mlw = boundVal('marker.line.width', Lib.mean, [0, 5]);
  23742. tEdit.marker = {
  23743. sizeref: 1,
  23744. sizemin: 1,
  23745. sizemode: 'diameter'
  23746. };
  23747. var ms = boundVal('marker.size', Lib.mean, [2, 16]);
  23748. dEdit.ms = ms;
  23749. tEdit.marker.size = ms;
  23750. }
  23751. if(showLines) {
  23752. tEdit.line = {
  23753. width: boundVal('line.width', pickFirst, [0, 10])
  23754. };
  23755. }
  23756. if(showText) {
  23757. dEdit.tx = 'Aa';
  23758. dEdit.tp = boundVal('textposition', pickFirst);
  23759. dEdit.ts = 10;
  23760. dEdit.tc = boundVal('textfont.color', pickFirst);
  23761. dEdit.tf = boundVal('textfont.family', pickFirst);
  23762. }
  23763. dMod = [Lib.minExtend(d0, dEdit)];
  23764. tMod = Lib.minExtend(trace, tEdit);
  23765. // always show legend items in base state
  23766. tMod.selectedpoints = null;
  23767. }
  23768. var ptgroup = d3.select(this).select('g.legendpoints');
  23769. var pts = ptgroup.selectAll('path.scatterpts')
  23770. .data(showMarkers ? dMod : []);
  23771. // make sure marker is on the bottom, in case it enters after text
  23772. pts.enter().insert('path', ':first-child')
  23773. .classed('scatterpts', true)
  23774. .attr('transform', 'translate(20,0)');
  23775. pts.exit().remove();
  23776. pts.call(Drawing.pointStyle, tMod, gd);
  23777. // 'mrc' is set in pointStyle and used in textPointStyle:
  23778. // constrain it here
  23779. if(showMarkers) dMod[0].mrc = 3;
  23780. var txt = ptgroup.selectAll('g.pointtext')
  23781. .data(showText ? dMod : []);
  23782. txt.enter()
  23783. .append('g').classed('pointtext', true)
  23784. .append('text').attr('transform', 'translate(20,0)');
  23785. txt.exit().remove();
  23786. txt.selectAll('text').call(Drawing.textPointStyle, tMod, gd);
  23787. }
  23788. function styleBars(d) {
  23789. var trace = d[0].trace,
  23790. marker = trace.marker || {},
  23791. markerLine = marker.line || {},
  23792. barpath = d3.select(this).select('g.legendpoints')
  23793. .selectAll('path.legendbar')
  23794. .data(Registry.traceIs(trace, 'bar') ? [d] : []);
  23795. barpath.enter().append('path').classed('legendbar', true)
  23796. .attr('d', 'M6,6H-6V-6H6Z')
  23797. .attr('transform', 'translate(20,0)');
  23798. barpath.exit().remove();
  23799. barpath.each(function(d) {
  23800. var p = d3.select(this),
  23801. d0 = d[0],
  23802. w = (d0.mlw + 1 || markerLine.width + 1) - 1;
  23803. p.style('stroke-width', w + 'px')
  23804. .call(Color.fill, d0.mc || marker.color);
  23805. if(w) {
  23806. p.call(Color.stroke, d0.mlc || markerLine.color);
  23807. }
  23808. });
  23809. }
  23810. function styleBoxes(d) {
  23811. var trace = d[0].trace,
  23812. pts = d3.select(this).select('g.legendpoints')
  23813. .selectAll('path.legendbox')
  23814. .data(Registry.traceIs(trace, 'box-violin') && trace.visible ? [d] : []);
  23815. pts.enter().append('path').classed('legendbox', true)
  23816. // if we want the median bar, prepend M6,0H-6
  23817. .attr('d', 'M6,6H-6V-6H6Z')
  23818. .attr('transform', 'translate(20,0)');
  23819. pts.exit().remove();
  23820. pts.each(function() {
  23821. var w = trace.line.width,
  23822. p = d3.select(this);
  23823. p.style('stroke-width', w + 'px')
  23824. .call(Color.fill, trace.fillcolor);
  23825. if(w) {
  23826. Color.stroke(p, trace.line.color);
  23827. }
  23828. });
  23829. }
  23830. function styleCandles(d) {
  23831. var trace = d[0].trace,
  23832. pts = d3.select(this).select('g.legendpoints')
  23833. .selectAll('path.legendcandle')
  23834. .data(trace.type === 'candlestick' && trace.visible ? [d, d] : []);
  23835. pts.enter().append('path').classed('legendcandle', true)
  23836. .attr('d', function(_, i) {
  23837. if(i) return 'M-15,0H-8M-8,6V-6H8Z'; // increasing
  23838. return 'M15,0H8M8,-6V6H-8Z'; // decreasing
  23839. })
  23840. .attr('transform', 'translate(20,0)')
  23841. .style('stroke-miterlimit', 1);
  23842. pts.exit().remove();
  23843. pts.each(function(_, i) {
  23844. var container = trace[i ? 'increasing' : 'decreasing'];
  23845. var w = container.line.width,
  23846. p = d3.select(this);
  23847. p.style('stroke-width', w + 'px')
  23848. .call(Color.fill, container.fillcolor);
  23849. if(w) {
  23850. Color.stroke(p, container.line.color);
  23851. }
  23852. });
  23853. }
  23854. function styleOHLC(d) {
  23855. var trace = d[0].trace,
  23856. pts = d3.select(this).select('g.legendpoints')
  23857. .selectAll('path.legendohlc')
  23858. .data(trace.type === 'ohlc' && trace.visible ? [d, d] : []);
  23859. pts.enter().append('path').classed('legendohlc', true)
  23860. .attr('d', function(_, i) {
  23861. if(i) return 'M-15,0H0M-8,-6V0'; // increasing
  23862. return 'M15,0H0M8,6V0'; // decreasing
  23863. })
  23864. .attr('transform', 'translate(20,0)')
  23865. .style('stroke-miterlimit', 1);
  23866. pts.exit().remove();
  23867. pts.each(function(_, i) {
  23868. var container = trace[i ? 'increasing' : 'decreasing'];
  23869. var w = container.line.width,
  23870. p = d3.select(this);
  23871. p.style('fill', 'none')
  23872. .call(Drawing.dashLine, container.line.dash, w);
  23873. if(w) {
  23874. Color.stroke(p, container.line.color);
  23875. }
  23876. });
  23877. }
  23878. function stylePies(d) {
  23879. var trace = d[0].trace,
  23880. pts = d3.select(this).select('g.legendpoints')
  23881. .selectAll('path.legendpie')
  23882. .data(Registry.traceIs(trace, 'pie') && trace.visible ? [d] : []);
  23883. pts.enter().append('path').classed('legendpie', true)
  23884. .attr('d', 'M6,6H-6V-6H6Z')
  23885. .attr('transform', 'translate(20,0)');
  23886. pts.exit().remove();
  23887. if(pts.size()) pts.call(stylePie, d[0], trace);
  23888. }
  23889. };
  23890. },{"../../lib":169,"../../registry":259,"../../traces/pie/style_one":364,"../../traces/scatter/subtypes":390,"../color":50,"../drawing":75,"d3":16}],112:[function(_dereq_,module,exports){
  23891. /**
  23892. * Copyright 2012-2018, Plotly, Inc.
  23893. * All rights reserved.
  23894. *
  23895. * This source code is licensed under the MIT license found in the
  23896. * LICENSE file in the root directory of this source tree.
  23897. */
  23898. 'use strict';
  23899. var Registry = _dereq_('../../registry');
  23900. var Plots = _dereq_('../../plots/plots');
  23901. var axisIds = _dereq_('../../plots/cartesian/axis_ids');
  23902. var Lib = _dereq_('../../lib');
  23903. var Icons = _dereq_('../../../build/ploticon');
  23904. var _ = Lib._;
  23905. var modeBarButtons = module.exports = {};
  23906. /**
  23907. * ModeBar buttons configuration
  23908. *
  23909. * @param {string} name
  23910. * name / id of the buttons (for tracking)
  23911. * @param {string} title
  23912. * text that appears while hovering over the button,
  23913. * enter null, false or '' for no hover text
  23914. * @param {string} icon
  23915. * svg icon object associated with the button
  23916. * can be linked to Plotly.Icons to use the default plotly icons
  23917. * @param {string} [gravity]
  23918. * icon positioning
  23919. * @param {function} click
  23920. * click handler associated with the button, a function of
  23921. * 'gd' (the main graph object) and
  23922. * 'ev' (the event object)
  23923. * @param {string} [attr]
  23924. * attribute associated with button,
  23925. * use this with 'val' to keep track of the state
  23926. * @param {*} [val]
  23927. * initial 'attr' value, can be a function of gd
  23928. * @param {boolean} [toggle]
  23929. * is the button a toggle button?
  23930. */
  23931. modeBarButtons.toImage = {
  23932. name: 'toImage',
  23933. title: function(gd) {
  23934. var opts = gd._context.toImageButtonOptions || {};
  23935. var format = opts.format || 'png';
  23936. return format === 'png' ?
  23937. _(gd, 'Download plot as a png') : // legacy text
  23938. _(gd, 'Download plot'); // generic non-PNG text
  23939. },
  23940. icon: Icons.camera,
  23941. click: function(gd) {
  23942. var toImageButtonOptions = gd._context.toImageButtonOptions;
  23943. var opts = {format: toImageButtonOptions.format || 'png'};
  23944. Lib.notifier(_(gd, 'Taking snapshot - this may take a few seconds'), 'long');
  23945. if(opts.format !== 'svg' && Lib.isIE()) {
  23946. Lib.notifier(_(gd, 'IE only supports svg. Changing format to svg.'), 'long');
  23947. opts.format = 'svg';
  23948. }
  23949. ['filename', 'width', 'height', 'scale'].forEach(function(key) {
  23950. if(toImageButtonOptions[key]) {
  23951. opts[key] = toImageButtonOptions[key];
  23952. }
  23953. });
  23954. Registry.call('downloadImage', gd, opts)
  23955. .then(function(filename) {
  23956. Lib.notifier(_(gd, 'Snapshot succeeded') + ' - ' + filename, 'long');
  23957. })
  23958. .catch(function() {
  23959. Lib.notifier(_(gd, 'Sorry, there was a problem downloading your snapshot!'), 'long');
  23960. });
  23961. }
  23962. };
  23963. modeBarButtons.sendDataToCloud = {
  23964. name: 'sendDataToCloud',
  23965. title: function(gd) { return _(gd, 'Edit in Chart Studio'); },
  23966. icon: Icons.disk,
  23967. click: function(gd) {
  23968. Plots.sendDataToCloud(gd);
  23969. }
  23970. };
  23971. modeBarButtons.zoom2d = {
  23972. name: 'zoom2d',
  23973. title: function(gd) { return _(gd, 'Zoom'); },
  23974. attr: 'dragmode',
  23975. val: 'zoom',
  23976. icon: Icons.zoombox,
  23977. click: handleCartesian
  23978. };
  23979. modeBarButtons.pan2d = {
  23980. name: 'pan2d',
  23981. title: function(gd) { return _(gd, 'Pan'); },
  23982. attr: 'dragmode',
  23983. val: 'pan',
  23984. icon: Icons.pan,
  23985. click: handleCartesian
  23986. };
  23987. modeBarButtons.select2d = {
  23988. name: 'select2d',
  23989. title: function(gd) { return _(gd, 'Box Select'); },
  23990. attr: 'dragmode',
  23991. val: 'select',
  23992. icon: Icons.selectbox,
  23993. click: handleCartesian
  23994. };
  23995. modeBarButtons.lasso2d = {
  23996. name: 'lasso2d',
  23997. title: function(gd) { return _(gd, 'Lasso Select'); },
  23998. attr: 'dragmode',
  23999. val: 'lasso',
  24000. icon: Icons.lasso,
  24001. click: handleCartesian
  24002. };
  24003. modeBarButtons.zoomIn2d = {
  24004. name: 'zoomIn2d',
  24005. title: function(gd) { return _(gd, 'Zoom in'); },
  24006. attr: 'zoom',
  24007. val: 'in',
  24008. icon: Icons.zoom_plus,
  24009. click: handleCartesian
  24010. };
  24011. modeBarButtons.zoomOut2d = {
  24012. name: 'zoomOut2d',
  24013. title: function(gd) { return _(gd, 'Zoom out'); },
  24014. attr: 'zoom',
  24015. val: 'out',
  24016. icon: Icons.zoom_minus,
  24017. click: handleCartesian
  24018. };
  24019. modeBarButtons.autoScale2d = {
  24020. name: 'autoScale2d',
  24021. title: function(gd) { return _(gd, 'Autoscale'); },
  24022. attr: 'zoom',
  24023. val: 'auto',
  24024. icon: Icons.autoscale,
  24025. click: handleCartesian
  24026. };
  24027. modeBarButtons.resetScale2d = {
  24028. name: 'resetScale2d',
  24029. title: function(gd) { return _(gd, 'Reset axes'); },
  24030. attr: 'zoom',
  24031. val: 'reset',
  24032. icon: Icons.home,
  24033. click: handleCartesian
  24034. };
  24035. modeBarButtons.hoverClosestCartesian = {
  24036. name: 'hoverClosestCartesian',
  24037. title: function(gd) { return _(gd, 'Show closest data on hover'); },
  24038. attr: 'hovermode',
  24039. val: 'closest',
  24040. icon: Icons.tooltip_basic,
  24041. gravity: 'ne',
  24042. click: handleCartesian
  24043. };
  24044. modeBarButtons.hoverCompareCartesian = {
  24045. name: 'hoverCompareCartesian',
  24046. title: function(gd) { return _(gd, 'Compare data on hover'); },
  24047. attr: 'hovermode',
  24048. val: function(gd) {
  24049. return gd._fullLayout._isHoriz ? 'y' : 'x';
  24050. },
  24051. icon: Icons.tooltip_compare,
  24052. gravity: 'ne',
  24053. click: handleCartesian
  24054. };
  24055. function handleCartesian(gd, ev) {
  24056. var button = ev.currentTarget;
  24057. var astr = button.getAttribute('data-attr');
  24058. var val = button.getAttribute('data-val') || true;
  24059. var fullLayout = gd._fullLayout;
  24060. var aobj = {};
  24061. var axList = axisIds.list(gd, null, true);
  24062. var allSpikesEnabled = 'on';
  24063. var ax, i;
  24064. if(astr === 'zoom') {
  24065. var mag = (val === 'in') ? 0.5 : 2,
  24066. r0 = (1 + mag) / 2,
  24067. r1 = (1 - mag) / 2;
  24068. var axName;
  24069. for(i = 0; i < axList.length; i++) {
  24070. ax = axList[i];
  24071. if(!ax.fixedrange) {
  24072. axName = ax._name;
  24073. if(val === 'auto') aobj[axName + '.autorange'] = true;
  24074. else if(val === 'reset') {
  24075. if(ax._rangeInitial === undefined) {
  24076. aobj[axName + '.autorange'] = true;
  24077. }
  24078. else {
  24079. var rangeInitial = ax._rangeInitial.slice();
  24080. aobj[axName + '.range[0]'] = rangeInitial[0];
  24081. aobj[axName + '.range[1]'] = rangeInitial[1];
  24082. }
  24083. if(ax._showSpikeInitial !== undefined) {
  24084. aobj[axName + '.showspikes'] = ax._showSpikeInitial;
  24085. if(allSpikesEnabled === 'on' && !ax._showSpikeInitial) {
  24086. allSpikesEnabled = 'off';
  24087. }
  24088. }
  24089. }
  24090. else {
  24091. var rangeNow = [
  24092. ax.r2l(ax.range[0]),
  24093. ax.r2l(ax.range[1]),
  24094. ];
  24095. var rangeNew = [
  24096. r0 * rangeNow[0] + r1 * rangeNow[1],
  24097. r0 * rangeNow[1] + r1 * rangeNow[0]
  24098. ];
  24099. aobj[axName + '.range[0]'] = ax.l2r(rangeNew[0]);
  24100. aobj[axName + '.range[1]'] = ax.l2r(rangeNew[1]);
  24101. }
  24102. }
  24103. }
  24104. fullLayout._cartesianSpikesEnabled = allSpikesEnabled;
  24105. }
  24106. else {
  24107. // if ALL traces have orientation 'h', 'hovermode': 'x' otherwise: 'y'
  24108. if(astr === 'hovermode' && (val === 'x' || val === 'y')) {
  24109. val = fullLayout._isHoriz ? 'y' : 'x';
  24110. button.setAttribute('data-val', val);
  24111. } else if(astr === 'hovermode' && val === 'closest') {
  24112. for(i = 0; i < axList.length; i++) {
  24113. ax = axList[i];
  24114. if(allSpikesEnabled === 'on' && !ax.showspikes) {
  24115. allSpikesEnabled = 'off';
  24116. }
  24117. }
  24118. fullLayout._cartesianSpikesEnabled = allSpikesEnabled;
  24119. }
  24120. aobj[astr] = val;
  24121. }
  24122. Registry.call('relayout', gd, aobj);
  24123. }
  24124. modeBarButtons.zoom3d = {
  24125. name: 'zoom3d',
  24126. title: function(gd) { return _(gd, 'Zoom'); },
  24127. attr: 'scene.dragmode',
  24128. val: 'zoom',
  24129. icon: Icons.zoombox,
  24130. click: handleDrag3d
  24131. };
  24132. modeBarButtons.pan3d = {
  24133. name: 'pan3d',
  24134. title: function(gd) { return _(gd, 'Pan'); },
  24135. attr: 'scene.dragmode',
  24136. val: 'pan',
  24137. icon: Icons.pan,
  24138. click: handleDrag3d
  24139. };
  24140. modeBarButtons.orbitRotation = {
  24141. name: 'orbitRotation',
  24142. title: function(gd) { return _(gd, 'Orbital rotation'); },
  24143. attr: 'scene.dragmode',
  24144. val: 'orbit',
  24145. icon: Icons['3d_rotate'],
  24146. click: handleDrag3d
  24147. };
  24148. modeBarButtons.tableRotation = {
  24149. name: 'tableRotation',
  24150. title: function(gd) { return _(gd, 'Turntable rotation'); },
  24151. attr: 'scene.dragmode',
  24152. val: 'turntable',
  24153. icon: Icons['z-axis'],
  24154. click: handleDrag3d
  24155. };
  24156. function handleDrag3d(gd, ev) {
  24157. var button = ev.currentTarget;
  24158. var attr = button.getAttribute('data-attr');
  24159. var val = button.getAttribute('data-val') || true;
  24160. var sceneIds = gd._fullLayout._subplots.gl3d;
  24161. var layoutUpdate = {};
  24162. var parts = attr.split('.');
  24163. for(var i = 0; i < sceneIds.length; i++) {
  24164. layoutUpdate[sceneIds[i] + '.' + parts[1]] = val;
  24165. }
  24166. // for multi-type subplots
  24167. var val2d = (val === 'pan') ? val : 'zoom';
  24168. layoutUpdate.dragmode = val2d;
  24169. Registry.call('relayout', gd, layoutUpdate);
  24170. }
  24171. modeBarButtons.resetCameraDefault3d = {
  24172. name: 'resetCameraDefault3d',
  24173. title: function(gd) { return _(gd, 'Reset camera to default'); },
  24174. attr: 'resetDefault',
  24175. icon: Icons.home,
  24176. click: handleCamera3d
  24177. };
  24178. modeBarButtons.resetCameraLastSave3d = {
  24179. name: 'resetCameraLastSave3d',
  24180. title: function(gd) { return _(gd, 'Reset camera to last save'); },
  24181. attr: 'resetLastSave',
  24182. icon: Icons.movie,
  24183. click: handleCamera3d
  24184. };
  24185. function handleCamera3d(gd, ev) {
  24186. var button = ev.currentTarget;
  24187. var attr = button.getAttribute('data-attr');
  24188. var fullLayout = gd._fullLayout;
  24189. var sceneIds = fullLayout._subplots.gl3d;
  24190. var aobj = {};
  24191. for(var i = 0; i < sceneIds.length; i++) {
  24192. var sceneId = sceneIds[i],
  24193. key = sceneId + '.camera',
  24194. scene = fullLayout[sceneId]._scene;
  24195. if(attr === 'resetDefault') {
  24196. aobj[key] = null;
  24197. }
  24198. else if(attr === 'resetLastSave') {
  24199. aobj[key] = Lib.extendDeep({}, scene.cameraInitial);
  24200. }
  24201. }
  24202. Registry.call('relayout', gd, aobj);
  24203. }
  24204. modeBarButtons.hoverClosest3d = {
  24205. name: 'hoverClosest3d',
  24206. title: function(gd) { return _(gd, 'Toggle show closest data on hover'); },
  24207. attr: 'hovermode',
  24208. val: null,
  24209. toggle: true,
  24210. icon: Icons.tooltip_basic,
  24211. gravity: 'ne',
  24212. click: handleHover3d
  24213. };
  24214. function handleHover3d(gd, ev) {
  24215. var button = ev.currentTarget;
  24216. var val = button._previousVal || false;
  24217. var layout = gd.layout;
  24218. var fullLayout = gd._fullLayout;
  24219. var sceneIds = fullLayout._subplots.gl3d;
  24220. var axes = ['xaxis', 'yaxis', 'zaxis'];
  24221. var spikeAttrs = ['showspikes', 'spikesides', 'spikethickness', 'spikecolor'];
  24222. // initialize 'current spike' object to be stored in the DOM
  24223. var currentSpikes = {};
  24224. var axisSpikes = {};
  24225. var layoutUpdate = {};
  24226. if(val) {
  24227. layoutUpdate = Lib.extendDeep(layout, val);
  24228. button._previousVal = null;
  24229. }
  24230. else {
  24231. layoutUpdate = {
  24232. 'allaxes.showspikes': false
  24233. };
  24234. for(var i = 0; i < sceneIds.length; i++) {
  24235. var sceneId = sceneIds[i],
  24236. sceneLayout = fullLayout[sceneId],
  24237. sceneSpikes = currentSpikes[sceneId] = {};
  24238. sceneSpikes.hovermode = sceneLayout.hovermode;
  24239. layoutUpdate[sceneId + '.hovermode'] = false;
  24240. // copy all the current spike attrs
  24241. for(var j = 0; j < 3; j++) {
  24242. var axis = axes[j];
  24243. axisSpikes = sceneSpikes[axis] = {};
  24244. for(var k = 0; k < spikeAttrs.length; k++) {
  24245. var spikeAttr = spikeAttrs[k];
  24246. axisSpikes[spikeAttr] = sceneLayout[axis][spikeAttr];
  24247. }
  24248. }
  24249. }
  24250. button._previousVal = Lib.extendDeep({}, currentSpikes);
  24251. }
  24252. Registry.call('relayout', gd, layoutUpdate);
  24253. }
  24254. modeBarButtons.zoomInGeo = {
  24255. name: 'zoomInGeo',
  24256. title: function(gd) { return _(gd, 'Zoom in'); },
  24257. attr: 'zoom',
  24258. val: 'in',
  24259. icon: Icons.zoom_plus,
  24260. click: handleGeo
  24261. };
  24262. modeBarButtons.zoomOutGeo = {
  24263. name: 'zoomOutGeo',
  24264. title: function(gd) { return _(gd, 'Zoom out'); },
  24265. attr: 'zoom',
  24266. val: 'out',
  24267. icon: Icons.zoom_minus,
  24268. click: handleGeo
  24269. };
  24270. modeBarButtons.resetGeo = {
  24271. name: 'resetGeo',
  24272. title: function(gd) { return _(gd, 'Reset'); },
  24273. attr: 'reset',
  24274. val: null,
  24275. icon: Icons.autoscale,
  24276. click: handleGeo
  24277. };
  24278. modeBarButtons.hoverClosestGeo = {
  24279. name: 'hoverClosestGeo',
  24280. title: function(gd) { return _(gd, 'Toggle show closest data on hover'); },
  24281. attr: 'hovermode',
  24282. val: null,
  24283. toggle: true,
  24284. icon: Icons.tooltip_basic,
  24285. gravity: 'ne',
  24286. click: toggleHover
  24287. };
  24288. function handleGeo(gd, ev) {
  24289. var button = ev.currentTarget;
  24290. var attr = button.getAttribute('data-attr');
  24291. var val = button.getAttribute('data-val') || true;
  24292. var fullLayout = gd._fullLayout;
  24293. var geoIds = fullLayout._subplots.geo;
  24294. for(var i = 0; i < geoIds.length; i++) {
  24295. var id = geoIds[i];
  24296. var geoLayout = fullLayout[id];
  24297. if(attr === 'zoom') {
  24298. var scale = geoLayout.projection.scale;
  24299. var newScale = (val === 'in') ? 2 * scale : 0.5 * scale;
  24300. Registry.call('relayout', gd, id + '.projection.scale', newScale);
  24301. } else if(attr === 'reset') {
  24302. resetView(gd, 'geo');
  24303. }
  24304. }
  24305. }
  24306. modeBarButtons.hoverClosestGl2d = {
  24307. name: 'hoverClosestGl2d',
  24308. title: function(gd) { return _(gd, 'Toggle show closest data on hover'); },
  24309. attr: 'hovermode',
  24310. val: null,
  24311. toggle: true,
  24312. icon: Icons.tooltip_basic,
  24313. gravity: 'ne',
  24314. click: toggleHover
  24315. };
  24316. modeBarButtons.hoverClosestPie = {
  24317. name: 'hoverClosestPie',
  24318. title: function(gd) { return _(gd, 'Toggle show closest data on hover'); },
  24319. attr: 'hovermode',
  24320. val: 'closest',
  24321. icon: Icons.tooltip_basic,
  24322. gravity: 'ne',
  24323. click: toggleHover
  24324. };
  24325. function toggleHover(gd) {
  24326. var fullLayout = gd._fullLayout;
  24327. var onHoverVal;
  24328. if(fullLayout._has('cartesian')) {
  24329. onHoverVal = fullLayout._isHoriz ? 'y' : 'x';
  24330. }
  24331. else onHoverVal = 'closest';
  24332. var newHover = gd._fullLayout.hovermode ? false : onHoverVal;
  24333. Registry.call('relayout', gd, 'hovermode', newHover);
  24334. }
  24335. // buttons when more then one plot types are present
  24336. modeBarButtons.toggleHover = {
  24337. name: 'toggleHover',
  24338. title: function(gd) { return _(gd, 'Toggle show closest data on hover'); },
  24339. attr: 'hovermode',
  24340. val: null,
  24341. toggle: true,
  24342. icon: Icons.tooltip_basic,
  24343. gravity: 'ne',
  24344. click: function(gd, ev) {
  24345. toggleHover(gd);
  24346. // the 3d hovermode update must come
  24347. // last so that layout.hovermode update does not
  24348. // override scene?.hovermode?.layout.
  24349. handleHover3d(gd, ev);
  24350. }
  24351. };
  24352. modeBarButtons.resetViews = {
  24353. name: 'resetViews',
  24354. title: function(gd) { return _(gd, 'Reset views'); },
  24355. icon: Icons.home,
  24356. click: function(gd, ev) {
  24357. var button = ev.currentTarget;
  24358. button.setAttribute('data-attr', 'zoom');
  24359. button.setAttribute('data-val', 'reset');
  24360. handleCartesian(gd, ev);
  24361. button.setAttribute('data-attr', 'resetLastSave');
  24362. handleCamera3d(gd, ev);
  24363. resetView(gd, 'geo');
  24364. resetView(gd, 'mapbox');
  24365. }
  24366. };
  24367. modeBarButtons.toggleSpikelines = {
  24368. name: 'toggleSpikelines',
  24369. title: function(gd) { return _(gd, 'Toggle Spike Lines'); },
  24370. icon: Icons.spikeline,
  24371. attr: '_cartesianSpikesEnabled',
  24372. val: 'on',
  24373. click: function(gd) {
  24374. var fullLayout = gd._fullLayout;
  24375. fullLayout._cartesianSpikesEnabled = fullLayout._cartesianSpikesEnabled === 'on' ? 'off' : 'on';
  24376. var aobj = setSpikelineVisibility(gd);
  24377. Registry.call('relayout', gd, aobj);
  24378. }
  24379. };
  24380. function setSpikelineVisibility(gd) {
  24381. var fullLayout = gd._fullLayout;
  24382. var axList = axisIds.list(gd, null, true);
  24383. var aobj = {};
  24384. var ax, axName;
  24385. for(var i = 0; i < axList.length; i++) {
  24386. ax = axList[i];
  24387. axName = ax._name;
  24388. aobj[axName + '.showspikes'] = fullLayout._cartesianSpikesEnabled === 'on' ? true : ax._showSpikeInitial;
  24389. }
  24390. return aobj;
  24391. }
  24392. modeBarButtons.resetViewMapbox = {
  24393. name: 'resetViewMapbox',
  24394. title: function(gd) { return _(gd, 'Reset view'); },
  24395. attr: 'reset',
  24396. icon: Icons.home,
  24397. click: function(gd) {
  24398. resetView(gd, 'mapbox');
  24399. }
  24400. };
  24401. function resetView(gd, subplotType) {
  24402. var fullLayout = gd._fullLayout;
  24403. var subplotIds = fullLayout._subplots[subplotType];
  24404. var aObj = {};
  24405. for(var i = 0; i < subplotIds.length; i++) {
  24406. var id = subplotIds[i];
  24407. var subplotObj = fullLayout[id]._subplot;
  24408. var viewInitial = subplotObj.viewInitial;
  24409. var viewKeys = Object.keys(viewInitial);
  24410. for(var j = 0; j < viewKeys.length; j++) {
  24411. var key = viewKeys[j];
  24412. aObj[id + '.' + key] = viewInitial[key];
  24413. }
  24414. }
  24415. Registry.call('relayout', gd, aObj);
  24416. }
  24417. },{"../../../build/ploticon":2,"../../lib":169,"../../plots/cartesian/axis_ids":217,"../../plots/plots":246,"../../registry":259}],113:[function(_dereq_,module,exports){
  24418. /**
  24419. * Copyright 2012-2018, Plotly, Inc.
  24420. * All rights reserved.
  24421. *
  24422. * This source code is licensed under the MIT license found in the
  24423. * LICENSE file in the root directory of this source tree.
  24424. */
  24425. 'use strict';
  24426. exports.manage = _dereq_('./manage');
  24427. },{"./manage":114}],114:[function(_dereq_,module,exports){
  24428. /**
  24429. * Copyright 2012-2018, Plotly, Inc.
  24430. * All rights reserved.
  24431. *
  24432. * This source code is licensed under the MIT license found in the
  24433. * LICENSE file in the root directory of this source tree.
  24434. */
  24435. 'use strict';
  24436. var axisIds = _dereq_('../../plots/cartesian/axis_ids');
  24437. var scatterSubTypes = _dereq_('../../traces/scatter/subtypes');
  24438. var Registry = _dereq_('../../registry');
  24439. var createModeBar = _dereq_('./modebar');
  24440. var modeBarButtons = _dereq_('./buttons');
  24441. /**
  24442. * ModeBar wrapper around 'create' and 'update',
  24443. * chooses buttons to pass to ModeBar constructor based on
  24444. * plot type and plot config.
  24445. *
  24446. * @param {object} gd main plot object
  24447. *
  24448. */
  24449. module.exports = function manageModeBar(gd) {
  24450. var fullLayout = gd._fullLayout,
  24451. context = gd._context,
  24452. modeBar = fullLayout._modeBar;
  24453. if(!context.displayModeBar) {
  24454. if(modeBar) {
  24455. modeBar.destroy();
  24456. delete fullLayout._modeBar;
  24457. }
  24458. return;
  24459. }
  24460. if(!Array.isArray(context.modeBarButtonsToRemove)) {
  24461. throw new Error([
  24462. '*modeBarButtonsToRemove* configuration options',
  24463. 'must be an array.'
  24464. ].join(' '));
  24465. }
  24466. if(!Array.isArray(context.modeBarButtonsToAdd)) {
  24467. throw new Error([
  24468. '*modeBarButtonsToAdd* configuration options',
  24469. 'must be an array.'
  24470. ].join(' '));
  24471. }
  24472. var customButtons = context.modeBarButtons;
  24473. var buttonGroups;
  24474. if(Array.isArray(customButtons) && customButtons.length) {
  24475. buttonGroups = fillCustomButton(customButtons);
  24476. }
  24477. else {
  24478. buttonGroups = getButtonGroups(
  24479. gd,
  24480. context.modeBarButtonsToRemove,
  24481. context.modeBarButtonsToAdd
  24482. );
  24483. }
  24484. if(modeBar) modeBar.update(gd, buttonGroups);
  24485. else fullLayout._modeBar = createModeBar(gd, buttonGroups);
  24486. };
  24487. // logic behind which buttons are displayed by default
  24488. function getButtonGroups(gd, buttonsToRemove, buttonsToAdd) {
  24489. var fullLayout = gd._fullLayout;
  24490. var fullData = gd._fullData;
  24491. var hasCartesian = fullLayout._has('cartesian');
  24492. var hasGL3D = fullLayout._has('gl3d');
  24493. var hasGeo = fullLayout._has('geo');
  24494. var hasPie = fullLayout._has('pie');
  24495. var hasGL2D = fullLayout._has('gl2d');
  24496. var hasTernary = fullLayout._has('ternary');
  24497. var hasMapbox = fullLayout._has('mapbox');
  24498. var hasPolar = fullLayout._has('polar');
  24499. var allAxesFixed = areAllAxesFixed(fullLayout);
  24500. var groups = [];
  24501. function addGroup(newGroup) {
  24502. if(!newGroup.length) return;
  24503. var out = [];
  24504. for(var i = 0; i < newGroup.length; i++) {
  24505. var button = newGroup[i];
  24506. if(buttonsToRemove.indexOf(button) !== -1) continue;
  24507. out.push(modeBarButtons[button]);
  24508. }
  24509. groups.push(out);
  24510. }
  24511. // buttons common to all plot types
  24512. addGroup(['toImage', 'sendDataToCloud']);
  24513. var zoomGroup = [];
  24514. var hoverGroup = [];
  24515. var resetGroup = [];
  24516. var dragModeGroup = [];
  24517. if((hasCartesian || hasGL2D || hasPie || hasTernary) + hasGeo + hasGL3D + hasMapbox + hasPolar > 1) {
  24518. // graphs with more than one plot types get 'union buttons'
  24519. // which reset the view or toggle hover labels across all subplots.
  24520. hoverGroup = ['toggleHover'];
  24521. resetGroup = ['resetViews'];
  24522. }
  24523. else if(hasGeo) {
  24524. zoomGroup = ['zoomInGeo', 'zoomOutGeo'];
  24525. hoverGroup = ['hoverClosestGeo'];
  24526. resetGroup = ['resetGeo'];
  24527. }
  24528. else if(hasGL3D) {
  24529. hoverGroup = ['hoverClosest3d'];
  24530. resetGroup = ['resetCameraDefault3d', 'resetCameraLastSave3d'];
  24531. }
  24532. else if(hasMapbox) {
  24533. hoverGroup = ['toggleHover'];
  24534. resetGroup = ['resetViewMapbox'];
  24535. }
  24536. else if(hasGL2D) {
  24537. hoverGroup = ['hoverClosestGl2d'];
  24538. }
  24539. else if(hasPie) {
  24540. hoverGroup = ['hoverClosestPie'];
  24541. }
  24542. else { // hasPolar, hasTernary
  24543. // always show at least one hover icon.
  24544. hoverGroup = ['toggleHover'];
  24545. }
  24546. // if we have cartesian, allow switching between closest and compare
  24547. // regardless of what other types are on the plot, since they'll all
  24548. // just treat any truthy hovermode as 'closest'
  24549. if(hasCartesian) {
  24550. hoverGroup = ['toggleSpikelines', 'hoverClosestCartesian', 'hoverCompareCartesian'];
  24551. }
  24552. if((hasCartesian || hasGL2D) && !allAxesFixed) {
  24553. zoomGroup = ['zoomIn2d', 'zoomOut2d', 'autoScale2d'];
  24554. if(resetGroup[0] !== 'resetViews') resetGroup = ['resetScale2d'];
  24555. }
  24556. if(hasGL3D) {
  24557. dragModeGroup = ['zoom3d', 'pan3d', 'orbitRotation', 'tableRotation'];
  24558. }
  24559. else if(((hasCartesian || hasGL2D) && !allAxesFixed) || hasTernary) {
  24560. dragModeGroup = ['zoom2d', 'pan2d'];
  24561. }
  24562. else if(hasMapbox || hasGeo) {
  24563. dragModeGroup = ['pan2d'];
  24564. }
  24565. else if(hasPolar) {
  24566. dragModeGroup = ['zoom2d'];
  24567. }
  24568. if(isSelectable(fullData)) {
  24569. dragModeGroup.push('select2d', 'lasso2d');
  24570. }
  24571. addGroup(dragModeGroup);
  24572. addGroup(zoomGroup.concat(resetGroup));
  24573. addGroup(hoverGroup);
  24574. return appendButtonsToGroups(groups, buttonsToAdd);
  24575. }
  24576. function areAllAxesFixed(fullLayout) {
  24577. var axList = axisIds.list({_fullLayout: fullLayout}, null, true);
  24578. for(var i = 0; i < axList.length; i++) {
  24579. if(!axList[i].fixedrange) {
  24580. return false;
  24581. }
  24582. }
  24583. return true;
  24584. }
  24585. // look for traces that support selection
  24586. // to be updated as we add more selectPoints handlers
  24587. function isSelectable(fullData) {
  24588. var selectable = false;
  24589. for(var i = 0; i < fullData.length; i++) {
  24590. if(selectable) break;
  24591. var trace = fullData[i];
  24592. if(!trace._module || !trace._module.selectPoints) continue;
  24593. if(Registry.traceIs(trace, 'scatter-like')) {
  24594. if(scatterSubTypes.hasMarkers(trace) || scatterSubTypes.hasText(trace)) {
  24595. selectable = true;
  24596. }
  24597. } else if(Registry.traceIs(trace, 'box-violin')) {
  24598. if(trace.boxpoints === 'all' || trace.points === 'all') {
  24599. selectable = true;
  24600. }
  24601. }
  24602. // assume that in general if the trace module has selectPoints,
  24603. // then it's selectable. Scatter is an exception to this because it must
  24604. // have markers or text, not just be a scatter type.
  24605. else selectable = true;
  24606. }
  24607. return selectable;
  24608. }
  24609. function appendButtonsToGroups(groups, buttons) {
  24610. if(buttons.length) {
  24611. if(Array.isArray(buttons[0])) {
  24612. for(var i = 0; i < buttons.length; i++) {
  24613. groups.push(buttons[i]);
  24614. }
  24615. }
  24616. else groups.push(buttons);
  24617. }
  24618. return groups;
  24619. }
  24620. // fill in custom buttons referring to default mode bar buttons
  24621. function fillCustomButton(customButtons) {
  24622. for(var i = 0; i < customButtons.length; i++) {
  24623. var buttonGroup = customButtons[i];
  24624. for(var j = 0; j < buttonGroup.length; j++) {
  24625. var button = buttonGroup[j];
  24626. if(typeof button === 'string') {
  24627. if(modeBarButtons[button] !== undefined) {
  24628. customButtons[i][j] = modeBarButtons[button];
  24629. }
  24630. else {
  24631. throw new Error([
  24632. '*modeBarButtons* configuration options',
  24633. 'invalid button name'
  24634. ].join(' '));
  24635. }
  24636. }
  24637. }
  24638. }
  24639. return customButtons;
  24640. }
  24641. },{"../../plots/cartesian/axis_ids":217,"../../registry":259,"../../traces/scatter/subtypes":390,"./buttons":112,"./modebar":115}],115:[function(_dereq_,module,exports){
  24642. /**
  24643. * Copyright 2012-2018, Plotly, Inc.
  24644. * All rights reserved.
  24645. *
  24646. * This source code is licensed under the MIT license found in the
  24647. * LICENSE file in the root directory of this source tree.
  24648. */
  24649. 'use strict';
  24650. var d3 = _dereq_('d3');
  24651. var isNumeric = _dereq_('fast-isnumeric');
  24652. var Lib = _dereq_('../../lib');
  24653. var Icons = _dereq_('../../../build/ploticon');
  24654. /**
  24655. * UI controller for interactive plots
  24656. * @Class
  24657. * @Param {object} opts
  24658. * @Param {object} opts.buttons nested arrays of grouped buttons config objects
  24659. * @Param {object} opts.container container div to append modeBar
  24660. * @Param {object} opts.graphInfo primary plot object containing data and layout
  24661. */
  24662. function ModeBar(opts) {
  24663. this.container = opts.container;
  24664. this.element = document.createElement('div');
  24665. this.update(opts.graphInfo, opts.buttons);
  24666. this.container.appendChild(this.element);
  24667. }
  24668. var proto = ModeBar.prototype;
  24669. /**
  24670. * Update modeBar (buttons and logo)
  24671. *
  24672. * @param {object} graphInfo primary plot object containing data and layout
  24673. * @param {array of arrays} buttons nested arrays of grouped buttons to initialize
  24674. *
  24675. */
  24676. proto.update = function(graphInfo, buttons) {
  24677. this.graphInfo = graphInfo;
  24678. var context = this.graphInfo._context;
  24679. if(context.displayModeBar === 'hover') {
  24680. this.element.className = 'modebar modebar--hover';
  24681. }
  24682. else this.element.className = 'modebar';
  24683. // if buttons or logo have changed, redraw modebar interior
  24684. var needsNewButtons = !this.hasButtons(buttons);
  24685. var needsNewLogo = (this.hasLogo !== context.displaylogo);
  24686. var needsNewLocale = (this.locale !== context.locale);
  24687. this.locale = context.locale;
  24688. if(needsNewButtons || needsNewLogo || needsNewLocale) {
  24689. this.removeAllButtons();
  24690. this.updateButtons(buttons);
  24691. if(context.displaylogo) {
  24692. this.element.appendChild(this.getLogo());
  24693. this.hasLogo = true;
  24694. }
  24695. }
  24696. this.updateActiveButton();
  24697. };
  24698. proto.updateButtons = function(buttons) {
  24699. var _this = this;
  24700. this.buttons = buttons;
  24701. this.buttonElements = [];
  24702. this.buttonsNames = [];
  24703. this.buttons.forEach(function(buttonGroup) {
  24704. var group = _this.createGroup();
  24705. buttonGroup.forEach(function(buttonConfig) {
  24706. var buttonName = buttonConfig.name;
  24707. if(!buttonName) {
  24708. throw new Error('must provide button \'name\' in button config');
  24709. }
  24710. if(_this.buttonsNames.indexOf(buttonName) !== -1) {
  24711. throw new Error('button name \'' + buttonName + '\' is taken');
  24712. }
  24713. _this.buttonsNames.push(buttonName);
  24714. var button = _this.createButton(buttonConfig);
  24715. _this.buttonElements.push(button);
  24716. group.appendChild(button);
  24717. });
  24718. _this.element.appendChild(group);
  24719. });
  24720. };
  24721. /**
  24722. * Empty div for containing a group of buttons
  24723. * @Return {HTMLelement}
  24724. */
  24725. proto.createGroup = function() {
  24726. var group = document.createElement('div');
  24727. group.className = 'modebar-group';
  24728. return group;
  24729. };
  24730. /**
  24731. * Create a new button div and set constant and configurable attributes
  24732. * @Param {object} config (see ./buttons.js for more info)
  24733. * @Return {HTMLelement}
  24734. */
  24735. proto.createButton = function(config) {
  24736. var _this = this,
  24737. button = document.createElement('a');
  24738. button.setAttribute('rel', 'tooltip');
  24739. button.className = 'modebar-btn';
  24740. var title = config.title;
  24741. if(title === undefined) title = config.name;
  24742. // for localization: allow title to be a callable that takes gd as arg
  24743. else if(typeof title === 'function') title = title(this.graphInfo);
  24744. if(title || title === 0) button.setAttribute('data-title', title);
  24745. if(config.attr !== undefined) button.setAttribute('data-attr', config.attr);
  24746. var val = config.val;
  24747. if(val !== undefined) {
  24748. if(typeof val === 'function') val = val(this.graphInfo);
  24749. button.setAttribute('data-val', val);
  24750. }
  24751. var click = config.click;
  24752. if(typeof click !== 'function') {
  24753. throw new Error('must provide button \'click\' function in button config');
  24754. }
  24755. else {
  24756. button.addEventListener('click', function(ev) {
  24757. config.click(_this.graphInfo, ev);
  24758. // only needed for 'hoverClosestGeo' which does not call relayout
  24759. _this.updateActiveButton(ev.currentTarget);
  24760. });
  24761. }
  24762. button.setAttribute('data-toggle', config.toggle || false);
  24763. if(config.toggle) d3.select(button).classed('active', true);
  24764. var icon = config.icon;
  24765. if(typeof icon === 'function') {
  24766. button.appendChild(icon());
  24767. }
  24768. else {
  24769. button.appendChild(this.createIcon(icon || Icons.question));
  24770. }
  24771. button.setAttribute('data-gravity', config.gravity || 'n');
  24772. return button;
  24773. };
  24774. /**
  24775. * Add an icon to a button
  24776. * @Param {object} thisIcon
  24777. * @Param {number} thisIcon.width
  24778. * @Param {string} thisIcon.path
  24779. * @Return {HTMLelement}
  24780. */
  24781. proto.createIcon = function(thisIcon) {
  24782. var iconHeight = isNumeric(thisIcon.height) ?
  24783. Number(thisIcon.height) :
  24784. thisIcon.ascent - thisIcon.descent,
  24785. svgNS = 'http://www.w3.org/2000/svg',
  24786. icon = document.createElementNS(svgNS, 'svg'),
  24787. path = document.createElementNS(svgNS, 'path');
  24788. icon.setAttribute('height', '1em');
  24789. icon.setAttribute('width', (thisIcon.width / iconHeight) + 'em');
  24790. icon.setAttribute('viewBox', [0, 0, thisIcon.width, iconHeight].join(' '));
  24791. path.setAttribute('d', thisIcon.path);
  24792. if(thisIcon.transform) {
  24793. path.setAttribute('transform', thisIcon.transform);
  24794. }
  24795. else if(thisIcon.ascent !== undefined) {
  24796. // Legacy icon transform calculation
  24797. path.setAttribute('transform', 'matrix(1 0 0 -1 0 ' + thisIcon.ascent + ')');
  24798. }
  24799. icon.appendChild(path);
  24800. return icon;
  24801. };
  24802. /**
  24803. * Updates active button with attribute specified in layout
  24804. * @Param {object} graphInfo plot object containing data and layout
  24805. * @Return {HTMLelement}
  24806. */
  24807. proto.updateActiveButton = function(buttonClicked) {
  24808. var fullLayout = this.graphInfo._fullLayout,
  24809. dataAttrClicked = (buttonClicked !== undefined) ?
  24810. buttonClicked.getAttribute('data-attr') :
  24811. null;
  24812. this.buttonElements.forEach(function(button) {
  24813. var thisval = button.getAttribute('data-val') || true,
  24814. dataAttr = button.getAttribute('data-attr'),
  24815. isToggleButton = (button.getAttribute('data-toggle') === 'true'),
  24816. button3 = d3.select(button);
  24817. // Use 'data-toggle' and 'buttonClicked' to toggle buttons
  24818. // that have no one-to-one equivalent in fullLayout
  24819. if(isToggleButton) {
  24820. if(dataAttr === dataAttrClicked) {
  24821. button3.classed('active', !button3.classed('active'));
  24822. }
  24823. }
  24824. else {
  24825. var val = (dataAttr === null) ?
  24826. dataAttr :
  24827. Lib.nestedProperty(fullLayout, dataAttr).get();
  24828. button3.classed('active', val === thisval);
  24829. }
  24830. });
  24831. };
  24832. /**
  24833. * Check if modeBar is configured as button configuration argument
  24834. *
  24835. * @Param {object} buttons 2d array of grouped button config objects
  24836. * @Return {boolean}
  24837. */
  24838. proto.hasButtons = function(buttons) {
  24839. var currentButtons = this.buttons;
  24840. if(!currentButtons) return false;
  24841. if(buttons.length !== currentButtons.length) return false;
  24842. for(var i = 0; i < buttons.length; ++i) {
  24843. if(buttons[i].length !== currentButtons[i].length) return false;
  24844. for(var j = 0; j < buttons[i].length; j++) {
  24845. if(buttons[i][j].name !== currentButtons[i][j].name) return false;
  24846. }
  24847. }
  24848. return true;
  24849. };
  24850. /**
  24851. * @return {HTMLDivElement} The logo image wrapped in a group
  24852. */
  24853. proto.getLogo = function() {
  24854. var group = this.createGroup(),
  24855. a = document.createElement('a');
  24856. a.href = 'https://plot.ly/';
  24857. a.target = '_blank';
  24858. a.setAttribute('data-title', Lib._(this.graphInfo, 'Produced with Plotly'));
  24859. a.className = 'modebar-btn plotlyjsicon modebar-btn--logo';
  24860. a.appendChild(this.createIcon(Icons.plotlylogo));
  24861. group.appendChild(a);
  24862. return group;
  24863. };
  24864. proto.removeAllButtons = function() {
  24865. while(this.element.firstChild) {
  24866. this.element.removeChild(this.element.firstChild);
  24867. }
  24868. this.hasLogo = false;
  24869. };
  24870. proto.destroy = function() {
  24871. Lib.removeElement(this.container.querySelector('.modebar'));
  24872. };
  24873. function createModeBar(gd, buttons) {
  24874. var fullLayout = gd._fullLayout;
  24875. var modeBar = new ModeBar({
  24876. graphInfo: gd,
  24877. container: fullLayout._paperdiv.node(),
  24878. buttons: buttons
  24879. });
  24880. if(fullLayout._privateplot) {
  24881. d3.select(modeBar.element).append('span')
  24882. .classed('badge-private float--left', true)
  24883. .text('PRIVATE');
  24884. }
  24885. return modeBar;
  24886. }
  24887. module.exports = createModeBar;
  24888. },{"../../../build/ploticon":2,"../../lib":169,"d3":16,"fast-isnumeric":18}],116:[function(_dereq_,module,exports){
  24889. /**
  24890. * Copyright 2012-2018, Plotly, Inc.
  24891. * All rights reserved.
  24892. *
  24893. * This source code is licensed under the MIT license found in the
  24894. * LICENSE file in the root directory of this source tree.
  24895. */
  24896. 'use strict';
  24897. var fontAttrs = _dereq_('../../plots/font_attributes');
  24898. var colorAttrs = _dereq_('../color/attributes');
  24899. var templatedArray = _dereq_('../../plot_api/plot_template').templatedArray;
  24900. var buttonAttrs = templatedArray('button', {
  24901. visible: {
  24902. valType: 'boolean',
  24903. dflt: true,
  24904. editType: 'plot',
  24905. },
  24906. step: {
  24907. valType: 'enumerated',
  24908. values: ['month', 'year', 'day', 'hour', 'minute', 'second', 'all'],
  24909. dflt: 'month',
  24910. editType: 'plot',
  24911. },
  24912. stepmode: {
  24913. valType: 'enumerated',
  24914. values: ['backward', 'todate'],
  24915. dflt: 'backward',
  24916. editType: 'plot',
  24917. },
  24918. count: {
  24919. valType: 'number',
  24920. min: 0,
  24921. dflt: 1,
  24922. editType: 'plot',
  24923. },
  24924. label: {
  24925. valType: 'string',
  24926. editType: 'plot',
  24927. },
  24928. editType: 'plot',
  24929. });
  24930. module.exports = {
  24931. visible: {
  24932. valType: 'boolean',
  24933. editType: 'plot',
  24934. },
  24935. buttons: buttonAttrs,
  24936. x: {
  24937. valType: 'number',
  24938. min: -2,
  24939. max: 3,
  24940. editType: 'plot',
  24941. },
  24942. xanchor: {
  24943. valType: 'enumerated',
  24944. values: ['auto', 'left', 'center', 'right'],
  24945. dflt: 'left',
  24946. editType: 'plot',
  24947. },
  24948. y: {
  24949. valType: 'number',
  24950. min: -2,
  24951. max: 3,
  24952. editType: 'plot',
  24953. },
  24954. yanchor: {
  24955. valType: 'enumerated',
  24956. values: ['auto', 'top', 'middle', 'bottom'],
  24957. dflt: 'bottom',
  24958. editType: 'plot',
  24959. },
  24960. font: fontAttrs({
  24961. editType: 'plot',
  24962. }),
  24963. bgcolor: {
  24964. valType: 'color',
  24965. dflt: colorAttrs.lightLine,
  24966. editType: 'plot',
  24967. },
  24968. activecolor: {
  24969. valType: 'color',
  24970. editType: 'plot',
  24971. },
  24972. bordercolor: {
  24973. valType: 'color',
  24974. dflt: colorAttrs.defaultLine,
  24975. editType: 'plot',
  24976. },
  24977. borderwidth: {
  24978. valType: 'number',
  24979. min: 0,
  24980. dflt: 0,
  24981. editType: 'plot',
  24982. },
  24983. editType: 'plot'
  24984. };
  24985. },{"../../plot_api/plot_template":204,"../../plots/font_attributes":240,"../color/attributes":49}],117:[function(_dereq_,module,exports){
  24986. /**
  24987. * Copyright 2012-2018, Plotly, Inc.
  24988. * All rights reserved.
  24989. *
  24990. * This source code is licensed under the MIT license found in the
  24991. * LICENSE file in the root directory of this source tree.
  24992. */
  24993. 'use strict';
  24994. module.exports = {
  24995. // 'y' position pad above counter axis domain
  24996. yPad: 0.02,
  24997. // minimum button width (regardless of text size)
  24998. minButtonWidth: 30,
  24999. // buttons rect radii
  25000. rx: 3,
  25001. ry: 3,
  25002. // light fraction used to compute the 'activecolor' default
  25003. lightAmount: 25,
  25004. darkAmount: 10
  25005. };
  25006. },{}],118:[function(_dereq_,module,exports){
  25007. /**
  25008. * Copyright 2012-2018, Plotly, Inc.
  25009. * All rights reserved.
  25010. *
  25011. * This source code is licensed under the MIT license found in the
  25012. * LICENSE file in the root directory of this source tree.
  25013. */
  25014. 'use strict';
  25015. var Lib = _dereq_('../../lib');
  25016. var Color = _dereq_('../color');
  25017. var Template = _dereq_('../../plot_api/plot_template');
  25018. var handleArrayContainerDefaults = _dereq_('../../plots/array_container_defaults');
  25019. var attributes = _dereq_('./attributes');
  25020. var constants = _dereq_('./constants');
  25021. module.exports = function handleDefaults(containerIn, containerOut, layout, counterAxes, calendar) {
  25022. var selectorIn = containerIn.rangeselector || {};
  25023. var selectorOut = Template.newContainer(containerOut, 'rangeselector');
  25024. function coerce(attr, dflt) {
  25025. return Lib.coerce(selectorIn, selectorOut, attributes, attr, dflt);
  25026. }
  25027. var buttons = handleArrayContainerDefaults(selectorIn, selectorOut, {
  25028. name: 'buttons',
  25029. handleItemDefaults: buttonDefaults,
  25030. calendar: calendar
  25031. });
  25032. var visible = coerce('visible', buttons.length > 0);
  25033. if(visible) {
  25034. var posDflt = getPosDflt(containerOut, layout, counterAxes);
  25035. coerce('x', posDflt[0]);
  25036. coerce('y', posDflt[1]);
  25037. Lib.noneOrAll(containerIn, containerOut, ['x', 'y']);
  25038. coerce('xanchor');
  25039. coerce('yanchor');
  25040. Lib.coerceFont(coerce, 'font', layout.font);
  25041. var bgColor = coerce('bgcolor');
  25042. coerce('activecolor', Color.contrast(bgColor, constants.lightAmount, constants.darkAmount));
  25043. coerce('bordercolor');
  25044. coerce('borderwidth');
  25045. }
  25046. };
  25047. function buttonDefaults(buttonIn, buttonOut, selectorOut, opts) {
  25048. var calendar = opts.calendar;
  25049. function coerce(attr, dflt) {
  25050. return Lib.coerce(buttonIn, buttonOut, attributes.buttons, attr, dflt);
  25051. }
  25052. var visible = coerce('visible');
  25053. if(visible) {
  25054. var step = coerce('step');
  25055. if(step !== 'all') {
  25056. if(calendar && calendar !== 'gregorian' && (step === 'month' || step === 'year')) {
  25057. buttonOut.stepmode = 'backward';
  25058. }
  25059. else {
  25060. coerce('stepmode');
  25061. }
  25062. coerce('count');
  25063. }
  25064. coerce('label');
  25065. }
  25066. }
  25067. function getPosDflt(containerOut, layout, counterAxes) {
  25068. var anchoredList = counterAxes.filter(function(ax) {
  25069. return layout[ax].anchor === containerOut._id;
  25070. });
  25071. var posY = 0;
  25072. for(var i = 0; i < anchoredList.length; i++) {
  25073. var domain = layout[anchoredList[i]].domain;
  25074. if(domain) posY = Math.max(domain[1], posY);
  25075. }
  25076. return [containerOut.domain[0], posY + constants.yPad];
  25077. }
  25078. },{"../../lib":169,"../../plot_api/plot_template":204,"../../plots/array_container_defaults":210,"../color":50,"./attributes":116,"./constants":117}],119:[function(_dereq_,module,exports){
  25079. /**
  25080. * Copyright 2012-2018, Plotly, Inc.
  25081. * All rights reserved.
  25082. *
  25083. * This source code is licensed under the MIT license found in the
  25084. * LICENSE file in the root directory of this source tree.
  25085. */
  25086. 'use strict';
  25087. var d3 = _dereq_('d3');
  25088. var Registry = _dereq_('../../registry');
  25089. var Plots = _dereq_('../../plots/plots');
  25090. var Color = _dereq_('../color');
  25091. var Drawing = _dereq_('../drawing');
  25092. var Lib = _dereq_('../../lib');
  25093. var svgTextUtils = _dereq_('../../lib/svg_text_utils');
  25094. var axisIds = _dereq_('../../plots/cartesian/axis_ids');
  25095. var anchorUtils = _dereq_('../legend/anchor_utils');
  25096. var alignmentConstants = _dereq_('../../constants/alignment');
  25097. var LINE_SPACING = alignmentConstants.LINE_SPACING;
  25098. var FROM_TL = alignmentConstants.FROM_TL;
  25099. var FROM_BR = alignmentConstants.FROM_BR;
  25100. var constants = _dereq_('./constants');
  25101. var getUpdateObject = _dereq_('./get_update_object');
  25102. module.exports = function draw(gd) {
  25103. var fullLayout = gd._fullLayout;
  25104. var selectors = fullLayout._infolayer.selectAll('.rangeselector')
  25105. .data(makeSelectorData(gd), selectorKeyFunc);
  25106. selectors.enter().append('g')
  25107. .classed('rangeselector', true);
  25108. selectors.exit().remove();
  25109. selectors.style({
  25110. cursor: 'pointer',
  25111. 'pointer-events': 'all'
  25112. });
  25113. selectors.each(function(d) {
  25114. var selector = d3.select(this),
  25115. axisLayout = d,
  25116. selectorLayout = axisLayout.rangeselector;
  25117. var buttons = selector.selectAll('g.button')
  25118. .data(Lib.filterVisible(selectorLayout.buttons));
  25119. buttons.enter().append('g')
  25120. .classed('button', true);
  25121. buttons.exit().remove();
  25122. buttons.each(function(d) {
  25123. var button = d3.select(this);
  25124. var update = getUpdateObject(axisLayout, d);
  25125. d._isActive = isActive(axisLayout, d, update);
  25126. button.call(drawButtonRect, selectorLayout, d);
  25127. button.call(drawButtonText, selectorLayout, d, gd);
  25128. button.on('click', function() {
  25129. if(gd._dragged) return;
  25130. Registry.call('relayout', gd, update);
  25131. });
  25132. button.on('mouseover', function() {
  25133. d._isHovered = true;
  25134. button.call(drawButtonRect, selectorLayout, d);
  25135. });
  25136. button.on('mouseout', function() {
  25137. d._isHovered = false;
  25138. button.call(drawButtonRect, selectorLayout, d);
  25139. });
  25140. });
  25141. reposition(gd, buttons, selectorLayout, axisLayout._name, selector);
  25142. });
  25143. };
  25144. function makeSelectorData(gd) {
  25145. var axes = axisIds.list(gd, 'x', true);
  25146. var data = [];
  25147. for(var i = 0; i < axes.length; i++) {
  25148. var axis = axes[i];
  25149. if(axis.rangeselector && axis.rangeselector.visible) {
  25150. data.push(axis);
  25151. }
  25152. }
  25153. return data;
  25154. }
  25155. function selectorKeyFunc(d) {
  25156. return d._id;
  25157. }
  25158. function isActive(axisLayout, opts, update) {
  25159. if(opts.step === 'all') {
  25160. return axisLayout.autorange === true;
  25161. }
  25162. else {
  25163. var keys = Object.keys(update);
  25164. return (
  25165. axisLayout.range[0] === update[keys[0]] &&
  25166. axisLayout.range[1] === update[keys[1]]
  25167. );
  25168. }
  25169. }
  25170. function drawButtonRect(button, selectorLayout, d) {
  25171. var rect = Lib.ensureSingle(button, 'rect', 'selector-rect', function(s) {
  25172. s.attr('shape-rendering', 'crispEdges');
  25173. });
  25174. rect.attr({
  25175. 'rx': constants.rx,
  25176. 'ry': constants.ry
  25177. });
  25178. rect.call(Color.stroke, selectorLayout.bordercolor)
  25179. .call(Color.fill, getFillColor(selectorLayout, d))
  25180. .style('stroke-width', selectorLayout.borderwidth + 'px');
  25181. }
  25182. function getFillColor(selectorLayout, d) {
  25183. return (d._isActive || d._isHovered) ?
  25184. selectorLayout.activecolor :
  25185. selectorLayout.bgcolor;
  25186. }
  25187. function drawButtonText(button, selectorLayout, d, gd) {
  25188. function textLayout(s) {
  25189. svgTextUtils.convertToTspans(s, gd);
  25190. }
  25191. var text = Lib.ensureSingle(button, 'text', 'selector-text', function(s) {
  25192. s.classed('user-select-none', true)
  25193. .attr('text-anchor', 'middle');
  25194. });
  25195. text.call(Drawing.font, selectorLayout.font)
  25196. .text(getLabel(d))
  25197. .call(textLayout);
  25198. }
  25199. function getLabel(opts) {
  25200. if(opts.label) return opts.label;
  25201. if(opts.step === 'all') return 'all';
  25202. return opts.count + opts.step.charAt(0);
  25203. }
  25204. function reposition(gd, buttons, opts, axName, selector) {
  25205. var width = 0;
  25206. var height = 0;
  25207. var borderWidth = opts.borderwidth;
  25208. buttons.each(function() {
  25209. var button = d3.select(this);
  25210. var text = button.select('.selector-text');
  25211. var tHeight = opts.font.size * LINE_SPACING;
  25212. var hEff = Math.max(tHeight * svgTextUtils.lineCount(text), 16) + 3;
  25213. height = Math.max(height, hEff);
  25214. });
  25215. buttons.each(function() {
  25216. var button = d3.select(this);
  25217. var rect = button.select('.selector-rect');
  25218. var text = button.select('.selector-text');
  25219. var tWidth = text.node() && Drawing.bBox(text.node()).width;
  25220. var tHeight = opts.font.size * LINE_SPACING;
  25221. var tLines = svgTextUtils.lineCount(text);
  25222. var wEff = Math.max(tWidth + 10, constants.minButtonWidth);
  25223. // TODO add MathJax support
  25224. // TODO add buttongap attribute
  25225. button.attr('transform', 'translate(' +
  25226. (borderWidth + width) + ',' + borderWidth +
  25227. ')');
  25228. rect.attr({
  25229. x: 0,
  25230. y: 0,
  25231. width: wEff,
  25232. height: height
  25233. });
  25234. svgTextUtils.positionText(text, wEff / 2,
  25235. height / 2 - ((tLines - 1) * tHeight / 2) + 3);
  25236. width += wEff + 5;
  25237. });
  25238. var graphSize = gd._fullLayout._size;
  25239. var lx = graphSize.l + graphSize.w * opts.x;
  25240. var ly = graphSize.t + graphSize.h * (1 - opts.y);
  25241. var xanchor = 'left';
  25242. if(anchorUtils.isRightAnchor(opts)) {
  25243. lx -= width;
  25244. xanchor = 'right';
  25245. }
  25246. if(anchorUtils.isCenterAnchor(opts)) {
  25247. lx -= width / 2;
  25248. xanchor = 'center';
  25249. }
  25250. var yanchor = 'top';
  25251. if(anchorUtils.isBottomAnchor(opts)) {
  25252. ly -= height;
  25253. yanchor = 'bottom';
  25254. }
  25255. if(anchorUtils.isMiddleAnchor(opts)) {
  25256. ly -= height / 2;
  25257. yanchor = 'middle';
  25258. }
  25259. width = Math.ceil(width);
  25260. height = Math.ceil(height);
  25261. lx = Math.round(lx);
  25262. ly = Math.round(ly);
  25263. Plots.autoMargin(gd, axName + '-range-selector', {
  25264. x: opts.x,
  25265. y: opts.y,
  25266. l: width * FROM_TL[xanchor],
  25267. r: width * FROM_BR[xanchor],
  25268. b: height * FROM_BR[yanchor],
  25269. t: height * FROM_TL[yanchor]
  25270. });
  25271. selector.attr('transform', 'translate(' + lx + ',' + ly + ')');
  25272. }
  25273. },{"../../constants/alignment":148,"../../lib":169,"../../lib/svg_text_utils":191,"../../plots/cartesian/axis_ids":217,"../../plots/plots":246,"../../registry":259,"../color":50,"../drawing":75,"../legend/anchor_utils":102,"./constants":117,"./get_update_object":120,"d3":16}],120:[function(_dereq_,module,exports){
  25274. /**
  25275. * Copyright 2012-2018, Plotly, Inc.
  25276. * All rights reserved.
  25277. *
  25278. * This source code is licensed under the MIT license found in the
  25279. * LICENSE file in the root directory of this source tree.
  25280. */
  25281. 'use strict';
  25282. var d3 = _dereq_('d3');
  25283. module.exports = function getUpdateObject(axisLayout, buttonLayout) {
  25284. var axName = axisLayout._name;
  25285. var update = {};
  25286. if(buttonLayout.step === 'all') {
  25287. update[axName + '.autorange'] = true;
  25288. }
  25289. else {
  25290. var xrange = getXRange(axisLayout, buttonLayout);
  25291. update[axName + '.range[0]'] = xrange[0];
  25292. update[axName + '.range[1]'] = xrange[1];
  25293. }
  25294. return update;
  25295. };
  25296. function getXRange(axisLayout, buttonLayout) {
  25297. var currentRange = axisLayout.range;
  25298. var base = new Date(axisLayout.r2l(currentRange[1]));
  25299. var step = buttonLayout.step,
  25300. count = buttonLayout.count;
  25301. var range0;
  25302. switch(buttonLayout.stepmode) {
  25303. case 'backward':
  25304. range0 = axisLayout.l2r(+d3.time[step].utc.offset(base, -count));
  25305. break;
  25306. case 'todate':
  25307. var base2 = d3.time[step].utc.offset(base, -count);
  25308. range0 = axisLayout.l2r(+d3.time[step].utc.ceil(base2));
  25309. break;
  25310. }
  25311. var range1 = currentRange[1];
  25312. return [range0, range1];
  25313. }
  25314. },{"d3":16}],121:[function(_dereq_,module,exports){
  25315. /**
  25316. * Copyright 2012-2018, Plotly, Inc.
  25317. * All rights reserved.
  25318. *
  25319. * This source code is licensed under the MIT license found in the
  25320. * LICENSE file in the root directory of this source tree.
  25321. */
  25322. 'use strict';
  25323. module.exports = {
  25324. moduleType: 'component',
  25325. name: 'rangeselector',
  25326. schema: {
  25327. subplots: {
  25328. xaxis: {rangeselector: _dereq_('./attributes')}
  25329. }
  25330. },
  25331. layoutAttributes: _dereq_('./attributes'),
  25332. handleDefaults: _dereq_('./defaults'),
  25333. draw: _dereq_('./draw')
  25334. };
  25335. },{"./attributes":116,"./defaults":118,"./draw":119}],122:[function(_dereq_,module,exports){
  25336. /**
  25337. * Copyright 2012-2018, Plotly, Inc.
  25338. * All rights reserved.
  25339. *
  25340. * This source code is licensed under the MIT license found in the
  25341. * LICENSE file in the root directory of this source tree.
  25342. */
  25343. 'use strict';
  25344. var colorAttributes = _dereq_('../color/attributes');
  25345. module.exports = {
  25346. bgcolor: {
  25347. valType: 'color',
  25348. dflt: colorAttributes.background,
  25349. editType: 'plot',
  25350. },
  25351. bordercolor: {
  25352. valType: 'color',
  25353. dflt: colorAttributes.defaultLine,
  25354. editType: 'plot',
  25355. },
  25356. borderwidth: {
  25357. valType: 'integer',
  25358. dflt: 0,
  25359. min: 0,
  25360. editType: 'plot',
  25361. },
  25362. autorange: {
  25363. valType: 'boolean',
  25364. dflt: true,
  25365. editType: 'calc',
  25366. impliedEdits: {'range[0]': undefined, 'range[1]': undefined},
  25367. },
  25368. range: {
  25369. valType: 'info_array',
  25370. items: [
  25371. {valType: 'any', editType: 'calc', impliedEdits: {'^autorange': false}},
  25372. {valType: 'any', editType: 'calc', impliedEdits: {'^autorange': false}}
  25373. ],
  25374. editType: 'calc',
  25375. impliedEdits: {'autorange': false},
  25376. },
  25377. thickness: {
  25378. valType: 'number',
  25379. dflt: 0.15,
  25380. min: 0,
  25381. max: 1,
  25382. editType: 'plot',
  25383. },
  25384. visible: {
  25385. valType: 'boolean',
  25386. dflt: true,
  25387. editType: 'calc',
  25388. },
  25389. editType: 'calc'
  25390. };
  25391. },{"../color/attributes":49}],123:[function(_dereq_,module,exports){
  25392. /**
  25393. * Copyright 2012-2018, Plotly, Inc.
  25394. * All rights reserved.
  25395. *
  25396. * This source code is licensed under the MIT license found in the
  25397. * LICENSE file in the root directory of this source tree.
  25398. */
  25399. 'use strict';
  25400. var listAxes = _dereq_('../../plots/cartesian/axis_ids').list;
  25401. var getAutoRange = _dereq_('../../plots/cartesian/autorange').getAutoRange;
  25402. var constants = _dereq_('./constants');
  25403. module.exports = function calcAutorange(gd) {
  25404. var axes = listAxes(gd, 'x', true);
  25405. // Compute new slider range using axis autorange if necessary.
  25406. //
  25407. // Copy back range to input range slider container to skip
  25408. // this step in subsequent draw calls.
  25409. for(var i = 0; i < axes.length; i++) {
  25410. var ax = axes[i];
  25411. var opts = ax[constants.name];
  25412. if(opts && opts.visible && opts.autorange) {
  25413. opts._input.autorange = true;
  25414. opts._input.range = opts.range = getAutoRange(gd, ax);
  25415. }
  25416. }
  25417. };
  25418. },{"../../plots/cartesian/autorange":213,"../../plots/cartesian/axis_ids":217,"./constants":124}],124:[function(_dereq_,module,exports){
  25419. /**
  25420. * Copyright 2012-2018, Plotly, Inc.
  25421. * All rights reserved.
  25422. *
  25423. * This source code is licensed under the MIT license found in the
  25424. * LICENSE file in the root directory of this source tree.
  25425. */
  25426. 'use strict';
  25427. module.exports = {
  25428. // attribute container name
  25429. name: 'rangeslider',
  25430. // class names
  25431. containerClassName: 'rangeslider-container',
  25432. bgClassName: 'rangeslider-bg',
  25433. rangePlotClassName: 'rangeslider-rangeplot',
  25434. maskMinClassName: 'rangeslider-mask-min',
  25435. maskMaxClassName: 'rangeslider-mask-max',
  25436. slideBoxClassName: 'rangeslider-slidebox',
  25437. grabberMinClassName: 'rangeslider-grabber-min',
  25438. grabAreaMinClassName: 'rangeslider-grabarea-min',
  25439. handleMinClassName: 'rangeslider-handle-min',
  25440. grabberMaxClassName: 'rangeslider-grabber-max',
  25441. grabAreaMaxClassName: 'rangeslider-grabarea-max',
  25442. handleMaxClassName: 'rangeslider-handle-max',
  25443. maskMinOppAxisClassName: 'rangeslider-mask-min-opp-axis',
  25444. maskMaxOppAxisClassName: 'rangeslider-mask-max-opp-axis',
  25445. // style constants
  25446. maskColor: 'rgba(0,0,0,0.4)',
  25447. maskOppAxisColor: 'rgba(0,0,0,0.2)',
  25448. slideBoxFill: 'transparent',
  25449. slideBoxCursor: 'ew-resize',
  25450. grabAreaFill: 'transparent',
  25451. grabAreaCursor: 'col-resize',
  25452. grabAreaWidth: 10,
  25453. handleWidth: 4,
  25454. handleRadius: 1,
  25455. handleStrokeWidth: 1,
  25456. extraPad: 15
  25457. };
  25458. },{}],125:[function(_dereq_,module,exports){
  25459. /**
  25460. * Copyright 2012-2018, Plotly, Inc.
  25461. * All rights reserved.
  25462. *
  25463. * This source code is licensed under the MIT license found in the
  25464. * LICENSE file in the root directory of this source tree.
  25465. */
  25466. 'use strict';
  25467. var Lib = _dereq_('../../lib');
  25468. var Template = _dereq_('../../plot_api/plot_template');
  25469. var axisIds = _dereq_('../../plots/cartesian/axis_ids');
  25470. var attributes = _dereq_('./attributes');
  25471. var oppAxisAttrs = _dereq_('./oppaxis_attributes');
  25472. module.exports = function handleDefaults(layoutIn, layoutOut, axName) {
  25473. var axIn = layoutIn[axName];
  25474. var axOut = layoutOut[axName];
  25475. if(!(axIn.rangeslider || layoutOut._requestRangeslider[axOut._id])) return;
  25476. // not super proud of this (maybe store _ in axis object instead
  25477. if(!Lib.isPlainObject(axIn.rangeslider)) {
  25478. axIn.rangeslider = {};
  25479. }
  25480. var containerIn = axIn.rangeslider;
  25481. var containerOut = Template.newContainer(axOut, 'rangeslider');
  25482. function coerce(attr, dflt) {
  25483. return Lib.coerce(containerIn, containerOut, attributes, attr, dflt);
  25484. }
  25485. var rangeContainerIn, rangeContainerOut;
  25486. function coerceRange(attr, dflt) {
  25487. return Lib.coerce(rangeContainerIn, rangeContainerOut, oppAxisAttrs, attr, dflt);
  25488. }
  25489. var visible = coerce('visible');
  25490. if(!visible) return;
  25491. coerce('bgcolor', layoutOut.plot_bgcolor);
  25492. coerce('bordercolor');
  25493. coerce('borderwidth');
  25494. coerce('thickness');
  25495. coerce('autorange', !axOut.isValidRange(containerIn.range));
  25496. coerce('range');
  25497. var subplots = layoutOut._subplots;
  25498. if(subplots) {
  25499. var yIds = subplots.cartesian
  25500. .filter(function(subplotId) {
  25501. return subplotId.substr(0, subplotId.indexOf('y')) === axisIds.name2id(axName);
  25502. })
  25503. .map(function(subplotId) {
  25504. return subplotId.substr(subplotId.indexOf('y'), subplotId.length);
  25505. });
  25506. var yNames = Lib.simpleMap(yIds, axisIds.id2name);
  25507. for(var i = 0; i < yNames.length; i++) {
  25508. var yName = yNames[i];
  25509. rangeContainerIn = containerIn[yName] || {};
  25510. rangeContainerOut = Template.newContainer(containerOut, yName, 'yaxis');
  25511. var yAxOut = layoutOut[yName];
  25512. var rangemodeDflt;
  25513. if(rangeContainerIn.range && yAxOut.isValidRange(rangeContainerIn.range)) {
  25514. rangemodeDflt = 'fixed';
  25515. }
  25516. var rangeMode = coerceRange('rangemode', rangemodeDflt);
  25517. if(rangeMode !== 'match') {
  25518. coerceRange('range', yAxOut.range.slice());
  25519. }
  25520. }
  25521. }
  25522. // to map back range slider (auto) range
  25523. containerOut._input = containerIn;
  25524. };
  25525. },{"../../lib":169,"../../plot_api/plot_template":204,"../../plots/cartesian/axis_ids":217,"./attributes":122,"./oppaxis_attributes":128}],126:[function(_dereq_,module,exports){
  25526. /**
  25527. * Copyright 2012-2018, Plotly, Inc.
  25528. * All rights reserved.
  25529. *
  25530. * This source code is licensed under the MIT license found in the
  25531. * LICENSE file in the root directory of this source tree.
  25532. */
  25533. 'use strict';
  25534. var d3 = _dereq_('d3');
  25535. var Registry = _dereq_('../../registry');
  25536. var Plots = _dereq_('../../plots/plots');
  25537. var Lib = _dereq_('../../lib');
  25538. var Drawing = _dereq_('../drawing');
  25539. var Color = _dereq_('../color');
  25540. var Titles = _dereq_('../titles');
  25541. var Cartesian = _dereq_('../../plots/cartesian');
  25542. var Axes = _dereq_('../../plots/cartesian/axes');
  25543. var dragElement = _dereq_('../dragelement');
  25544. var setCursor = _dereq_('../../lib/setcursor');
  25545. var constants = _dereq_('./constants');
  25546. module.exports = function(gd) {
  25547. var fullLayout = gd._fullLayout,
  25548. rangeSliderData = makeRangeSliderData(fullLayout);
  25549. /*
  25550. * <g container />
  25551. * <rect bg />
  25552. * < .... range plot />
  25553. * <rect mask-min />
  25554. * <rect mask-max />
  25555. * <rect slidebox />
  25556. * <g grabber-min />
  25557. * <rect handle-min />
  25558. * <rect grabare-min />
  25559. * <g grabber-max />
  25560. * <rect handle-max />
  25561. * <rect grabare-max />
  25562. *
  25563. * ...
  25564. */
  25565. function keyFunction(axisOpts) {
  25566. return axisOpts._name;
  25567. }
  25568. var rangeSliders = fullLayout._infolayer
  25569. .selectAll('g.' + constants.containerClassName)
  25570. .data(rangeSliderData, keyFunction);
  25571. rangeSliders.enter().append('g')
  25572. .classed(constants.containerClassName, true)
  25573. .attr('pointer-events', 'all');
  25574. // remove exiting sliders and their corresponding clip paths
  25575. rangeSliders.exit().each(function(axisOpts) {
  25576. var opts = axisOpts[constants.name];
  25577. fullLayout._topdefs.select('#' + opts._clipId).remove();
  25578. }).remove();
  25579. // return early if no range slider is visible
  25580. if(rangeSliderData.length === 0) return;
  25581. // for all present range sliders
  25582. rangeSliders.each(function(axisOpts) {
  25583. var rangeSlider = d3.select(this),
  25584. opts = axisOpts[constants.name],
  25585. oppAxisOpts = fullLayout[Axes.id2name(axisOpts.anchor)],
  25586. oppAxisRangeOpts = opts[Axes.id2name(axisOpts.anchor)];
  25587. // update range
  25588. // Expand slider range to the axis range
  25589. // TODO: what if the ranges are reversed?
  25590. if(opts.range) {
  25591. var outRange = opts.range;
  25592. var axRange = axisOpts.range;
  25593. outRange[0] = axisOpts.l2r(Math.min(axisOpts.r2l(outRange[0]), axisOpts.r2l(axRange[0])));
  25594. outRange[1] = axisOpts.l2r(Math.max(axisOpts.r2l(outRange[1]), axisOpts.r2l(axRange[1])));
  25595. opts._input.range = outRange.slice();
  25596. }
  25597. axisOpts.cleanRange('rangeslider.range');
  25598. // update range slider dimensions
  25599. var margin = fullLayout.margin;
  25600. var graphSize = fullLayout._size;
  25601. var domain = axisOpts.domain;
  25602. var tickHeight = (axisOpts._boundingBox || {}).height || 0;
  25603. var oppBottom = Infinity;
  25604. var subplotData = Axes.getSubplots(gd, axisOpts);
  25605. for(var i = 0; i < subplotData.length; i++) {
  25606. var oppAxis = Axes.getFromId(gd, subplotData[i].substr(subplotData[i].indexOf('y')));
  25607. oppBottom = Math.min(oppBottom, oppAxis.domain[0]);
  25608. }
  25609. opts._id = constants.name + axisOpts._id;
  25610. opts._clipId = opts._id + '-' + fullLayout._uid;
  25611. opts._width = graphSize.w * (domain[1] - domain[0]);
  25612. opts._height = (fullLayout.height - margin.b - margin.t) * opts.thickness;
  25613. opts._offsetShift = Math.floor(opts.borderwidth / 2);
  25614. var x = Math.round(margin.l + (graphSize.w * domain[0]));
  25615. var y = Math.round(
  25616. graphSize.t + graphSize.h * (1 - oppBottom) +
  25617. tickHeight +
  25618. opts._offsetShift + constants.extraPad
  25619. );
  25620. rangeSlider.attr('transform', 'translate(' + x + ',' + y + ')');
  25621. // update data <--> pixel coordinate conversion methods
  25622. var range0 = axisOpts.r2l(opts.range[0]),
  25623. range1 = axisOpts.r2l(opts.range[1]),
  25624. dist = range1 - range0;
  25625. opts.p2d = function(v) {
  25626. return (v / opts._width) * dist + range0;
  25627. };
  25628. opts.d2p = function(v) {
  25629. return (v - range0) / dist * opts._width;
  25630. };
  25631. opts._rl = [range0, range1];
  25632. if(oppAxisRangeOpts.rangemode !== 'match') {
  25633. var range0OppAxis = oppAxisOpts.r2l(oppAxisRangeOpts.range[0]),
  25634. range1OppAxis = oppAxisOpts.r2l(oppAxisRangeOpts.range[1]),
  25635. distOppAxis = range1OppAxis - range0OppAxis;
  25636. opts.d2pOppAxis = function(v) {
  25637. return (v - range0OppAxis) / distOppAxis * opts._height;
  25638. };
  25639. }
  25640. // update inner nodes
  25641. rangeSlider
  25642. .call(drawBg, gd, axisOpts, opts)
  25643. .call(addClipPath, gd, axisOpts, opts)
  25644. .call(drawRangePlot, gd, axisOpts, opts)
  25645. .call(drawMasks, gd, axisOpts, opts, oppAxisRangeOpts)
  25646. .call(drawSlideBox, gd, axisOpts, opts)
  25647. .call(drawGrabbers, gd, axisOpts, opts);
  25648. // setup drag element
  25649. setupDragElement(rangeSlider, gd, axisOpts, opts);
  25650. // update current range
  25651. setPixelRange(rangeSlider, gd, axisOpts, opts, oppAxisOpts, oppAxisRangeOpts);
  25652. // title goes next to range slider instead of tick labels, so
  25653. // just take it over and draw it from here
  25654. if(axisOpts.side === 'bottom') {
  25655. Titles.draw(gd, axisOpts._id + 'title', {
  25656. propContainer: axisOpts,
  25657. propName: axisOpts._name + '.title',
  25658. placeholder: fullLayout._dfltTitle.x,
  25659. attributes: {
  25660. x: axisOpts._offset + axisOpts._length / 2,
  25661. y: y + opts._height + opts._offsetShift + 10 + 1.5 * axisOpts.titlefont.size,
  25662. 'text-anchor': 'middle'
  25663. }
  25664. });
  25665. }
  25666. // update margins
  25667. Plots.autoMargin(gd, opts._id, {
  25668. x: domain[0],
  25669. y: oppBottom,
  25670. l: 0,
  25671. r: 0,
  25672. t: 0,
  25673. b: opts._height + margin.b + tickHeight,
  25674. pad: constants.extraPad + opts._offsetShift * 2
  25675. });
  25676. });
  25677. };
  25678. function makeRangeSliderData(fullLayout) {
  25679. var axes = Axes.list({ _fullLayout: fullLayout }, 'x', true),
  25680. name = constants.name,
  25681. out = [];
  25682. if(fullLayout._has('gl2d')) return out;
  25683. for(var i = 0; i < axes.length; i++) {
  25684. var ax = axes[i];
  25685. if(ax[name] && ax[name].visible) out.push(ax);
  25686. }
  25687. return out;
  25688. }
  25689. function setupDragElement(rangeSlider, gd, axisOpts, opts) {
  25690. var slideBox = rangeSlider.select('rect.' + constants.slideBoxClassName).node(),
  25691. grabAreaMin = rangeSlider.select('rect.' + constants.grabAreaMinClassName).node(),
  25692. grabAreaMax = rangeSlider.select('rect.' + constants.grabAreaMaxClassName).node();
  25693. rangeSlider.on('mousedown', function() {
  25694. var event = d3.event,
  25695. target = event.target,
  25696. startX = event.clientX,
  25697. offsetX = startX - rangeSlider.node().getBoundingClientRect().left,
  25698. minVal = opts.d2p(axisOpts._rl[0]),
  25699. maxVal = opts.d2p(axisOpts._rl[1]);
  25700. var dragCover = dragElement.coverSlip();
  25701. dragCover.addEventListener('mousemove', mouseMove);
  25702. dragCover.addEventListener('mouseup', mouseUp);
  25703. function mouseMove(e) {
  25704. var delta = +e.clientX - startX;
  25705. var pixelMin, pixelMax, cursor;
  25706. switch(target) {
  25707. case slideBox:
  25708. cursor = 'ew-resize';
  25709. pixelMin = minVal + delta;
  25710. pixelMax = maxVal + delta;
  25711. break;
  25712. case grabAreaMin:
  25713. cursor = 'col-resize';
  25714. pixelMin = minVal + delta;
  25715. pixelMax = maxVal;
  25716. break;
  25717. case grabAreaMax:
  25718. cursor = 'col-resize';
  25719. pixelMin = minVal;
  25720. pixelMax = maxVal + delta;
  25721. break;
  25722. default:
  25723. cursor = 'ew-resize';
  25724. pixelMin = offsetX;
  25725. pixelMax = offsetX + delta;
  25726. break;
  25727. }
  25728. if(pixelMax < pixelMin) {
  25729. var tmp = pixelMax;
  25730. pixelMax = pixelMin;
  25731. pixelMin = tmp;
  25732. }
  25733. opts._pixelMin = pixelMin;
  25734. opts._pixelMax = pixelMax;
  25735. setCursor(d3.select(dragCover), cursor);
  25736. setDataRange(rangeSlider, gd, axisOpts, opts);
  25737. }
  25738. function mouseUp() {
  25739. dragCover.removeEventListener('mousemove', mouseMove);
  25740. dragCover.removeEventListener('mouseup', mouseUp);
  25741. Lib.removeElement(dragCover);
  25742. }
  25743. });
  25744. }
  25745. function setDataRange(rangeSlider, gd, axisOpts, opts) {
  25746. function clamp(v) {
  25747. return axisOpts.l2r(Lib.constrain(v, opts._rl[0], opts._rl[1]));
  25748. }
  25749. var dataMin = clamp(opts.p2d(opts._pixelMin)),
  25750. dataMax = clamp(opts.p2d(opts._pixelMax));
  25751. window.requestAnimationFrame(function() {
  25752. Registry.call('relayout', gd, axisOpts._name + '.range', [dataMin, dataMax]);
  25753. });
  25754. }
  25755. function setPixelRange(rangeSlider, gd, axisOpts, opts, oppAxisOpts, oppAxisRangeOpts) {
  25756. var hw2 = constants.handleWidth / 2;
  25757. function clamp(v) {
  25758. return Lib.constrain(v, 0, opts._width);
  25759. }
  25760. function clampOppAxis(v) {
  25761. return Lib.constrain(v, 0, opts._height);
  25762. }
  25763. function clampHandle(v) {
  25764. return Lib.constrain(v, -hw2, opts._width + hw2);
  25765. }
  25766. var pixelMin = clamp(opts.d2p(axisOpts._rl[0])),
  25767. pixelMax = clamp(opts.d2p(axisOpts._rl[1]));
  25768. rangeSlider.select('rect.' + constants.slideBoxClassName)
  25769. .attr('x', pixelMin)
  25770. .attr('width', pixelMax - pixelMin);
  25771. rangeSlider.select('rect.' + constants.maskMinClassName)
  25772. .attr('width', pixelMin);
  25773. rangeSlider.select('rect.' + constants.maskMaxClassName)
  25774. .attr('x', pixelMax)
  25775. .attr('width', opts._width - pixelMax);
  25776. if(oppAxisRangeOpts.rangemode !== 'match') {
  25777. var pixelMinOppAxis = opts._height - clampOppAxis(opts.d2pOppAxis(oppAxisOpts._rl[1])),
  25778. pixelMaxOppAxis = opts._height - clampOppAxis(opts.d2pOppAxis(oppAxisOpts._rl[0]));
  25779. rangeSlider.select('rect.' + constants.maskMinOppAxisClassName)
  25780. .attr('x', pixelMin)
  25781. .attr('height', pixelMinOppAxis)
  25782. .attr('width', pixelMax - pixelMin);
  25783. rangeSlider.select('rect.' + constants.maskMaxOppAxisClassName)
  25784. .attr('x', pixelMin)
  25785. .attr('y', pixelMaxOppAxis)
  25786. .attr('height', opts._height - pixelMaxOppAxis)
  25787. .attr('width', pixelMax - pixelMin);
  25788. rangeSlider.select('rect.' + constants.slideBoxClassName)
  25789. .attr('y', pixelMinOppAxis)
  25790. .attr('height', pixelMaxOppAxis - pixelMinOppAxis);
  25791. }
  25792. // add offset for crispier corners
  25793. // https://github.com/plotly/plotly.js/pull/1409
  25794. var offset = 0.5;
  25795. var xMin = Math.round(clampHandle(pixelMin - hw2)) - offset,
  25796. xMax = Math.round(clampHandle(pixelMax - hw2)) + offset;
  25797. rangeSlider.select('g.' + constants.grabberMinClassName)
  25798. .attr('transform', 'translate(' + xMin + ',' + offset + ')');
  25799. rangeSlider.select('g.' + constants.grabberMaxClassName)
  25800. .attr('transform', 'translate(' + xMax + ',' + offset + ')');
  25801. }
  25802. function drawBg(rangeSlider, gd, axisOpts, opts) {
  25803. var bg = Lib.ensureSingle(rangeSlider, 'rect', constants.bgClassName, function(s) {
  25804. s.attr({
  25805. x: 0,
  25806. y: 0,
  25807. 'shape-rendering': 'crispEdges'
  25808. });
  25809. });
  25810. var borderCorrect = (opts.borderwidth % 2) === 0 ?
  25811. opts.borderwidth :
  25812. opts.borderwidth - 1;
  25813. var offsetShift = -opts._offsetShift;
  25814. var lw = Drawing.crispRound(gd, opts.borderwidth);
  25815. bg.attr({
  25816. width: opts._width + borderCorrect,
  25817. height: opts._height + borderCorrect,
  25818. transform: 'translate(' + offsetShift + ',' + offsetShift + ')',
  25819. fill: opts.bgcolor,
  25820. stroke: opts.bordercolor,
  25821. 'stroke-width': lw
  25822. });
  25823. }
  25824. function addClipPath(rangeSlider, gd, axisOpts, opts) {
  25825. var fullLayout = gd._fullLayout;
  25826. var clipPath = Lib.ensureSingleById(fullLayout._topdefs, 'clipPath', opts._clipId, function(s) {
  25827. s.append('rect').attr({ x: 0, y: 0 });
  25828. });
  25829. clipPath.select('rect').attr({
  25830. width: opts._width,
  25831. height: opts._height
  25832. });
  25833. }
  25834. function drawRangePlot(rangeSlider, gd, axisOpts, opts) {
  25835. var subplotData = Axes.getSubplots(gd, axisOpts),
  25836. calcData = gd.calcdata;
  25837. var rangePlots = rangeSlider.selectAll('g.' + constants.rangePlotClassName)
  25838. .data(subplotData, Lib.identity);
  25839. rangePlots.enter().append('g')
  25840. .attr('class', function(id) { return constants.rangePlotClassName + ' ' + id; })
  25841. .call(Drawing.setClipUrl, opts._clipId);
  25842. rangePlots.order();
  25843. rangePlots.exit().remove();
  25844. var mainplotinfo;
  25845. rangePlots.each(function(id, i) {
  25846. var plotgroup = d3.select(this),
  25847. isMainPlot = (i === 0);
  25848. var oppAxisOpts = Axes.getFromId(gd, id, 'y'),
  25849. oppAxisName = oppAxisOpts._name,
  25850. oppAxisRangeOpts = opts[oppAxisName];
  25851. var mockFigure = {
  25852. data: [],
  25853. layout: {
  25854. xaxis: {
  25855. type: axisOpts.type,
  25856. domain: [0, 1],
  25857. range: opts.range.slice(),
  25858. calendar: axisOpts.calendar
  25859. },
  25860. width: opts._width,
  25861. height: opts._height,
  25862. margin: { t: 0, b: 0, l: 0, r: 0 }
  25863. },
  25864. _context: gd._context
  25865. };
  25866. mockFigure.layout[oppAxisName] = {
  25867. type: oppAxisOpts.type,
  25868. domain: [0, 1],
  25869. range: oppAxisRangeOpts.rangemode !== 'match' ? oppAxisRangeOpts.range.slice() : oppAxisOpts.range.slice(),
  25870. calendar: oppAxisOpts.calendar
  25871. };
  25872. Plots.supplyDefaults(mockFigure);
  25873. var xa = mockFigure._fullLayout.xaxis;
  25874. var ya = mockFigure._fullLayout[oppAxisName];
  25875. var plotinfo = {
  25876. id: id,
  25877. plotgroup: plotgroup,
  25878. xaxis: xa,
  25879. yaxis: ya,
  25880. isRangePlot: true
  25881. };
  25882. if(isMainPlot) mainplotinfo = plotinfo;
  25883. else {
  25884. plotinfo.mainplot = 'xy';
  25885. plotinfo.mainplotinfo = mainplotinfo;
  25886. }
  25887. Cartesian.rangePlot(gd, plotinfo, filterRangePlotCalcData(calcData, id));
  25888. });
  25889. }
  25890. function filterRangePlotCalcData(calcData, subplotId) {
  25891. var out = [];
  25892. for(var i = 0; i < calcData.length; i++) {
  25893. var calcTrace = calcData[i],
  25894. trace = calcTrace[0].trace;
  25895. if(trace.xaxis + trace.yaxis === subplotId) {
  25896. out.push(calcTrace);
  25897. }
  25898. }
  25899. return out;
  25900. }
  25901. function drawMasks(rangeSlider, gd, axisOpts, opts, oppAxisRangeOpts) {
  25902. var maskMin = Lib.ensureSingle(rangeSlider, 'rect', constants.maskMinClassName, function(s) {
  25903. s.attr({
  25904. x: 0,
  25905. y: 0,
  25906. 'shape-rendering': 'crispEdges'
  25907. });
  25908. });
  25909. maskMin
  25910. .attr('height', opts._height)
  25911. .call(Color.fill, constants.maskColor);
  25912. var maskMax = Lib.ensureSingle(rangeSlider, 'rect', constants.maskMaxClassName, function(s) {
  25913. s.attr({
  25914. y: 0,
  25915. 'shape-rendering': 'crispEdges'
  25916. });
  25917. });
  25918. maskMax
  25919. .attr('height', opts._height)
  25920. .call(Color.fill, constants.maskColor);
  25921. // masks used for oppAxis zoom
  25922. if(oppAxisRangeOpts.rangemode !== 'match') {
  25923. var maskMinOppAxis = Lib.ensureSingle(rangeSlider, 'rect', constants.maskMinOppAxisClassName, function(s) {
  25924. s.attr({
  25925. y: 0,
  25926. 'shape-rendering': 'crispEdges'
  25927. });
  25928. });
  25929. maskMinOppAxis
  25930. .attr('width', opts._width)
  25931. .call(Color.fill, constants.maskOppAxisColor);
  25932. var maskMaxOppAxis = Lib.ensureSingle(rangeSlider, 'rect', constants.maskMaxOppAxisClassName, function(s) {
  25933. s.attr({
  25934. y: 0,
  25935. 'shape-rendering': 'crispEdges'
  25936. });
  25937. });
  25938. maskMaxOppAxis
  25939. .attr('width', opts._width)
  25940. .style('border-top', constants.maskOppBorder)
  25941. .call(Color.fill, constants.maskOppAxisColor);
  25942. }
  25943. }
  25944. function drawSlideBox(rangeSlider, gd, axisOpts, opts) {
  25945. if(gd._context.staticPlot) return;
  25946. var slideBox = Lib.ensureSingle(rangeSlider, 'rect', constants.slideBoxClassName, function(s) {
  25947. s.attr({
  25948. y: 0,
  25949. cursor: constants.slideBoxCursor,
  25950. 'shape-rendering': 'crispEdges'
  25951. });
  25952. });
  25953. slideBox.attr({
  25954. height: opts._height,
  25955. fill: constants.slideBoxFill
  25956. });
  25957. }
  25958. function drawGrabbers(rangeSlider, gd, axisOpts, opts) {
  25959. // <g grabber />
  25960. var grabberMin = Lib.ensureSingle(rangeSlider, 'g', constants.grabberMinClassName);
  25961. var grabberMax = Lib.ensureSingle(rangeSlider, 'g', constants.grabberMaxClassName);
  25962. // <g handle />
  25963. var handleFixAttrs = {
  25964. x: 0,
  25965. width: constants.handleWidth,
  25966. rx: constants.handleRadius,
  25967. fill: Color.background,
  25968. stroke: Color.defaultLine,
  25969. 'stroke-width': constants.handleStrokeWidth,
  25970. 'shape-rendering': 'crispEdges'
  25971. };
  25972. var handleDynamicAttrs = {
  25973. y: Math.round(opts._height / 4),
  25974. height: Math.round(opts._height / 2),
  25975. };
  25976. var handleMin = Lib.ensureSingle(grabberMin, 'rect', constants.handleMinClassName, function(s) {
  25977. s.attr(handleFixAttrs);
  25978. });
  25979. handleMin.attr(handleDynamicAttrs);
  25980. var handleMax = Lib.ensureSingle(grabberMax, 'rect', constants.handleMaxClassName, function(s) {
  25981. s.attr(handleFixAttrs);
  25982. });
  25983. handleMax.attr(handleDynamicAttrs);
  25984. // <g grabarea />
  25985. if(gd._context.staticPlot) return;
  25986. var grabAreaFixAttrs = {
  25987. width: constants.grabAreaWidth,
  25988. x: 0,
  25989. y: 0,
  25990. fill: constants.grabAreaFill,
  25991. cursor: constants.grabAreaCursor
  25992. };
  25993. var grabAreaMin = Lib.ensureSingle(grabberMin, 'rect', constants.grabAreaMinClassName, function(s) {
  25994. s.attr(grabAreaFixAttrs);
  25995. });
  25996. grabAreaMin.attr('height', opts._height);
  25997. var grabAreaMax = Lib.ensureSingle(grabberMax, 'rect', constants.grabAreaMaxClassName, function(s) {
  25998. s.attr(grabAreaFixAttrs);
  25999. });
  26000. grabAreaMax.attr('height', opts._height);
  26001. }
  26002. },{"../../lib":169,"../../lib/setcursor":189,"../../plots/cartesian":225,"../../plots/cartesian/axes":214,"../../plots/plots":246,"../../registry":259,"../color":50,"../dragelement":72,"../drawing":75,"../titles":141,"./constants":124,"d3":16}],127:[function(_dereq_,module,exports){
  26003. /**
  26004. * Copyright 2012-2018, Plotly, Inc.
  26005. * All rights reserved.
  26006. *
  26007. * This source code is licensed under the MIT license found in the
  26008. * LICENSE file in the root directory of this source tree.
  26009. */
  26010. 'use strict';
  26011. var Lib = _dereq_('../../lib');
  26012. var attrs = _dereq_('./attributes');
  26013. var oppAxisAttrs = _dereq_('./oppaxis_attributes');
  26014. module.exports = {
  26015. moduleType: 'component',
  26016. name: 'rangeslider',
  26017. schema: {
  26018. subplots: {
  26019. xaxis: {
  26020. rangeslider: Lib.extendFlat({}, attrs, {
  26021. yaxis: oppAxisAttrs
  26022. })
  26023. }
  26024. }
  26025. },
  26026. layoutAttributes: _dereq_('./attributes'),
  26027. handleDefaults: _dereq_('./defaults'),
  26028. calcAutorange: _dereq_('./calc_autorange'),
  26029. draw: _dereq_('./draw')
  26030. };
  26031. },{"../../lib":169,"./attributes":122,"./calc_autorange":123,"./defaults":125,"./draw":126,"./oppaxis_attributes":128}],128:[function(_dereq_,module,exports){
  26032. /**
  26033. * Copyright 2012-2018, Plotly, Inc.
  26034. * All rights reserved.
  26035. *
  26036. * This source code is licensed under the MIT license found in the
  26037. * LICENSE file in the root directory of this source tree.
  26038. */
  26039. 'use strict';
  26040. module.exports = {
  26041. // not really a 'subplot' attribute container,
  26042. // but this is the flag we use to denote attributes that
  26043. // support yaxis, yaxis2, yaxis3, ... counters
  26044. _isSubplotObj: true,
  26045. rangemode: {
  26046. valType: 'enumerated',
  26047. values: ['auto', 'fixed', 'match'],
  26048. dflt: 'match',
  26049. editType: 'calc',
  26050. },
  26051. range: {
  26052. valType: 'info_array',
  26053. items: [
  26054. {valType: 'any', editType: 'plot'},
  26055. {valType: 'any', editType: 'plot'}
  26056. ],
  26057. editType: 'plot',
  26058. },
  26059. editType: 'calc'
  26060. };
  26061. },{}],129:[function(_dereq_,module,exports){
  26062. /**
  26063. * Copyright 2012-2018, Plotly, Inc.
  26064. * All rights reserved.
  26065. *
  26066. * This source code is licensed under the MIT license found in the
  26067. * LICENSE file in the root directory of this source tree.
  26068. */
  26069. 'use strict';
  26070. var annAttrs = _dereq_('../annotations/attributes');
  26071. var scatterLineAttrs = _dereq_('../../traces/scatter/attributes').line;
  26072. var dash = _dereq_('../drawing/attributes').dash;
  26073. var extendFlat = _dereq_('../../lib/extend').extendFlat;
  26074. var templatedArray = _dereq_('../../plot_api/plot_template').templatedArray;
  26075. module.exports = templatedArray('shape', {
  26076. visible: {
  26077. valType: 'boolean',
  26078. dflt: true,
  26079. editType: 'calc+arraydraw',
  26080. },
  26081. type: {
  26082. valType: 'enumerated',
  26083. values: ['circle', 'rect', 'path', 'line'],
  26084. editType: 'calc+arraydraw',
  26085. },
  26086. layer: {
  26087. valType: 'enumerated',
  26088. values: ['below', 'above'],
  26089. dflt: 'above',
  26090. editType: 'arraydraw',
  26091. },
  26092. xref: extendFlat({}, annAttrs.xref, {
  26093. }),
  26094. xsizemode: {
  26095. valType: 'enumerated',
  26096. values: ['scaled', 'pixel'],
  26097. dflt: 'scaled',
  26098. editType: 'calc+arraydraw',
  26099. },
  26100. xanchor: {
  26101. valType: 'any',
  26102. editType: 'calc+arraydraw',
  26103. },
  26104. x0: {
  26105. valType: 'any',
  26106. editType: 'calc+arraydraw',
  26107. },
  26108. x1: {
  26109. valType: 'any',
  26110. editType: 'calc+arraydraw',
  26111. },
  26112. yref: extendFlat({}, annAttrs.yref, {
  26113. }),
  26114. ysizemode: {
  26115. valType: 'enumerated',
  26116. values: ['scaled', 'pixel'],
  26117. dflt: 'scaled',
  26118. editType: 'calc+arraydraw',
  26119. },
  26120. yanchor: {
  26121. valType: 'any',
  26122. editType: 'calc+arraydraw',
  26123. },
  26124. y0: {
  26125. valType: 'any',
  26126. editType: 'calc+arraydraw',
  26127. },
  26128. y1: {
  26129. valType: 'any',
  26130. editType: 'calc+arraydraw',
  26131. },
  26132. path: {
  26133. valType: 'string',
  26134. editType: 'calc+arraydraw',
  26135. },
  26136. opacity: {
  26137. valType: 'number',
  26138. min: 0,
  26139. max: 1,
  26140. dflt: 1,
  26141. editType: 'arraydraw',
  26142. },
  26143. line: {
  26144. color: extendFlat({}, scatterLineAttrs.color, {editType: 'arraydraw'}),
  26145. width: extendFlat({}, scatterLineAttrs.width, {editType: 'calc+arraydraw'}),
  26146. dash: extendFlat({}, dash, {editType: 'arraydraw'}),
  26147. editType: 'calc+arraydraw'
  26148. },
  26149. fillcolor: {
  26150. valType: 'color',
  26151. dflt: 'rgba(0,0,0,0)',
  26152. editType: 'arraydraw',
  26153. },
  26154. editType: 'arraydraw'
  26155. });
  26156. },{"../../lib/extend":163,"../../plot_api/plot_template":204,"../../traces/scatter/attributes":366,"../annotations/attributes":35,"../drawing/attributes":74}],130:[function(_dereq_,module,exports){
  26157. /**
  26158. * Copyright 2012-2018, Plotly, Inc.
  26159. * All rights reserved.
  26160. *
  26161. * This source code is licensed under the MIT license found in the
  26162. * LICENSE file in the root directory of this source tree.
  26163. */
  26164. 'use strict';
  26165. var Lib = _dereq_('../../lib');
  26166. var Axes = _dereq_('../../plots/cartesian/axes');
  26167. var constants = _dereq_('./constants');
  26168. var helpers = _dereq_('./helpers');
  26169. module.exports = function calcAutorange(gd) {
  26170. var fullLayout = gd._fullLayout,
  26171. shapeList = Lib.filterVisible(fullLayout.shapes);
  26172. if(!shapeList.length || !gd._fullData.length) return;
  26173. for(var i = 0; i < shapeList.length; i++) {
  26174. var shape = shapeList[i];
  26175. shape._extremes = {};
  26176. var ax, bounds;
  26177. if(shape.xref !== 'paper') {
  26178. var vx0 = shape.xsizemode === 'pixel' ? shape.xanchor : shape.x0,
  26179. vx1 = shape.xsizemode === 'pixel' ? shape.xanchor : shape.x1;
  26180. ax = Axes.getFromId(gd, shape.xref);
  26181. bounds = shapeBounds(ax, vx0, vx1, shape.path, constants.paramIsX);
  26182. if(bounds) {
  26183. shape._extremes[ax._id] = Axes.findExtremes(ax, bounds, calcXPaddingOptions(shape));
  26184. }
  26185. }
  26186. if(shape.yref !== 'paper') {
  26187. var vy0 = shape.ysizemode === 'pixel' ? shape.yanchor : shape.y0,
  26188. vy1 = shape.ysizemode === 'pixel' ? shape.yanchor : shape.y1;
  26189. ax = Axes.getFromId(gd, shape.yref);
  26190. bounds = shapeBounds(ax, vy0, vy1, shape.path, constants.paramIsY);
  26191. if(bounds) {
  26192. shape._extremes[ax._id] = Axes.findExtremes(ax, bounds, calcYPaddingOptions(shape));
  26193. }
  26194. }
  26195. }
  26196. };
  26197. function calcXPaddingOptions(shape) {
  26198. return calcPaddingOptions(shape.line.width, shape.xsizemode, shape.x0, shape.x1, shape.path, false);
  26199. }
  26200. function calcYPaddingOptions(shape) {
  26201. return calcPaddingOptions(shape.line.width, shape.ysizemode, shape.y0, shape.y1, shape.path, true);
  26202. }
  26203. function calcPaddingOptions(lineWidth, sizeMode, v0, v1, path, isYAxis) {
  26204. var ppad = lineWidth / 2,
  26205. axisDirectionReverted = isYAxis;
  26206. if(sizeMode === 'pixel') {
  26207. var coords = path ?
  26208. helpers.extractPathCoords(path, isYAxis ? constants.paramIsY : constants.paramIsX) :
  26209. [v0, v1];
  26210. var maxValue = Lib.aggNums(Math.max, null, coords),
  26211. minValue = Lib.aggNums(Math.min, null, coords),
  26212. beforePad = minValue < 0 ? Math.abs(minValue) + ppad : ppad,
  26213. afterPad = maxValue > 0 ? maxValue + ppad : ppad;
  26214. return {
  26215. ppad: ppad,
  26216. ppadplus: axisDirectionReverted ? beforePad : afterPad,
  26217. ppadminus: axisDirectionReverted ? afterPad : beforePad
  26218. };
  26219. } else {
  26220. return {ppad: ppad};
  26221. }
  26222. }
  26223. function shapeBounds(ax, v0, v1, path, paramsToUse) {
  26224. var convertVal = (ax.type === 'category') ? ax.r2c : ax.d2c;
  26225. if(v0 !== undefined) return [convertVal(v0), convertVal(v1)];
  26226. if(!path) return;
  26227. var min = Infinity,
  26228. max = -Infinity,
  26229. segments = path.match(constants.segmentRE),
  26230. i,
  26231. segment,
  26232. drawnParam,
  26233. params,
  26234. val;
  26235. if(ax.type === 'date') convertVal = helpers.decodeDate(convertVal);
  26236. for(i = 0; i < segments.length; i++) {
  26237. segment = segments[i];
  26238. drawnParam = paramsToUse[segment.charAt(0)].drawn;
  26239. if(drawnParam === undefined) continue;
  26240. params = segments[i].substr(1).match(constants.paramRE);
  26241. if(!params || params.length < drawnParam) continue;
  26242. val = convertVal(params[drawnParam]);
  26243. if(val < min) min = val;
  26244. if(val > max) max = val;
  26245. }
  26246. if(max >= min) return [min, max];
  26247. }
  26248. },{"../../lib":169,"../../plots/cartesian/axes":214,"./constants":131,"./helpers":134}],131:[function(_dereq_,module,exports){
  26249. /**
  26250. * Copyright 2012-2018, Plotly, Inc.
  26251. * All rights reserved.
  26252. *
  26253. * This source code is licensed under the MIT license found in the
  26254. * LICENSE file in the root directory of this source tree.
  26255. */
  26256. 'use strict';
  26257. module.exports = {
  26258. segmentRE: /[MLHVQCTSZ][^MLHVQCTSZ]*/g,
  26259. paramRE: /[^\s,]+/g,
  26260. // which numbers in each path segment are x (or y) values
  26261. // drawn is which param is a drawn point, as opposed to a
  26262. // control point (which doesn't count toward autorange.
  26263. // TODO: this means curved paths could extend beyond the
  26264. // autorange bounds. This is a bit tricky to get right
  26265. // unless we revert to bounding boxes, but perhaps there's
  26266. // a calculation we could do...)
  26267. paramIsX: {
  26268. M: {0: true, drawn: 0},
  26269. L: {0: true, drawn: 0},
  26270. H: {0: true, drawn: 0},
  26271. V: {},
  26272. Q: {0: true, 2: true, drawn: 2},
  26273. C: {0: true, 2: true, 4: true, drawn: 4},
  26274. T: {0: true, drawn: 0},
  26275. S: {0: true, 2: true, drawn: 2},
  26276. // A: {0: true, 5: true},
  26277. Z: {}
  26278. },
  26279. paramIsY: {
  26280. M: {1: true, drawn: 1},
  26281. L: {1: true, drawn: 1},
  26282. H: {},
  26283. V: {0: true, drawn: 0},
  26284. Q: {1: true, 3: true, drawn: 3},
  26285. C: {1: true, 3: true, 5: true, drawn: 5},
  26286. T: {1: true, drawn: 1},
  26287. S: {1: true, 3: true, drawn: 5},
  26288. // A: {1: true, 6: true},
  26289. Z: {}
  26290. },
  26291. numParams: {
  26292. M: 2,
  26293. L: 2,
  26294. H: 1,
  26295. V: 1,
  26296. Q: 4,
  26297. C: 6,
  26298. T: 2,
  26299. S: 4,
  26300. // A: 7,
  26301. Z: 0
  26302. }
  26303. };
  26304. },{}],132:[function(_dereq_,module,exports){
  26305. /**
  26306. * Copyright 2012-2018, Plotly, Inc.
  26307. * All rights reserved.
  26308. *
  26309. * This source code is licensed under the MIT license found in the
  26310. * LICENSE file in the root directory of this source tree.
  26311. */
  26312. 'use strict';
  26313. var Lib = _dereq_('../../lib');
  26314. var Axes = _dereq_('../../plots/cartesian/axes');
  26315. var handleArrayContainerDefaults = _dereq_('../../plots/array_container_defaults');
  26316. var attributes = _dereq_('./attributes');
  26317. var helpers = _dereq_('./helpers');
  26318. module.exports = function supplyLayoutDefaults(layoutIn, layoutOut) {
  26319. handleArrayContainerDefaults(layoutIn, layoutOut, {
  26320. name: 'shapes',
  26321. handleItemDefaults: handleShapeDefaults
  26322. });
  26323. };
  26324. function handleShapeDefaults(shapeIn, shapeOut, fullLayout) {
  26325. function coerce(attr, dflt) {
  26326. return Lib.coerce(shapeIn, shapeOut, attributes, attr, dflt);
  26327. }
  26328. var visible = coerce('visible');
  26329. if(!visible) return;
  26330. coerce('layer');
  26331. coerce('opacity');
  26332. coerce('fillcolor');
  26333. coerce('line.color');
  26334. coerce('line.width');
  26335. coerce('line.dash');
  26336. var dfltType = shapeIn.path ? 'path' : 'rect',
  26337. shapeType = coerce('type', dfltType),
  26338. xSizeMode = coerce('xsizemode'),
  26339. ySizeMode = coerce('ysizemode');
  26340. // positioning
  26341. var axLetters = ['x', 'y'];
  26342. for(var i = 0; i < 2; i++) {
  26343. var axLetter = axLetters[i],
  26344. attrAnchor = axLetter + 'anchor',
  26345. sizeMode = axLetter === 'x' ? xSizeMode : ySizeMode,
  26346. gdMock = {_fullLayout: fullLayout},
  26347. ax,
  26348. pos2r,
  26349. r2pos;
  26350. // xref, yref
  26351. var axRef = Axes.coerceRef(shapeIn, shapeOut, gdMock, axLetter, '', 'paper');
  26352. if(axRef !== 'paper') {
  26353. ax = Axes.getFromId(gdMock, axRef);
  26354. ax._shapeIndices.push(shapeOut._index);
  26355. r2pos = helpers.rangeToShapePosition(ax);
  26356. pos2r = helpers.shapePositionToRange(ax);
  26357. }
  26358. else {
  26359. pos2r = r2pos = Lib.identity;
  26360. }
  26361. // Coerce x0, x1, y0, y1
  26362. if(shapeType !== 'path') {
  26363. var dflt0 = 0.25,
  26364. dflt1 = 0.75;
  26365. // hack until V2.0 when log has regular range behavior - make it look like other
  26366. // ranges to send to coerce, then put it back after
  26367. // this is all to give reasonable default position behavior on log axes, which is
  26368. // a pretty unimportant edge case so we could just ignore this.
  26369. var attr0 = axLetter + '0',
  26370. attr1 = axLetter + '1',
  26371. in0 = shapeIn[attr0],
  26372. in1 = shapeIn[attr1];
  26373. shapeIn[attr0] = pos2r(shapeIn[attr0], true);
  26374. shapeIn[attr1] = pos2r(shapeIn[attr1], true);
  26375. if(sizeMode === 'pixel') {
  26376. coerce(attr0, 0);
  26377. coerce(attr1, 10);
  26378. } else {
  26379. Axes.coercePosition(shapeOut, gdMock, coerce, axRef, attr0, dflt0);
  26380. Axes.coercePosition(shapeOut, gdMock, coerce, axRef, attr1, dflt1);
  26381. }
  26382. // hack part 2
  26383. shapeOut[attr0] = r2pos(shapeOut[attr0]);
  26384. shapeOut[attr1] = r2pos(shapeOut[attr1]);
  26385. shapeIn[attr0] = in0;
  26386. shapeIn[attr1] = in1;
  26387. }
  26388. // Coerce xanchor and yanchor
  26389. if(sizeMode === 'pixel') {
  26390. // Hack for log axis described above
  26391. var inAnchor = shapeIn[attrAnchor];
  26392. shapeIn[attrAnchor] = pos2r(shapeIn[attrAnchor], true);
  26393. Axes.coercePosition(shapeOut, gdMock, coerce, axRef, attrAnchor, 0.25);
  26394. // Hack part 2
  26395. shapeOut[attrAnchor] = r2pos(shapeOut[attrAnchor]);
  26396. shapeIn[attrAnchor] = inAnchor;
  26397. }
  26398. }
  26399. if(shapeType === 'path') {
  26400. coerce('path');
  26401. }
  26402. else {
  26403. Lib.noneOrAll(shapeIn, shapeOut, ['x0', 'x1', 'y0', 'y1']);
  26404. }
  26405. }
  26406. },{"../../lib":169,"../../plots/array_container_defaults":210,"../../plots/cartesian/axes":214,"./attributes":129,"./helpers":134}],133:[function(_dereq_,module,exports){
  26407. /**
  26408. * Copyright 2012-2018, Plotly, Inc.
  26409. * All rights reserved.
  26410. *
  26411. * This source code is licensed under the MIT license found in the
  26412. * LICENSE file in the root directory of this source tree.
  26413. */
  26414. 'use strict';
  26415. var Registry = _dereq_('../../registry');
  26416. var Lib = _dereq_('../../lib');
  26417. var Axes = _dereq_('../../plots/cartesian/axes');
  26418. var Color = _dereq_('../color');
  26419. var Drawing = _dereq_('../drawing');
  26420. var arrayEditor = _dereq_('../../plot_api/plot_template').arrayEditor;
  26421. var dragElement = _dereq_('../dragelement');
  26422. var setCursor = _dereq_('../../lib/setcursor');
  26423. var constants = _dereq_('./constants');
  26424. var helpers = _dereq_('./helpers');
  26425. // Shapes are stored in gd.layout.shapes, an array of objects
  26426. // index can point to one item in this array,
  26427. // or non-numeric to simply add a new one
  26428. // or -1 to modify all existing
  26429. // opt can be the full options object, or one key (to be set to value)
  26430. // or undefined to simply redraw
  26431. // if opt is blank, val can be 'add' or a full options object to add a new
  26432. // annotation at that point in the array, or 'remove' to delete this one
  26433. module.exports = {
  26434. draw: draw,
  26435. drawOne: drawOne
  26436. };
  26437. function draw(gd) {
  26438. var fullLayout = gd._fullLayout;
  26439. // Remove previous shapes before drawing new in shapes in fullLayout.shapes
  26440. fullLayout._shapeUpperLayer.selectAll('path').remove();
  26441. fullLayout._shapeLowerLayer.selectAll('path').remove();
  26442. for(var k in fullLayout._plots) {
  26443. var shapelayer = fullLayout._plots[k].shapelayer;
  26444. if(shapelayer) shapelayer.selectAll('path').remove();
  26445. }
  26446. for(var i = 0; i < fullLayout.shapes.length; i++) {
  26447. if(fullLayout.shapes[i].visible) {
  26448. drawOne(gd, i);
  26449. }
  26450. }
  26451. // may need to resurrect this if we put text (LaTeX) in shapes
  26452. // return Plots.previousPromises(gd);
  26453. }
  26454. function drawOne(gd, index) {
  26455. // remove the existing shape if there is one.
  26456. // because indices can change, we need to look in all shape layers
  26457. gd._fullLayout._paperdiv
  26458. .selectAll('.shapelayer [data-index="' + index + '"]')
  26459. .remove();
  26460. var options = gd._fullLayout.shapes[index] || {};
  26461. // this shape is gone - quit now after deleting it
  26462. // TODO: use d3 idioms instead of deleting and redrawing every time
  26463. if(!options._input || options.visible === false) return;
  26464. if(options.layer !== 'below') {
  26465. drawShape(gd._fullLayout._shapeUpperLayer);
  26466. }
  26467. else if(options.xref === 'paper' || options.yref === 'paper') {
  26468. drawShape(gd._fullLayout._shapeLowerLayer);
  26469. }
  26470. else {
  26471. var plotinfo = gd._fullLayout._plots[options.xref + options.yref];
  26472. if(plotinfo) {
  26473. var mainPlot = plotinfo.mainplotinfo || plotinfo;
  26474. drawShape(mainPlot.shapelayer);
  26475. }
  26476. else {
  26477. // Fall back to _shapeLowerLayer in case the requested subplot doesn't exist.
  26478. // This can happen if you reference the shape to an x / y axis combination
  26479. // that doesn't have any data on it (and layer is below)
  26480. drawShape(gd._fullLayout._shapeLowerLayer);
  26481. }
  26482. }
  26483. function drawShape(shapeLayer) {
  26484. var attrs = {
  26485. 'data-index': index,
  26486. 'fill-rule': 'evenodd',
  26487. d: getPathString(gd, options)
  26488. },
  26489. lineColor = options.line.width ?
  26490. options.line.color : 'rgba(0,0,0,0)';
  26491. var path = shapeLayer.append('path')
  26492. .attr(attrs)
  26493. .style('opacity', options.opacity)
  26494. .call(Color.stroke, lineColor)
  26495. .call(Color.fill, options.fillcolor)
  26496. .call(Drawing.dashLine, options.line.dash, options.line.width);
  26497. setClipPath(path, gd, options);
  26498. if(gd._context.edits.shapePosition) setupDragElement(gd, path, options, index, shapeLayer);
  26499. }
  26500. }
  26501. function setClipPath(shapePath, gd, shapeOptions) {
  26502. // note that for layer="below" the clipAxes can be different from the
  26503. // subplot we're drawing this in. This could cause problems if the shape
  26504. // spans two subplots. See https://github.com/plotly/plotly.js/issues/1452
  26505. var clipAxes = (shapeOptions.xref + shapeOptions.yref).replace(/paper/g, '');
  26506. shapePath.call(Drawing.setClipUrl, clipAxes ?
  26507. ('clip' + gd._fullLayout._uid + clipAxes) :
  26508. null
  26509. );
  26510. }
  26511. function setupDragElement(gd, shapePath, shapeOptions, index, shapeLayer) {
  26512. var MINWIDTH = 10;
  26513. var MINHEIGHT = 10;
  26514. var xPixelSized = shapeOptions.xsizemode === 'pixel';
  26515. var yPixelSized = shapeOptions.ysizemode === 'pixel';
  26516. var isLine = shapeOptions.type === 'line';
  26517. var isPath = shapeOptions.type === 'path';
  26518. var editHelpers = arrayEditor(gd.layout, 'shapes', shapeOptions);
  26519. var modifyItem = editHelpers.modifyItem;
  26520. var x0, y0, x1, y1, xAnchor, yAnchor;
  26521. var n0, s0, w0, e0, optN, optS, optW, optE;
  26522. var pathIn;
  26523. // setup conversion functions
  26524. var xa = Axes.getFromId(gd, shapeOptions.xref),
  26525. ya = Axes.getFromId(gd, shapeOptions.yref),
  26526. x2p = helpers.getDataToPixel(gd, xa),
  26527. y2p = helpers.getDataToPixel(gd, ya, true),
  26528. p2x = helpers.getPixelToData(gd, xa),
  26529. p2y = helpers.getPixelToData(gd, ya, true);
  26530. var sensoryElement = obtainSensoryElement();
  26531. var dragOptions = {
  26532. element: sensoryElement.node(),
  26533. gd: gd,
  26534. prepFn: startDrag,
  26535. doneFn: endDrag,
  26536. clickFn: abortDrag
  26537. },
  26538. dragMode;
  26539. dragElement.init(dragOptions);
  26540. sensoryElement.node().onmousemove = updateDragMode;
  26541. function obtainSensoryElement() {
  26542. return isLine ? createLineDragHandles() : shapePath;
  26543. }
  26544. function createLineDragHandles() {
  26545. var minSensoryWidth = 10,
  26546. sensoryWidth = Math.max(shapeOptions.line.width, minSensoryWidth);
  26547. // Helper shapes group
  26548. // Note that by setting the `data-index` attr, it is ensured that
  26549. // the helper group is purged in this modules `draw` function
  26550. var g = shapeLayer.append('g')
  26551. .attr('data-index', index);
  26552. // Helper path for moving
  26553. g.append('path')
  26554. .attr('d', shapePath.attr('d'))
  26555. .style({
  26556. 'cursor': 'move',
  26557. 'stroke-width': sensoryWidth,
  26558. 'stroke-opacity': '0' // ensure not visible
  26559. });
  26560. // Helper circles for resizing
  26561. var circleStyle = {
  26562. 'fill-opacity': '0' // ensure not visible
  26563. };
  26564. var circleRadius = sensoryWidth / 2 > minSensoryWidth ? sensoryWidth / 2 : minSensoryWidth;
  26565. g.append('circle')
  26566. .attr({
  26567. 'data-line-point': 'start-point',
  26568. 'cx': xPixelSized ? x2p(shapeOptions.xanchor) + shapeOptions.x0 : x2p(shapeOptions.x0),
  26569. 'cy': yPixelSized ? y2p(shapeOptions.yanchor) - shapeOptions.y0 : y2p(shapeOptions.y0),
  26570. 'r': circleRadius
  26571. })
  26572. .style(circleStyle)
  26573. .classed('cursor-grab', true);
  26574. g.append('circle')
  26575. .attr({
  26576. 'data-line-point': 'end-point',
  26577. 'cx': xPixelSized ? x2p(shapeOptions.xanchor) + shapeOptions.x1 : x2p(shapeOptions.x1),
  26578. 'cy': yPixelSized ? y2p(shapeOptions.yanchor) - shapeOptions.y1 : y2p(shapeOptions.y1),
  26579. 'r': circleRadius
  26580. })
  26581. .style(circleStyle)
  26582. .classed('cursor-grab', true);
  26583. return g;
  26584. }
  26585. function updateDragMode(evt) {
  26586. if(isLine) {
  26587. if(evt.target.tagName === 'path') {
  26588. dragMode = 'move';
  26589. } else {
  26590. dragMode = evt.target.attributes['data-line-point'].value === 'start-point' ?
  26591. 'resize-over-start-point' : 'resize-over-end-point';
  26592. }
  26593. } else {
  26594. // element might not be on screen at time of setup,
  26595. // so obtain bounding box here
  26596. var dragBBox = dragOptions.element.getBoundingClientRect();
  26597. // choose 'move' or 'resize'
  26598. // based on initial position of cursor within the drag element
  26599. var w = dragBBox.right - dragBBox.left,
  26600. h = dragBBox.bottom - dragBBox.top,
  26601. x = evt.clientX - dragBBox.left,
  26602. y = evt.clientY - dragBBox.top,
  26603. cursor = (!isPath && w > MINWIDTH && h > MINHEIGHT && !evt.shiftKey) ?
  26604. dragElement.getCursor(x / w, 1 - y / h) :
  26605. 'move';
  26606. setCursor(shapePath, cursor);
  26607. // possible values 'move', 'sw', 'w', 'se', 'e', 'ne', 'n', 'nw' and 'w'
  26608. dragMode = cursor.split('-')[0];
  26609. }
  26610. }
  26611. function startDrag(evt) {
  26612. // setup update strings and initial values
  26613. if(xPixelSized) {
  26614. xAnchor = x2p(shapeOptions.xanchor);
  26615. }
  26616. if(yPixelSized) {
  26617. yAnchor = y2p(shapeOptions.yanchor);
  26618. }
  26619. if(shapeOptions.type === 'path') {
  26620. pathIn = shapeOptions.path;
  26621. }
  26622. else {
  26623. x0 = xPixelSized ? shapeOptions.x0 : x2p(shapeOptions.x0);
  26624. y0 = yPixelSized ? shapeOptions.y0 : y2p(shapeOptions.y0);
  26625. x1 = xPixelSized ? shapeOptions.x1 : x2p(shapeOptions.x1);
  26626. y1 = yPixelSized ? shapeOptions.y1 : y2p(shapeOptions.y1);
  26627. }
  26628. if(x0 < x1) {
  26629. w0 = x0;
  26630. optW = 'x0';
  26631. e0 = x1;
  26632. optE = 'x1';
  26633. }
  26634. else {
  26635. w0 = x1;
  26636. optW = 'x1';
  26637. e0 = x0;
  26638. optE = 'x0';
  26639. }
  26640. // For fixed size shapes take opposing direction of y-axis into account.
  26641. // Hint: For data sized shapes this is done by the y2p function.
  26642. if((!yPixelSized && y0 < y1) || (yPixelSized && y0 > y1)) {
  26643. n0 = y0;
  26644. optN = 'y0';
  26645. s0 = y1;
  26646. optS = 'y1';
  26647. }
  26648. else {
  26649. n0 = y1;
  26650. optN = 'y1';
  26651. s0 = y0;
  26652. optS = 'y0';
  26653. }
  26654. // setup dragMode and the corresponding handler
  26655. updateDragMode(evt);
  26656. renderVisualCues(shapeLayer, shapeOptions);
  26657. deactivateClipPathTemporarily(shapePath, shapeOptions, gd);
  26658. dragOptions.moveFn = (dragMode === 'move') ? moveShape : resizeShape;
  26659. }
  26660. function endDrag() {
  26661. setCursor(shapePath);
  26662. removeVisualCues(shapeLayer);
  26663. // Don't rely on clipPath being activated during re-layout
  26664. setClipPath(shapePath, gd, shapeOptions);
  26665. Registry.call('relayout', gd, editHelpers.getUpdateObj());
  26666. }
  26667. function abortDrag() {
  26668. removeVisualCues(shapeLayer);
  26669. }
  26670. function moveShape(dx, dy) {
  26671. if(shapeOptions.type === 'path') {
  26672. var noOp = function(coord) { return coord; },
  26673. moveX = noOp,
  26674. moveY = noOp;
  26675. if(xPixelSized) {
  26676. modifyItem('xanchor', shapeOptions.xanchor = p2x(xAnchor + dx));
  26677. } else {
  26678. moveX = function moveX(x) { return p2x(x2p(x) + dx); };
  26679. if(xa && xa.type === 'date') moveX = helpers.encodeDate(moveX);
  26680. }
  26681. if(yPixelSized) {
  26682. modifyItem('yanchor', shapeOptions.yanchor = p2y(yAnchor + dy));
  26683. } else {
  26684. moveY = function moveY(y) { return p2y(y2p(y) + dy); };
  26685. if(ya && ya.type === 'date') moveY = helpers.encodeDate(moveY);
  26686. }
  26687. modifyItem('path', shapeOptions.path = movePath(pathIn, moveX, moveY));
  26688. }
  26689. else {
  26690. if(xPixelSized) {
  26691. modifyItem('xanchor', shapeOptions.xanchor = p2x(xAnchor + dx));
  26692. } else {
  26693. modifyItem('x0', shapeOptions.x0 = p2x(x0 + dx));
  26694. modifyItem('x1', shapeOptions.x1 = p2x(x1 + dx));
  26695. }
  26696. if(yPixelSized) {
  26697. modifyItem('yanchor', shapeOptions.yanchor = p2y(yAnchor + dy));
  26698. } else {
  26699. modifyItem('y0', shapeOptions.y0 = p2y(y0 + dy));
  26700. modifyItem('y1', shapeOptions.y1 = p2y(y1 + dy));
  26701. }
  26702. }
  26703. shapePath.attr('d', getPathString(gd, shapeOptions));
  26704. renderVisualCues(shapeLayer, shapeOptions);
  26705. }
  26706. function resizeShape(dx, dy) {
  26707. if(isPath) {
  26708. // TODO: implement path resize, don't forget to update dragMode code
  26709. var noOp = function(coord) { return coord; },
  26710. moveX = noOp,
  26711. moveY = noOp;
  26712. if(xPixelSized) {
  26713. modifyItem('xanchor', shapeOptions.xanchor = p2x(xAnchor + dx));
  26714. } else {
  26715. moveX = function moveX(x) { return p2x(x2p(x) + dx); };
  26716. if(xa && xa.type === 'date') moveX = helpers.encodeDate(moveX);
  26717. }
  26718. if(yPixelSized) {
  26719. modifyItem('yanchor', shapeOptions.yanchor = p2y(yAnchor + dy));
  26720. } else {
  26721. moveY = function moveY(y) { return p2y(y2p(y) + dy); };
  26722. if(ya && ya.type === 'date') moveY = helpers.encodeDate(moveY);
  26723. }
  26724. modifyItem('path', shapeOptions.path = movePath(pathIn, moveX, moveY));
  26725. }
  26726. else if(isLine) {
  26727. if(dragMode === 'resize-over-start-point') {
  26728. var newX0 = x0 + dx;
  26729. var newY0 = yPixelSized ? y0 - dy : y0 + dy;
  26730. modifyItem('x0', shapeOptions.x0 = xPixelSized ? newX0 : p2x(newX0));
  26731. modifyItem('y0', shapeOptions.y0 = yPixelSized ? newY0 : p2y(newY0));
  26732. } else if(dragMode === 'resize-over-end-point') {
  26733. var newX1 = x1 + dx;
  26734. var newY1 = yPixelSized ? y1 - dy : y1 + dy;
  26735. modifyItem('x1', shapeOptions.x1 = xPixelSized ? newX1 : p2x(newX1));
  26736. modifyItem('y1', shapeOptions.y1 = yPixelSized ? newY1 : p2y(newY1));
  26737. }
  26738. }
  26739. else {
  26740. var newN = (~dragMode.indexOf('n')) ? n0 + dy : n0,
  26741. newS = (~dragMode.indexOf('s')) ? s0 + dy : s0,
  26742. newW = (~dragMode.indexOf('w')) ? w0 + dx : w0,
  26743. newE = (~dragMode.indexOf('e')) ? e0 + dx : e0;
  26744. // Do things in opposing direction for y-axis.
  26745. // Hint: for data-sized shapes the reversal of axis direction is done in p2y.
  26746. if(~dragMode.indexOf('n') && yPixelSized) newN = n0 - dy;
  26747. if(~dragMode.indexOf('s') && yPixelSized) newS = s0 - dy;
  26748. // Update shape eventually. Again, be aware of the
  26749. // opposing direction of the y-axis of fixed size shapes.
  26750. if((!yPixelSized && newS - newN > MINHEIGHT) ||
  26751. (yPixelSized && newN - newS > MINHEIGHT)) {
  26752. modifyItem(optN, shapeOptions[optN] = yPixelSized ? newN : p2y(newN));
  26753. modifyItem(optS, shapeOptions[optS] = yPixelSized ? newS : p2y(newS));
  26754. }
  26755. if(newE - newW > MINWIDTH) {
  26756. modifyItem(optW, shapeOptions[optW] = xPixelSized ? newW : p2x(newW));
  26757. modifyItem(optE, shapeOptions[optE] = xPixelSized ? newE : p2x(newE));
  26758. }
  26759. }
  26760. shapePath.attr('d', getPathString(gd, shapeOptions));
  26761. renderVisualCues(shapeLayer, shapeOptions);
  26762. }
  26763. function renderVisualCues(shapeLayer, shapeOptions) {
  26764. if(xPixelSized || yPixelSized) {
  26765. renderAnchor();
  26766. }
  26767. function renderAnchor() {
  26768. var isNotPath = shapeOptions.type !== 'path';
  26769. // d3 join with dummy data to satisfy d3 data-binding
  26770. var visualCues = shapeLayer.selectAll('.visual-cue').data([0]);
  26771. // Enter
  26772. var strokeWidth = 1;
  26773. visualCues.enter()
  26774. .append('path')
  26775. .attr({
  26776. 'fill': '#fff',
  26777. 'fill-rule': 'evenodd',
  26778. 'stroke': '#000',
  26779. 'stroke-width': strokeWidth
  26780. })
  26781. .classed('visual-cue', true);
  26782. // Update
  26783. var posX = x2p(
  26784. xPixelSized ?
  26785. shapeOptions.xanchor :
  26786. Lib.midRange(
  26787. isNotPath ?
  26788. [shapeOptions.x0, shapeOptions.x1] :
  26789. helpers.extractPathCoords(shapeOptions.path, constants.paramIsX))
  26790. );
  26791. var posY = y2p(
  26792. yPixelSized ?
  26793. shapeOptions.yanchor :
  26794. Lib.midRange(
  26795. isNotPath ?
  26796. [shapeOptions.y0, shapeOptions.y1] :
  26797. helpers.extractPathCoords(shapeOptions.path, constants.paramIsY))
  26798. );
  26799. posX = helpers.roundPositionForSharpStrokeRendering(posX, strokeWidth);
  26800. posY = helpers.roundPositionForSharpStrokeRendering(posY, strokeWidth);
  26801. if(xPixelSized && yPixelSized) {
  26802. var crossPath = 'M' + (posX - 1 - strokeWidth) + ',' + (posY - 1 - strokeWidth) +
  26803. 'h-8v2h8 v8h2v-8 h8v-2h-8 v-8h-2 Z';
  26804. visualCues.attr('d', crossPath);
  26805. } else if(xPixelSized) {
  26806. var vBarPath = 'M' + (posX - 1 - strokeWidth) + ',' + (posY - 9 - strokeWidth) +
  26807. 'v18 h2 v-18 Z';
  26808. visualCues.attr('d', vBarPath);
  26809. } else {
  26810. var hBarPath = 'M' + (posX - 9 - strokeWidth) + ',' + (posY - 1 - strokeWidth) +
  26811. 'h18 v2 h-18 Z';
  26812. visualCues.attr('d', hBarPath);
  26813. }
  26814. }
  26815. }
  26816. function removeVisualCues(shapeLayer) {
  26817. shapeLayer.selectAll('.visual-cue').remove();
  26818. }
  26819. function deactivateClipPathTemporarily(shapePath, shapeOptions, gd) {
  26820. var xref = shapeOptions.xref,
  26821. yref = shapeOptions.yref,
  26822. xa = Axes.getFromId(gd, xref),
  26823. ya = Axes.getFromId(gd, yref);
  26824. var clipAxes = '';
  26825. if(xref !== 'paper' && !xa.autorange) clipAxes += xref;
  26826. if(yref !== 'paper' && !ya.autorange) clipAxes += yref;
  26827. shapePath.call(Drawing.setClipUrl, clipAxes ?
  26828. 'clip' + gd._fullLayout._uid + clipAxes :
  26829. null
  26830. );
  26831. }
  26832. }
  26833. function getPathString(gd, options) {
  26834. var type = options.type,
  26835. xa = Axes.getFromId(gd, options.xref),
  26836. ya = Axes.getFromId(gd, options.yref),
  26837. gs = gd._fullLayout._size,
  26838. x2r, x2p, y2r, y2p,
  26839. x0, x1, y0, y1;
  26840. if(xa) {
  26841. x2r = helpers.shapePositionToRange(xa);
  26842. x2p = function(v) { return xa._offset + xa.r2p(x2r(v, true)); };
  26843. }
  26844. else {
  26845. x2p = function(v) { return gs.l + gs.w * v; };
  26846. }
  26847. if(ya) {
  26848. y2r = helpers.shapePositionToRange(ya);
  26849. y2p = function(v) { return ya._offset + ya.r2p(y2r(v, true)); };
  26850. }
  26851. else {
  26852. y2p = function(v) { return gs.t + gs.h * (1 - v); };
  26853. }
  26854. if(type === 'path') {
  26855. if(xa && xa.type === 'date') x2p = helpers.decodeDate(x2p);
  26856. if(ya && ya.type === 'date') y2p = helpers.decodeDate(y2p);
  26857. return convertPath(options, x2p, y2p);
  26858. }
  26859. if(options.xsizemode === 'pixel') {
  26860. var xAnchorPos = x2p(options.xanchor);
  26861. x0 = xAnchorPos + options.x0;
  26862. x1 = xAnchorPos + options.x1;
  26863. }
  26864. else {
  26865. x0 = x2p(options.x0);
  26866. x1 = x2p(options.x1);
  26867. }
  26868. if(options.ysizemode === 'pixel') {
  26869. var yAnchorPos = y2p(options.yanchor);
  26870. y0 = yAnchorPos - options.y0;
  26871. y1 = yAnchorPos - options.y1;
  26872. }
  26873. else {
  26874. y0 = y2p(options.y0);
  26875. y1 = y2p(options.y1);
  26876. }
  26877. if(type === 'line') return 'M' + x0 + ',' + y0 + 'L' + x1 + ',' + y1;
  26878. if(type === 'rect') return 'M' + x0 + ',' + y0 + 'H' + x1 + 'V' + y1 + 'H' + x0 + 'Z';
  26879. // circle
  26880. var cx = (x0 + x1) / 2,
  26881. cy = (y0 + y1) / 2,
  26882. rx = Math.abs(cx - x0),
  26883. ry = Math.abs(cy - y0),
  26884. rArc = 'A' + rx + ',' + ry,
  26885. rightPt = (cx + rx) + ',' + cy,
  26886. topPt = cx + ',' + (cy - ry);
  26887. return 'M' + rightPt + rArc + ' 0 1,1 ' + topPt +
  26888. rArc + ' 0 0,1 ' + rightPt + 'Z';
  26889. }
  26890. function convertPath(options, x2p, y2p) {
  26891. var pathIn = options.path,
  26892. xSizemode = options.xsizemode,
  26893. ySizemode = options.ysizemode,
  26894. xAnchor = options.xanchor,
  26895. yAnchor = options.yanchor;
  26896. return pathIn.replace(constants.segmentRE, function(segment) {
  26897. var paramNumber = 0,
  26898. segmentType = segment.charAt(0),
  26899. xParams = constants.paramIsX[segmentType],
  26900. yParams = constants.paramIsY[segmentType],
  26901. nParams = constants.numParams[segmentType];
  26902. var paramString = segment.substr(1).replace(constants.paramRE, function(param) {
  26903. if(xParams[paramNumber]) {
  26904. if(xSizemode === 'pixel') param = x2p(xAnchor) + Number(param);
  26905. else param = x2p(param);
  26906. }
  26907. else if(yParams[paramNumber]) {
  26908. if(ySizemode === 'pixel') param = y2p(yAnchor) - Number(param);
  26909. else param = y2p(param);
  26910. }
  26911. paramNumber++;
  26912. if(paramNumber > nParams) param = 'X';
  26913. return param;
  26914. });
  26915. if(paramNumber > nParams) {
  26916. paramString = paramString.replace(/[\s,]*X.*/, '');
  26917. Lib.log('Ignoring extra params in segment ' + segment);
  26918. }
  26919. return segmentType + paramString;
  26920. });
  26921. }
  26922. function movePath(pathIn, moveX, moveY) {
  26923. return pathIn.replace(constants.segmentRE, function(segment) {
  26924. var paramNumber = 0,
  26925. segmentType = segment.charAt(0),
  26926. xParams = constants.paramIsX[segmentType],
  26927. yParams = constants.paramIsY[segmentType],
  26928. nParams = constants.numParams[segmentType];
  26929. var paramString = segment.substr(1).replace(constants.paramRE, function(param) {
  26930. if(paramNumber >= nParams) return param;
  26931. if(xParams[paramNumber]) param = moveX(param);
  26932. else if(yParams[paramNumber]) param = moveY(param);
  26933. paramNumber++;
  26934. return param;
  26935. });
  26936. return segmentType + paramString;
  26937. });
  26938. }
  26939. },{"../../lib":169,"../../lib/setcursor":189,"../../plot_api/plot_template":204,"../../plots/cartesian/axes":214,"../../registry":259,"../color":50,"../dragelement":72,"../drawing":75,"./constants":131,"./helpers":134}],134:[function(_dereq_,module,exports){
  26940. /**
  26941. * Copyright 2012-2018, Plotly, Inc.
  26942. * All rights reserved.
  26943. *
  26944. * This source code is licensed under the MIT license found in the
  26945. * LICENSE file in the root directory of this source tree.
  26946. */
  26947. 'use strict';
  26948. var constants = _dereq_('./constants');
  26949. var Lib = _dereq_('../../lib');
  26950. // special position conversion functions... category axis positions can't be
  26951. // specified by their data values, because they don't make a continuous mapping.
  26952. // so these have to be specified in terms of the category serial numbers,
  26953. // but can take fractional values. Other axis types we specify position based on
  26954. // the actual data values.
  26955. // TODO: in V2.0 (when log axis ranges are in data units) range and shape position
  26956. // will be identical, so rangeToShapePosition and shapePositionToRange can be
  26957. // removed entirely.
  26958. exports.rangeToShapePosition = function(ax) {
  26959. return (ax.type === 'log') ? ax.r2d : function(v) { return v; };
  26960. };
  26961. exports.shapePositionToRange = function(ax) {
  26962. return (ax.type === 'log') ? ax.d2r : function(v) { return v; };
  26963. };
  26964. exports.decodeDate = function(convertToPx) {
  26965. return function(v) {
  26966. if(v.replace) v = v.replace('_', ' ');
  26967. return convertToPx(v);
  26968. };
  26969. };
  26970. exports.encodeDate = function(convertToDate) {
  26971. return function(v) { return convertToDate(v).replace(' ', '_'); };
  26972. };
  26973. exports.extractPathCoords = function(path, paramsToUse) {
  26974. var extractedCoordinates = [];
  26975. var segments = path.match(constants.segmentRE);
  26976. segments.forEach(function(segment) {
  26977. var relevantParamIdx = paramsToUse[segment.charAt(0)].drawn;
  26978. if(relevantParamIdx === undefined) return;
  26979. var params = segment.substr(1).match(constants.paramRE);
  26980. if(!params || params.length < relevantParamIdx) return;
  26981. extractedCoordinates.push(Lib.cleanNumber(params[relevantParamIdx]));
  26982. });
  26983. return extractedCoordinates;
  26984. };
  26985. exports.getDataToPixel = function(gd, axis, isVertical) {
  26986. var gs = gd._fullLayout._size,
  26987. dataToPixel;
  26988. if(axis) {
  26989. var d2r = exports.shapePositionToRange(axis);
  26990. dataToPixel = function(v) {
  26991. return axis._offset + axis.r2p(d2r(v, true));
  26992. };
  26993. if(axis.type === 'date') dataToPixel = exports.decodeDate(dataToPixel);
  26994. }
  26995. else if(isVertical) {
  26996. dataToPixel = function(v) { return gs.t + gs.h * (1 - v); };
  26997. }
  26998. else {
  26999. dataToPixel = function(v) { return gs.l + gs.w * v; };
  27000. }
  27001. return dataToPixel;
  27002. };
  27003. exports.getPixelToData = function(gd, axis, isVertical) {
  27004. var gs = gd._fullLayout._size,
  27005. pixelToData;
  27006. if(axis) {
  27007. var r2d = exports.rangeToShapePosition(axis);
  27008. pixelToData = function(p) { return r2d(axis.p2r(p - axis._offset)); };
  27009. }
  27010. else if(isVertical) {
  27011. pixelToData = function(p) { return 1 - (p - gs.t) / gs.h; };
  27012. }
  27013. else {
  27014. pixelToData = function(p) { return (p - gs.l) / gs.w; };
  27015. }
  27016. return pixelToData;
  27017. };
  27018. /**
  27019. * Based on the given stroke width, rounds the passed
  27020. * position value to represent either a full or half pixel.
  27021. *
  27022. * In case of an odd stroke width (e.g. 1), this measure ensures
  27023. * that a stroke positioned at the returned position isn't rendered
  27024. * blurry due to anti-aliasing.
  27025. *
  27026. * In case of an even stroke width (e.g. 2), this measure ensures
  27027. * that the position value is transformed to a full pixel value
  27028. * so that anti-aliasing doesn't take effect either.
  27029. *
  27030. * @param {number} pos The raw position value to be transformed
  27031. * @param {number} strokeWidth The stroke width
  27032. * @returns {number} either an integer or a .5 decimal number
  27033. */
  27034. exports.roundPositionForSharpStrokeRendering = function(pos, strokeWidth) {
  27035. var strokeWidthIsOdd = Math.round(strokeWidth % 2) === 1;
  27036. var posValAsInt = Math.round(pos);
  27037. return strokeWidthIsOdd ? posValAsInt + 0.5 : posValAsInt;
  27038. };
  27039. },{"../../lib":169,"./constants":131}],135:[function(_dereq_,module,exports){
  27040. /**
  27041. * Copyright 2012-2018, Plotly, Inc.
  27042. * All rights reserved.
  27043. *
  27044. * This source code is licensed under the MIT license found in the
  27045. * LICENSE file in the root directory of this source tree.
  27046. */
  27047. 'use strict';
  27048. var drawModule = _dereq_('./draw');
  27049. module.exports = {
  27050. moduleType: 'component',
  27051. name: 'shapes',
  27052. layoutAttributes: _dereq_('./attributes'),
  27053. supplyLayoutDefaults: _dereq_('./defaults'),
  27054. includeBasePlot: _dereq_('../../plots/cartesian/include_components')('shapes'),
  27055. calcAutorange: _dereq_('./calc_autorange'),
  27056. draw: drawModule.draw,
  27057. drawOne: drawModule.drawOne
  27058. };
  27059. },{"../../plots/cartesian/include_components":224,"./attributes":129,"./calc_autorange":130,"./defaults":132,"./draw":133}],136:[function(_dereq_,module,exports){
  27060. /**
  27061. * Copyright 2012-2018, Plotly, Inc.
  27062. * All rights reserved.
  27063. *
  27064. * This source code is licensed under the MIT license found in the
  27065. * LICENSE file in the root directory of this source tree.
  27066. */
  27067. 'use strict';
  27068. var fontAttrs = _dereq_('../../plots/font_attributes');
  27069. var padAttrs = _dereq_('../../plots/pad_attributes');
  27070. var extendDeepAll = _dereq_('../../lib/extend').extendDeepAll;
  27071. var overrideAll = _dereq_('../../plot_api/edit_types').overrideAll;
  27072. var animationAttrs = _dereq_('../../plots/animation_attributes');
  27073. var templatedArray = _dereq_('../../plot_api/plot_template').templatedArray;
  27074. var constants = _dereq_('./constants');
  27075. var stepsAttrs = templatedArray('step', {
  27076. visible: {
  27077. valType: 'boolean',
  27078. dflt: true,
  27079. },
  27080. method: {
  27081. valType: 'enumerated',
  27082. values: ['restyle', 'relayout', 'animate', 'update', 'skip'],
  27083. dflt: 'restyle',
  27084. },
  27085. args: {
  27086. valType: 'info_array',
  27087. freeLength: true,
  27088. items: [
  27089. { valType: 'any' },
  27090. { valType: 'any' },
  27091. { valType: 'any' }
  27092. ],
  27093. },
  27094. label: {
  27095. valType: 'string',
  27096. },
  27097. value: {
  27098. valType: 'string',
  27099. },
  27100. execute: {
  27101. valType: 'boolean',
  27102. dflt: true,
  27103. }
  27104. });
  27105. module.exports = overrideAll(templatedArray('slider', {
  27106. visible: {
  27107. valType: 'boolean',
  27108. dflt: true,
  27109. },
  27110. active: {
  27111. valType: 'number',
  27112. min: 0,
  27113. dflt: 0,
  27114. },
  27115. steps: stepsAttrs,
  27116. lenmode: {
  27117. valType: 'enumerated',
  27118. values: ['fraction', 'pixels'],
  27119. dflt: 'fraction',
  27120. },
  27121. len: {
  27122. valType: 'number',
  27123. min: 0,
  27124. dflt: 1,
  27125. },
  27126. x: {
  27127. valType: 'number',
  27128. min: -2,
  27129. max: 3,
  27130. dflt: 0,
  27131. },
  27132. pad: extendDeepAll({}, padAttrs, {
  27133. }, {t: {dflt: 20}}),
  27134. xanchor: {
  27135. valType: 'enumerated',
  27136. values: ['auto', 'left', 'center', 'right'],
  27137. dflt: 'left',
  27138. },
  27139. y: {
  27140. valType: 'number',
  27141. min: -2,
  27142. max: 3,
  27143. dflt: 0,
  27144. },
  27145. yanchor: {
  27146. valType: 'enumerated',
  27147. values: ['auto', 'top', 'middle', 'bottom'],
  27148. dflt: 'top',
  27149. },
  27150. transition: {
  27151. duration: {
  27152. valType: 'number',
  27153. min: 0,
  27154. dflt: 150,
  27155. },
  27156. easing: {
  27157. valType: 'enumerated',
  27158. values: animationAttrs.transition.easing.values,
  27159. dflt: 'cubic-in-out',
  27160. }
  27161. },
  27162. currentvalue: {
  27163. visible: {
  27164. valType: 'boolean',
  27165. dflt: true,
  27166. },
  27167. xanchor: {
  27168. valType: 'enumerated',
  27169. values: ['left', 'center', 'right'],
  27170. dflt: 'left',
  27171. },
  27172. offset: {
  27173. valType: 'number',
  27174. dflt: 10,
  27175. },
  27176. prefix: {
  27177. valType: 'string',
  27178. },
  27179. suffix: {
  27180. valType: 'string',
  27181. },
  27182. font: fontAttrs({
  27183. })
  27184. },
  27185. font: fontAttrs({
  27186. }),
  27187. activebgcolor: {
  27188. valType: 'color',
  27189. dflt: constants.gripBgActiveColor,
  27190. },
  27191. bgcolor: {
  27192. valType: 'color',
  27193. dflt: constants.railBgColor,
  27194. },
  27195. bordercolor: {
  27196. valType: 'color',
  27197. dflt: constants.railBorderColor,
  27198. },
  27199. borderwidth: {
  27200. valType: 'number',
  27201. min: 0,
  27202. dflt: constants.railBorderWidth,
  27203. },
  27204. ticklen: {
  27205. valType: 'number',
  27206. min: 0,
  27207. dflt: constants.tickLength,
  27208. },
  27209. tickcolor: {
  27210. valType: 'color',
  27211. dflt: constants.tickColor,
  27212. },
  27213. tickwidth: {
  27214. valType: 'number',
  27215. min: 0,
  27216. dflt: 1,
  27217. },
  27218. minorticklen: {
  27219. valType: 'number',
  27220. min: 0,
  27221. dflt: constants.minorTickLength,
  27222. }
  27223. }), 'arraydraw', 'from-root');
  27224. },{"../../lib/extend":163,"../../plot_api/edit_types":197,"../../plot_api/plot_template":204,"../../plots/animation_attributes":209,"../../plots/font_attributes":240,"../../plots/pad_attributes":245,"./constants":137}],137:[function(_dereq_,module,exports){
  27225. /**
  27226. * Copyright 2012-2018, Plotly, Inc.
  27227. * All rights reserved.
  27228. *
  27229. * This source code is licensed under the MIT license found in the
  27230. * LICENSE file in the root directory of this source tree.
  27231. */
  27232. 'use strict';
  27233. module.exports = {
  27234. // layout attribute name
  27235. name: 'sliders',
  27236. // class names
  27237. containerClassName: 'slider-container',
  27238. groupClassName: 'slider-group',
  27239. inputAreaClass: 'slider-input-area',
  27240. railRectClass: 'slider-rail-rect',
  27241. railTouchRectClass: 'slider-rail-touch-rect',
  27242. gripRectClass: 'slider-grip-rect',
  27243. tickRectClass: 'slider-tick-rect',
  27244. inputProxyClass: 'slider-input-proxy',
  27245. labelsClass: 'slider-labels',
  27246. labelGroupClass: 'slider-label-group',
  27247. labelClass: 'slider-label',
  27248. currentValueClass: 'slider-current-value',
  27249. railHeight: 5,
  27250. // DOM attribute name in button group keeping track
  27251. // of active update menu
  27252. menuIndexAttrName: 'slider-active-index',
  27253. // id root pass to Plots.autoMargin
  27254. autoMarginIdRoot: 'slider-',
  27255. // min item width / height
  27256. minWidth: 30,
  27257. minHeight: 30,
  27258. // padding around item text
  27259. textPadX: 40,
  27260. // arrow offset off right edge
  27261. arrowOffsetX: 4,
  27262. railRadius: 2,
  27263. railWidth: 5,
  27264. railBorder: 4,
  27265. railBorderWidth: 1,
  27266. railBorderColor: '#bec8d9',
  27267. railBgColor: '#f8fafc',
  27268. // The distance of the rail from the edge of the touchable area
  27269. // Slightly less than the step inset because of the curved edges
  27270. // of the rail
  27271. railInset: 8,
  27272. // The distance from the extremal tick marks to the edge of the
  27273. // touchable area. This is basically the same as the grip radius,
  27274. // but for other styles it wouldn't really need to be.
  27275. stepInset: 10,
  27276. gripRadius: 10,
  27277. gripWidth: 20,
  27278. gripHeight: 20,
  27279. gripBorder: 20,
  27280. gripBorderWidth: 1,
  27281. gripBorderColor: '#bec8d9',
  27282. gripBgColor: '#f6f8fa',
  27283. gripBgActiveColor: '#dbdde0',
  27284. labelPadding: 8,
  27285. labelOffset: 0,
  27286. tickWidth: 1,
  27287. tickColor: '#333',
  27288. tickOffset: 25,
  27289. tickLength: 7,
  27290. minorTickOffset: 25,
  27291. minorTickColor: '#333',
  27292. minorTickLength: 4,
  27293. // Extra space below the current value label:
  27294. currentValuePadding: 8,
  27295. currentValueInset: 0,
  27296. };
  27297. },{}],138:[function(_dereq_,module,exports){
  27298. /**
  27299. * Copyright 2012-2018, Plotly, Inc.
  27300. * All rights reserved.
  27301. *
  27302. * This source code is licensed under the MIT license found in the
  27303. * LICENSE file in the root directory of this source tree.
  27304. */
  27305. 'use strict';
  27306. var Lib = _dereq_('../../lib');
  27307. var handleArrayContainerDefaults = _dereq_('../../plots/array_container_defaults');
  27308. var attributes = _dereq_('./attributes');
  27309. var constants = _dereq_('./constants');
  27310. var name = constants.name;
  27311. var stepAttrs = attributes.steps;
  27312. module.exports = function slidersDefaults(layoutIn, layoutOut) {
  27313. handleArrayContainerDefaults(layoutIn, layoutOut, {
  27314. name: name,
  27315. handleItemDefaults: sliderDefaults
  27316. });
  27317. };
  27318. function sliderDefaults(sliderIn, sliderOut, layoutOut) {
  27319. function coerce(attr, dflt) {
  27320. return Lib.coerce(sliderIn, sliderOut, attributes, attr, dflt);
  27321. }
  27322. var steps = handleArrayContainerDefaults(sliderIn, sliderOut, {
  27323. name: 'steps',
  27324. handleItemDefaults: stepDefaults
  27325. });
  27326. var stepCount = 0;
  27327. for(var i = 0; i < steps.length; i++) {
  27328. if(steps[i].visible) stepCount++;
  27329. }
  27330. var visible;
  27331. // If it has fewer than two options, it's not really a slider
  27332. if(stepCount < 2) visible = sliderOut.visible = false;
  27333. else visible = coerce('visible');
  27334. if(!visible) return;
  27335. sliderOut._stepCount = stepCount;
  27336. var visSteps = sliderOut._visibleSteps = Lib.filterVisible(steps);
  27337. var active = coerce('active');
  27338. if(!(steps[active] || {}).visible) sliderOut.active = visSteps[0]._index;
  27339. coerce('x');
  27340. coerce('y');
  27341. Lib.noneOrAll(sliderIn, sliderOut, ['x', 'y']);
  27342. coerce('xanchor');
  27343. coerce('yanchor');
  27344. coerce('len');
  27345. coerce('lenmode');
  27346. coerce('pad.t');
  27347. coerce('pad.r');
  27348. coerce('pad.b');
  27349. coerce('pad.l');
  27350. Lib.coerceFont(coerce, 'font', layoutOut.font);
  27351. var currentValueIsVisible = coerce('currentvalue.visible');
  27352. if(currentValueIsVisible) {
  27353. coerce('currentvalue.xanchor');
  27354. coerce('currentvalue.prefix');
  27355. coerce('currentvalue.suffix');
  27356. coerce('currentvalue.offset');
  27357. Lib.coerceFont(coerce, 'currentvalue.font', sliderOut.font);
  27358. }
  27359. coerce('transition.duration');
  27360. coerce('transition.easing');
  27361. coerce('bgcolor');
  27362. coerce('activebgcolor');
  27363. coerce('bordercolor');
  27364. coerce('borderwidth');
  27365. coerce('ticklen');
  27366. coerce('tickwidth');
  27367. coerce('tickcolor');
  27368. coerce('minorticklen');
  27369. }
  27370. function stepDefaults(valueIn, valueOut) {
  27371. function coerce(attr, dflt) {
  27372. return Lib.coerce(valueIn, valueOut, stepAttrs, attr, dflt);
  27373. }
  27374. var visible;
  27375. if(valueIn.method !== 'skip' && !Array.isArray(valueIn.args)) {
  27376. visible = valueOut.visible = false;
  27377. }
  27378. else visible = coerce('visible');
  27379. if(visible) {
  27380. coerce('method');
  27381. coerce('args');
  27382. var label = coerce('label', 'step-' + valueOut._index);
  27383. coerce('value', label);
  27384. coerce('execute');
  27385. }
  27386. }
  27387. },{"../../lib":169,"../../plots/array_container_defaults":210,"./attributes":136,"./constants":137}],139:[function(_dereq_,module,exports){
  27388. /**
  27389. * Copyright 2012-2018, Plotly, Inc.
  27390. * All rights reserved.
  27391. *
  27392. * This source code is licensed under the MIT license found in the
  27393. * LICENSE file in the root directory of this source tree.
  27394. */
  27395. 'use strict';
  27396. var d3 = _dereq_('d3');
  27397. var Plots = _dereq_('../../plots/plots');
  27398. var Color = _dereq_('../color');
  27399. var Drawing = _dereq_('../drawing');
  27400. var Lib = _dereq_('../../lib');
  27401. var svgTextUtils = _dereq_('../../lib/svg_text_utils');
  27402. var anchorUtils = _dereq_('../legend/anchor_utils');
  27403. var arrayEditor = _dereq_('../../plot_api/plot_template').arrayEditor;
  27404. var constants = _dereq_('./constants');
  27405. var alignmentConstants = _dereq_('../../constants/alignment');
  27406. var LINE_SPACING = alignmentConstants.LINE_SPACING;
  27407. var FROM_TL = alignmentConstants.FROM_TL;
  27408. var FROM_BR = alignmentConstants.FROM_BR;
  27409. module.exports = function draw(gd) {
  27410. var fullLayout = gd._fullLayout,
  27411. sliderData = makeSliderData(fullLayout, gd);
  27412. // draw a container for *all* sliders:
  27413. var sliders = fullLayout._infolayer
  27414. .selectAll('g.' + constants.containerClassName)
  27415. .data(sliderData.length > 0 ? [0] : []);
  27416. sliders.enter().append('g')
  27417. .classed(constants.containerClassName, true)
  27418. .style('cursor', 'ew-resize');
  27419. function clearSlider(sliderOpts) {
  27420. if(sliderOpts._commandObserver) {
  27421. sliderOpts._commandObserver.remove();
  27422. delete sliderOpts._commandObserver;
  27423. }
  27424. // Most components don't need to explicitly remove autoMargin, because
  27425. // marginPushers does this - but slider updates don't go through
  27426. // a full replot so we need to explicitly remove it.
  27427. Plots.autoMargin(gd, autoMarginId(sliderOpts));
  27428. }
  27429. sliders.exit().each(function() {
  27430. d3.select(this).selectAll('g.' + constants.groupClassName)
  27431. .each(clearSlider);
  27432. })
  27433. .remove();
  27434. // Return early if no menus visible:
  27435. if(sliderData.length === 0) return;
  27436. var sliderGroups = sliders.selectAll('g.' + constants.groupClassName)
  27437. .data(sliderData, keyFunction);
  27438. sliderGroups.enter().append('g')
  27439. .classed(constants.groupClassName, true);
  27440. sliderGroups.exit()
  27441. .each(clearSlider)
  27442. .remove();
  27443. // Find the dimensions of the sliders:
  27444. for(var i = 0; i < sliderData.length; i++) {
  27445. var sliderOpts = sliderData[i];
  27446. findDimensions(gd, sliderOpts);
  27447. }
  27448. sliderGroups.each(function(sliderOpts) {
  27449. var gSlider = d3.select(this);
  27450. computeLabelSteps(sliderOpts);
  27451. Plots.manageCommandObserver(gd, sliderOpts, sliderOpts._visibleSteps, function(data) {
  27452. // NB: Same as below. This is *not* always the same as sliderOpts since
  27453. // if a new set of steps comes in, the reference in this callback would
  27454. // be invalid. We need to refetch it from the slider group, which is
  27455. // the join data that creates this slider. So if this slider still exists,
  27456. // the group should be valid, *to the best of my knowledge.* If not,
  27457. // we'd have to look it up by d3 data join index/key.
  27458. var opts = gSlider.data()[0];
  27459. if(opts.active === data.index) return;
  27460. if(opts._dragging) return;
  27461. setActive(gd, gSlider, opts, data.index, false, true);
  27462. });
  27463. drawSlider(gd, d3.select(this), sliderOpts);
  27464. });
  27465. };
  27466. function autoMarginId(sliderOpts) {
  27467. return constants.autoMarginIdRoot + sliderOpts._index;
  27468. }
  27469. // This really only just filters by visibility:
  27470. function makeSliderData(fullLayout, gd) {
  27471. var contOpts = fullLayout[constants.name],
  27472. sliderData = [];
  27473. for(var i = 0; i < contOpts.length; i++) {
  27474. var item = contOpts[i];
  27475. if(!item.visible) continue;
  27476. item._gd = gd;
  27477. sliderData.push(item);
  27478. }
  27479. return sliderData;
  27480. }
  27481. // This is set in the defaults step:
  27482. function keyFunction(opts) {
  27483. return opts._index;
  27484. }
  27485. // Compute the dimensions (mutates sliderOpts):
  27486. function findDimensions(gd, sliderOpts) {
  27487. var sliderLabels = Drawing.tester.selectAll('g.' + constants.labelGroupClass)
  27488. .data(sliderOpts._visibleSteps);
  27489. sliderLabels.enter().append('g')
  27490. .classed(constants.labelGroupClass, true);
  27491. // loop over fake buttons to find width / height
  27492. var maxLabelWidth = 0;
  27493. var labelHeight = 0;
  27494. sliderLabels.each(function(stepOpts) {
  27495. var labelGroup = d3.select(this);
  27496. var text = drawLabel(labelGroup, {step: stepOpts}, sliderOpts);
  27497. var textNode = text.node();
  27498. if(textNode) {
  27499. var bBox = Drawing.bBox(textNode);
  27500. labelHeight = Math.max(labelHeight, bBox.height);
  27501. maxLabelWidth = Math.max(maxLabelWidth, bBox.width);
  27502. }
  27503. });
  27504. sliderLabels.remove();
  27505. var dims = sliderOpts._dims = {};
  27506. dims.inputAreaWidth = Math.max(
  27507. constants.railWidth,
  27508. constants.gripHeight
  27509. );
  27510. // calculate some overall dimensions - some of these are needed for
  27511. // calculating the currentValue dimensions
  27512. var graphSize = gd._fullLayout._size;
  27513. dims.lx = graphSize.l + graphSize.w * sliderOpts.x;
  27514. dims.ly = graphSize.t + graphSize.h * (1 - sliderOpts.y);
  27515. if(sliderOpts.lenmode === 'fraction') {
  27516. // fraction:
  27517. dims.outerLength = Math.round(graphSize.w * sliderOpts.len);
  27518. } else {
  27519. // pixels:
  27520. dims.outerLength = sliderOpts.len;
  27521. }
  27522. // The length of the rail, *excluding* padding on either end:
  27523. dims.inputAreaStart = 0;
  27524. dims.inputAreaLength = Math.round(dims.outerLength - sliderOpts.pad.l - sliderOpts.pad.r);
  27525. var textableInputLength = dims.inputAreaLength - 2 * constants.stepInset;
  27526. var availableSpacePerLabel = textableInputLength / (sliderOpts._stepCount - 1);
  27527. var computedSpacePerLabel = maxLabelWidth + constants.labelPadding;
  27528. dims.labelStride = Math.max(1, Math.ceil(computedSpacePerLabel / availableSpacePerLabel));
  27529. dims.labelHeight = labelHeight;
  27530. // loop over all possible values for currentValue to find the
  27531. // area we need for it
  27532. dims.currentValueMaxWidth = 0;
  27533. dims.currentValueHeight = 0;
  27534. dims.currentValueTotalHeight = 0;
  27535. dims.currentValueMaxLines = 1;
  27536. if(sliderOpts.currentvalue.visible) {
  27537. // Get the dimensions of the current value label:
  27538. var dummyGroup = Drawing.tester.append('g');
  27539. sliderLabels.each(function(stepOpts) {
  27540. var curValPrefix = drawCurrentValue(dummyGroup, sliderOpts, stepOpts.label);
  27541. var curValSize = (curValPrefix.node() && Drawing.bBox(curValPrefix.node())) || {width: 0, height: 0};
  27542. var lines = svgTextUtils.lineCount(curValPrefix);
  27543. dims.currentValueMaxWidth = Math.max(dims.currentValueMaxWidth, Math.ceil(curValSize.width));
  27544. dims.currentValueHeight = Math.max(dims.currentValueHeight, Math.ceil(curValSize.height));
  27545. dims.currentValueMaxLines = Math.max(dims.currentValueMaxLines, lines);
  27546. });
  27547. dims.currentValueTotalHeight = dims.currentValueHeight + sliderOpts.currentvalue.offset;
  27548. dummyGroup.remove();
  27549. }
  27550. dims.height = dims.currentValueTotalHeight + constants.tickOffset + sliderOpts.ticklen + constants.labelOffset + dims.labelHeight + sliderOpts.pad.t + sliderOpts.pad.b;
  27551. var xanchor = 'left';
  27552. if(anchorUtils.isRightAnchor(sliderOpts)) {
  27553. dims.lx -= dims.outerLength;
  27554. xanchor = 'right';
  27555. }
  27556. if(anchorUtils.isCenterAnchor(sliderOpts)) {
  27557. dims.lx -= dims.outerLength / 2;
  27558. xanchor = 'center';
  27559. }
  27560. var yanchor = 'top';
  27561. if(anchorUtils.isBottomAnchor(sliderOpts)) {
  27562. dims.ly -= dims.height;
  27563. yanchor = 'bottom';
  27564. }
  27565. if(anchorUtils.isMiddleAnchor(sliderOpts)) {
  27566. dims.ly -= dims.height / 2;
  27567. yanchor = 'middle';
  27568. }
  27569. dims.outerLength = Math.ceil(dims.outerLength);
  27570. dims.height = Math.ceil(dims.height);
  27571. dims.lx = Math.round(dims.lx);
  27572. dims.ly = Math.round(dims.ly);
  27573. var marginOpts = {
  27574. y: sliderOpts.y,
  27575. b: dims.height * FROM_BR[yanchor],
  27576. t: dims.height * FROM_TL[yanchor]
  27577. };
  27578. if(sliderOpts.lenmode === 'fraction') {
  27579. marginOpts.l = 0;
  27580. marginOpts.xl = sliderOpts.x - sliderOpts.len * FROM_TL[xanchor];
  27581. marginOpts.r = 0;
  27582. marginOpts.xr = sliderOpts.x + sliderOpts.len * FROM_BR[xanchor];
  27583. }
  27584. else {
  27585. marginOpts.x = sliderOpts.x;
  27586. marginOpts.l = dims.outerLength * FROM_TL[xanchor];
  27587. marginOpts.r = dims.outerLength * FROM_BR[xanchor];
  27588. }
  27589. Plots.autoMargin(gd, autoMarginId(sliderOpts), marginOpts);
  27590. }
  27591. function drawSlider(gd, sliderGroup, sliderOpts) {
  27592. // This is related to the other long notes in this file regarding what happens
  27593. // when slider steps disappear. This particular fix handles what happens when
  27594. // the *current* slider step is removed. The drawing functions will error out
  27595. // when they fail to find it, so the fix for now is that it will just draw the
  27596. // slider in the first position but will not execute the command.
  27597. if(!((sliderOpts.steps[sliderOpts.active] || {}).visible)) {
  27598. sliderOpts.active = sliderOpts._visibleSteps[0]._index;
  27599. }
  27600. // These are carefully ordered for proper z-ordering:
  27601. sliderGroup
  27602. .call(drawCurrentValue, sliderOpts)
  27603. .call(drawRail, sliderOpts)
  27604. .call(drawLabelGroup, sliderOpts)
  27605. .call(drawTicks, sliderOpts)
  27606. .call(drawTouchRect, gd, sliderOpts)
  27607. .call(drawGrip, gd, sliderOpts);
  27608. var dims = sliderOpts._dims;
  27609. // Position the rectangle:
  27610. Drawing.setTranslate(sliderGroup, dims.lx + sliderOpts.pad.l, dims.ly + sliderOpts.pad.t);
  27611. sliderGroup.call(setGripPosition, sliderOpts, false);
  27612. sliderGroup.call(drawCurrentValue, sliderOpts);
  27613. }
  27614. function drawCurrentValue(sliderGroup, sliderOpts, valueOverride) {
  27615. if(!sliderOpts.currentvalue.visible) return;
  27616. var dims = sliderOpts._dims;
  27617. var x0, textAnchor;
  27618. switch(sliderOpts.currentvalue.xanchor) {
  27619. case 'right':
  27620. // This is anchored left and adjusted by the width of the longest label
  27621. // so that the prefix doesn't move. The goal of this is to emphasize
  27622. // what's actually changing and make the update less distracting.
  27623. x0 = dims.inputAreaLength - constants.currentValueInset - dims.currentValueMaxWidth;
  27624. textAnchor = 'left';
  27625. break;
  27626. case 'center':
  27627. x0 = dims.inputAreaLength * 0.5;
  27628. textAnchor = 'middle';
  27629. break;
  27630. default:
  27631. x0 = constants.currentValueInset;
  27632. textAnchor = 'left';
  27633. }
  27634. var text = Lib.ensureSingle(sliderGroup, 'text', constants.labelClass, function(s) {
  27635. s.classed('user-select-none', true)
  27636. .attr({
  27637. 'text-anchor': textAnchor,
  27638. 'data-notex': 1
  27639. });
  27640. });
  27641. var str = sliderOpts.currentvalue.prefix ? sliderOpts.currentvalue.prefix : '';
  27642. if(typeof valueOverride === 'string') {
  27643. str += valueOverride;
  27644. } else {
  27645. var curVal = sliderOpts.steps[sliderOpts.active].label;
  27646. str += curVal;
  27647. }
  27648. if(sliderOpts.currentvalue.suffix) {
  27649. str += sliderOpts.currentvalue.suffix;
  27650. }
  27651. text.call(Drawing.font, sliderOpts.currentvalue.font)
  27652. .text(str)
  27653. .call(svgTextUtils.convertToTspans, sliderOpts._gd);
  27654. var lines = svgTextUtils.lineCount(text);
  27655. var y0 = (dims.currentValueMaxLines + 1 - lines) *
  27656. sliderOpts.currentvalue.font.size * LINE_SPACING;
  27657. svgTextUtils.positionText(text, x0, y0);
  27658. return text;
  27659. }
  27660. function drawGrip(sliderGroup, gd, sliderOpts) {
  27661. var grip = Lib.ensureSingle(sliderGroup, 'rect', constants.gripRectClass, function(s) {
  27662. s.call(attachGripEvents, gd, sliderGroup, sliderOpts)
  27663. .style('pointer-events', 'all');
  27664. });
  27665. grip.attr({
  27666. width: constants.gripWidth,
  27667. height: constants.gripHeight,
  27668. rx: constants.gripRadius,
  27669. ry: constants.gripRadius,
  27670. })
  27671. .call(Color.stroke, sliderOpts.bordercolor)
  27672. .call(Color.fill, sliderOpts.bgcolor)
  27673. .style('stroke-width', sliderOpts.borderwidth + 'px');
  27674. }
  27675. function drawLabel(item, data, sliderOpts) {
  27676. var text = Lib.ensureSingle(item, 'text', constants.labelClass, function(s) {
  27677. s.classed('user-select-none', true)
  27678. .attr({
  27679. 'text-anchor': 'middle',
  27680. 'data-notex': 1
  27681. });
  27682. });
  27683. text.call(Drawing.font, sliderOpts.font)
  27684. .text(data.step.label)
  27685. .call(svgTextUtils.convertToTspans, sliderOpts._gd);
  27686. return text;
  27687. }
  27688. function drawLabelGroup(sliderGroup, sliderOpts) {
  27689. var labels = Lib.ensureSingle(sliderGroup, 'g', constants.labelsClass);
  27690. var dims = sliderOpts._dims;
  27691. var labelItems = labels.selectAll('g.' + constants.labelGroupClass)
  27692. .data(dims.labelSteps);
  27693. labelItems.enter().append('g')
  27694. .classed(constants.labelGroupClass, true);
  27695. labelItems.exit().remove();
  27696. labelItems.each(function(d) {
  27697. var item = d3.select(this);
  27698. item.call(drawLabel, d, sliderOpts);
  27699. Drawing.setTranslate(item,
  27700. normalizedValueToPosition(sliderOpts, d.fraction),
  27701. constants.tickOffset +
  27702. sliderOpts.ticklen +
  27703. // position is the baseline of the top line of text only, even
  27704. // if the label spans multiple lines
  27705. sliderOpts.font.size * LINE_SPACING +
  27706. constants.labelOffset +
  27707. dims.currentValueTotalHeight
  27708. );
  27709. });
  27710. }
  27711. function handleInput(gd, sliderGroup, sliderOpts, normalizedPosition, doTransition) {
  27712. var quantizedPosition = Math.round(normalizedPosition * (sliderOpts._stepCount - 1));
  27713. var quantizedIndex = sliderOpts._visibleSteps[quantizedPosition]._index;
  27714. if(quantizedIndex !== sliderOpts.active) {
  27715. setActive(gd, sliderGroup, sliderOpts, quantizedIndex, true, doTransition);
  27716. }
  27717. }
  27718. function setActive(gd, sliderGroup, sliderOpts, index, doCallback, doTransition) {
  27719. var previousActive = sliderOpts.active;
  27720. sliderOpts.active = index;
  27721. // due to templating, it's possible this slider doesn't even exist yet
  27722. arrayEditor(gd.layout, constants.name, sliderOpts)
  27723. .applyUpdate('active', index);
  27724. var step = sliderOpts.steps[sliderOpts.active];
  27725. sliderGroup.call(setGripPosition, sliderOpts, doTransition);
  27726. sliderGroup.call(drawCurrentValue, sliderOpts);
  27727. gd.emit('plotly_sliderchange', {
  27728. slider: sliderOpts,
  27729. step: sliderOpts.steps[sliderOpts.active],
  27730. interaction: doCallback,
  27731. previousActive: previousActive
  27732. });
  27733. if(step && step.method && doCallback) {
  27734. if(sliderGroup._nextMethod) {
  27735. // If we've already queued up an update, just overwrite it with the most recent:
  27736. sliderGroup._nextMethod.step = step;
  27737. sliderGroup._nextMethod.doCallback = doCallback;
  27738. sliderGroup._nextMethod.doTransition = doTransition;
  27739. } else {
  27740. sliderGroup._nextMethod = {step: step, doCallback: doCallback, doTransition: doTransition};
  27741. sliderGroup._nextMethodRaf = window.requestAnimationFrame(function() {
  27742. var _step = sliderGroup._nextMethod.step;
  27743. if(!_step.method) return;
  27744. if(_step.execute) {
  27745. Plots.executeAPICommand(gd, _step.method, _step.args);
  27746. }
  27747. sliderGroup._nextMethod = null;
  27748. sliderGroup._nextMethodRaf = null;
  27749. });
  27750. }
  27751. }
  27752. }
  27753. function attachGripEvents(item, gd, sliderGroup) {
  27754. var node = sliderGroup.node();
  27755. var $gd = d3.select(gd);
  27756. // NB: This is *not* the same as sliderOpts itself! These callbacks
  27757. // are in a closure so this array won't actually be correct if the
  27758. // steps have changed since this was initialized. The sliderGroup,
  27759. // however, has not changed since that *is* the slider, so it must
  27760. // be present to receive mouse events.
  27761. function getSliderOpts() {
  27762. return sliderGroup.data()[0];
  27763. }
  27764. item.on('mousedown', function() {
  27765. var sliderOpts = getSliderOpts();
  27766. gd.emit('plotly_sliderstart', {slider: sliderOpts});
  27767. var grip = sliderGroup.select('.' + constants.gripRectClass);
  27768. d3.event.stopPropagation();
  27769. d3.event.preventDefault();
  27770. grip.call(Color.fill, sliderOpts.activebgcolor);
  27771. var normalizedPosition = positionToNormalizedValue(sliderOpts, d3.mouse(node)[0]);
  27772. handleInput(gd, sliderGroup, sliderOpts, normalizedPosition, true);
  27773. sliderOpts._dragging = true;
  27774. $gd.on('mousemove', function() {
  27775. var sliderOpts = getSliderOpts();
  27776. var normalizedPosition = positionToNormalizedValue(sliderOpts, d3.mouse(node)[0]);
  27777. handleInput(gd, sliderGroup, sliderOpts, normalizedPosition, false);
  27778. });
  27779. $gd.on('mouseup', function() {
  27780. var sliderOpts = getSliderOpts();
  27781. sliderOpts._dragging = false;
  27782. grip.call(Color.fill, sliderOpts.bgcolor);
  27783. $gd.on('mouseup', null);
  27784. $gd.on('mousemove', null);
  27785. gd.emit('plotly_sliderend', {
  27786. slider: sliderOpts,
  27787. step: sliderOpts.steps[sliderOpts.active]
  27788. });
  27789. });
  27790. });
  27791. }
  27792. function drawTicks(sliderGroup, sliderOpts) {
  27793. var tick = sliderGroup.selectAll('rect.' + constants.tickRectClass)
  27794. .data(sliderOpts._visibleSteps);
  27795. var dims = sliderOpts._dims;
  27796. tick.enter().append('rect')
  27797. .classed(constants.tickRectClass, true);
  27798. tick.exit().remove();
  27799. tick.attr({
  27800. width: sliderOpts.tickwidth + 'px',
  27801. 'shape-rendering': 'crispEdges'
  27802. });
  27803. tick.each(function(d, i) {
  27804. var isMajor = i % dims.labelStride === 0;
  27805. var item = d3.select(this);
  27806. item
  27807. .attr({height: isMajor ? sliderOpts.ticklen : sliderOpts.minorticklen})
  27808. .call(Color.fill, isMajor ? sliderOpts.tickcolor : sliderOpts.tickcolor);
  27809. Drawing.setTranslate(item,
  27810. normalizedValueToPosition(sliderOpts, i / (sliderOpts._stepCount - 1)) - 0.5 * sliderOpts.tickwidth,
  27811. (isMajor ? constants.tickOffset : constants.minorTickOffset) + dims.currentValueTotalHeight
  27812. );
  27813. });
  27814. }
  27815. function computeLabelSteps(sliderOpts) {
  27816. var dims = sliderOpts._dims;
  27817. dims.labelSteps = [];
  27818. var nsteps = sliderOpts._stepCount;
  27819. for(var i = 0; i < nsteps; i += dims.labelStride) {
  27820. dims.labelSteps.push({
  27821. fraction: i / (nsteps - 1),
  27822. step: sliderOpts._visibleSteps[i]
  27823. });
  27824. }
  27825. }
  27826. function setGripPosition(sliderGroup, sliderOpts, doTransition) {
  27827. var grip = sliderGroup.select('rect.' + constants.gripRectClass);
  27828. var quantizedIndex = 0;
  27829. for(var i = 0; i < sliderOpts._stepCount; i++) {
  27830. if(sliderOpts._visibleSteps[i]._index === sliderOpts.active) {
  27831. quantizedIndex = i;
  27832. break;
  27833. }
  27834. }
  27835. var x = normalizedValueToPosition(sliderOpts, quantizedIndex / (sliderOpts._stepCount - 1));
  27836. // If this is true, then *this component* is already invoking its own command
  27837. // and has triggered its own animation.
  27838. if(sliderOpts._invokingCommand) return;
  27839. var el = grip;
  27840. if(doTransition && sliderOpts.transition.duration > 0) {
  27841. el = el.transition()
  27842. .duration(sliderOpts.transition.duration)
  27843. .ease(sliderOpts.transition.easing);
  27844. }
  27845. // Drawing.setTranslate doesn't work here becasue of the transition duck-typing.
  27846. // It's also not necessary because there are no other transitions to preserve.
  27847. el.attr('transform', 'translate(' + (x - constants.gripWidth * 0.5) + ',' + (sliderOpts._dims.currentValueTotalHeight) + ')');
  27848. }
  27849. // Convert a number from [0-1] to a pixel position relative to the slider group container:
  27850. function normalizedValueToPosition(sliderOpts, normalizedPosition) {
  27851. var dims = sliderOpts._dims;
  27852. return dims.inputAreaStart + constants.stepInset +
  27853. (dims.inputAreaLength - 2 * constants.stepInset) * Math.min(1, Math.max(0, normalizedPosition));
  27854. }
  27855. // Convert a position relative to the slider group to a nubmer in [0, 1]
  27856. function positionToNormalizedValue(sliderOpts, position) {
  27857. var dims = sliderOpts._dims;
  27858. return Math.min(1, Math.max(0, (position - constants.stepInset - dims.inputAreaStart) / (dims.inputAreaLength - 2 * constants.stepInset - 2 * dims.inputAreaStart)));
  27859. }
  27860. function drawTouchRect(sliderGroup, gd, sliderOpts) {
  27861. var dims = sliderOpts._dims;
  27862. var rect = Lib.ensureSingle(sliderGroup, 'rect', constants.railTouchRectClass, function(s) {
  27863. s.call(attachGripEvents, gd, sliderGroup, sliderOpts)
  27864. .style('pointer-events', 'all');
  27865. });
  27866. rect.attr({
  27867. width: dims.inputAreaLength,
  27868. height: Math.max(dims.inputAreaWidth, constants.tickOffset + sliderOpts.ticklen + dims.labelHeight)
  27869. })
  27870. .call(Color.fill, sliderOpts.bgcolor)
  27871. .attr('opacity', 0);
  27872. Drawing.setTranslate(rect, 0, dims.currentValueTotalHeight);
  27873. }
  27874. function drawRail(sliderGroup, sliderOpts) {
  27875. var dims = sliderOpts._dims;
  27876. var computedLength = dims.inputAreaLength - constants.railInset * 2;
  27877. var rect = Lib.ensureSingle(sliderGroup, 'rect', constants.railRectClass);
  27878. rect.attr({
  27879. width: computedLength,
  27880. height: constants.railWidth,
  27881. rx: constants.railRadius,
  27882. ry: constants.railRadius,
  27883. 'shape-rendering': 'crispEdges'
  27884. })
  27885. .call(Color.stroke, sliderOpts.bordercolor)
  27886. .call(Color.fill, sliderOpts.bgcolor)
  27887. .style('stroke-width', sliderOpts.borderwidth + 'px');
  27888. Drawing.setTranslate(rect,
  27889. constants.railInset,
  27890. (dims.inputAreaWidth - constants.railWidth) * 0.5 + dims.currentValueTotalHeight
  27891. );
  27892. }
  27893. },{"../../constants/alignment":148,"../../lib":169,"../../lib/svg_text_utils":191,"../../plot_api/plot_template":204,"../../plots/plots":246,"../color":50,"../drawing":75,"../legend/anchor_utils":102,"./constants":137,"d3":16}],140:[function(_dereq_,module,exports){
  27894. /**
  27895. * Copyright 2012-2018, Plotly, Inc.
  27896. * All rights reserved.
  27897. *
  27898. * This source code is licensed under the MIT license found in the
  27899. * LICENSE file in the root directory of this source tree.
  27900. */
  27901. 'use strict';
  27902. var constants = _dereq_('./constants');
  27903. module.exports = {
  27904. moduleType: 'component',
  27905. name: constants.name,
  27906. layoutAttributes: _dereq_('./attributes'),
  27907. supplyLayoutDefaults: _dereq_('./defaults'),
  27908. draw: _dereq_('./draw')
  27909. };
  27910. },{"./attributes":136,"./constants":137,"./defaults":138,"./draw":139}],141:[function(_dereq_,module,exports){
  27911. /**
  27912. * Copyright 2012-2018, Plotly, Inc.
  27913. * All rights reserved.
  27914. *
  27915. * This source code is licensed under the MIT license found in the
  27916. * LICENSE file in the root directory of this source tree.
  27917. */
  27918. 'use strict';
  27919. var d3 = _dereq_('d3');
  27920. var isNumeric = _dereq_('fast-isnumeric');
  27921. var Plots = _dereq_('../../plots/plots');
  27922. var Registry = _dereq_('../../registry');
  27923. var Lib = _dereq_('../../lib');
  27924. var Drawing = _dereq_('../drawing');
  27925. var Color = _dereq_('../color');
  27926. var svgTextUtils = _dereq_('../../lib/svg_text_utils');
  27927. var interactConstants = _dereq_('../../constants/interactions');
  27928. module.exports = {
  27929. draw: draw
  27930. };
  27931. var numStripRE = / [XY][0-9]* /;
  27932. /**
  27933. * Titles - (re)draw titles on the axes and plot:
  27934. * @param {DOM element} gd - the graphDiv
  27935. * @param {string} titleClass - the css class of this title
  27936. * @param {object} options - how and what to draw
  27937. * propContainer - the layout object containing `title` and `titlefont`
  27938. * attributes that apply to this title
  27939. * propName - the full name of the title property (for Plotly.relayout)
  27940. * [traceIndex] - include only if this property applies to one trace
  27941. * (such as a colorbar title) - then editing pipes to Plotly.restyle
  27942. * instead of Plotly.relayout
  27943. * placeholder - placeholder text for an empty editable title
  27944. * [avoid] {object} - include if this title should move to avoid other elements
  27945. * selection - d3 selection of elements to avoid
  27946. * side - which direction to move if there is a conflict
  27947. * [offsetLeft] - if these elements are subject to a translation
  27948. * wrt the title element
  27949. * [offsetTop]
  27950. * attributes {object} - position and alignment attributes
  27951. * x - pixels
  27952. * y - pixels
  27953. * text-anchor - start|middle|end
  27954. * transform {object} - how to transform the title after positioning
  27955. * rotate - degrees
  27956. * offset - shift up/down in the rotated frame (unused?)
  27957. * containerGroup - if an svg <g> element already exists to hold this
  27958. * title, include here. Otherwise it will go in fullLayout._infolayer
  27959. *
  27960. * @return {selection} d3 selection of title container group
  27961. */
  27962. function draw(gd, titleClass, options) {
  27963. var cont = options.propContainer;
  27964. var prop = options.propName;
  27965. var placeholder = options.placeholder;
  27966. var traceIndex = options.traceIndex;
  27967. var avoid = options.avoid || {};
  27968. var attributes = options.attributes;
  27969. var transform = options.transform;
  27970. var group = options.containerGroup;
  27971. var fullLayout = gd._fullLayout;
  27972. var titlefont = cont.titlefont || {};
  27973. var font = titlefont.family;
  27974. var fontSize = titlefont.size;
  27975. var fontColor = titlefont.color;
  27976. var opacity = 1;
  27977. var isplaceholder = false;
  27978. var txt = (cont.title || '').trim();
  27979. // only make this title editable if we positively identify its property
  27980. // as one that has editing enabled.
  27981. var editAttr;
  27982. if(prop === 'title') editAttr = 'titleText';
  27983. else if(prop.indexOf('axis') !== -1) editAttr = 'axisTitleText';
  27984. else if(prop.indexOf('colorbar' !== -1)) editAttr = 'colorbarTitleText';
  27985. var editable = gd._context.edits[editAttr];
  27986. if(txt === '') opacity = 0;
  27987. // look for placeholder text while stripping out numbers from eg X2, Y3
  27988. // this is just for backward compatibility with the old version that had
  27989. // "Click to enter X2 title" and may have gotten saved in some old plots,
  27990. // we don't want this to show up when these are displayed.
  27991. else if(txt.replace(numStripRE, ' % ') === placeholder.replace(numStripRE, ' % ')) {
  27992. opacity = 0.2;
  27993. isplaceholder = true;
  27994. if(!editable) txt = '';
  27995. }
  27996. var elShouldExist = txt || editable;
  27997. if(!group) {
  27998. group = Lib.ensureSingle(fullLayout._infolayer, 'g', 'g-' + titleClass);
  27999. }
  28000. var el = group.selectAll('text')
  28001. .data(elShouldExist ? [0] : []);
  28002. el.enter().append('text');
  28003. el.text(txt)
  28004. // this is hacky, but convertToTspans uses the class
  28005. // to determine whether to rotate mathJax...
  28006. // so we need to clear out any old class and put the
  28007. // correct one (only relevant for colorbars, at least
  28008. // for now) - ie don't use .classed
  28009. .attr('class', titleClass);
  28010. el.exit().remove();
  28011. if(!elShouldExist) return group;
  28012. function titleLayout(titleEl) {
  28013. Lib.syncOrAsync([drawTitle, scootTitle], titleEl);
  28014. }
  28015. function drawTitle(titleEl) {
  28016. var transformVal;
  28017. if(transform) {
  28018. transformVal = '';
  28019. if(transform.rotate) {
  28020. transformVal += 'rotate(' + [transform.rotate, attributes.x, attributes.y] + ')';
  28021. }
  28022. if(transform.offset) {
  28023. transformVal += 'translate(0, ' + transform.offset + ')';
  28024. }
  28025. } else {
  28026. transformVal = null;
  28027. }
  28028. titleEl.attr('transform', transformVal);
  28029. titleEl.style({
  28030. 'font-family': font,
  28031. 'font-size': d3.round(fontSize, 2) + 'px',
  28032. fill: Color.rgb(fontColor),
  28033. opacity: opacity * Color.opacity(fontColor),
  28034. 'font-weight': Plots.fontWeight
  28035. })
  28036. .attr(attributes)
  28037. .call(svgTextUtils.convertToTspans, gd);
  28038. return Plots.previousPromises(gd);
  28039. }
  28040. function scootTitle(titleElIn) {
  28041. var titleGroup = d3.select(titleElIn.node().parentNode);
  28042. if(avoid && avoid.selection && avoid.side && txt) {
  28043. titleGroup.attr('transform', null);
  28044. // move toward avoid.side (= left, right, top, bottom) if needed
  28045. // can include pad (pixels, default 2)
  28046. var shift = 0;
  28047. var backside = {
  28048. left: 'right',
  28049. right: 'left',
  28050. top: 'bottom',
  28051. bottom: 'top'
  28052. }[avoid.side];
  28053. var shiftSign = (['left', 'top'].indexOf(avoid.side) !== -1) ?
  28054. -1 : 1;
  28055. var pad = isNumeric(avoid.pad) ? avoid.pad : 2;
  28056. var titlebb = Drawing.bBox(titleGroup.node());
  28057. var paperbb = {
  28058. left: 0,
  28059. top: 0,
  28060. right: fullLayout.width,
  28061. bottom: fullLayout.height
  28062. };
  28063. var maxshift = avoid.maxShift || (
  28064. (paperbb[avoid.side] - titlebb[avoid.side]) *
  28065. ((avoid.side === 'left' || avoid.side === 'top') ? -1 : 1));
  28066. // Prevent the title going off the paper
  28067. if(maxshift < 0) shift = maxshift;
  28068. else {
  28069. // so we don't have to offset each avoided element,
  28070. // give the title the opposite offset
  28071. var offsetLeft = avoid.offsetLeft || 0;
  28072. var offsetTop = avoid.offsetTop || 0;
  28073. titlebb.left -= offsetLeft;
  28074. titlebb.right -= offsetLeft;
  28075. titlebb.top -= offsetTop;
  28076. titlebb.bottom -= offsetTop;
  28077. // iterate over a set of elements (avoid.selection)
  28078. // to avoid collisions with
  28079. avoid.selection.each(function() {
  28080. var avoidbb = Drawing.bBox(this);
  28081. if(Lib.bBoxIntersect(titlebb, avoidbb, pad)) {
  28082. shift = Math.max(shift, shiftSign * (
  28083. avoidbb[avoid.side] - titlebb[backside]) + pad);
  28084. }
  28085. });
  28086. shift = Math.min(maxshift, shift);
  28087. }
  28088. if(shift > 0 || maxshift < 0) {
  28089. var shiftTemplate = {
  28090. left: [-shift, 0],
  28091. right: [shift, 0],
  28092. top: [0, -shift],
  28093. bottom: [0, shift]
  28094. }[avoid.side];
  28095. titleGroup.attr('transform',
  28096. 'translate(' + shiftTemplate + ')');
  28097. }
  28098. }
  28099. }
  28100. el.call(titleLayout);
  28101. function setPlaceholder() {
  28102. opacity = 0;
  28103. isplaceholder = true;
  28104. el.text(placeholder)
  28105. .on('mouseover.opacity', function() {
  28106. d3.select(this).transition()
  28107. .duration(interactConstants.SHOW_PLACEHOLDER).style('opacity', 1);
  28108. })
  28109. .on('mouseout.opacity', function() {
  28110. d3.select(this).transition()
  28111. .duration(interactConstants.HIDE_PLACEHOLDER).style('opacity', 0);
  28112. });
  28113. }
  28114. if(editable) {
  28115. if(!txt) setPlaceholder();
  28116. else el.on('.opacity', null);
  28117. el.call(svgTextUtils.makeEditable, {gd: gd})
  28118. .on('edit', function(text) {
  28119. if(traceIndex !== undefined) {
  28120. Registry.call('restyle', gd, prop, text, traceIndex);
  28121. } else {
  28122. Registry.call('relayout', gd, prop, text);
  28123. }
  28124. })
  28125. .on('cancel', function() {
  28126. this.text(this.attr('data-unformatted'))
  28127. .call(titleLayout);
  28128. })
  28129. .on('input', function(d) {
  28130. this.text(d || ' ')
  28131. .call(svgTextUtils.positionText, attributes.x, attributes.y);
  28132. });
  28133. }
  28134. el.classed('js-placeholder', isplaceholder);
  28135. return group;
  28136. }
  28137. },{"../../constants/interactions":150,"../../lib":169,"../../lib/svg_text_utils":191,"../../plots/plots":246,"../../registry":259,"../color":50,"../drawing":75,"d3":16,"fast-isnumeric":18}],142:[function(_dereq_,module,exports){
  28138. /**
  28139. * Copyright 2012-2018, Plotly, Inc.
  28140. * All rights reserved.
  28141. *
  28142. * This source code is licensed under the MIT license found in the
  28143. * LICENSE file in the root directory of this source tree.
  28144. */
  28145. 'use strict';
  28146. var fontAttrs = _dereq_('../../plots/font_attributes');
  28147. var colorAttrs = _dereq_('../color/attributes');
  28148. var extendFlat = _dereq_('../../lib/extend').extendFlat;
  28149. var overrideAll = _dereq_('../../plot_api/edit_types').overrideAll;
  28150. var padAttrs = _dereq_('../../plots/pad_attributes');
  28151. var templatedArray = _dereq_('../../plot_api/plot_template').templatedArray;
  28152. var buttonsAttrs = templatedArray('button', {
  28153. visible: {
  28154. valType: 'boolean',
  28155. },
  28156. method: {
  28157. valType: 'enumerated',
  28158. values: ['restyle', 'relayout', 'animate', 'update', 'skip'],
  28159. dflt: 'restyle',
  28160. },
  28161. args: {
  28162. valType: 'info_array',
  28163. freeLength: true,
  28164. items: [
  28165. {valType: 'any'},
  28166. {valType: 'any'},
  28167. {valType: 'any'}
  28168. ],
  28169. },
  28170. label: {
  28171. valType: 'string',
  28172. dflt: '',
  28173. },
  28174. execute: {
  28175. valType: 'boolean',
  28176. dflt: true,
  28177. }
  28178. });
  28179. module.exports = overrideAll(templatedArray('updatemenu', {
  28180. _arrayAttrRegexps: [/^updatemenus\[(0|[1-9][0-9]+)\]\.buttons/],
  28181. visible: {
  28182. valType: 'boolean',
  28183. },
  28184. type: {
  28185. valType: 'enumerated',
  28186. values: ['dropdown', 'buttons'],
  28187. dflt: 'dropdown',
  28188. },
  28189. direction: {
  28190. valType: 'enumerated',
  28191. values: ['left', 'right', 'up', 'down'],
  28192. dflt: 'down',
  28193. },
  28194. active: {
  28195. valType: 'integer',
  28196. min: -1,
  28197. dflt: 0,
  28198. },
  28199. showactive: {
  28200. valType: 'boolean',
  28201. dflt: true,
  28202. },
  28203. buttons: buttonsAttrs,
  28204. x: {
  28205. valType: 'number',
  28206. min: -2,
  28207. max: 3,
  28208. dflt: -0.05,
  28209. },
  28210. xanchor: {
  28211. valType: 'enumerated',
  28212. values: ['auto', 'left', 'center', 'right'],
  28213. dflt: 'right',
  28214. },
  28215. y: {
  28216. valType: 'number',
  28217. min: -2,
  28218. max: 3,
  28219. dflt: 1,
  28220. },
  28221. yanchor: {
  28222. valType: 'enumerated',
  28223. values: ['auto', 'top', 'middle', 'bottom'],
  28224. dflt: 'top',
  28225. },
  28226. pad: extendFlat({}, padAttrs, {
  28227. }),
  28228. font: fontAttrs({
  28229. }),
  28230. bgcolor: {
  28231. valType: 'color',
  28232. },
  28233. bordercolor: {
  28234. valType: 'color',
  28235. dflt: colorAttrs.borderLine,
  28236. },
  28237. borderwidth: {
  28238. valType: 'number',
  28239. min: 0,
  28240. dflt: 1,
  28241. editType: 'arraydraw',
  28242. }
  28243. }), 'arraydraw', 'from-root');
  28244. },{"../../lib/extend":163,"../../plot_api/edit_types":197,"../../plot_api/plot_template":204,"../../plots/font_attributes":240,"../../plots/pad_attributes":245,"../color/attributes":49}],143:[function(_dereq_,module,exports){
  28245. /**
  28246. * Copyright 2012-2018, Plotly, Inc.
  28247. * All rights reserved.
  28248. *
  28249. * This source code is licensed under the MIT license found in the
  28250. * LICENSE file in the root directory of this source tree.
  28251. */
  28252. 'use strict';
  28253. module.exports = {
  28254. // layout attribute name
  28255. name: 'updatemenus',
  28256. // class names
  28257. containerClassName: 'updatemenu-container',
  28258. headerGroupClassName: 'updatemenu-header-group',
  28259. headerClassName: 'updatemenu-header',
  28260. headerArrowClassName: 'updatemenu-header-arrow',
  28261. dropdownButtonGroupClassName: 'updatemenu-dropdown-button-group',
  28262. dropdownButtonClassName: 'updatemenu-dropdown-button',
  28263. buttonClassName: 'updatemenu-button',
  28264. itemRectClassName: 'updatemenu-item-rect',
  28265. itemTextClassName: 'updatemenu-item-text',
  28266. // DOM attribute name in button group keeping track
  28267. // of active update menu
  28268. menuIndexAttrName: 'updatemenu-active-index',
  28269. // id root pass to Plots.autoMargin
  28270. autoMarginIdRoot: 'updatemenu-',
  28271. // options when 'active: -1'
  28272. blankHeaderOpts: { label: ' ' },
  28273. // min item width / height
  28274. minWidth: 30,
  28275. minHeight: 30,
  28276. // padding around item text
  28277. textPadX: 24,
  28278. arrowPadX: 16,
  28279. // item rect radii
  28280. rx: 2,
  28281. ry: 2,
  28282. // item text x offset off left edge
  28283. textOffsetX: 12,
  28284. // item text y offset (w.r.t. middle)
  28285. textOffsetY: 3,
  28286. // arrow offset off right edge
  28287. arrowOffsetX: 4,
  28288. // gap between header and buttons
  28289. gapButtonHeader: 5,
  28290. // gap between between buttons
  28291. gapButton: 2,
  28292. // color given to active buttons
  28293. activeColor: '#F4FAFF',
  28294. // color given to hovered buttons
  28295. hoverColor: '#F4FAFF',
  28296. // symbol for menu open arrow
  28297. arrowSymbol: {
  28298. left: '◄',
  28299. right: '►',
  28300. up: '▲',
  28301. down: '▼'
  28302. }
  28303. };
  28304. },{}],144:[function(_dereq_,module,exports){
  28305. /**
  28306. * Copyright 2012-2018, Plotly, Inc.
  28307. * All rights reserved.
  28308. *
  28309. * This source code is licensed under the MIT license found in the
  28310. * LICENSE file in the root directory of this source tree.
  28311. */
  28312. 'use strict';
  28313. var Lib = _dereq_('../../lib');
  28314. var handleArrayContainerDefaults = _dereq_('../../plots/array_container_defaults');
  28315. var attributes = _dereq_('./attributes');
  28316. var constants = _dereq_('./constants');
  28317. var name = constants.name;
  28318. var buttonAttrs = attributes.buttons;
  28319. module.exports = function updateMenusDefaults(layoutIn, layoutOut) {
  28320. var opts = {
  28321. name: name,
  28322. handleItemDefaults: menuDefaults
  28323. };
  28324. handleArrayContainerDefaults(layoutIn, layoutOut, opts);
  28325. };
  28326. function menuDefaults(menuIn, menuOut, layoutOut) {
  28327. function coerce(attr, dflt) {
  28328. return Lib.coerce(menuIn, menuOut, attributes, attr, dflt);
  28329. }
  28330. var buttons = handleArrayContainerDefaults(menuIn, menuOut, {
  28331. name: 'buttons',
  28332. handleItemDefaults: buttonDefaults
  28333. });
  28334. var visible = coerce('visible', buttons.length > 0);
  28335. if(!visible) return;
  28336. coerce('active');
  28337. coerce('direction');
  28338. coerce('type');
  28339. coerce('showactive');
  28340. coerce('x');
  28341. coerce('y');
  28342. Lib.noneOrAll(menuIn, menuOut, ['x', 'y']);
  28343. coerce('xanchor');
  28344. coerce('yanchor');
  28345. coerce('pad.t');
  28346. coerce('pad.r');
  28347. coerce('pad.b');
  28348. coerce('pad.l');
  28349. Lib.coerceFont(coerce, 'font', layoutOut.font);
  28350. coerce('bgcolor', layoutOut.paper_bgcolor);
  28351. coerce('bordercolor');
  28352. coerce('borderwidth');
  28353. }
  28354. function buttonDefaults(buttonIn, buttonOut) {
  28355. function coerce(attr, dflt) {
  28356. return Lib.coerce(buttonIn, buttonOut, buttonAttrs, attr, dflt);
  28357. }
  28358. var visible = coerce('visible',
  28359. (buttonIn.method === 'skip' || Array.isArray(buttonIn.args)));
  28360. if(visible) {
  28361. coerce('method');
  28362. coerce('args');
  28363. coerce('label');
  28364. coerce('execute');
  28365. }
  28366. }
  28367. },{"../../lib":169,"../../plots/array_container_defaults":210,"./attributes":142,"./constants":143}],145:[function(_dereq_,module,exports){
  28368. /**
  28369. * Copyright 2012-2018, Plotly, Inc.
  28370. * All rights reserved.
  28371. *
  28372. * This source code is licensed under the MIT license found in the
  28373. * LICENSE file in the root directory of this source tree.
  28374. */
  28375. 'use strict';
  28376. var d3 = _dereq_('d3');
  28377. var Plots = _dereq_('../../plots/plots');
  28378. var Color = _dereq_('../color');
  28379. var Drawing = _dereq_('../drawing');
  28380. var Lib = _dereq_('../../lib');
  28381. var svgTextUtils = _dereq_('../../lib/svg_text_utils');
  28382. var anchorUtils = _dereq_('../legend/anchor_utils');
  28383. var arrayEditor = _dereq_('../../plot_api/plot_template').arrayEditor;
  28384. var LINE_SPACING = _dereq_('../../constants/alignment').LINE_SPACING;
  28385. var constants = _dereq_('./constants');
  28386. var ScrollBox = _dereq_('./scrollbox');
  28387. module.exports = function draw(gd) {
  28388. var fullLayout = gd._fullLayout,
  28389. menuData = Lib.filterVisible(fullLayout[constants.name]);
  28390. /* Update menu data is bound to the header-group.
  28391. * The items in the header group are always present.
  28392. *
  28393. * Upon clicking on a header its corresponding button
  28394. * data is bound to the button-group.
  28395. *
  28396. * We draw all headers in one group before all buttons
  28397. * so that the buttons *always* appear above the headers.
  28398. *
  28399. * Note that only one set of buttons are visible at once.
  28400. *
  28401. * <g container />
  28402. *
  28403. * <g header-group />
  28404. * <g item header />
  28405. * <text item header-arrow />
  28406. * <g header-group />
  28407. * <g item header />
  28408. * <text item header-arrow />
  28409. * ...
  28410. *
  28411. * <g button-group />
  28412. * <g item button />
  28413. * <g item button />
  28414. * ...
  28415. */
  28416. function clearAutoMargin(menuOpts) {
  28417. Plots.autoMargin(gd, autoMarginId(menuOpts));
  28418. }
  28419. // draw update menu container
  28420. var menus = fullLayout._menulayer
  28421. .selectAll('g.' + constants.containerClassName)
  28422. .data(menuData.length > 0 ? [0] : []);
  28423. menus.enter().append('g')
  28424. .classed(constants.containerClassName, true)
  28425. .style('cursor', 'pointer');
  28426. menus.exit().each(function() {
  28427. // Most components don't need to explicitly remove autoMargin, because
  28428. // marginPushers does this - but updatemenu updates don't go through
  28429. // a full replot so we need to explicitly remove it.
  28430. // This is for removing *all* updatemenus, removing individuals is
  28431. // handled below, in headerGroups.exit
  28432. d3.select(this).selectAll('g.' + constants.headerGroupClassName)
  28433. .each(clearAutoMargin);
  28434. }).remove();
  28435. // return early if no update menus are visible
  28436. if(menuData.length === 0) return;
  28437. // join header group
  28438. var headerGroups = menus.selectAll('g.' + constants.headerGroupClassName)
  28439. .data(menuData, keyFunction);
  28440. headerGroups.enter().append('g')
  28441. .classed(constants.headerGroupClassName, true);
  28442. // draw dropdown button container
  28443. var gButton = Lib.ensureSingle(menus, 'g', constants.dropdownButtonGroupClassName, function(s) {
  28444. s.style('pointer-events', 'all');
  28445. });
  28446. // find dimensions before plotting anything (this mutates menuOpts)
  28447. for(var i = 0; i < menuData.length; i++) {
  28448. var menuOpts = menuData[i];
  28449. findDimensions(gd, menuOpts);
  28450. }
  28451. // setup scrollbox
  28452. var scrollBoxId = 'updatemenus' + fullLayout._uid,
  28453. scrollBox = new ScrollBox(gd, gButton, scrollBoxId);
  28454. // remove exiting header, remove dropped buttons and reset margins
  28455. if(headerGroups.enter().size()) {
  28456. // make sure gButton is on top of all headers
  28457. gButton.node().parentNode.appendChild(gButton.node());
  28458. gButton.call(removeAllButtons);
  28459. }
  28460. headerGroups.exit().each(function(menuOpts) {
  28461. gButton.call(removeAllButtons);
  28462. clearAutoMargin(menuOpts);
  28463. }).remove();
  28464. // draw headers!
  28465. headerGroups.each(function(menuOpts) {
  28466. var gHeader = d3.select(this);
  28467. var _gButton = menuOpts.type === 'dropdown' ? gButton : null;
  28468. Plots.manageCommandObserver(gd, menuOpts, menuOpts.buttons, function(data) {
  28469. setActive(gd, menuOpts, menuOpts.buttons[data.index], gHeader, _gButton, scrollBox, data.index, true);
  28470. });
  28471. if(menuOpts.type === 'dropdown') {
  28472. drawHeader(gd, gHeader, gButton, scrollBox, menuOpts);
  28473. // if this menu is active, update the dropdown container
  28474. if(isActive(gButton, menuOpts)) {
  28475. drawButtons(gd, gHeader, gButton, scrollBox, menuOpts);
  28476. }
  28477. } else {
  28478. drawButtons(gd, gHeader, null, null, menuOpts);
  28479. }
  28480. });
  28481. };
  28482. // Note that '_index' is set at the default step,
  28483. // it corresponds to the menu index in the user layout update menu container.
  28484. // Because a menu can be set invisible,
  28485. // this is a more 'consistent' field than the index in the menuData.
  28486. function keyFunction(menuOpts) {
  28487. return menuOpts._index;
  28488. }
  28489. function isFolded(gButton) {
  28490. return +gButton.attr(constants.menuIndexAttrName) === -1;
  28491. }
  28492. function isActive(gButton, menuOpts) {
  28493. return +gButton.attr(constants.menuIndexAttrName) === menuOpts._index;
  28494. }
  28495. function setActive(gd, menuOpts, buttonOpts, gHeader, gButton, scrollBox, buttonIndex, isSilentUpdate) {
  28496. // update 'active' attribute in menuOpts
  28497. menuOpts.active = buttonIndex;
  28498. // due to templating, it's possible this slider doesn't even exist yet
  28499. arrayEditor(gd.layout, constants.name, menuOpts)
  28500. .applyUpdate('active', buttonIndex);
  28501. if(menuOpts.type === 'buttons') {
  28502. drawButtons(gd, gHeader, null, null, menuOpts);
  28503. }
  28504. else if(menuOpts.type === 'dropdown') {
  28505. // fold up buttons and redraw header
  28506. gButton.attr(constants.menuIndexAttrName, '-1');
  28507. drawHeader(gd, gHeader, gButton, scrollBox, menuOpts);
  28508. if(!isSilentUpdate) {
  28509. drawButtons(gd, gHeader, gButton, scrollBox, menuOpts);
  28510. }
  28511. }
  28512. }
  28513. function drawHeader(gd, gHeader, gButton, scrollBox, menuOpts) {
  28514. var header = Lib.ensureSingle(gHeader, 'g', constants.headerClassName, function(s) {
  28515. s.style('pointer-events', 'all');
  28516. });
  28517. var dims = menuOpts._dims;
  28518. var active = menuOpts.active;
  28519. var headerOpts = menuOpts.buttons[active] || constants.blankHeaderOpts;
  28520. var posOpts = { y: menuOpts.pad.t, yPad: 0, x: menuOpts.pad.l, xPad: 0, index: 0 };
  28521. var positionOverrides = {
  28522. width: dims.headerWidth,
  28523. height: dims.headerHeight
  28524. };
  28525. header
  28526. .call(drawItem, menuOpts, headerOpts, gd)
  28527. .call(setItemPosition, menuOpts, posOpts, positionOverrides);
  28528. // draw drop arrow at the right edge
  28529. var arrow = Lib.ensureSingle(gHeader, 'text', constants.headerArrowClassName, function(s) {
  28530. s.classed('user-select-none', true)
  28531. .attr('text-anchor', 'end')
  28532. .call(Drawing.font, menuOpts.font)
  28533. .text(constants.arrowSymbol[menuOpts.direction]);
  28534. });
  28535. arrow.attr({
  28536. x: dims.headerWidth - constants.arrowOffsetX + menuOpts.pad.l,
  28537. y: dims.headerHeight / 2 + constants.textOffsetY + menuOpts.pad.t
  28538. });
  28539. header.on('click', function() {
  28540. gButton.call(removeAllButtons,
  28541. String(isActive(gButton, menuOpts) ? -1 : menuOpts._index)
  28542. );
  28543. drawButtons(gd, gHeader, gButton, scrollBox, menuOpts);
  28544. });
  28545. header.on('mouseover', function() {
  28546. header.call(styleOnMouseOver);
  28547. });
  28548. header.on('mouseout', function() {
  28549. header.call(styleOnMouseOut, menuOpts);
  28550. });
  28551. // translate header group
  28552. Drawing.setTranslate(gHeader, dims.lx, dims.ly);
  28553. }
  28554. function drawButtons(gd, gHeader, gButton, scrollBox, menuOpts) {
  28555. // If this is a set of buttons, set pointer events = all since we play
  28556. // some minor games with which container is which in order to simplify
  28557. // the drawing of *either* buttons or menus
  28558. if(!gButton) {
  28559. gButton = gHeader;
  28560. gButton.attr('pointer-events', 'all');
  28561. }
  28562. var buttonData = (!isFolded(gButton) || menuOpts.type === 'buttons') ?
  28563. menuOpts.buttons :
  28564. [];
  28565. var klass = menuOpts.type === 'dropdown' ? constants.dropdownButtonClassName : constants.buttonClassName;
  28566. var buttons = gButton.selectAll('g.' + klass)
  28567. .data(Lib.filterVisible(buttonData));
  28568. var enter = buttons.enter().append('g')
  28569. .classed(klass, true);
  28570. var exit = buttons.exit();
  28571. if(menuOpts.type === 'dropdown') {
  28572. enter.attr('opacity', '0')
  28573. .transition()
  28574. .attr('opacity', '1');
  28575. exit.transition()
  28576. .attr('opacity', '0')
  28577. .remove();
  28578. } else {
  28579. exit.remove();
  28580. }
  28581. var x0 = 0;
  28582. var y0 = 0;
  28583. var dims = menuOpts._dims;
  28584. var isVertical = ['up', 'down'].indexOf(menuOpts.direction) !== -1;
  28585. if(menuOpts.type === 'dropdown') {
  28586. if(isVertical) {
  28587. y0 = dims.headerHeight + constants.gapButtonHeader;
  28588. } else {
  28589. x0 = dims.headerWidth + constants.gapButtonHeader;
  28590. }
  28591. }
  28592. if(menuOpts.type === 'dropdown' && menuOpts.direction === 'up') {
  28593. y0 = -constants.gapButtonHeader + constants.gapButton - dims.openHeight;
  28594. }
  28595. if(menuOpts.type === 'dropdown' && menuOpts.direction === 'left') {
  28596. x0 = -constants.gapButtonHeader + constants.gapButton - dims.openWidth;
  28597. }
  28598. var posOpts = {
  28599. x: dims.lx + x0 + menuOpts.pad.l,
  28600. y: dims.ly + y0 + menuOpts.pad.t,
  28601. yPad: constants.gapButton,
  28602. xPad: constants.gapButton,
  28603. index: 0,
  28604. };
  28605. var scrollBoxPosition = {
  28606. l: posOpts.x + menuOpts.borderwidth,
  28607. t: posOpts.y + menuOpts.borderwidth
  28608. };
  28609. buttons.each(function(buttonOpts, buttonIndex) {
  28610. var button = d3.select(this);
  28611. button
  28612. .call(drawItem, menuOpts, buttonOpts, gd)
  28613. .call(setItemPosition, menuOpts, posOpts);
  28614. button.on('click', function() {
  28615. // skip `dragend` events
  28616. if(d3.event.defaultPrevented) return;
  28617. setActive(gd, menuOpts, buttonOpts, gHeader, gButton, scrollBox, buttonIndex);
  28618. if(buttonOpts.execute) {
  28619. Plots.executeAPICommand(gd, buttonOpts.method, buttonOpts.args);
  28620. }
  28621. gd.emit('plotly_buttonclicked', {menu: menuOpts, button: buttonOpts, active: menuOpts.active});
  28622. });
  28623. button.on('mouseover', function() {
  28624. button.call(styleOnMouseOver);
  28625. });
  28626. button.on('mouseout', function() {
  28627. button.call(styleOnMouseOut, menuOpts);
  28628. buttons.call(styleButtons, menuOpts);
  28629. });
  28630. });
  28631. buttons.call(styleButtons, menuOpts);
  28632. if(isVertical) {
  28633. scrollBoxPosition.w = Math.max(dims.openWidth, dims.headerWidth);
  28634. scrollBoxPosition.h = posOpts.y - scrollBoxPosition.t;
  28635. }
  28636. else {
  28637. scrollBoxPosition.w = posOpts.x - scrollBoxPosition.l;
  28638. scrollBoxPosition.h = Math.max(dims.openHeight, dims.headerHeight);
  28639. }
  28640. scrollBoxPosition.direction = menuOpts.direction;
  28641. if(scrollBox) {
  28642. if(buttons.size()) {
  28643. drawScrollBox(gd, gHeader, gButton, scrollBox, menuOpts, scrollBoxPosition);
  28644. }
  28645. else {
  28646. hideScrollBox(scrollBox);
  28647. }
  28648. }
  28649. }
  28650. function drawScrollBox(gd, gHeader, gButton, scrollBox, menuOpts, position) {
  28651. // enable the scrollbox
  28652. var direction = menuOpts.direction;
  28653. var isVertical = (direction === 'up' || direction === 'down');
  28654. var dims = menuOpts._dims;
  28655. var active = menuOpts.active,
  28656. translateX, translateY,
  28657. i;
  28658. if(isVertical) {
  28659. translateY = 0;
  28660. for(i = 0; i < active; i++) {
  28661. translateY += dims.heights[i] + constants.gapButton;
  28662. }
  28663. }
  28664. else {
  28665. translateX = 0;
  28666. for(i = 0; i < active; i++) {
  28667. translateX += dims.widths[i] + constants.gapButton;
  28668. }
  28669. }
  28670. scrollBox.enable(position, translateX, translateY);
  28671. if(scrollBox.hbar) {
  28672. scrollBox.hbar
  28673. .attr('opacity', '0')
  28674. .transition()
  28675. .attr('opacity', '1');
  28676. }
  28677. if(scrollBox.vbar) {
  28678. scrollBox.vbar
  28679. .attr('opacity', '0')
  28680. .transition()
  28681. .attr('opacity', '1');
  28682. }
  28683. }
  28684. function hideScrollBox(scrollBox) {
  28685. var hasHBar = !!scrollBox.hbar,
  28686. hasVBar = !!scrollBox.vbar;
  28687. if(hasHBar) {
  28688. scrollBox.hbar
  28689. .transition()
  28690. .attr('opacity', '0')
  28691. .each('end', function() {
  28692. hasHBar = false;
  28693. if(!hasVBar) scrollBox.disable();
  28694. });
  28695. }
  28696. if(hasVBar) {
  28697. scrollBox.vbar
  28698. .transition()
  28699. .attr('opacity', '0')
  28700. .each('end', function() {
  28701. hasVBar = false;
  28702. if(!hasHBar) scrollBox.disable();
  28703. });
  28704. }
  28705. }
  28706. function drawItem(item, menuOpts, itemOpts, gd) {
  28707. item.call(drawItemRect, menuOpts)
  28708. .call(drawItemText, menuOpts, itemOpts, gd);
  28709. }
  28710. function drawItemRect(item, menuOpts) {
  28711. var rect = Lib.ensureSingle(item, 'rect', constants.itemRectClassName, function(s) {
  28712. s.attr({
  28713. rx: constants.rx,
  28714. ry: constants.ry,
  28715. 'shape-rendering': 'crispEdges'
  28716. });
  28717. });
  28718. rect.call(Color.stroke, menuOpts.bordercolor)
  28719. .call(Color.fill, menuOpts.bgcolor)
  28720. .style('stroke-width', menuOpts.borderwidth + 'px');
  28721. }
  28722. function drawItemText(item, menuOpts, itemOpts, gd) {
  28723. var text = Lib.ensureSingle(item, 'text', constants.itemTextClassName, function(s) {
  28724. s.classed('user-select-none', true)
  28725. .attr({
  28726. 'text-anchor': 'start',
  28727. 'data-notex': 1
  28728. });
  28729. });
  28730. text.call(Drawing.font, menuOpts.font)
  28731. .text(itemOpts.label)
  28732. .call(svgTextUtils.convertToTspans, gd);
  28733. }
  28734. function styleButtons(buttons, menuOpts) {
  28735. var active = menuOpts.active;
  28736. buttons.each(function(buttonOpts, i) {
  28737. var button = d3.select(this);
  28738. if(i === active && menuOpts.showactive) {
  28739. button.select('rect.' + constants.itemRectClassName)
  28740. .call(Color.fill, constants.activeColor);
  28741. }
  28742. });
  28743. }
  28744. function styleOnMouseOver(item) {
  28745. item.select('rect.' + constants.itemRectClassName)
  28746. .call(Color.fill, constants.hoverColor);
  28747. }
  28748. function styleOnMouseOut(item, menuOpts) {
  28749. item.select('rect.' + constants.itemRectClassName)
  28750. .call(Color.fill, menuOpts.bgcolor);
  28751. }
  28752. // find item dimensions (this mutates menuOpts)
  28753. function findDimensions(gd, menuOpts) {
  28754. var dims = menuOpts._dims = {
  28755. width1: 0,
  28756. height1: 0,
  28757. heights: [],
  28758. widths: [],
  28759. totalWidth: 0,
  28760. totalHeight: 0,
  28761. openWidth: 0,
  28762. openHeight: 0,
  28763. lx: 0,
  28764. ly: 0
  28765. };
  28766. var fakeButtons = Drawing.tester.selectAll('g.' + constants.dropdownButtonClassName)
  28767. .data(Lib.filterVisible(menuOpts.buttons));
  28768. fakeButtons.enter().append('g')
  28769. .classed(constants.dropdownButtonClassName, true);
  28770. var isVertical = ['up', 'down'].indexOf(menuOpts.direction) !== -1;
  28771. // loop over fake buttons to find width / height
  28772. fakeButtons.each(function(buttonOpts, i) {
  28773. var button = d3.select(this);
  28774. button.call(drawItem, menuOpts, buttonOpts, gd);
  28775. var text = button.select('.' + constants.itemTextClassName);
  28776. // width is given by max width of all buttons
  28777. var tWidth = text.node() && Drawing.bBox(text.node()).width;
  28778. var wEff = Math.max(tWidth + constants.textPadX, constants.minWidth);
  28779. // height is determined by item text
  28780. var tHeight = menuOpts.font.size * LINE_SPACING;
  28781. var tLines = svgTextUtils.lineCount(text);
  28782. var hEff = Math.max(tHeight * tLines, constants.minHeight) + constants.textOffsetY;
  28783. hEff = Math.ceil(hEff);
  28784. wEff = Math.ceil(wEff);
  28785. // Store per-item sizes since a row of horizontal buttons, for example,
  28786. // don't all need to be the same width:
  28787. dims.widths[i] = wEff;
  28788. dims.heights[i] = hEff;
  28789. // Height and width of individual element:
  28790. dims.height1 = Math.max(dims.height1, hEff);
  28791. dims.width1 = Math.max(dims.width1, wEff);
  28792. if(isVertical) {
  28793. dims.totalWidth = Math.max(dims.totalWidth, wEff);
  28794. dims.openWidth = dims.totalWidth;
  28795. dims.totalHeight += hEff + constants.gapButton;
  28796. dims.openHeight += hEff + constants.gapButton;
  28797. } else {
  28798. dims.totalWidth += wEff + constants.gapButton;
  28799. dims.openWidth += wEff + constants.gapButton;
  28800. dims.totalHeight = Math.max(dims.totalHeight, hEff);
  28801. dims.openHeight = dims.totalHeight;
  28802. }
  28803. });
  28804. if(isVertical) {
  28805. dims.totalHeight -= constants.gapButton;
  28806. } else {
  28807. dims.totalWidth -= constants.gapButton;
  28808. }
  28809. dims.headerWidth = dims.width1 + constants.arrowPadX;
  28810. dims.headerHeight = dims.height1;
  28811. if(menuOpts.type === 'dropdown') {
  28812. if(isVertical) {
  28813. dims.width1 += constants.arrowPadX;
  28814. dims.totalHeight = dims.height1;
  28815. } else {
  28816. dims.totalWidth = dims.width1;
  28817. }
  28818. dims.totalWidth += constants.arrowPadX;
  28819. }
  28820. fakeButtons.remove();
  28821. var paddedWidth = dims.totalWidth + menuOpts.pad.l + menuOpts.pad.r;
  28822. var paddedHeight = dims.totalHeight + menuOpts.pad.t + menuOpts.pad.b;
  28823. var graphSize = gd._fullLayout._size;
  28824. dims.lx = graphSize.l + graphSize.w * menuOpts.x;
  28825. dims.ly = graphSize.t + graphSize.h * (1 - menuOpts.y);
  28826. var xanchor = 'left';
  28827. if(anchorUtils.isRightAnchor(menuOpts)) {
  28828. dims.lx -= paddedWidth;
  28829. xanchor = 'right';
  28830. }
  28831. if(anchorUtils.isCenterAnchor(menuOpts)) {
  28832. dims.lx -= paddedWidth / 2;
  28833. xanchor = 'center';
  28834. }
  28835. var yanchor = 'top';
  28836. if(anchorUtils.isBottomAnchor(menuOpts)) {
  28837. dims.ly -= paddedHeight;
  28838. yanchor = 'bottom';
  28839. }
  28840. if(anchorUtils.isMiddleAnchor(menuOpts)) {
  28841. dims.ly -= paddedHeight / 2;
  28842. yanchor = 'middle';
  28843. }
  28844. dims.totalWidth = Math.ceil(dims.totalWidth);
  28845. dims.totalHeight = Math.ceil(dims.totalHeight);
  28846. dims.lx = Math.round(dims.lx);
  28847. dims.ly = Math.round(dims.ly);
  28848. Plots.autoMargin(gd, autoMarginId(menuOpts), {
  28849. x: menuOpts.x,
  28850. y: menuOpts.y,
  28851. l: paddedWidth * ({right: 1, center: 0.5}[xanchor] || 0),
  28852. r: paddedWidth * ({left: 1, center: 0.5}[xanchor] || 0),
  28853. b: paddedHeight * ({top: 1, middle: 0.5}[yanchor] || 0),
  28854. t: paddedHeight * ({bottom: 1, middle: 0.5}[yanchor] || 0)
  28855. });
  28856. }
  28857. function autoMarginId(menuOpts) {
  28858. return constants.autoMarginIdRoot + menuOpts._index;
  28859. }
  28860. // set item positions (mutates posOpts)
  28861. function setItemPosition(item, menuOpts, posOpts, overrideOpts) {
  28862. overrideOpts = overrideOpts || {};
  28863. var rect = item.select('.' + constants.itemRectClassName);
  28864. var text = item.select('.' + constants.itemTextClassName);
  28865. var borderWidth = menuOpts.borderwidth;
  28866. var index = posOpts.index;
  28867. var dims = menuOpts._dims;
  28868. Drawing.setTranslate(item, borderWidth + posOpts.x, borderWidth + posOpts.y);
  28869. var isVertical = ['up', 'down'].indexOf(menuOpts.direction) !== -1;
  28870. var finalHeight = overrideOpts.height || (isVertical ? dims.heights[index] : dims.height1);
  28871. rect.attr({
  28872. x: 0,
  28873. y: 0,
  28874. width: overrideOpts.width || (isVertical ? dims.width1 : dims.widths[index]),
  28875. height: finalHeight
  28876. });
  28877. var tHeight = menuOpts.font.size * LINE_SPACING;
  28878. var tLines = svgTextUtils.lineCount(text);
  28879. var spanOffset = ((tLines - 1) * tHeight / 2);
  28880. svgTextUtils.positionText(text, constants.textOffsetX,
  28881. finalHeight / 2 - spanOffset + constants.textOffsetY);
  28882. if(isVertical) {
  28883. posOpts.y += dims.heights[index] + posOpts.yPad;
  28884. } else {
  28885. posOpts.x += dims.widths[index] + posOpts.xPad;
  28886. }
  28887. posOpts.index++;
  28888. }
  28889. function removeAllButtons(gButton, newMenuIndexAttr) {
  28890. gButton
  28891. .attr(constants.menuIndexAttrName, newMenuIndexAttr || '-1')
  28892. .selectAll('g.' + constants.dropdownButtonClassName).remove();
  28893. }
  28894. },{"../../constants/alignment":148,"../../lib":169,"../../lib/svg_text_utils":191,"../../plot_api/plot_template":204,"../../plots/plots":246,"../color":50,"../drawing":75,"../legend/anchor_utils":102,"./constants":143,"./scrollbox":147,"d3":16}],146:[function(_dereq_,module,exports){
  28895. arguments[4][140][0].apply(exports,arguments)
  28896. },{"./attributes":142,"./constants":143,"./defaults":144,"./draw":145,"dup":140}],147:[function(_dereq_,module,exports){
  28897. /**
  28898. * Copyright 2012-2018, Plotly, Inc.
  28899. * All rights reserved.
  28900. *
  28901. * This source code is licensed under the MIT license found in the
  28902. * LICENSE file in the root directory of this source tree.
  28903. */
  28904. 'use strict';
  28905. module.exports = ScrollBox;
  28906. var d3 = _dereq_('d3');
  28907. var Color = _dereq_('../color');
  28908. var Drawing = _dereq_('../drawing');
  28909. var Lib = _dereq_('../../lib');
  28910. /**
  28911. * Helper class to setup a scroll box
  28912. *
  28913. * @class
  28914. * @param gd Plotly's graph div
  28915. * @param container Container to be scroll-boxed (as a D3 selection)
  28916. * @param {string} id Id for the clip path to implement the scroll box
  28917. */
  28918. function ScrollBox(gd, container, id) {
  28919. this.gd = gd;
  28920. this.container = container;
  28921. this.id = id;
  28922. // See ScrollBox.prototype.enable for further definition
  28923. this.position = null; // scrollbox position
  28924. this.translateX = null; // scrollbox horizontal translation
  28925. this.translateY = null; // scrollbox vertical translation
  28926. this.hbar = null; // horizontal scrollbar D3 selection
  28927. this.vbar = null; // vertical scrollbar D3 selection
  28928. // <rect> element to capture pointer events
  28929. this.bg = this.container.selectAll('rect.scrollbox-bg').data([0]);
  28930. this.bg.exit()
  28931. .on('.drag', null)
  28932. .on('wheel', null)
  28933. .remove();
  28934. this.bg.enter().append('rect')
  28935. .classed('scrollbox-bg', true)
  28936. .style('pointer-events', 'all')
  28937. .attr({
  28938. opacity: 0,
  28939. x: 0,
  28940. y: 0,
  28941. width: 0,
  28942. height: 0
  28943. });
  28944. }
  28945. // scroll bar dimensions
  28946. ScrollBox.barWidth = 2;
  28947. ScrollBox.barLength = 20;
  28948. ScrollBox.barRadius = 2;
  28949. ScrollBox.barPad = 1;
  28950. ScrollBox.barColor = '#808BA4';
  28951. /**
  28952. * If needed, setup a clip path and scrollbars
  28953. *
  28954. * @method
  28955. * @param {Object} position
  28956. * @param {number} position.l Left side position (in pixels)
  28957. * @param {number} position.t Top side (in pixels)
  28958. * @param {number} position.w Width (in pixels)
  28959. * @param {number} position.h Height (in pixels)
  28960. * @param {string} [position.direction='down']
  28961. * Either 'down', 'left', 'right' or 'up'
  28962. * @param {number} [translateX=0] Horizontal offset (in pixels)
  28963. * @param {number} [translateY=0] Vertical offset (in pixels)
  28964. */
  28965. ScrollBox.prototype.enable = function enable(position, translateX, translateY) {
  28966. var fullLayout = this.gd._fullLayout,
  28967. fullWidth = fullLayout.width,
  28968. fullHeight = fullLayout.height;
  28969. // compute position of scrollbox
  28970. this.position = position;
  28971. var l = this.position.l,
  28972. w = this.position.w,
  28973. t = this.position.t,
  28974. h = this.position.h,
  28975. direction = this.position.direction,
  28976. isDown = (direction === 'down'),
  28977. isLeft = (direction === 'left'),
  28978. isRight = (direction === 'right'),
  28979. isUp = (direction === 'up'),
  28980. boxW = w,
  28981. boxH = h,
  28982. boxL, boxR,
  28983. boxT, boxB;
  28984. if(!isDown && !isLeft && !isRight && !isUp) {
  28985. this.position.direction = 'down';
  28986. isDown = true;
  28987. }
  28988. var isVertical = isDown || isUp;
  28989. if(isVertical) {
  28990. boxL = l;
  28991. boxR = boxL + boxW;
  28992. if(isDown) {
  28993. // anchor to top side
  28994. boxT = t;
  28995. boxB = Math.min(boxT + boxH, fullHeight);
  28996. boxH = boxB - boxT;
  28997. }
  28998. else {
  28999. // anchor to bottom side
  29000. boxB = t + boxH;
  29001. boxT = Math.max(boxB - boxH, 0);
  29002. boxH = boxB - boxT;
  29003. }
  29004. }
  29005. else {
  29006. boxT = t;
  29007. boxB = boxT + boxH;
  29008. if(isLeft) {
  29009. // anchor to right side
  29010. boxR = l + boxW;
  29011. boxL = Math.max(boxR - boxW, 0);
  29012. boxW = boxR - boxL;
  29013. }
  29014. else {
  29015. // anchor to left side
  29016. boxL = l;
  29017. boxR = Math.min(boxL + boxW, fullWidth);
  29018. boxW = boxR - boxL;
  29019. }
  29020. }
  29021. this._box = {
  29022. l: boxL,
  29023. t: boxT,
  29024. w: boxW,
  29025. h: boxH
  29026. };
  29027. // compute position of horizontal scroll bar
  29028. var needsHorizontalScrollBar = (w > boxW),
  29029. hbarW = ScrollBox.barLength + 2 * ScrollBox.barPad,
  29030. hbarH = ScrollBox.barWidth + 2 * ScrollBox.barPad,
  29031. // draw horizontal scrollbar on the bottom side
  29032. hbarL = l,
  29033. hbarT = t + h;
  29034. if(hbarT + hbarH > fullHeight) hbarT = fullHeight - hbarH;
  29035. var hbar = this.container.selectAll('rect.scrollbar-horizontal').data(
  29036. (needsHorizontalScrollBar) ? [0] : []);
  29037. hbar.exit()
  29038. .on('.drag', null)
  29039. .remove();
  29040. hbar.enter().append('rect')
  29041. .classed('scrollbar-horizontal', true)
  29042. .call(Color.fill, ScrollBox.barColor);
  29043. if(needsHorizontalScrollBar) {
  29044. this.hbar = hbar.attr({
  29045. 'rx': ScrollBox.barRadius,
  29046. 'ry': ScrollBox.barRadius,
  29047. 'x': hbarL,
  29048. 'y': hbarT,
  29049. 'width': hbarW,
  29050. 'height': hbarH
  29051. });
  29052. // hbar center moves between hbarXMin and hbarXMin + hbarTranslateMax
  29053. this._hbarXMin = hbarL + hbarW / 2;
  29054. this._hbarTranslateMax = boxW - hbarW;
  29055. }
  29056. else {
  29057. delete this.hbar;
  29058. delete this._hbarXMin;
  29059. delete this._hbarTranslateMax;
  29060. }
  29061. // compute position of vertical scroll bar
  29062. var needsVerticalScrollBar = (h > boxH),
  29063. vbarW = ScrollBox.barWidth + 2 * ScrollBox.barPad,
  29064. vbarH = ScrollBox.barLength + 2 * ScrollBox.barPad,
  29065. // draw vertical scrollbar on the right side
  29066. vbarL = l + w,
  29067. vbarT = t;
  29068. if(vbarL + vbarW > fullWidth) vbarL = fullWidth - vbarW;
  29069. var vbar = this.container.selectAll('rect.scrollbar-vertical').data(
  29070. (needsVerticalScrollBar) ? [0] : []);
  29071. vbar.exit()
  29072. .on('.drag', null)
  29073. .remove();
  29074. vbar.enter().append('rect')
  29075. .classed('scrollbar-vertical', true)
  29076. .call(Color.fill, ScrollBox.barColor);
  29077. if(needsVerticalScrollBar) {
  29078. this.vbar = vbar.attr({
  29079. 'rx': ScrollBox.barRadius,
  29080. 'ry': ScrollBox.barRadius,
  29081. 'x': vbarL,
  29082. 'y': vbarT,
  29083. 'width': vbarW,
  29084. 'height': vbarH
  29085. });
  29086. // vbar center moves between vbarYMin and vbarYMin + vbarTranslateMax
  29087. this._vbarYMin = vbarT + vbarH / 2;
  29088. this._vbarTranslateMax = boxH - vbarH;
  29089. }
  29090. else {
  29091. delete this.vbar;
  29092. delete this._vbarYMin;
  29093. delete this._vbarTranslateMax;
  29094. }
  29095. // setup a clip path (if scroll bars are needed)
  29096. var clipId = this.id,
  29097. clipL = boxL - 0.5,
  29098. clipR = (needsVerticalScrollBar) ? boxR + vbarW + 0.5 : boxR + 0.5,
  29099. clipT = boxT - 0.5,
  29100. clipB = (needsHorizontalScrollBar) ? boxB + hbarH + 0.5 : boxB + 0.5;
  29101. var clipPath = fullLayout._topdefs.selectAll('#' + clipId)
  29102. .data((needsHorizontalScrollBar || needsVerticalScrollBar) ? [0] : []);
  29103. clipPath.exit().remove();
  29104. clipPath.enter()
  29105. .append('clipPath').attr('id', clipId)
  29106. .append('rect');
  29107. if(needsHorizontalScrollBar || needsVerticalScrollBar) {
  29108. this._clipRect = clipPath.select('rect').attr({
  29109. x: Math.floor(clipL),
  29110. y: Math.floor(clipT),
  29111. width: Math.ceil(clipR) - Math.floor(clipL),
  29112. height: Math.ceil(clipB) - Math.floor(clipT)
  29113. });
  29114. this.container.call(Drawing.setClipUrl, clipId);
  29115. this.bg.attr({
  29116. x: l,
  29117. y: t,
  29118. width: w,
  29119. height: h
  29120. });
  29121. }
  29122. else {
  29123. this.bg.attr({
  29124. width: 0,
  29125. height: 0
  29126. });
  29127. this.container
  29128. .on('wheel', null)
  29129. .on('.drag', null)
  29130. .call(Drawing.setClipUrl, null);
  29131. delete this._clipRect;
  29132. }
  29133. // set up drag listeners (if scroll bars are needed)
  29134. if(needsHorizontalScrollBar || needsVerticalScrollBar) {
  29135. var onBoxDrag = d3.behavior.drag()
  29136. .on('dragstart', function() {
  29137. d3.event.sourceEvent.preventDefault();
  29138. })
  29139. .on('drag', this._onBoxDrag.bind(this));
  29140. this.container
  29141. .on('wheel', null)
  29142. .on('wheel', this._onBoxWheel.bind(this))
  29143. .on('.drag', null)
  29144. .call(onBoxDrag);
  29145. var onBarDrag = d3.behavior.drag()
  29146. .on('dragstart', function() {
  29147. d3.event.sourceEvent.preventDefault();
  29148. d3.event.sourceEvent.stopPropagation();
  29149. })
  29150. .on('drag', this._onBarDrag.bind(this));
  29151. if(needsHorizontalScrollBar) {
  29152. this.hbar
  29153. .on('.drag', null)
  29154. .call(onBarDrag);
  29155. }
  29156. if(needsVerticalScrollBar) {
  29157. this.vbar
  29158. .on('.drag', null)
  29159. .call(onBarDrag);
  29160. }
  29161. }
  29162. // set scrollbox translation
  29163. this.setTranslate(translateX, translateY);
  29164. };
  29165. /**
  29166. * If present, remove clip-path and scrollbars
  29167. *
  29168. * @method
  29169. */
  29170. ScrollBox.prototype.disable = function disable() {
  29171. if(this.hbar || this.vbar) {
  29172. this.bg.attr({
  29173. width: 0,
  29174. height: 0
  29175. });
  29176. this.container
  29177. .on('wheel', null)
  29178. .on('.drag', null)
  29179. .call(Drawing.setClipUrl, null);
  29180. delete this._clipRect;
  29181. }
  29182. if(this.hbar) {
  29183. this.hbar.on('.drag', null);
  29184. this.hbar.remove();
  29185. delete this.hbar;
  29186. delete this._hbarXMin;
  29187. delete this._hbarTranslateMax;
  29188. }
  29189. if(this.vbar) {
  29190. this.vbar.on('.drag', null);
  29191. this.vbar.remove();
  29192. delete this.vbar;
  29193. delete this._vbarYMin;
  29194. delete this._vbarTranslateMax;
  29195. }
  29196. };
  29197. /**
  29198. * Handles scroll box drag events
  29199. *
  29200. * @method
  29201. */
  29202. ScrollBox.prototype._onBoxDrag = function onBarDrag() {
  29203. var translateX = this.translateX,
  29204. translateY = this.translateY;
  29205. if(this.hbar) {
  29206. translateX -= d3.event.dx;
  29207. }
  29208. if(this.vbar) {
  29209. translateY -= d3.event.dy;
  29210. }
  29211. this.setTranslate(translateX, translateY);
  29212. };
  29213. /**
  29214. * Handles scroll box wheel events
  29215. *
  29216. * @method
  29217. */
  29218. ScrollBox.prototype._onBoxWheel = function onBarWheel() {
  29219. var translateX = this.translateX,
  29220. translateY = this.translateY;
  29221. if(this.hbar) {
  29222. translateX += d3.event.deltaY;
  29223. }
  29224. if(this.vbar) {
  29225. translateY += d3.event.deltaY;
  29226. }
  29227. this.setTranslate(translateX, translateY);
  29228. };
  29229. /**
  29230. * Handles scroll bar drag events
  29231. *
  29232. * @method
  29233. */
  29234. ScrollBox.prototype._onBarDrag = function onBarDrag() {
  29235. var translateX = this.translateX,
  29236. translateY = this.translateY;
  29237. if(this.hbar) {
  29238. var xMin = translateX + this._hbarXMin,
  29239. xMax = xMin + this._hbarTranslateMax,
  29240. x = Lib.constrain(d3.event.x, xMin, xMax),
  29241. xf = (x - xMin) / (xMax - xMin);
  29242. var translateXMax = this.position.w - this._box.w;
  29243. translateX = xf * translateXMax;
  29244. }
  29245. if(this.vbar) {
  29246. var yMin = translateY + this._vbarYMin,
  29247. yMax = yMin + this._vbarTranslateMax,
  29248. y = Lib.constrain(d3.event.y, yMin, yMax),
  29249. yf = (y - yMin) / (yMax - yMin);
  29250. var translateYMax = this.position.h - this._box.h;
  29251. translateY = yf * translateYMax;
  29252. }
  29253. this.setTranslate(translateX, translateY);
  29254. };
  29255. /**
  29256. * Set clip path and scroll bar translate transform
  29257. *
  29258. * @method
  29259. * @param {number} [translateX=0] Horizontal offset (in pixels)
  29260. * @param {number} [translateY=0] Vertical offset (in pixels)
  29261. */
  29262. ScrollBox.prototype.setTranslate = function setTranslate(translateX, translateY) {
  29263. // store translateX and translateY (needed by mouse event handlers)
  29264. var translateXMax = this.position.w - this._box.w,
  29265. translateYMax = this.position.h - this._box.h;
  29266. translateX = Lib.constrain(translateX || 0, 0, translateXMax);
  29267. translateY = Lib.constrain(translateY || 0, 0, translateYMax);
  29268. this.translateX = translateX;
  29269. this.translateY = translateY;
  29270. this.container.call(Drawing.setTranslate,
  29271. this._box.l - this.position.l - translateX,
  29272. this._box.t - this.position.t - translateY);
  29273. if(this._clipRect) {
  29274. this._clipRect.attr({
  29275. x: Math.floor(this.position.l + translateX - 0.5),
  29276. y: Math.floor(this.position.t + translateY - 0.5)
  29277. });
  29278. }
  29279. if(this.hbar) {
  29280. var xf = translateX / translateXMax;
  29281. this.hbar.call(Drawing.setTranslate,
  29282. translateX + xf * this._hbarTranslateMax,
  29283. translateY);
  29284. }
  29285. if(this.vbar) {
  29286. var yf = translateY / translateYMax;
  29287. this.vbar.call(Drawing.setTranslate,
  29288. translateX,
  29289. translateY + yf * this._vbarTranslateMax);
  29290. }
  29291. };
  29292. },{"../../lib":169,"../color":50,"../drawing":75,"d3":16}],148:[function(_dereq_,module,exports){
  29293. /**
  29294. * Copyright 2012-2018, Plotly, Inc.
  29295. * All rights reserved.
  29296. *
  29297. * This source code is licensed under the MIT license found in the
  29298. * LICENSE file in the root directory of this source tree.
  29299. */
  29300. 'use strict';
  29301. // fraction of some size to get to a named position
  29302. module.exports = {
  29303. // from bottom left: this is the origin of our paper-reference
  29304. // positioning system
  29305. FROM_BL: {
  29306. left: 0,
  29307. center: 0.5,
  29308. right: 1,
  29309. bottom: 0,
  29310. middle: 0.5,
  29311. top: 1
  29312. },
  29313. // from top left: this is the screen pixel positioning origin
  29314. FROM_TL: {
  29315. left: 0,
  29316. center: 0.5,
  29317. right: 1,
  29318. bottom: 1,
  29319. middle: 0.5,
  29320. top: 0
  29321. },
  29322. // from bottom right: sometimes you just need the opposite of ^^
  29323. FROM_BR: {
  29324. left: 1,
  29325. center: 0.5,
  29326. right: 0,
  29327. bottom: 0,
  29328. middle: 0.5,
  29329. top: 1
  29330. },
  29331. // multiple of fontSize to get the vertical offset between lines
  29332. LINE_SPACING: 1.3,
  29333. // multiple of fontSize to shift from the baseline to the midline
  29334. // (to use when we don't calculate this shift from Drawing.bBox)
  29335. // To be precise this should be half the cap height (capital letter)
  29336. // of the font, and according to wikipedia:
  29337. // an "average" font might have a cap height of 70% of the em
  29338. // https://en.wikipedia.org/wiki/Em_(typography)#History
  29339. MID_SHIFT: 0.35,
  29340. OPPOSITE_SIDE: {
  29341. left: 'right',
  29342. right: 'left',
  29343. top: 'bottom',
  29344. bottom: 'top'
  29345. }
  29346. };
  29347. },{}],149:[function(_dereq_,module,exports){
  29348. /**
  29349. * Copyright 2012-2018, Plotly, Inc.
  29350. * All rights reserved.
  29351. *
  29352. * This source code is licensed under the MIT license found in the
  29353. * LICENSE file in the root directory of this source tree.
  29354. */
  29355. 'use strict';
  29356. module.exports = {
  29357. COMPARISON_OPS: ['=', '!=', '<', '>=', '>', '<='],
  29358. COMPARISON_OPS2: ['=', '<', '>=', '>', '<='],
  29359. INTERVAL_OPS: ['[]', '()', '[)', '(]', '][', ')(', '](', ')['],
  29360. SET_OPS: ['{}', '}{'],
  29361. CONSTRAINT_REDUCTION: {
  29362. // for contour constraints, open/closed endpoints are equivalent
  29363. '=': '=',
  29364. '<': '<',
  29365. '<=': '<',
  29366. '>': '>',
  29367. '>=': '>',
  29368. '[]': '[]',
  29369. '()': '[]',
  29370. '[)': '[]',
  29371. '(]': '[]',
  29372. '][': '][',
  29373. ')(': '][',
  29374. '](': '][',
  29375. ')[': ']['
  29376. }
  29377. };
  29378. },{}],150:[function(_dereq_,module,exports){
  29379. /**
  29380. * Copyright 2012-2018, Plotly, Inc.
  29381. * All rights reserved.
  29382. *
  29383. * This source code is licensed under the MIT license found in the
  29384. * LICENSE file in the root directory of this source tree.
  29385. */
  29386. 'use strict';
  29387. module.exports = {
  29388. /**
  29389. * Timing information for interactive elements
  29390. */
  29391. SHOW_PLACEHOLDER: 100,
  29392. HIDE_PLACEHOLDER: 1000,
  29393. // ms between first mousedown and 2nd mouseup to constitute dblclick...
  29394. // we don't seem to have access to the system setting
  29395. DBLCLICKDELAY: 300,
  29396. // opacity dimming fraction for points that are not in selection
  29397. DESELECTDIM: 0.2
  29398. };
  29399. },{}],151:[function(_dereq_,module,exports){
  29400. /**
  29401. * Copyright 2012-2018, Plotly, Inc.
  29402. * All rights reserved.
  29403. *
  29404. * This source code is licensed under the MIT license found in the
  29405. * LICENSE file in the root directory of this source tree.
  29406. */
  29407. 'use strict';
  29408. module.exports = {
  29409. /**
  29410. * Standardize all missing data in calcdata to use undefined
  29411. * never null or NaN.
  29412. * That way we can use !==undefined, or !== BADNUM,
  29413. * to test for real data
  29414. */
  29415. BADNUM: undefined,
  29416. /*
  29417. * Limit certain operations to well below floating point max value
  29418. * to avoid glitches: Make sure that even when you multiply it by the
  29419. * number of pixels on a giant screen it still works
  29420. */
  29421. FP_SAFE: Number.MAX_VALUE / 10000,
  29422. /*
  29423. * conversion of date units to milliseconds
  29424. * year and month constants are marked "AVG"
  29425. * to remind us that not all years and months
  29426. * have the same length
  29427. */
  29428. ONEAVGYEAR: 31557600000, // 365.25 days
  29429. ONEAVGMONTH: 2629800000, // 1/12 of ONEAVGYEAR
  29430. ONEDAY: 86400000,
  29431. ONEHOUR: 3600000,
  29432. ONEMIN: 60000,
  29433. ONESEC: 1000,
  29434. /*
  29435. * For fast conversion btwn world calendars and epoch ms, the Julian Day Number
  29436. * of the unix epoch. From calendars.instance().newDate(1970, 1, 1).toJD()
  29437. */
  29438. EPOCHJD: 2440587.5,
  29439. /*
  29440. * Are two values nearly equal? Compare to 1PPM
  29441. */
  29442. ALMOST_EQUAL: 1 - 1e-6,
  29443. /*
  29444. * If we're asked to clip a non-positive log value, how far off-screen
  29445. * do we put it?
  29446. */
  29447. LOG_CLIP: 10,
  29448. /*
  29449. * not a number, but for displaying numbers: the "minus sign" symbol is
  29450. * wider than the regular ascii dash "-"
  29451. */
  29452. MINUS_SIGN: '\u2212'
  29453. };
  29454. },{}],152:[function(_dereq_,module,exports){
  29455. /**
  29456. * Copyright 2012-2018, Plotly, Inc.
  29457. * All rights reserved.
  29458. *
  29459. * This source code is licensed under the MIT license found in the
  29460. * LICENSE file in the root directory of this source tree.
  29461. */
  29462. 'use strict';
  29463. exports.xmlns = 'http://www.w3.org/2000/xmlns/';
  29464. exports.svg = 'http://www.w3.org/2000/svg';
  29465. exports.xlink = 'http://www.w3.org/1999/xlink';
  29466. // the 'old' d3 quirk got fix in v3.5.7
  29467. // https://github.com/mbostock/d3/commit/a6f66e9dd37f764403fc7c1f26be09ab4af24fed
  29468. exports.svgAttrs = {
  29469. xmlns: exports.svg,
  29470. 'xmlns:xlink': exports.xlink
  29471. };
  29472. },{}],153:[function(_dereq_,module,exports){
  29473. /**
  29474. * Copyright 2012-2018, Plotly, Inc.
  29475. * All rights reserved.
  29476. *
  29477. * This source code is licensed under the MIT license found in the
  29478. * LICENSE file in the root directory of this source tree.
  29479. */
  29480. 'use strict';
  29481. // package version injected by `npm run preprocess`
  29482. exports.version = '1.41.3';
  29483. // inject promise polyfill
  29484. _dereq_('es6-promise').polyfill();
  29485. // inject plot css
  29486. _dereq_('../build/plotcss');
  29487. // inject default MathJax config
  29488. _dereq_('./fonts/mathjax_config');
  29489. // include registry module and expose register method
  29490. var Registry = _dereq_('./registry');
  29491. var register = exports.register = Registry.register;
  29492. // expose plot api methods
  29493. var plotApi = _dereq_('./plot_api');
  29494. var methodNames = Object.keys(plotApi);
  29495. for(var i = 0; i < methodNames.length; i++) {
  29496. var name = methodNames[i];
  29497. exports[name] = plotApi[name];
  29498. register({
  29499. moduleType: 'apiMethod',
  29500. name: name,
  29501. fn: plotApi[name]
  29502. });
  29503. }
  29504. // scatter is the only trace included by default
  29505. register(_dereq_('./traces/scatter'));
  29506. // register all registrable components modules
  29507. register([
  29508. _dereq_('./components/fx'),
  29509. _dereq_('./components/legend'),
  29510. _dereq_('./components/annotations'),
  29511. _dereq_('./components/annotations3d'),
  29512. _dereq_('./components/shapes'),
  29513. _dereq_('./components/images'),
  29514. _dereq_('./components/updatemenus'),
  29515. _dereq_('./components/sliders'),
  29516. _dereq_('./components/rangeslider'),
  29517. _dereq_('./components/rangeselector'),
  29518. _dereq_('./components/grid'),
  29519. _dereq_('./components/errorbars')
  29520. ]);
  29521. // locales en and en-US are required for default behavior
  29522. register([
  29523. _dereq_('./locale-en'),
  29524. _dereq_('./locale-en-us')
  29525. ]);
  29526. // plot icons
  29527. exports.Icons = _dereq_('../build/ploticon');
  29528. // unofficial 'beta' plot methods, use at your own risk
  29529. exports.Plots = _dereq_('./plots/plots');
  29530. exports.Fx = _dereq_('./components/fx');
  29531. exports.Snapshot = _dereq_('./snapshot');
  29532. exports.PlotSchema = _dereq_('./plot_api/plot_schema');
  29533. exports.Queue = _dereq_('./lib/queue');
  29534. // export d3 used in the bundle
  29535. exports.d3 = _dereq_('d3');
  29536. },{"../build/plotcss":1,"../build/ploticon":2,"./components/annotations":43,"./components/annotations3d":48,"./components/errorbars":81,"./components/fx":92,"./components/grid":96,"./components/images":101,"./components/legend":110,"./components/rangeselector":121,"./components/rangeslider":127,"./components/shapes":135,"./components/sliders":140,"./components/updatemenus":146,"./fonts/mathjax_config":154,"./lib/queue":184,"./locale-en":195,"./locale-en-us":194,"./plot_api":199,"./plot_api/plot_schema":203,"./plots/plots":246,"./registry":259,"./snapshot":264,"./traces/scatter":378,"d3":16,"es6-promise":17}],154:[function(_dereq_,module,exports){
  29537. /**
  29538. * Copyright 2012-2018, Plotly, Inc.
  29539. * All rights reserved.
  29540. *
  29541. * This source code is licensed under the MIT license found in the
  29542. * LICENSE file in the root directory of this source tree.
  29543. */
  29544. 'use strict';
  29545. /* global MathJax:false */
  29546. /**
  29547. * Check and configure MathJax
  29548. */
  29549. if(typeof MathJax !== 'undefined') {
  29550. exports.MathJax = true;
  29551. MathJax.Hub.Config({
  29552. messageStyle: 'none',
  29553. skipStartupTypeset: true,
  29554. displayAlign: 'left',
  29555. tex2jax: {
  29556. inlineMath: [['$', '$'], ['\\(', '\\)']]
  29557. }
  29558. });
  29559. MathJax.Hub.Configured();
  29560. } else {
  29561. exports.MathJax = false;
  29562. }
  29563. },{}],155:[function(_dereq_,module,exports){
  29564. /**
  29565. * Copyright 2012-2018, Plotly, Inc.
  29566. * All rights reserved.
  29567. *
  29568. * This source code is licensed under the MIT license found in the
  29569. * LICENSE file in the root directory of this source tree.
  29570. */
  29571. 'use strict';
  29572. var modModule = _dereq_('./mod');
  29573. var mod = modModule.mod;
  29574. var modHalf = modModule.modHalf;
  29575. var PI = Math.PI;
  29576. var twoPI = 2 * PI;
  29577. function deg2rad(deg) { return deg / 180 * PI; }
  29578. function rad2deg(rad) { return rad / PI * 180; }
  29579. /**
  29580. * is sector a full circle?
  29581. * ... this comes up a lot in SVG path-drawing routines
  29582. *
  29583. * N.B. we consider all sectors that span more that 2pi 'full' circles
  29584. *
  29585. * @param {2-item array} aBnds : angular bounds in *radians*
  29586. * @return {boolean}
  29587. */
  29588. function isFullCircle(aBnds) {
  29589. return Math.abs(aBnds[1] - aBnds[0]) > twoPI - 1e-15;
  29590. }
  29591. /**
  29592. * angular delta between angle 'a' and 'b'
  29593. * solution taken from: https://stackoverflow.com/a/2007279
  29594. *
  29595. * @param {number} a : first angle in *radians*
  29596. * @param {number} b : second angle in *radians*
  29597. * @return {number} angular delta in *radians*
  29598. */
  29599. function angleDelta(a, b) {
  29600. return modHalf(b - a, twoPI);
  29601. }
  29602. /**
  29603. * angular distance between angle 'a' and 'b'
  29604. *
  29605. * @param {number} a : first angle in *radians*
  29606. * @param {number} b : second angle in *radians*
  29607. * @return {number} angular distance in *radians*
  29608. */
  29609. function angleDist(a, b) {
  29610. return Math.abs(angleDelta(a, b));
  29611. }
  29612. /**
  29613. * is angle inside sector?
  29614. *
  29615. * @param {number} a : angle to test in *radians*
  29616. * @param {2-item array} aBnds : sector's angular bounds in *radians*
  29617. * @param {boolean}
  29618. */
  29619. function isAngleInsideSector(a, aBnds) {
  29620. if(isFullCircle(aBnds)) return true;
  29621. var s0, s1;
  29622. if(aBnds[0] < aBnds[1]) {
  29623. s0 = aBnds[0];
  29624. s1 = aBnds[1];
  29625. } else {
  29626. s0 = aBnds[1];
  29627. s1 = aBnds[0];
  29628. }
  29629. s0 = mod(s0, twoPI);
  29630. s1 = mod(s1, twoPI);
  29631. if(s0 > s1) s1 += twoPI;
  29632. var a0 = mod(a, twoPI);
  29633. var a1 = a0 + twoPI;
  29634. return (a0 >= s0 && a0 <= s1) || (a1 >= s0 && a1 <= s1);
  29635. }
  29636. /**
  29637. * is pt (r,a) inside sector?
  29638. *
  29639. * @param {number} r : pt's radial coordinate
  29640. * @param {number} a : pt's angular coordinate in *radians*
  29641. * @param {2-item array} rBnds : sector's radial bounds
  29642. * @param {2-item array} aBnds : sector's angular bounds in *radians*
  29643. * @return {boolean}
  29644. */
  29645. function isPtInsideSector(r, a, rBnds, aBnds) {
  29646. if(!isAngleInsideSector(a, aBnds)) return false;
  29647. var r0, r1;
  29648. if(rBnds[0] < rBnds[1]) {
  29649. r0 = rBnds[0];
  29650. r1 = rBnds[1];
  29651. } else {
  29652. r0 = rBnds[1];
  29653. r1 = rBnds[0];
  29654. }
  29655. return r >= r0 && r <= r1;
  29656. }
  29657. // common to pathArc, pathSector and pathAnnulus
  29658. function _path(r0, r1, a0, a1, cx, cy, isClosed) {
  29659. cx = cx || 0;
  29660. cy = cy || 0;
  29661. var isCircle = isFullCircle([a0, a1]);
  29662. var aStart, aMid, aEnd;
  29663. var rStart, rEnd;
  29664. if(isCircle) {
  29665. aStart = 0;
  29666. aMid = PI;
  29667. aEnd = twoPI;
  29668. } else {
  29669. if(a0 < a1) {
  29670. aStart = a0;
  29671. aEnd = a1;
  29672. } else {
  29673. aStart = a1;
  29674. aEnd = a0;
  29675. }
  29676. }
  29677. if(r0 < r1) {
  29678. rStart = r0;
  29679. rEnd = r1;
  29680. } else {
  29681. rStart = r1;
  29682. rEnd = r0;
  29683. }
  29684. // N.B. svg coordinates here, where y increases downward
  29685. function pt(r, a) {
  29686. return [r * Math.cos(a) + cx, cy - r * Math.sin(a)];
  29687. }
  29688. var largeArc = Math.abs(aEnd - aStart) <= PI ? 0 : 1;
  29689. function arc(r, a, cw) {
  29690. return 'A' + [r, r] + ' ' + [0, largeArc, cw] + ' ' + pt(r, a);
  29691. }
  29692. var p;
  29693. if(isCircle) {
  29694. if(rStart === null) {
  29695. p = 'M' + pt(rEnd, aStart) +
  29696. arc(rEnd, aMid, 0) +
  29697. arc(rEnd, aEnd, 0) + 'Z';
  29698. } else {
  29699. p = 'M' + pt(rStart, aStart) +
  29700. arc(rStart, aMid, 0) +
  29701. arc(rStart, aEnd, 0) + 'Z' +
  29702. 'M' + pt(rEnd, aStart) +
  29703. arc(rEnd, aMid, 1) +
  29704. arc(rEnd, aEnd, 1) + 'Z';
  29705. }
  29706. } else {
  29707. if(rStart === null) {
  29708. p = 'M' + pt(rEnd, aStart) + arc(rEnd, aEnd, 0);
  29709. if(isClosed) p += 'L0,0Z';
  29710. } else {
  29711. p = 'M' + pt(rStart, aStart) +
  29712. 'L' + pt(rEnd, aStart) +
  29713. arc(rEnd, aEnd, 0) +
  29714. 'L' + pt(rStart, aEnd) +
  29715. arc(rStart, aStart, 1) + 'Z';
  29716. }
  29717. }
  29718. return p;
  29719. }
  29720. /**
  29721. * path an arc
  29722. *
  29723. * @param {number} r : radius
  29724. * @param {number} a0 : first angular coordinate in *radians*
  29725. * @param {number} a1 : second angular coordinate in *radians*
  29726. * @param {number (optional)} cx : x coordinate of center
  29727. * @param {number (optional)} cy : y coordinate of center
  29728. * @return {string} svg path
  29729. */
  29730. function pathArc(r, a0, a1, cx, cy) {
  29731. return _path(null, r, a0, a1, cx, cy, 0);
  29732. }
  29733. /**
  29734. * path a sector
  29735. *
  29736. * @param {number} r : radius
  29737. * @param {number} a0 : first angular coordinate in *radians*
  29738. * @param {number} a1 : second angular coordinate in *radians*
  29739. * @param {number (optional)} cx : x coordinate of center
  29740. * @param {number (optional)} cy : y coordinate of center
  29741. * @return {string} svg path
  29742. */
  29743. function pathSector(r, a0, a1, cx, cy) {
  29744. return _path(null, r, a0, a1, cx, cy, 1);
  29745. }
  29746. /**
  29747. * path an annulus
  29748. *
  29749. * @param {number} r0 : first radial coordinate
  29750. * @param {number} r1 : second radial coordinate
  29751. * @param {number} a0 : first angular coordinate in *radians*
  29752. * @param {number} a1 : second angular coordinate in *radians*
  29753. * @param {number (optional)} cx : x coordinate of center
  29754. * @param {number (optional)} cy : y coordinate of center
  29755. * @return {string} svg path
  29756. */
  29757. function pathAnnulus(r0, r1, a0, a1, cx, cy) {
  29758. return _path(r0, r1, a0, a1, cx, cy, 1);
  29759. }
  29760. module.exports = {
  29761. deg2rad: deg2rad,
  29762. rad2deg: rad2deg,
  29763. angleDelta: angleDelta,
  29764. angleDist: angleDist,
  29765. isFullCircle: isFullCircle,
  29766. isAngleInsideSector: isAngleInsideSector,
  29767. isPtInsideSector: isPtInsideSector,
  29768. pathArc: pathArc,
  29769. pathSector: pathSector,
  29770. pathAnnulus: pathAnnulus
  29771. };
  29772. },{"./mod":177}],156:[function(_dereq_,module,exports){
  29773. /**
  29774. * Copyright 2012-2018, Plotly, Inc.
  29775. * All rights reserved.
  29776. *
  29777. * This source code is licensed under the MIT license found in the
  29778. * LICENSE file in the root directory of this source tree.
  29779. */
  29780. 'use strict';
  29781. var isNumeric = _dereq_('fast-isnumeric');
  29782. var BADNUM = _dereq_('../constants/numerical').BADNUM;
  29783. // precompile for speed
  29784. var JUNK = /^['"%,$#\s']+|[, ]|['"%,$#\s']+$/g;
  29785. /**
  29786. * cleanNumber: remove common leading and trailing cruft
  29787. * Always returns either a number or BADNUM.
  29788. */
  29789. module.exports = function cleanNumber(v) {
  29790. if(typeof v === 'string') {
  29791. v = v.replace(JUNK, '');
  29792. }
  29793. if(isNumeric(v)) return Number(v);
  29794. return BADNUM;
  29795. };
  29796. },{"../constants/numerical":151,"fast-isnumeric":18}],157:[function(_dereq_,module,exports){
  29797. /**
  29798. * Copyright 2012-2018, Plotly, Inc.
  29799. * All rights reserved.
  29800. *
  29801. * This source code is licensed under the MIT license found in the
  29802. * LICENSE file in the root directory of this source tree.
  29803. */
  29804. 'use strict';
  29805. /**
  29806. * Clear gl frame (if any). This is a common pattern as
  29807. * we usually set `preserveDrawingBuffer: true` during
  29808. * gl context creation (e.g. via `reglUtils.prepare`).
  29809. *
  29810. * @param {DOM node or object} gd : graph div object
  29811. */
  29812. module.exports = function clearGlCanvases(gd) {
  29813. var fullLayout = gd._fullLayout;
  29814. if(fullLayout._glcanvas && fullLayout._glcanvas.size()) {
  29815. fullLayout._glcanvas.each(function(d) {
  29816. if(d.regl) d.regl.clear({color: true, depth: true});
  29817. });
  29818. }
  29819. };
  29820. },{}],158:[function(_dereq_,module,exports){
  29821. /**
  29822. * Copyright 2012-2018, Plotly, Inc.
  29823. * All rights reserved.
  29824. *
  29825. * This source code is licensed under the MIT license found in the
  29826. * LICENSE file in the root directory of this source tree.
  29827. */
  29828. 'use strict';
  29829. /**
  29830. * Clear responsive handlers (if any).
  29831. *
  29832. * @param {DOM node or object} gd : graph div object
  29833. */
  29834. module.exports = function clearResponsive(gd) {
  29835. if(gd._responsiveChartHandler) {
  29836. window.removeEventListener('resize', gd._responsiveChartHandler);
  29837. delete gd._responsiveChartHandler;
  29838. }
  29839. };
  29840. },{}],159:[function(_dereq_,module,exports){
  29841. /**
  29842. * Copyright 2012-2018, Plotly, Inc.
  29843. * All rights reserved.
  29844. *
  29845. * This source code is licensed under the MIT license found in the
  29846. * LICENSE file in the root directory of this source tree.
  29847. */
  29848. 'use strict';
  29849. var isNumeric = _dereq_('fast-isnumeric');
  29850. var tinycolor = _dereq_('tinycolor2');
  29851. var baseTraceAttrs = _dereq_('../plots/attributes');
  29852. var getColorscale = _dereq_('../components/colorscale/get_scale');
  29853. var colorscaleNames = Object.keys(_dereq_('../components/colorscale/scales'));
  29854. var nestedProperty = _dereq_('./nested_property');
  29855. var counterRegex = _dereq_('./regex').counter;
  29856. var DESELECTDIM = _dereq_('../constants/interactions').DESELECTDIM;
  29857. var modHalf = _dereq_('./mod').modHalf;
  29858. var isArrayOrTypedArray = _dereq_('./is_array').isArrayOrTypedArray;
  29859. exports.valObjectMeta = {
  29860. data_array: {
  29861. // You can use *dflt=[] to force said array to exist though.
  29862. coerceFunction: function(v, propOut, dflt) {
  29863. // TODO maybe `v: {type: 'float32', vals: [/* ... */]}` also
  29864. if(isArrayOrTypedArray(v)) propOut.set(v);
  29865. else if(dflt !== undefined) propOut.set(dflt);
  29866. }
  29867. },
  29868. enumerated: {
  29869. coerceFunction: function(v, propOut, dflt, opts) {
  29870. if(opts.coerceNumber) v = +v;
  29871. if(opts.values.indexOf(v) === -1) propOut.set(dflt);
  29872. else propOut.set(v);
  29873. },
  29874. validateFunction: function(v, opts) {
  29875. if(opts.coerceNumber) v = +v;
  29876. var values = opts.values;
  29877. for(var i = 0; i < values.length; i++) {
  29878. var k = String(values[i]);
  29879. if((k.charAt(0) === '/' && k.charAt(k.length - 1) === '/')) {
  29880. var regex = new RegExp(k.substr(1, k.length - 2));
  29881. if(regex.test(v)) return true;
  29882. } else if(v === values[i]) return true;
  29883. }
  29884. return false;
  29885. }
  29886. },
  29887. 'boolean': {
  29888. coerceFunction: function(v, propOut, dflt) {
  29889. if(v === true || v === false) propOut.set(v);
  29890. else propOut.set(dflt);
  29891. }
  29892. },
  29893. number: {
  29894. coerceFunction: function(v, propOut, dflt, opts) {
  29895. if(!isNumeric(v) ||
  29896. (opts.min !== undefined && v < opts.min) ||
  29897. (opts.max !== undefined && v > opts.max)) {
  29898. propOut.set(dflt);
  29899. }
  29900. else propOut.set(+v);
  29901. }
  29902. },
  29903. integer: {
  29904. coerceFunction: function(v, propOut, dflt, opts) {
  29905. if(v % 1 || !isNumeric(v) ||
  29906. (opts.min !== undefined && v < opts.min) ||
  29907. (opts.max !== undefined && v > opts.max)) {
  29908. propOut.set(dflt);
  29909. }
  29910. else propOut.set(+v);
  29911. }
  29912. },
  29913. string: {
  29914. // TODO 'values shouldn't be in there (edge case: 'dash' in Scatter)
  29915. coerceFunction: function(v, propOut, dflt, opts) {
  29916. if(typeof v !== 'string') {
  29917. var okToCoerce = (typeof v === 'number');
  29918. if(opts.strict === true || !okToCoerce) propOut.set(dflt);
  29919. else propOut.set(String(v));
  29920. }
  29921. else if(opts.noBlank && !v) propOut.set(dflt);
  29922. else propOut.set(v);
  29923. }
  29924. },
  29925. color: {
  29926. coerceFunction: function(v, propOut, dflt) {
  29927. if(tinycolor(v).isValid()) propOut.set(v);
  29928. else propOut.set(dflt);
  29929. }
  29930. },
  29931. colorlist: {
  29932. coerceFunction: function(v, propOut, dflt) {
  29933. function isColor(color) {
  29934. return tinycolor(color).isValid();
  29935. }
  29936. if(!Array.isArray(v) || !v.length) propOut.set(dflt);
  29937. else if(v.every(isColor)) propOut.set(v);
  29938. else propOut.set(dflt);
  29939. }
  29940. },
  29941. colorscale: {
  29942. coerceFunction: function(v, propOut, dflt) {
  29943. propOut.set(getColorscale(v, dflt));
  29944. }
  29945. },
  29946. angle: {
  29947. coerceFunction: function(v, propOut, dflt) {
  29948. if(v === 'auto') propOut.set('auto');
  29949. else if(!isNumeric(v)) propOut.set(dflt);
  29950. else propOut.set(modHalf(+v, 360));
  29951. }
  29952. },
  29953. subplotid: {
  29954. coerceFunction: function(v, propOut, dflt, opts) {
  29955. var regex = opts.regex || counterRegex(dflt);
  29956. if(typeof v === 'string' && regex.test(v)) {
  29957. propOut.set(v);
  29958. return;
  29959. }
  29960. propOut.set(dflt);
  29961. },
  29962. validateFunction: function(v, opts) {
  29963. var dflt = opts.dflt;
  29964. if(v === dflt) return true;
  29965. if(typeof v !== 'string') return false;
  29966. if(counterRegex(dflt).test(v)) return true;
  29967. return false;
  29968. }
  29969. },
  29970. flaglist: {
  29971. coerceFunction: function(v, propOut, dflt, opts) {
  29972. if(typeof v !== 'string') {
  29973. propOut.set(dflt);
  29974. return;
  29975. }
  29976. if((opts.extras || []).indexOf(v) !== -1) {
  29977. propOut.set(v);
  29978. return;
  29979. }
  29980. var vParts = v.split('+'),
  29981. i = 0;
  29982. while(i < vParts.length) {
  29983. var vi = vParts[i];
  29984. if(opts.flags.indexOf(vi) === -1 || vParts.indexOf(vi) < i) {
  29985. vParts.splice(i, 1);
  29986. }
  29987. else i++;
  29988. }
  29989. if(!vParts.length) propOut.set(dflt);
  29990. else propOut.set(vParts.join('+'));
  29991. }
  29992. },
  29993. any: {
  29994. coerceFunction: function(v, propOut, dflt) {
  29995. if(v === undefined) propOut.set(dflt);
  29996. else propOut.set(v);
  29997. }
  29998. },
  29999. info_array: {
  30000. // set `dimensions=2` for a 2D array or '1-2' for either
  30001. // `items` may be a single object instead of an array, in which case
  30002. // `freeLength` must be true.
  30003. // if `dimensions='1-2'` and items is a 1D array, then the value can
  30004. // either be a matching 1D array or an array of such matching 1D arrays
  30005. coerceFunction: function(v, propOut, dflt, opts) {
  30006. // simplified coerce function just for array items
  30007. function coercePart(v, opts, dflt) {
  30008. var out;
  30009. var propPart = {set: function(v) { out = v; }};
  30010. if(dflt === undefined) dflt = opts.dflt;
  30011. exports.valObjectMeta[opts.valType].coerceFunction(v, propPart, dflt, opts);
  30012. return out;
  30013. }
  30014. var twoD = opts.dimensions === 2 || (opts.dimensions === '1-2' && Array.isArray(v) && Array.isArray(v[0]));
  30015. if(!Array.isArray(v)) {
  30016. propOut.set(dflt);
  30017. return;
  30018. }
  30019. var items = opts.items;
  30020. var vOut = [];
  30021. var arrayItems = Array.isArray(items);
  30022. var arrayItems2D = arrayItems && twoD && Array.isArray(items[0]);
  30023. var innerItemsOnly = twoD && arrayItems && !arrayItems2D;
  30024. var len = (arrayItems && !innerItemsOnly) ? items.length : v.length;
  30025. var i, j, row, item, len2, vNew;
  30026. dflt = Array.isArray(dflt) ? dflt : [];
  30027. if(twoD) {
  30028. for(i = 0; i < len; i++) {
  30029. vOut[i] = [];
  30030. row = Array.isArray(v[i]) ? v[i] : [];
  30031. if(innerItemsOnly) len2 = items.length;
  30032. else if(arrayItems) len2 = items[i].length;
  30033. else len2 = row.length;
  30034. for(j = 0; j < len2; j++) {
  30035. if(innerItemsOnly) item = items[j];
  30036. else if(arrayItems) item = items[i][j];
  30037. else item = items;
  30038. vNew = coercePart(row[j], item, (dflt[i] || [])[j]);
  30039. if(vNew !== undefined) vOut[i][j] = vNew;
  30040. }
  30041. }
  30042. }
  30043. else {
  30044. for(i = 0; i < len; i++) {
  30045. vNew = coercePart(v[i], arrayItems ? items[i] : items, dflt[i]);
  30046. if(vNew !== undefined) vOut[i] = vNew;
  30047. }
  30048. }
  30049. propOut.set(vOut);
  30050. },
  30051. validateFunction: function(v, opts) {
  30052. if(!Array.isArray(v)) return false;
  30053. var items = opts.items;
  30054. var arrayItems = Array.isArray(items);
  30055. var twoD = opts.dimensions === 2;
  30056. // when free length is off, input and declared lengths must match
  30057. if(!opts.freeLength && v.length !== items.length) return false;
  30058. // valid when all input items are valid
  30059. for(var i = 0; i < v.length; i++) {
  30060. if(twoD) {
  30061. if(!Array.isArray(v[i]) || (!opts.freeLength && v[i].length !== items[i].length)) {
  30062. return false;
  30063. }
  30064. for(var j = 0; j < v[i].length; j++) {
  30065. if(!validate(v[i][j], arrayItems ? items[i][j] : items)) {
  30066. return false;
  30067. }
  30068. }
  30069. }
  30070. else if(!validate(v[i], arrayItems ? items[i] : items)) return false;
  30071. }
  30072. return true;
  30073. }
  30074. }
  30075. };
  30076. /**
  30077. * Ensures that container[attribute] has a valid value.
  30078. *
  30079. * attributes[attribute] is an object with possible keys:
  30080. * - valType: data_array, enumerated, boolean, ... as in valObjectMeta
  30081. * - values: (enumerated only) array of allowed vals
  30082. * - min, max: (number, integer only) inclusive bounds on allowed vals
  30083. * either or both may be omitted
  30084. * - dflt: if attribute is invalid or missing, use this default
  30085. * if dflt is provided as an argument to lib.coerce it takes precedence
  30086. * as a convenience, returns the value it finally set
  30087. */
  30088. exports.coerce = function(containerIn, containerOut, attributes, attribute, dflt) {
  30089. var opts = nestedProperty(attributes, attribute).get();
  30090. var propIn = nestedProperty(containerIn, attribute);
  30091. var propOut = nestedProperty(containerOut, attribute);
  30092. var v = propIn.get();
  30093. var template = containerOut._template;
  30094. if(v === undefined && template) {
  30095. v = nestedProperty(template, attribute).get();
  30096. // already used the template value, so short-circuit the second check
  30097. template = 0;
  30098. }
  30099. if(dflt === undefined) dflt = opts.dflt;
  30100. /**
  30101. * arrayOk: value MAY be an array, then we do no value checking
  30102. * at this point, because it can be more complicated than the
  30103. * individual form (eg. some array vals can be numbers, even if the
  30104. * single values must be color strings)
  30105. */
  30106. if(opts.arrayOk && isArrayOrTypedArray(v)) {
  30107. propOut.set(v);
  30108. return v;
  30109. }
  30110. var coerceFunction = exports.valObjectMeta[opts.valType].coerceFunction;
  30111. coerceFunction(v, propOut, dflt, opts);
  30112. var out = propOut.get();
  30113. // in case v was provided but invalid, try the template again so it still
  30114. // overrides the regular default
  30115. if(template && out === dflt && !validate(v, opts)) {
  30116. v = nestedProperty(template, attribute).get();
  30117. coerceFunction(v, propOut, dflt, opts);
  30118. out = propOut.get();
  30119. }
  30120. return out;
  30121. };
  30122. /**
  30123. * Variation on coerce
  30124. *
  30125. * Uses coerce to get attribute value if user input is valid,
  30126. * returns attribute default if user input it not valid or
  30127. * returns false if there is no user input.
  30128. */
  30129. exports.coerce2 = function(containerIn, containerOut, attributes, attribute, dflt) {
  30130. var propIn = nestedProperty(containerIn, attribute),
  30131. propOut = exports.coerce(containerIn, containerOut, attributes, attribute, dflt),
  30132. valIn = propIn.get();
  30133. return (valIn !== undefined && valIn !== null) ? propOut : false;
  30134. };
  30135. /*
  30136. * Shortcut to coerce the three font attributes
  30137. *
  30138. * 'coerce' is a lib.coerce wrapper with implied first three arguments
  30139. */
  30140. exports.coerceFont = function(coerce, attr, dfltObj) {
  30141. var out = {};
  30142. dfltObj = dfltObj || {};
  30143. out.family = coerce(attr + '.family', dfltObj.family);
  30144. out.size = coerce(attr + '.size', dfltObj.size);
  30145. out.color = coerce(attr + '.color', dfltObj.color);
  30146. return out;
  30147. };
  30148. /** Coerce shortcut for 'hoverinfo'
  30149. * handling 1-vs-multi-trace dflt logic
  30150. *
  30151. * @param {object} traceIn : user trace object
  30152. * @param {object} traceOut : full trace object (requires _module ref)
  30153. * @param {object} layoutOut : full layout object (require _dataLength ref)
  30154. * @return {any} : the coerced value
  30155. */
  30156. exports.coerceHoverinfo = function(traceIn, traceOut, layoutOut) {
  30157. var moduleAttrs = traceOut._module.attributes;
  30158. var attrs = moduleAttrs.hoverinfo ? moduleAttrs : baseTraceAttrs;
  30159. var valObj = attrs.hoverinfo;
  30160. var dflt;
  30161. if(layoutOut._dataLength === 1) {
  30162. var flags = valObj.dflt === 'all' ?
  30163. valObj.flags.slice() :
  30164. valObj.dflt.split('+');
  30165. flags.splice(flags.indexOf('name'), 1);
  30166. dflt = flags.join('+');
  30167. }
  30168. return exports.coerce(traceIn, traceOut, attrs, 'hoverinfo', dflt);
  30169. };
  30170. /** Coerce shortcut for [un]selected.marker.opacity,
  30171. * which has special default logic, to ensure that it corresponds to the
  30172. * default selection behavior while allowing to be overtaken by any other
  30173. * [un]selected attribute.
  30174. *
  30175. * N.B. This must be called *after* coercing all the other [un]selected attrs,
  30176. * to give the intended result.
  30177. *
  30178. * @param {object} traceOut : fullData item
  30179. * @param {function} coerce : lib.coerce wrapper with implied first three arguments
  30180. */
  30181. exports.coerceSelectionMarkerOpacity = function(traceOut, coerce) {
  30182. if(!traceOut.marker) return;
  30183. var mo = traceOut.marker.opacity;
  30184. // you can still have a `marker` container with no markers if there's text
  30185. if(mo === undefined) return;
  30186. var smoDflt;
  30187. var usmoDflt;
  30188. // Don't give [un]selected.marker.opacity a default value if
  30189. // marker.opacity is an array: handle this during style step.
  30190. //
  30191. // Only give [un]selected.marker.opacity a default value if you don't
  30192. // set any other [un]selected attributes.
  30193. if(!isArrayOrTypedArray(mo) && !traceOut.selected && !traceOut.unselected) {
  30194. smoDflt = mo;
  30195. usmoDflt = DESELECTDIM * mo;
  30196. }
  30197. coerce('selected.marker.opacity', smoDflt);
  30198. coerce('unselected.marker.opacity', usmoDflt);
  30199. };
  30200. function validate(value, opts) {
  30201. var valObjectDef = exports.valObjectMeta[opts.valType];
  30202. if(opts.arrayOk && isArrayOrTypedArray(value)) return true;
  30203. if(valObjectDef.validateFunction) {
  30204. return valObjectDef.validateFunction(value, opts);
  30205. }
  30206. var failed = {},
  30207. out = failed,
  30208. propMock = { set: function(v) { out = v; } };
  30209. // 'failed' just something mutable that won't be === anything else
  30210. valObjectDef.coerceFunction(value, propMock, failed, opts);
  30211. return out !== failed;
  30212. }
  30213. exports.validate = validate;
  30214. },{"../components/colorscale/get_scale":63,"../components/colorscale/scales":69,"../constants/interactions":150,"../plots/attributes":211,"./is_array":170,"./mod":177,"./nested_property":178,"./regex":185,"fast-isnumeric":18,"tinycolor2":33}],160:[function(_dereq_,module,exports){
  30215. /**
  30216. * Copyright 2012-2018, Plotly, Inc.
  30217. * All rights reserved.
  30218. *
  30219. * This source code is licensed under the MIT license found in the
  30220. * LICENSE file in the root directory of this source tree.
  30221. */
  30222. 'use strict';
  30223. var d3 = _dereq_('d3');
  30224. var isNumeric = _dereq_('fast-isnumeric');
  30225. var Loggers = _dereq_('./loggers');
  30226. var mod = _dereq_('./mod').mod;
  30227. var constants = _dereq_('../constants/numerical');
  30228. var BADNUM = constants.BADNUM;
  30229. var ONEDAY = constants.ONEDAY;
  30230. var ONEHOUR = constants.ONEHOUR;
  30231. var ONEMIN = constants.ONEMIN;
  30232. var ONESEC = constants.ONESEC;
  30233. var EPOCHJD = constants.EPOCHJD;
  30234. var Registry = _dereq_('../registry');
  30235. var utcFormat = d3.time.format.utc;
  30236. var DATETIME_REGEXP = /^\s*(-?\d\d\d\d|\d\d)(-(\d?\d)(-(\d?\d)([ Tt]([01]?\d|2[0-3])(:([0-5]\d)(:([0-5]\d(\.\d+)?))?(Z|z|[+\-]\d\d:?\d\d)?)?)?)?)?\s*$/m;
  30237. // special regex for chinese calendars to support yyyy-mmi-dd etc for intercalary months
  30238. var DATETIME_REGEXP_CN = /^\s*(-?\d\d\d\d|\d\d)(-(\d?\di?)(-(\d?\d)([ Tt]([01]?\d|2[0-3])(:([0-5]\d)(:([0-5]\d(\.\d+)?))?(Z|z|[+\-]\d\d:?\d\d)?)?)?)?)?\s*$/m;
  30239. // for 2-digit years, the first year we map them onto
  30240. var YFIRST = new Date().getFullYear() - 70;
  30241. function isWorldCalendar(calendar) {
  30242. return (
  30243. calendar &&
  30244. Registry.componentsRegistry.calendars &&
  30245. typeof calendar === 'string' && calendar !== 'gregorian'
  30246. );
  30247. }
  30248. /*
  30249. * dateTick0: get the canonical tick for this calendar
  30250. *
  30251. * bool sunday is for week ticks, shift it to a Sunday.
  30252. */
  30253. exports.dateTick0 = function(calendar, sunday) {
  30254. if(isWorldCalendar(calendar)) {
  30255. return sunday ?
  30256. Registry.getComponentMethod('calendars', 'CANONICAL_SUNDAY')[calendar] :
  30257. Registry.getComponentMethod('calendars', 'CANONICAL_TICK')[calendar];
  30258. }
  30259. else {
  30260. return sunday ? '2000-01-02' : '2000-01-01';
  30261. }
  30262. };
  30263. /*
  30264. * dfltRange: for each calendar, give a valid default range
  30265. */
  30266. exports.dfltRange = function(calendar) {
  30267. if(isWorldCalendar(calendar)) {
  30268. return Registry.getComponentMethod('calendars', 'DFLTRANGE')[calendar];
  30269. }
  30270. else {
  30271. return ['2000-01-01', '2001-01-01'];
  30272. }
  30273. };
  30274. // is an object a javascript date?
  30275. exports.isJSDate = function(v) {
  30276. return typeof v === 'object' && v !== null && typeof v.getTime === 'function';
  30277. };
  30278. // The absolute limits of our date-time system
  30279. // This is a little weird: we use MIN_MS and MAX_MS in dateTime2ms
  30280. // but we use dateTime2ms to calculate them (after defining it!)
  30281. var MIN_MS, MAX_MS;
  30282. /**
  30283. * dateTime2ms - turn a date object or string s into milliseconds
  30284. * (relative to 1970-01-01, per javascript standard)
  30285. * optional calendar (string) to use a non-gregorian calendar
  30286. *
  30287. * Returns BADNUM if it doesn't find a date
  30288. *
  30289. * strings should have the form:
  30290. *
  30291. * -?YYYY-mm-dd<sep>HH:MM:SS.sss<tzInfo>?
  30292. *
  30293. * <sep>: space (our normal standard) or T or t (ISO-8601)
  30294. * <tzInfo>: Z, z, or [+\-]HH:?MM and we THROW IT AWAY
  30295. * this format comes from https://tools.ietf.org/html/rfc3339#section-5.6
  30296. * but we allow it even with a space as the separator
  30297. *
  30298. * May truncate after any full field, and sss can be any length
  30299. * even >3 digits, though javascript dates truncate to milliseconds,
  30300. * we keep as much as javascript numeric precision can hold, but we only
  30301. * report back up to 100 microsecond precision, because most dates support
  30302. * this precision (close to 1970 support more, very far away support less)
  30303. *
  30304. * Expanded to support negative years to -9999 but you must always
  30305. * give 4 digits, except for 2-digit positive years which we assume are
  30306. * near the present time.
  30307. * Note that we follow ISO 8601:2004: there *is* a year 0, which
  30308. * is 1BC/BCE, and -1===2BC etc.
  30309. *
  30310. * World calendars: not all of these *have* agreed extensions to this full range,
  30311. * if you have another calendar system but want a date range outside its validity,
  30312. * you can use a gregorian date string prefixed with 'G' or 'g'.
  30313. *
  30314. * Where to cut off 2-digit years between 1900s and 2000s?
  30315. * from http://support.microsoft.com/kb/244664:
  30316. * 1930-2029 (the most retro of all...)
  30317. * but in my mac chrome from eg. d=new Date(Date.parse('8/19/50')):
  30318. * 1950-2049
  30319. * by Java, from http://stackoverflow.com/questions/2024273/:
  30320. * now-80 - now+19
  30321. * or FileMaker Pro, from
  30322. * http://www.filemaker.com/12help/html/add_view_data.4.21.html:
  30323. * now-70 - now+29
  30324. * but python strptime etc, via
  30325. * http://docs.python.org/py3k/library/time.html:
  30326. * 1969-2068 (super forward-looking, but static, not sliding!)
  30327. *
  30328. * lets go with now-70 to now+29, and if anyone runs into this problem
  30329. * they can learn the hard way not to use 2-digit years, as no choice we
  30330. * make now will cover all possibilities. mostly this will all be taken
  30331. * care of in initial parsing, should only be an issue for hand-entered data
  30332. * currently (2016) this range is:
  30333. * 1946-2045
  30334. */
  30335. exports.dateTime2ms = function(s, calendar) {
  30336. // first check if s is a date object
  30337. if(exports.isJSDate(s)) {
  30338. // Convert to the UTC milliseconds that give the same
  30339. // hours as this date has in the local timezone
  30340. var tzOffset = s.getTimezoneOffset() * ONEMIN;
  30341. var offsetTweak = (s.getUTCMinutes() - s.getMinutes()) * ONEMIN +
  30342. (s.getUTCSeconds() - s.getSeconds()) * ONESEC +
  30343. (s.getUTCMilliseconds() - s.getMilliseconds());
  30344. if(offsetTweak) {
  30345. var comb = 3 * ONEMIN;
  30346. tzOffset = tzOffset - comb / 2 + mod(offsetTweak - tzOffset + comb / 2, comb);
  30347. }
  30348. s = Number(s) - tzOffset;
  30349. if(s >= MIN_MS && s <= MAX_MS) return s;
  30350. return BADNUM;
  30351. }
  30352. // otherwise only accept strings and numbers
  30353. if(typeof s !== 'string' && typeof s !== 'number') return BADNUM;
  30354. s = String(s);
  30355. var isWorld = isWorldCalendar(calendar);
  30356. // to handle out-of-range dates in international calendars, accept
  30357. // 'G' as a prefix to force the built-in gregorian calendar.
  30358. var s0 = s.charAt(0);
  30359. if(isWorld && (s0 === 'G' || s0 === 'g')) {
  30360. s = s.substr(1);
  30361. calendar = '';
  30362. }
  30363. var isChinese = isWorld && calendar.substr(0, 7) === 'chinese';
  30364. var match = s.match(isChinese ? DATETIME_REGEXP_CN : DATETIME_REGEXP);
  30365. if(!match) return BADNUM;
  30366. var y = match[1],
  30367. m = match[3] || '1',
  30368. d = Number(match[5] || 1),
  30369. H = Number(match[7] || 0),
  30370. M = Number(match[9] || 0),
  30371. S = Number(match[11] || 0);
  30372. if(isWorld) {
  30373. // disallow 2-digit years for world calendars
  30374. if(y.length === 2) return BADNUM;
  30375. y = Number(y);
  30376. var cDate;
  30377. try {
  30378. var calInstance = Registry.getComponentMethod('calendars', 'getCal')(calendar);
  30379. if(isChinese) {
  30380. var isIntercalary = m.charAt(m.length - 1) === 'i';
  30381. m = parseInt(m, 10);
  30382. cDate = calInstance.newDate(y, calInstance.toMonthIndex(y, m, isIntercalary), d);
  30383. }
  30384. else {
  30385. cDate = calInstance.newDate(y, Number(m), d);
  30386. }
  30387. }
  30388. catch(e) { return BADNUM; } // Invalid ... date
  30389. if(!cDate) return BADNUM;
  30390. return ((cDate.toJD() - EPOCHJD) * ONEDAY) +
  30391. (H * ONEHOUR) + (M * ONEMIN) + (S * ONESEC);
  30392. }
  30393. if(y.length === 2) {
  30394. y = (Number(y) + 2000 - YFIRST) % 100 + YFIRST;
  30395. }
  30396. else y = Number(y);
  30397. // new Date uses months from 0; subtract 1 here just so we
  30398. // don't have to do it again during the validity test below
  30399. m -= 1;
  30400. // javascript takes new Date(0..99,m,d) to mean 1900-1999, so
  30401. // to support years 0-99 we need to use setFullYear explicitly
  30402. // Note that 2000 is a leap year.
  30403. var date = new Date(Date.UTC(2000, m, d, H, M));
  30404. date.setUTCFullYear(y);
  30405. if(date.getUTCMonth() !== m) return BADNUM;
  30406. if(date.getUTCDate() !== d) return BADNUM;
  30407. return date.getTime() + S * ONESEC;
  30408. };
  30409. MIN_MS = exports.MIN_MS = exports.dateTime2ms('-9999');
  30410. MAX_MS = exports.MAX_MS = exports.dateTime2ms('9999-12-31 23:59:59.9999');
  30411. // is string s a date? (see above)
  30412. exports.isDateTime = function(s, calendar) {
  30413. return (exports.dateTime2ms(s, calendar) !== BADNUM);
  30414. };
  30415. // pad a number with zeroes, to given # of digits before the decimal point
  30416. function lpad(val, digits) {
  30417. return String(val + Math.pow(10, digits)).substr(1);
  30418. }
  30419. /**
  30420. * Turn ms into string of the form YYYY-mm-dd HH:MM:SS.ssss
  30421. * Crop any trailing zeros in time, except never stop right after hours
  30422. * (we could choose to crop '-01' from date too but for now we always
  30423. * show the whole date)
  30424. * Optional range r is the data range that applies, also in ms.
  30425. * If rng is big, the later parts of time will be omitted
  30426. */
  30427. var NINETYDAYS = 90 * ONEDAY;
  30428. var THREEHOURS = 3 * ONEHOUR;
  30429. var FIVEMIN = 5 * ONEMIN;
  30430. exports.ms2DateTime = function(ms, r, calendar) {
  30431. if(typeof ms !== 'number' || !(ms >= MIN_MS && ms <= MAX_MS)) return BADNUM;
  30432. if(!r) r = 0;
  30433. var msecTenths = Math.floor(mod(ms + 0.05, 1) * 10),
  30434. msRounded = Math.round(ms - msecTenths / 10),
  30435. dateStr, h, m, s, msec10, d;
  30436. if(isWorldCalendar(calendar)) {
  30437. var dateJD = Math.floor(msRounded / ONEDAY) + EPOCHJD,
  30438. timeMs = Math.floor(mod(ms, ONEDAY));
  30439. try {
  30440. dateStr = Registry.getComponentMethod('calendars', 'getCal')(calendar)
  30441. .fromJD(dateJD).formatDate('yyyy-mm-dd');
  30442. }
  30443. catch(e) {
  30444. // invalid date in this calendar - fall back to Gyyyy-mm-dd
  30445. dateStr = utcFormat('G%Y-%m-%d')(new Date(msRounded));
  30446. }
  30447. // yyyy does NOT guarantee 4-digit years. YYYY mostly does, but does
  30448. // other things for a few calendars, so we can't trust it. Just pad
  30449. // it manually (after the '-' if there is one)
  30450. if(dateStr.charAt(0) === '-') {
  30451. while(dateStr.length < 11) dateStr = '-0' + dateStr.substr(1);
  30452. }
  30453. else {
  30454. while(dateStr.length < 10) dateStr = '0' + dateStr;
  30455. }
  30456. // TODO: if this is faster, we could use this block for extracting
  30457. // the time components of regular gregorian too
  30458. h = (r < NINETYDAYS) ? Math.floor(timeMs / ONEHOUR) : 0;
  30459. m = (r < NINETYDAYS) ? Math.floor((timeMs % ONEHOUR) / ONEMIN) : 0;
  30460. s = (r < THREEHOURS) ? Math.floor((timeMs % ONEMIN) / ONESEC) : 0;
  30461. msec10 = (r < FIVEMIN) ? (timeMs % ONESEC) * 10 + msecTenths : 0;
  30462. }
  30463. else {
  30464. d = new Date(msRounded);
  30465. dateStr = utcFormat('%Y-%m-%d')(d);
  30466. // <90 days: add hours and minutes - never *only* add hours
  30467. h = (r < NINETYDAYS) ? d.getUTCHours() : 0;
  30468. m = (r < NINETYDAYS) ? d.getUTCMinutes() : 0;
  30469. // <3 hours: add seconds
  30470. s = (r < THREEHOURS) ? d.getUTCSeconds() : 0;
  30471. // <5 minutes: add ms (plus one extra digit, this is msec*10)
  30472. msec10 = (r < FIVEMIN) ? d.getUTCMilliseconds() * 10 + msecTenths : 0;
  30473. }
  30474. return includeTime(dateStr, h, m, s, msec10);
  30475. };
  30476. // For converting old-style milliseconds to date strings,
  30477. // we use the local timezone rather than UTC like we use
  30478. // everywhere else, both for backward compatibility and
  30479. // because that's how people mostly use javasript date objects.
  30480. // Clip one extra day off our date range though so we can't get
  30481. // thrown beyond the range by the timezone shift.
  30482. exports.ms2DateTimeLocal = function(ms) {
  30483. if(!(ms >= MIN_MS + ONEDAY && ms <= MAX_MS - ONEDAY)) return BADNUM;
  30484. var msecTenths = Math.floor(mod(ms + 0.05, 1) * 10),
  30485. d = new Date(Math.round(ms - msecTenths / 10)),
  30486. dateStr = d3.time.format('%Y-%m-%d')(d),
  30487. h = d.getHours(),
  30488. m = d.getMinutes(),
  30489. s = d.getSeconds(),
  30490. msec10 = d.getUTCMilliseconds() * 10 + msecTenths;
  30491. return includeTime(dateStr, h, m, s, msec10);
  30492. };
  30493. function includeTime(dateStr, h, m, s, msec10) {
  30494. // include each part that has nonzero data in or after it
  30495. if(h || m || s || msec10) {
  30496. dateStr += ' ' + lpad(h, 2) + ':' + lpad(m, 2);
  30497. if(s || msec10) {
  30498. dateStr += ':' + lpad(s, 2);
  30499. if(msec10) {
  30500. var digits = 4;
  30501. while(msec10 % 10 === 0) {
  30502. digits -= 1;
  30503. msec10 /= 10;
  30504. }
  30505. dateStr += '.' + lpad(msec10, digits);
  30506. }
  30507. }
  30508. }
  30509. return dateStr;
  30510. }
  30511. // normalize date format to date string, in case it starts as
  30512. // a Date object or milliseconds
  30513. // optional dflt is the return value if cleaning fails
  30514. exports.cleanDate = function(v, dflt, calendar) {
  30515. if(exports.isJSDate(v) || typeof v === 'number') {
  30516. // do not allow milliseconds (old) or jsdate objects (inherently
  30517. // described as gregorian dates) with world calendars
  30518. if(isWorldCalendar(calendar)) {
  30519. Loggers.error('JS Dates and milliseconds are incompatible with world calendars', v);
  30520. return dflt;
  30521. }
  30522. // NOTE: if someone puts in a year as a number rather than a string,
  30523. // this will mistakenly convert it thinking it's milliseconds from 1970
  30524. // that is: '2012' -> Jan. 1, 2012, but 2012 -> 2012 epoch milliseconds
  30525. v = exports.ms2DateTimeLocal(+v);
  30526. if(!v && dflt !== undefined) return dflt;
  30527. }
  30528. else if(!exports.isDateTime(v, calendar)) {
  30529. Loggers.error('unrecognized date', v);
  30530. return dflt;
  30531. }
  30532. return v;
  30533. };
  30534. /*
  30535. * Date formatting for ticks and hovertext
  30536. */
  30537. /*
  30538. * modDateFormat: Support world calendars, and add one item to
  30539. * d3's vocabulary:
  30540. * %{n}f where n is the max number of digits of fractional seconds
  30541. */
  30542. var fracMatch = /%\d?f/g;
  30543. function modDateFormat(fmt, x, formatter, calendar) {
  30544. fmt = fmt.replace(fracMatch, function(match) {
  30545. var digits = Math.min(+(match.charAt(1)) || 6, 6),
  30546. fracSecs = ((x / 1000 % 1) + 2)
  30547. .toFixed(digits)
  30548. .substr(2).replace(/0+$/, '') || '0';
  30549. return fracSecs;
  30550. });
  30551. var d = new Date(Math.floor(x + 0.05));
  30552. if(isWorldCalendar(calendar)) {
  30553. try {
  30554. fmt = Registry.getComponentMethod('calendars', 'worldCalFmt')(fmt, x, calendar);
  30555. }
  30556. catch(e) {
  30557. return 'Invalid';
  30558. }
  30559. }
  30560. return formatter(fmt)(d);
  30561. }
  30562. /*
  30563. * formatTime: create a time string from:
  30564. * x: milliseconds
  30565. * tr: tickround ('M', 'S', or # digits)
  30566. * only supports UTC times (where every day is 24 hours and 0 is at midnight)
  30567. */
  30568. var MAXSECONDS = [59, 59.9, 59.99, 59.999, 59.9999];
  30569. function formatTime(x, tr) {
  30570. var timePart = mod(x + 0.05, ONEDAY);
  30571. var timeStr = lpad(Math.floor(timePart / ONEHOUR), 2) + ':' +
  30572. lpad(mod(Math.floor(timePart / ONEMIN), 60), 2);
  30573. if(tr !== 'M') {
  30574. if(!isNumeric(tr)) tr = 0; // should only be 'S'
  30575. /*
  30576. * this is a weird one - and shouldn't come up unless people
  30577. * monkey with tick0 in weird ways, but we need to do something!
  30578. * IN PARTICULAR we had better not display garbage (see below)
  30579. * for numbers we always round to the nearest increment of the
  30580. * precision we're showing, and this seems like the right way to
  30581. * handle seconds and milliseconds, as they have a decimal point
  30582. * and people will interpret that to mean rounding like numbers.
  30583. * but for larger increments we floor the value: it's always
  30584. * 2013 until the ball drops on the new year. We could argue about
  30585. * which field it is where we start rounding (should 12:08:59
  30586. * round to 12:09 if we're stopping at minutes?) but for now I'll
  30587. * say we round seconds but floor everything else. BUT that means
  30588. * we need to never round up to 60 seconds, ie 23:59:60
  30589. */
  30590. var sec = Math.min(mod(x / ONESEC, 60), MAXSECONDS[tr]);
  30591. var secStr = (100 + sec).toFixed(tr).substr(1);
  30592. if(tr > 0) {
  30593. secStr = secStr.replace(/0+$/, '').replace(/[\.]$/, '');
  30594. }
  30595. timeStr += ':' + secStr;
  30596. }
  30597. return timeStr;
  30598. }
  30599. /*
  30600. * formatDate: turn a date into tick or hover label text.
  30601. *
  30602. * x: milliseconds, the value to convert
  30603. * fmt: optional, an explicit format string (d3 format, even for world calendars)
  30604. * tr: tickround ('y', 'm', 'd', 'M', 'S', or # digits)
  30605. * used if no explicit fmt is provided
  30606. * formatter: locale-aware d3 date formatter for standard gregorian calendars
  30607. * should be the result of exports.getD3DateFormat(gd)
  30608. * calendar: optional string, the world calendar system to use
  30609. *
  30610. * returns the date/time as a string, potentially with the leading portion
  30611. * on a separate line (after '\n')
  30612. * Note that this means if you provide an explicit format which includes '\n'
  30613. * the axis may choose to strip things after it when they don't change from
  30614. * one tick to the next (as it does with automatic formatting)
  30615. */
  30616. exports.formatDate = function(x, fmt, tr, formatter, calendar, extraFormat) {
  30617. calendar = isWorldCalendar(calendar) && calendar;
  30618. if(!fmt) {
  30619. if(tr === 'y') fmt = extraFormat.year;
  30620. else if(tr === 'm') fmt = extraFormat.month;
  30621. else if(tr === 'd') {
  30622. fmt = extraFormat.dayMonth + '\n' + extraFormat.year;
  30623. }
  30624. else {
  30625. return formatTime(x, tr) + '\n' + modDateFormat(extraFormat.dayMonthYear, x, formatter, calendar);
  30626. }
  30627. }
  30628. return modDateFormat(fmt, x, formatter, calendar);
  30629. };
  30630. /*
  30631. * incrementMonth: make a new milliseconds value from the given one,
  30632. * having changed the month
  30633. *
  30634. * special case for world calendars: multiples of 12 are treated as years,
  30635. * even for calendar systems that don't have (always or ever) 12 months/year
  30636. * TODO: perhaps we need a different code for year increments to support this?
  30637. *
  30638. * ms (number): the initial millisecond value
  30639. * dMonth (int): the (signed) number of months to shift
  30640. * calendar (string): the calendar system to use
  30641. *
  30642. * changing month does not (and CANNOT) always preserve day, since
  30643. * months have different lengths. The worst example of this is:
  30644. * d = new Date(1970,0,31); d.setMonth(1) -> Feb 31 turns into Mar 3
  30645. *
  30646. * But we want to be able to iterate over the last day of each month,
  30647. * regardless of what its number is.
  30648. * So shift 3 days forward, THEN set the new month, then unshift:
  30649. * 1/31 -> 2/28 (or 29) -> 3/31 -> 4/30 -> ...
  30650. *
  30651. * Note that odd behavior still exists if you start from the 26th-28th:
  30652. * 1/28 -> 2/28 -> 3/31
  30653. * but at least you can't shift any dates into the wrong month,
  30654. * and ticks on these days incrementing by month would be very unusual
  30655. */
  30656. var THREEDAYS = 3 * ONEDAY;
  30657. exports.incrementMonth = function(ms, dMonth, calendar) {
  30658. calendar = isWorldCalendar(calendar) && calendar;
  30659. // pull time out and operate on pure dates, then add time back at the end
  30660. // this gives maximum precision - not that we *normally* care if we're
  30661. // incrementing by month, but better to be safe!
  30662. var timeMs = mod(ms, ONEDAY);
  30663. ms = Math.round(ms - timeMs);
  30664. if(calendar) {
  30665. try {
  30666. var dateJD = Math.round(ms / ONEDAY) + EPOCHJD,
  30667. calInstance = Registry.getComponentMethod('calendars', 'getCal')(calendar),
  30668. cDate = calInstance.fromJD(dateJD);
  30669. if(dMonth % 12) calInstance.add(cDate, dMonth, 'm');
  30670. else calInstance.add(cDate, dMonth / 12, 'y');
  30671. return (cDate.toJD() - EPOCHJD) * ONEDAY + timeMs;
  30672. }
  30673. catch(e) {
  30674. Loggers.error('invalid ms ' + ms + ' in calendar ' + calendar);
  30675. // then keep going in gregorian even though the result will be 'Invalid'
  30676. }
  30677. }
  30678. var y = new Date(ms + THREEDAYS);
  30679. return y.setUTCMonth(y.getUTCMonth() + dMonth) + timeMs - THREEDAYS;
  30680. };
  30681. /*
  30682. * findExactDates: what fraction of data is exact days, months, or years?
  30683. *
  30684. * data: array of millisecond values
  30685. * calendar (string) the calendar to test against
  30686. */
  30687. exports.findExactDates = function(data, calendar) {
  30688. var exactYears = 0,
  30689. exactMonths = 0,
  30690. exactDays = 0,
  30691. blankCount = 0,
  30692. d,
  30693. di;
  30694. var calInstance = (
  30695. isWorldCalendar(calendar) &&
  30696. Registry.getComponentMethod('calendars', 'getCal')(calendar)
  30697. );
  30698. for(var i = 0; i < data.length; i++) {
  30699. di = data[i];
  30700. // not date data at all
  30701. if(!isNumeric(di)) {
  30702. blankCount ++;
  30703. continue;
  30704. }
  30705. // not an exact date
  30706. if(di % ONEDAY) continue;
  30707. if(calInstance) {
  30708. try {
  30709. d = calInstance.fromJD(di / ONEDAY + EPOCHJD);
  30710. if(d.day() === 1) {
  30711. if(d.month() === 1) exactYears++;
  30712. else exactMonths++;
  30713. }
  30714. else exactDays++;
  30715. }
  30716. catch(e) {
  30717. // invalid date in this calendar - ignore it here.
  30718. }
  30719. }
  30720. else {
  30721. d = new Date(di);
  30722. if(d.getUTCDate() === 1) {
  30723. if(d.getUTCMonth() === 0) exactYears++;
  30724. else exactMonths++;
  30725. }
  30726. else exactDays++;
  30727. }
  30728. }
  30729. exactMonths += exactYears;
  30730. exactDays += exactMonths;
  30731. var dataCount = data.length - blankCount;
  30732. return {
  30733. exactYears: exactYears / dataCount,
  30734. exactMonths: exactMonths / dataCount,
  30735. exactDays: exactDays / dataCount
  30736. };
  30737. };
  30738. },{"../constants/numerical":151,"../registry":259,"./loggers":174,"./mod":177,"d3":16,"fast-isnumeric":18}],161:[function(_dereq_,module,exports){
  30739. /**
  30740. * Copyright 2012-2018, Plotly, Inc.
  30741. * All rights reserved.
  30742. *
  30743. * This source code is licensed under the MIT license found in the
  30744. * LICENSE file in the root directory of this source tree.
  30745. */
  30746. 'use strict';
  30747. /*
  30748. * Ensures an array has the right amount of storage space. If it doesn't
  30749. * exist, it creates an array. If it does exist, it returns it if too
  30750. * short or truncates it in-place.
  30751. *
  30752. * The goal is to just reuse memory to avoid a bit of excessive garbage
  30753. * collection.
  30754. */
  30755. module.exports = function ensureArray(out, n) {
  30756. if(!Array.isArray(out)) out = [];
  30757. // If too long, truncate. (If too short, it will grow
  30758. // automatically so we don't care about that case)
  30759. out.length = n;
  30760. return out;
  30761. };
  30762. },{}],162:[function(_dereq_,module,exports){
  30763. /**
  30764. * Copyright 2012-2018, Plotly, Inc.
  30765. * All rights reserved.
  30766. *
  30767. * This source code is licensed under the MIT license found in the
  30768. * LICENSE file in the root directory of this source tree.
  30769. */
  30770. 'use strict';
  30771. /* global jQuery:false */
  30772. var EventEmitter = _dereq_('events').EventEmitter;
  30773. var Events = {
  30774. init: function(plotObj) {
  30775. /*
  30776. * If we have already instantiated an emitter for this plot
  30777. * return early.
  30778. */
  30779. if(plotObj._ev instanceof EventEmitter) return plotObj;
  30780. var ev = new EventEmitter();
  30781. var internalEv = new EventEmitter();
  30782. /*
  30783. * Assign to plot._ev while we still live in a land
  30784. * where plot is a DOM element with stuff attached to it.
  30785. * In the future we can make plot the event emitter itself.
  30786. */
  30787. plotObj._ev = ev;
  30788. /*
  30789. * Create a second event handler that will manage events *internally*.
  30790. * This allows parts of plotly to respond to thing like relayout without
  30791. * having to use the user-facing event handler. They cannot peacefully
  30792. * coexist on the same handler because a user invoking
  30793. * plotObj.removeAllListeners() would detach internal events, breaking
  30794. * plotly.
  30795. */
  30796. plotObj._internalEv = internalEv;
  30797. /*
  30798. * Assign bound methods from the ev to the plot object. These methods
  30799. * will reference the 'this' of plot._ev even though they are methods
  30800. * of plot. This will keep the event machinery away from the plot object
  30801. * which currently is often a DOM element but presents an API that will
  30802. * continue to function when plot becomes an emitter. Not all EventEmitter
  30803. * methods have been bound to `plot` as some do not currently add value to
  30804. * the Plotly event API.
  30805. */
  30806. plotObj.on = ev.on.bind(ev);
  30807. plotObj.once = ev.once.bind(ev);
  30808. plotObj.removeListener = ev.removeListener.bind(ev);
  30809. plotObj.removeAllListeners = ev.removeAllListeners.bind(ev);
  30810. /*
  30811. * Create functions for managing internal events. These are *only* triggered
  30812. * by the mirroring of external events via the emit function.
  30813. */
  30814. plotObj._internalOn = internalEv.on.bind(internalEv);
  30815. plotObj._internalOnce = internalEv.once.bind(internalEv);
  30816. plotObj._removeInternalListener = internalEv.removeListener.bind(internalEv);
  30817. plotObj._removeAllInternalListeners = internalEv.removeAllListeners.bind(internalEv);
  30818. /*
  30819. * We must wrap emit to continue to support JQuery events. The idea
  30820. * is to check to see if the user is using JQuery events, if they are
  30821. * we emit JQuery events to trigger user handlers as well as the EventEmitter
  30822. * events.
  30823. */
  30824. plotObj.emit = function(event, data) {
  30825. if(typeof jQuery !== 'undefined') {
  30826. jQuery(plotObj).trigger(event, data);
  30827. }
  30828. ev.emit(event, data);
  30829. internalEv.emit(event, data);
  30830. };
  30831. return plotObj;
  30832. },
  30833. /*
  30834. * This function behaves like jQuery's triggerHandler. It calls
  30835. * all handlers for a particular event and returns the return value
  30836. * of the LAST handler. This function also triggers jQuery's
  30837. * triggerHandler for backwards compatibility.
  30838. */
  30839. triggerHandler: function(plotObj, event, data) {
  30840. var jQueryHandlerValue;
  30841. var nodeEventHandlerValue;
  30842. /*
  30843. * If jQuery exists run all its handlers for this event and
  30844. * collect the return value of the LAST handler function
  30845. */
  30846. if(typeof jQuery !== 'undefined') {
  30847. jQueryHandlerValue = jQuery(plotObj).triggerHandler(event, data);
  30848. }
  30849. /*
  30850. * Now run all the node style event handlers
  30851. */
  30852. var ev = plotObj._ev;
  30853. if(!ev) return jQueryHandlerValue;
  30854. var handlers = ev._events[event];
  30855. if(!handlers) return jQueryHandlerValue;
  30856. // making sure 'this' is the EventEmitter instance
  30857. function apply(handler) {
  30858. // The 'once' case, we can't just call handler() as we need
  30859. // the return value here. So,
  30860. // - remove handler
  30861. // - call listener and grab return value!
  30862. // - stash 'fired' key to not call handler twice
  30863. if(handler.listener) {
  30864. ev.removeListener(event, handler.listener);
  30865. if(!handler.fired) {
  30866. handler.fired = true;
  30867. return handler.listener.apply(ev, [data]);
  30868. }
  30869. } else {
  30870. return handler.apply(ev, [data]);
  30871. }
  30872. }
  30873. // handlers can be function or an array of functions
  30874. handlers = Array.isArray(handlers) ? handlers : [handlers];
  30875. var i;
  30876. for(i = 0; i < handlers.length - 1; i++) {
  30877. apply(handlers[i]);
  30878. }
  30879. // now call the final handler and collect its value
  30880. nodeEventHandlerValue = apply(handlers[i]);
  30881. /*
  30882. * Return either the jQuery handler value if it exists or the
  30883. * nodeEventHandler value. jQuery event value supersedes nodejs
  30884. * events for backwards compatibility reasons.
  30885. */
  30886. return jQueryHandlerValue !== undefined ?
  30887. jQueryHandlerValue :
  30888. nodeEventHandlerValue;
  30889. },
  30890. purge: function(plotObj) {
  30891. delete plotObj._ev;
  30892. delete plotObj.on;
  30893. delete plotObj.once;
  30894. delete plotObj.removeListener;
  30895. delete plotObj.removeAllListeners;
  30896. delete plotObj.emit;
  30897. delete plotObj._ev;
  30898. delete plotObj._internalEv;
  30899. delete plotObj._internalOn;
  30900. delete plotObj._internalOnce;
  30901. delete plotObj._removeInternalListener;
  30902. delete plotObj._removeAllInternalListeners;
  30903. return plotObj;
  30904. }
  30905. };
  30906. module.exports = Events;
  30907. },{"events":15}],163:[function(_dereq_,module,exports){
  30908. /**
  30909. * Copyright 2012-2018, Plotly, Inc.
  30910. * All rights reserved.
  30911. *
  30912. * This source code is licensed under the MIT license found in the
  30913. * LICENSE file in the root directory of this source tree.
  30914. */
  30915. 'use strict';
  30916. var isPlainObject = _dereq_('./is_plain_object.js');
  30917. var isArray = Array.isArray;
  30918. function primitivesLoopSplice(source, target) {
  30919. var i, value;
  30920. for(i = 0; i < source.length; i++) {
  30921. value = source[i];
  30922. if(value !== null && typeof(value) === 'object') {
  30923. return false;
  30924. }
  30925. if(value !== void(0)) {
  30926. target[i] = value;
  30927. }
  30928. }
  30929. return true;
  30930. }
  30931. exports.extendFlat = function() {
  30932. return _extend(arguments, false, false, false);
  30933. };
  30934. exports.extendDeep = function() {
  30935. return _extend(arguments, true, false, false);
  30936. };
  30937. exports.extendDeepAll = function() {
  30938. return _extend(arguments, true, true, false);
  30939. };
  30940. exports.extendDeepNoArrays = function() {
  30941. return _extend(arguments, true, false, true);
  30942. };
  30943. /*
  30944. * Inspired by https://github.com/justmoon/node-extend/blob/master/index.js
  30945. * All credit to the jQuery authors for perfecting this amazing utility.
  30946. *
  30947. * API difference with jQuery version:
  30948. * - No optional boolean (true -> deep extend) first argument,
  30949. * use `extendFlat` for first-level only extend and
  30950. * use `extendDeep` for a deep extend.
  30951. *
  30952. * Other differences with jQuery version:
  30953. * - Uses a modern (and faster) isPlainObject routine.
  30954. * - Expected to work with object {} and array [] arguments only.
  30955. * - Does not check for circular structure.
  30956. * FYI: jQuery only does a check across one level.
  30957. * Warning: this might result in infinite loops.
  30958. *
  30959. */
  30960. function _extend(inputs, isDeep, keepAllKeys, noArrayCopies) {
  30961. var target = inputs[0],
  30962. length = inputs.length;
  30963. var input, key, src, copy, copyIsArray, clone, allPrimitives;
  30964. // TODO does this do the right thing for typed arrays?
  30965. if(length === 2 && isArray(target) && isArray(inputs[1]) && target.length === 0) {
  30966. allPrimitives = primitivesLoopSplice(inputs[1], target);
  30967. if(allPrimitives) {
  30968. return target;
  30969. } else {
  30970. target.splice(0, target.length); // reset target and continue to next block
  30971. }
  30972. }
  30973. for(var i = 1; i < length; i++) {
  30974. input = inputs[i];
  30975. for(key in input) {
  30976. src = target[key];
  30977. copy = input[key];
  30978. // Stop early and just transfer the array if array copies are disallowed:
  30979. if(noArrayCopies && isArray(copy)) {
  30980. target[key] = copy;
  30981. }
  30982. // recurse if we're merging plain objects or arrays
  30983. else if(isDeep && copy && (isPlainObject(copy) || (copyIsArray = isArray(copy)))) {
  30984. if(copyIsArray) {
  30985. copyIsArray = false;
  30986. clone = src && isArray(src) ? src : [];
  30987. } else {
  30988. clone = src && isPlainObject(src) ? src : {};
  30989. }
  30990. // never move original objects, clone them
  30991. target[key] = _extend([clone, copy], isDeep, keepAllKeys, noArrayCopies);
  30992. }
  30993. // don't bring in undefined values, except for extendDeepAll
  30994. else if(typeof copy !== 'undefined' || keepAllKeys) {
  30995. target[key] = copy;
  30996. }
  30997. }
  30998. }
  30999. return target;
  31000. }
  31001. },{"./is_plain_object.js":171}],164:[function(_dereq_,module,exports){
  31002. /**
  31003. * Copyright 2012-2018, Plotly, Inc.
  31004. * All rights reserved.
  31005. *
  31006. * This source code is licensed under the MIT license found in the
  31007. * LICENSE file in the root directory of this source tree.
  31008. */
  31009. 'use strict';
  31010. /**
  31011. * Return news array containing only the unique items
  31012. * found in input array.
  31013. *
  31014. * IMPORTANT: Note that items are considered unique
  31015. * if `String({})` is unique. For example;
  31016. *
  31017. * Lib.filterUnique([ { a: 1 }, { b: 2 } ])
  31018. *
  31019. * returns [{ a: 1 }]
  31020. *
  31021. * and
  31022. *
  31023. * Lib.filterUnique([ '1', 1 ])
  31024. *
  31025. * returns ['1']
  31026. *
  31027. *
  31028. * @param {array} array base array
  31029. * @return {array} new filtered array
  31030. */
  31031. module.exports = function filterUnique(array) {
  31032. var seen = {},
  31033. out = [],
  31034. j = 0;
  31035. for(var i = 0; i < array.length; i++) {
  31036. var item = array[i];
  31037. if(seen[item] !== 1) {
  31038. seen[item] = 1;
  31039. out[j++] = item;
  31040. }
  31041. }
  31042. return out;
  31043. };
  31044. },{}],165:[function(_dereq_,module,exports){
  31045. /**
  31046. * Copyright 2012-2018, Plotly, Inc.
  31047. * All rights reserved.
  31048. *
  31049. * This source code is licensed under the MIT license found in the
  31050. * LICENSE file in the root directory of this source tree.
  31051. */
  31052. 'use strict';
  31053. /** Filter out object items with visible !== true
  31054. * insider array container.
  31055. *
  31056. * @param {array of objects} container
  31057. * @return {array of objects} of length <= container
  31058. *
  31059. */
  31060. module.exports = function filterVisible(container) {
  31061. var filterFn = isCalcData(container) ? calcDataFilter : baseFilter;
  31062. var out = [];
  31063. for(var i = 0; i < container.length; i++) {
  31064. var item = container[i];
  31065. if(filterFn(item)) out.push(item);
  31066. }
  31067. return out;
  31068. };
  31069. function baseFilter(item) {
  31070. return item.visible === true;
  31071. }
  31072. function calcDataFilter(item) {
  31073. return item[0].trace.visible === true;
  31074. }
  31075. function isCalcData(cont) {
  31076. return (
  31077. Array.isArray(cont) &&
  31078. Array.isArray(cont[0]) &&
  31079. cont[0][0] &&
  31080. cont[0][0].trace
  31081. );
  31082. }
  31083. },{}],166:[function(_dereq_,module,exports){
  31084. /**
  31085. * Copyright 2012-2018, Plotly, Inc.
  31086. * All rights reserved.
  31087. *
  31088. * This source code is licensed under the MIT license found in the
  31089. * LICENSE file in the root directory of this source tree.
  31090. */
  31091. 'use strict';
  31092. var mod = _dereq_('./mod').mod;
  31093. /*
  31094. * look for intersection of two line segments
  31095. * (1->2 and 3->4) - returns array [x,y] if they do, null if not
  31096. */
  31097. exports.segmentsIntersect = segmentsIntersect;
  31098. function segmentsIntersect(x1, y1, x2, y2, x3, y3, x4, y4) {
  31099. var a = x2 - x1,
  31100. b = x3 - x1,
  31101. c = x4 - x3,
  31102. d = y2 - y1,
  31103. e = y3 - y1,
  31104. f = y4 - y3,
  31105. det = a * f - c * d;
  31106. // parallel lines? intersection is undefined
  31107. // ignore the case where they are colinear
  31108. if(det === 0) return null;
  31109. var t = (b * f - c * e) / det,
  31110. u = (b * d - a * e) / det;
  31111. // segments do not intersect?
  31112. if(u < 0 || u > 1 || t < 0 || t > 1) return null;
  31113. return {x: x1 + a * t, y: y1 + d * t};
  31114. }
  31115. /*
  31116. * find the minimum distance between two line segments (1->2 and 3->4)
  31117. */
  31118. exports.segmentDistance = function segmentDistance(x1, y1, x2, y2, x3, y3, x4, y4) {
  31119. if(segmentsIntersect(x1, y1, x2, y2, x3, y3, x4, y4)) return 0;
  31120. // the two segments and their lengths squared
  31121. var x12 = x2 - x1;
  31122. var y12 = y2 - y1;
  31123. var x34 = x4 - x3;
  31124. var y34 = y4 - y3;
  31125. var l2_12 = x12 * x12 + y12 * y12;
  31126. var l2_34 = x34 * x34 + y34 * y34;
  31127. // calculate distance squared, then take the sqrt at the very end
  31128. var dist2 = Math.min(
  31129. perpDistance2(x12, y12, l2_12, x3 - x1, y3 - y1),
  31130. perpDistance2(x12, y12, l2_12, x4 - x1, y4 - y1),
  31131. perpDistance2(x34, y34, l2_34, x1 - x3, y1 - y3),
  31132. perpDistance2(x34, y34, l2_34, x2 - x3, y2 - y3)
  31133. );
  31134. return Math.sqrt(dist2);
  31135. };
  31136. /*
  31137. * distance squared from segment ab to point c
  31138. * [xab, yab] is the vector b-a
  31139. * [xac, yac] is the vector c-a
  31140. * l2_ab is the length squared of (b-a), just to simplify calculation
  31141. */
  31142. function perpDistance2(xab, yab, l2_ab, xac, yac) {
  31143. var fc_ab = (xac * xab + yac * yab);
  31144. if(fc_ab < 0) {
  31145. // point c is closer to point a
  31146. return xac * xac + yac * yac;
  31147. }
  31148. else if(fc_ab > l2_ab) {
  31149. // point c is closer to point b
  31150. var xbc = xac - xab;
  31151. var ybc = yac - yab;
  31152. return xbc * xbc + ybc * ybc;
  31153. }
  31154. else {
  31155. // perpendicular distance is the shortest
  31156. var crossProduct = xac * yab - yac * xab;
  31157. return crossProduct * crossProduct / l2_ab;
  31158. }
  31159. }
  31160. // a very short-term cache for getTextLocation, just because
  31161. // we're often looping over the same locations multiple times
  31162. // invalidated as soon as we look at a different path
  31163. var locationCache, workingPath, workingTextWidth;
  31164. // turn a path and position along it into x, y, and angle for the given text
  31165. exports.getTextLocation = function getTextLocation(path, totalPathLen, positionOnPath, textWidth) {
  31166. if(path !== workingPath || textWidth !== workingTextWidth) {
  31167. locationCache = {};
  31168. workingPath = path;
  31169. workingTextWidth = textWidth;
  31170. }
  31171. if(locationCache[positionOnPath]) {
  31172. return locationCache[positionOnPath];
  31173. }
  31174. // for the angle, use points on the path separated by the text width
  31175. // even though due to curvature, the text will cover a bit more than that
  31176. var p0 = path.getPointAtLength(mod(positionOnPath - textWidth / 2, totalPathLen));
  31177. var p1 = path.getPointAtLength(mod(positionOnPath + textWidth / 2, totalPathLen));
  31178. // note: atan handles 1/0 nicely
  31179. var theta = Math.atan((p1.y - p0.y) / (p1.x - p0.x));
  31180. // center the text at 2/3 of the center position plus 1/3 the p0/p1 midpoint
  31181. // that's the average position of this segment, assuming it's roughly quadratic
  31182. var pCenter = path.getPointAtLength(mod(positionOnPath, totalPathLen));
  31183. var x = (pCenter.x * 4 + p0.x + p1.x) / 6;
  31184. var y = (pCenter.y * 4 + p0.y + p1.y) / 6;
  31185. var out = {x: x, y: y, theta: theta};
  31186. locationCache[positionOnPath] = out;
  31187. return out;
  31188. };
  31189. exports.clearLocationCache = function() {
  31190. workingPath = null;
  31191. };
  31192. /*
  31193. * Find the segment of `path` that's within the visible area
  31194. * given by `bounds` {left, right, top, bottom}, to within a
  31195. * precision of `buffer` px
  31196. *
  31197. * returns: undefined if nothing is visible, else object:
  31198. * {
  31199. * min: position where the path first enters bounds, or 0 if it
  31200. * starts within bounds
  31201. * max: position where the path last exits bounds, or the path length
  31202. * if it finishes within bounds
  31203. * len: max - min, ie the length of visible path
  31204. * total: the total path length - just included so the caller doesn't
  31205. * need to call path.getTotalLength() again
  31206. * isClosed: true iff the start and end points of the path are both visible
  31207. * and are at the same point
  31208. * }
  31209. *
  31210. * Works by starting from either end and repeatedly finding the distance from
  31211. * that point to the plot area, and if it's outside the plot, moving along the
  31212. * path by that distance (because the plot must be at least that far away on
  31213. * the path). Note that if a path enters, exits, and re-enters the plot, we
  31214. * will not capture this behavior.
  31215. */
  31216. exports.getVisibleSegment = function getVisibleSegment(path, bounds, buffer) {
  31217. var left = bounds.left;
  31218. var right = bounds.right;
  31219. var top = bounds.top;
  31220. var bottom = bounds.bottom;
  31221. var pMin = 0;
  31222. var pTotal = path.getTotalLength();
  31223. var pMax = pTotal;
  31224. var pt0, ptTotal;
  31225. function getDistToPlot(len) {
  31226. var pt = path.getPointAtLength(len);
  31227. // hold on to the start and end points for `closed`
  31228. if(len === 0) pt0 = pt;
  31229. else if(len === pTotal) ptTotal = pt;
  31230. var dx = (pt.x < left) ? left - pt.x : (pt.x > right ? pt.x - right : 0);
  31231. var dy = (pt.y < top) ? top - pt.y : (pt.y > bottom ? pt.y - bottom : 0);
  31232. return Math.sqrt(dx * dx + dy * dy);
  31233. }
  31234. var distToPlot = getDistToPlot(pMin);
  31235. while(distToPlot) {
  31236. pMin += distToPlot + buffer;
  31237. if(pMin > pMax) return;
  31238. distToPlot = getDistToPlot(pMin);
  31239. }
  31240. distToPlot = getDistToPlot(pMax);
  31241. while(distToPlot) {
  31242. pMax -= distToPlot + buffer;
  31243. if(pMin > pMax) return;
  31244. distToPlot = getDistToPlot(pMax);
  31245. }
  31246. return {
  31247. min: pMin,
  31248. max: pMax,
  31249. len: pMax - pMin,
  31250. total: pTotal,
  31251. isClosed: pMin === 0 && pMax === pTotal &&
  31252. Math.abs(pt0.x - ptTotal.x) < 0.1 &&
  31253. Math.abs(pt0.y - ptTotal.y) < 0.1
  31254. };
  31255. };
  31256. /**
  31257. * Find point on SVG path corresponding to a given constraint coordinate
  31258. *
  31259. * @param {SVGPathElement} path
  31260. * @param {Number} val : constraint coordinate value
  31261. * @param {String} coord : 'x' or 'y' the constraint coordinate
  31262. * @param {Object} opts :
  31263. * - {Number} pathLength : supply total path length before hand
  31264. * - {Number} tolerance
  31265. * - {Number} iterationLimit
  31266. * @return {SVGPoint}
  31267. */
  31268. exports.findPointOnPath = function findPointOnPath(path, val, coord, opts) {
  31269. opts = opts || {};
  31270. var pathLength = opts.pathLength || path.getTotalLength();
  31271. var tolerance = opts.tolerance || 1e-3;
  31272. var iterationLimit = opts.iterationLimit || 30;
  31273. // if path starts at a val greater than the path tail (like on vertical violins),
  31274. // we must flip the sign of the computed diff.
  31275. var mul = path.getPointAtLength(0)[coord] > path.getPointAtLength(pathLength)[coord] ? -1 : 1;
  31276. var i = 0;
  31277. var b0 = 0;
  31278. var b1 = pathLength;
  31279. var mid;
  31280. var pt;
  31281. var diff;
  31282. while(i < iterationLimit) {
  31283. mid = (b0 + b1) / 2;
  31284. pt = path.getPointAtLength(mid);
  31285. diff = pt[coord] - val;
  31286. if(Math.abs(diff) < tolerance) {
  31287. return pt;
  31288. } else {
  31289. if(mul * diff > 0) {
  31290. b1 = mid;
  31291. } else {
  31292. b0 = mid;
  31293. }
  31294. i++;
  31295. }
  31296. }
  31297. return pt;
  31298. };
  31299. },{"./mod":177}],167:[function(_dereq_,module,exports){
  31300. /**
  31301. * Copyright 2012-2018, Plotly, Inc.
  31302. * All rights reserved.
  31303. *
  31304. * This source code is licensed under the MIT license found in the
  31305. * LICENSE file in the root directory of this source tree.
  31306. */
  31307. 'use strict';
  31308. /**
  31309. * Allow referencing a graph DOM element either directly
  31310. * or by its id string
  31311. *
  31312. * @param {HTMLDivElement|string} gd: a graph element or its id
  31313. *
  31314. * @returns {HTMLDivElement} the DOM element of the graph
  31315. */
  31316. module.exports = function(gd) {
  31317. var gdElement;
  31318. if(typeof gd === 'string') {
  31319. gdElement = document.getElementById(gd);
  31320. if(gdElement === null) {
  31321. throw new Error('No DOM element with id \'' + gd + '\' exists on the page.');
  31322. }
  31323. return gdElement;
  31324. }
  31325. else if(gd === null || gd === undefined) {
  31326. throw new Error('DOM element provided is null or undefined');
  31327. }
  31328. return gd; // otherwise assume that gd is a DOM element
  31329. };
  31330. },{}],168:[function(_dereq_,module,exports){
  31331. /**
  31332. * Copyright 2012-2018, Plotly, Inc.
  31333. * All rights reserved.
  31334. *
  31335. * This source code is licensed under the MIT license found in the
  31336. * LICENSE file in the root directory of this source tree.
  31337. */
  31338. 'use strict';
  31339. // Simple helper functions
  31340. // none of these need any external deps
  31341. module.exports = function identity(d) { return d; };
  31342. },{}],169:[function(_dereq_,module,exports){
  31343. /**
  31344. * Copyright 2012-2018, Plotly, Inc.
  31345. * All rights reserved.
  31346. *
  31347. * This source code is licensed under the MIT license found in the
  31348. * LICENSE file in the root directory of this source tree.
  31349. */
  31350. 'use strict';
  31351. var d3 = _dereq_('d3');
  31352. var isNumeric = _dereq_('fast-isnumeric');
  31353. var numConstants = _dereq_('../constants/numerical');
  31354. var FP_SAFE = numConstants.FP_SAFE;
  31355. var BADNUM = numConstants.BADNUM;
  31356. var lib = module.exports = {};
  31357. lib.nestedProperty = _dereq_('./nested_property');
  31358. lib.keyedContainer = _dereq_('./keyed_container');
  31359. lib.relativeAttr = _dereq_('./relative_attr');
  31360. lib.isPlainObject = _dereq_('./is_plain_object');
  31361. lib.toLogRange = _dereq_('./to_log_range');
  31362. lib.relinkPrivateKeys = _dereq_('./relink_private');
  31363. lib.ensureArray = _dereq_('./ensure_array');
  31364. var modModule = _dereq_('./mod');
  31365. lib.mod = modModule.mod;
  31366. lib.modHalf = modModule.modHalf;
  31367. var isArrayModule = _dereq_('./is_array');
  31368. lib.isTypedArray = isArrayModule.isTypedArray;
  31369. lib.isArrayOrTypedArray = isArrayModule.isArrayOrTypedArray;
  31370. lib.isArray1D = isArrayModule.isArray1D;
  31371. var coerceModule = _dereq_('./coerce');
  31372. lib.valObjectMeta = coerceModule.valObjectMeta;
  31373. lib.coerce = coerceModule.coerce;
  31374. lib.coerce2 = coerceModule.coerce2;
  31375. lib.coerceFont = coerceModule.coerceFont;
  31376. lib.coerceHoverinfo = coerceModule.coerceHoverinfo;
  31377. lib.coerceSelectionMarkerOpacity = coerceModule.coerceSelectionMarkerOpacity;
  31378. lib.validate = coerceModule.validate;
  31379. var datesModule = _dereq_('./dates');
  31380. lib.dateTime2ms = datesModule.dateTime2ms;
  31381. lib.isDateTime = datesModule.isDateTime;
  31382. lib.ms2DateTime = datesModule.ms2DateTime;
  31383. lib.ms2DateTimeLocal = datesModule.ms2DateTimeLocal;
  31384. lib.cleanDate = datesModule.cleanDate;
  31385. lib.isJSDate = datesModule.isJSDate;
  31386. lib.formatDate = datesModule.formatDate;
  31387. lib.incrementMonth = datesModule.incrementMonth;
  31388. lib.dateTick0 = datesModule.dateTick0;
  31389. lib.dfltRange = datesModule.dfltRange;
  31390. lib.findExactDates = datesModule.findExactDates;
  31391. lib.MIN_MS = datesModule.MIN_MS;
  31392. lib.MAX_MS = datesModule.MAX_MS;
  31393. var searchModule = _dereq_('./search');
  31394. lib.findBin = searchModule.findBin;
  31395. lib.sorterAsc = searchModule.sorterAsc;
  31396. lib.sorterDes = searchModule.sorterDes;
  31397. lib.distinctVals = searchModule.distinctVals;
  31398. lib.roundUp = searchModule.roundUp;
  31399. lib.sort = searchModule.sort;
  31400. lib.findIndexOfMin = searchModule.findIndexOfMin;
  31401. var statsModule = _dereq_('./stats');
  31402. lib.aggNums = statsModule.aggNums;
  31403. lib.len = statsModule.len;
  31404. lib.mean = statsModule.mean;
  31405. lib.midRange = statsModule.midRange;
  31406. lib.variance = statsModule.variance;
  31407. lib.stdev = statsModule.stdev;
  31408. lib.interp = statsModule.interp;
  31409. var matrixModule = _dereq_('./matrix');
  31410. lib.init2dArray = matrixModule.init2dArray;
  31411. lib.transposeRagged = matrixModule.transposeRagged;
  31412. lib.dot = matrixModule.dot;
  31413. lib.translationMatrix = matrixModule.translationMatrix;
  31414. lib.rotationMatrix = matrixModule.rotationMatrix;
  31415. lib.rotationXYMatrix = matrixModule.rotationXYMatrix;
  31416. lib.apply2DTransform = matrixModule.apply2DTransform;
  31417. lib.apply2DTransform2 = matrixModule.apply2DTransform2;
  31418. var anglesModule = _dereq_('./angles');
  31419. lib.deg2rad = anglesModule.deg2rad;
  31420. lib.rad2deg = anglesModule.rad2deg;
  31421. lib.angleDelta = anglesModule.angleDelta;
  31422. lib.angleDist = anglesModule.angleDist;
  31423. lib.isFullCircle = anglesModule.isFullCircle;
  31424. lib.isAngleInsideSector = anglesModule.isAngleInsideSector;
  31425. lib.isPtInsideSector = anglesModule.isPtInsideSector;
  31426. lib.pathArc = anglesModule.pathArc;
  31427. lib.pathSector = anglesModule.pathSector;
  31428. lib.pathAnnulus = anglesModule.pathAnnulus;
  31429. var geom2dModule = _dereq_('./geometry2d');
  31430. lib.segmentsIntersect = geom2dModule.segmentsIntersect;
  31431. lib.segmentDistance = geom2dModule.segmentDistance;
  31432. lib.getTextLocation = geom2dModule.getTextLocation;
  31433. lib.clearLocationCache = geom2dModule.clearLocationCache;
  31434. lib.getVisibleSegment = geom2dModule.getVisibleSegment;
  31435. lib.findPointOnPath = geom2dModule.findPointOnPath;
  31436. var extendModule = _dereq_('./extend');
  31437. lib.extendFlat = extendModule.extendFlat;
  31438. lib.extendDeep = extendModule.extendDeep;
  31439. lib.extendDeepAll = extendModule.extendDeepAll;
  31440. lib.extendDeepNoArrays = extendModule.extendDeepNoArrays;
  31441. var loggersModule = _dereq_('./loggers');
  31442. lib.log = loggersModule.log;
  31443. lib.warn = loggersModule.warn;
  31444. lib.error = loggersModule.error;
  31445. var regexModule = _dereq_('./regex');
  31446. lib.counterRegex = regexModule.counter;
  31447. var throttleModule = _dereq_('./throttle');
  31448. lib.throttle = throttleModule.throttle;
  31449. lib.throttleDone = throttleModule.done;
  31450. lib.clearThrottle = throttleModule.clear;
  31451. lib.getGraphDiv = _dereq_('./get_graph_div');
  31452. lib.clearResponsive = _dereq_('./clear_responsive');
  31453. lib.makeTraceGroups = _dereq_('./make_trace_groups');
  31454. lib._ = _dereq_('./localize');
  31455. lib.notifier = _dereq_('./notifier');
  31456. lib.filterUnique = _dereq_('./filter_unique');
  31457. lib.filterVisible = _dereq_('./filter_visible');
  31458. lib.pushUnique = _dereq_('./push_unique');
  31459. lib.cleanNumber = _dereq_('./clean_number');
  31460. lib.ensureNumber = function num(v) {
  31461. if(!isNumeric(v)) return BADNUM;
  31462. v = Number(v);
  31463. if(v < -FP_SAFE || v > FP_SAFE) return BADNUM;
  31464. return isNumeric(v) ? Number(v) : BADNUM;
  31465. };
  31466. /**
  31467. * Is v a valid array index? Accepts numeric strings as well as numbers.
  31468. *
  31469. * @param {any} v: the value to test
  31470. * @param {Optional[integer]} len: the array length we are indexing
  31471. *
  31472. * @return {bool}: v is a valid array index
  31473. */
  31474. lib.isIndex = function(v, len) {
  31475. if(len !== undefined && v >= len) return false;
  31476. return isNumeric(v) && (v >= 0) && (v % 1 === 0);
  31477. };
  31478. lib.noop = _dereq_('./noop');
  31479. lib.identity = _dereq_('./identity');
  31480. /**
  31481. * create an array of length 'cnt' filled with 'v' at all indices
  31482. *
  31483. * @param {any} v
  31484. * @param {number} cnt
  31485. * @return {array}
  31486. */
  31487. lib.repeat = function(v, cnt) {
  31488. var out = new Array(cnt);
  31489. for(var i = 0; i < cnt; i++) {
  31490. out[i] = v;
  31491. }
  31492. return out;
  31493. };
  31494. /**
  31495. * swap x and y of the same attribute in container cont
  31496. * specify attr with a ? in place of x/y
  31497. * you can also swap other things than x/y by providing part1 and part2
  31498. */
  31499. lib.swapAttrs = function(cont, attrList, part1, part2) {
  31500. if(!part1) part1 = 'x';
  31501. if(!part2) part2 = 'y';
  31502. for(var i = 0; i < attrList.length; i++) {
  31503. var attr = attrList[i],
  31504. xp = lib.nestedProperty(cont, attr.replace('?', part1)),
  31505. yp = lib.nestedProperty(cont, attr.replace('?', part2)),
  31506. temp = xp.get();
  31507. xp.set(yp.get());
  31508. yp.set(temp);
  31509. }
  31510. };
  31511. /**
  31512. * SVG painter's algo worked around with reinsertion
  31513. */
  31514. lib.raiseToTop = function raiseToTop(elem) {
  31515. elem.parentNode.appendChild(elem);
  31516. };
  31517. /**
  31518. * cancel a possibly pending transition; returned selection may be used by caller
  31519. */
  31520. lib.cancelTransition = function(selection) {
  31521. return selection.transition().duration(0);
  31522. };
  31523. // constrain - restrict a number v to be between v0 and v1
  31524. lib.constrain = function(v, v0, v1) {
  31525. if(v0 > v1) return Math.max(v1, Math.min(v0, v));
  31526. return Math.max(v0, Math.min(v1, v));
  31527. };
  31528. /**
  31529. * do two bounding boxes from getBoundingClientRect,
  31530. * ie {left,right,top,bottom,width,height}, overlap?
  31531. * takes optional padding pixels
  31532. */
  31533. lib.bBoxIntersect = function(a, b, pad) {
  31534. pad = pad || 0;
  31535. return (a.left <= b.right + pad &&
  31536. b.left <= a.right + pad &&
  31537. a.top <= b.bottom + pad &&
  31538. b.top <= a.bottom + pad);
  31539. };
  31540. /*
  31541. * simpleMap: alternative to Array.map that only
  31542. * passes on the element and up to 2 extra args you
  31543. * provide (but not the array index or the whole array)
  31544. *
  31545. * array: the array to map it to
  31546. * func: the function to apply
  31547. * x1, x2: optional extra args
  31548. */
  31549. lib.simpleMap = function(array, func, x1, x2) {
  31550. var len = array.length,
  31551. out = new Array(len);
  31552. for(var i = 0; i < len; i++) out[i] = func(array[i], x1, x2);
  31553. return out;
  31554. };
  31555. /**
  31556. * Random string generator
  31557. *
  31558. * @param {object} existing
  31559. * pass in strings to avoid as keys with truthy values
  31560. * @param {int} bits
  31561. * bits of information in the output string, default 24
  31562. * @param {int} base
  31563. * base of string representation, default 16. Should be a power of 2.
  31564. */
  31565. lib.randstr = function randstr(existing, bits, base, _recursion) {
  31566. if(!base) base = 16;
  31567. if(bits === undefined) bits = 24;
  31568. if(bits <= 0) return '0';
  31569. var digits = Math.log(Math.pow(2, bits)) / Math.log(base);
  31570. var res = '';
  31571. var i, b, x;
  31572. for(i = 2; digits === Infinity; i *= 2) {
  31573. digits = Math.log(Math.pow(2, bits / i)) / Math.log(base) * i;
  31574. }
  31575. var rem = digits - Math.floor(digits);
  31576. for(i = 0; i < Math.floor(digits); i++) {
  31577. x = Math.floor(Math.random() * base).toString(base);
  31578. res = x + res;
  31579. }
  31580. if(rem) {
  31581. b = Math.pow(base, rem);
  31582. x = Math.floor(Math.random() * b).toString(base);
  31583. res = x + res;
  31584. }
  31585. var parsed = parseInt(res, base);
  31586. if((existing && existing[res]) ||
  31587. (parsed !== Infinity && parsed >= Math.pow(2, bits))) {
  31588. if(_recursion > 10) {
  31589. lib.warn('randstr failed uniqueness');
  31590. return res;
  31591. }
  31592. return randstr(existing, bits, base, (_recursion || 0) + 1);
  31593. }
  31594. else return res;
  31595. };
  31596. lib.OptionControl = function(opt, optname) {
  31597. /*
  31598. * An environment to contain all option setters and
  31599. * getters that collectively modify opts.
  31600. *
  31601. * You can call up opts from any function in new object
  31602. * as this.optname || this.opt
  31603. *
  31604. * See FitOpts for example of usage
  31605. */
  31606. if(!opt) opt = {};
  31607. if(!optname) optname = 'opt';
  31608. var self = {};
  31609. self.optionList = [];
  31610. self._newoption = function(optObj) {
  31611. optObj[optname] = opt;
  31612. self[optObj.name] = optObj;
  31613. self.optionList.push(optObj);
  31614. };
  31615. self['_' + optname] = opt;
  31616. return self;
  31617. };
  31618. /**
  31619. * lib.smooth: smooth arrayIn by convolving with
  31620. * a hann window with given full width at half max
  31621. * bounce the ends in, so the output has the same length as the input
  31622. */
  31623. lib.smooth = function(arrayIn, FWHM) {
  31624. FWHM = Math.round(FWHM) || 0; // only makes sense for integers
  31625. if(FWHM < 2) return arrayIn;
  31626. var alen = arrayIn.length,
  31627. alen2 = 2 * alen,
  31628. wlen = 2 * FWHM - 1,
  31629. w = new Array(wlen),
  31630. arrayOut = new Array(alen),
  31631. i,
  31632. j,
  31633. k,
  31634. v;
  31635. // first make the window array
  31636. for(i = 0; i < wlen; i++) {
  31637. w[i] = (1 - Math.cos(Math.PI * (i + 1) / FWHM)) / (2 * FWHM);
  31638. }
  31639. // now do the convolution
  31640. for(i = 0; i < alen; i++) {
  31641. v = 0;
  31642. for(j = 0; j < wlen; j++) {
  31643. k = i + j + 1 - FWHM;
  31644. // multibounce
  31645. if(k < -alen) k -= alen2 * Math.round(k / alen2);
  31646. else if(k >= alen2) k -= alen2 * Math.floor(k / alen2);
  31647. // single bounce
  31648. if(k < 0) k = - 1 - k;
  31649. else if(k >= alen) k = alen2 - 1 - k;
  31650. v += arrayIn[k] * w[j];
  31651. }
  31652. arrayOut[i] = v;
  31653. }
  31654. return arrayOut;
  31655. };
  31656. /**
  31657. * syncOrAsync: run a sequence of functions synchronously
  31658. * as long as its returns are not promises (ie have no .then)
  31659. * includes one argument arg to send to all functions...
  31660. * this is mainly just to prevent us having to make wrapper functions
  31661. * when the only purpose of the wrapper is to reference gd
  31662. * and a final step to be executed at the end
  31663. * TODO: if there's an error and everything is sync,
  31664. * this doesn't happen yet because we want to make sure
  31665. * that it gets reported
  31666. */
  31667. lib.syncOrAsync = function(sequence, arg, finalStep) {
  31668. var ret, fni;
  31669. function continueAsync() {
  31670. return lib.syncOrAsync(sequence, arg, finalStep);
  31671. }
  31672. while(sequence.length) {
  31673. fni = sequence.splice(0, 1)[0];
  31674. ret = fni(arg);
  31675. if(ret && ret.then) {
  31676. return ret.then(continueAsync)
  31677. .then(undefined, lib.promiseError);
  31678. }
  31679. }
  31680. return finalStep && finalStep(arg);
  31681. };
  31682. /**
  31683. * Helper to strip trailing slash, from
  31684. * http://stackoverflow.com/questions/6680825/return-string-without-trailing-slash
  31685. */
  31686. lib.stripTrailingSlash = function(str) {
  31687. if(str.substr(-1) === '/') return str.substr(0, str.length - 1);
  31688. return str;
  31689. };
  31690. lib.noneOrAll = function(containerIn, containerOut, attrList) {
  31691. /**
  31692. * some attributes come together, so if you have one of them
  31693. * in the input, you should copy the default values of the others
  31694. * to the input as well.
  31695. */
  31696. if(!containerIn) return;
  31697. var hasAny = false,
  31698. hasAll = true,
  31699. i,
  31700. val;
  31701. for(i = 0; i < attrList.length; i++) {
  31702. val = containerIn[attrList[i]];
  31703. if(val !== undefined && val !== null) hasAny = true;
  31704. else hasAll = false;
  31705. }
  31706. if(hasAny && !hasAll) {
  31707. for(i = 0; i < attrList.length; i++) {
  31708. containerIn[attrList[i]] = containerOut[attrList[i]];
  31709. }
  31710. }
  31711. };
  31712. /** merges calcdata field (given by cdAttr) with traceAttr values
  31713. *
  31714. * N.B. Loop over minimum of cd.length and traceAttr.length
  31715. * i.e. it does not try to fill in beyond traceAttr.length-1
  31716. *
  31717. * @param {array} traceAttr : trace attribute
  31718. * @param {object} cd : calcdata trace
  31719. * @param {string} cdAttr : calcdata key
  31720. */
  31721. lib.mergeArray = function(traceAttr, cd, cdAttr) {
  31722. if(lib.isArrayOrTypedArray(traceAttr)) {
  31723. var imax = Math.min(traceAttr.length, cd.length);
  31724. for(var i = 0; i < imax; i++) cd[i][cdAttr] = traceAttr[i];
  31725. }
  31726. };
  31727. /** fills calcdata field (given by cdAttr) with traceAttr values
  31728. * or function of traceAttr values (e.g. some fallback)
  31729. *
  31730. * N.B. Loops over all cd items.
  31731. *
  31732. * @param {array} traceAttr : trace attribute
  31733. * @param {object} cd : calcdata trace
  31734. * @param {string} cdAttr : calcdata key
  31735. * @param {function} [fn] : optional function to apply to each array item
  31736. */
  31737. lib.fillArray = function(traceAttr, cd, cdAttr, fn) {
  31738. fn = fn || lib.identity;
  31739. if(lib.isArrayOrTypedArray(traceAttr)) {
  31740. for(var i = 0; i < cd.length; i++) {
  31741. cd[i][cdAttr] = fn(traceAttr[i]);
  31742. }
  31743. }
  31744. };
  31745. /** Handler for trace-wide vs per-point options
  31746. *
  31747. * @param {object} trace : (full) trace object
  31748. * @param {number} ptNumber : index of the point in question
  31749. * @param {string} astr : attribute string
  31750. * @param {function} [fn] : optional function to apply to each array item
  31751. *
  31752. * @return {any}
  31753. */
  31754. lib.castOption = function(trace, ptNumber, astr, fn) {
  31755. fn = fn || lib.identity;
  31756. var val = lib.nestedProperty(trace, astr).get();
  31757. if(lib.isArrayOrTypedArray(val)) {
  31758. if(Array.isArray(ptNumber) && lib.isArrayOrTypedArray(val[ptNumber[0]])) {
  31759. return fn(val[ptNumber[0]][ptNumber[1]]);
  31760. } else {
  31761. return fn(val[ptNumber]);
  31762. }
  31763. } else {
  31764. return val;
  31765. }
  31766. };
  31767. /** Extract option from calcdata item, correctly falling back to
  31768. * trace value if not found.
  31769. *
  31770. * @param {object} calcPt : calcdata[i][j] item
  31771. * @param {object} trace : (full) trace object
  31772. * @param {string} calcKey : calcdata key
  31773. * @param {string} traceKey : aka trace attribute string
  31774. * @return {any}
  31775. */
  31776. lib.extractOption = function(calcPt, trace, calcKey, traceKey) {
  31777. if(calcKey in calcPt) return calcPt[calcKey];
  31778. // fallback to trace value,
  31779. // must check if value isn't itself an array
  31780. // which means the trace attribute has a corresponding
  31781. // calcdata key, but its value is falsy
  31782. var traceVal = lib.nestedProperty(trace, traceKey).get();
  31783. if(!Array.isArray(traceVal)) return traceVal;
  31784. };
  31785. function makePtIndex2PtNumber(indexToPoints) {
  31786. var ptIndex2ptNumber = {};
  31787. for(var k in indexToPoints) {
  31788. var pts = indexToPoints[k];
  31789. for(var j = 0; j < pts.length; j++) {
  31790. ptIndex2ptNumber[pts[j]] = +k;
  31791. }
  31792. }
  31793. return ptIndex2ptNumber;
  31794. }
  31795. /** Tag selected calcdata items
  31796. *
  31797. * N.B. note that point 'index' corresponds to input data array index
  31798. * whereas 'number' is its post-transform version.
  31799. *
  31800. * @param {array} calcTrace
  31801. * @param {object} trace
  31802. * - selectedpoints {array}
  31803. * - _indexToPoints {object}
  31804. * @param {ptNumber2cdIndex} ptNumber2cdIndex (optional)
  31805. * optional map object for trace types that do not have 1-to-1 point number to
  31806. * calcdata item index correspondence (e.g. histogram)
  31807. */
  31808. lib.tagSelected = function(calcTrace, trace, ptNumber2cdIndex) {
  31809. var selectedpoints = trace.selectedpoints;
  31810. var indexToPoints = trace._indexToPoints;
  31811. var ptIndex2ptNumber;
  31812. // make pt index-to-number map object, which takes care of transformed traces
  31813. if(indexToPoints) {
  31814. ptIndex2ptNumber = makePtIndex2PtNumber(indexToPoints);
  31815. }
  31816. function isCdIndexValid(v) {
  31817. return v !== undefined && v < calcTrace.length;
  31818. }
  31819. for(var i = 0; i < selectedpoints.length; i++) {
  31820. var ptIndex = selectedpoints[i];
  31821. if(lib.isIndex(ptIndex)) {
  31822. var ptNumber = ptIndex2ptNumber ? ptIndex2ptNumber[ptIndex] : ptIndex;
  31823. var cdIndex = ptNumber2cdIndex ? ptNumber2cdIndex[ptNumber] : ptNumber;
  31824. if(isCdIndexValid(cdIndex)) {
  31825. calcTrace[cdIndex].selected = 1;
  31826. }
  31827. }
  31828. }
  31829. };
  31830. lib.selIndices2selPoints = function(trace) {
  31831. var selectedpoints = trace.selectedpoints;
  31832. var indexToPoints = trace._indexToPoints;
  31833. if(indexToPoints) {
  31834. var ptIndex2ptNumber = makePtIndex2PtNumber(indexToPoints);
  31835. var out = [];
  31836. for(var i = 0; i < selectedpoints.length; i++) {
  31837. var ptIndex = selectedpoints[i];
  31838. if(lib.isIndex(ptIndex)) {
  31839. var ptNumber = ptIndex2ptNumber[ptIndex];
  31840. if(lib.isIndex(ptNumber)) {
  31841. out.push(ptNumber);
  31842. }
  31843. }
  31844. }
  31845. return out;
  31846. } else {
  31847. return selectedpoints;
  31848. }
  31849. };
  31850. /** Returns target as set by 'target' transform attribute
  31851. *
  31852. * @param {object} trace : full trace object
  31853. * @param {object} transformOpts : transform option object
  31854. * - target (string} :
  31855. * either an attribute string referencing an array in the trace object, or
  31856. * a set array.
  31857. *
  31858. * @return {array or false} : the target array (NOT a copy!!) or false if invalid
  31859. */
  31860. lib.getTargetArray = function(trace, transformOpts) {
  31861. var target = transformOpts.target;
  31862. if(typeof target === 'string' && target) {
  31863. var array = lib.nestedProperty(trace, target).get();
  31864. return Array.isArray(array) ? array : false;
  31865. } else if(Array.isArray(target)) {
  31866. return target;
  31867. }
  31868. return false;
  31869. };
  31870. /**
  31871. * modified version of jQuery's extend to strip out private objs and functions,
  31872. * and cut arrays down to first <arraylen> or 1 elements
  31873. * because extend-like algorithms are hella slow
  31874. * obj2 is assumed to already be clean of these things (including no arrays)
  31875. */
  31876. lib.minExtend = function(obj1, obj2) {
  31877. var objOut = {};
  31878. if(typeof obj2 !== 'object') obj2 = {};
  31879. var arrayLen = 3,
  31880. keys = Object.keys(obj1),
  31881. i,
  31882. k,
  31883. v;
  31884. for(i = 0; i < keys.length; i++) {
  31885. k = keys[i];
  31886. v = obj1[k];
  31887. if(k.charAt(0) === '_' || typeof v === 'function') continue;
  31888. else if(k === 'module') objOut[k] = v;
  31889. else if(Array.isArray(v)) objOut[k] = v.slice(0, arrayLen);
  31890. else if(v && (typeof v === 'object')) objOut[k] = lib.minExtend(obj1[k], obj2[k]);
  31891. else objOut[k] = v;
  31892. }
  31893. keys = Object.keys(obj2);
  31894. for(i = 0; i < keys.length; i++) {
  31895. k = keys[i];
  31896. v = obj2[k];
  31897. if(typeof v !== 'object' || !(k in objOut) || typeof objOut[k] !== 'object') {
  31898. objOut[k] = v;
  31899. }
  31900. }
  31901. return objOut;
  31902. };
  31903. lib.titleCase = function(s) {
  31904. return s.charAt(0).toUpperCase() + s.substr(1);
  31905. };
  31906. lib.containsAny = function(s, fragments) {
  31907. for(var i = 0; i < fragments.length; i++) {
  31908. if(s.indexOf(fragments[i]) !== -1) return true;
  31909. }
  31910. return false;
  31911. };
  31912. lib.isPlotDiv = function(el) {
  31913. var el3 = d3.select(el);
  31914. return el3.node() instanceof HTMLElement &&
  31915. el3.size() &&
  31916. el3.classed('js-plotly-plot');
  31917. };
  31918. lib.removeElement = function(el) {
  31919. var elParent = el && el.parentNode;
  31920. if(elParent) elParent.removeChild(el);
  31921. };
  31922. /**
  31923. * for dynamically adding style rules
  31924. * makes one stylesheet that contains all rules added
  31925. * by all calls to this function
  31926. */
  31927. lib.addStyleRule = function(selector, styleString) {
  31928. if(!lib.styleSheet) {
  31929. var style = document.createElement('style');
  31930. // WebKit hack :(
  31931. style.appendChild(document.createTextNode(''));
  31932. document.head.appendChild(style);
  31933. lib.styleSheet = style.sheet;
  31934. }
  31935. var styleSheet = lib.styleSheet;
  31936. if(styleSheet.insertRule) {
  31937. styleSheet.insertRule(selector + '{' + styleString + '}', 0);
  31938. }
  31939. else if(styleSheet.addRule) {
  31940. styleSheet.addRule(selector, styleString, 0);
  31941. }
  31942. else lib.warn('addStyleRule failed');
  31943. };
  31944. lib.isIE = function() {
  31945. return typeof window.navigator.msSaveBlob !== 'undefined';
  31946. };
  31947. /**
  31948. * Duck typing to recognize a d3 selection, mostly for IE9's benefit
  31949. * because it doesn't handle instanceof like modern browsers
  31950. */
  31951. lib.isD3Selection = function(obj) {
  31952. return obj && (typeof obj.classed === 'function');
  31953. };
  31954. /**
  31955. * Append element to DOM only if not present.
  31956. *
  31957. * @param {d3 selection} parent : parent selection of the element in question
  31958. * @param {string} nodeType : node type of element to append
  31959. * @param {string} className (optional) : class name of element in question
  31960. * @param {fn} enterFn (optional) : optional fn applied to entering elements only
  31961. * @return {d3 selection} selection of new layer
  31962. *
  31963. * Previously, we were using the following pattern:
  31964. *
  31965. * ```
  31966. * var sel = parent.selectAll('.' + className)
  31967. * .data([0]);
  31968. *
  31969. * sel.enter().append(nodeType)
  31970. * .classed(className, true);
  31971. *
  31972. * return sel;
  31973. * ```
  31974. *
  31975. * in numerous places in our codebase to achieve the same behavior.
  31976. *
  31977. * The logic below performs much better, mostly as we are using
  31978. * `.select` instead `.selectAll` that is `querySelector` instead of
  31979. * `querySelectorAll`.
  31980. *
  31981. */
  31982. lib.ensureSingle = function(parent, nodeType, className, enterFn) {
  31983. var sel = parent.select(nodeType + (className ? '.' + className : ''));
  31984. if(sel.size()) return sel;
  31985. var layer = parent.append(nodeType);
  31986. if(className) layer.classed(className, true);
  31987. if(enterFn) layer.call(enterFn);
  31988. return layer;
  31989. };
  31990. /**
  31991. * Same as Lib.ensureSingle, but using id as selector.
  31992. * This version is mostly used for clipPath nodes.
  31993. *
  31994. * @param {d3 selection} parent : parent selection of the element in question
  31995. * @param {string} nodeType : node type of element to append
  31996. * @param {string} id : id of element in question
  31997. * @param {fn} enterFn (optional) : optional fn applied to entering elements only
  31998. * @return {d3 selection} selection of new layer
  31999. */
  32000. lib.ensureSingleById = function(parent, nodeType, id, enterFn) {
  32001. var sel = parent.select(nodeType + '#' + id);
  32002. if(sel.size()) return sel;
  32003. var layer = parent.append(nodeType).attr('id', id);
  32004. if(enterFn) layer.call(enterFn);
  32005. return layer;
  32006. };
  32007. /**
  32008. * Converts a string path to an object.
  32009. *
  32010. * When given a string containing an array element, it will create a `null`
  32011. * filled array of the given size.
  32012. *
  32013. * @example
  32014. * lib.objectFromPath('nested.test[2].path', 'value');
  32015. * // returns { nested: { test: [null, null, { path: 'value' }]}
  32016. *
  32017. * @param {string} path to nested value
  32018. * @param {*} any value to be set
  32019. *
  32020. * @return {Object} the constructed object with a full nested path
  32021. */
  32022. lib.objectFromPath = function(path, value) {
  32023. var keys = path.split('.'),
  32024. tmpObj,
  32025. obj = tmpObj = {};
  32026. for(var i = 0; i < keys.length; i++) {
  32027. var key = keys[i];
  32028. var el = null;
  32029. var parts = keys[i].match(/(.*)\[([0-9]+)\]/);
  32030. if(parts) {
  32031. key = parts[1];
  32032. el = parts[2];
  32033. tmpObj = tmpObj[key] = [];
  32034. if(i === keys.length - 1) {
  32035. tmpObj[el] = value;
  32036. } else {
  32037. tmpObj[el] = {};
  32038. }
  32039. tmpObj = tmpObj[el];
  32040. } else {
  32041. if(i === keys.length - 1) {
  32042. tmpObj[key] = value;
  32043. } else {
  32044. tmpObj[key] = {};
  32045. }
  32046. tmpObj = tmpObj[key];
  32047. }
  32048. }
  32049. return obj;
  32050. };
  32051. /**
  32052. * Iterate through an object in-place, converting dotted properties to objects.
  32053. *
  32054. * Examples:
  32055. *
  32056. * lib.expandObjectPaths({'nested.test.path': 'value'});
  32057. * => { nested: { test: {path: 'value'}}}
  32058. *
  32059. * It also handles array notation, e.g.:
  32060. *
  32061. * lib.expandObjectPaths({'foo[1].bar': 'value'});
  32062. * => { foo: [null, {bar: value}] }
  32063. *
  32064. * It handles merges the results when two properties are specified in parallel:
  32065. *
  32066. * lib.expandObjectPaths({'foo[1].bar': 10, 'foo[0].bar': 20});
  32067. * => { foo: [{bar: 10}, {bar: 20}] }
  32068. *
  32069. * It does NOT, however, merge mulitple mutliply-nested arrays::
  32070. *
  32071. * lib.expandObjectPaths({'marker[1].range[1]': 5, 'marker[1].range[0]': 4})
  32072. * => { marker: [null, {range: 4}] }
  32073. */
  32074. // Store this to avoid recompiling regex on *every* prop since this may happen many
  32075. // many times for animations. Could maybe be inside the function. Not sure about
  32076. // scoping vs. recompilation tradeoff, but at least it's not just inlining it into
  32077. // the inner loop.
  32078. var dottedPropertyRegex = /^([^\[\.]+)\.(.+)?/;
  32079. var indexedPropertyRegex = /^([^\.]+)\[([0-9]+)\](\.)?(.+)?/;
  32080. lib.expandObjectPaths = function(data) {
  32081. var match, key, prop, datum, idx, dest, trailingPath;
  32082. if(typeof data === 'object' && !Array.isArray(data)) {
  32083. for(key in data) {
  32084. if(data.hasOwnProperty(key)) {
  32085. if((match = key.match(dottedPropertyRegex))) {
  32086. datum = data[key];
  32087. prop = match[1];
  32088. delete data[key];
  32089. data[prop] = lib.extendDeepNoArrays(data[prop] || {}, lib.objectFromPath(key, lib.expandObjectPaths(datum))[prop]);
  32090. } else if((match = key.match(indexedPropertyRegex))) {
  32091. datum = data[key];
  32092. prop = match[1];
  32093. idx = parseInt(match[2]);
  32094. delete data[key];
  32095. data[prop] = data[prop] || [];
  32096. if(match[3] === '.') {
  32097. // This is the case where theere are subsequent properties into which
  32098. // we must recurse, e.g. transforms[0].value
  32099. trailingPath = match[4];
  32100. dest = data[prop][idx] = data[prop][idx] || {};
  32101. // NB: Extend deep no arrays prevents this from working on multiple
  32102. // nested properties in the same object, e.g.
  32103. //
  32104. // {
  32105. // foo[0].bar[1].range
  32106. // foo[0].bar[0].range
  32107. // }
  32108. //
  32109. // In this case, the extendDeepNoArrays will overwrite one array with
  32110. // the other, so that both properties *will not* be present in the
  32111. // result. Fixing this would require a more intelligent tracking
  32112. // of changes and merging than extendDeepNoArrays currently accomplishes.
  32113. lib.extendDeepNoArrays(dest, lib.objectFromPath(trailingPath, lib.expandObjectPaths(datum)));
  32114. } else {
  32115. // This is the case where this property is the end of the line,
  32116. // e.g. xaxis.range[0]
  32117. data[prop][idx] = lib.expandObjectPaths(datum);
  32118. }
  32119. } else {
  32120. data[key] = lib.expandObjectPaths(data[key]);
  32121. }
  32122. }
  32123. }
  32124. }
  32125. return data;
  32126. };
  32127. /**
  32128. * Converts value to string separated by the provided separators.
  32129. *
  32130. * @example
  32131. * lib.numSeparate(2016, '.,');
  32132. * // returns '2016'
  32133. *
  32134. * @example
  32135. * lib.numSeparate(3000, '.,', true);
  32136. * // returns '3,000'
  32137. *
  32138. * @example
  32139. * lib.numSeparate(1234.56, '|,')
  32140. * // returns '1,234|56'
  32141. *
  32142. * @param {string|number} value the value to be converted
  32143. * @param {string} separators string of decimal, then thousands separators
  32144. * @param {boolean} separatethousands boolean, 4-digit integers are separated if true
  32145. *
  32146. * @return {string} the value that has been separated
  32147. */
  32148. lib.numSeparate = function(value, separators, separatethousands) {
  32149. if(!separatethousands) separatethousands = false;
  32150. if(typeof separators !== 'string' || separators.length === 0) {
  32151. throw new Error('Separator string required for formatting!');
  32152. }
  32153. if(typeof value === 'number') {
  32154. value = String(value);
  32155. }
  32156. var thousandsRe = /(\d+)(\d{3})/,
  32157. decimalSep = separators.charAt(0),
  32158. thouSep = separators.charAt(1);
  32159. var x = value.split('.'),
  32160. x1 = x[0],
  32161. x2 = x.length > 1 ? decimalSep + x[1] : '';
  32162. // Years are ignored for thousands separators
  32163. if(thouSep && (x.length > 1 || x1.length > 4 || separatethousands)) {
  32164. while(thousandsRe.test(x1)) {
  32165. x1 = x1.replace(thousandsRe, '$1' + thouSep + '$2');
  32166. }
  32167. }
  32168. return x1 + x2;
  32169. };
  32170. var TEMPLATE_STRING_REGEX = /%{([^\s%{}]*)}/g;
  32171. var SIMPLE_PROPERTY_REGEX = /^\w*$/;
  32172. /*
  32173. * Substitute values from an object into a string
  32174. *
  32175. * Examples:
  32176. * Lib.templateString('name: %{trace}', {trace: 'asdf'}) --> 'name: asdf'
  32177. * Lib.templateString('name: %{trace[0].name}', {trace: [{name: 'asdf'}]}) --> 'name: asdf'
  32178. *
  32179. * @param {string} input string containing %{...} template strings
  32180. * @param {obj} data object containing substitution values
  32181. *
  32182. * @return {string} templated string
  32183. */
  32184. lib.templateString = function(string, obj) {
  32185. // Not all that useful, but cache nestedProperty instantiation
  32186. // just in case it speeds things up *slightly*:
  32187. var getterCache = {};
  32188. return string.replace(TEMPLATE_STRING_REGEX, function(dummy, key) {
  32189. if(SIMPLE_PROPERTY_REGEX.test(key)) {
  32190. return obj[key] || '';
  32191. }
  32192. getterCache[key] = getterCache[key] || lib.nestedProperty(obj, key).get;
  32193. return getterCache[key]() || '';
  32194. });
  32195. };
  32196. /*
  32197. * alphanumeric string sort, tailored for subplot IDs like scene2, scene10, x10y13 etc
  32198. */
  32199. var char0 = 48;
  32200. var char9 = 57;
  32201. lib.subplotSort = function(a, b) {
  32202. var l = Math.min(a.length, b.length) + 1;
  32203. var numA = 0;
  32204. var numB = 0;
  32205. for(var i = 0; i < l; i++) {
  32206. var charA = a.charCodeAt(i) || 0;
  32207. var charB = b.charCodeAt(i) || 0;
  32208. var isNumA = charA >= char0 && charA <= char9;
  32209. var isNumB = charB >= char0 && charB <= char9;
  32210. if(isNumA) numA = 10 * numA + charA - char0;
  32211. if(isNumB) numB = 10 * numB + charB - char0;
  32212. if(!isNumA || !isNumB) {
  32213. if(numA !== numB) return numA - numB;
  32214. if(charA !== charB) return charA - charB;
  32215. }
  32216. }
  32217. return numB - numA;
  32218. };
  32219. // repeatable pseudorandom generator
  32220. var randSeed = 2000000000;
  32221. lib.seedPseudoRandom = function() {
  32222. randSeed = 2000000000;
  32223. };
  32224. lib.pseudoRandom = function() {
  32225. var lastVal = randSeed;
  32226. randSeed = (69069 * randSeed + 1) % 4294967296;
  32227. // don't let consecutive vals be too close together
  32228. // gets away from really trying to be random, in favor of better local uniformity
  32229. if(Math.abs(randSeed - lastVal) < 429496729) return lib.pseudoRandom();
  32230. return randSeed / 4294967296;
  32231. };
  32232. },{"../constants/numerical":151,"./angles":155,"./clean_number":156,"./clear_responsive":158,"./coerce":159,"./dates":160,"./ensure_array":161,"./extend":163,"./filter_unique":164,"./filter_visible":165,"./geometry2d":166,"./get_graph_div":167,"./identity":168,"./is_array":170,"./is_plain_object":171,"./keyed_container":172,"./localize":173,"./loggers":174,"./make_trace_groups":175,"./matrix":176,"./mod":177,"./nested_property":178,"./noop":179,"./notifier":180,"./push_unique":183,"./regex":185,"./relative_attr":186,"./relink_private":187,"./search":188,"./stats":190,"./throttle":192,"./to_log_range":193,"d3":16,"fast-isnumeric":18}],170:[function(_dereq_,module,exports){
  32233. /**
  32234. * Copyright 2012-2018, Plotly, Inc.
  32235. * All rights reserved.
  32236. *
  32237. * This source code is licensed under the MIT license found in the
  32238. * LICENSE file in the root directory of this source tree.
  32239. */
  32240. 'use strict';
  32241. // IE9 fallbacks
  32242. var ab = (typeof ArrayBuffer === 'undefined' || !ArrayBuffer.isView) ?
  32243. {isView: function() { return false; }} :
  32244. ArrayBuffer;
  32245. var dv = (typeof DataView === 'undefined') ?
  32246. function() {} :
  32247. DataView;
  32248. function isTypedArray(a) {
  32249. return ab.isView(a) && !(a instanceof dv);
  32250. }
  32251. function isArrayOrTypedArray(a) {
  32252. return Array.isArray(a) || isTypedArray(a);
  32253. }
  32254. /*
  32255. * Test whether an input object is 1D.
  32256. *
  32257. * Assumes we already know the object is an array.
  32258. *
  32259. * Looks only at the first element, if the dimensionality is
  32260. * not consistent we won't figure that out here.
  32261. */
  32262. function isArray1D(a) {
  32263. return !isArrayOrTypedArray(a[0]);
  32264. }
  32265. module.exports = {
  32266. isTypedArray: isTypedArray,
  32267. isArrayOrTypedArray: isArrayOrTypedArray,
  32268. isArray1D: isArray1D
  32269. };
  32270. },{}],171:[function(_dereq_,module,exports){
  32271. /**
  32272. * Copyright 2012-2018, Plotly, Inc.
  32273. * All rights reserved.
  32274. *
  32275. * This source code is licensed under the MIT license found in the
  32276. * LICENSE file in the root directory of this source tree.
  32277. */
  32278. 'use strict';
  32279. // more info: http://stackoverflow.com/questions/18531624/isplainobject-thing
  32280. module.exports = function isPlainObject(obj) {
  32281. // We need to be a little less strict in the `imagetest` container because
  32282. // of how async image requests are handled.
  32283. //
  32284. // N.B. isPlainObject(new Constructor()) will return true in `imagetest`
  32285. if(window && window.process && window.process.versions) {
  32286. return Object.prototype.toString.call(obj) === '[object Object]';
  32287. }
  32288. return (
  32289. Object.prototype.toString.call(obj) === '[object Object]' &&
  32290. Object.getPrototypeOf(obj) === Object.prototype
  32291. );
  32292. };
  32293. },{}],172:[function(_dereq_,module,exports){
  32294. /**
  32295. * Copyright 2012-2018, Plotly, Inc.
  32296. * All rights reserved.
  32297. *
  32298. * This source code is licensed under the MIT license found in the
  32299. * LICENSE file in the root directory of this source tree.
  32300. */
  32301. 'use strict';
  32302. var nestedProperty = _dereq_('./nested_property');
  32303. var SIMPLE_PROPERTY_REGEX = /^\w*$/;
  32304. // bitmask for deciding what's updated. Sometimes the name needs to be updated,
  32305. // sometimes the value needs to be updated, and sometimes both do. This is just
  32306. // a simple way to track what's updated such that it's a simple OR operation to
  32307. // assimilate new updates.
  32308. //
  32309. // The only exception is the UNSET bit that tracks when we need to explicitly
  32310. // unset and remove the property. This concrn arises because of the special
  32311. // way in which nestedProperty handles null/undefined. When you specify `null`,
  32312. // it prunes any unused items in the tree. I ran into some issues with it getting
  32313. // null vs undefined confused, so UNSET is just a bit that forces the property
  32314. // update to send `null`, removing the property explicitly rather than setting
  32315. // it to undefined.
  32316. var NONE = 0;
  32317. var NAME = 1;
  32318. var VALUE = 2;
  32319. var BOTH = 3;
  32320. var UNSET = 4;
  32321. module.exports = function keyedContainer(baseObj, path, keyName, valueName) {
  32322. keyName = keyName || 'name';
  32323. valueName = valueName || 'value';
  32324. var i, arr, baseProp;
  32325. var changeTypes = {};
  32326. if(path && path.length) {
  32327. baseProp = nestedProperty(baseObj, path);
  32328. arr = baseProp.get();
  32329. } else {
  32330. arr = baseObj;
  32331. }
  32332. path = path || '';
  32333. // Construct an index:
  32334. var indexLookup = {};
  32335. if(arr) {
  32336. for(i = 0; i < arr.length; i++) {
  32337. indexLookup[arr[i][keyName]] = i;
  32338. }
  32339. }
  32340. var isSimpleValueProp = SIMPLE_PROPERTY_REGEX.test(valueName);
  32341. var obj = {
  32342. set: function(name, value) {
  32343. var changeType = value === null ? UNSET : NONE;
  32344. // create the base array if necessary
  32345. if(!arr) {
  32346. if(!baseProp || changeType === UNSET) return;
  32347. arr = [];
  32348. baseProp.set(arr);
  32349. }
  32350. var idx = indexLookup[name];
  32351. if(idx === undefined) {
  32352. if(changeType === UNSET) return;
  32353. changeType = changeType | BOTH;
  32354. idx = arr.length;
  32355. indexLookup[name] = idx;
  32356. } else if(value !== (isSimpleValueProp ? arr[idx][valueName] : nestedProperty(arr[idx], valueName).get())) {
  32357. changeType = changeType | VALUE;
  32358. }
  32359. var newValue = arr[idx] = arr[idx] || {};
  32360. newValue[keyName] = name;
  32361. if(isSimpleValueProp) {
  32362. newValue[valueName] = value;
  32363. } else {
  32364. nestedProperty(newValue, valueName).set(value);
  32365. }
  32366. // If it's not an unset, force that bit to be unset. This is all related to the fact
  32367. // that undefined and null are a bit specially implemented in nestedProperties.
  32368. if(value !== null) {
  32369. changeType = changeType & ~UNSET;
  32370. }
  32371. changeTypes[idx] = changeTypes[idx] | changeType;
  32372. return obj;
  32373. },
  32374. get: function(name) {
  32375. if(!arr) return;
  32376. var idx = indexLookup[name];
  32377. if(idx === undefined) {
  32378. return undefined;
  32379. } else if(isSimpleValueProp) {
  32380. return arr[idx][valueName];
  32381. } else {
  32382. return nestedProperty(arr[idx], valueName).get();
  32383. }
  32384. },
  32385. rename: function(name, newName) {
  32386. var idx = indexLookup[name];
  32387. if(idx === undefined) return obj;
  32388. changeTypes[idx] = changeTypes[idx] | NAME;
  32389. indexLookup[newName] = idx;
  32390. delete indexLookup[name];
  32391. arr[idx][keyName] = newName;
  32392. return obj;
  32393. },
  32394. remove: function(name) {
  32395. var idx = indexLookup[name];
  32396. if(idx === undefined) return obj;
  32397. var object = arr[idx];
  32398. if(Object.keys(object).length > 2) {
  32399. // This object contains more than just the key/value, so unset
  32400. // the value without modifying the entry otherwise:
  32401. changeTypes[idx] = changeTypes[idx] | VALUE;
  32402. return obj.set(name, null);
  32403. }
  32404. if(isSimpleValueProp) {
  32405. for(i = idx; i < arr.length; i++) {
  32406. changeTypes[i] = changeTypes[i] | BOTH;
  32407. }
  32408. for(i = idx; i < arr.length; i++) {
  32409. indexLookup[arr[i][keyName]]--;
  32410. }
  32411. arr.splice(idx, 1);
  32412. delete(indexLookup[name]);
  32413. } else {
  32414. // Perform this update *strictly* so we can check whether the result's
  32415. // been pruned. If so, it's a removal. If not, it's a value unset only.
  32416. nestedProperty(object, valueName).set(null);
  32417. // Now check if the top level nested property has any keys left. If so,
  32418. // the object still has values so we only want to unset the key. If not,
  32419. // the entire object can be removed since there's no other data.
  32420. // var topLevelKeys = Object.keys(object[valueName.split('.')[0]] || []);
  32421. changeTypes[idx] = changeTypes[idx] | VALUE | UNSET;
  32422. }
  32423. return obj;
  32424. },
  32425. constructUpdate: function() {
  32426. var astr, idx;
  32427. var update = {};
  32428. var changed = Object.keys(changeTypes);
  32429. for(var i = 0; i < changed.length; i++) {
  32430. idx = changed[i];
  32431. astr = path + '[' + idx + ']';
  32432. if(arr[idx]) {
  32433. if(changeTypes[idx] & NAME) {
  32434. update[astr + '.' + keyName] = arr[idx][keyName];
  32435. }
  32436. if(changeTypes[idx] & VALUE) {
  32437. if(isSimpleValueProp) {
  32438. update[astr + '.' + valueName] = (changeTypes[idx] & UNSET) ? null : arr[idx][valueName];
  32439. } else {
  32440. update[astr + '.' + valueName] = (changeTypes[idx] & UNSET) ? null : nestedProperty(arr[idx], valueName).get();
  32441. }
  32442. }
  32443. } else {
  32444. update[astr] = null;
  32445. }
  32446. }
  32447. return update;
  32448. }
  32449. };
  32450. return obj;
  32451. };
  32452. },{"./nested_property":178}],173:[function(_dereq_,module,exports){
  32453. /**
  32454. * Copyright 2012-2018, Plotly, Inc.
  32455. * All rights reserved.
  32456. *
  32457. * This source code is licensed under the MIT license found in the
  32458. * LICENSE file in the root directory of this source tree.
  32459. */
  32460. 'use strict';
  32461. var Registry = _dereq_('../registry');
  32462. /**
  32463. * localize: translate a string for the current locale
  32464. *
  32465. * @param {object} gd: the graphDiv for context
  32466. * gd._context.locale determines the language (& optional region/country)
  32467. * the dictionary for each locale may either be supplied in
  32468. * gd._context.locales or globally via Plotly.register
  32469. * @param {string} s: the string to translate
  32470. */
  32471. module.exports = function localize(gd, s) {
  32472. var locale = gd._context.locale;
  32473. /*
  32474. * Priority of lookup:
  32475. * contextDicts[locale],
  32476. * registeredDicts[locale],
  32477. * contextDicts[baseLocale], (if baseLocale is distinct)
  32478. * registeredDicts[baseLocale]
  32479. * Return the first translation we find.
  32480. * This way if you have a regionalization you are allowed to specify
  32481. * only what's different from the base locale, everything else will
  32482. * fall back on the base.
  32483. */
  32484. for(var i = 0; i < 2; i++) {
  32485. var locales = gd._context.locales;
  32486. for(var j = 0; j < 2; j++) {
  32487. var dict = (locales[locale] || {}).dictionary;
  32488. if(dict) {
  32489. var out = dict[s];
  32490. if(out) return out;
  32491. }
  32492. locales = Registry.localeRegistry;
  32493. }
  32494. var baseLocale = locale.split('-')[0];
  32495. if(baseLocale === locale) break;
  32496. locale = baseLocale;
  32497. }
  32498. return s;
  32499. };
  32500. },{"../registry":259}],174:[function(_dereq_,module,exports){
  32501. /**
  32502. * Copyright 2012-2018, Plotly, Inc.
  32503. * All rights reserved.
  32504. *
  32505. * This source code is licensed under the MIT license found in the
  32506. * LICENSE file in the root directory of this source tree.
  32507. */
  32508. 'use strict';
  32509. /* eslint-disable no-console */
  32510. var config = _dereq_('../plot_api/plot_config');
  32511. var loggers = module.exports = {};
  32512. /**
  32513. * ------------------------------------------
  32514. * debugging tools
  32515. * ------------------------------------------
  32516. */
  32517. loggers.log = function() {
  32518. if(config.logging > 1) {
  32519. var messages = ['LOG:'];
  32520. for(var i = 0; i < arguments.length; i++) {
  32521. messages.push(arguments[i]);
  32522. }
  32523. apply(console.trace || console.log, messages);
  32524. }
  32525. };
  32526. loggers.warn = function() {
  32527. if(config.logging > 0) {
  32528. var messages = ['WARN:'];
  32529. for(var i = 0; i < arguments.length; i++) {
  32530. messages.push(arguments[i]);
  32531. }
  32532. apply(console.trace || console.log, messages);
  32533. }
  32534. };
  32535. loggers.error = function() {
  32536. if(config.logging > 0) {
  32537. var messages = ['ERROR:'];
  32538. for(var i = 0; i < arguments.length; i++) {
  32539. messages.push(arguments[i]);
  32540. }
  32541. apply(console.error, messages);
  32542. }
  32543. };
  32544. /*
  32545. * Robust apply, for IE9 where console.log doesn't support
  32546. * apply like other functions do
  32547. */
  32548. function apply(f, args) {
  32549. if(f.apply) {
  32550. f.apply(f, args);
  32551. }
  32552. else {
  32553. for(var i = 0; i < args.length; i++) {
  32554. f(args[i]);
  32555. }
  32556. }
  32557. }
  32558. },{"../plot_api/plot_config":202}],175:[function(_dereq_,module,exports){
  32559. /**
  32560. * Copyright 2012-2018, Plotly, Inc.
  32561. * All rights reserved.
  32562. *
  32563. * This source code is licensed under the MIT license found in the
  32564. * LICENSE file in the root directory of this source tree.
  32565. */
  32566. 'use strict';
  32567. /**
  32568. * General helper to manage trace groups based on calcdata
  32569. *
  32570. * @param {d3.selection} traceLayer: a selection containing a single group
  32571. * to draw these traces into
  32572. * @param {array} cdModule: array of calcdata items for this
  32573. * module and subplot combination. Assumes the calcdata item for each
  32574. * trace is an array with the fullData trace attached to the first item.
  32575. * @param {string} cls: the class attribute to give each trace group
  32576. * so you can give multiple classes separated by spaces
  32577. */
  32578. module.exports = function makeTraceGroups(traceLayer, cdModule, cls) {
  32579. var traces = traceLayer.selectAll('g.' + cls.replace(/\s/g, '.'))
  32580. .data(cdModule, function(cd) { return cd[0].trace.uid; });
  32581. traces.exit().remove();
  32582. traces.enter().append('g')
  32583. .attr('class', cls);
  32584. traces.order();
  32585. return traces;
  32586. };
  32587. },{}],176:[function(_dereq_,module,exports){
  32588. /**
  32589. * Copyright 2012-2018, Plotly, Inc.
  32590. * All rights reserved.
  32591. *
  32592. * This source code is licensed under the MIT license found in the
  32593. * LICENSE file in the root directory of this source tree.
  32594. */
  32595. 'use strict';
  32596. exports.init2dArray = function(rowLength, colLength) {
  32597. var array = new Array(rowLength);
  32598. for(var i = 0; i < rowLength; i++) array[i] = new Array(colLength);
  32599. return array;
  32600. };
  32601. /**
  32602. * transpose a (possibly ragged) 2d array z. inspired by
  32603. * http://stackoverflow.com/questions/17428587/
  32604. * transposing-a-2d-array-in-javascript
  32605. */
  32606. exports.transposeRagged = function(z) {
  32607. var maxlen = 0,
  32608. zlen = z.length,
  32609. i,
  32610. j;
  32611. // Maximum row length:
  32612. for(i = 0; i < zlen; i++) maxlen = Math.max(maxlen, z[i].length);
  32613. var t = new Array(maxlen);
  32614. for(i = 0; i < maxlen; i++) {
  32615. t[i] = new Array(zlen);
  32616. for(j = 0; j < zlen; j++) t[i][j] = z[j][i];
  32617. }
  32618. return t;
  32619. };
  32620. // our own dot function so that we don't need to include numeric
  32621. exports.dot = function(x, y) {
  32622. if(!(x.length && y.length) || x.length !== y.length) return null;
  32623. var len = x.length,
  32624. out,
  32625. i;
  32626. if(x[0].length) {
  32627. // mat-vec or mat-mat
  32628. out = new Array(len);
  32629. for(i = 0; i < len; i++) out[i] = exports.dot(x[i], y);
  32630. }
  32631. else if(y[0].length) {
  32632. // vec-mat
  32633. var yTranspose = exports.transposeRagged(y);
  32634. out = new Array(yTranspose.length);
  32635. for(i = 0; i < yTranspose.length; i++) out[i] = exports.dot(x, yTranspose[i]);
  32636. }
  32637. else {
  32638. // vec-vec
  32639. out = 0;
  32640. for(i = 0; i < len; i++) out += x[i] * y[i];
  32641. }
  32642. return out;
  32643. };
  32644. // translate by (x,y)
  32645. exports.translationMatrix = function(x, y) {
  32646. return [[1, 0, x], [0, 1, y], [0, 0, 1]];
  32647. };
  32648. // rotate by alpha around (0,0)
  32649. exports.rotationMatrix = function(alpha) {
  32650. var a = alpha * Math.PI / 180;
  32651. return [[Math.cos(a), -Math.sin(a), 0],
  32652. [Math.sin(a), Math.cos(a), 0],
  32653. [0, 0, 1]];
  32654. };
  32655. // rotate by alpha around (x,y)
  32656. exports.rotationXYMatrix = function(a, x, y) {
  32657. return exports.dot(
  32658. exports.dot(exports.translationMatrix(x, y),
  32659. exports.rotationMatrix(a)),
  32660. exports.translationMatrix(-x, -y));
  32661. };
  32662. // applies a 2D transformation matrix to either x and y params or an [x,y] array
  32663. exports.apply2DTransform = function(transform) {
  32664. return function() {
  32665. var args = arguments;
  32666. if(args.length === 3) {
  32667. args = args[0];
  32668. }// from map
  32669. var xy = arguments.length === 1 ? args[0] : [args[0], args[1]];
  32670. return exports.dot(transform, [xy[0], xy[1], 1]).slice(0, 2);
  32671. };
  32672. };
  32673. // applies a 2D transformation matrix to an [x1,y1,x2,y2] array (to transform a segment)
  32674. exports.apply2DTransform2 = function(transform) {
  32675. var at = exports.apply2DTransform(transform);
  32676. return function(xys) {
  32677. return at(xys.slice(0, 2)).concat(at(xys.slice(2, 4)));
  32678. };
  32679. };
  32680. },{}],177:[function(_dereq_,module,exports){
  32681. /**
  32682. * Copyright 2012-2018, Plotly, Inc.
  32683. * All rights reserved.
  32684. *
  32685. * This source code is licensed under the MIT license found in the
  32686. * LICENSE file in the root directory of this source tree.
  32687. */
  32688. 'use strict';
  32689. /**
  32690. * sanitized modulus function that always returns in the range [0, d)
  32691. * rather than (-d, 0] if v is negative
  32692. */
  32693. function mod(v, d) {
  32694. var out = v % d;
  32695. return out < 0 ? out + d : out;
  32696. }
  32697. /**
  32698. * sanitized modulus function that always returns in the range [-d/2, d/2]
  32699. * rather than (-d, 0] if v is negative
  32700. */
  32701. function modHalf(v, d) {
  32702. return Math.abs(v) > (d / 2) ?
  32703. v - Math.round(v / d) * d :
  32704. v;
  32705. }
  32706. module.exports = {
  32707. mod: mod,
  32708. modHalf: modHalf
  32709. };
  32710. },{}],178:[function(_dereq_,module,exports){
  32711. /**
  32712. * Copyright 2012-2018, Plotly, Inc.
  32713. * All rights reserved.
  32714. *
  32715. * This source code is licensed under the MIT license found in the
  32716. * LICENSE file in the root directory of this source tree.
  32717. */
  32718. 'use strict';
  32719. var isNumeric = _dereq_('fast-isnumeric');
  32720. var isArrayOrTypedArray = _dereq_('./is_array').isArrayOrTypedArray;
  32721. /**
  32722. * convert a string s (such as 'xaxis.range[0]')
  32723. * representing a property of nested object into set and get methods
  32724. * also return the string and object so we don't have to keep track of them
  32725. * allows [-1] for an array index, to set a property inside all elements
  32726. * of an array
  32727. * eg if obj = {arr: [{a: 1}, {a: 2}]}
  32728. * you can do p = nestedProperty(obj, 'arr[-1].a')
  32729. * but you cannot set the array itself this way, to do that
  32730. * just set the whole array.
  32731. * eg if obj = {arr: [1, 2, 3]}
  32732. * you can't do nestedProperty(obj, 'arr[-1]').set(5)
  32733. * but you can do nestedProperty(obj, 'arr').set([5, 5, 5])
  32734. */
  32735. module.exports = function nestedProperty(container, propStr) {
  32736. if(isNumeric(propStr)) propStr = String(propStr);
  32737. else if(typeof propStr !== 'string' ||
  32738. propStr.substr(propStr.length - 4) === '[-1]') {
  32739. throw 'bad property string';
  32740. }
  32741. var j = 0,
  32742. propParts = propStr.split('.'),
  32743. indexed,
  32744. indices,
  32745. i;
  32746. // check for parts of the nesting hierarchy that are numbers (ie array elements)
  32747. while(j < propParts.length) {
  32748. // look for non-bracket chars, then any number of [##] blocks
  32749. indexed = String(propParts[j]).match(/^([^\[\]]*)((\[\-?[0-9]*\])+)$/);
  32750. if(indexed) {
  32751. if(indexed[1]) propParts[j] = indexed[1];
  32752. // allow propStr to start with bracketed array indices
  32753. else if(j === 0) propParts.splice(0, 1);
  32754. else throw 'bad property string';
  32755. indices = indexed[2]
  32756. .substr(1, indexed[2].length - 2)
  32757. .split('][');
  32758. for(i = 0; i < indices.length; i++) {
  32759. j++;
  32760. propParts.splice(j, 0, Number(indices[i]));
  32761. }
  32762. }
  32763. j++;
  32764. }
  32765. if(typeof container !== 'object') {
  32766. return badContainer(container, propStr, propParts);
  32767. }
  32768. return {
  32769. set: npSet(container, propParts, propStr),
  32770. get: npGet(container, propParts),
  32771. astr: propStr,
  32772. parts: propParts,
  32773. obj: container
  32774. };
  32775. };
  32776. function npGet(cont, parts) {
  32777. return function() {
  32778. var curCont = cont,
  32779. curPart,
  32780. allSame,
  32781. out,
  32782. i,
  32783. j;
  32784. for(i = 0; i < parts.length - 1; i++) {
  32785. curPart = parts[i];
  32786. if(curPart === -1) {
  32787. allSame = true;
  32788. out = [];
  32789. for(j = 0; j < curCont.length; j++) {
  32790. out[j] = npGet(curCont[j], parts.slice(i + 1))();
  32791. if(out[j] !== out[0]) allSame = false;
  32792. }
  32793. return allSame ? out[0] : out;
  32794. }
  32795. if(typeof curPart === 'number' && !isArrayOrTypedArray(curCont)) {
  32796. return undefined;
  32797. }
  32798. curCont = curCont[curPart];
  32799. if(typeof curCont !== 'object' || curCont === null) {
  32800. return undefined;
  32801. }
  32802. }
  32803. // only hit this if parts.length === 1
  32804. if(typeof curCont !== 'object' || curCont === null) return undefined;
  32805. out = curCont[parts[i]];
  32806. if(out === null) return undefined;
  32807. return out;
  32808. };
  32809. }
  32810. /*
  32811. * Can this value be deleted? We can delete `undefined`, and `null` except INSIDE an
  32812. * *args* array.
  32813. *
  32814. * Previously we also deleted some `{}` and `[]`, in order to try and make set/unset
  32815. * a net noop; but this causes far more complication than it's worth, and still had
  32816. * lots of exceptions. See https://github.com/plotly/plotly.js/issues/1410
  32817. *
  32818. * *args* arrays get passed directly to API methods and we should respect null if
  32819. * the user put it there, but otherwise null is deleted as we use it as code
  32820. * in restyle/relayout/update for "delete this value" whereas undefined means
  32821. * "ignore this edit"
  32822. */
  32823. var ARGS_PATTERN = /(^|\.)args\[/;
  32824. function isDeletable(val, propStr) {
  32825. return (val === undefined) || (val === null && !propStr.match(ARGS_PATTERN));
  32826. }
  32827. function npSet(cont, parts, propStr) {
  32828. return function(val) {
  32829. var curCont = cont,
  32830. propPart = '',
  32831. containerLevels = [[cont, propPart]],
  32832. toDelete = isDeletable(val, propStr),
  32833. curPart,
  32834. i;
  32835. for(i = 0; i < parts.length - 1; i++) {
  32836. curPart = parts[i];
  32837. if(typeof curPart === 'number' && !isArrayOrTypedArray(curCont)) {
  32838. throw 'array index but container is not an array';
  32839. }
  32840. // handle special -1 array index
  32841. if(curPart === -1) {
  32842. toDelete = !setArrayAll(curCont, parts.slice(i + 1), val, propStr);
  32843. if(toDelete) break;
  32844. else return;
  32845. }
  32846. if(!checkNewContainer(curCont, curPart, parts[i + 1], toDelete)) {
  32847. break;
  32848. }
  32849. curCont = curCont[curPart];
  32850. if(typeof curCont !== 'object' || curCont === null) {
  32851. throw 'container is not an object';
  32852. }
  32853. propPart = joinPropStr(propPart, curPart);
  32854. containerLevels.push([curCont, propPart]);
  32855. }
  32856. if(toDelete) {
  32857. if(i === parts.length - 1) {
  32858. delete curCont[parts[i]];
  32859. // The one bit of pruning we still do: drop `undefined` from the end of arrays.
  32860. // In case someone has already unset previous items, continue until we hit a
  32861. // non-undefined value.
  32862. if(Array.isArray(curCont) && +parts[i] === curCont.length - 1) {
  32863. while(curCont.length && curCont[curCont.length - 1] === undefined) {
  32864. curCont.pop();
  32865. }
  32866. }
  32867. }
  32868. }
  32869. else curCont[parts[i]] = val;
  32870. };
  32871. }
  32872. function joinPropStr(propStr, newPart) {
  32873. var toAdd = newPart;
  32874. if(isNumeric(newPart)) toAdd = '[' + newPart + ']';
  32875. else if(propStr) toAdd = '.' + newPart;
  32876. return propStr + toAdd;
  32877. }
  32878. // handle special -1 array index
  32879. function setArrayAll(containerArray, innerParts, val, propStr) {
  32880. var arrayVal = isArrayOrTypedArray(val),
  32881. allSet = true,
  32882. thisVal = val,
  32883. thisPropStr = propStr.replace('-1', 0),
  32884. deleteThis = arrayVal ? false : isDeletable(val, thisPropStr),
  32885. firstPart = innerParts[0],
  32886. i;
  32887. for(i = 0; i < containerArray.length; i++) {
  32888. thisPropStr = propStr.replace('-1', i);
  32889. if(arrayVal) {
  32890. thisVal = val[i % val.length];
  32891. deleteThis = isDeletable(thisVal, thisPropStr);
  32892. }
  32893. if(deleteThis) allSet = false;
  32894. if(!checkNewContainer(containerArray, i, firstPart, deleteThis)) {
  32895. continue;
  32896. }
  32897. npSet(containerArray[i], innerParts, propStr.replace('-1', i))(thisVal);
  32898. }
  32899. return allSet;
  32900. }
  32901. /**
  32902. * make new sub-container as needed.
  32903. * returns false if there's no container and none is needed
  32904. * because we're only deleting an attribute
  32905. */
  32906. function checkNewContainer(container, part, nextPart, toDelete) {
  32907. if(container[part] === undefined) {
  32908. if(toDelete) return false;
  32909. if(typeof nextPart === 'number') container[part] = [];
  32910. else container[part] = {};
  32911. }
  32912. return true;
  32913. }
  32914. function badContainer(container, propStr, propParts) {
  32915. return {
  32916. set: function() { throw 'bad container'; },
  32917. get: function() {},
  32918. astr: propStr,
  32919. parts: propParts,
  32920. obj: container
  32921. };
  32922. }
  32923. },{"./is_array":170,"fast-isnumeric":18}],179:[function(_dereq_,module,exports){
  32924. /**
  32925. * Copyright 2012-2018, Plotly, Inc.
  32926. * All rights reserved.
  32927. *
  32928. * This source code is licensed under the MIT license found in the
  32929. * LICENSE file in the root directory of this source tree.
  32930. */
  32931. 'use strict';
  32932. // Simple helper functions
  32933. // none of these need any external deps
  32934. module.exports = function noop() {};
  32935. },{}],180:[function(_dereq_,module,exports){
  32936. /**
  32937. * Copyright 2012-2018, Plotly, Inc.
  32938. * All rights reserved.
  32939. *
  32940. * This source code is licensed under the MIT license found in the
  32941. * LICENSE file in the root directory of this source tree.
  32942. */
  32943. 'use strict';
  32944. var d3 = _dereq_('d3');
  32945. var isNumeric = _dereq_('fast-isnumeric');
  32946. var NOTEDATA = [];
  32947. /**
  32948. * notifier
  32949. * @param {String} text The person's user name
  32950. * @param {Number} [delay=1000] The delay time in milliseconds
  32951. * or 'long' which provides 2000 ms delay time.
  32952. * @return {undefined} this function does not return a value
  32953. */
  32954. module.exports = function(text, displayLength) {
  32955. if(NOTEDATA.indexOf(text) !== -1) return;
  32956. NOTEDATA.push(text);
  32957. var ts = 1000;
  32958. if(isNumeric(displayLength)) ts = displayLength;
  32959. else if(displayLength === 'long') ts = 3000;
  32960. var notifierContainer = d3.select('body')
  32961. .selectAll('.plotly-notifier')
  32962. .data([0]);
  32963. notifierContainer.enter()
  32964. .append('div')
  32965. .classed('plotly-notifier', true);
  32966. var notes = notifierContainer.selectAll('.notifier-note').data(NOTEDATA);
  32967. function killNote(transition) {
  32968. transition
  32969. .duration(700)
  32970. .style('opacity', 0)
  32971. .each('end', function(thisText) {
  32972. var thisIndex = NOTEDATA.indexOf(thisText);
  32973. if(thisIndex !== -1) NOTEDATA.splice(thisIndex, 1);
  32974. d3.select(this).remove();
  32975. });
  32976. }
  32977. notes.enter().append('div')
  32978. .classed('notifier-note', true)
  32979. .style('opacity', 0)
  32980. .each(function(thisText) {
  32981. var note = d3.select(this);
  32982. note.append('button')
  32983. .classed('notifier-close', true)
  32984. .html('&times;')
  32985. .on('click', function() {
  32986. note.transition().call(killNote);
  32987. });
  32988. var p = note.append('p');
  32989. var lines = thisText.split(/<br\s*\/?>/g);
  32990. for(var i = 0; i < lines.length; i++) {
  32991. if(i) p.append('br');
  32992. p.append('span').text(lines[i]);
  32993. }
  32994. note.transition()
  32995. .duration(700)
  32996. .style('opacity', 1)
  32997. .transition()
  32998. .delay(ts)
  32999. .call(killNote);
  33000. });
  33001. };
  33002. },{"d3":16,"fast-isnumeric":18}],181:[function(_dereq_,module,exports){
  33003. /**
  33004. * Copyright 2012-2018, Plotly, Inc.
  33005. * All rights reserved.
  33006. *
  33007. * This source code is licensed under the MIT license found in the
  33008. * LICENSE file in the root directory of this source tree.
  33009. */
  33010. 'use strict';
  33011. var setCursor = _dereq_('./setcursor');
  33012. var STASHATTR = 'data-savedcursor';
  33013. var NO_CURSOR = '!!';
  33014. /*
  33015. * works with our CSS cursor classes (see css/_cursor.scss)
  33016. * to override a previous cursor set on d3 single-element selections,
  33017. * by moving the name of the original cursor to the data-savedcursor attr.
  33018. * omit cursor to revert to the previously set value.
  33019. */
  33020. module.exports = function overrideCursor(el3, csr) {
  33021. var savedCursor = el3.attr(STASHATTR);
  33022. if(csr) {
  33023. if(!savedCursor) {
  33024. var classes = (el3.attr('class') || '').split(' ');
  33025. for(var i = 0; i < classes.length; i++) {
  33026. var cls = classes[i];
  33027. if(cls.indexOf('cursor-') === 0) {
  33028. el3.attr(STASHATTR, cls.substr(7))
  33029. .classed(cls, false);
  33030. }
  33031. }
  33032. if(!el3.attr(STASHATTR)) {
  33033. el3.attr(STASHATTR, NO_CURSOR);
  33034. }
  33035. }
  33036. setCursor(el3, csr);
  33037. }
  33038. else if(savedCursor) {
  33039. el3.attr(STASHATTR, null);
  33040. if(savedCursor === NO_CURSOR) setCursor(el3);
  33041. else setCursor(el3, savedCursor);
  33042. }
  33043. };
  33044. },{"./setcursor":189}],182:[function(_dereq_,module,exports){
  33045. /**
  33046. * Copyright 2012-2018, Plotly, Inc.
  33047. * All rights reserved.
  33048. *
  33049. * This source code is licensed under the MIT license found in the
  33050. * LICENSE file in the root directory of this source tree.
  33051. */
  33052. 'use strict';
  33053. var dot = _dereq_('./matrix').dot;
  33054. var BADNUM = _dereq_('../constants/numerical').BADNUM;
  33055. var polygon = module.exports = {};
  33056. /**
  33057. * Turn an array of [x, y] pairs into a polygon object
  33058. * that can test if points are inside it
  33059. *
  33060. * @param ptsIn Array of [x, y] pairs
  33061. *
  33062. * @returns polygon Object {xmin, xmax, ymin, ymax, pts, contains}
  33063. * (x|y)(min|max) are the bounding rect of the polygon
  33064. * pts is the original array, with the first pair repeated at the end
  33065. * contains is a function: (pt, omitFirstEdge)
  33066. * pt is the [x, y] pair to test
  33067. * omitFirstEdge truthy means points exactly on the first edge don't
  33068. * count. This is for use adding one polygon to another so we
  33069. * don't double-count the edge where they meet.
  33070. * returns boolean: is pt inside the polygon (including on its edges)
  33071. */
  33072. polygon.tester = function tester(ptsIn) {
  33073. var pts = ptsIn.slice(),
  33074. xmin = pts[0][0],
  33075. xmax = xmin,
  33076. ymin = pts[0][1],
  33077. ymax = ymin,
  33078. i;
  33079. pts.push(pts[0]);
  33080. for(i = 1; i < pts.length; i++) {
  33081. xmin = Math.min(xmin, pts[i][0]);
  33082. xmax = Math.max(xmax, pts[i][0]);
  33083. ymin = Math.min(ymin, pts[i][1]);
  33084. ymax = Math.max(ymax, pts[i][1]);
  33085. }
  33086. // do we have a rectangle? Handle this here, so we can use the same
  33087. // tester for the rectangular case without sacrificing speed
  33088. var isRect = false,
  33089. rectFirstEdgeTest;
  33090. if(pts.length === 5) {
  33091. if(pts[0][0] === pts[1][0]) { // vert, horz, vert, horz
  33092. if(pts[2][0] === pts[3][0] &&
  33093. pts[0][1] === pts[3][1] &&
  33094. pts[1][1] === pts[2][1]) {
  33095. isRect = true;
  33096. rectFirstEdgeTest = function(pt) { return pt[0] === pts[0][0]; };
  33097. }
  33098. }
  33099. else if(pts[0][1] === pts[1][1]) { // horz, vert, horz, vert
  33100. if(pts[2][1] === pts[3][1] &&
  33101. pts[0][0] === pts[3][0] &&
  33102. pts[1][0] === pts[2][0]) {
  33103. isRect = true;
  33104. rectFirstEdgeTest = function(pt) { return pt[1] === pts[0][1]; };
  33105. }
  33106. }
  33107. }
  33108. function rectContains(pt, omitFirstEdge) {
  33109. var x = pt[0],
  33110. y = pt[1];
  33111. if(x === BADNUM || x < xmin || x > xmax || y === BADNUM || y < ymin || y > ymax) {
  33112. // pt is outside the bounding box of polygon
  33113. return false;
  33114. }
  33115. if(omitFirstEdge && rectFirstEdgeTest(pt)) return false;
  33116. return true;
  33117. }
  33118. function contains(pt, omitFirstEdge) {
  33119. var x = pt[0],
  33120. y = pt[1];
  33121. if(x === BADNUM || x < xmin || x > xmax || y === BADNUM || y < ymin || y > ymax) {
  33122. // pt is outside the bounding box of polygon
  33123. return false;
  33124. }
  33125. var imax = pts.length,
  33126. x1 = pts[0][0],
  33127. y1 = pts[0][1],
  33128. crossings = 0,
  33129. i,
  33130. x0,
  33131. y0,
  33132. xmini,
  33133. ycross;
  33134. for(i = 1; i < imax; i++) {
  33135. // find all crossings of a vertical line upward from pt with
  33136. // polygon segments
  33137. // crossings exactly at xmax don't count, unless the point is
  33138. // exactly on the segment, then it counts as inside.
  33139. x0 = x1;
  33140. y0 = y1;
  33141. x1 = pts[i][0];
  33142. y1 = pts[i][1];
  33143. xmini = Math.min(x0, x1);
  33144. // outside the bounding box of this segment, it's only a crossing
  33145. // if it's below the box.
  33146. if(x < xmini || x > Math.max(x0, x1) || y > Math.max(y0, y1)) {
  33147. continue;
  33148. }
  33149. else if(y < Math.min(y0, y1)) {
  33150. // don't count the left-most point of the segment as a crossing
  33151. // because we don't want to double-count adjacent crossings
  33152. // UNLESS the polygon turns past vertical at exactly this x
  33153. // Note that this is repeated below, but we can't factor it out
  33154. // because
  33155. if(x !== xmini) crossings++;
  33156. }
  33157. // inside the bounding box, check the actual line intercept
  33158. else {
  33159. // vertical segment - we know already that the point is exactly
  33160. // on the segment, so mark the crossing as exactly at the point.
  33161. if(x1 === x0) ycross = y;
  33162. // any other angle
  33163. else ycross = y0 + (x - x0) * (y1 - y0) / (x1 - x0);
  33164. // exactly on the edge: counts as inside the polygon, unless it's the
  33165. // first edge and we're omitting it.
  33166. if(y === ycross) {
  33167. if(i === 1 && omitFirstEdge) return false;
  33168. return true;
  33169. }
  33170. if(y <= ycross && x !== xmini) crossings++;
  33171. }
  33172. }
  33173. // if we've gotten this far, odd crossings means inside, even is outside
  33174. return crossings % 2 === 1;
  33175. }
  33176. // detect if poly is degenerate
  33177. var degenerate = true;
  33178. var lastPt = pts[0];
  33179. for(i = 1; i < pts.length; i++) {
  33180. if(lastPt[0] !== pts[i][0] || lastPt[1] !== pts[i][1]) {
  33181. degenerate = false;
  33182. break;
  33183. }
  33184. }
  33185. return {
  33186. xmin: xmin,
  33187. xmax: xmax,
  33188. ymin: ymin,
  33189. ymax: ymax,
  33190. pts: pts,
  33191. contains: isRect ? rectContains : contains,
  33192. isRect: isRect,
  33193. degenerate: degenerate
  33194. };
  33195. };
  33196. /**
  33197. * Test if a segment of a points array is bent or straight
  33198. *
  33199. * @param pts Array of [x, y] pairs
  33200. * @param start the index of the proposed start of the straight section
  33201. * @param end the index of the proposed end point
  33202. * @param tolerance the max distance off the line connecting start and end
  33203. * before the line counts as bent
  33204. * @returns boolean: true means this segment is bent, false means straight
  33205. */
  33206. var isBent = polygon.isSegmentBent = function isBent(pts, start, end, tolerance) {
  33207. var startPt = pts[start],
  33208. segment = [pts[end][0] - startPt[0], pts[end][1] - startPt[1]],
  33209. segmentSquared = dot(segment, segment),
  33210. segmentLen = Math.sqrt(segmentSquared),
  33211. unitPerp = [-segment[1] / segmentLen, segment[0] / segmentLen],
  33212. i,
  33213. part,
  33214. partParallel;
  33215. for(i = start + 1; i < end; i++) {
  33216. part = [pts[i][0] - startPt[0], pts[i][1] - startPt[1]];
  33217. partParallel = dot(part, segment);
  33218. if(partParallel < 0 || partParallel > segmentSquared ||
  33219. Math.abs(dot(part, unitPerp)) > tolerance) return true;
  33220. }
  33221. return false;
  33222. };
  33223. /**
  33224. * Make a filtering polygon, to minimize the number of segments
  33225. *
  33226. * @param pts Array of [x, y] pairs (must start with at least 1 pair)
  33227. * @param tolerance the maximum deviation from straight allowed for
  33228. * removing points to simplify the polygon
  33229. *
  33230. * @returns Object {addPt, raw, filtered}
  33231. * addPt is a function(pt: [x, y] pair) to add a raw point and
  33232. * continue filtering
  33233. * raw is all the input points
  33234. * filtered is the resulting filtered Array of [x, y] pairs
  33235. */
  33236. polygon.filter = function filter(pts, tolerance) {
  33237. var ptsFiltered = [pts[0]],
  33238. doneRawIndex = 0,
  33239. doneFilteredIndex = 0;
  33240. function addPt(pt) {
  33241. pts.push(pt);
  33242. var prevFilterLen = ptsFiltered.length,
  33243. iLast = doneRawIndex;
  33244. ptsFiltered.splice(doneFilteredIndex + 1);
  33245. for(var i = iLast + 1; i < pts.length; i++) {
  33246. if(i === pts.length - 1 || isBent(pts, iLast, i + 1, tolerance)) {
  33247. ptsFiltered.push(pts[i]);
  33248. if(ptsFiltered.length < prevFilterLen - 2) {
  33249. doneRawIndex = i;
  33250. doneFilteredIndex = ptsFiltered.length - 1;
  33251. }
  33252. iLast = i;
  33253. }
  33254. }
  33255. }
  33256. if(pts.length > 1) {
  33257. var lastPt = pts.pop();
  33258. addPt(lastPt);
  33259. }
  33260. return {
  33261. addPt: addPt,
  33262. raw: pts,
  33263. filtered: ptsFiltered
  33264. };
  33265. };
  33266. },{"../constants/numerical":151,"./matrix":176}],183:[function(_dereq_,module,exports){
  33267. /**
  33268. * Copyright 2012-2018, Plotly, Inc.
  33269. * All rights reserved.
  33270. *
  33271. * This source code is licensed under the MIT license found in the
  33272. * LICENSE file in the root directory of this source tree.
  33273. */
  33274. 'use strict';
  33275. /**
  33276. * Push array with unique items
  33277. *
  33278. * Ignores falsy items, except 0 so we can use it to construct arrays of indices.
  33279. *
  33280. * @param {array} array
  33281. * array to be filled
  33282. * @param {any} item
  33283. * item to be or not to be inserted
  33284. * @return {array}
  33285. * ref to array (now possibly containing one more item)
  33286. *
  33287. */
  33288. module.exports = function pushUnique(array, item) {
  33289. if(item instanceof RegExp) {
  33290. var itemStr = item.toString(),
  33291. i;
  33292. for(i = 0; i < array.length; i++) {
  33293. if(array[i] instanceof RegExp && array[i].toString() === itemStr) {
  33294. return array;
  33295. }
  33296. }
  33297. array.push(item);
  33298. }
  33299. else if((item || item === 0) && array.indexOf(item) === -1) array.push(item);
  33300. return array;
  33301. };
  33302. },{}],184:[function(_dereq_,module,exports){
  33303. /**
  33304. * Copyright 2012-2018, Plotly, Inc.
  33305. * All rights reserved.
  33306. *
  33307. * This source code is licensed under the MIT license found in the
  33308. * LICENSE file in the root directory of this source tree.
  33309. */
  33310. 'use strict';
  33311. var Lib = _dereq_('../lib');
  33312. var config = _dereq_('../plot_api/plot_config');
  33313. /**
  33314. * Copy arg array *without* removing `undefined` values from objects.
  33315. *
  33316. * @param gd
  33317. * @param args
  33318. * @returns {Array}
  33319. */
  33320. function copyArgArray(gd, args) {
  33321. var copy = [];
  33322. var arg;
  33323. for(var i = 0; i < args.length; i++) {
  33324. arg = args[i];
  33325. if(arg === gd) copy[i] = arg;
  33326. else if(typeof arg === 'object') {
  33327. copy[i] = Array.isArray(arg) ?
  33328. Lib.extendDeep([], arg) :
  33329. Lib.extendDeepAll({}, arg);
  33330. }
  33331. else copy[i] = arg;
  33332. }
  33333. return copy;
  33334. }
  33335. // -----------------------------------------------------
  33336. // Undo/Redo queue for plots
  33337. // -----------------------------------------------------
  33338. var queue = {};
  33339. // TODO: disable/enable undo and redo buttons appropriately
  33340. /**
  33341. * Add an item to the undoQueue for a graphDiv
  33342. *
  33343. * @param gd
  33344. * @param undoFunc Function undo this operation
  33345. * @param undoArgs Args to supply undoFunc with
  33346. * @param redoFunc Function to redo this operation
  33347. * @param redoArgs Args to supply redoFunc with
  33348. */
  33349. queue.add = function(gd, undoFunc, undoArgs, redoFunc, redoArgs) {
  33350. var queueObj,
  33351. queueIndex;
  33352. // make sure we have the queue and our position in it
  33353. gd.undoQueue = gd.undoQueue || {index: 0, queue: [], sequence: false};
  33354. queueIndex = gd.undoQueue.index;
  33355. // if we're already playing an undo or redo, or if this is an auto operation
  33356. // (like pane resize... any others?) then we don't save this to the undo queue
  33357. if(gd.autoplay) {
  33358. if(!gd.undoQueue.inSequence) gd.autoplay = false;
  33359. return;
  33360. }
  33361. // if we're not in a sequence or are just starting, we need a new queue item
  33362. if(!gd.undoQueue.sequence || gd.undoQueue.beginSequence) {
  33363. queueObj = {undo: {calls: [], args: []}, redo: {calls: [], args: []}};
  33364. gd.undoQueue.queue.splice(queueIndex, gd.undoQueue.queue.length - queueIndex, queueObj);
  33365. gd.undoQueue.index += 1;
  33366. } else {
  33367. queueObj = gd.undoQueue.queue[queueIndex - 1];
  33368. }
  33369. gd.undoQueue.beginSequence = false;
  33370. // we unshift to handle calls for undo in a forward for loop later
  33371. if(queueObj) {
  33372. queueObj.undo.calls.unshift(undoFunc);
  33373. queueObj.undo.args.unshift(undoArgs);
  33374. queueObj.redo.calls.push(redoFunc);
  33375. queueObj.redo.args.push(redoArgs);
  33376. }
  33377. if(gd.undoQueue.queue.length > config.queueLength) {
  33378. gd.undoQueue.queue.shift();
  33379. gd.undoQueue.index--;
  33380. }
  33381. };
  33382. /**
  33383. * Begin a sequence of undoQueue changes
  33384. *
  33385. * @param gd
  33386. */
  33387. queue.startSequence = function(gd) {
  33388. gd.undoQueue = gd.undoQueue || {index: 0, queue: [], sequence: false};
  33389. gd.undoQueue.sequence = true;
  33390. gd.undoQueue.beginSequence = true;
  33391. };
  33392. /**
  33393. * Stop a sequence of undoQueue changes
  33394. *
  33395. * Call this *after* you're sure your undo chain has ended
  33396. *
  33397. * @param gd
  33398. */
  33399. queue.stopSequence = function(gd) {
  33400. gd.undoQueue = gd.undoQueue || {index: 0, queue: [], sequence: false};
  33401. gd.undoQueue.sequence = false;
  33402. gd.undoQueue.beginSequence = false;
  33403. };
  33404. /**
  33405. * Move one step back in the undo queue, and undo the object there.
  33406. *
  33407. * @param gd
  33408. */
  33409. queue.undo = function undo(gd) {
  33410. var queueObj, i;
  33411. if(gd.framework && gd.framework.isPolar) {
  33412. gd.framework.undo();
  33413. return;
  33414. }
  33415. if(gd.undoQueue === undefined ||
  33416. isNaN(gd.undoQueue.index) ||
  33417. gd.undoQueue.index <= 0) {
  33418. return;
  33419. }
  33420. // index is pointing to next *forward* queueObj, point to the one we're undoing
  33421. gd.undoQueue.index--;
  33422. // get the queueObj for instructions on how to undo
  33423. queueObj = gd.undoQueue.queue[gd.undoQueue.index];
  33424. // this sequence keeps things from adding to the queue during undo/redo
  33425. gd.undoQueue.inSequence = true;
  33426. for(i = 0; i < queueObj.undo.calls.length; i++) {
  33427. queue.plotDo(gd, queueObj.undo.calls[i], queueObj.undo.args[i]);
  33428. }
  33429. gd.undoQueue.inSequence = false;
  33430. gd.autoplay = false;
  33431. };
  33432. /**
  33433. * Redo the current object in the undo, then move forward in the queue.
  33434. *
  33435. * @param gd
  33436. */
  33437. queue.redo = function redo(gd) {
  33438. var queueObj, i;
  33439. if(gd.framework && gd.framework.isPolar) {
  33440. gd.framework.redo();
  33441. return;
  33442. }
  33443. if(gd.undoQueue === undefined ||
  33444. isNaN(gd.undoQueue.index) ||
  33445. gd.undoQueue.index >= gd.undoQueue.queue.length) {
  33446. return;
  33447. }
  33448. // get the queueObj for instructions on how to undo
  33449. queueObj = gd.undoQueue.queue[gd.undoQueue.index];
  33450. // this sequence keeps things from adding to the queue during undo/redo
  33451. gd.undoQueue.inSequence = true;
  33452. for(i = 0; i < queueObj.redo.calls.length; i++) {
  33453. queue.plotDo(gd, queueObj.redo.calls[i], queueObj.redo.args[i]);
  33454. }
  33455. gd.undoQueue.inSequence = false;
  33456. gd.autoplay = false;
  33457. // index is pointing to the thing we just redid, move it
  33458. gd.undoQueue.index++;
  33459. };
  33460. /**
  33461. * Called by undo/redo to make the actual changes.
  33462. *
  33463. * Not meant to be called publically, but included for mocking out in tests.
  33464. *
  33465. * @param gd
  33466. * @param func
  33467. * @param args
  33468. */
  33469. queue.plotDo = function(gd, func, args) {
  33470. gd.autoplay = true;
  33471. // this *won't* copy gd and it preserves `undefined` properties!
  33472. args = copyArgArray(gd, args);
  33473. // call the supplied function
  33474. func.apply(null, args);
  33475. };
  33476. module.exports = queue;
  33477. },{"../lib":169,"../plot_api/plot_config":202}],185:[function(_dereq_,module,exports){
  33478. /**
  33479. * Copyright 2012-2018, Plotly, Inc.
  33480. * All rights reserved.
  33481. *
  33482. * This source code is licensed under the MIT license found in the
  33483. * LICENSE file in the root directory of this source tree.
  33484. */
  33485. 'use strict';
  33486. /*
  33487. * make a regex for matching counter ids/names ie xaxis, xaxis2, xaxis10...
  33488. *
  33489. * @param {string} head: the head of the pattern, eg 'x' matches 'x', 'x2', 'x10' etc.
  33490. * 'xy' is a special case for cartesian subplots: it matches 'x2y3' etc
  33491. * @param {Optional(string)} tail: a fixed piece after the id
  33492. * eg counterRegex('scene', '.annotations') for scene2.annotations etc.
  33493. * @param {boolean} openEnded: if true, the string may continue past the match.
  33494. */
  33495. exports.counter = function(head, tail, openEnded) {
  33496. var fullTail = (tail || '') + (openEnded ? '' : '$');
  33497. if(head === 'xy') {
  33498. return new RegExp('^x([2-9]|[1-9][0-9]+)?y([2-9]|[1-9][0-9]+)?' + fullTail);
  33499. }
  33500. return new RegExp('^' + head + '([2-9]|[1-9][0-9]+)?' + fullTail);
  33501. };
  33502. },{}],186:[function(_dereq_,module,exports){
  33503. /**
  33504. * Copyright 2012-2018, Plotly, Inc.
  33505. * All rights reserved.
  33506. *
  33507. * This source code is licensed under the MIT license found in the
  33508. * LICENSE file in the root directory of this source tree.
  33509. */
  33510. 'use strict';
  33511. // ASCEND: chop off the last nesting level - either [<n>] or .<key> - to ascend
  33512. // the attribute tree. the remaining attrString is in match[1]
  33513. var ASCEND = /^(.*)(\.[^\.\[\]]+|\[\d\])$/;
  33514. // SIMPLEATTR: is this an un-nested attribute? (no dots or brackets)
  33515. var SIMPLEATTR = /^[^\.\[\]]+$/;
  33516. /*
  33517. * calculate a relative attribute string, similar to a relative path
  33518. *
  33519. * @param {string} baseAttr:
  33520. * an attribute string, such as 'annotations[3].x'. The "current location"
  33521. * is the attribute string minus the last component ('annotations[3]')
  33522. * @param {string} relativeAttr:
  33523. * a route to the desired attribute string, using '^' to ascend
  33524. *
  33525. * @return {string} attrString:
  33526. * for example:
  33527. * relativeAttr('annotations[3].x', 'y') = 'annotations[3].y'
  33528. * relativeAttr('annotations[3].x', '^[2].z') = 'annotations[2].z'
  33529. * relativeAttr('annotations[3].x', '^^margin') = 'margin'
  33530. * relativeAttr('annotations[3].x', '^^margin.r') = 'margin.r'
  33531. */
  33532. module.exports = function(baseAttr, relativeAttr) {
  33533. while(relativeAttr) {
  33534. var match = baseAttr.match(ASCEND);
  33535. if(match) baseAttr = match[1];
  33536. else if(baseAttr.match(SIMPLEATTR)) baseAttr = '';
  33537. else throw new Error('bad relativeAttr call:' + [baseAttr, relativeAttr]);
  33538. if(relativeAttr.charAt(0) === '^') relativeAttr = relativeAttr.slice(1);
  33539. else break;
  33540. }
  33541. if(baseAttr && relativeAttr.charAt(0) !== '[') {
  33542. return baseAttr + '.' + relativeAttr;
  33543. }
  33544. return baseAttr + relativeAttr;
  33545. };
  33546. },{}],187:[function(_dereq_,module,exports){
  33547. /**
  33548. * Copyright 2012-2018, Plotly, Inc.
  33549. * All rights reserved.
  33550. *
  33551. * This source code is licensed under the MIT license found in the
  33552. * LICENSE file in the root directory of this source tree.
  33553. */
  33554. 'use strict';
  33555. var isArrayOrTypedArray = _dereq_('./is_array').isArrayOrTypedArray;
  33556. var isPlainObject = _dereq_('./is_plain_object');
  33557. /**
  33558. * Relink private _keys and keys with a function value from one container
  33559. * to the new container.
  33560. * Relink means copying if object is pass-by-value and adding a reference
  33561. * if object is pass-by-ref.
  33562. * This prevents deepCopying massive structures like a webgl context.
  33563. */
  33564. module.exports = function relinkPrivateKeys(toContainer, fromContainer) {
  33565. for(var k in fromContainer) {
  33566. var fromVal = fromContainer[k];
  33567. var toVal = toContainer[k];
  33568. if(toVal === fromVal) {
  33569. continue;
  33570. }
  33571. if(k.charAt(0) === '_' || typeof fromVal === 'function') {
  33572. // if it already exists at this point, it's something
  33573. // that we recreate each time around, so ignore it
  33574. if(k in toContainer) continue;
  33575. toContainer[k] = fromVal;
  33576. }
  33577. else if(isArrayOrTypedArray(fromVal) && isArrayOrTypedArray(toVal) && isPlainObject(fromVal[0])) {
  33578. // filter out data_array items that can contain user objects
  33579. // most of the time the toVal === fromVal check will catch these early
  33580. // but if the user makes new ones we also don't want to recurse in.
  33581. if(k === 'customdata' || k === 'ids') continue;
  33582. // recurse into arrays containers
  33583. var minLen = Math.min(fromVal.length, toVal.length);
  33584. for(var j = 0; j < minLen; j++) {
  33585. if((toVal[j] !== fromVal[j]) && isPlainObject(fromVal[j]) && isPlainObject(toVal[j])) {
  33586. relinkPrivateKeys(toVal[j], fromVal[j]);
  33587. }
  33588. }
  33589. }
  33590. else if(isPlainObject(fromVal) && isPlainObject(toVal)) {
  33591. // recurse into objects, but only if they still exist
  33592. relinkPrivateKeys(toVal, fromVal);
  33593. if(!Object.keys(toVal).length) delete toContainer[k];
  33594. }
  33595. }
  33596. };
  33597. },{"./is_array":170,"./is_plain_object":171}],188:[function(_dereq_,module,exports){
  33598. /**
  33599. * Copyright 2012-2018, Plotly, Inc.
  33600. * All rights reserved.
  33601. *
  33602. * This source code is licensed under the MIT license found in the
  33603. * LICENSE file in the root directory of this source tree.
  33604. */
  33605. 'use strict';
  33606. var isNumeric = _dereq_('fast-isnumeric');
  33607. var loggers = _dereq_('./loggers');
  33608. var identity = _dereq_('./identity');
  33609. // don't trust floating point equality - fraction of bin size to call
  33610. // "on the line" and ensure that they go the right way specified by
  33611. // linelow
  33612. var roundingError = 1e-9;
  33613. /**
  33614. * findBin - find the bin for val - note that it can return outside the
  33615. * bin range any pos. or neg. integer for linear bins, or -1 or
  33616. * bins.length-1 for explicit.
  33617. * bins is either an object {start,size,end} or an array length #bins+1
  33618. * bins can be either increasing or decreasing but must be monotonic
  33619. * for linear bins, we can just calculate. For listed bins, run a binary
  33620. * search linelow (truthy) says the bin boundary should be attributed to
  33621. * the lower bin rather than the default upper bin
  33622. */
  33623. exports.findBin = function(val, bins, linelow) {
  33624. if(isNumeric(bins.start)) {
  33625. return linelow ?
  33626. Math.ceil((val - bins.start) / bins.size - roundingError) - 1 :
  33627. Math.floor((val - bins.start) / bins.size + roundingError);
  33628. }
  33629. else {
  33630. var n1 = 0;
  33631. var n2 = bins.length;
  33632. var c = 0;
  33633. var binSize = (n2 > 1) ? (bins[n2 - 1] - bins[0]) / (n2 - 1) : 1;
  33634. var n, test;
  33635. if(binSize >= 0) {
  33636. test = linelow ? lessThan : lessOrEqual;
  33637. } else {
  33638. test = linelow ? greaterOrEqual : greaterThan;
  33639. }
  33640. val += binSize * roundingError * (linelow ? -1 : 1) * (binSize >= 0 ? 1 : -1);
  33641. // c is just to avoid infinite loops if there's an error
  33642. while(n1 < n2 && c++ < 100) {
  33643. n = Math.floor((n1 + n2) / 2);
  33644. if(test(bins[n], val)) n1 = n + 1;
  33645. else n2 = n;
  33646. }
  33647. if(c > 90) loggers.log('Long binary search...');
  33648. return n1 - 1;
  33649. }
  33650. };
  33651. function lessThan(a, b) { return a < b; }
  33652. function lessOrEqual(a, b) { return a <= b; }
  33653. function greaterThan(a, b) { return a > b; }
  33654. function greaterOrEqual(a, b) { return a >= b; }
  33655. exports.sorterAsc = function(a, b) { return a - b; };
  33656. exports.sorterDes = function(a, b) { return b - a; };
  33657. /**
  33658. * find distinct values in an array, lumping together ones that appear to
  33659. * just be off by a rounding error
  33660. * return the distinct values and the minimum difference between any two
  33661. */
  33662. exports.distinctVals = function(valsIn) {
  33663. var vals = valsIn.slice(); // otherwise we sort the original array...
  33664. vals.sort(exports.sorterAsc);
  33665. var l = vals.length - 1,
  33666. minDiff = (vals[l] - vals[0]) || 1,
  33667. errDiff = minDiff / (l || 1) / 10000,
  33668. v2 = [vals[0]];
  33669. for(var i = 0; i < l; i++) {
  33670. // make sure values aren't just off by a rounding error
  33671. if(vals[i + 1] > vals[i] + errDiff) {
  33672. minDiff = Math.min(minDiff, vals[i + 1] - vals[i]);
  33673. v2.push(vals[i + 1]);
  33674. }
  33675. }
  33676. return {vals: v2, minDiff: minDiff};
  33677. };
  33678. /**
  33679. * return the smallest element from (sorted) array arrayIn that's bigger than val,
  33680. * or (reverse) the largest element smaller than val
  33681. * used to find the best tick given the minimum (non-rounded) tick
  33682. * particularly useful for date/time where things are not powers of 10
  33683. * binary search is probably overkill here...
  33684. */
  33685. exports.roundUp = function(val, arrayIn, reverse) {
  33686. var low = 0,
  33687. high = arrayIn.length - 1,
  33688. mid,
  33689. c = 0,
  33690. dlow = reverse ? 0 : 1,
  33691. dhigh = reverse ? 1 : 0,
  33692. rounded = reverse ? Math.ceil : Math.floor;
  33693. // c is just to avoid infinite loops if there's an error
  33694. while(low < high && c++ < 100) {
  33695. mid = rounded((low + high) / 2);
  33696. if(arrayIn[mid] <= val) low = mid + dlow;
  33697. else high = mid - dhigh;
  33698. }
  33699. return arrayIn[low];
  33700. };
  33701. /**
  33702. * Tweak to Array.sort(sortFn) that improves performance for pre-sorted arrays
  33703. *
  33704. * Motivation: sometimes we need to sort arrays but the input is likely to
  33705. * already be sorted. Browsers don't seem to pick up on pre-sorted arrays,
  33706. * and in fact Chrome is actually *slower* sorting pre-sorted arrays than purely
  33707. * random arrays. FF is at least faster if the array is pre-sorted, but still
  33708. * not as fast as it could be.
  33709. * Here's how this plays out sorting a length-1e6 array:
  33710. *
  33711. * Calls to Sort FN | Chrome bare | FF bare | Chrome tweak | FF tweak
  33712. * | v68.0 Mac | v61.0 Mac| |
  33713. * ------------------+---------------+-----------+----------------+------------
  33714. * ordered | 30.4e6 | 10.1e6 | 1e6 | 1e6
  33715. * reversed | 29.4e6 | 9.9e6 | 1e6 + reverse | 1e6 + reverse
  33716. * random | ~21e6 | ~18.7e6 | ~21e6 | ~18.7e6
  33717. *
  33718. * So this is a substantial win for pre-sorted (ordered or exactly reversed)
  33719. * arrays. Including this wrapper on an unsorted array adds a penalty that will
  33720. * in general be only a few calls to the sort function. The only case this
  33721. * penalty will be significant is if the array is mostly sorted but there are
  33722. * a few unsorted items near the end, but the penalty is still at most N calls
  33723. * out of (for N=1e6) ~20N total calls
  33724. *
  33725. * @param {Array} array: the array, to be sorted in place
  33726. * @param {function} sortFn: As in Array.sort, function(a, b) that puts
  33727. * item a before item b if the return is negative, a after b if positive,
  33728. * and no change if zero.
  33729. * @return {Array}: the original array, sorted in place.
  33730. */
  33731. exports.sort = function(array, sortFn) {
  33732. var notOrdered = 0;
  33733. var notReversed = 0;
  33734. for(var i = 1; i < array.length; i++) {
  33735. var pairOrder = sortFn(array[i], array[i - 1]);
  33736. if(pairOrder < 0) notOrdered = 1;
  33737. else if(pairOrder > 0) notReversed = 1;
  33738. if(notOrdered && notReversed) return array.sort(sortFn);
  33739. }
  33740. return notReversed ? array : array.reverse();
  33741. };
  33742. /**
  33743. * find index in array 'arr' that minimizes 'fn'
  33744. *
  33745. * @param {array} arr : array where to search
  33746. * @param {fn (optional)} fn : function to minimize,
  33747. * if not given, fn is the identity function
  33748. * @return {integer}
  33749. */
  33750. exports.findIndexOfMin = function(arr, fn) {
  33751. fn = fn || identity;
  33752. var min = Infinity;
  33753. var ind;
  33754. for(var i = 0; i < arr.length; i++) {
  33755. var v = fn(arr[i]);
  33756. if(v < min) {
  33757. min = v;
  33758. ind = i;
  33759. }
  33760. }
  33761. return ind;
  33762. };
  33763. },{"./identity":168,"./loggers":174,"fast-isnumeric":18}],189:[function(_dereq_,module,exports){
  33764. /**
  33765. * Copyright 2012-2018, Plotly, Inc.
  33766. * All rights reserved.
  33767. *
  33768. * This source code is licensed under the MIT license found in the
  33769. * LICENSE file in the root directory of this source tree.
  33770. */
  33771. 'use strict';
  33772. // works with our CSS cursor classes (see css/_cursor.scss)
  33773. // to apply cursors to d3 single-element selections.
  33774. // omit cursor to revert to the default.
  33775. module.exports = function setCursor(el3, csr) {
  33776. (el3.attr('class') || '').split(' ').forEach(function(cls) {
  33777. if(cls.indexOf('cursor-') === 0) el3.classed(cls, false);
  33778. });
  33779. if(csr) el3.classed('cursor-' + csr, true);
  33780. };
  33781. },{}],190:[function(_dereq_,module,exports){
  33782. /**
  33783. * Copyright 2012-2018, Plotly, Inc.
  33784. * All rights reserved.
  33785. *
  33786. * This source code is licensed under the MIT license found in the
  33787. * LICENSE file in the root directory of this source tree.
  33788. */
  33789. 'use strict';
  33790. var isNumeric = _dereq_('fast-isnumeric');
  33791. var isArrayOrTypedArray = _dereq_('./is_array').isArrayOrTypedArray;
  33792. /**
  33793. * aggNums() returns the result of an aggregate function applied to an array of
  33794. * values, where non-numerical values have been tossed out.
  33795. *
  33796. * @param {function} f - aggregation function (e.g., Math.min)
  33797. * @param {Number} v - initial value (continuing from previous calls)
  33798. * if there's no continuing value, use null for selector-type
  33799. * functions (max,min), or 0 for summations
  33800. * @param {Array} a - array to aggregate (may be nested, we will recurse,
  33801. * but all elements must have the same dimension)
  33802. * @param {Number} len - maximum length of a to aggregate
  33803. * @return {Number} - result of f applied to a starting from v
  33804. */
  33805. exports.aggNums = function(f, v, a, len) {
  33806. var i,
  33807. b;
  33808. if(!len || len > a.length) len = a.length;
  33809. if(!isNumeric(v)) v = false;
  33810. if(isArrayOrTypedArray(a[0])) {
  33811. b = new Array(len);
  33812. for(i = 0; i < len; i++) b[i] = exports.aggNums(f, v, a[i]);
  33813. a = b;
  33814. }
  33815. for(i = 0; i < len; i++) {
  33816. if(!isNumeric(v)) v = a[i];
  33817. else if(isNumeric(a[i])) v = f(+v, +a[i]);
  33818. }
  33819. return v;
  33820. };
  33821. /**
  33822. * mean & std dev functions using aggNums, so it handles non-numerics nicely
  33823. * even need to use aggNums instead of .length, to toss out non-numerics
  33824. */
  33825. exports.len = function(data) {
  33826. return exports.aggNums(function(a) { return a + 1; }, 0, data);
  33827. };
  33828. exports.mean = function(data, len) {
  33829. if(!len) len = exports.len(data);
  33830. return exports.aggNums(function(a, b) { return a + b; }, 0, data) / len;
  33831. };
  33832. exports.midRange = function(numArr) {
  33833. if(numArr === undefined || numArr.length === 0) return undefined;
  33834. return (exports.aggNums(Math.max, null, numArr) + exports.aggNums(Math.min, null, numArr)) / 2;
  33835. };
  33836. exports.variance = function(data, len, mean) {
  33837. if(!len) len = exports.len(data);
  33838. if(!isNumeric(mean)) mean = exports.mean(data, len);
  33839. return exports.aggNums(function(a, b) {
  33840. return a + Math.pow(b - mean, 2);
  33841. }, 0, data) / len;
  33842. };
  33843. exports.stdev = function(data, len, mean) {
  33844. return Math.sqrt(exports.variance(data, len, mean));
  33845. };
  33846. /**
  33847. * interp() computes a percentile (quantile) for a given distribution.
  33848. * We interpolate the distribution (to compute quantiles, we follow method #10 here:
  33849. * http://www.amstat.org/publications/jse/v14n3/langford.html).
  33850. * Typically the index or rank (n * arr.length) may be non-integer.
  33851. * For reference: ends are clipped to the extreme values in the array;
  33852. * For box plots: index you get is half a point too high (see
  33853. * http://en.wikipedia.org/wiki/Percentile#Nearest_rank) but note that this definition
  33854. * indexes from 1 rather than 0, so we subtract 1/2 (instead of add).
  33855. *
  33856. * @param {Array} arr - This array contains the values that make up the distribution.
  33857. * @param {Number} n - Between 0 and 1, n = p/100 is such that we compute the p^th percentile.
  33858. * For example, the 50th percentile (or median) corresponds to n = 0.5
  33859. * @return {Number} - percentile
  33860. */
  33861. exports.interp = function(arr, n) {
  33862. if(!isNumeric(n)) throw 'n should be a finite number';
  33863. n = n * arr.length - 0.5;
  33864. if(n < 0) return arr[0];
  33865. if(n > arr.length - 1) return arr[arr.length - 1];
  33866. var frac = n % 1;
  33867. return frac * arr[Math.ceil(n)] + (1 - frac) * arr[Math.floor(n)];
  33868. };
  33869. },{"./is_array":170,"fast-isnumeric":18}],191:[function(_dereq_,module,exports){
  33870. /**
  33871. * Copyright 2012-2018, Plotly, Inc.
  33872. * All rights reserved.
  33873. *
  33874. * This source code is licensed under the MIT license found in the
  33875. * LICENSE file in the root directory of this source tree.
  33876. */
  33877. 'use strict';
  33878. /* global MathJax:false */
  33879. var d3 = _dereq_('d3');
  33880. var Lib = _dereq_('../lib');
  33881. var xmlnsNamespaces = _dereq_('../constants/xmlns_namespaces');
  33882. var LINE_SPACING = _dereq_('../constants/alignment').LINE_SPACING;
  33883. // text converter
  33884. function getSize(_selection, _dimension) {
  33885. return _selection.node().getBoundingClientRect()[_dimension];
  33886. }
  33887. var FIND_TEX = /([^$]*)([$]+[^$]*[$]+)([^$]*)/;
  33888. exports.convertToTspans = function(_context, gd, _callback) {
  33889. var str = _context.text();
  33890. // Until we get tex integrated more fully (so it can be used along with non-tex)
  33891. // allow some elements to prohibit it by attaching 'data-notex' to the original
  33892. var tex = (!_context.attr('data-notex')) &&
  33893. (typeof MathJax !== 'undefined') &&
  33894. str.match(FIND_TEX);
  33895. var parent = d3.select(_context.node().parentNode);
  33896. if(parent.empty()) return;
  33897. var svgClass = (_context.attr('class')) ? _context.attr('class').split(' ')[0] : 'text';
  33898. svgClass += '-math';
  33899. parent.selectAll('svg.' + svgClass).remove();
  33900. parent.selectAll('g.' + svgClass + '-group').remove();
  33901. _context.style('display', null)
  33902. .attr({
  33903. // some callers use data-unformatted *from the <text> element* in 'cancel'
  33904. // so we need it here even if we're going to turn it into math
  33905. // these two (plus style and text-anchor attributes) form the key we're
  33906. // going to use for Drawing.bBox
  33907. 'data-unformatted': str,
  33908. 'data-math': 'N'
  33909. });
  33910. function showText() {
  33911. if(!parent.empty()) {
  33912. svgClass = _context.attr('class') + '-math';
  33913. parent.select('svg.' + svgClass).remove();
  33914. }
  33915. _context.text('')
  33916. .style('white-space', 'pre');
  33917. var hasLink = buildSVGText(_context.node(), str);
  33918. if(hasLink) {
  33919. // at least in Chrome, pointer-events does not seem
  33920. // to be honored in children of <text> elements
  33921. // so if we have an anchor, we have to make the
  33922. // whole element respond
  33923. _context.style('pointer-events', 'all');
  33924. }
  33925. exports.positionText(_context);
  33926. if(_callback) _callback.call(_context);
  33927. }
  33928. if(tex) {
  33929. ((gd && gd._promises) || []).push(new Promise(function(resolve) {
  33930. _context.style('display', 'none');
  33931. var fontSize = parseInt(_context.node().style.fontSize, 10);
  33932. var config = {fontSize: fontSize};
  33933. texToSVG(tex[2], config, function(_svgEl, _glyphDefs, _svgBBox) {
  33934. parent.selectAll('svg.' + svgClass).remove();
  33935. parent.selectAll('g.' + svgClass + '-group').remove();
  33936. var newSvg = _svgEl && _svgEl.select('svg');
  33937. if(!newSvg || !newSvg.node()) {
  33938. showText();
  33939. resolve();
  33940. return;
  33941. }
  33942. var mathjaxGroup = parent.append('g')
  33943. .classed(svgClass + '-group', true)
  33944. .attr({
  33945. 'pointer-events': 'none',
  33946. 'data-unformatted': str,
  33947. 'data-math': 'Y'
  33948. });
  33949. mathjaxGroup.node().appendChild(newSvg.node());
  33950. // stitch the glyph defs
  33951. if(_glyphDefs && _glyphDefs.node()) {
  33952. newSvg.node().insertBefore(_glyphDefs.node().cloneNode(true),
  33953. newSvg.node().firstChild);
  33954. }
  33955. newSvg.attr({
  33956. 'class': svgClass,
  33957. height: _svgBBox.height,
  33958. preserveAspectRatio: 'xMinYMin meet'
  33959. })
  33960. .style({overflow: 'visible', 'pointer-events': 'none'});
  33961. var fill = _context.node().style.fill || 'black';
  33962. newSvg.select('g').attr({fill: fill, stroke: fill});
  33963. var newSvgW = getSize(newSvg, 'width'),
  33964. newSvgH = getSize(newSvg, 'height'),
  33965. newX = +_context.attr('x') - newSvgW *
  33966. {start: 0, middle: 0.5, end: 1}[_context.attr('text-anchor') || 'start'],
  33967. // font baseline is about 1/4 fontSize below centerline
  33968. textHeight = fontSize || getSize(_context, 'height'),
  33969. dy = -textHeight / 4;
  33970. if(svgClass[0] === 'y') {
  33971. mathjaxGroup.attr({
  33972. transform: 'rotate(' + [-90, +_context.attr('x'), +_context.attr('y')] +
  33973. ') translate(' + [-newSvgW / 2, dy - newSvgH / 2] + ')'
  33974. });
  33975. newSvg.attr({x: +_context.attr('x'), y: +_context.attr('y')});
  33976. }
  33977. else if(svgClass[0] === 'l') {
  33978. newSvg.attr({x: _context.attr('x'), y: dy - (newSvgH / 2)});
  33979. }
  33980. else if(svgClass[0] === 'a') {
  33981. newSvg.attr({x: 0, y: dy});
  33982. }
  33983. else {
  33984. newSvg.attr({x: newX, y: (+_context.attr('y') + dy - newSvgH / 2)});
  33985. }
  33986. if(_callback) _callback.call(_context, mathjaxGroup);
  33987. resolve(mathjaxGroup);
  33988. });
  33989. }));
  33990. }
  33991. else showText();
  33992. return _context;
  33993. };
  33994. // MathJax
  33995. var LT_MATCH = /(<|&lt;|&#60;)/g;
  33996. var GT_MATCH = /(>|&gt;|&#62;)/g;
  33997. function cleanEscapesForTex(s) {
  33998. return s.replace(LT_MATCH, '\\lt ')
  33999. .replace(GT_MATCH, '\\gt ');
  34000. }
  34001. function texToSVG(_texString, _config, _callback) {
  34002. var randomID = 'math-output-' + Lib.randstr({}, 64);
  34003. var tmpDiv = d3.select('body').append('div')
  34004. .attr({id: randomID})
  34005. .style({visibility: 'hidden', position: 'absolute'})
  34006. .style({'font-size': _config.fontSize + 'px'})
  34007. .text(cleanEscapesForTex(_texString));
  34008. MathJax.Hub.Queue(['Typeset', MathJax.Hub, tmpDiv.node()], function() {
  34009. var glyphDefs = d3.select('body').select('#MathJax_SVG_glyphs');
  34010. if(tmpDiv.select('.MathJax_SVG').empty() || !tmpDiv.select('svg').node()) {
  34011. Lib.log('There was an error in the tex syntax.', _texString);
  34012. _callback();
  34013. }
  34014. else {
  34015. var svgBBox = tmpDiv.select('svg').node().getBoundingClientRect();
  34016. _callback(tmpDiv.select('.MathJax_SVG'), glyphDefs, svgBBox);
  34017. }
  34018. tmpDiv.remove();
  34019. });
  34020. }
  34021. var TAG_STYLES = {
  34022. // would like to use baseline-shift for sub/sup but FF doesn't support it
  34023. // so we need to use dy along with the uber hacky shift-back-to
  34024. // baseline below
  34025. sup: 'font-size:70%',
  34026. sub: 'font-size:70%',
  34027. b: 'font-weight:bold',
  34028. i: 'font-style:italic',
  34029. a: 'cursor:pointer',
  34030. span: '',
  34031. em: 'font-style:italic;font-weight:bold'
  34032. };
  34033. // baseline shifts for sub and sup
  34034. var SHIFT_DY = {
  34035. sub: '0.3em',
  34036. sup: '-0.6em'
  34037. };
  34038. // reset baseline by adding a tspan (empty except for a zero-width space)
  34039. // with dy of -70% * SHIFT_DY (because font-size=70%)
  34040. var RESET_DY = {
  34041. sub: '-0.21em',
  34042. sup: '0.42em'
  34043. };
  34044. var ZERO_WIDTH_SPACE = '\u200b';
  34045. /*
  34046. * Whitelist of protocols in user-supplied urls. Mostly we want to avoid javascript
  34047. * and related attack vectors. The empty items are there for IE, that in various
  34048. * versions treats relative paths as having different flavors of no protocol, while
  34049. * other browsers have these explicitly inherit the protocol of the page they're in.
  34050. */
  34051. var PROTOCOLS = ['http:', 'https:', 'mailto:', '', undefined, ':'];
  34052. var STRIP_TAGS = new RegExp('</?(' + Object.keys(TAG_STYLES).join('|') + ')( [^>]*)?/?>', 'g');
  34053. var NEWLINES = /(\r\n?|\n)/g;
  34054. var SPLIT_TAGS = /(<[^<>]*>)/;
  34055. var ONE_TAG = /<(\/?)([^ >]*)(\s+(.*))?>/i;
  34056. var BR_TAG = /<br(\s+.*)?>/i;
  34057. /*
  34058. * style and href: pull them out of either single or double quotes. Also
  34059. * - target: (_blank|_self|_parent|_top|framename)
  34060. * note that you can't use target to get a popup but if you use popup,
  34061. * a `framename` will be passed along as the name of the popup window.
  34062. * per the spec, cannot contain whitespace.
  34063. * for backward compatibility we default to '_blank'
  34064. * - popup: a custom one for us to enable popup (new window) links. String
  34065. * for window.open -> strWindowFeatures, like 'menubar=yes,width=500,height=550'
  34066. * note that at least in Chrome, you need to give at least one property
  34067. * in this string or the page will open in a new tab anyway. We follow this
  34068. * convention and will not make a popup if this string is empty.
  34069. * per the spec, cannot contain whitespace.
  34070. *
  34071. * Because we hack in other attributes with style (sub & sup), drop any trailing
  34072. * semicolon in user-supplied styles so we can consistently append the tag-dependent style
  34073. *
  34074. * These are for tag attributes; Chrome anyway will convert entities in
  34075. * attribute values, but not in attribute names
  34076. * you can test this by for example:
  34077. * > p = document.createElement('p')
  34078. * > p.innerHTML = '<span styl&#x65;="font-color:r&#x65;d;">Hi</span>'
  34079. * > p.innerHTML
  34080. * <- '<span styl&#x65;="font-color:red;">Hi</span>'
  34081. */
  34082. var STYLEMATCH = /(^|[\s"'])style\s*=\s*("([^"]*);?"|'([^']*);?')/i;
  34083. var HREFMATCH = /(^|[\s"'])href\s*=\s*("([^"]*)"|'([^']*)')/i;
  34084. var TARGETMATCH = /(^|[\s"'])target\s*=\s*("([^"\s]*)"|'([^'\s]*)')/i;
  34085. var POPUPMATCH = /(^|[\s"'])popup\s*=\s*("([\w=,]*)"|'([\w=,]*)')/i;
  34086. // dedicated matcher for these quoted regexes, that can return their results
  34087. // in two different places
  34088. function getQuotedMatch(_str, re) {
  34089. if(!_str) return null;
  34090. var match = _str.match(re);
  34091. var result = match && (match[3] || match[4]);
  34092. return result && convertEntities(result);
  34093. }
  34094. var COLORMATCH = /(^|;)\s*color:/;
  34095. exports.plainText = function(_str) {
  34096. // strip out our pseudo-html so we have a readable
  34097. // version to put into text fields
  34098. return (_str || '').replace(STRIP_TAGS, ' ');
  34099. };
  34100. /*
  34101. * N.B. HTML entities are listed without the leading '&' and trailing ';'
  34102. * https://www.freeformatter.com/html-entities.html
  34103. *
  34104. * FWIW if we wanted to support the full set, it has 2261 entries:
  34105. * https://www.w3.org/TR/html5/entities.json
  34106. * though I notice that some of these are duplicates and/or are missing ";"
  34107. * eg: "&amp;", "&amp", "&AMP;", and "&AMP" all map to "&"
  34108. * We no longer need to include numeric entities here, these are now handled
  34109. * by String.fromCodePoint/fromCharCode
  34110. *
  34111. * Anyway the only ones that are really important to allow are the HTML special
  34112. * chars <, >, and &, because these ones can trigger special processing if not
  34113. * replaced by the corresponding entity.
  34114. */
  34115. var entityToUnicode = {
  34116. mu: 'μ',
  34117. amp: '&',
  34118. lt: '<',
  34119. gt: '>',
  34120. nbsp: ' ',
  34121. times: '×',
  34122. plusmn: '±',
  34123. deg: '°'
  34124. };
  34125. // NOTE: in general entities can contain uppercase too (so [a-zA-Z]) but all the
  34126. // ones we support use only lowercase. If we ever change that, update the regex.
  34127. var ENTITY_MATCH = /&(#\d+|#x[\da-fA-F]+|[a-z]+);/g;
  34128. function convertEntities(_str) {
  34129. return _str.replace(ENTITY_MATCH, function(fullMatch, innerMatch) {
  34130. var outChar;
  34131. if(innerMatch.charAt(0) === '#') {
  34132. // cannot use String.fromCodePoint in IE
  34133. outChar = fromCodePoint(
  34134. innerMatch.charAt(1) === 'x' ?
  34135. parseInt(innerMatch.substr(2), 16) :
  34136. parseInt(innerMatch.substr(1), 10)
  34137. );
  34138. }
  34139. else outChar = entityToUnicode[innerMatch];
  34140. // as in regular HTML, if we didn't decode the entity just
  34141. // leave the raw text in place.
  34142. return outChar || fullMatch;
  34143. });
  34144. }
  34145. exports.convertEntities = convertEntities;
  34146. function fromCodePoint(code) {
  34147. // Don't allow overflow. In Chrome this turns into � but I feel like it's
  34148. // more useful to just not convert it at all.
  34149. if(code > 0x10FFFF) return;
  34150. var stringFromCodePoint = String.fromCodePoint;
  34151. if(stringFromCodePoint) return stringFromCodePoint(code);
  34152. // IE doesn't have String.fromCodePoint
  34153. // see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint
  34154. var stringFromCharCode = String.fromCharCode;
  34155. if(code <= 0xFFFF) return stringFromCharCode(code);
  34156. return stringFromCharCode(
  34157. (code >> 10) + 0xD7C0,
  34158. (code % 0x400) + 0xDC00
  34159. );
  34160. }
  34161. /*
  34162. * buildSVGText: convert our pseudo-html into SVG tspan elements, and attach these
  34163. * to containerNode
  34164. *
  34165. * @param {svg text element} containerNode: the <text> node to insert this text into
  34166. * @param {string} str: the pseudo-html string to convert to svg
  34167. *
  34168. * @returns {bool}: does the result contain any links? We need to handle the text element
  34169. * somewhat differently if it does, so just keep track of this when it happens.
  34170. */
  34171. function buildSVGText(containerNode, str) {
  34172. /*
  34173. * Normalize behavior between IE and others wrt newlines and whitespace:pre
  34174. * this combination makes IE barf https://github.com/plotly/plotly.js/issues/746
  34175. * Chrome and FF display \n, \r, or \r\n as a space in this mode.
  34176. * I feel like at some point we turned these into <br> but currently we don't so
  34177. * I'm just going to cement what we do now in Chrome and FF
  34178. */
  34179. str = str.replace(NEWLINES, ' ');
  34180. var hasLink = false;
  34181. // as we're building the text, keep track of what elements we're nested inside
  34182. // nodeStack will be an array of {node, type, style, href, target, popup}
  34183. // where only type: 'a' gets the last 3 and node is only added when it's created
  34184. var nodeStack = [];
  34185. var currentNode;
  34186. var currentLine = -1;
  34187. function newLine() {
  34188. currentLine++;
  34189. var lineNode = document.createElementNS(xmlnsNamespaces.svg, 'tspan');
  34190. d3.select(lineNode).attr({
  34191. class: 'line',
  34192. dy: (currentLine * LINE_SPACING) + 'em'
  34193. });
  34194. containerNode.appendChild(lineNode);
  34195. currentNode = lineNode;
  34196. var oldNodeStack = nodeStack;
  34197. nodeStack = [{node: lineNode}];
  34198. if(oldNodeStack.length > 1) {
  34199. for(var i = 1; i < oldNodeStack.length; i++) {
  34200. enterNode(oldNodeStack[i]);
  34201. }
  34202. }
  34203. }
  34204. function enterNode(nodeSpec) {
  34205. var type = nodeSpec.type;
  34206. var nodeAttrs = {};
  34207. var nodeType;
  34208. if(type === 'a') {
  34209. nodeType = 'a';
  34210. var target = nodeSpec.target;
  34211. var href = nodeSpec.href;
  34212. var popup = nodeSpec.popup;
  34213. if(href) {
  34214. nodeAttrs = {
  34215. 'xlink:xlink:show': (target === '_blank' || target.charAt(0) !== '_') ? 'new' : 'replace',
  34216. target: target,
  34217. 'xlink:xlink:href': href
  34218. };
  34219. if(popup) {
  34220. // security: href and target are not inserted as code but
  34221. // as attributes. popup is, but limited to /[A-Za-z0-9_=,]/
  34222. nodeAttrs.onclick = 'window.open(this.href.baseVal,this.target.baseVal,"' +
  34223. popup + '");return false;';
  34224. }
  34225. }
  34226. }
  34227. else nodeType = 'tspan';
  34228. if(nodeSpec.style) nodeAttrs.style = nodeSpec.style;
  34229. var newNode = document.createElementNS(xmlnsNamespaces.svg, nodeType);
  34230. if(type === 'sup' || type === 'sub') {
  34231. addTextNode(currentNode, ZERO_WIDTH_SPACE);
  34232. currentNode.appendChild(newNode);
  34233. var resetter = document.createElementNS(xmlnsNamespaces.svg, 'tspan');
  34234. addTextNode(resetter, ZERO_WIDTH_SPACE);
  34235. d3.select(resetter).attr('dy', RESET_DY[type]);
  34236. nodeAttrs.dy = SHIFT_DY[type];
  34237. currentNode.appendChild(newNode);
  34238. currentNode.appendChild(resetter);
  34239. }
  34240. else {
  34241. currentNode.appendChild(newNode);
  34242. }
  34243. d3.select(newNode).attr(nodeAttrs);
  34244. currentNode = nodeSpec.node = newNode;
  34245. nodeStack.push(nodeSpec);
  34246. }
  34247. function addTextNode(node, text) {
  34248. node.appendChild(document.createTextNode(text));
  34249. }
  34250. function exitNode(type) {
  34251. // A bare closing tag can't close the root node. If we encounter this it
  34252. // means there's an extra closing tag that can just be ignored:
  34253. if(nodeStack.length === 1) {
  34254. Lib.log('Ignoring unexpected end tag </' + type + '>.', str);
  34255. return;
  34256. }
  34257. var innerNode = nodeStack.pop();
  34258. if(type !== innerNode.type) {
  34259. Lib.log('Start tag <' + innerNode.type + '> doesnt match end tag <' +
  34260. type + '>. Pretending it did match.', str);
  34261. }
  34262. currentNode = nodeStack[nodeStack.length - 1].node;
  34263. }
  34264. var hasLines = BR_TAG.test(str);
  34265. if(hasLines) newLine();
  34266. else {
  34267. currentNode = containerNode;
  34268. nodeStack = [{node: containerNode}];
  34269. }
  34270. var parts = str.split(SPLIT_TAGS);
  34271. for(var i = 0; i < parts.length; i++) {
  34272. var parti = parts[i];
  34273. var match = parti.match(ONE_TAG);
  34274. var tagType = match && match[2].toLowerCase();
  34275. var tagStyle = TAG_STYLES[tagType];
  34276. if(tagType === 'br') {
  34277. newLine();
  34278. }
  34279. else if(tagStyle === undefined) {
  34280. addTextNode(currentNode, convertEntities(parti));
  34281. }
  34282. else {
  34283. // tag - open or close
  34284. if(match[1]) {
  34285. exitNode(tagType);
  34286. }
  34287. else {
  34288. var extra = match[4];
  34289. var nodeSpec = {type: tagType};
  34290. // now add style, from both the tag name and any extra css
  34291. // Most of the svg css that users will care about is just like html,
  34292. // but font color is different (uses fill). Let our users ignore this.
  34293. var css = getQuotedMatch(extra, STYLEMATCH);
  34294. if(css) {
  34295. css = css.replace(COLORMATCH, '$1 fill:');
  34296. if(tagStyle) css += ';' + tagStyle;
  34297. }
  34298. else if(tagStyle) css = tagStyle;
  34299. if(css) nodeSpec.style = css;
  34300. if(tagType === 'a') {
  34301. hasLink = true;
  34302. var href = getQuotedMatch(extra, HREFMATCH);
  34303. if(href) {
  34304. // check safe protocols
  34305. var dummyAnchor = document.createElement('a');
  34306. dummyAnchor.href = href;
  34307. if(PROTOCOLS.indexOf(dummyAnchor.protocol) !== -1) {
  34308. // Decode href to allow both already encoded and not encoded
  34309. // URIs. Without decoding prior encoding, an already encoded
  34310. // URI would be encoded twice producing a semantically different URI.
  34311. nodeSpec.href = encodeURI(decodeURI(href));
  34312. nodeSpec.target = getQuotedMatch(extra, TARGETMATCH) || '_blank';
  34313. nodeSpec.popup = getQuotedMatch(extra, POPUPMATCH);
  34314. }
  34315. }
  34316. }
  34317. enterNode(nodeSpec);
  34318. }
  34319. }
  34320. }
  34321. return hasLink;
  34322. }
  34323. exports.lineCount = function lineCount(s) {
  34324. return s.selectAll('tspan.line').size() || 1;
  34325. };
  34326. exports.positionText = function positionText(s, x, y) {
  34327. return s.each(function() {
  34328. var text = d3.select(this);
  34329. function setOrGet(attr, val) {
  34330. if(val === undefined) {
  34331. val = text.attr(attr);
  34332. if(val === null) {
  34333. text.attr(attr, 0);
  34334. val = 0;
  34335. }
  34336. }
  34337. else text.attr(attr, val);
  34338. return val;
  34339. }
  34340. var thisX = setOrGet('x', x);
  34341. var thisY = setOrGet('y', y);
  34342. if(this.nodeName === 'text') {
  34343. text.selectAll('tspan.line').attr({x: thisX, y: thisY});
  34344. }
  34345. });
  34346. };
  34347. function alignHTMLWith(_base, container, options) {
  34348. var alignH = options.horizontalAlign,
  34349. alignV = options.verticalAlign || 'top',
  34350. bRect = _base.node().getBoundingClientRect(),
  34351. cRect = container.node().getBoundingClientRect(),
  34352. thisRect,
  34353. getTop,
  34354. getLeft;
  34355. if(alignV === 'bottom') {
  34356. getTop = function() { return bRect.bottom - thisRect.height; };
  34357. } else if(alignV === 'middle') {
  34358. getTop = function() { return bRect.top + (bRect.height - thisRect.height) / 2; };
  34359. } else { // default: top
  34360. getTop = function() { return bRect.top; };
  34361. }
  34362. if(alignH === 'right') {
  34363. getLeft = function() { return bRect.right - thisRect.width; };
  34364. } else if(alignH === 'center') {
  34365. getLeft = function() { return bRect.left + (bRect.width - thisRect.width) / 2; };
  34366. } else { // default: left
  34367. getLeft = function() { return bRect.left; };
  34368. }
  34369. return function() {
  34370. thisRect = this.node().getBoundingClientRect();
  34371. this.style({
  34372. top: (getTop() - cRect.top) + 'px',
  34373. left: (getLeft() - cRect.left) + 'px',
  34374. 'z-index': 1000
  34375. });
  34376. return this;
  34377. };
  34378. }
  34379. /*
  34380. * Editable title
  34381. * @param {d3.selection} context: the element being edited. Normally text,
  34382. * but if it isn't, you should provide the styling options
  34383. * @param {object} options:
  34384. * @param {div} options.gd: graphDiv
  34385. * @param {d3.selection} options.delegate: item to bind events to if not this
  34386. * @param {boolean} options.immediate: start editing now (true) or on click (false, default)
  34387. * @param {string} options.fill: font color if not as shown
  34388. * @param {string} options.background: background color if not as shown
  34389. * @param {string} options.text: initial text, if not as shown
  34390. * @param {string} options.horizontalAlign: alignment of the edit box wrt. the bound element
  34391. * @param {string} options.verticalAlign: alignment of the edit box wrt. the bound element
  34392. */
  34393. exports.makeEditable = function(context, options) {
  34394. var gd = options.gd;
  34395. var _delegate = options.delegate;
  34396. var dispatch = d3.dispatch('edit', 'input', 'cancel');
  34397. var handlerElement = _delegate || context;
  34398. context.style({'pointer-events': _delegate ? 'none' : 'all'});
  34399. if(context.size() !== 1) throw new Error('boo');
  34400. function handleClick() {
  34401. appendEditable();
  34402. context.style({opacity: 0});
  34403. // also hide any mathjax svg
  34404. var svgClass = handlerElement.attr('class'),
  34405. mathjaxClass;
  34406. if(svgClass) mathjaxClass = '.' + svgClass.split(' ')[0] + '-math-group';
  34407. else mathjaxClass = '[class*=-math-group]';
  34408. if(mathjaxClass) {
  34409. d3.select(context.node().parentNode).select(mathjaxClass).style({opacity: 0});
  34410. }
  34411. }
  34412. function selectElementContents(_el) {
  34413. var el = _el.node();
  34414. var range = document.createRange();
  34415. range.selectNodeContents(el);
  34416. var sel = window.getSelection();
  34417. sel.removeAllRanges();
  34418. sel.addRange(range);
  34419. el.focus();
  34420. }
  34421. function appendEditable() {
  34422. var plotDiv = d3.select(gd);
  34423. var container = plotDiv.select('.svg-container');
  34424. var div = container.append('div');
  34425. var cStyle = context.node().style;
  34426. var fontSize = parseFloat(cStyle.fontSize || 12);
  34427. var initialText = options.text;
  34428. if(initialText === undefined) initialText = context.attr('data-unformatted');
  34429. div.classed('plugin-editable editable', true)
  34430. .style({
  34431. position: 'absolute',
  34432. 'font-family': cStyle.fontFamily || 'Arial',
  34433. 'font-size': fontSize,
  34434. color: options.fill || cStyle.fill || 'black',
  34435. opacity: 1,
  34436. 'background-color': options.background || 'transparent',
  34437. outline: '#ffffff33 1px solid',
  34438. margin: [-fontSize / 8 + 1, 0, 0, -1].join('px ') + 'px',
  34439. padding: '0',
  34440. 'box-sizing': 'border-box'
  34441. })
  34442. .attr({contenteditable: true})
  34443. .text(initialText)
  34444. .call(alignHTMLWith(context, container, options))
  34445. .on('blur', function() {
  34446. gd._editing = false;
  34447. context.text(this.textContent)
  34448. .style({opacity: 1});
  34449. var svgClass = d3.select(this).attr('class'),
  34450. mathjaxClass;
  34451. if(svgClass) mathjaxClass = '.' + svgClass.split(' ')[0] + '-math-group';
  34452. else mathjaxClass = '[class*=-math-group]';
  34453. if(mathjaxClass) {
  34454. d3.select(context.node().parentNode).select(mathjaxClass).style({opacity: 0});
  34455. }
  34456. var text = this.textContent;
  34457. d3.select(this).transition().duration(0).remove();
  34458. d3.select(document).on('mouseup', null);
  34459. dispatch.edit.call(context, text);
  34460. })
  34461. .on('focus', function() {
  34462. var editDiv = this;
  34463. gd._editing = true;
  34464. d3.select(document).on('mouseup', function() {
  34465. if(d3.event.target === editDiv) return false;
  34466. if(document.activeElement === div.node()) div.node().blur();
  34467. });
  34468. })
  34469. .on('keyup', function() {
  34470. if(d3.event.which === 27) {
  34471. gd._editing = false;
  34472. context.style({opacity: 1});
  34473. d3.select(this)
  34474. .style({opacity: 0})
  34475. .on('blur', function() { return false; })
  34476. .transition().remove();
  34477. dispatch.cancel.call(context, this.textContent);
  34478. }
  34479. else {
  34480. dispatch.input.call(context, this.textContent);
  34481. d3.select(this).call(alignHTMLWith(context, container, options));
  34482. }
  34483. })
  34484. .on('keydown', function() {
  34485. if(d3.event.which === 13) this.blur();
  34486. })
  34487. .call(selectElementContents);
  34488. }
  34489. if(options.immediate) handleClick();
  34490. else handlerElement.on('click', handleClick);
  34491. return d3.rebind(context, dispatch, 'on');
  34492. };
  34493. },{"../constants/alignment":148,"../constants/xmlns_namespaces":152,"../lib":169,"d3":16}],192:[function(_dereq_,module,exports){
  34494. /**
  34495. * Copyright 2012-2018, Plotly, Inc.
  34496. * All rights reserved.
  34497. *
  34498. * This source code is licensed under the MIT license found in the
  34499. * LICENSE file in the root directory of this source tree.
  34500. */
  34501. 'use strict';
  34502. var timerCache = {};
  34503. /**
  34504. * Throttle a callback. `callback` executes synchronously only if
  34505. * more than `minInterval` milliseconds have already elapsed since the latest
  34506. * call (if any). Otherwise we wait until `minInterval` is over and execute the
  34507. * last callback received while waiting.
  34508. * So the first and last events in a train are always executed (eventually)
  34509. * but some of the events in the middle can be dropped.
  34510. *
  34511. * @param {string} id: an identifier to mark events to throttle together
  34512. * @param {number} minInterval: minimum time, in milliseconds, between
  34513. * invocations of `callback`
  34514. * @param {function} callback: the function to throttle. `callback` itself
  34515. * should be a purely synchronous function.
  34516. */
  34517. exports.throttle = function throttle(id, minInterval, callback) {
  34518. var cache = timerCache[id];
  34519. var now = Date.now();
  34520. if(!cache) {
  34521. /*
  34522. * Throw out old items before making a new one, to prevent the cache
  34523. * getting overgrown, for example from old plots that have been replaced.
  34524. * 1 minute age is arbitrary.
  34525. */
  34526. for(var idi in timerCache) {
  34527. if(timerCache[idi].ts < now - 60000) {
  34528. delete timerCache[idi];
  34529. }
  34530. }
  34531. cache = timerCache[id] = {ts: 0, timer: null};
  34532. }
  34533. _clearTimeout(cache);
  34534. function exec() {
  34535. callback();
  34536. cache.ts = Date.now();
  34537. if(cache.onDone) {
  34538. cache.onDone();
  34539. cache.onDone = null;
  34540. }
  34541. }
  34542. if(now > cache.ts + minInterval) {
  34543. exec();
  34544. return;
  34545. }
  34546. cache.timer = setTimeout(function() {
  34547. exec();
  34548. cache.timer = null;
  34549. }, minInterval);
  34550. };
  34551. exports.done = function(id) {
  34552. var cache = timerCache[id];
  34553. if(!cache || !cache.timer) return Promise.resolve();
  34554. return new Promise(function(resolve) {
  34555. var previousOnDone = cache.onDone;
  34556. cache.onDone = function onDone() {
  34557. if(previousOnDone) previousOnDone();
  34558. resolve();
  34559. cache.onDone = null;
  34560. };
  34561. });
  34562. };
  34563. /**
  34564. * Clear the throttle cache for one or all timers
  34565. * @param {optional string} id:
  34566. * if provided, clear just this timer
  34567. * if omitted, clear all timers (mainly useful for testing)
  34568. */
  34569. exports.clear = function(id) {
  34570. if(id) {
  34571. _clearTimeout(timerCache[id]);
  34572. delete timerCache[id];
  34573. }
  34574. else {
  34575. for(var idi in timerCache) exports.clear(idi);
  34576. }
  34577. };
  34578. function _clearTimeout(cache) {
  34579. if(cache && cache.timer !== null) {
  34580. clearTimeout(cache.timer);
  34581. cache.timer = null;
  34582. }
  34583. }
  34584. },{}],193:[function(_dereq_,module,exports){
  34585. /**
  34586. * Copyright 2012-2018, Plotly, Inc.
  34587. * All rights reserved.
  34588. *
  34589. * This source code is licensed under the MIT license found in the
  34590. * LICENSE file in the root directory of this source tree.
  34591. */
  34592. 'use strict';
  34593. var isNumeric = _dereq_('fast-isnumeric');
  34594. /**
  34595. * convert a linear value into a logged value, folding negative numbers into
  34596. * the given range
  34597. */
  34598. module.exports = function toLogRange(val, range) {
  34599. if(val > 0) return Math.log(val) / Math.LN10;
  34600. // move a negative value reference to a log axis - just put the
  34601. // result at the lowest range value on the plot (or if the range also went negative,
  34602. // one millionth of the top of the range)
  34603. var newVal = Math.log(Math.min(range[0], range[1])) / Math.LN10;
  34604. if(!isNumeric(newVal)) newVal = Math.log(Math.max(range[0], range[1])) / Math.LN10 - 6;
  34605. return newVal;
  34606. };
  34607. },{"fast-isnumeric":18}],194:[function(_dereq_,module,exports){
  34608. /**
  34609. * Copyright 2012-2018, Plotly, Inc.
  34610. * All rights reserved.
  34611. *
  34612. * This source code is licensed under the MIT license found in the
  34613. * LICENSE file in the root directory of this source tree.
  34614. */
  34615. 'use strict';
  34616. module.exports = {
  34617. moduleType: 'locale',
  34618. name: 'en-US',
  34619. dictionary: {
  34620. 'Click to enter Colorscale title': 'Click to enter Colorscale title'
  34621. },
  34622. format: {
  34623. date: '%m/%d/%Y'
  34624. }
  34625. };
  34626. },{}],195:[function(_dereq_,module,exports){
  34627. /**
  34628. * Copyright 2012-2018, Plotly, Inc.
  34629. * All rights reserved.
  34630. *
  34631. * This source code is licensed under the MIT license found in the
  34632. * LICENSE file in the root directory of this source tree.
  34633. */
  34634. 'use strict';
  34635. module.exports = {
  34636. moduleType: 'locale',
  34637. name: 'en',
  34638. dictionary: {
  34639. 'Click to enter Colorscale title': 'Click to enter Colourscale title'
  34640. },
  34641. format: {
  34642. days: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
  34643. shortDays: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
  34644. months: [
  34645. 'January', 'February', 'March', 'April', 'May', 'June',
  34646. 'July', 'August', 'September', 'October', 'November', 'December'
  34647. ],
  34648. shortMonths: [
  34649. 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
  34650. 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'
  34651. ],
  34652. periods: ['AM', 'PM'],
  34653. dateTime: '%a %b %e %X %Y',
  34654. date: '%d/%m/%Y',
  34655. time: '%H:%M:%S',
  34656. decimal: '.',
  34657. thousands: ',',
  34658. grouping: [3],
  34659. currency: ['$', ''],
  34660. year: '%Y',
  34661. month: '%b %Y',
  34662. dayMonth: '%b %-d',
  34663. dayMonthYear: '%b %-d, %Y'
  34664. }
  34665. };
  34666. },{}],196:[function(_dereq_,module,exports){
  34667. /**
  34668. * Copyright 2012-2018, Plotly, Inc.
  34669. * All rights reserved.
  34670. *
  34671. * This source code is licensed under the MIT license found in the
  34672. * LICENSE file in the root directory of this source tree.
  34673. */
  34674. 'use strict';
  34675. var Registry = _dereq_('../registry');
  34676. /*
  34677. * containerArrayMatch: does this attribute string point into a
  34678. * layout container array?
  34679. *
  34680. * @param {String} astr: an attribute string, like *annotations[2].text*
  34681. *
  34682. * @returns {Object | false} Returns false if `astr` doesn't match a container
  34683. * array. If it does, returns:
  34684. * {array: {String}, index: {Number}, property: {String}}
  34685. * ie the attribute string for the array, the index within the array (or ''
  34686. * if the whole array) and the property within that (or '' if the whole array
  34687. * or the whole object)
  34688. */
  34689. module.exports = function containerArrayMatch(astr) {
  34690. var rootContainers = Registry.layoutArrayContainers,
  34691. regexpContainers = Registry.layoutArrayRegexes,
  34692. rootPart = astr.split('[')[0],
  34693. arrayStr,
  34694. match;
  34695. // look for regexp matches first, because they may be nested inside root matches
  34696. // eg updatemenus[i].buttons is nested inside updatemenus
  34697. for(var i = 0; i < regexpContainers.length; i++) {
  34698. match = astr.match(regexpContainers[i]);
  34699. if(match && match.index === 0) {
  34700. arrayStr = match[0];
  34701. break;
  34702. }
  34703. }
  34704. // now look for root matches
  34705. if(!arrayStr) arrayStr = rootContainers[rootContainers.indexOf(rootPart)];
  34706. if(!arrayStr) return false;
  34707. var tail = astr.substr(arrayStr.length);
  34708. if(!tail) return {array: arrayStr, index: '', property: ''};
  34709. match = tail.match(/^\[(0|[1-9][0-9]*)\](\.(.+))?$/);
  34710. if(!match) return false;
  34711. return {array: arrayStr, index: Number(match[1]), property: match[3] || ''};
  34712. };
  34713. },{"../registry":259}],197:[function(_dereq_,module,exports){
  34714. /**
  34715. * Copyright 2012-2018, Plotly, Inc.
  34716. * All rights reserved.
  34717. *
  34718. * This source code is licensed under the MIT license found in the
  34719. * LICENSE file in the root directory of this source tree.
  34720. */
  34721. 'use strict';
  34722. var Lib = _dereq_('../lib');
  34723. var extendFlat = Lib.extendFlat;
  34724. var isPlainObject = Lib.isPlainObject;
  34725. var traceOpts = {
  34726. valType: 'flaglist',
  34727. extras: ['none'],
  34728. flags: ['calc', 'clearAxisTypes', 'plot', 'style', 'colorbars'],
  34729. };
  34730. var layoutOpts = {
  34731. valType: 'flaglist',
  34732. extras: ['none'],
  34733. flags: [
  34734. 'calc', 'plot', 'legend', 'ticks', 'axrange',
  34735. 'layoutstyle', 'modebar', 'camera', 'arraydraw'
  34736. ],
  34737. };
  34738. // flags for inside restyle/relayout include a few extras
  34739. // that shouldn't be used in attributes, to deal with certain
  34740. // combinations and conditionals efficiently
  34741. var traceEditTypeFlags = traceOpts.flags.slice()
  34742. .concat(['fullReplot']);
  34743. var layoutEditTypeFlags = layoutOpts.flags.slice()
  34744. .concat('layoutReplot');
  34745. module.exports = {
  34746. traces: traceOpts,
  34747. layout: layoutOpts,
  34748. /*
  34749. * default (all false) edit flags for restyle (traces)
  34750. * creates a new object each call, so the caller can mutate freely
  34751. */
  34752. traceFlags: function() { return falseObj(traceEditTypeFlags); },
  34753. /*
  34754. * default (all false) edit flags for relayout
  34755. * creates a new object each call, so the caller can mutate freely
  34756. */
  34757. layoutFlags: function() { return falseObj(layoutEditTypeFlags); },
  34758. /*
  34759. * update `flags` with the `editType` values found in `attr`
  34760. */
  34761. update: function(flags, attr) {
  34762. var editType = attr.editType;
  34763. if(editType && editType !== 'none') {
  34764. var editTypeParts = editType.split('+');
  34765. for(var i = 0; i < editTypeParts.length; i++) {
  34766. flags[editTypeParts[i]] = true;
  34767. }
  34768. }
  34769. },
  34770. overrideAll: overrideAll
  34771. };
  34772. function falseObj(keys) {
  34773. var out = {};
  34774. for(var i = 0; i < keys.length; i++) out[keys[i]] = false;
  34775. return out;
  34776. }
  34777. /**
  34778. * For attributes that are largely copied from elsewhere into a plot type that doesn't
  34779. * support partial redraws - overrides the editType field of all attributes in the object
  34780. *
  34781. * @param {object} attrs: the attributes to override. Will not be mutated.
  34782. * @param {string} editTypeOverride: the new editType to use
  34783. * @param {'nested'|'from-root'} overrideContainers:
  34784. * - 'nested' will override editType for nested containers but not the root.
  34785. * - 'from-root' will also override editType of the root container.
  34786. * Containers below the absolute top level (trace or layout root) DO need an
  34787. * editType even if they are not `valObject`s themselves (eg `scatter.marker`)
  34788. * to handle the case where you edit the whole container.
  34789. *
  34790. * @return {object} a new attributes object with `editType` modified as directed
  34791. */
  34792. function overrideAll(attrs, editTypeOverride, overrideContainers) {
  34793. var out = extendFlat({}, attrs);
  34794. for(var key in out) {
  34795. var attr = out[key];
  34796. if(isPlainObject(attr)) {
  34797. out[key] = overrideOne(attr, editTypeOverride, overrideContainers, key);
  34798. }
  34799. }
  34800. if(overrideContainers === 'from-root') out.editType = editTypeOverride;
  34801. return out;
  34802. }
  34803. function overrideOne(attr, editTypeOverride, overrideContainers, key) {
  34804. if(attr.valType) {
  34805. var out = extendFlat({}, attr);
  34806. out.editType = editTypeOverride;
  34807. if(Array.isArray(attr.items)) {
  34808. out.items = new Array(attr.items.length);
  34809. for(var i = 0; i < attr.items.length; i++) {
  34810. out.items[i] = overrideOne(attr.items[i], editTypeOverride, 'from-root');
  34811. }
  34812. }
  34813. return out;
  34814. }
  34815. else {
  34816. // don't provide an editType for the _deprecated container
  34817. return overrideAll(attr, editTypeOverride,
  34818. (key.charAt(0) === '_') ? 'nested' : 'from-root');
  34819. }
  34820. }
  34821. },{"../lib":169}],198:[function(_dereq_,module,exports){
  34822. /**
  34823. * Copyright 2012-2018, Plotly, Inc.
  34824. * All rights reserved.
  34825. *
  34826. * This source code is licensed under the MIT license found in the
  34827. * LICENSE file in the root directory of this source tree.
  34828. */
  34829. 'use strict';
  34830. var isNumeric = _dereq_('fast-isnumeric');
  34831. var m4FromQuat = _dereq_('gl-mat4/fromQuat');
  34832. var Registry = _dereq_('../registry');
  34833. var Lib = _dereq_('../lib');
  34834. var Plots = _dereq_('../plots/plots');
  34835. var AxisIds = _dereq_('../plots/cartesian/axis_ids');
  34836. var cleanId = AxisIds.cleanId;
  34837. var getFromTrace = AxisIds.getFromTrace;
  34838. var Color = _dereq_('../components/color');
  34839. // clear the promise queue if one of them got rejected
  34840. exports.clearPromiseQueue = function(gd) {
  34841. if(Array.isArray(gd._promises) && gd._promises.length > 0) {
  34842. Lib.log('Clearing previous rejected promises from queue.');
  34843. }
  34844. gd._promises = [];
  34845. };
  34846. // make a few changes to the layout right away
  34847. // before it gets used for anything
  34848. // backward compatibility and cleanup of nonstandard options
  34849. exports.cleanLayout = function(layout) {
  34850. var i, j;
  34851. if(!layout) layout = {};
  34852. // cannot have (x|y)axis1, numbering goes axis, axis2, axis3...
  34853. if(layout.xaxis1) {
  34854. if(!layout.xaxis) layout.xaxis = layout.xaxis1;
  34855. delete layout.xaxis1;
  34856. }
  34857. if(layout.yaxis1) {
  34858. if(!layout.yaxis) layout.yaxis = layout.yaxis1;
  34859. delete layout.yaxis1;
  34860. }
  34861. if(layout.scene1) {
  34862. if(!layout.scene) layout.scene = layout.scene1;
  34863. delete layout.scene1;
  34864. }
  34865. var axisAttrRegex = (Plots.subplotsRegistry.cartesian || {}).attrRegex;
  34866. var sceneAttrRegex = (Plots.subplotsRegistry.gl3d || {}).attrRegex;
  34867. var keys = Object.keys(layout);
  34868. for(i = 0; i < keys.length; i++) {
  34869. var key = keys[i];
  34870. // modifications to cartesian axes
  34871. if(axisAttrRegex && axisAttrRegex.test(key)) {
  34872. var ax = layout[key];
  34873. if(ax.anchor && ax.anchor !== 'free') {
  34874. ax.anchor = cleanId(ax.anchor);
  34875. }
  34876. if(ax.overlaying) ax.overlaying = cleanId(ax.overlaying);
  34877. // old method of axis type - isdate and islog (before category existed)
  34878. if(!ax.type) {
  34879. if(ax.isdate) ax.type = 'date';
  34880. else if(ax.islog) ax.type = 'log';
  34881. else if(ax.isdate === false && ax.islog === false) ax.type = 'linear';
  34882. }
  34883. if(ax.autorange === 'withzero' || ax.autorange === 'tozero') {
  34884. ax.autorange = true;
  34885. ax.rangemode = 'tozero';
  34886. }
  34887. delete ax.islog;
  34888. delete ax.isdate;
  34889. delete ax.categories; // replaced by _categories
  34890. // prune empty domain arrays made before the new nestedProperty
  34891. if(emptyContainer(ax, 'domain')) delete ax.domain;
  34892. // autotick -> tickmode
  34893. if(ax.autotick !== undefined) {
  34894. if(ax.tickmode === undefined) {
  34895. ax.tickmode = ax.autotick ? 'auto' : 'linear';
  34896. }
  34897. delete ax.autotick;
  34898. }
  34899. }
  34900. // modifications for 3D scenes
  34901. else if(sceneAttrRegex && sceneAttrRegex.test(key)) {
  34902. var scene = layout[key];
  34903. // clean old Camera coords
  34904. var cameraposition = scene.cameraposition;
  34905. if(Array.isArray(cameraposition) && cameraposition[0].length === 4) {
  34906. var rotation = cameraposition[0],
  34907. center = cameraposition[1],
  34908. radius = cameraposition[2],
  34909. mat = m4FromQuat([], rotation),
  34910. eye = [];
  34911. for(j = 0; j < 3; ++j) {
  34912. eye[j] = center[j] + radius * mat[2 + 4 * j];
  34913. }
  34914. scene.camera = {
  34915. eye: {x: eye[0], y: eye[1], z: eye[2]},
  34916. center: {x: center[0], y: center[1], z: center[2]},
  34917. up: {x: mat[1], y: mat[5], z: mat[9]}
  34918. };
  34919. delete scene.cameraposition;
  34920. }
  34921. }
  34922. }
  34923. var annotationsLen = Array.isArray(layout.annotations) ? layout.annotations.length : 0;
  34924. for(i = 0; i < annotationsLen; i++) {
  34925. var ann = layout.annotations[i];
  34926. if(!Lib.isPlainObject(ann)) continue;
  34927. if(ann.ref) {
  34928. if(ann.ref === 'paper') {
  34929. ann.xref = 'paper';
  34930. ann.yref = 'paper';
  34931. }
  34932. else if(ann.ref === 'data') {
  34933. ann.xref = 'x';
  34934. ann.yref = 'y';
  34935. }
  34936. delete ann.ref;
  34937. }
  34938. cleanAxRef(ann, 'xref');
  34939. cleanAxRef(ann, 'yref');
  34940. }
  34941. var shapesLen = Array.isArray(layout.shapes) ? layout.shapes.length : 0;
  34942. for(i = 0; i < shapesLen; i++) {
  34943. var shape = layout.shapes[i];
  34944. if(!Lib.isPlainObject(shape)) continue;
  34945. cleanAxRef(shape, 'xref');
  34946. cleanAxRef(shape, 'yref');
  34947. }
  34948. var legend = layout.legend;
  34949. if(legend) {
  34950. // check for old-style legend positioning (x or y is +/- 100)
  34951. if(legend.x > 3) {
  34952. legend.x = 1.02;
  34953. legend.xanchor = 'left';
  34954. }
  34955. else if(legend.x < -2) {
  34956. legend.x = -0.02;
  34957. legend.xanchor = 'right';
  34958. }
  34959. if(legend.y > 3) {
  34960. legend.y = 1.02;
  34961. legend.yanchor = 'bottom';
  34962. }
  34963. else if(legend.y < -2) {
  34964. legend.y = -0.02;
  34965. legend.yanchor = 'top';
  34966. }
  34967. }
  34968. /*
  34969. * Moved from rotate -> orbit for dragmode
  34970. */
  34971. if(layout.dragmode === 'rotate') layout.dragmode = 'orbit';
  34972. // sanitize rgb(fractions) and rgba(fractions) that old tinycolor
  34973. // supported, but new tinycolor does not because they're not valid css
  34974. Color.clean(layout);
  34975. return layout;
  34976. };
  34977. function cleanAxRef(container, attr) {
  34978. var valIn = container[attr],
  34979. axLetter = attr.charAt(0);
  34980. if(valIn && valIn !== 'paper') {
  34981. container[attr] = cleanId(valIn, axLetter);
  34982. }
  34983. }
  34984. /*
  34985. * cleanData: Make a few changes to the data for backward compatibility
  34986. * before it gets used for anything. Modifies the data traces users provide.
  34987. *
  34988. * Important: if you're going to add something here that modifies a data array,
  34989. * update it in place so the new array === the old one.
  34990. */
  34991. exports.cleanData = function(data) {
  34992. for(var tracei = 0; tracei < data.length; tracei++) {
  34993. var trace = data[tracei];
  34994. var i;
  34995. // use xbins to bin data in x, and ybins to bin data in y
  34996. if(trace.type === 'histogramy' && 'xbins' in trace && !('ybins' in trace)) {
  34997. trace.ybins = trace.xbins;
  34998. delete trace.xbins;
  34999. }
  35000. // error_y.opacity is obsolete - merge into color
  35001. if(trace.error_y && 'opacity' in trace.error_y) {
  35002. var dc = Color.defaults,
  35003. yeColor = trace.error_y.color ||
  35004. (Registry.traceIs(trace, 'bar') ? Color.defaultLine : dc[tracei % dc.length]);
  35005. trace.error_y.color = Color.addOpacity(
  35006. Color.rgb(yeColor),
  35007. Color.opacity(yeColor) * trace.error_y.opacity);
  35008. delete trace.error_y.opacity;
  35009. }
  35010. // convert bardir to orientation, and put the data into
  35011. // the axes it's eventually going to be used with
  35012. if('bardir' in trace) {
  35013. if(trace.bardir === 'h' && (Registry.traceIs(trace, 'bar') ||
  35014. trace.type.substr(0, 9) === 'histogram')) {
  35015. trace.orientation = 'h';
  35016. exports.swapXYData(trace);
  35017. }
  35018. delete trace.bardir;
  35019. }
  35020. // now we have only one 1D histogram type, and whether
  35021. // it uses x or y data depends on trace.orientation
  35022. if(trace.type === 'histogramy') exports.swapXYData(trace);
  35023. if(trace.type === 'histogramx' || trace.type === 'histogramy') {
  35024. trace.type = 'histogram';
  35025. }
  35026. // scl->scale, reversescl->reversescale
  35027. if('scl' in trace) {
  35028. trace.colorscale = trace.scl;
  35029. delete trace.scl;
  35030. }
  35031. if('reversescl' in trace) {
  35032. trace.reversescale = trace.reversescl;
  35033. delete trace.reversescl;
  35034. }
  35035. // axis ids x1 -> x, y1-> y
  35036. if(trace.xaxis) trace.xaxis = cleanId(trace.xaxis, 'x');
  35037. if(trace.yaxis) trace.yaxis = cleanId(trace.yaxis, 'y');
  35038. // scene ids scene1 -> scene
  35039. if(Registry.traceIs(trace, 'gl3d') && trace.scene) {
  35040. trace.scene = Plots.subplotsRegistry.gl3d.cleanId(trace.scene);
  35041. }
  35042. if(!Registry.traceIs(trace, 'pie') && !Registry.traceIs(trace, 'bar')) {
  35043. if(Array.isArray(trace.textposition)) {
  35044. for(i = 0; i < trace.textposition.length; i++) {
  35045. trace.textposition[i] = cleanTextPosition(trace.textposition[i]);
  35046. }
  35047. }
  35048. else if(trace.textposition) {
  35049. trace.textposition = cleanTextPosition(trace.textposition);
  35050. }
  35051. }
  35052. // fix typo in colorscale definition
  35053. var _module = Registry.getModule(trace);
  35054. if(_module && _module.colorbar) {
  35055. var containerName = _module.colorbar.container;
  35056. var container = containerName ? trace[containerName] : trace;
  35057. if(container && container.colorscale) {
  35058. if(container.colorscale === 'YIGnBu') container.colorscale = 'YlGnBu';
  35059. if(container.colorscale === 'YIOrRd') container.colorscale = 'YlOrRd';
  35060. }
  35061. }
  35062. // fix typo in surface 'highlight*' definitions
  35063. if(trace.type === 'surface' && Lib.isPlainObject(trace.contours)) {
  35064. var dims = ['x', 'y', 'z'];
  35065. for(i = 0; i < dims.length; i++) {
  35066. var opts = trace.contours[dims[i]];
  35067. if(!Lib.isPlainObject(opts)) continue;
  35068. if(opts.highlightColor) {
  35069. opts.highlightcolor = opts.highlightColor;
  35070. delete opts.highlightColor;
  35071. }
  35072. if(opts.highlightWidth) {
  35073. opts.highlightwidth = opts.highlightWidth;
  35074. delete opts.highlightWidth;
  35075. }
  35076. }
  35077. }
  35078. // fixes from converting finance from transforms to real trace types
  35079. if(trace.type === 'candlestick' || trace.type === 'ohlc') {
  35080. var increasingShowlegend = (trace.increasing || {}).showlegend !== false;
  35081. var decreasingShowlegend = (trace.decreasing || {}).showlegend !== false;
  35082. var increasingName = cleanFinanceDir(trace.increasing);
  35083. var decreasingName = cleanFinanceDir(trace.decreasing);
  35084. // now figure out something smart to do with the separate direction
  35085. // names we removed
  35086. if((increasingName !== false) && (decreasingName !== false)) {
  35087. // both sub-names existed: base name previously had no effect
  35088. // so ignore it and try to find a shared part of the sub-names
  35089. var newName = commonPrefix(
  35090. increasingName, decreasingName,
  35091. increasingShowlegend, decreasingShowlegend
  35092. );
  35093. // if no common part, leave whatever name was (or wasn't) there
  35094. if(newName) trace.name = newName;
  35095. }
  35096. else if((increasingName || decreasingName) && !trace.name) {
  35097. // one sub-name existed but not the base name - just use the sub-name
  35098. trace.name = increasingName || decreasingName;
  35099. }
  35100. }
  35101. // transforms backward compatibility fixes
  35102. if(Array.isArray(trace.transforms)) {
  35103. var transforms = trace.transforms;
  35104. for(i = 0; i < transforms.length; i++) {
  35105. var transform = transforms[i];
  35106. if(!Lib.isPlainObject(transform)) continue;
  35107. switch(transform.type) {
  35108. case 'filter':
  35109. if(transform.filtersrc) {
  35110. transform.target = transform.filtersrc;
  35111. delete transform.filtersrc;
  35112. }
  35113. if(transform.calendar) {
  35114. if(!transform.valuecalendar) {
  35115. transform.valuecalendar = transform.calendar;
  35116. }
  35117. delete transform.calendar;
  35118. }
  35119. break;
  35120. case 'groupby':
  35121. // Name has changed from `style` to `styles`, so use `style` but prefer `styles`:
  35122. transform.styles = transform.styles || transform.style;
  35123. if(transform.styles && !Array.isArray(transform.styles)) {
  35124. var prevStyles = transform.styles;
  35125. var styleKeys = Object.keys(prevStyles);
  35126. transform.styles = [];
  35127. for(var j = 0; j < styleKeys.length; j++) {
  35128. transform.styles.push({
  35129. target: styleKeys[j],
  35130. value: prevStyles[styleKeys[j]]
  35131. });
  35132. }
  35133. }
  35134. break;
  35135. }
  35136. }
  35137. }
  35138. // prune empty containers made before the new nestedProperty
  35139. if(emptyContainer(trace, 'line')) delete trace.line;
  35140. if('marker' in trace) {
  35141. if(emptyContainer(trace.marker, 'line')) delete trace.marker.line;
  35142. if(emptyContainer(trace, 'marker')) delete trace.marker;
  35143. }
  35144. // sanitize rgb(fractions) and rgba(fractions) that old tinycolor
  35145. // supported, but new tinycolor does not because they're not valid css
  35146. Color.clean(trace);
  35147. }
  35148. };
  35149. function cleanFinanceDir(dirContainer) {
  35150. if(!Lib.isPlainObject(dirContainer)) return false;
  35151. var dirName = dirContainer.name;
  35152. delete dirContainer.name;
  35153. delete dirContainer.showlegend;
  35154. return (typeof dirName === 'string' || typeof dirName === 'number') && String(dirName);
  35155. }
  35156. function commonPrefix(name1, name2, show1, show2) {
  35157. // if only one is shown in the legend, use that
  35158. if(show1 && !show2) return name1;
  35159. if(show2 && !show1) return name2;
  35160. // if both or neither are in the legend, check if one is blank (or whitespace)
  35161. // and use the other one
  35162. // note that hover labels can still use the name even if the legend doesn't
  35163. if(!name1.trim()) return name2;
  35164. if(!name2.trim()) return name1;
  35165. var minLen = Math.min(name1.length, name2.length);
  35166. var i;
  35167. for(i = 0; i < minLen; i++) {
  35168. if(name1.charAt(i) !== name2.charAt(i)) break;
  35169. }
  35170. var out = name1.substr(0, i);
  35171. return out.trim();
  35172. }
  35173. // textposition - support partial attributes (ie just 'top')
  35174. // and incorrect use of middle / center etc.
  35175. function cleanTextPosition(textposition) {
  35176. var posY = 'middle',
  35177. posX = 'center';
  35178. if(textposition.indexOf('top') !== -1) posY = 'top';
  35179. else if(textposition.indexOf('bottom') !== -1) posY = 'bottom';
  35180. if(textposition.indexOf('left') !== -1) posX = 'left';
  35181. else if(textposition.indexOf('right') !== -1) posX = 'right';
  35182. return posY + ' ' + posX;
  35183. }
  35184. function emptyContainer(outer, innerStr) {
  35185. return (innerStr in outer) &&
  35186. (typeof outer[innerStr] === 'object') &&
  35187. (Object.keys(outer[innerStr]).length === 0);
  35188. }
  35189. // swap all the data and data attributes associated with x and y
  35190. exports.swapXYData = function(trace) {
  35191. var i;
  35192. Lib.swapAttrs(trace, ['?', '?0', 'd?', '?bins', 'nbins?', 'autobin?', '?src', 'error_?']);
  35193. if(Array.isArray(trace.z) && Array.isArray(trace.z[0])) {
  35194. if(trace.transpose) delete trace.transpose;
  35195. else trace.transpose = true;
  35196. }
  35197. if(trace.error_x && trace.error_y) {
  35198. var errorY = trace.error_y,
  35199. copyYstyle = ('copy_ystyle' in errorY) ? errorY.copy_ystyle :
  35200. !(errorY.color || errorY.thickness || errorY.width);
  35201. Lib.swapAttrs(trace, ['error_?.copy_ystyle']);
  35202. if(copyYstyle) {
  35203. Lib.swapAttrs(trace, ['error_?.color', 'error_?.thickness', 'error_?.width']);
  35204. }
  35205. }
  35206. if(typeof trace.hoverinfo === 'string') {
  35207. var hoverInfoParts = trace.hoverinfo.split('+');
  35208. for(i = 0; i < hoverInfoParts.length; i++) {
  35209. if(hoverInfoParts[i] === 'x') hoverInfoParts[i] = 'y';
  35210. else if(hoverInfoParts[i] === 'y') hoverInfoParts[i] = 'x';
  35211. }
  35212. trace.hoverinfo = hoverInfoParts.join('+');
  35213. }
  35214. };
  35215. // coerce traceIndices input to array of trace indices
  35216. exports.coerceTraceIndices = function(gd, traceIndices) {
  35217. if(isNumeric(traceIndices)) {
  35218. return [traceIndices];
  35219. }
  35220. else if(!Array.isArray(traceIndices) || !traceIndices.length) {
  35221. return gd.data.map(function(_, i) { return i; });
  35222. }
  35223. return traceIndices;
  35224. };
  35225. /**
  35226. * Manages logic around array container item creation / deletion / update
  35227. * that nested property alone can't handle.
  35228. *
  35229. * @param {Object} np
  35230. * nested property of update attribute string about trace or layout object
  35231. * @param {*} newVal
  35232. * update value passed to restyle / relayout / update
  35233. * @param {Object} undoit
  35234. * undo hash (N.B. undoit may be mutated here).
  35235. *
  35236. */
  35237. exports.manageArrayContainers = function(np, newVal, undoit) {
  35238. var obj = np.obj,
  35239. parts = np.parts,
  35240. pLength = parts.length,
  35241. pLast = parts[pLength - 1];
  35242. var pLastIsNumber = isNumeric(pLast);
  35243. // delete item
  35244. if(pLastIsNumber && newVal === null) {
  35245. // Clear item in array container when new value is null
  35246. var contPath = parts.slice(0, pLength - 1).join('.'),
  35247. cont = Lib.nestedProperty(obj, contPath).get();
  35248. cont.splice(pLast, 1);
  35249. // Note that nested property clears null / undefined at end of
  35250. // array container, but not within them.
  35251. }
  35252. // create item
  35253. else if(pLastIsNumber && np.get() === undefined) {
  35254. // When adding a new item, make sure undo command will remove it
  35255. if(np.get() === undefined) undoit[np.astr] = null;
  35256. np.set(newVal);
  35257. }
  35258. // update item
  35259. else {
  35260. // If the last part of attribute string isn't a number,
  35261. // np.set is all we need.
  35262. np.set(newVal);
  35263. }
  35264. };
  35265. /*
  35266. * Match the part to strip off to turn an attribute into its parent
  35267. * really it should be either '.some_characters' or '[number]'
  35268. * but we're a little more permissive here and match either
  35269. * '.not_brackets_or_dot' or '[not_brackets_or_dot]'
  35270. */
  35271. var ATTR_TAIL_RE = /(\.[^\[\]\.]+|\[[^\[\]\.]+\])$/;
  35272. function getParent(attr) {
  35273. var tail = attr.search(ATTR_TAIL_RE);
  35274. if(tail > 0) return attr.substr(0, tail);
  35275. }
  35276. /*
  35277. * hasParent: does an attribute object contain a parent of the given attribute?
  35278. * for example, given 'images[2].x' do we also have 'images' or 'images[2]'?
  35279. *
  35280. * @param {Object} aobj
  35281. * update object, whose keys are attribute strings and values are their new settings
  35282. * @param {string} attr
  35283. * the attribute string to test against
  35284. * @returns {Boolean}
  35285. * is a parent of attr present in aobj?
  35286. */
  35287. exports.hasParent = function(aobj, attr) {
  35288. var attrParent = getParent(attr);
  35289. while(attrParent) {
  35290. if(attrParent in aobj) return true;
  35291. attrParent = getParent(attrParent);
  35292. }
  35293. return false;
  35294. };
  35295. /**
  35296. * Empty out types for all axes containing these traces so we auto-set them again
  35297. *
  35298. * @param {object} gd
  35299. * @param {[integer]} traces: trace indices to search for axes to clear the types of
  35300. * @param {object} layoutUpdate: any update being done concurrently to the layout,
  35301. * which may supercede clearing the axis types
  35302. */
  35303. var axLetters = ['x', 'y', 'z'];
  35304. exports.clearAxisTypes = function(gd, traces, layoutUpdate) {
  35305. for(var i = 0; i < traces.length; i++) {
  35306. var trace = gd._fullData[i];
  35307. for(var j = 0; j < 3; j++) {
  35308. var ax = getFromTrace(gd, trace, axLetters[j]);
  35309. // do not clear log type - that's never an auto result so must have been intentional
  35310. if(ax && ax.type !== 'log') {
  35311. var axAttr = ax._name;
  35312. var sceneName = ax._id.substr(1);
  35313. if(sceneName.substr(0, 5) === 'scene') {
  35314. if(layoutUpdate[sceneName] !== undefined) continue;
  35315. axAttr = sceneName + '.' + axAttr;
  35316. }
  35317. var typeAttr = axAttr + '.type';
  35318. if(layoutUpdate[axAttr] === undefined && layoutUpdate[typeAttr] === undefined) {
  35319. Lib.nestedProperty(gd.layout, typeAttr).set(null);
  35320. }
  35321. }
  35322. }
  35323. }
  35324. };
  35325. },{"../components/color":50,"../lib":169,"../plots/cartesian/axis_ids":217,"../plots/plots":246,"../registry":259,"fast-isnumeric":18,"gl-mat4/fromQuat":19}],199:[function(_dereq_,module,exports){
  35326. /**
  35327. * Copyright 2012-2018, Plotly, Inc.
  35328. * All rights reserved.
  35329. *
  35330. * This source code is licensed under the MIT license found in the
  35331. * LICENSE file in the root directory of this source tree.
  35332. */
  35333. 'use strict';
  35334. var main = _dereq_('./plot_api');
  35335. exports.plot = main.plot;
  35336. exports.newPlot = main.newPlot;
  35337. exports.restyle = main.restyle;
  35338. exports.relayout = main.relayout;
  35339. exports.redraw = main.redraw;
  35340. exports.update = main.update;
  35341. exports.react = main.react;
  35342. exports.extendTraces = main.extendTraces;
  35343. exports.prependTraces = main.prependTraces;
  35344. exports.addTraces = main.addTraces;
  35345. exports.deleteTraces = main.deleteTraces;
  35346. exports.moveTraces = main.moveTraces;
  35347. exports.purge = main.purge;
  35348. exports.addFrames = main.addFrames;
  35349. exports.deleteFrames = main.deleteFrames;
  35350. exports.animate = main.animate;
  35351. exports.setPlotConfig = main.setPlotConfig;
  35352. exports.toImage = _dereq_('./to_image');
  35353. exports.validate = _dereq_('./validate');
  35354. exports.downloadImage = _dereq_('../snapshot/download');
  35355. var templateApi = _dereq_('./template_api');
  35356. exports.makeTemplate = templateApi.makeTemplate;
  35357. exports.validateTemplate = templateApi.validateTemplate;
  35358. },{"../snapshot/download":261,"./plot_api":201,"./template_api":206,"./to_image":207,"./validate":208}],200:[function(_dereq_,module,exports){
  35359. /**
  35360. * Copyright 2012-2018, Plotly, Inc.
  35361. * All rights reserved.
  35362. *
  35363. * This source code is licensed under the MIT license found in the
  35364. * LICENSE file in the root directory of this source tree.
  35365. */
  35366. 'use strict';
  35367. var nestedProperty = _dereq_('../lib/nested_property');
  35368. var isPlainObject = _dereq_('../lib/is_plain_object');
  35369. var noop = _dereq_('../lib/noop');
  35370. var Loggers = _dereq_('../lib/loggers');
  35371. var sorterAsc = _dereq_('../lib/search').sorterAsc;
  35372. var Registry = _dereq_('../registry');
  35373. exports.containerArrayMatch = _dereq_('./container_array_match');
  35374. var isAddVal = exports.isAddVal = function isAddVal(val) {
  35375. return val === 'add' || isPlainObject(val);
  35376. };
  35377. var isRemoveVal = exports.isRemoveVal = function isRemoveVal(val) {
  35378. return val === null || val === 'remove';
  35379. };
  35380. /*
  35381. * applyContainerArrayChanges: for managing arrays of layout components in relayout
  35382. * handles them all with a consistent interface.
  35383. *
  35384. * Here are the supported actions -> relayout calls -> edits we get here
  35385. * (as prepared in _relayout):
  35386. *
  35387. * add an empty obj -> {'annotations[2]': 'add'} -> {2: {'': 'add'}}
  35388. * add a specific obj -> {'annotations[2]': {attrs}} -> {2: {'': {attrs}}}
  35389. * delete an obj -> {'annotations[2]': 'remove'} -> {2: {'': 'remove'}}
  35390. * -> {'annotations[2]': null} -> {2: {'': null}}
  35391. * delete the whole array -> {'annotations': 'remove'} -> {'': {'': 'remove'}}
  35392. * -> {'annotations': null} -> {'': {'': null}}
  35393. * edit an object -> {'annotations[2].text': 'boo'} -> {2: {'text': 'boo'}}
  35394. *
  35395. * You can combine many edits to different objects. Objects are added and edited
  35396. * in ascending order, then removed in descending order.
  35397. * For example, starting with [a, b, c], if you want to:
  35398. * - replace b with d:
  35399. * {'annotations[1]': d, 'annotations[2]': null} (b is item 2 after adding d)
  35400. * - add a new item d between a and b, and edit b:
  35401. * {'annotations[1]': d, 'annotations[2].x': newX} (b is item 2 after adding d)
  35402. * - delete b and edit c:
  35403. * {'annotations[1]': null, 'annotations[2].x': newX} (c is edited before b is removed)
  35404. *
  35405. * You CANNOT combine adding/deleting an item at index `i` with edits to the same index `i`
  35406. * You CANNOT combine replacing/deleting the whole array with anything else (for the same array).
  35407. *
  35408. * @param {HTMLDivElement} gd
  35409. * the DOM element of the graph container div
  35410. * @param {Lib.nestedProperty} componentType: the array we are editing
  35411. * @param {Object} edits
  35412. * the changes to make; keys are indices to edit, values are themselves objects:
  35413. * {attr: newValue} of changes to make to that index (with add/remove behavior
  35414. * in special values of the empty attr)
  35415. * @param {Object} flags
  35416. * the flags for which actions we're going to perform to display these (and
  35417. * any other) changes. If we're already `recalc`ing, we don't need to redraw
  35418. * individual items
  35419. *
  35420. * @returns {bool} `true` if it managed to complete drawing of the changes
  35421. * `false` would mean the parent should replot.
  35422. */
  35423. exports.applyContainerArrayChanges = function applyContainerArrayChanges(gd, np, edits, flags) {
  35424. var componentType = np.astr,
  35425. supplyComponentDefaults = Registry.getComponentMethod(componentType, 'supplyLayoutDefaults'),
  35426. draw = Registry.getComponentMethod(componentType, 'draw'),
  35427. drawOne = Registry.getComponentMethod(componentType, 'drawOne'),
  35428. replotLater = flags.replot || flags.recalc || (supplyComponentDefaults === noop) ||
  35429. (draw === noop),
  35430. layout = gd.layout,
  35431. fullLayout = gd._fullLayout;
  35432. if(edits['']) {
  35433. if(Object.keys(edits).length > 1) {
  35434. Loggers.warn('Full array edits are incompatible with other edits',
  35435. componentType);
  35436. }
  35437. var fullVal = edits[''][''];
  35438. if(isRemoveVal(fullVal)) np.set(null);
  35439. else if(Array.isArray(fullVal)) np.set(fullVal);
  35440. else {
  35441. Loggers.warn('Unrecognized full array edit value', componentType, fullVal);
  35442. return true;
  35443. }
  35444. if(replotLater) return false;
  35445. supplyComponentDefaults(layout, fullLayout);
  35446. draw(gd);
  35447. return true;
  35448. }
  35449. var componentNums = Object.keys(edits).map(Number).sort(sorterAsc),
  35450. componentArrayIn = np.get(),
  35451. componentArray = componentArrayIn || [],
  35452. // componentArrayFull is used just to keep splices in line between
  35453. // full and input arrays, so private keys can be copied over after
  35454. // redoing supplyDefaults
  35455. // TODO: this assumes componentArray is in gd.layout - which will not be
  35456. // true after we extend this to restyle
  35457. componentArrayFull = nestedProperty(fullLayout, componentType).get();
  35458. var deletes = [],
  35459. firstIndexChange = -1,
  35460. maxIndex = componentArray.length,
  35461. i,
  35462. j,
  35463. componentNum,
  35464. objEdits,
  35465. objKeys,
  35466. objVal,
  35467. adding;
  35468. // first make the add and edit changes
  35469. for(i = 0; i < componentNums.length; i++) {
  35470. componentNum = componentNums[i];
  35471. objEdits = edits[componentNum];
  35472. objKeys = Object.keys(objEdits);
  35473. objVal = objEdits[''],
  35474. adding = isAddVal(objVal);
  35475. if(componentNum < 0 || componentNum > componentArray.length - (adding ? 0 : 1)) {
  35476. Loggers.warn('index out of range', componentType, componentNum);
  35477. continue;
  35478. }
  35479. if(objVal !== undefined) {
  35480. if(objKeys.length > 1) {
  35481. Loggers.warn(
  35482. 'Insertion & removal are incompatible with edits to the same index.',
  35483. componentType, componentNum);
  35484. }
  35485. if(isRemoveVal(objVal)) {
  35486. deletes.push(componentNum);
  35487. }
  35488. else if(adding) {
  35489. if(objVal === 'add') objVal = {};
  35490. componentArray.splice(componentNum, 0, objVal);
  35491. if(componentArrayFull) componentArrayFull.splice(componentNum, 0, {});
  35492. }
  35493. else {
  35494. Loggers.warn('Unrecognized full object edit value',
  35495. componentType, componentNum, objVal);
  35496. }
  35497. if(firstIndexChange === -1) firstIndexChange = componentNum;
  35498. }
  35499. else {
  35500. for(j = 0; j < objKeys.length; j++) {
  35501. nestedProperty(componentArray[componentNum], objKeys[j]).set(objEdits[objKeys[j]]);
  35502. }
  35503. }
  35504. }
  35505. // now do deletes
  35506. for(i = deletes.length - 1; i >= 0; i--) {
  35507. componentArray.splice(deletes[i], 1);
  35508. // TODO: this drops private keys that had been stored in componentArrayFull
  35509. // does this have any ill effects?
  35510. if(componentArrayFull) componentArrayFull.splice(deletes[i], 1);
  35511. }
  35512. if(!componentArray.length) np.set(null);
  35513. else if(!componentArrayIn) np.set(componentArray);
  35514. if(replotLater) return false;
  35515. supplyComponentDefaults(layout, fullLayout);
  35516. // finally draw all the components we need to
  35517. // if we added or removed any, redraw all after it
  35518. if(drawOne !== noop) {
  35519. var indicesToDraw;
  35520. if(firstIndexChange === -1) {
  35521. // there's no re-indexing to do, so only redraw components that changed
  35522. indicesToDraw = componentNums;
  35523. }
  35524. else {
  35525. // in case the component array was shortened, we still need do call
  35526. // drawOne on the latter items so they get properly removed
  35527. maxIndex = Math.max(componentArray.length, maxIndex);
  35528. indicesToDraw = [];
  35529. for(i = 0; i < componentNums.length; i++) {
  35530. componentNum = componentNums[i];
  35531. if(componentNum >= firstIndexChange) break;
  35532. indicesToDraw.push(componentNum);
  35533. }
  35534. for(i = firstIndexChange; i < maxIndex; i++) {
  35535. indicesToDraw.push(i);
  35536. }
  35537. }
  35538. for(i = 0; i < indicesToDraw.length; i++) {
  35539. drawOne(gd, indicesToDraw[i]);
  35540. }
  35541. }
  35542. else draw(gd);
  35543. return true;
  35544. };
  35545. },{"../lib/is_plain_object":171,"../lib/loggers":174,"../lib/nested_property":178,"../lib/noop":179,"../lib/search":188,"../registry":259,"./container_array_match":196}],201:[function(_dereq_,module,exports){
  35546. /**
  35547. * Copyright 2012-2018, Plotly, Inc.
  35548. * All rights reserved.
  35549. *
  35550. * This source code is licensed under the MIT license found in the
  35551. * LICENSE file in the root directory of this source tree.
  35552. */
  35553. 'use strict';
  35554. var d3 = _dereq_('d3');
  35555. var isNumeric = _dereq_('fast-isnumeric');
  35556. var hasHover = _dereq_('has-hover');
  35557. var Lib = _dereq_('../lib');
  35558. var Events = _dereq_('../lib/events');
  35559. var Queue = _dereq_('../lib/queue');
  35560. var Registry = _dereq_('../registry');
  35561. var PlotSchema = _dereq_('./plot_schema');
  35562. var Plots = _dereq_('../plots/plots');
  35563. var Polar = _dereq_('../plots/polar/legacy');
  35564. var Axes = _dereq_('../plots/cartesian/axes');
  35565. var Drawing = _dereq_('../components/drawing');
  35566. var Color = _dereq_('../components/color');
  35567. var connectColorbar = _dereq_('../components/colorbar/connect');
  35568. var initInteractions = _dereq_('../plots/cartesian/graph_interact').initInteractions;
  35569. var xmlnsNamespaces = _dereq_('../constants/xmlns_namespaces');
  35570. var svgTextUtils = _dereq_('../lib/svg_text_utils');
  35571. var defaultConfig = _dereq_('./plot_config');
  35572. var manageArrays = _dereq_('./manage_arrays');
  35573. var helpers = _dereq_('./helpers');
  35574. var subroutines = _dereq_('./subroutines');
  35575. var editTypes = _dereq_('./edit_types');
  35576. var AX_NAME_PATTERN = _dereq_('../plots/cartesian/constants').AX_NAME_PATTERN;
  35577. var numericNameWarningCount = 0;
  35578. var numericNameWarningCountLimit = 5;
  35579. /**
  35580. * Main plot-creation function
  35581. *
  35582. * @param {string id or DOM element} gd
  35583. * the id or DOM element of the graph container div
  35584. * @param {array of objects} data
  35585. * array of traces, containing the data and display information for each trace
  35586. * @param {object} layout
  35587. * object describing the overall display of the plot,
  35588. * all the stuff that doesn't pertain to any individual trace
  35589. * @param {object} config
  35590. * configuration options (see ./plot_config.js for more info)
  35591. *
  35592. * OR
  35593. *
  35594. * @param {string id or DOM element} gd
  35595. * the id or DOM element of the graph container div
  35596. * @param {object} figure
  35597. * object containing `data`, `layout`, `config`, and `frames` members
  35598. *
  35599. */
  35600. exports.plot = function(gd, data, layout, config) {
  35601. var frames;
  35602. gd = Lib.getGraphDiv(gd);
  35603. // Events.init is idempotent and bails early if gd has already been init'd
  35604. Events.init(gd);
  35605. if(Lib.isPlainObject(data)) {
  35606. var obj = data;
  35607. data = obj.data;
  35608. layout = obj.layout;
  35609. config = obj.config;
  35610. frames = obj.frames;
  35611. }
  35612. var okToPlot = Events.triggerHandler(gd, 'plotly_beforeplot', [data, layout, config]);
  35613. if(okToPlot === false) return Promise.reject();
  35614. // if there's no data or layout, and this isn't yet a plotly plot
  35615. // container, log a warning to help plotly.js users debug
  35616. if(!data && !layout && !Lib.isPlotDiv(gd)) {
  35617. Lib.warn('Calling Plotly.plot as if redrawing ' +
  35618. 'but this container doesn\'t yet have a plot.', gd);
  35619. }
  35620. function addFrames() {
  35621. if(frames) {
  35622. return exports.addFrames(gd, frames);
  35623. }
  35624. }
  35625. // transfer configuration options to gd until we move over to
  35626. // a more OO like model
  35627. setPlotContext(gd, config);
  35628. if(!layout) layout = {};
  35629. // hook class for plots main container (in case of plotly.js
  35630. // this won't be #embedded-graph or .js-tab-contents)
  35631. d3.select(gd).classed('js-plotly-plot', true);
  35632. // off-screen getBoundingClientRect testing space,
  35633. // in #js-plotly-tester (and stored as Drawing.tester)
  35634. // so we can share cached text across tabs
  35635. Drawing.makeTester();
  35636. // clear stashed base url
  35637. delete Drawing.baseUrl;
  35638. // collect promises for any async actions during plotting
  35639. // any part of the plotting code can push to gd._promises, then
  35640. // before we move to the next step, we check that they're all
  35641. // complete, and empty out the promise list again.
  35642. if(!Array.isArray(gd._promises)) gd._promises = [];
  35643. var graphWasEmpty = ((gd.data || []).length === 0 && Array.isArray(data));
  35644. // if there is already data on the graph, append the new data
  35645. // if you only want to redraw, pass a non-array for data
  35646. if(Array.isArray(data)) {
  35647. helpers.cleanData(data);
  35648. if(graphWasEmpty) gd.data = data;
  35649. else gd.data.push.apply(gd.data, data);
  35650. // for routines outside graph_obj that want a clean tab
  35651. // (rather than appending to an existing one) gd.empty
  35652. // is used to determine whether to make a new tab
  35653. gd.empty = false;
  35654. }
  35655. if(!gd.layout || graphWasEmpty) gd.layout = helpers.cleanLayout(layout);
  35656. // if the user is trying to drag the axes, allow new data and layout
  35657. // to come in but don't allow a replot.
  35658. if(gd._dragging && !gd._transitioning) {
  35659. // signal to drag handler that after everything else is done
  35660. // we need to replot, because something has changed
  35661. gd._replotPending = true;
  35662. return Promise.reject();
  35663. } else {
  35664. // we're going ahead with a replot now
  35665. gd._replotPending = false;
  35666. }
  35667. Plots.supplyDefaults(gd);
  35668. var fullLayout = gd._fullLayout;
  35669. var hasCartesian = fullLayout._has('cartesian');
  35670. // Legacy polar plots
  35671. if(!fullLayout._has('polar') && data && data[0] && data[0].r) {
  35672. Lib.log('Legacy polar charts are deprecated!');
  35673. return plotPolar(gd, data, layout);
  35674. }
  35675. // so we don't try to re-call Plotly.plot from inside
  35676. // legend and colorbar, if margins changed
  35677. fullLayout._replotting = true;
  35678. // make or remake the framework if we need to
  35679. if(graphWasEmpty) makePlotFramework(gd);
  35680. // polar need a different framework
  35681. if(gd.framework !== makePlotFramework) {
  35682. gd.framework = makePlotFramework;
  35683. makePlotFramework(gd);
  35684. }
  35685. // clear gradient defs on each .plot call, because we know we'll loop through all traces
  35686. Drawing.initGradients(gd);
  35687. // save initial show spikes once per graph
  35688. if(graphWasEmpty) Axes.saveShowSpikeInitial(gd);
  35689. // prepare the data and find the autorange
  35690. // generate calcdata, if we need to
  35691. // to force redoing calcdata, just delete it before calling Plotly.plot
  35692. var recalc = !gd.calcdata || gd.calcdata.length !== (gd._fullData || []).length;
  35693. if(recalc) Plots.doCalcdata(gd);
  35694. // in case it has changed, attach fullData traces to calcdata
  35695. for(var i = 0; i < gd.calcdata.length; i++) {
  35696. gd.calcdata[i][0].trace = gd._fullData[i];
  35697. }
  35698. // make the figure responsive
  35699. if(gd._context.responsive) {
  35700. if(!gd._responsiveChartHandler) {
  35701. // Keep a reference to the resize handler to purge it down the road
  35702. gd._responsiveChartHandler = function() {Plots.resize(gd);};
  35703. // Listen to window resize
  35704. window.addEventListener('resize', gd._responsiveChartHandler);
  35705. }
  35706. } else {
  35707. Lib.clearResponsive(gd);
  35708. }
  35709. /*
  35710. * start async-friendly code - now we're actually drawing things
  35711. */
  35712. var oldmargins = JSON.stringify(fullLayout._size);
  35713. // draw framework first so that margin-pushing
  35714. // components can position themselves correctly
  35715. var drawFrameworkCalls = 0;
  35716. function drawFramework() {
  35717. var basePlotModules = fullLayout._basePlotModules;
  35718. for(var i = 0; i < basePlotModules.length; i++) {
  35719. if(basePlotModules[i].drawFramework) {
  35720. basePlotModules[i].drawFramework(gd);
  35721. }
  35722. }
  35723. if(!fullLayout._glcanvas && fullLayout._has('gl')) {
  35724. fullLayout._glcanvas = fullLayout._glcontainer.selectAll('.gl-canvas').data([{
  35725. key: 'contextLayer',
  35726. context: true,
  35727. pick: false
  35728. }, {
  35729. key: 'focusLayer',
  35730. context: false,
  35731. pick: false
  35732. }, {
  35733. key: 'pickLayer',
  35734. context: false,
  35735. pick: true
  35736. }], function(d) { return d.key; });
  35737. fullLayout._glcanvas.enter().append('canvas')
  35738. .attr('class', function(d) {
  35739. return 'gl-canvas gl-canvas-' + d.key.replace('Layer', '');
  35740. })
  35741. .style({
  35742. 'position': 'absolute',
  35743. 'top': 0,
  35744. 'left': 0,
  35745. 'width': '100%',
  35746. 'height': '100%',
  35747. 'overflow': 'visible',
  35748. 'pointer-events': 'none'
  35749. });
  35750. }
  35751. if(fullLayout._glcanvas) {
  35752. fullLayout._glcanvas
  35753. .attr('width', fullLayout.width)
  35754. .attr('height', fullLayout.height);
  35755. var regl = fullLayout._glcanvas.data()[0].regl;
  35756. if(regl) {
  35757. // Unfortunately, this can happen when relayouting to large
  35758. // width/height on some browsers.
  35759. if(fullLayout.width !== regl._gl.drawingBufferWidth ||
  35760. fullLayout.height !== regl._gl.drawingBufferHeight
  35761. ) {
  35762. var msg = 'WebGL context buffer and canvas dimensions do not match due to browser/WebGL bug.';
  35763. if(drawFrameworkCalls) {
  35764. Lib.error(msg);
  35765. } else {
  35766. Lib.log(msg + ' Clearing graph and plotting again.');
  35767. Plots.cleanPlot([], {}, gd._fullData, fullLayout, gd.calcdata);
  35768. Plots.supplyDefaults(gd);
  35769. fullLayout = gd._fullLayout;
  35770. Plots.doCalcdata(gd);
  35771. drawFrameworkCalls++;
  35772. return drawFramework();
  35773. }
  35774. }
  35775. }
  35776. }
  35777. return Plots.previousPromises(gd);
  35778. }
  35779. // draw anything that can affect margins.
  35780. function marginPushers() {
  35781. var calcdata = gd.calcdata;
  35782. var i, cd, trace;
  35783. // First reset the list of things that are allowed to change the margins
  35784. // So any deleted traces or components will be wiped out of the
  35785. // automargin calculation.
  35786. // This means *every* margin pusher must be listed here, even if it
  35787. // doesn't actually try to push the margins until later.
  35788. Plots.clearAutoMarginIds(gd);
  35789. subroutines.drawMarginPushers(gd);
  35790. Axes.allowAutoMargin(gd);
  35791. for(i = 0; i < calcdata.length; i++) {
  35792. cd = calcdata[i];
  35793. trace = cd[0].trace;
  35794. var colorbarOpts = trace._module.colorbar;
  35795. if(trace.visible !== true || !colorbarOpts) {
  35796. Plots.autoMargin(gd, 'cb' + trace.uid);
  35797. }
  35798. else connectColorbar(gd, cd, colorbarOpts);
  35799. }
  35800. Plots.doAutoMargin(gd);
  35801. return Plots.previousPromises(gd);
  35802. }
  35803. // in case the margins changed, draw margin pushers again
  35804. function marginPushersAgain() {
  35805. if(JSON.stringify(fullLayout._size) === oldmargins) return;
  35806. return Lib.syncOrAsync([
  35807. marginPushers,
  35808. subroutines.layoutStyles
  35809. ], gd);
  35810. }
  35811. function positionAndAutorange() {
  35812. if(!recalc) {
  35813. doAutoRangeAndConstraints();
  35814. return;
  35815. }
  35816. // TODO: autosize extra for text markers and images
  35817. // see https://github.com/plotly/plotly.js/issues/1111
  35818. return Lib.syncOrAsync([
  35819. Registry.getComponentMethod('shapes', 'calcAutorange'),
  35820. Registry.getComponentMethod('annotations', 'calcAutorange'),
  35821. doAutoRangeAndConstraints,
  35822. Registry.getComponentMethod('rangeslider', 'calcAutorange')
  35823. ], gd);
  35824. }
  35825. function doAutoRangeAndConstraints() {
  35826. if(gd._transitioning) return;
  35827. subroutines.doAutoRangeAndConstraints(gd);
  35828. // store initial ranges *after* enforcing constraints, otherwise
  35829. // we will never look like we're at the initial ranges
  35830. if(graphWasEmpty) Axes.saveRangeInitial(gd);
  35831. }
  35832. // draw ticks, titles, and calculate axis scaling (._b, ._m)
  35833. function drawAxes() {
  35834. return Axes.doTicks(gd, graphWasEmpty ? '' : 'redraw');
  35835. }
  35836. var seq = [
  35837. Plots.previousPromises,
  35838. addFrames,
  35839. drawFramework,
  35840. marginPushers,
  35841. marginPushersAgain
  35842. ];
  35843. if(hasCartesian) seq.push(positionAndAutorange);
  35844. seq.push(subroutines.layoutStyles);
  35845. if(hasCartesian) seq.push(drawAxes);
  35846. seq.push(
  35847. subroutines.drawData,
  35848. subroutines.finalDraw,
  35849. initInteractions,
  35850. Plots.addLinks,
  35851. Plots.rehover,
  35852. // TODO: doAutoMargin is only needed here for axis automargin, which
  35853. // happens outside of marginPushers where all the other automargins are
  35854. // calculated. Would be much better to separate margin calculations from
  35855. // component drawing - see https://github.com/plotly/plotly.js/issues/2704
  35856. Plots.doAutoMargin,
  35857. Plots.previousPromises
  35858. );
  35859. // even if everything we did was synchronous, return a promise
  35860. // so that the caller doesn't care which route we took
  35861. var plotDone = Lib.syncOrAsync(seq, gd);
  35862. if(!plotDone || !plotDone.then) plotDone = Promise.resolve();
  35863. return plotDone.then(function() {
  35864. emitAfterPlot(gd);
  35865. return gd;
  35866. });
  35867. };
  35868. function emitAfterPlot(gd) {
  35869. var fullLayout = gd._fullLayout;
  35870. if(fullLayout._redrawFromAutoMarginCount) {
  35871. fullLayout._redrawFromAutoMarginCount--;
  35872. } else {
  35873. gd.emit('plotly_afterplot');
  35874. }
  35875. }
  35876. exports.setPlotConfig = function setPlotConfig(obj) {
  35877. return Lib.extendFlat(defaultConfig, obj);
  35878. };
  35879. function setBackground(gd, bgColor) {
  35880. try {
  35881. gd._fullLayout._paper.style('background', bgColor);
  35882. } catch(e) {
  35883. Lib.error(e);
  35884. }
  35885. }
  35886. function opaqueSetBackground(gd, bgColor) {
  35887. var blend = Color.combine(bgColor, 'white');
  35888. setBackground(gd, blend);
  35889. }
  35890. function setPlotContext(gd, config) {
  35891. if(!gd._context) gd._context = Lib.extendDeep({}, defaultConfig);
  35892. var context = gd._context;
  35893. var i, keys, key;
  35894. if(config) {
  35895. keys = Object.keys(config);
  35896. for(i = 0; i < keys.length; i++) {
  35897. key = keys[i];
  35898. if(key === 'editable' || key === 'edits') continue;
  35899. if(key in context) {
  35900. if(key === 'setBackground' && config[key] === 'opaque') {
  35901. context[key] = opaqueSetBackground;
  35902. } else {
  35903. context[key] = config[key];
  35904. }
  35905. }
  35906. }
  35907. // map plot3dPixelRatio to plotGlPixelRatio for backward compatibility
  35908. if(config.plot3dPixelRatio && !context.plotGlPixelRatio) {
  35909. context.plotGlPixelRatio = context.plot3dPixelRatio;
  35910. }
  35911. // now deal with editable and edits - first editable overrides
  35912. // everything, then edits refines
  35913. var editable = config.editable;
  35914. if(editable !== undefined) {
  35915. // we're not going to *use* context.editable, we're only going to
  35916. // use context.edits... but keep it for the record
  35917. context.editable = editable;
  35918. keys = Object.keys(context.edits);
  35919. for(i = 0; i < keys.length; i++) {
  35920. context.edits[keys[i]] = editable;
  35921. }
  35922. }
  35923. if(config.edits) {
  35924. keys = Object.keys(config.edits);
  35925. for(i = 0; i < keys.length; i++) {
  35926. key = keys[i];
  35927. if(key in context.edits) {
  35928. context.edits[key] = config.edits[key];
  35929. }
  35930. }
  35931. }
  35932. }
  35933. // staticPlot forces a bunch of others:
  35934. if(context.staticPlot) {
  35935. context.editable = false;
  35936. context.edits = {};
  35937. context.autosizable = false;
  35938. context.scrollZoom = false;
  35939. context.doubleClick = false;
  35940. context.showTips = false;
  35941. context.showLink = false;
  35942. context.displayModeBar = false;
  35943. }
  35944. // make sure hover-only devices have mode bar visible
  35945. if(context.displayModeBar === 'hover' && !hasHover) {
  35946. context.displayModeBar = true;
  35947. }
  35948. // default and fallback for setBackground
  35949. if(context.setBackground === 'transparent' || typeof context.setBackground !== 'function') {
  35950. context.setBackground = setBackground;
  35951. }
  35952. }
  35953. function plotPolar(gd, data, layout) {
  35954. // build or reuse the container skeleton
  35955. var plotContainer = d3.select(gd).selectAll('.plot-container')
  35956. .data([0]);
  35957. plotContainer.enter()
  35958. .insert('div', ':first-child')
  35959. .classed('plot-container plotly', true);
  35960. var paperDiv = plotContainer.selectAll('.svg-container')
  35961. .data([0]);
  35962. paperDiv.enter().append('div')
  35963. .classed('svg-container', true)
  35964. .style('position', 'relative');
  35965. // empty it everytime for now
  35966. paperDiv.html('');
  35967. // fulfill gd requirements
  35968. if(data) gd.data = data;
  35969. if(layout) gd.layout = layout;
  35970. Polar.manager.fillLayout(gd);
  35971. // resize canvas
  35972. paperDiv.style({
  35973. width: gd._fullLayout.width + 'px',
  35974. height: gd._fullLayout.height + 'px'
  35975. });
  35976. // instantiate framework
  35977. gd.framework = Polar.manager.framework(gd);
  35978. // plot
  35979. gd.framework({data: gd.data, layout: gd.layout}, paperDiv.node());
  35980. // set undo point
  35981. gd.framework.setUndoPoint();
  35982. // get the resulting svg for extending it
  35983. var polarPlotSVG = gd.framework.svg();
  35984. // editable title
  35985. var opacity = 1;
  35986. var txt = gd._fullLayout.title;
  35987. if(txt === '' || !txt) opacity = 0;
  35988. var titleLayout = function() {
  35989. this.call(svgTextUtils.convertToTspans, gd);
  35990. // TODO: html/mathjax
  35991. // TODO: center title
  35992. };
  35993. var title = polarPlotSVG.select('.title-group text')
  35994. .call(titleLayout);
  35995. if(gd._context.edits.titleText) {
  35996. var placeholderText = Lib._(gd, 'Click to enter Plot title');
  35997. if(!txt || txt === placeholderText) {
  35998. opacity = 0.2;
  35999. // placeholder is not going through convertToTspans
  36000. // so needs explicit data-unformatted
  36001. title.attr({'data-unformatted': placeholderText})
  36002. .text(placeholderText)
  36003. .style({opacity: opacity})
  36004. .on('mouseover.opacity', function() {
  36005. d3.select(this).transition().duration(100)
  36006. .style('opacity', 1);
  36007. })
  36008. .on('mouseout.opacity', function() {
  36009. d3.select(this).transition().duration(1000)
  36010. .style('opacity', 0);
  36011. });
  36012. }
  36013. var setContenteditable = function() {
  36014. this.call(svgTextUtils.makeEditable, {gd: gd})
  36015. .on('edit', function(text) {
  36016. gd.framework({layout: {title: text}});
  36017. this.text(text)
  36018. .call(titleLayout);
  36019. this.call(setContenteditable);
  36020. })
  36021. .on('cancel', function() {
  36022. var txt = this.attr('data-unformatted');
  36023. this.text(txt).call(titleLayout);
  36024. });
  36025. };
  36026. title.call(setContenteditable);
  36027. }
  36028. gd._context.setBackground(gd, gd._fullLayout.paper_bgcolor);
  36029. Plots.addLinks(gd);
  36030. return Promise.resolve();
  36031. }
  36032. // convenience function to force a full redraw, mostly for use by plotly.js
  36033. exports.redraw = function(gd) {
  36034. gd = Lib.getGraphDiv(gd);
  36035. if(!Lib.isPlotDiv(gd)) {
  36036. throw new Error('This element is not a Plotly plot: ' + gd);
  36037. }
  36038. helpers.cleanData(gd.data);
  36039. helpers.cleanLayout(gd.layout);
  36040. gd.calcdata = undefined;
  36041. return exports.plot(gd).then(function() {
  36042. gd.emit('plotly_redraw');
  36043. return gd;
  36044. });
  36045. };
  36046. /**
  36047. * Convenience function to make idempotent plot option obvious to users.
  36048. *
  36049. * @param gd
  36050. * @param {Object[]} data
  36051. * @param {Object} layout
  36052. * @param {Object} config
  36053. */
  36054. exports.newPlot = function(gd, data, layout, config) {
  36055. gd = Lib.getGraphDiv(gd);
  36056. // remove gl contexts
  36057. Plots.cleanPlot([], {}, gd._fullData || [], gd._fullLayout || {}, gd.calcdata || []);
  36058. Plots.purge(gd);
  36059. return exports.plot(gd, data, layout, config);
  36060. };
  36061. /**
  36062. * Wrap negative indicies to their positive counterparts.
  36063. *
  36064. * @param {Number[]} indices An array of indices
  36065. * @param {Number} maxIndex The maximum index allowable (arr.length - 1)
  36066. */
  36067. function positivifyIndices(indices, maxIndex) {
  36068. var parentLength = maxIndex + 1,
  36069. positiveIndices = [],
  36070. i,
  36071. index;
  36072. for(i = 0; i < indices.length; i++) {
  36073. index = indices[i];
  36074. if(index < 0) {
  36075. positiveIndices.push(parentLength + index);
  36076. } else {
  36077. positiveIndices.push(index);
  36078. }
  36079. }
  36080. return positiveIndices;
  36081. }
  36082. /**
  36083. * Ensures that an index array for manipulating gd.data is valid.
  36084. *
  36085. * Intended for use with addTraces, deleteTraces, and moveTraces.
  36086. *
  36087. * @param gd
  36088. * @param indices
  36089. * @param arrayName
  36090. */
  36091. function assertIndexArray(gd, indices, arrayName) {
  36092. var i,
  36093. index;
  36094. for(i = 0; i < indices.length; i++) {
  36095. index = indices[i];
  36096. // validate that indices are indeed integers
  36097. if(index !== parseInt(index, 10)) {
  36098. throw new Error('all values in ' + arrayName + ' must be integers');
  36099. }
  36100. // check that all indices are in bounds for given gd.data array length
  36101. if(index >= gd.data.length || index < -gd.data.length) {
  36102. throw new Error(arrayName + ' must be valid indices for gd.data.');
  36103. }
  36104. // check that indices aren't repeated
  36105. if(indices.indexOf(index, i + 1) > -1 ||
  36106. index >= 0 && indices.indexOf(-gd.data.length + index) > -1 ||
  36107. index < 0 && indices.indexOf(gd.data.length + index) > -1) {
  36108. throw new Error('each index in ' + arrayName + ' must be unique.');
  36109. }
  36110. }
  36111. }
  36112. /**
  36113. * Private function used by Plotly.moveTraces to check input args
  36114. *
  36115. * @param gd
  36116. * @param currentIndices
  36117. * @param newIndices
  36118. */
  36119. function checkMoveTracesArgs(gd, currentIndices, newIndices) {
  36120. // check that gd has attribute 'data' and 'data' is array
  36121. if(!Array.isArray(gd.data)) {
  36122. throw new Error('gd.data must be an array.');
  36123. }
  36124. // validate currentIndices array
  36125. if(typeof currentIndices === 'undefined') {
  36126. throw new Error('currentIndices is a required argument.');
  36127. } else if(!Array.isArray(currentIndices)) {
  36128. currentIndices = [currentIndices];
  36129. }
  36130. assertIndexArray(gd, currentIndices, 'currentIndices');
  36131. // validate newIndices array if it exists
  36132. if(typeof newIndices !== 'undefined' && !Array.isArray(newIndices)) {
  36133. newIndices = [newIndices];
  36134. }
  36135. if(typeof newIndices !== 'undefined') {
  36136. assertIndexArray(gd, newIndices, 'newIndices');
  36137. }
  36138. // check currentIndices and newIndices are the same length if newIdices exists
  36139. if(typeof newIndices !== 'undefined' && currentIndices.length !== newIndices.length) {
  36140. throw new Error('current and new indices must be of equal length.');
  36141. }
  36142. }
  36143. /**
  36144. * A private function to reduce the type checking clutter in addTraces.
  36145. *
  36146. * @param gd
  36147. * @param traces
  36148. * @param newIndices
  36149. */
  36150. function checkAddTracesArgs(gd, traces, newIndices) {
  36151. var i, value;
  36152. // check that gd has attribute 'data' and 'data' is array
  36153. if(!Array.isArray(gd.data)) {
  36154. throw new Error('gd.data must be an array.');
  36155. }
  36156. // make sure traces exists
  36157. if(typeof traces === 'undefined') {
  36158. throw new Error('traces must be defined.');
  36159. }
  36160. // make sure traces is an array
  36161. if(!Array.isArray(traces)) {
  36162. traces = [traces];
  36163. }
  36164. // make sure each value in traces is an object
  36165. for(i = 0; i < traces.length; i++) {
  36166. value = traces[i];
  36167. if(typeof value !== 'object' || (Array.isArray(value) || value === null)) {
  36168. throw new Error('all values in traces array must be non-array objects');
  36169. }
  36170. }
  36171. // make sure we have an index for each trace
  36172. if(typeof newIndices !== 'undefined' && !Array.isArray(newIndices)) {
  36173. newIndices = [newIndices];
  36174. }
  36175. if(typeof newIndices !== 'undefined' && newIndices.length !== traces.length) {
  36176. throw new Error(
  36177. 'if indices is specified, traces.length must equal indices.length'
  36178. );
  36179. }
  36180. }
  36181. /**
  36182. * A private function to reduce the type checking clutter in spliceTraces.
  36183. * Get all update Properties from gd.data. Validate inputs and outputs.
  36184. * Used by prependTrace and extendTraces
  36185. *
  36186. * @param gd
  36187. * @param update
  36188. * @param indices
  36189. * @param maxPoints
  36190. */
  36191. function assertExtendTracesArgs(gd, update, indices, maxPoints) {
  36192. var maxPointsIsObject = Lib.isPlainObject(maxPoints);
  36193. if(!Array.isArray(gd.data)) {
  36194. throw new Error('gd.data must be an array');
  36195. }
  36196. if(!Lib.isPlainObject(update)) {
  36197. throw new Error('update must be a key:value object');
  36198. }
  36199. if(typeof indices === 'undefined') {
  36200. throw new Error('indices must be an integer or array of integers');
  36201. }
  36202. assertIndexArray(gd, indices, 'indices');
  36203. for(var key in update) {
  36204. /*
  36205. * Verify that the attribute to be updated contains as many trace updates
  36206. * as indices. Failure must result in throw and no-op
  36207. */
  36208. if(!Array.isArray(update[key]) || update[key].length !== indices.length) {
  36209. throw new Error('attribute ' + key + ' must be an array of length equal to indices array length');
  36210. }
  36211. /*
  36212. * if maxPoints is an object it must match keys and array lengths of 'update' 1:1
  36213. */
  36214. if(maxPointsIsObject &&
  36215. (!(key in maxPoints) || !Array.isArray(maxPoints[key]) ||
  36216. maxPoints[key].length !== update[key].length)) {
  36217. throw new Error('when maxPoints is set as a key:value object it must contain a 1:1 ' +
  36218. 'corrispondence with the keys and number of traces in the update object');
  36219. }
  36220. }
  36221. }
  36222. /**
  36223. * A private function to reduce the type checking clutter in spliceTraces.
  36224. *
  36225. * @param {Object|HTMLDivElement} gd
  36226. * @param {Object} update
  36227. * @param {Number[]} indices
  36228. * @param {Number||Object} maxPoints
  36229. * @return {Object[]}
  36230. */
  36231. function getExtendProperties(gd, update, indices, maxPoints) {
  36232. var maxPointsIsObject = Lib.isPlainObject(maxPoints),
  36233. updateProps = [];
  36234. var trace, target, prop, insert, maxp;
  36235. // allow scalar index to represent a single trace position
  36236. if(!Array.isArray(indices)) indices = [indices];
  36237. // negative indices are wrapped around to their positive value. Equivalent to python indexing.
  36238. indices = positivifyIndices(indices, gd.data.length - 1);
  36239. // loop through all update keys and traces and harvest validated data.
  36240. for(var key in update) {
  36241. for(var j = 0; j < indices.length; j++) {
  36242. /*
  36243. * Choose the trace indexed by the indices map argument and get the prop setter-getter
  36244. * instance that references the key and value for this particular trace.
  36245. */
  36246. trace = gd.data[indices[j]];
  36247. prop = Lib.nestedProperty(trace, key);
  36248. /*
  36249. * Target is the existing gd.data.trace.dataArray value like "x" or "marker.size"
  36250. * Target must exist as an Array to allow the extend operation to be performed.
  36251. */
  36252. target = prop.get();
  36253. insert = update[key][j];
  36254. if(!Lib.isArrayOrTypedArray(insert)) {
  36255. throw new Error('attribute: ' + key + ' index: ' + j + ' must be an array');
  36256. }
  36257. if(!Lib.isArrayOrTypedArray(target)) {
  36258. throw new Error('cannot extend missing or non-array attribute: ' + key);
  36259. }
  36260. if(target.constructor !== insert.constructor) {
  36261. throw new Error('cannot extend array with an array of a different type: ' + key);
  36262. }
  36263. /*
  36264. * maxPoints may be an object map or a scalar. If object select the key:value, else
  36265. * Use the scalar maxPoints for all key and trace combinations.
  36266. */
  36267. maxp = maxPointsIsObject ? maxPoints[key][j] : maxPoints;
  36268. // could have chosen null here, -1 just tells us to not take a window
  36269. if(!isNumeric(maxp)) maxp = -1;
  36270. /*
  36271. * Wrap the nestedProperty in an object containing required data
  36272. * for lengthening and windowing this particular trace - key combination.
  36273. * Flooring maxp mirrors the behaviour of floats in the Array.slice JSnative function.
  36274. */
  36275. updateProps.push({
  36276. prop: prop,
  36277. target: target,
  36278. insert: insert,
  36279. maxp: Math.floor(maxp)
  36280. });
  36281. }
  36282. }
  36283. // all target and insertion data now validated
  36284. return updateProps;
  36285. }
  36286. /**
  36287. * A private function to key Extend and Prepend traces DRY
  36288. *
  36289. * @param {Object|HTMLDivElement} gd
  36290. * @param {Object} update
  36291. * @param {Number[]} indices
  36292. * @param {Number||Object} maxPoints
  36293. * @param {Function} updateArray
  36294. * @return {Object}
  36295. */
  36296. function spliceTraces(gd, update, indices, maxPoints, updateArray) {
  36297. assertExtendTracesArgs(gd, update, indices, maxPoints);
  36298. var updateProps = getExtendProperties(gd, update, indices, maxPoints);
  36299. var undoUpdate = {};
  36300. var undoPoints = {};
  36301. for(var i = 0; i < updateProps.length; i++) {
  36302. var prop = updateProps[i].prop;
  36303. var maxp = updateProps[i].maxp;
  36304. // return new array and remainder
  36305. var out = updateArray(updateProps[i].target, updateProps[i].insert, maxp);
  36306. prop.set(out[0]);
  36307. // build the inverse update object for the undo operation
  36308. if(!Array.isArray(undoUpdate[prop.astr])) undoUpdate[prop.astr] = [];
  36309. undoUpdate[prop.astr].push(out[1]);
  36310. // build the matching maxPoints undo object containing original trace lengths
  36311. if(!Array.isArray(undoPoints[prop.astr])) undoPoints[prop.astr] = [];
  36312. undoPoints[prop.astr].push(updateProps[i].target.length);
  36313. }
  36314. return {update: undoUpdate, maxPoints: undoPoints};
  36315. }
  36316. function concatTypedArray(arr0, arr1) {
  36317. var arr2 = new arr0.constructor(arr0.length + arr1.length);
  36318. arr2.set(arr0);
  36319. arr2.set(arr1, arr0.length);
  36320. return arr2;
  36321. }
  36322. /**
  36323. * extend && prepend traces at indices with update arrays, window trace lengths to maxPoints
  36324. *
  36325. * Extend and Prepend have identical APIs. Prepend inserts an array at the head while Extend
  36326. * inserts an array off the tail. Prepend truncates the tail of the array - counting maxPoints
  36327. * from the head, whereas Extend truncates the head of the array, counting backward maxPoints
  36328. * from the tail.
  36329. *
  36330. * If maxPoints is undefined, nonNumeric, negative or greater than extended trace length no
  36331. * truncation / windowing will be performed. If its zero, well the whole trace is truncated.
  36332. *
  36333. * @param {Object|HTMLDivElement} gd The graph div
  36334. * @param {Object} update The key:array map of target attributes to extend
  36335. * @param {Number|Number[]} indices The locations of traces to be extended
  36336. * @param {Number|Object} [maxPoints] Number of points for trace window after lengthening.
  36337. *
  36338. */
  36339. exports.extendTraces = function extendTraces(gd, update, indices, maxPoints) {
  36340. gd = Lib.getGraphDiv(gd);
  36341. function updateArray(target, insert, maxp) {
  36342. var newArray, remainder;
  36343. if(Lib.isTypedArray(target)) {
  36344. if(maxp < 0) {
  36345. var none = new target.constructor(0);
  36346. var both = concatTypedArray(target, insert);
  36347. if(maxp < 0) {
  36348. newArray = both;
  36349. remainder = none;
  36350. } else {
  36351. newArray = none;
  36352. remainder = both;
  36353. }
  36354. } else {
  36355. newArray = new target.constructor(maxp);
  36356. remainder = new target.constructor(target.length + insert.length - maxp);
  36357. if(maxp === insert.length) {
  36358. newArray.set(insert);
  36359. remainder.set(target);
  36360. } else if(maxp < insert.length) {
  36361. var numberOfItemsFromInsert = insert.length - maxp;
  36362. newArray.set(insert.subarray(numberOfItemsFromInsert));
  36363. remainder.set(target);
  36364. remainder.set(insert.subarray(0, numberOfItemsFromInsert), target.length);
  36365. } else {
  36366. var numberOfItemsFromTarget = maxp - insert.length;
  36367. var targetBegin = target.length - numberOfItemsFromTarget;
  36368. newArray.set(target.subarray(targetBegin));
  36369. newArray.set(insert, numberOfItemsFromTarget);
  36370. remainder.set(target.subarray(0, targetBegin));
  36371. }
  36372. }
  36373. } else {
  36374. newArray = target.concat(insert);
  36375. remainder = (maxp >= 0 && maxp < newArray.length) ?
  36376. newArray.splice(0, newArray.length - maxp) :
  36377. [];
  36378. }
  36379. return [newArray, remainder];
  36380. }
  36381. var undo = spliceTraces(gd, update, indices, maxPoints, updateArray);
  36382. var promise = exports.redraw(gd);
  36383. var undoArgs = [gd, undo.update, indices, undo.maxPoints];
  36384. Queue.add(gd, exports.prependTraces, undoArgs, extendTraces, arguments);
  36385. return promise;
  36386. };
  36387. exports.prependTraces = function prependTraces(gd, update, indices, maxPoints) {
  36388. gd = Lib.getGraphDiv(gd);
  36389. function updateArray(target, insert, maxp) {
  36390. var newArray, remainder;
  36391. if(Lib.isTypedArray(target)) {
  36392. if(maxp <= 0) {
  36393. var none = new target.constructor(0);
  36394. var both = concatTypedArray(insert, target);
  36395. if(maxp < 0) {
  36396. newArray = both;
  36397. remainder = none;
  36398. } else {
  36399. newArray = none;
  36400. remainder = both;
  36401. }
  36402. } else {
  36403. newArray = new target.constructor(maxp);
  36404. remainder = new target.constructor(target.length + insert.length - maxp);
  36405. if(maxp === insert.length) {
  36406. newArray.set(insert);
  36407. remainder.set(target);
  36408. } else if(maxp < insert.length) {
  36409. var numberOfItemsFromInsert = insert.length - maxp;
  36410. newArray.set(insert.subarray(0, numberOfItemsFromInsert));
  36411. remainder.set(insert.subarray(numberOfItemsFromInsert));
  36412. remainder.set(target, numberOfItemsFromInsert);
  36413. } else {
  36414. var numberOfItemsFromTarget = maxp - insert.length;
  36415. newArray.set(insert);
  36416. newArray.set(target.subarray(0, numberOfItemsFromTarget), insert.length);
  36417. remainder.set(target.subarray(numberOfItemsFromTarget));
  36418. }
  36419. }
  36420. } else {
  36421. newArray = insert.concat(target);
  36422. remainder = (maxp >= 0 && maxp < newArray.length) ?
  36423. newArray.splice(maxp, newArray.length) :
  36424. [];
  36425. }
  36426. return [newArray, remainder];
  36427. }
  36428. var undo = spliceTraces(gd, update, indices, maxPoints, updateArray);
  36429. var promise = exports.redraw(gd);
  36430. var undoArgs = [gd, undo.update, indices, undo.maxPoints];
  36431. Queue.add(gd, exports.extendTraces, undoArgs, prependTraces, arguments);
  36432. return promise;
  36433. };
  36434. /**
  36435. * Add data traces to an existing graph div.
  36436. *
  36437. * @param {Object|HTMLDivElement} gd The graph div
  36438. * @param {Object[]} gd.data The array of traces we're adding to
  36439. * @param {Object[]|Object} traces The object or array of objects to add
  36440. * @param {Number[]|Number} [newIndices=[gd.data.length]] Locations to add traces
  36441. *
  36442. */
  36443. exports.addTraces = function addTraces(gd, traces, newIndices) {
  36444. gd = Lib.getGraphDiv(gd);
  36445. var currentIndices = [],
  36446. undoFunc = exports.deleteTraces,
  36447. redoFunc = addTraces,
  36448. undoArgs = [gd, currentIndices],
  36449. redoArgs = [gd, traces], // no newIndices here
  36450. i,
  36451. promise;
  36452. // all validation is done elsewhere to remove clutter here
  36453. checkAddTracesArgs(gd, traces, newIndices);
  36454. // make sure traces is an array
  36455. if(!Array.isArray(traces)) {
  36456. traces = [traces];
  36457. }
  36458. // make sure traces do not repeat existing ones
  36459. traces = traces.map(function(trace) {
  36460. return Lib.extendFlat({}, trace);
  36461. });
  36462. helpers.cleanData(traces);
  36463. // add the traces to gd.data (no redrawing yet!)
  36464. for(i = 0; i < traces.length; i++) {
  36465. gd.data.push(traces[i]);
  36466. }
  36467. // to continue, we need to call moveTraces which requires currentIndices
  36468. for(i = 0; i < traces.length; i++) {
  36469. currentIndices.push(-traces.length + i);
  36470. }
  36471. // if the user didn't define newIndices, they just want the traces appended
  36472. // i.e., we can simply redraw and be done
  36473. if(typeof newIndices === 'undefined') {
  36474. promise = exports.redraw(gd);
  36475. Queue.add(gd, undoFunc, undoArgs, redoFunc, redoArgs);
  36476. return promise;
  36477. }
  36478. // make sure indices is property defined
  36479. if(!Array.isArray(newIndices)) {
  36480. newIndices = [newIndices];
  36481. }
  36482. try {
  36483. // this is redundant, but necessary to not catch later possible errors!
  36484. checkMoveTracesArgs(gd, currentIndices, newIndices);
  36485. }
  36486. catch(error) {
  36487. // something went wrong, reset gd to be safe and rethrow error
  36488. gd.data.splice(gd.data.length - traces.length, traces.length);
  36489. throw error;
  36490. }
  36491. // if we're here, the user has defined specific places to place the new traces
  36492. // this requires some extra work that moveTraces will do
  36493. Queue.startSequence(gd);
  36494. Queue.add(gd, undoFunc, undoArgs, redoFunc, redoArgs);
  36495. promise = exports.moveTraces(gd, currentIndices, newIndices);
  36496. Queue.stopSequence(gd);
  36497. return promise;
  36498. };
  36499. /**
  36500. * Delete traces at `indices` from gd.data array.
  36501. *
  36502. * @param {Object|HTMLDivElement} gd The graph div
  36503. * @param {Object[]} gd.data The array of traces we're removing from
  36504. * @param {Number|Number[]} indices The indices
  36505. */
  36506. exports.deleteTraces = function deleteTraces(gd, indices) {
  36507. gd = Lib.getGraphDiv(gd);
  36508. var traces = [],
  36509. undoFunc = exports.addTraces,
  36510. redoFunc = deleteTraces,
  36511. undoArgs = [gd, traces, indices],
  36512. redoArgs = [gd, indices],
  36513. i,
  36514. deletedTrace;
  36515. // make sure indices are defined
  36516. if(typeof indices === 'undefined') {
  36517. throw new Error('indices must be an integer or array of integers.');
  36518. } else if(!Array.isArray(indices)) {
  36519. indices = [indices];
  36520. }
  36521. assertIndexArray(gd, indices, 'indices');
  36522. // convert negative indices to positive indices
  36523. indices = positivifyIndices(indices, gd.data.length - 1);
  36524. // we want descending here so that splicing later doesn't affect indexing
  36525. indices.sort(Lib.sorterDes);
  36526. for(i = 0; i < indices.length; i += 1) {
  36527. deletedTrace = gd.data.splice(indices[i], 1)[0];
  36528. traces.push(deletedTrace);
  36529. }
  36530. var promise = exports.redraw(gd);
  36531. Queue.add(gd, undoFunc, undoArgs, redoFunc, redoArgs);
  36532. return promise;
  36533. };
  36534. /**
  36535. * Move traces at currentIndices array to locations in newIndices array.
  36536. *
  36537. * If newIndices is omitted, currentIndices will be moved to the end. E.g.,
  36538. * these are equivalent:
  36539. *
  36540. * Plotly.moveTraces(gd, [1, 2, 3], [-3, -2, -1])
  36541. * Plotly.moveTraces(gd, [1, 2, 3])
  36542. *
  36543. * @param {Object|HTMLDivElement} gd The graph div
  36544. * @param {Object[]} gd.data The array of traces we're removing from
  36545. * @param {Number|Number[]} currentIndices The locations of traces to be moved
  36546. * @param {Number|Number[]} [newIndices] The locations to move traces to
  36547. *
  36548. * Example calls:
  36549. *
  36550. * // move trace i to location x
  36551. * Plotly.moveTraces(gd, i, x)
  36552. *
  36553. * // move trace i to end of array
  36554. * Plotly.moveTraces(gd, i)
  36555. *
  36556. * // move traces i, j, k to end of array (i != j != k)
  36557. * Plotly.moveTraces(gd, [i, j, k])
  36558. *
  36559. * // move traces [i, j, k] to [x, y, z] (i != j != k) (x != y != z)
  36560. * Plotly.moveTraces(gd, [i, j, k], [x, y, z])
  36561. *
  36562. * // reorder all traces (assume there are 5--a, b, c, d, e)
  36563. * Plotly.moveTraces(gd, [b, d, e, a, c]) // same as 'move to end'
  36564. */
  36565. exports.moveTraces = function moveTraces(gd, currentIndices, newIndices) {
  36566. gd = Lib.getGraphDiv(gd);
  36567. var newData = [],
  36568. movingTraceMap = [],
  36569. undoFunc = moveTraces,
  36570. redoFunc = moveTraces,
  36571. undoArgs = [gd, newIndices, currentIndices],
  36572. redoArgs = [gd, currentIndices, newIndices],
  36573. i;
  36574. // to reduce complexity here, check args elsewhere
  36575. // this throws errors where appropriate
  36576. checkMoveTracesArgs(gd, currentIndices, newIndices);
  36577. // make sure currentIndices is an array
  36578. currentIndices = Array.isArray(currentIndices) ? currentIndices : [currentIndices];
  36579. // if undefined, define newIndices to point to the end of gd.data array
  36580. if(typeof newIndices === 'undefined') {
  36581. newIndices = [];
  36582. for(i = 0; i < currentIndices.length; i++) {
  36583. newIndices.push(-currentIndices.length + i);
  36584. }
  36585. }
  36586. // make sure newIndices is an array if it's user-defined
  36587. newIndices = Array.isArray(newIndices) ? newIndices : [newIndices];
  36588. // convert negative indices to positive indices (they're the same length)
  36589. currentIndices = positivifyIndices(currentIndices, gd.data.length - 1);
  36590. newIndices = positivifyIndices(newIndices, gd.data.length - 1);
  36591. // at this point, we've coerced the index arrays into predictable forms
  36592. // get the traces that aren't being moved around
  36593. for(i = 0; i < gd.data.length; i++) {
  36594. // if index isn't in currentIndices, include it in ignored!
  36595. if(currentIndices.indexOf(i) === -1) {
  36596. newData.push(gd.data[i]);
  36597. }
  36598. }
  36599. // get a mapping of indices to moving traces
  36600. for(i = 0; i < currentIndices.length; i++) {
  36601. movingTraceMap.push({newIndex: newIndices[i], trace: gd.data[currentIndices[i]]});
  36602. }
  36603. // reorder this mapping by newIndex, ascending
  36604. movingTraceMap.sort(function(a, b) {
  36605. return a.newIndex - b.newIndex;
  36606. });
  36607. // now, add the moving traces back in, in order!
  36608. for(i = 0; i < movingTraceMap.length; i += 1) {
  36609. newData.splice(movingTraceMap[i].newIndex, 0, movingTraceMap[i].trace);
  36610. }
  36611. gd.data = newData;
  36612. var promise = exports.redraw(gd);
  36613. Queue.add(gd, undoFunc, undoArgs, redoFunc, redoArgs);
  36614. return promise;
  36615. };
  36616. /**
  36617. * restyle: update trace attributes of an existing plot
  36618. *
  36619. * Can be called two ways.
  36620. *
  36621. * Signature 1:
  36622. * @param {String | HTMLDivElement} gd
  36623. * the id or DOM element of the graph container div
  36624. * @param {String} astr
  36625. * attribute string (like `'marker.symbol'`) to update
  36626. * @param {*} val
  36627. * value to give this attribute
  36628. * @param {Number[] | Number} [traces]
  36629. * integer or array of integers for the traces to alter (all if omitted)
  36630. *
  36631. * Signature 2:
  36632. * @param {String | HTMLDivElement} gd
  36633. * (as in signature 1)
  36634. * @param {Object} aobj
  36635. * attribute object `{astr1: val1, astr2: val2 ...}`
  36636. * allows setting multiple attributes simultaneously
  36637. * @param {Number[] | Number} [traces]
  36638. * (as in signature 1)
  36639. *
  36640. * `val` (or `val1`, `val2` ... in the object form) can be an array,
  36641. * to apply different values to each trace.
  36642. *
  36643. * If the array is too short, it will wrap around (useful for
  36644. * style files that want to specify cyclical default values).
  36645. */
  36646. exports.restyle = function restyle(gd, astr, val, _traces) {
  36647. gd = Lib.getGraphDiv(gd);
  36648. helpers.clearPromiseQueue(gd);
  36649. var aobj = {};
  36650. if(typeof astr === 'string') aobj[astr] = val;
  36651. else if(Lib.isPlainObject(astr)) {
  36652. // the 3-arg form
  36653. aobj = Lib.extendFlat({}, astr);
  36654. if(_traces === undefined) _traces = val;
  36655. }
  36656. else {
  36657. Lib.warn('Restyle fail.', astr, val, _traces);
  36658. return Promise.reject();
  36659. }
  36660. if(Object.keys(aobj).length) gd.changed = true;
  36661. var traces = helpers.coerceTraceIndices(gd, _traces);
  36662. var specs = _restyle(gd, aobj, traces);
  36663. var flags = specs.flags;
  36664. // clear calcdata and/or axis types if required so they get regenerated
  36665. if(flags.calc) gd.calcdata = undefined;
  36666. if(flags.clearAxisTypes) helpers.clearAxisTypes(gd, traces, {});
  36667. // fill in redraw sequence
  36668. var seq = [];
  36669. if(flags.fullReplot) {
  36670. seq.push(exports.plot);
  36671. } else {
  36672. seq.push(Plots.previousPromises);
  36673. Plots.supplyDefaults(gd);
  36674. if(flags.style) seq.push(subroutines.doTraceStyle);
  36675. if(flags.colorbars) seq.push(subroutines.doColorBars);
  36676. seq.push(emitAfterPlot);
  36677. }
  36678. seq.push(Plots.rehover);
  36679. Queue.add(gd,
  36680. restyle, [gd, specs.undoit, specs.traces],
  36681. restyle, [gd, specs.redoit, specs.traces]
  36682. );
  36683. var plotDone = Lib.syncOrAsync(seq, gd);
  36684. if(!plotDone || !plotDone.then) plotDone = Promise.resolve();
  36685. return plotDone.then(function() {
  36686. gd.emit('plotly_restyle', specs.eventData);
  36687. return gd;
  36688. });
  36689. };
  36690. // for undo: undefined initial vals must be turned into nulls
  36691. // so that we unset rather than ignore them
  36692. function undefinedToNull(val) {
  36693. if(val === undefined) return null;
  36694. return val;
  36695. }
  36696. function _restyle(gd, aobj, traces) {
  36697. var fullLayout = gd._fullLayout,
  36698. fullData = gd._fullData,
  36699. data = gd.data,
  36700. i;
  36701. // initialize flags
  36702. var flags = editTypes.traceFlags();
  36703. // copies of the change (and previous values of anything affected)
  36704. // for the undo / redo queue
  36705. var redoit = {},
  36706. undoit = {},
  36707. axlist;
  36708. // make a new empty vals array for undoit
  36709. function a0() { return traces.map(function() { return undefined; }); }
  36710. // for autoranging multiple axes
  36711. function addToAxlist(axid) {
  36712. var axName = Axes.id2name(axid);
  36713. if(axlist.indexOf(axName) === -1) axlist.push(axName);
  36714. }
  36715. function autorangeAttr(axName) { return 'LAYOUT' + axName + '.autorange'; }
  36716. function rangeAttr(axName) { return 'LAYOUT' + axName + '.range'; }
  36717. // for attrs that interact (like scales & autoscales), save the
  36718. // old vals before making the change
  36719. // val=undefined will not set a value, just record what the value was.
  36720. // val=null will delete the attribute
  36721. // attr can be an array to set several at once (all to the same val)
  36722. function doextra(attr, val, i) {
  36723. if(Array.isArray(attr)) {
  36724. attr.forEach(function(a) { doextra(a, val, i); });
  36725. return;
  36726. }
  36727. // quit if explicitly setting this elsewhere
  36728. if(attr in aobj || helpers.hasParent(aobj, attr)) return;
  36729. var extraparam;
  36730. if(attr.substr(0, 6) === 'LAYOUT') {
  36731. extraparam = Lib.nestedProperty(gd.layout, attr.replace('LAYOUT', ''));
  36732. } else {
  36733. extraparam = Lib.nestedProperty(data[traces[i]], attr);
  36734. }
  36735. if(!(attr in undoit)) {
  36736. undoit[attr] = a0();
  36737. }
  36738. if(undoit[attr][i] === undefined) {
  36739. undoit[attr][i] = undefinedToNull(extraparam.get());
  36740. }
  36741. if(val !== undefined) {
  36742. extraparam.set(val);
  36743. }
  36744. }
  36745. // now make the changes to gd.data (and occasionally gd.layout)
  36746. // and figure out what kind of graphics update we need to do
  36747. for(var ai in aobj) {
  36748. if(helpers.hasParent(aobj, ai)) {
  36749. throw new Error('cannot set ' + ai + 'and a parent attribute simultaneously');
  36750. }
  36751. var vi = aobj[ai],
  36752. cont,
  36753. contFull,
  36754. param,
  36755. oldVal,
  36756. newVal,
  36757. valObject;
  36758. redoit[ai] = vi;
  36759. if(ai.substr(0, 6) === 'LAYOUT') {
  36760. param = Lib.nestedProperty(gd.layout, ai.replace('LAYOUT', ''));
  36761. undoit[ai] = [undefinedToNull(param.get())];
  36762. // since we're allowing val to be an array, allow it here too,
  36763. // even though that's meaningless
  36764. param.set(Array.isArray(vi) ? vi[0] : vi);
  36765. // ironically, the layout attrs in restyle only require replot,
  36766. // not relayout
  36767. flags.calc = true;
  36768. continue;
  36769. }
  36770. // set attribute in gd.data
  36771. undoit[ai] = a0();
  36772. for(i = 0; i < traces.length; i++) {
  36773. cont = data[traces[i]];
  36774. contFull = fullData[traces[i]];
  36775. param = Lib.nestedProperty(cont, ai);
  36776. oldVal = param.get();
  36777. newVal = Array.isArray(vi) ? vi[i % vi.length] : vi;
  36778. if(newVal === undefined) continue;
  36779. var finalPart = param.parts[param.parts.length - 1];
  36780. var prefix = ai.substr(0, ai.length - finalPart.length - 1);
  36781. var prefixDot = prefix ? prefix + '.' : '';
  36782. var innerContFull = prefix ?
  36783. Lib.nestedProperty(contFull, prefix).get() : contFull;
  36784. valObject = PlotSchema.getTraceValObject(contFull, param.parts);
  36785. if(valObject && valObject.impliedEdits && newVal !== null) {
  36786. for(var impliedKey in valObject.impliedEdits) {
  36787. doextra(Lib.relativeAttr(ai, impliedKey), valObject.impliedEdits[impliedKey], i);
  36788. }
  36789. }
  36790. // changing colorbar size modes,
  36791. // make the resulting size not change
  36792. // note that colorbar fractional sizing is based on the
  36793. // original plot size, before anything (like a colorbar)
  36794. // increases the margins
  36795. else if((finalPart === 'thicknessmode' || finalPart === 'lenmode') &&
  36796. oldVal !== newVal &&
  36797. (newVal === 'fraction' || newVal === 'pixels') &&
  36798. innerContFull
  36799. ) {
  36800. var gs = fullLayout._size;
  36801. var orient = innerContFull.orient;
  36802. var topOrBottom = (orient === 'top') || (orient === 'bottom');
  36803. if(finalPart === 'thicknessmode') {
  36804. var thicknorm = topOrBottom ? gs.h : gs.w;
  36805. doextra(prefixDot + 'thickness', innerContFull.thickness *
  36806. (newVal === 'fraction' ? 1 / thicknorm : thicknorm), i);
  36807. }
  36808. else {
  36809. var lennorm = topOrBottom ? gs.w : gs.h;
  36810. doextra(prefixDot + 'len', innerContFull.len *
  36811. (newVal === 'fraction' ? 1 / lennorm : lennorm), i);
  36812. }
  36813. }
  36814. else if(ai === 'type' && (newVal === 'pie') !== (oldVal === 'pie')) {
  36815. var labelsTo = 'x',
  36816. valuesTo = 'y';
  36817. if((newVal === 'bar' || oldVal === 'bar') && cont.orientation === 'h') {
  36818. labelsTo = 'y';
  36819. valuesTo = 'x';
  36820. }
  36821. Lib.swapAttrs(cont, ['?', '?src'], 'labels', labelsTo);
  36822. Lib.swapAttrs(cont, ['d?', '?0'], 'label', labelsTo);
  36823. Lib.swapAttrs(cont, ['?', '?src'], 'values', valuesTo);
  36824. if(oldVal === 'pie') {
  36825. Lib.nestedProperty(cont, 'marker.color')
  36826. .set(Lib.nestedProperty(cont, 'marker.colors').get());
  36827. // super kludgy - but if all pies are gone we won't remove them otherwise
  36828. fullLayout._pielayer.selectAll('g.trace').remove();
  36829. } else if(Registry.traceIs(cont, 'cartesian')) {
  36830. Lib.nestedProperty(cont, 'marker.colors')
  36831. .set(Lib.nestedProperty(cont, 'marker.color').get());
  36832. }
  36833. }
  36834. undoit[ai][i] = undefinedToNull(oldVal);
  36835. // set the new value - if val is an array, it's one el per trace
  36836. // first check for attributes that get more complex alterations
  36837. var swapAttrs = [
  36838. 'swapxy', 'swapxyaxes', 'orientation', 'orientationaxes'
  36839. ];
  36840. if(swapAttrs.indexOf(ai) !== -1) {
  36841. // setting an orientation: make sure it's changing
  36842. // before we swap everything else
  36843. if(ai === 'orientation') {
  36844. param.set(newVal);
  36845. // obnoxious that we need this level of coupling... but in order to
  36846. // properly handle setting orientation to `null` we need to mimic
  36847. // the logic inside Bars.supplyDefaults for default orientation
  36848. var defaultOrientation = (cont.x && !cont.y) ? 'h' : 'v';
  36849. if((param.get() || defaultOrientation) === contFull.orientation) {
  36850. continue;
  36851. }
  36852. }
  36853. // orientationaxes has no value,
  36854. // it flips everything and the axes
  36855. else if(ai === 'orientationaxes') {
  36856. cont.orientation =
  36857. {v: 'h', h: 'v'}[contFull.orientation];
  36858. }
  36859. helpers.swapXYData(cont);
  36860. flags.calc = flags.clearAxisTypes = true;
  36861. }
  36862. else if(Plots.dataArrayContainers.indexOf(param.parts[0]) !== -1) {
  36863. // TODO: use manageArrays.applyContainerArrayChanges here too
  36864. helpers.manageArrayContainers(param, newVal, undoit);
  36865. flags.calc = true;
  36866. }
  36867. else {
  36868. if(valObject) {
  36869. // must redo calcdata when restyling array values of arrayOk attributes
  36870. if(valObject.arrayOk && (
  36871. Lib.isArrayOrTypedArray(newVal) || Lib.isArrayOrTypedArray(oldVal))
  36872. ) {
  36873. flags.calc = true;
  36874. }
  36875. else editTypes.update(flags, valObject);
  36876. }
  36877. else {
  36878. /*
  36879. * if we couldn't find valObject, assume a full recalc.
  36880. * This can happen if you're changing type and making
  36881. * some other edits too, so the modules we're
  36882. * looking at don't have these attributes in them.
  36883. */
  36884. flags.calc = true;
  36885. }
  36886. // all the other ones, just modify that one attribute
  36887. param.set(newVal);
  36888. }
  36889. }
  36890. // swap the data attributes of the relevant x and y axes?
  36891. if(['swapxyaxes', 'orientationaxes'].indexOf(ai) !== -1) {
  36892. Axes.swap(gd, traces);
  36893. }
  36894. // swap hovermode if set to "compare x/y data"
  36895. if(ai === 'orientationaxes') {
  36896. var hovermode = Lib.nestedProperty(gd.layout, 'hovermode');
  36897. if(hovermode.get() === 'x') {
  36898. hovermode.set('y');
  36899. } else if(hovermode.get() === 'y') {
  36900. hovermode.set('x');
  36901. }
  36902. }
  36903. // major enough changes deserve autoscale, autobin, and
  36904. // non-reversed axes so people don't get confused
  36905. if(['orientation', 'type'].indexOf(ai) !== -1) {
  36906. axlist = [];
  36907. for(i = 0; i < traces.length; i++) {
  36908. var trace = data[traces[i]];
  36909. if(Registry.traceIs(trace, 'cartesian')) {
  36910. addToAxlist(trace.xaxis || 'x');
  36911. addToAxlist(trace.yaxis || 'y');
  36912. if(ai === 'type') {
  36913. doextra(['autobinx', 'autobiny'], true, i);
  36914. }
  36915. }
  36916. }
  36917. doextra(axlist.map(autorangeAttr), true, 0);
  36918. doextra(axlist.map(rangeAttr), [0, 1], 0);
  36919. }
  36920. }
  36921. if(flags.calc || flags.plot) {
  36922. flags.fullReplot = true;
  36923. }
  36924. return {
  36925. flags: flags,
  36926. undoit: undoit,
  36927. redoit: redoit,
  36928. traces: traces,
  36929. eventData: Lib.extendDeepNoArrays([], [redoit, traces])
  36930. };
  36931. }
  36932. /**
  36933. * relayout: update layout attributes of an existing plot
  36934. *
  36935. * Can be called two ways:
  36936. *
  36937. * Signature 1:
  36938. * @param {String | HTMLDivElement} gd
  36939. * the id or dom element of the graph container div
  36940. * @param {String} astr
  36941. * attribute string (like `'xaxis.range[0]'`) to update
  36942. * @param {*} val
  36943. * value to give this attribute
  36944. *
  36945. * Signature 2:
  36946. * @param {String | HTMLDivElement} gd
  36947. * (as in signature 1)
  36948. * @param {Object} aobj
  36949. * attribute object `{astr1: val1, astr2: val2 ...}`
  36950. * allows setting multiple attributes simultaneously
  36951. */
  36952. exports.relayout = function relayout(gd, astr, val) {
  36953. gd = Lib.getGraphDiv(gd);
  36954. helpers.clearPromiseQueue(gd);
  36955. if(gd.framework && gd.framework.isPolar) {
  36956. return Promise.resolve(gd);
  36957. }
  36958. var aobj = {};
  36959. if(typeof astr === 'string') {
  36960. aobj[astr] = val;
  36961. } else if(Lib.isPlainObject(astr)) {
  36962. aobj = Lib.extendFlat({}, astr);
  36963. } else {
  36964. Lib.warn('Relayout fail.', astr, val);
  36965. return Promise.reject();
  36966. }
  36967. if(Object.keys(aobj).length) gd.changed = true;
  36968. var specs = _relayout(gd, aobj);
  36969. var flags = specs.flags;
  36970. // clear calcdata if required
  36971. if(flags.calc) gd.calcdata = undefined;
  36972. // fill in redraw sequence
  36973. // even if we don't have anything left in aobj,
  36974. // something may have happened within relayout that we
  36975. // need to wait for
  36976. var seq = [Plots.previousPromises];
  36977. if(flags.layoutReplot) {
  36978. seq.push(subroutines.layoutReplot);
  36979. }
  36980. else if(Object.keys(aobj).length) {
  36981. Plots.supplyDefaults(gd);
  36982. if(flags.legend) seq.push(subroutines.doLegend);
  36983. if(flags.layoutstyle) seq.push(subroutines.layoutStyles);
  36984. if(flags.axrange) {
  36985. addAxRangeSequence(seq, specs.rangesAltered);
  36986. }
  36987. if(flags.ticks) seq.push(subroutines.doTicksRelayout);
  36988. if(flags.modebar) seq.push(subroutines.doModeBar);
  36989. if(flags.camera) seq.push(subroutines.doCamera);
  36990. seq.push(emitAfterPlot);
  36991. }
  36992. seq.push(Plots.rehover);
  36993. Queue.add(gd,
  36994. relayout, [gd, specs.undoit],
  36995. relayout, [gd, specs.redoit]
  36996. );
  36997. var plotDone = Lib.syncOrAsync(seq, gd);
  36998. if(!plotDone || !plotDone.then) plotDone = Promise.resolve(gd);
  36999. return plotDone.then(function() {
  37000. gd.emit('plotly_relayout', specs.eventData);
  37001. return gd;
  37002. });
  37003. };
  37004. function addAxRangeSequence(seq, rangesAltered) {
  37005. // N.B. leave as sequence of subroutines (for now) instead of
  37006. // subroutine of its own so that finalDraw always gets
  37007. // executed after drawData
  37008. var doTicks = rangesAltered ?
  37009. function(gd) { return subroutines.doTicksRelayout(gd, rangesAltered); } :
  37010. subroutines.doTicksRelayout;
  37011. seq.push(
  37012. subroutines.doAutoRangeAndConstraints,
  37013. doTicks,
  37014. subroutines.drawData,
  37015. subroutines.finalDraw
  37016. );
  37017. }
  37018. var AX_RANGE_RE = /^[xyz]axis[0-9]*\.range(\[[0|1]\])?$/;
  37019. var AX_AUTORANGE_RE = /^[xyz]axis[0-9]*\.autorange$/;
  37020. var AX_DOMAIN_RE = /^[xyz]axis[0-9]*\.domain(\[[0|1]\])?$/;
  37021. function _relayout(gd, aobj) {
  37022. var layout = gd.layout,
  37023. fullLayout = gd._fullLayout,
  37024. keys = Object.keys(aobj),
  37025. axes = Axes.list(gd),
  37026. arrayEdits = {},
  37027. arrayStr,
  37028. i,
  37029. j;
  37030. // look for 'allaxes', split out into all axes
  37031. // in case of 3D the axis are nested within a scene which is held in _id
  37032. for(i = 0; i < keys.length; i++) {
  37033. if(keys[i].indexOf('allaxes') === 0) {
  37034. for(j = 0; j < axes.length; j++) {
  37035. var scene = axes[j]._id.substr(1),
  37036. axisAttr = (scene.indexOf('scene') !== -1) ? (scene + '.') : '',
  37037. newkey = keys[i].replace('allaxes', axisAttr + axes[j]._name);
  37038. if(!aobj[newkey]) aobj[newkey] = aobj[keys[i]];
  37039. }
  37040. delete aobj[keys[i]];
  37041. }
  37042. }
  37043. // initialize flags
  37044. var flags = editTypes.layoutFlags();
  37045. // copies of the change (and previous values of anything affected)
  37046. // for the undo / redo queue
  37047. var redoit = {},
  37048. undoit = {};
  37049. // for attrs that interact (like scales & autoscales), save the
  37050. // old vals before making the change
  37051. // val=undefined will not set a value, just record what the value was.
  37052. // attr can be an array to set several at once (all to the same val)
  37053. function doextra(attr, val) {
  37054. if(Array.isArray(attr)) {
  37055. attr.forEach(function(a) { doextra(a, val); });
  37056. return;
  37057. }
  37058. // if we have another value for this attribute (explicitly or
  37059. // via a parent) do not override with this auto-generated extra
  37060. if(attr in aobj || helpers.hasParent(aobj, attr)) return;
  37061. var p = Lib.nestedProperty(layout, attr);
  37062. if(!(attr in undoit)) {
  37063. undoit[attr] = undefinedToNull(p.get());
  37064. }
  37065. if(val !== undefined) p.set(val);
  37066. }
  37067. // for constraint enforcement: keep track of all axes (as {id: name})
  37068. // we're editing the (auto)range of, so we can tell the others constrained
  37069. // to scale with them that it's OK for them to shrink
  37070. var rangesAltered = {};
  37071. var axId;
  37072. function recordAlteredAxis(pleafPlus) {
  37073. var axId = Axes.name2id(pleafPlus.split('.')[0]);
  37074. rangesAltered[axId] = 1;
  37075. return axId;
  37076. }
  37077. // alter gd.layout
  37078. for(var ai in aobj) {
  37079. if(helpers.hasParent(aobj, ai)) {
  37080. throw new Error('cannot set ' + ai + 'and a parent attribute simultaneously');
  37081. }
  37082. var p = Lib.nestedProperty(layout, ai);
  37083. var vi = aobj[ai];
  37084. var plen = p.parts.length;
  37085. // p.parts may end with an index integer if the property is an array
  37086. var pend = plen - 1;
  37087. while(pend > 0 && typeof p.parts[pend] !== 'string') pend--;
  37088. // last property in chain (leaf node)
  37089. var pleaf = p.parts[pend];
  37090. // leaf plus immediate parent
  37091. var pleafPlus = p.parts[pend - 1] + '.' + pleaf;
  37092. // trunk nodes (everything except the leaf)
  37093. var ptrunk = p.parts.slice(0, pend).join('.');
  37094. var parentIn = Lib.nestedProperty(gd.layout, ptrunk).get();
  37095. var parentFull = Lib.nestedProperty(fullLayout, ptrunk).get();
  37096. var vOld = p.get();
  37097. if(vi === undefined) continue;
  37098. redoit[ai] = vi;
  37099. // axis reverse is special - it is its own inverse
  37100. // op and has no flag.
  37101. undoit[ai] = (pleaf === 'reverse') ? vi : undefinedToNull(vOld);
  37102. var valObject = PlotSchema.getLayoutValObject(fullLayout, p.parts);
  37103. if(valObject && valObject.impliedEdits && vi !== null) {
  37104. for(var impliedKey in valObject.impliedEdits) {
  37105. doextra(Lib.relativeAttr(ai, impliedKey), valObject.impliedEdits[impliedKey]);
  37106. }
  37107. }
  37108. // Setting width or height to null must reset the graph's width / height
  37109. // back to its initial value as computed during the first pass in Plots.plotAutoSize.
  37110. //
  37111. // To do so, we must manually set them back here using the _initialAutoSize cache.
  37112. if(['width', 'height'].indexOf(ai) !== -1 && vi === null) {
  37113. fullLayout[ai] = gd._initialAutoSize[ai];
  37114. }
  37115. // check autorange vs range
  37116. else if(pleafPlus.match(AX_RANGE_RE)) {
  37117. recordAlteredAxis(pleafPlus);
  37118. Lib.nestedProperty(fullLayout, ptrunk + '._inputRange').set(null);
  37119. }
  37120. else if(pleafPlus.match(AX_AUTORANGE_RE)) {
  37121. recordAlteredAxis(pleafPlus);
  37122. Lib.nestedProperty(fullLayout, ptrunk + '._inputRange').set(null);
  37123. var axFull = Lib.nestedProperty(fullLayout, ptrunk).get();
  37124. if(axFull._inputDomain) {
  37125. // if we're autoranging and this axis has a constrained domain,
  37126. // reset it so we don't get locked into a shrunken size
  37127. axFull._input.domain = axFull._inputDomain.slice();
  37128. }
  37129. }
  37130. else if(pleafPlus.match(AX_DOMAIN_RE)) {
  37131. Lib.nestedProperty(fullLayout, ptrunk + '._inputDomain').set(null);
  37132. }
  37133. // toggling axis type between log and linear: we need to convert
  37134. // positions for components that are still using linearized values,
  37135. // not data values like newer components.
  37136. // previously we did this for log <-> not-log, but now only do it
  37137. // for log <-> linear
  37138. if(pleaf === 'type') {
  37139. var ax = parentIn,
  37140. toLog = parentFull.type === 'linear' && vi === 'log',
  37141. fromLog = parentFull.type === 'log' && vi === 'linear';
  37142. if(toLog || fromLog) {
  37143. if(!ax || !ax.range) {
  37144. // 2D never gets here, but 3D does
  37145. // I don't think this is needed, but left here in case there
  37146. // are edge cases I'm not thinking of.
  37147. doextra(ptrunk + '.autorange', true);
  37148. }
  37149. else if(!parentFull.autorange) {
  37150. // toggling log without autorange: need to also recalculate ranges
  37151. // because log axes use linearized values for range endpoints
  37152. var r0 = ax.range[0],
  37153. r1 = ax.range[1];
  37154. if(toLog) {
  37155. // if both limits are negative, autorange
  37156. if(r0 <= 0 && r1 <= 0) {
  37157. doextra(ptrunk + '.autorange', true);
  37158. }
  37159. // if one is negative, set it 6 orders below the other.
  37160. if(r0 <= 0) r0 = r1 / 1e6;
  37161. else if(r1 <= 0) r1 = r0 / 1e6;
  37162. // now set the range values as appropriate
  37163. doextra(ptrunk + '.range[0]', Math.log(r0) / Math.LN10);
  37164. doextra(ptrunk + '.range[1]', Math.log(r1) / Math.LN10);
  37165. }
  37166. else {
  37167. doextra(ptrunk + '.range[0]', Math.pow(10, r0));
  37168. doextra(ptrunk + '.range[1]', Math.pow(10, r1));
  37169. }
  37170. }
  37171. else if(toLog) {
  37172. // just make sure the range is positive and in the right
  37173. // order, it'll get recalculated later
  37174. ax.range = (ax.range[1] > ax.range[0]) ? [1, 2] : [2, 1];
  37175. }
  37176. // clear polar view initial stash for radial range so that
  37177. // value get recomputed in correct units
  37178. if(Array.isArray(fullLayout._subplots.polar) &&
  37179. fullLayout._subplots.polar.length &&
  37180. fullLayout[p.parts[0]] &&
  37181. p.parts[1] === 'radialaxis'
  37182. ) {
  37183. delete fullLayout[p.parts[0]]._subplot.viewInitial['radialaxis.range'];
  37184. }
  37185. // Annotations and images also need to convert to/from linearized coords
  37186. // Shapes do not need this :)
  37187. Registry.getComponentMethod('annotations', 'convertCoords')(gd, parentFull, vi, doextra);
  37188. Registry.getComponentMethod('images', 'convertCoords')(gd, parentFull, vi, doextra);
  37189. }
  37190. else {
  37191. // any other type changes: the range from the previous type
  37192. // will not make sense, so autorange it.
  37193. doextra(ptrunk + '.autorange', true);
  37194. doextra(ptrunk + '.range', null);
  37195. }
  37196. Lib.nestedProperty(fullLayout, ptrunk + '._inputRange').set(null);
  37197. }
  37198. else if(pleaf.match(AX_NAME_PATTERN)) {
  37199. var fullProp = Lib.nestedProperty(fullLayout, ai).get(),
  37200. newType = (vi || {}).type;
  37201. // This can potentially cause strange behavior if the autotype is not
  37202. // numeric (linear, because we don't auto-log) but the previous type
  37203. // was log. That's a very strange edge case though
  37204. if(!newType || newType === '-') newType = 'linear';
  37205. Registry.getComponentMethod('annotations', 'convertCoords')(gd, fullProp, newType, doextra);
  37206. Registry.getComponentMethod('images', 'convertCoords')(gd, fullProp, newType, doextra);
  37207. }
  37208. // alter gd.layout
  37209. // collect array component edits for execution all together
  37210. // so we can ensure consistent behavior adding/removing items
  37211. // and order-independence for add/remove/edit all together in
  37212. // one relayout call
  37213. var containerArrayMatch = manageArrays.containerArrayMatch(ai);
  37214. if(containerArrayMatch) {
  37215. arrayStr = containerArrayMatch.array;
  37216. i = containerArrayMatch.index;
  37217. var propStr = containerArrayMatch.property;
  37218. var componentArray = Lib.nestedProperty(layout, arrayStr);
  37219. var obji = (componentArray || [])[i] || {};
  37220. var updateValObject = valObject || {editType: 'calc'};
  37221. if(propStr === '') {
  37222. // special handling of undoit if we're adding or removing an element
  37223. // ie 'annotations[2]' which can be {...} (add) or null (remove)
  37224. if(manageArrays.isAddVal(vi)) {
  37225. undoit[ai] = null;
  37226. } else if(manageArrays.isRemoveVal(vi)) {
  37227. undoit[ai] = obji;
  37228. } else {
  37229. Lib.warn('unrecognized full object value', aobj);
  37230. }
  37231. }
  37232. editTypes.update(flags, updateValObject);
  37233. // prepare the edits object we'll send to applyContainerArrayChanges
  37234. if(!arrayEdits[arrayStr]) arrayEdits[arrayStr] = {};
  37235. var objEdits = arrayEdits[arrayStr][i];
  37236. if(!objEdits) objEdits = arrayEdits[arrayStr][i] = {};
  37237. objEdits[propStr] = vi;
  37238. delete aobj[ai];
  37239. }
  37240. // handle axis reversal explicitly, as there's no 'reverse' attribute
  37241. else if(pleaf === 'reverse') {
  37242. if(parentIn.range) parentIn.range.reverse();
  37243. else {
  37244. doextra(ptrunk + '.autorange', true);
  37245. parentIn.range = [1, 0];
  37246. }
  37247. if(parentFull.autorange) flags.calc = true;
  37248. else flags.plot = true;
  37249. }
  37250. else {
  37251. if((fullLayout._has('scatter-like') && fullLayout._has('regl')) &&
  37252. (ai === 'dragmode' &&
  37253. (vi === 'lasso' || vi === 'select') &&
  37254. !(vOld === 'lasso' || vOld === 'select'))
  37255. ) {
  37256. flags.plot = true;
  37257. }
  37258. else if(valObject) editTypes.update(flags, valObject);
  37259. else flags.calc = true;
  37260. p.set(vi);
  37261. }
  37262. }
  37263. // now we've collected component edits - execute them all together
  37264. for(arrayStr in arrayEdits) {
  37265. var finished = manageArrays.applyContainerArrayChanges(gd,
  37266. Lib.nestedProperty(layout, arrayStr), arrayEdits[arrayStr], flags);
  37267. if(!finished) flags.plot = true;
  37268. }
  37269. // figure out if we need to recalculate axis constraints
  37270. var constraints = fullLayout._axisConstraintGroups || [];
  37271. for(axId in rangesAltered) {
  37272. for(i = 0; i < constraints.length; i++) {
  37273. var group = constraints[i];
  37274. if(group[axId]) {
  37275. // Always recalc if we're changing constrained ranges.
  37276. // Otherwise it's possible to violate the constraints by
  37277. // specifying arbitrary ranges for all axes in the group.
  37278. // this way some ranges may expand beyond what's specified,
  37279. // as they do at first draw, to satisfy the constraints.
  37280. flags.calc = true;
  37281. for(var groupAxId in group) {
  37282. if(!rangesAltered[groupAxId]) {
  37283. Axes.getFromId(gd, groupAxId)._constraintShrinkable = true;
  37284. }
  37285. }
  37286. }
  37287. }
  37288. }
  37289. // If the autosize changed or height or width was explicitly specified,
  37290. // this triggers a redraw
  37291. // TODO: do we really need special aobj.height/width handling here?
  37292. // couldn't editType do this?
  37293. if(updateAutosize(gd) || aobj.height || aobj.width) flags.plot = true;
  37294. if(flags.plot || flags.calc) {
  37295. flags.layoutReplot = true;
  37296. }
  37297. // now all attribute mods are done, as are
  37298. // redo and undo so we can save them
  37299. return {
  37300. flags: flags,
  37301. rangesAltered: rangesAltered,
  37302. undoit: undoit,
  37303. redoit: redoit,
  37304. eventData: Lib.extendDeep({}, redoit)
  37305. };
  37306. }
  37307. /*
  37308. * updateAutosize: we made a change, does it change the autosize result?
  37309. * puts the new size into fullLayout
  37310. * returns true if either height or width changed
  37311. */
  37312. function updateAutosize(gd) {
  37313. var fullLayout = gd._fullLayout;
  37314. var oldWidth = fullLayout.width;
  37315. var oldHeight = fullLayout.height;
  37316. // calculate autosizing
  37317. if(gd.layout.autosize) Plots.plotAutoSize(gd, gd.layout, fullLayout);
  37318. return (fullLayout.width !== oldWidth) || (fullLayout.height !== oldHeight);
  37319. }
  37320. /**
  37321. * update: update trace and layout attributes of an existing plot
  37322. *
  37323. * @param {String | HTMLDivElement} gd
  37324. * the id or DOM element of the graph container div
  37325. * @param {Object} traceUpdate
  37326. * attribute object `{astr1: val1, astr2: val2 ...}`
  37327. * corresponding to updates in the plot's traces
  37328. * @param {Object} layoutUpdate
  37329. * attribute object `{astr1: val1, astr2: val2 ...}`
  37330. * corresponding to updates in the plot's layout
  37331. * @param {Number[] | Number} [traces]
  37332. * integer or array of integers for the traces to alter (all if omitted)
  37333. *
  37334. */
  37335. exports.update = function update(gd, traceUpdate, layoutUpdate, _traces) {
  37336. gd = Lib.getGraphDiv(gd);
  37337. helpers.clearPromiseQueue(gd);
  37338. if(gd.framework && gd.framework.isPolar) {
  37339. return Promise.resolve(gd);
  37340. }
  37341. if(!Lib.isPlainObject(traceUpdate)) traceUpdate = {};
  37342. if(!Lib.isPlainObject(layoutUpdate)) layoutUpdate = {};
  37343. if(Object.keys(traceUpdate).length) gd.changed = true;
  37344. if(Object.keys(layoutUpdate).length) gd.changed = true;
  37345. var traces = helpers.coerceTraceIndices(gd, _traces);
  37346. var restyleSpecs = _restyle(gd, Lib.extendFlat({}, traceUpdate), traces);
  37347. var restyleFlags = restyleSpecs.flags;
  37348. var relayoutSpecs = _relayout(gd, Lib.extendFlat({}, layoutUpdate));
  37349. var relayoutFlags = relayoutSpecs.flags;
  37350. // clear calcdata and/or axis types if required
  37351. if(restyleFlags.calc || relayoutFlags.calc) gd.calcdata = undefined;
  37352. if(restyleFlags.clearAxisTypes) helpers.clearAxisTypes(gd, traces, layoutUpdate);
  37353. // fill in redraw sequence
  37354. var seq = [];
  37355. if(restyleFlags.fullReplot && relayoutFlags.layoutReplot) {
  37356. var data = gd.data,
  37357. layout = gd.layout;
  37358. // clear existing data/layout on gd
  37359. // so that Plotly.plot doesn't try to extend them
  37360. gd.data = undefined;
  37361. gd.layout = undefined;
  37362. seq.push(function() { return exports.plot(gd, data, layout); });
  37363. }
  37364. else if(restyleFlags.fullReplot) {
  37365. seq.push(exports.plot);
  37366. }
  37367. else if(relayoutFlags.layoutReplot) {
  37368. seq.push(subroutines.layoutReplot);
  37369. }
  37370. else {
  37371. seq.push(Plots.previousPromises);
  37372. Plots.supplyDefaults(gd);
  37373. if(restyleFlags.style) seq.push(subroutines.doTraceStyle);
  37374. if(restyleFlags.colorbars) seq.push(subroutines.doColorBars);
  37375. if(relayoutFlags.legend) seq.push(subroutines.doLegend);
  37376. if(relayoutFlags.layoutstyle) seq.push(subroutines.layoutStyles);
  37377. if(relayoutFlags.axrange) {
  37378. addAxRangeSequence(seq, relayoutSpecs.rangesAltered);
  37379. }
  37380. if(relayoutFlags.ticks) seq.push(subroutines.doTicksRelayout);
  37381. if(relayoutFlags.modebar) seq.push(subroutines.doModeBar);
  37382. if(relayoutFlags.camera) seq.push(subroutines.doCamera);
  37383. seq.push(emitAfterPlot);
  37384. }
  37385. seq.push(Plots.rehover);
  37386. Queue.add(gd,
  37387. update, [gd, restyleSpecs.undoit, relayoutSpecs.undoit, restyleSpecs.traces],
  37388. update, [gd, restyleSpecs.redoit, relayoutSpecs.redoit, restyleSpecs.traces]
  37389. );
  37390. var plotDone = Lib.syncOrAsync(seq, gd);
  37391. if(!plotDone || !plotDone.then) plotDone = Promise.resolve(gd);
  37392. return plotDone.then(function() {
  37393. gd.emit('plotly_update', {
  37394. data: restyleSpecs.eventData,
  37395. layout: relayoutSpecs.eventData
  37396. });
  37397. return gd;
  37398. });
  37399. };
  37400. /**
  37401. * Plotly.react:
  37402. * A plot/update method that takes the full plot state (same API as plot/newPlot)
  37403. * and diffs to determine the minimal update pathway
  37404. *
  37405. * @param {string id or DOM element} gd
  37406. * the id or DOM element of the graph container div
  37407. * @param {array of objects} data
  37408. * array of traces, containing the data and display information for each trace
  37409. * @param {object} layout
  37410. * object describing the overall display of the plot,
  37411. * all the stuff that doesn't pertain to any individual trace
  37412. * @param {object} config
  37413. * configuration options (see ./plot_config.js for more info)
  37414. *
  37415. * OR
  37416. *
  37417. * @param {string id or DOM element} gd
  37418. * the id or DOM element of the graph container div
  37419. * @param {object} figure
  37420. * object containing `data`, `layout`, `config`, and `frames` members
  37421. *
  37422. */
  37423. exports.react = function(gd, data, layout, config) {
  37424. var frames, plotDone;
  37425. function addFrames() { return exports.addFrames(gd, frames); }
  37426. gd = Lib.getGraphDiv(gd);
  37427. var oldFullData = gd._fullData;
  37428. var oldFullLayout = gd._fullLayout;
  37429. // you can use this as the initial draw as well as to update
  37430. if(!Lib.isPlotDiv(gd) || !oldFullData || !oldFullLayout) {
  37431. plotDone = exports.newPlot(gd, data, layout, config);
  37432. }
  37433. else {
  37434. if(Lib.isPlainObject(data)) {
  37435. var obj = data;
  37436. data = obj.data;
  37437. layout = obj.layout;
  37438. config = obj.config;
  37439. frames = obj.frames;
  37440. }
  37441. var configChanged = false;
  37442. // assume that if there's a config at all, we're reacting to it too,
  37443. // and completely replace the previous config
  37444. if(config) {
  37445. var oldConfig = Lib.extendDeep({}, gd._context);
  37446. gd._context = undefined;
  37447. setPlotContext(gd, config);
  37448. configChanged = diffConfig(oldConfig, gd._context);
  37449. }
  37450. gd.data = data || [];
  37451. helpers.cleanData(gd.data);
  37452. gd.layout = layout || {};
  37453. helpers.cleanLayout(gd.layout);
  37454. // "true" skips updating calcdata and remapping arrays from calcTransforms,
  37455. // which supplyDefaults usually does at the end, but we may need to NOT do
  37456. // if the diff (which we haven't determined yet) says we'll recalc
  37457. Plots.supplyDefaults(gd, {skipUpdateCalc: true});
  37458. var newFullData = gd._fullData;
  37459. var newFullLayout = gd._fullLayout;
  37460. var immutable = newFullLayout.datarevision === undefined;
  37461. var restyleFlags = diffData(gd, oldFullData, newFullData, immutable);
  37462. var relayoutFlags = diffLayout(gd, oldFullLayout, newFullLayout, immutable);
  37463. // TODO: how to translate this part of relayout to Plotly.react?
  37464. // // Setting width or height to null must reset the graph's width / height
  37465. // // back to its initial value as computed during the first pass in Plots.plotAutoSize.
  37466. // //
  37467. // // To do so, we must manually set them back here using the _initialAutoSize cache.
  37468. // if(['width', 'height'].indexOf(ai) !== -1 && vi === null) {
  37469. // fullLayout[ai] = gd._initialAutoSize[ai];
  37470. // }
  37471. if(updateAutosize(gd)) relayoutFlags.layoutReplot = true;
  37472. // clear calcdata if required
  37473. if(restyleFlags.calc || relayoutFlags.calc) gd.calcdata = undefined;
  37474. // otherwise do the calcdata updates and calcTransform array remaps that we skipped earlier
  37475. else Plots.supplyDefaultsUpdateCalc(gd.calcdata, newFullData);
  37476. // Note: what restyle/relayout use impliedEdits and clearAxisTypes for
  37477. // must be handled by the user when using Plotly.react.
  37478. // fill in redraw sequence
  37479. var seq = [];
  37480. if(frames) {
  37481. gd._transitionData = {};
  37482. Plots.createTransitionData(gd);
  37483. seq.push(addFrames);
  37484. }
  37485. if(restyleFlags.fullReplot || relayoutFlags.layoutReplot || configChanged) {
  37486. gd._fullLayout._skipDefaults = true;
  37487. seq.push(exports.plot);
  37488. }
  37489. else {
  37490. for(var componentType in relayoutFlags.arrays) {
  37491. var indices = relayoutFlags.arrays[componentType];
  37492. if(indices.length) {
  37493. var drawOne = Registry.getComponentMethod(componentType, 'drawOne');
  37494. if(drawOne !== Lib.noop) {
  37495. for(var i = 0; i < indices.length; i++) {
  37496. drawOne(gd, indices[i]);
  37497. }
  37498. }
  37499. else {
  37500. var draw = Registry.getComponentMethod(componentType, 'draw');
  37501. if(draw === Lib.noop) {
  37502. throw new Error('cannot draw components: ' + componentType);
  37503. }
  37504. draw(gd);
  37505. }
  37506. }
  37507. }
  37508. seq.push(Plots.previousPromises);
  37509. if(restyleFlags.style) seq.push(subroutines.doTraceStyle);
  37510. if(restyleFlags.colorbars) seq.push(subroutines.doColorBars);
  37511. if(relayoutFlags.legend) seq.push(subroutines.doLegend);
  37512. if(relayoutFlags.layoutstyle) seq.push(subroutines.layoutStyles);
  37513. if(relayoutFlags.axrange) addAxRangeSequence(seq);
  37514. if(relayoutFlags.ticks) seq.push(subroutines.doTicksRelayout);
  37515. if(relayoutFlags.modebar) seq.push(subroutines.doModeBar);
  37516. if(relayoutFlags.camera) seq.push(subroutines.doCamera);
  37517. seq.push(emitAfterPlot);
  37518. }
  37519. seq.push(Plots.rehover);
  37520. plotDone = Lib.syncOrAsync(seq, gd);
  37521. if(!plotDone || !plotDone.then) plotDone = Promise.resolve(gd);
  37522. }
  37523. return plotDone.then(function() {
  37524. gd.emit('plotly_react', {
  37525. data: data,
  37526. layout: layout
  37527. });
  37528. return gd;
  37529. });
  37530. };
  37531. function diffData(gd, oldFullData, newFullData, immutable) {
  37532. if(oldFullData.length !== newFullData.length) {
  37533. return {
  37534. fullReplot: true,
  37535. calc: true
  37536. };
  37537. }
  37538. var flags = editTypes.traceFlags();
  37539. flags.arrays = {};
  37540. var i, trace;
  37541. function getTraceValObject(parts) {
  37542. return PlotSchema.getTraceValObject(trace, parts);
  37543. }
  37544. var diffOpts = {
  37545. getValObject: getTraceValObject,
  37546. flags: flags,
  37547. immutable: immutable,
  37548. gd: gd
  37549. };
  37550. var seenUIDs = {};
  37551. for(i = 0; i < oldFullData.length; i++) {
  37552. trace = newFullData[i]._fullInput;
  37553. if(Plots.hasMakesDataTransform(trace)) trace = newFullData[i];
  37554. if(seenUIDs[trace.uid]) continue;
  37555. seenUIDs[trace.uid] = 1;
  37556. getDiffFlags(oldFullData[i]._fullInput, trace, [], diffOpts);
  37557. }
  37558. if(flags.calc || flags.plot) {
  37559. flags.fullReplot = true;
  37560. }
  37561. return flags;
  37562. }
  37563. function diffLayout(gd, oldFullLayout, newFullLayout, immutable) {
  37564. var flags = editTypes.layoutFlags();
  37565. flags.arrays = {};
  37566. function getLayoutValObject(parts) {
  37567. return PlotSchema.getLayoutValObject(newFullLayout, parts);
  37568. }
  37569. var diffOpts = {
  37570. getValObject: getLayoutValObject,
  37571. flags: flags,
  37572. immutable: immutable,
  37573. gd: gd
  37574. };
  37575. getDiffFlags(oldFullLayout, newFullLayout, [], diffOpts);
  37576. if(flags.plot || flags.calc) {
  37577. flags.layoutReplot = true;
  37578. }
  37579. return flags;
  37580. }
  37581. function getDiffFlags(oldContainer, newContainer, outerparts, opts) {
  37582. var valObject, key;
  37583. var getValObject = opts.getValObject;
  37584. var flags = opts.flags;
  37585. var immutable = opts.immutable;
  37586. var inArray = opts.inArray;
  37587. var arrayIndex = opts.arrayIndex;
  37588. function changed() {
  37589. var editType = valObject.editType;
  37590. if(inArray && editType.indexOf('arraydraw') !== -1) {
  37591. Lib.pushUnique(flags.arrays[inArray], arrayIndex);
  37592. return;
  37593. }
  37594. editTypes.update(flags, valObject);
  37595. }
  37596. function valObjectCanBeDataArray(valObject) {
  37597. return valObject.valType === 'data_array' || valObject.arrayOk;
  37598. }
  37599. for(key in oldContainer) {
  37600. // short-circuit based on previous calls or previous keys that already maximized the pathway
  37601. if(flags.calc) return;
  37602. var oldVal = oldContainer[key];
  37603. var newVal = newContainer[key];
  37604. if(key.charAt(0) === '_' || typeof oldVal === 'function' || oldVal === newVal) continue;
  37605. // FIXME: ax.tick0 and dtick get filled in during plotting (except for geo subplots),
  37606. // and unlike other auto values they don't make it back into the input,
  37607. // so newContainer won't have them.
  37608. if((key === 'tick0' || key === 'dtick') && outerparts[0] !== 'geo') {
  37609. var tickMode = newContainer.tickmode;
  37610. if(tickMode === 'auto' || tickMode === 'array' || !tickMode) continue;
  37611. }
  37612. // FIXME: Similarly for axis ranges for 3D
  37613. // contourcarpet doesn't HAVE zmin/zmax, they're just auto-added. It needs them.
  37614. if(key === 'range' && newContainer.autorange) continue;
  37615. if((key === 'zmin' || key === 'zmax') && newContainer.type === 'contourcarpet') continue;
  37616. var parts = outerparts.concat(key);
  37617. valObject = getValObject(parts);
  37618. // in case type changed, we may not even *have* a valObject.
  37619. if(!valObject) continue;
  37620. if(valObject._compareAsJSON && JSON.stringify(oldVal) === JSON.stringify(newVal)) continue;
  37621. var valType = valObject.valType;
  37622. var i;
  37623. var canBeDataArray = valObjectCanBeDataArray(valObject);
  37624. var wasArray = Array.isArray(oldVal);
  37625. var nowArray = Array.isArray(newVal);
  37626. // hack for traces that modify the data in supplyDefaults, like
  37627. // converting 1D to 2D arrays, which will always create new objects
  37628. if(wasArray && nowArray) {
  37629. var inputKey = '_input_' + key;
  37630. var oldValIn = oldContainer[inputKey];
  37631. var newValIn = newContainer[inputKey];
  37632. if(Array.isArray(oldValIn) && oldValIn === newValIn) continue;
  37633. }
  37634. if(newVal === undefined) {
  37635. if(canBeDataArray && wasArray) flags.calc = true;
  37636. else changed();
  37637. }
  37638. else if(valObject._isLinkedToArray) {
  37639. var arrayEditIndices = [];
  37640. var extraIndices = false;
  37641. if(!inArray) flags.arrays[key] = arrayEditIndices;
  37642. var minLen = Math.min(oldVal.length, newVal.length);
  37643. var maxLen = Math.max(oldVal.length, newVal.length);
  37644. if(minLen !== maxLen) {
  37645. if(valObject.editType === 'arraydraw') {
  37646. extraIndices = true;
  37647. }
  37648. else {
  37649. changed();
  37650. continue;
  37651. }
  37652. }
  37653. for(i = 0; i < minLen; i++) {
  37654. getDiffFlags(oldVal[i], newVal[i], parts.concat(i),
  37655. // add array indices, but not if we're already in an array
  37656. Lib.extendFlat({inArray: key, arrayIndex: i}, opts));
  37657. }
  37658. // put this at the end so that we know our collected array indices are sorted
  37659. // but the check for length changes happens up front so we can short-circuit
  37660. // diffing if appropriate
  37661. if(extraIndices) {
  37662. for(i = minLen; i < maxLen; i++) {
  37663. arrayEditIndices.push(i);
  37664. }
  37665. }
  37666. }
  37667. else if(!valType && Lib.isPlainObject(oldVal)) {
  37668. getDiffFlags(oldVal, newVal, parts, opts);
  37669. }
  37670. else if(canBeDataArray) {
  37671. if(wasArray && nowArray) {
  37672. // don't try to diff two data arrays. If immutable we know the data changed,
  37673. // if not, assume it didn't and let `layout.datarevision` tell us if it did
  37674. if(immutable) {
  37675. flags.calc = true;
  37676. }
  37677. }
  37678. else if(wasArray !== nowArray) {
  37679. flags.calc = true;
  37680. }
  37681. else changed();
  37682. }
  37683. else if(wasArray && nowArray) {
  37684. // info array, colorscale, 'any' - these are short, just stringify.
  37685. // I don't *think* that covers up any real differences post-validation, does it?
  37686. // otherwise we need to dive in 1 (info_array) or 2 (colorscale) levels and compare
  37687. // all elements.
  37688. if(oldVal.length !== newVal.length || String(oldVal) !== String(newVal)) {
  37689. changed();
  37690. }
  37691. }
  37692. else {
  37693. changed();
  37694. }
  37695. }
  37696. for(key in newContainer) {
  37697. if(!(key in oldContainer || key.charAt(0) === '_' || typeof newContainer[key] === 'function')) {
  37698. valObject = getValObject(outerparts.concat(key));
  37699. if(valObjectCanBeDataArray(valObject) && Array.isArray(newContainer[key])) {
  37700. flags.calc = true;
  37701. return;
  37702. }
  37703. else changed();
  37704. }
  37705. }
  37706. }
  37707. /*
  37708. * simple diff for config - for now, just treat all changes as equivalent
  37709. */
  37710. function diffConfig(oldConfig, newConfig) {
  37711. var key;
  37712. for(key in oldConfig) {
  37713. var oldVal = oldConfig[key];
  37714. var newVal = newConfig[key];
  37715. if(oldVal !== newVal) {
  37716. if(Lib.isPlainObject(oldVal) && Lib.isPlainObject(newVal)) {
  37717. if(diffConfig(oldVal, newVal)) {
  37718. return true;
  37719. }
  37720. }
  37721. else if(Array.isArray(oldVal) && Array.isArray(newVal)) {
  37722. if(oldVal.length !== newVal.length) {
  37723. return true;
  37724. }
  37725. for(var i = 0; i < oldVal.length; i++) {
  37726. if(oldVal[i] !== newVal[i]) {
  37727. if(Lib.isPlainObject(oldVal[i]) && Lib.isPlainObject(newVal[i])) {
  37728. if(diffConfig(oldVal[i], newVal[i])) {
  37729. return true;
  37730. }
  37731. }
  37732. else {
  37733. return true;
  37734. }
  37735. }
  37736. }
  37737. }
  37738. else {
  37739. return true;
  37740. }
  37741. }
  37742. }
  37743. }
  37744. /**
  37745. * Animate to a frame, sequence of frame, frame group, or frame definition
  37746. *
  37747. * @param {string id or DOM element} gd
  37748. * the id or DOM element of the graph container div
  37749. *
  37750. * @param {string or object or array of strings or array of objects} frameOrGroupNameOrFrameList
  37751. * a single frame, array of frames, or group to which to animate. The intent is
  37752. * inferred by the type of the input. Valid inputs are:
  37753. *
  37754. * - string, e.g. 'groupname': animate all frames of a given `group` in the order
  37755. * in which they are defined via `Plotly.addFrames`.
  37756. *
  37757. * - array of strings, e.g. ['frame1', frame2']: a list of frames by name to which
  37758. * to animate in sequence
  37759. *
  37760. * - object: {data: ...}: a frame definition to which to animate. The frame is not
  37761. * and does not need to be added via `Plotly.addFrames`. It may contain any of
  37762. * the properties of a frame, including `data`, `layout`, and `traces`. The
  37763. * frame is used as provided and does not use the `baseframe` property.
  37764. *
  37765. * - array of objects, e.g. [{data: ...}, {data: ...}]: a list of frame objects,
  37766. * each following the same rules as a single `object`.
  37767. *
  37768. * @param {object} animationOpts
  37769. * configuration for the animation
  37770. */
  37771. exports.animate = function(gd, frameOrGroupNameOrFrameList, animationOpts) {
  37772. gd = Lib.getGraphDiv(gd);
  37773. if(!Lib.isPlotDiv(gd)) {
  37774. throw new Error(
  37775. 'This element is not a Plotly plot: ' + gd + '. It\'s likely that you\'ve failed ' +
  37776. 'to create a plot before animating it. For more details, see ' +
  37777. 'https://plot.ly/javascript/animations/'
  37778. );
  37779. }
  37780. var trans = gd._transitionData;
  37781. // This is the queue of frames that will be animated as soon as possible. They
  37782. // are popped immediately upon the *start* of a transition:
  37783. if(!trans._frameQueue) {
  37784. trans._frameQueue = [];
  37785. }
  37786. animationOpts = Plots.supplyAnimationDefaults(animationOpts);
  37787. var transitionOpts = animationOpts.transition;
  37788. var frameOpts = animationOpts.frame;
  37789. // Since frames are popped immediately, an empty queue only means all frames have
  37790. // *started* to transition, not that the animation is complete. To solve that,
  37791. // track a separate counter that increments at the same time as frames are added
  37792. // to the queue, but decrements only when the transition is complete.
  37793. if(trans._frameWaitingCnt === undefined) {
  37794. trans._frameWaitingCnt = 0;
  37795. }
  37796. function getTransitionOpts(i) {
  37797. if(Array.isArray(transitionOpts)) {
  37798. if(i >= transitionOpts.length) {
  37799. return transitionOpts[0];
  37800. } else {
  37801. return transitionOpts[i];
  37802. }
  37803. } else {
  37804. return transitionOpts;
  37805. }
  37806. }
  37807. function getFrameOpts(i) {
  37808. if(Array.isArray(frameOpts)) {
  37809. if(i >= frameOpts.length) {
  37810. return frameOpts[0];
  37811. } else {
  37812. return frameOpts[i];
  37813. }
  37814. } else {
  37815. return frameOpts;
  37816. }
  37817. }
  37818. // Execute a callback after the wrapper function has been called n times.
  37819. // This is used to defer the resolution until a transition has resovled *and*
  37820. // the frame has completed. If it's not done this way, then we get a race
  37821. // condition in which the animation might resolve before a transition is complete
  37822. // or vice versa.
  37823. function callbackOnNthTime(cb, n) {
  37824. var cnt = 0;
  37825. return function() {
  37826. if(cb && ++cnt === n) {
  37827. return cb();
  37828. }
  37829. };
  37830. }
  37831. return new Promise(function(resolve, reject) {
  37832. function discardExistingFrames() {
  37833. if(trans._frameQueue.length === 0) {
  37834. return;
  37835. }
  37836. while(trans._frameQueue.length) {
  37837. var next = trans._frameQueue.pop();
  37838. if(next.onInterrupt) {
  37839. next.onInterrupt();
  37840. }
  37841. }
  37842. gd.emit('plotly_animationinterrupted', []);
  37843. }
  37844. function queueFrames(frameList) {
  37845. if(frameList.length === 0) return;
  37846. for(var i = 0; i < frameList.length; i++) {
  37847. var computedFrame;
  37848. if(frameList[i].type === 'byname') {
  37849. // If it's a named frame, compute it:
  37850. computedFrame = Plots.computeFrame(gd, frameList[i].name);
  37851. } else {
  37852. // Otherwise we must have been given a simple object, so treat
  37853. // the input itself as the computed frame.
  37854. computedFrame = frameList[i].data;
  37855. }
  37856. var frameOpts = getFrameOpts(i);
  37857. var transitionOpts = getTransitionOpts(i);
  37858. // It doesn't make much sense for the transition duration to be greater than
  37859. // the frame duration, so limit it:
  37860. transitionOpts.duration = Math.min(transitionOpts.duration, frameOpts.duration);
  37861. var nextFrame = {
  37862. frame: computedFrame,
  37863. name: frameList[i].name,
  37864. frameOpts: frameOpts,
  37865. transitionOpts: transitionOpts,
  37866. };
  37867. if(i === frameList.length - 1) {
  37868. // The last frame in this .animate call stores the promise resolve
  37869. // and reject callbacks. This is how we ensure that the animation
  37870. // loop (which may exist as a result of a *different* .animate call)
  37871. // still resolves or rejecdts this .animate call's promise. once it's
  37872. // complete.
  37873. nextFrame.onComplete = callbackOnNthTime(resolve, 2);
  37874. nextFrame.onInterrupt = reject;
  37875. }
  37876. trans._frameQueue.push(nextFrame);
  37877. }
  37878. // Set it as never having transitioned to a frame. This will cause the animation
  37879. // loop to immediately transition to the next frame (which, for immediate mode,
  37880. // is the first frame in the list since all others would have been discarded
  37881. // below)
  37882. if(animationOpts.mode === 'immediate') {
  37883. trans._lastFrameAt = -Infinity;
  37884. }
  37885. // Only it's not already running, start a RAF loop. This could be avoided in the
  37886. // case that there's only one frame, but it significantly complicated the logic
  37887. // and only sped things up by about 5% or so for a lorenz attractor simulation.
  37888. // It would be a fine thing to implement, but the benefit of that optimization
  37889. // doesn't seem worth the extra complexity.
  37890. if(!trans._animationRaf) {
  37891. beginAnimationLoop();
  37892. }
  37893. }
  37894. function stopAnimationLoop() {
  37895. gd.emit('plotly_animated');
  37896. // Be sure to unset also since it's how we know whether a loop is already running:
  37897. window.cancelAnimationFrame(trans._animationRaf);
  37898. trans._animationRaf = null;
  37899. }
  37900. function nextFrame() {
  37901. if(trans._currentFrame && trans._currentFrame.onComplete) {
  37902. // Execute the callback and unset it to ensure it doesn't
  37903. // accidentally get called twice
  37904. trans._currentFrame.onComplete();
  37905. }
  37906. var newFrame = trans._currentFrame = trans._frameQueue.shift();
  37907. if(newFrame) {
  37908. // Since it's sometimes necessary to do deep digging into frame data,
  37909. // we'll consider it not 100% impossible for nulls or numbers to sneak through,
  37910. // so check when casting the name, just to be absolutely certain:
  37911. var stringName = newFrame.name ? newFrame.name.toString() : null;
  37912. gd._fullLayout._currentFrame = stringName;
  37913. trans._lastFrameAt = Date.now();
  37914. trans._timeToNext = newFrame.frameOpts.duration;
  37915. // This is simply called and it's left to .transition to decide how to manage
  37916. // interrupting current transitions. That means we don't need to worry about
  37917. // how it resolves or what happens after this:
  37918. Plots.transition(gd,
  37919. newFrame.frame.data,
  37920. newFrame.frame.layout,
  37921. helpers.coerceTraceIndices(gd, newFrame.frame.traces),
  37922. newFrame.frameOpts,
  37923. newFrame.transitionOpts
  37924. ).then(function() {
  37925. if(newFrame.onComplete) {
  37926. newFrame.onComplete();
  37927. }
  37928. });
  37929. gd.emit('plotly_animatingframe', {
  37930. name: stringName,
  37931. frame: newFrame.frame,
  37932. animation: {
  37933. frame: newFrame.frameOpts,
  37934. transition: newFrame.transitionOpts,
  37935. }
  37936. });
  37937. } else {
  37938. // If there are no more frames, then stop the RAF loop:
  37939. stopAnimationLoop();
  37940. }
  37941. }
  37942. function beginAnimationLoop() {
  37943. gd.emit('plotly_animating');
  37944. // If no timer is running, then set last frame = long ago so that the next
  37945. // frame is immediately transitioned:
  37946. trans._lastFrameAt = -Infinity;
  37947. trans._timeToNext = 0;
  37948. trans._runningTransitions = 0;
  37949. trans._currentFrame = null;
  37950. var doFrame = function() {
  37951. // This *must* be requested before nextFrame since nextFrame may decide
  37952. // to cancel it if there's nothing more to animated:
  37953. trans._animationRaf = window.requestAnimationFrame(doFrame);
  37954. // Check if we're ready for a new frame:
  37955. if(Date.now() - trans._lastFrameAt > trans._timeToNext) {
  37956. nextFrame();
  37957. }
  37958. };
  37959. doFrame();
  37960. }
  37961. // This is an animate-local counter that helps match up option input list
  37962. // items with the particular frame.
  37963. var configCounter = 0;
  37964. function setTransitionConfig(frame) {
  37965. if(Array.isArray(transitionOpts)) {
  37966. if(configCounter >= transitionOpts.length) {
  37967. frame.transitionOpts = transitionOpts[configCounter];
  37968. } else {
  37969. frame.transitionOpts = transitionOpts[0];
  37970. }
  37971. } else {
  37972. frame.transitionOpts = transitionOpts;
  37973. }
  37974. configCounter++;
  37975. return frame;
  37976. }
  37977. // Disambiguate what's sort of frames have been received
  37978. var i, frame;
  37979. var frameList = [];
  37980. var allFrames = frameOrGroupNameOrFrameList === undefined || frameOrGroupNameOrFrameList === null;
  37981. var isFrameArray = Array.isArray(frameOrGroupNameOrFrameList);
  37982. var isSingleFrame = !allFrames && !isFrameArray && Lib.isPlainObject(frameOrGroupNameOrFrameList);
  37983. if(isSingleFrame) {
  37984. // In this case, a simple object has been passed to animate.
  37985. frameList.push({
  37986. type: 'object',
  37987. data: setTransitionConfig(Lib.extendFlat({}, frameOrGroupNameOrFrameList))
  37988. });
  37989. } else if(allFrames || ['string', 'number'].indexOf(typeof frameOrGroupNameOrFrameList) !== -1) {
  37990. // In this case, null or undefined has been passed so that we want to
  37991. // animate *all* currently defined frames
  37992. for(i = 0; i < trans._frames.length; i++) {
  37993. frame = trans._frames[i];
  37994. if(!frame) continue;
  37995. if(allFrames || String(frame.group) === String(frameOrGroupNameOrFrameList)) {
  37996. frameList.push({
  37997. type: 'byname',
  37998. name: String(frame.name),
  37999. data: setTransitionConfig({name: frame.name})
  38000. });
  38001. }
  38002. }
  38003. } else if(isFrameArray) {
  38004. for(i = 0; i < frameOrGroupNameOrFrameList.length; i++) {
  38005. var frameOrName = frameOrGroupNameOrFrameList[i];
  38006. if(['number', 'string'].indexOf(typeof frameOrName) !== -1) {
  38007. frameOrName = String(frameOrName);
  38008. // In this case, there's an array and this frame is a string name:
  38009. frameList.push({
  38010. type: 'byname',
  38011. name: frameOrName,
  38012. data: setTransitionConfig({name: frameOrName})
  38013. });
  38014. } else if(Lib.isPlainObject(frameOrName)) {
  38015. frameList.push({
  38016. type: 'object',
  38017. data: setTransitionConfig(Lib.extendFlat({}, frameOrName))
  38018. });
  38019. }
  38020. }
  38021. }
  38022. // Verify that all of these frames actually exist; return and reject if not:
  38023. for(i = 0; i < frameList.length; i++) {
  38024. frame = frameList[i];
  38025. if(frame.type === 'byname' && !trans._frameHash[frame.data.name]) {
  38026. Lib.warn('animate failure: frame not found: "' + frame.data.name + '"');
  38027. reject();
  38028. return;
  38029. }
  38030. }
  38031. // If the mode is either next or immediate, then all currently queued frames must
  38032. // be dumped and the corresponding .animate promises rejected.
  38033. if(['next', 'immediate'].indexOf(animationOpts.mode) !== -1) {
  38034. discardExistingFrames();
  38035. }
  38036. if(animationOpts.direction === 'reverse') {
  38037. frameList.reverse();
  38038. }
  38039. var currentFrame = gd._fullLayout._currentFrame;
  38040. if(currentFrame && animationOpts.fromcurrent) {
  38041. var idx = -1;
  38042. for(i = 0; i < frameList.length; i++) {
  38043. frame = frameList[i];
  38044. if(frame.type === 'byname' && frame.name === currentFrame) {
  38045. idx = i;
  38046. break;
  38047. }
  38048. }
  38049. if(idx > 0 && idx < frameList.length - 1) {
  38050. var filteredFrameList = [];
  38051. for(i = 0; i < frameList.length; i++) {
  38052. frame = frameList[i];
  38053. if(frameList[i].type !== 'byname' || i > idx) {
  38054. filteredFrameList.push(frame);
  38055. }
  38056. }
  38057. frameList = filteredFrameList;
  38058. }
  38059. }
  38060. if(frameList.length > 0) {
  38061. queueFrames(frameList);
  38062. } else {
  38063. // This is the case where there were simply no frames. It's a little strange
  38064. // since there's not much to do:
  38065. gd.emit('plotly_animated');
  38066. resolve();
  38067. }
  38068. });
  38069. };
  38070. /**
  38071. * Register new frames
  38072. *
  38073. * @param {string id or DOM element} gd
  38074. * the id or DOM element of the graph container div
  38075. *
  38076. * @param {array of objects} frameList
  38077. * list of frame definitions, in which each object includes any of:
  38078. * - name: {string} name of frame to add
  38079. * - data: {array of objects} trace data
  38080. * - layout {object} layout definition
  38081. * - traces {array} trace indices
  38082. * - baseframe {string} name of frame from which this frame gets defaults
  38083. *
  38084. * @param {array of integers} indices
  38085. * an array of integer indices matching the respective frames in `frameList`. If not
  38086. * provided, an index will be provided in serial order. If already used, the frame
  38087. * will be overwritten.
  38088. */
  38089. exports.addFrames = function(gd, frameList, indices) {
  38090. gd = Lib.getGraphDiv(gd);
  38091. if(frameList === null || frameList === undefined) {
  38092. return Promise.resolve();
  38093. }
  38094. if(!Lib.isPlotDiv(gd)) {
  38095. throw new Error(
  38096. 'This element is not a Plotly plot: ' + gd + '. It\'s likely that you\'ve failed ' +
  38097. 'to create a plot before adding frames. For more details, see ' +
  38098. 'https://plot.ly/javascript/animations/'
  38099. );
  38100. }
  38101. var i, frame, j, idx;
  38102. var _frames = gd._transitionData._frames;
  38103. var _frameHash = gd._transitionData._frameHash;
  38104. if(!Array.isArray(frameList)) {
  38105. throw new Error('addFrames failure: frameList must be an Array of frame definitions' + frameList);
  38106. }
  38107. // Create a sorted list of insertions since we run into lots of problems if these
  38108. // aren't in ascending order of index:
  38109. //
  38110. // Strictly for sorting. Make sure this is guaranteed to never collide with any
  38111. // already-exisisting indices:
  38112. var bigIndex = _frames.length + frameList.length * 2;
  38113. var insertions = [];
  38114. var _frameHashLocal = {};
  38115. for(i = frameList.length - 1; i >= 0; i--) {
  38116. if(!Lib.isPlainObject(frameList[i])) continue;
  38117. // The entire logic for checking for this type of name collision can be removed once we migrate to ES6 and
  38118. // use a Map instead of an Object instance, as Map keys aren't converted to strings.
  38119. var lookupName = frameList[i].name;
  38120. var name = (_frameHash[lookupName] || _frameHashLocal[lookupName] || {}).name;
  38121. var newName = frameList[i].name;
  38122. var collisionPresent = _frameHash[name] || _frameHashLocal[name];
  38123. if(name && newName && typeof newName === 'number' && collisionPresent && numericNameWarningCount < numericNameWarningCountLimit) {
  38124. numericNameWarningCount++;
  38125. Lib.warn('addFrames: overwriting frame "' + (_frameHash[name] || _frameHashLocal[name]).name +
  38126. '" with a frame whose name of type "number" also equates to "' +
  38127. name + '". This is valid but may potentially lead to unexpected ' +
  38128. 'behavior since all plotly.js frame names are stored internally ' +
  38129. 'as strings.');
  38130. if(numericNameWarningCount === numericNameWarningCountLimit) {
  38131. Lib.warn('addFrames: This API call has yielded too many of these warnings. ' +
  38132. 'For the rest of this call, further warnings about numeric frame ' +
  38133. 'names will be suppressed.');
  38134. }
  38135. }
  38136. _frameHashLocal[lookupName] = {name: lookupName};
  38137. insertions.push({
  38138. frame: Plots.supplyFrameDefaults(frameList[i]),
  38139. index: (indices && indices[i] !== undefined && indices[i] !== null) ? indices[i] : bigIndex + i
  38140. });
  38141. }
  38142. // Sort this, taking note that undefined insertions end up at the end:
  38143. insertions.sort(function(a, b) {
  38144. if(a.index > b.index) return -1;
  38145. if(a.index < b.index) return 1;
  38146. return 0;
  38147. });
  38148. var ops = [];
  38149. var revops = [];
  38150. var frameCount = _frames.length;
  38151. for(i = insertions.length - 1; i >= 0; i--) {
  38152. frame = insertions[i].frame;
  38153. if(typeof frame.name === 'number') {
  38154. Lib.warn('Warning: addFrames accepts frames with numeric names, but the numbers are' +
  38155. 'implicitly cast to strings');
  38156. }
  38157. if(!frame.name) {
  38158. // Repeatedly assign a default name, incrementing the counter each time until
  38159. // we get a name that's not in the hashed lookup table:
  38160. while(_frameHash[(frame.name = 'frame ' + gd._transitionData._counter++)]);
  38161. }
  38162. if(_frameHash[frame.name]) {
  38163. // If frame is present, overwrite its definition:
  38164. for(j = 0; j < _frames.length; j++) {
  38165. if((_frames[j] || {}).name === frame.name) break;
  38166. }
  38167. ops.push({type: 'replace', index: j, value: frame});
  38168. revops.unshift({type: 'replace', index: j, value: _frames[j]});
  38169. } else {
  38170. // Otherwise insert it at the end of the list:
  38171. idx = Math.max(0, Math.min(insertions[i].index, frameCount));
  38172. ops.push({type: 'insert', index: idx, value: frame});
  38173. revops.unshift({type: 'delete', index: idx});
  38174. frameCount++;
  38175. }
  38176. }
  38177. var undoFunc = Plots.modifyFrames,
  38178. redoFunc = Plots.modifyFrames,
  38179. undoArgs = [gd, revops],
  38180. redoArgs = [gd, ops];
  38181. if(Queue) Queue.add(gd, undoFunc, undoArgs, redoFunc, redoArgs);
  38182. return Plots.modifyFrames(gd, ops);
  38183. };
  38184. /**
  38185. * Delete frame
  38186. *
  38187. * @param {string id or DOM element} gd
  38188. * the id or DOM element of the graph container div
  38189. *
  38190. * @param {array of integers} frameList
  38191. * list of integer indices of frames to be deleted
  38192. */
  38193. exports.deleteFrames = function(gd, frameList) {
  38194. gd = Lib.getGraphDiv(gd);
  38195. if(!Lib.isPlotDiv(gd)) {
  38196. throw new Error('This element is not a Plotly plot: ' + gd);
  38197. }
  38198. var i, idx;
  38199. var _frames = gd._transitionData._frames;
  38200. var ops = [];
  38201. var revops = [];
  38202. if(!frameList) {
  38203. frameList = [];
  38204. for(i = 0; i < _frames.length; i++) {
  38205. frameList.push(i);
  38206. }
  38207. }
  38208. frameList = frameList.slice(0);
  38209. frameList.sort();
  38210. for(i = frameList.length - 1; i >= 0; i--) {
  38211. idx = frameList[i];
  38212. ops.push({type: 'delete', index: idx});
  38213. revops.unshift({type: 'insert', index: idx, value: _frames[idx]});
  38214. }
  38215. var undoFunc = Plots.modifyFrames,
  38216. redoFunc = Plots.modifyFrames,
  38217. undoArgs = [gd, revops],
  38218. redoArgs = [gd, ops];
  38219. if(Queue) Queue.add(gd, undoFunc, undoArgs, redoFunc, redoArgs);
  38220. return Plots.modifyFrames(gd, ops);
  38221. };
  38222. /**
  38223. * Purge a graph container div back to its initial pre-Plotly.plot state
  38224. *
  38225. * @param {string id or DOM element} gd
  38226. * the id or DOM element of the graph container div
  38227. */
  38228. exports.purge = function purge(gd) {
  38229. gd = Lib.getGraphDiv(gd);
  38230. var fullLayout = gd._fullLayout || {};
  38231. var fullData = gd._fullData || [];
  38232. var calcdata = gd.calcdata || [];
  38233. // remove gl contexts
  38234. Plots.cleanPlot([], {}, fullData, fullLayout, calcdata);
  38235. // purge properties
  38236. Plots.purge(gd);
  38237. // purge event emitter methods
  38238. Events.purge(gd);
  38239. // remove plot container
  38240. if(fullLayout._container) fullLayout._container.remove();
  38241. // in contrast to Plotly.Plots.purge which does NOT clear _context!
  38242. delete gd._context;
  38243. return gd;
  38244. };
  38245. // -------------------------------------------------------
  38246. // makePlotFramework: Create the plot container and axes
  38247. // -------------------------------------------------------
  38248. function makePlotFramework(gd) {
  38249. var gd3 = d3.select(gd);
  38250. var fullLayout = gd._fullLayout;
  38251. // Plot container
  38252. fullLayout._container = gd3.selectAll('.plot-container').data([0]);
  38253. fullLayout._container.enter().insert('div', ':first-child')
  38254. .classed('plot-container', true)
  38255. .classed('plotly', true);
  38256. // Make the svg container
  38257. fullLayout._paperdiv = fullLayout._container.selectAll('.svg-container').data([0]);
  38258. fullLayout._paperdiv.enter().append('div')
  38259. .classed('svg-container', true)
  38260. .style('position', 'relative');
  38261. // Make the graph containers
  38262. // start fresh each time we get here, so we know the order comes out
  38263. // right, rather than enter/exit which can muck up the order
  38264. // TODO: sort out all the ordering so we don't have to
  38265. // explicitly delete anything
  38266. // FIXME: parcoords reuses this object, not the best pattern
  38267. fullLayout._glcontainer = fullLayout._paperdiv.selectAll('.gl-container')
  38268. .data([{}]);
  38269. fullLayout._glcontainer.enter().append('div')
  38270. .classed('gl-container', true);
  38271. fullLayout._paperdiv.selectAll('.main-svg').remove();
  38272. fullLayout._paper = fullLayout._paperdiv.insert('svg', ':first-child')
  38273. .classed('main-svg', true);
  38274. fullLayout._toppaper = fullLayout._paperdiv.append('svg')
  38275. .classed('main-svg', true);
  38276. if(!fullLayout._uid) {
  38277. var otherUids = {};
  38278. d3.selectAll('defs').each(function() {
  38279. if(this.id) otherUids[this.id.split('-')[1]] = 1;
  38280. });
  38281. fullLayout._uid = Lib.randstr(otherUids);
  38282. }
  38283. fullLayout._paperdiv.selectAll('.main-svg')
  38284. .attr(xmlnsNamespaces.svgAttrs);
  38285. fullLayout._defs = fullLayout._paper.append('defs')
  38286. .attr('id', 'defs-' + fullLayout._uid);
  38287. fullLayout._clips = fullLayout._defs.append('g')
  38288. .classed('clips', true);
  38289. fullLayout._topdefs = fullLayout._toppaper.append('defs')
  38290. .attr('id', 'topdefs-' + fullLayout._uid);
  38291. fullLayout._topclips = fullLayout._topdefs.append('g')
  38292. .classed('clips', true);
  38293. fullLayout._bgLayer = fullLayout._paper.append('g')
  38294. .classed('bglayer', true);
  38295. fullLayout._draggers = fullLayout._paper.append('g')
  38296. .classed('draglayer', true);
  38297. // lower shape/image layer - note that this is behind
  38298. // all subplots data/grids but above the backgrounds
  38299. // except inset subplots, whose backgrounds are drawn
  38300. // inside their own group so that they appear above
  38301. // the data for the main subplot
  38302. // lower shapes and images which are fully referenced to
  38303. // a subplot still get drawn within the subplot's group
  38304. // so they will work correctly on insets
  38305. var layerBelow = fullLayout._paper.append('g')
  38306. .classed('layer-below', true);
  38307. fullLayout._imageLowerLayer = layerBelow.append('g')
  38308. .classed('imagelayer', true);
  38309. fullLayout._shapeLowerLayer = layerBelow.append('g')
  38310. .classed('shapelayer', true);
  38311. // single cartesian layer for the whole plot
  38312. fullLayout._cartesianlayer = fullLayout._paper.append('g').classed('cartesianlayer', true);
  38313. // single polar layer for the whole plot
  38314. fullLayout._polarlayer = fullLayout._paper.append('g').classed('polarlayer', true);
  38315. // single ternary layer for the whole plot
  38316. fullLayout._ternarylayer = fullLayout._paper.append('g').classed('ternarylayer', true);
  38317. // single geo layer for the whole plot
  38318. fullLayout._geolayer = fullLayout._paper.append('g').classed('geolayer', true);
  38319. // single pie layer for the whole plot
  38320. fullLayout._pielayer = fullLayout._paper.append('g').classed('pielayer', true);
  38321. // fill in image server scrape-svg
  38322. fullLayout._glimages = fullLayout._paper.append('g').classed('glimages', true);
  38323. // lastly upper shapes, info (legend, annotations) and hover layers go on top
  38324. // these are in a different svg element normally, but get collapsed into a single
  38325. // svg when exporting (after inserting 3D)
  38326. // upper shapes/images are only those drawn above the whole plot, including subplots
  38327. var layerAbove = fullLayout._toppaper.append('g')
  38328. .classed('layer-above', true);
  38329. fullLayout._imageUpperLayer = layerAbove.append('g')
  38330. .classed('imagelayer', true);
  38331. fullLayout._shapeUpperLayer = layerAbove.append('g')
  38332. .classed('shapelayer', true);
  38333. fullLayout._infolayer = fullLayout._toppaper.append('g').classed('infolayer', true);
  38334. fullLayout._menulayer = fullLayout._toppaper.append('g').classed('menulayer', true);
  38335. fullLayout._zoomlayer = fullLayout._toppaper.append('g').classed('zoomlayer', true);
  38336. fullLayout._hoverlayer = fullLayout._toppaper.append('g').classed('hoverlayer', true);
  38337. gd.emit('plotly_framework');
  38338. }
  38339. },{"../components/color":50,"../components/colorbar/connect":52,"../components/drawing":75,"../constants/xmlns_namespaces":152,"../lib":169,"../lib/events":162,"../lib/queue":184,"../lib/svg_text_utils":191,"../plots/cartesian/axes":214,"../plots/cartesian/constants":219,"../plots/cartesian/graph_interact":223,"../plots/plots":246,"../plots/polar/legacy":249,"../registry":259,"./edit_types":197,"./helpers":198,"./manage_arrays":200,"./plot_config":202,"./plot_schema":203,"./subroutines":205,"d3":16,"fast-isnumeric":18,"has-hover":20}],202:[function(_dereq_,module,exports){
  38340. /**
  38341. * Copyright 2012-2018, Plotly, Inc.
  38342. * All rights reserved.
  38343. *
  38344. * This source code is licensed under the MIT license found in the
  38345. * LICENSE file in the root directory of this source tree.
  38346. */
  38347. 'use strict';
  38348. /**
  38349. * This will be transferred over to gd and overridden by
  38350. * config args to Plotly.plot.
  38351. *
  38352. * The defaults are the appropriate settings for plotly.js,
  38353. * so we get the right experience without any config argument.
  38354. */
  38355. module.exports = {
  38356. // no interactivity, for export or image generation
  38357. staticPlot: false,
  38358. // base URL for the 'Edit in Chart Studio' (aka sendDataToCloud) mode bar button
  38359. // and the showLink/sendData on-graph link
  38360. plotlyServerURL: 'https://plot.ly',
  38361. /*
  38362. * we can edit titles, move annotations, etc - sets all pieces of `edits`
  38363. * unless a separate `edits` config item overrides individual parts
  38364. */
  38365. editable: false,
  38366. edits: {
  38367. /*
  38368. * annotationPosition: the main anchor of the annotation, which is the
  38369. * text (if no arrow) or the arrow (which drags the whole thing leaving
  38370. * the arrow length & direction unchanged)
  38371. */
  38372. annotationPosition: false,
  38373. // just for annotations with arrows, change the length and direction of the arrow
  38374. annotationTail: false,
  38375. annotationText: false,
  38376. axisTitleText: false,
  38377. colorbarPosition: false,
  38378. colorbarTitleText: false,
  38379. legendPosition: false,
  38380. // edit the trace name fields from the legend
  38381. legendText: false,
  38382. shapePosition: false,
  38383. // the global `layout.title`
  38384. titleText: false
  38385. },
  38386. /*
  38387. * DO autosize once regardless of layout.autosize
  38388. * (use default width or height values otherwise)
  38389. */
  38390. autosizable: false,
  38391. // responsive: determines whether to change the layout size when window is resized
  38392. responsive: false,
  38393. // set the length of the undo/redo queue
  38394. queueLength: 0,
  38395. // if we DO autosize, do we fill the container or the screen?
  38396. fillFrame: false,
  38397. // if we DO autosize, set the frame margins in percents of plot size
  38398. frameMargins: 0,
  38399. // mousewheel or two-finger scroll zooms the plot
  38400. scrollZoom: false,
  38401. // double click interaction (false, 'reset', 'autosize' or 'reset+autosize')
  38402. doubleClick: 'reset+autosize',
  38403. // new users see some hints about interactivity
  38404. showTips: true,
  38405. // enable axis pan/zoom drag handles
  38406. showAxisDragHandles: true,
  38407. /*
  38408. * enable direct range entry at the pan/zoom drag points
  38409. * (drag handles must be enabled above)
  38410. */
  38411. showAxisRangeEntryBoxes: true,
  38412. // link to open this plot in plotly
  38413. showLink: false,
  38414. // if we show a link, does it contain data or just link to a plotly file?
  38415. sendData: true,
  38416. // text appearing in the sendData link
  38417. linkText: 'Edit chart',
  38418. // false or function adding source(s) to linkText <text>
  38419. showSources: false,
  38420. // display the mode bar (true, false, or 'hover')
  38421. displayModeBar: 'hover',
  38422. /*
  38423. * remove mode bar button by name
  38424. * (see ../components/modebar/buttons.js for the list of names)
  38425. */
  38426. modeBarButtonsToRemove: [],
  38427. /*
  38428. * add mode bar button using config objects
  38429. * (see ./components/modebar/buttons.js for list of arguments)
  38430. */
  38431. modeBarButtonsToAdd: [],
  38432. /*
  38433. * fully custom mode bar buttons as nested array,
  38434. * where the outer arrays represents button groups, and
  38435. * the inner arrays have buttons config objects or names of default buttons
  38436. * (see ../components/modebar/buttons.js for more info)
  38437. */
  38438. modeBarButtons: false,
  38439. // statically override options for toImage modebar button
  38440. // allowed keys are format, filename, width, height, scale
  38441. // see ../components/modebar/buttons.js
  38442. toImageButtonOptions: {},
  38443. // add the plotly logo on the end of the mode bar
  38444. displaylogo: true,
  38445. // increase the pixel ratio for Gl plot images
  38446. plotGlPixelRatio: 2,
  38447. /*
  38448. * background setting function
  38449. * 'transparent' sets the background `layout.paper_color`
  38450. * 'opaque' blends bg color with white ensuring an opaque background
  38451. * or any other custom function of gd
  38452. */
  38453. setBackground: 'transparent',
  38454. // URL to topojson files used in geo charts
  38455. topojsonURL: 'https://cdn.plot.ly/',
  38456. /*
  38457. * Mapbox access token (required to plot mapbox trace types)
  38458. * If using an Mapbox Atlas server, set this option to '',
  38459. * so that plotly.js won't attempt to authenticate to the public Mapbox server.
  38460. */
  38461. mapboxAccessToken: null,
  38462. /*
  38463. * Turn all console logging on or off (errors will be thrown)
  38464. * This should ONLY be set via Plotly.setPlotConfig
  38465. * 0: no logs
  38466. * 1: warnings and errors, but not informational messages
  38467. * 2: verbose logs
  38468. */
  38469. logging: 1,
  38470. /*
  38471. * Set global transform to be applied to all traces with no
  38472. * specification needed
  38473. */
  38474. globalTransforms: [],
  38475. /*
  38476. * Which localization should we use?
  38477. * Should be a string like 'en' or 'en-US'.
  38478. */
  38479. locale: 'en-US',
  38480. /*
  38481. * Localization definitions
  38482. * Locales can be provided either here (specific to one chart) or globally
  38483. * by registering them as modules.
  38484. * Should be an object of objects {locale: {dictionary: {...}, format: {...}}}
  38485. * {
  38486. * da: {
  38487. * dictionary: {'Reset axes': 'Nulstil aksler', ...},
  38488. * format: {months: [...], shortMonths: [...]}
  38489. * },
  38490. * ...
  38491. * }
  38492. * All parts are optional. When looking for translation or format fields, we
  38493. * look first for an exact match in a config locale, then in a registered
  38494. * module. If those fail, we strip off any regionalization ('en-US' -> 'en')
  38495. * and try each (config, registry) again. The final fallback for translation
  38496. * is untranslated (which is US English) and for formats is the base English
  38497. * (the only consequence being the last fallback date format %x is DD/MM/YYYY
  38498. * instead of MM/DD/YYYY). Currently `grouping` and `currency` are ignored
  38499. * for our automatic number formatting, but can be used in custom formats.
  38500. */
  38501. locales: {}
  38502. };
  38503. },{}],203:[function(_dereq_,module,exports){
  38504. /**
  38505. * Copyright 2012-2018, Plotly, Inc.
  38506. * All rights reserved.
  38507. *
  38508. * This source code is licensed under the MIT license found in the
  38509. * LICENSE file in the root directory of this source tree.
  38510. */
  38511. 'use strict';
  38512. var Registry = _dereq_('../registry');
  38513. var Lib = _dereq_('../lib');
  38514. var baseAttributes = _dereq_('../plots/attributes');
  38515. var baseLayoutAttributes = _dereq_('../plots/layout_attributes');
  38516. var frameAttributes = _dereq_('../plots/frame_attributes');
  38517. var animationAttributes = _dereq_('../plots/animation_attributes');
  38518. // polar attributes are not part of the Registry yet
  38519. var polarAreaAttrs = _dereq_('../plots/polar/legacy/area_attributes');
  38520. var polarAxisAttrs = _dereq_('../plots/polar/legacy/axis_attributes');
  38521. var editTypes = _dereq_('./edit_types');
  38522. var extendFlat = Lib.extendFlat;
  38523. var extendDeepAll = Lib.extendDeepAll;
  38524. var isPlainObject = Lib.isPlainObject;
  38525. var IS_SUBPLOT_OBJ = '_isSubplotObj';
  38526. var IS_LINKED_TO_ARRAY = '_isLinkedToArray';
  38527. var ARRAY_ATTR_REGEXPS = '_arrayAttrRegexps';
  38528. var DEPRECATED = '_deprecated';
  38529. var UNDERSCORE_ATTRS = [IS_SUBPLOT_OBJ, IS_LINKED_TO_ARRAY, ARRAY_ATTR_REGEXPS, DEPRECATED];
  38530. exports.IS_SUBPLOT_OBJ = IS_SUBPLOT_OBJ;
  38531. exports.IS_LINKED_TO_ARRAY = IS_LINKED_TO_ARRAY;
  38532. exports.DEPRECATED = DEPRECATED;
  38533. exports.UNDERSCORE_ATTRS = UNDERSCORE_ATTRS;
  38534. /** Outputs the full plotly.js plot schema
  38535. *
  38536. * @return {object}
  38537. * - defs
  38538. * - traces
  38539. * - layout
  38540. * - transforms
  38541. * - frames
  38542. * - animations
  38543. * - config (coming soon ...)
  38544. */
  38545. exports.get = function() {
  38546. var traces = {};
  38547. Registry.allTypes.concat('area').forEach(function(type) {
  38548. traces[type] = getTraceAttributes(type);
  38549. });
  38550. var transforms = {};
  38551. Object.keys(Registry.transformsRegistry).forEach(function(type) {
  38552. transforms[type] = getTransformAttributes(type);
  38553. });
  38554. return {
  38555. defs: {
  38556. valObjects: Lib.valObjectMeta,
  38557. metaKeys: UNDERSCORE_ATTRS.concat(['description', 'role', 'editType', 'impliedEdits']),
  38558. editType: {
  38559. traces: editTypes.traces,
  38560. layout: editTypes.layout
  38561. },
  38562. impliedEdits: {
  38563. }
  38564. },
  38565. traces: traces,
  38566. layout: getLayoutAttributes(),
  38567. transforms: transforms,
  38568. frames: getFramesAttributes(),
  38569. animation: formatAttributes(animationAttributes)
  38570. };
  38571. };
  38572. /**
  38573. * Crawl the attribute tree, recursively calling a callback function
  38574. *
  38575. * @param {object} attrs
  38576. * The node of the attribute tree (e.g. the root) from which recursion originates
  38577. * @param {Function} callback
  38578. * A callback function with the signature:
  38579. * @callback callback
  38580. * @param {object} attr an attribute
  38581. * @param {String} attrName name string
  38582. * @param {object[]} attrs all the attributes
  38583. * @param {Number} level the recursion level, 0 at the root
  38584. * @param {Number} [specifiedLevel]
  38585. * The level in the tree, in order to let the callback function detect descend or backtrack,
  38586. * typically unsupplied (implied 0), just used by the self-recursive call.
  38587. * The necessity arises because the tree traversal is not controlled by callback return values.
  38588. * The decision to not use callback return values for controlling tree pruning arose from
  38589. * the goal of keeping the crawler backwards compatible. Observe that one of the pruning conditions
  38590. * precedes the callback call.
  38591. * @param {string} [attrString]
  38592. * the path to the current attribute, as an attribute string (ie 'marker.line')
  38593. * typically unsupplied, but you may supply it if you want to disambiguate which attrs tree you
  38594. * are starting from
  38595. *
  38596. * @return {object} transformOut
  38597. * copy of transformIn that contains attribute defaults
  38598. */
  38599. exports.crawl = function(attrs, callback, specifiedLevel, attrString) {
  38600. var level = specifiedLevel || 0;
  38601. attrString = attrString || '';
  38602. Object.keys(attrs).forEach(function(attrName) {
  38603. var attr = attrs[attrName];
  38604. if(UNDERSCORE_ATTRS.indexOf(attrName) !== -1) return;
  38605. var fullAttrString = (attrString ? attrString + '.' : '') + attrName;
  38606. callback(attr, attrName, attrs, level, fullAttrString);
  38607. if(exports.isValObject(attr)) return;
  38608. if(isPlainObject(attr) && attrName !== 'impliedEdits') {
  38609. exports.crawl(attr, callback, level + 1, fullAttrString);
  38610. }
  38611. });
  38612. };
  38613. /** Is object a value object (or a container object)?
  38614. *
  38615. * @param {object} obj
  38616. * @return {boolean}
  38617. * returns true for a valid value object and
  38618. * false for tree nodes in the attribute hierarchy
  38619. */
  38620. exports.isValObject = function(obj) {
  38621. return obj && obj.valType !== undefined;
  38622. };
  38623. /**
  38624. * Find all data array attributes in a given trace object - including
  38625. * `arrayOk` attributes.
  38626. *
  38627. * @param {object} trace
  38628. * full trace object that contains a reference to `_module.attributes`
  38629. *
  38630. * @return {array} arrayAttributes
  38631. * list of array attributes for the given trace
  38632. */
  38633. exports.findArrayAttributes = function(trace) {
  38634. var arrayAttributes = [];
  38635. var stack = [];
  38636. var isArrayStack = [];
  38637. var baseContainer, baseAttrName;
  38638. function callback(attr, attrName, attrs, level) {
  38639. stack = stack.slice(0, level).concat([attrName]);
  38640. isArrayStack = isArrayStack.slice(0, level).concat([attr && attr._isLinkedToArray]);
  38641. var splittableAttr = (
  38642. attr &&
  38643. (attr.valType === 'data_array' || attr.arrayOk === true) &&
  38644. !(stack[level - 1] === 'colorbar' && (attrName === 'ticktext' || attrName === 'tickvals'))
  38645. );
  38646. // Manually exclude 'colorbar.tickvals' and 'colorbar.ticktext' for now
  38647. // which are declared as `valType: 'data_array'` but scale independently of
  38648. // the coordinate arrays.
  38649. //
  38650. // Down the road, we might want to add a schema field (e.g `uncorrelatedArray: true`)
  38651. // to distinguish attributes of the likes.
  38652. if(!splittableAttr) return;
  38653. crawlIntoTrace(baseContainer, 0, '');
  38654. }
  38655. function crawlIntoTrace(container, i, astrPartial) {
  38656. var item = container[stack[i]];
  38657. var newAstrPartial = astrPartial + stack[i];
  38658. if(i === stack.length - 1) {
  38659. if(Lib.isArrayOrTypedArray(item)) {
  38660. arrayAttributes.push(baseAttrName + newAstrPartial);
  38661. }
  38662. }
  38663. else {
  38664. if(isArrayStack[i]) {
  38665. if(Array.isArray(item)) {
  38666. for(var j = 0; j < item.length; j++) {
  38667. if(Lib.isPlainObject(item[j])) {
  38668. crawlIntoTrace(item[j], i + 1, newAstrPartial + '[' + j + '].');
  38669. }
  38670. }
  38671. }
  38672. }
  38673. else if(Lib.isPlainObject(item)) {
  38674. crawlIntoTrace(item, i + 1, newAstrPartial + '.');
  38675. }
  38676. }
  38677. }
  38678. baseContainer = trace;
  38679. baseAttrName = '';
  38680. exports.crawl(baseAttributes, callback);
  38681. if(trace._module && trace._module.attributes) {
  38682. exports.crawl(trace._module.attributes, callback);
  38683. }
  38684. var transforms = trace.transforms;
  38685. if(transforms) {
  38686. for(var i = 0; i < transforms.length; i++) {
  38687. var transform = transforms[i];
  38688. var module = transform._module;
  38689. if(module) {
  38690. baseAttrName = 'transforms[' + i + '].';
  38691. baseContainer = transform;
  38692. exports.crawl(module.attributes, callback);
  38693. }
  38694. }
  38695. }
  38696. return arrayAttributes;
  38697. };
  38698. /*
  38699. * Find the valObject for one attribute in an existing trace
  38700. *
  38701. * @param {object} trace
  38702. * full trace object that contains a reference to `_module.attributes`
  38703. * @param {object} parts
  38704. * an array of parts, like ['transforms', 1, 'value']
  38705. * typically from nestedProperty(...).parts
  38706. *
  38707. * @return {object|false}
  38708. * the valObject for this attribute, or the last found parent
  38709. * in some cases the innermost valObject will not exist, for example
  38710. * `valType: 'any'` attributes where we might set a part of the attribute.
  38711. * In that case, stop at the deepest valObject we *do* find.
  38712. */
  38713. exports.getTraceValObject = function(trace, parts) {
  38714. var head = parts[0];
  38715. var i = 1; // index to start recursing from
  38716. var moduleAttrs, valObject;
  38717. if(head === 'transforms') {
  38718. if(parts.length === 1) {
  38719. return baseAttributes.transforms;
  38720. }
  38721. var transforms = trace.transforms;
  38722. if(!Array.isArray(transforms) || !transforms.length) return false;
  38723. var tNum = parts[1];
  38724. if(!isIndex(tNum) || tNum >= transforms.length) {
  38725. return false;
  38726. }
  38727. moduleAttrs = (Registry.transformsRegistry[transforms[tNum].type] || {}).attributes;
  38728. valObject = moduleAttrs && moduleAttrs[parts[2]];
  38729. i = 3; // start recursing only inside the transform
  38730. }
  38731. else if(trace.type === 'area') {
  38732. valObject = polarAreaAttrs[head];
  38733. }
  38734. else {
  38735. // first look in the module for this trace
  38736. // components have already merged their trace attributes in here
  38737. var _module = trace._module;
  38738. if(!_module) _module = (Registry.modules[trace.type || baseAttributes.type.dflt] || {})._module;
  38739. if(!_module) return false;
  38740. moduleAttrs = _module.attributes;
  38741. valObject = moduleAttrs && moduleAttrs[head];
  38742. // then look in the subplot attributes
  38743. if(!valObject) {
  38744. var subplotModule = _module.basePlotModule;
  38745. if(subplotModule && subplotModule.attributes) {
  38746. valObject = subplotModule.attributes[head];
  38747. }
  38748. }
  38749. // finally look in the global attributes
  38750. if(!valObject) valObject = baseAttributes[head];
  38751. }
  38752. return recurseIntoValObject(valObject, parts, i);
  38753. };
  38754. /*
  38755. * Find the valObject for one layout attribute
  38756. *
  38757. * @param {array} parts
  38758. * an array of parts, like ['annotations', 1, 'x']
  38759. * typically from nestedProperty(...).parts
  38760. *
  38761. * @return {object|false}
  38762. * the valObject for this attribute, or the last found parent
  38763. * in some cases the innermost valObject will not exist, for example
  38764. * `valType: 'any'` attributes where we might set a part of the attribute.
  38765. * In that case, stop at the deepest valObject we *do* find.
  38766. */
  38767. exports.getLayoutValObject = function(fullLayout, parts) {
  38768. var valObject = layoutHeadAttr(fullLayout, parts[0]);
  38769. return recurseIntoValObject(valObject, parts, 1);
  38770. };
  38771. function layoutHeadAttr(fullLayout, head) {
  38772. var i, key, _module, attributes;
  38773. // look for attributes of the subplot types used on the plot
  38774. var basePlotModules = fullLayout._basePlotModules;
  38775. if(basePlotModules) {
  38776. var out;
  38777. for(i = 0; i < basePlotModules.length; i++) {
  38778. _module = basePlotModules[i];
  38779. if(_module.attrRegex && _module.attrRegex.test(head)) {
  38780. // if a module defines overrides, these take precedence
  38781. // initially this is to allow gl2d different editTypes from svg cartesian
  38782. if(_module.layoutAttrOverrides) return _module.layoutAttrOverrides;
  38783. // otherwise take the first attributes we find
  38784. if(!out && _module.layoutAttributes) out = _module.layoutAttributes;
  38785. }
  38786. // a module can also override the behavior of base (and component) module layout attrs
  38787. // again see gl2d for initial use case
  38788. var baseOverrides = _module.baseLayoutAttrOverrides;
  38789. if(baseOverrides && head in baseOverrides) return baseOverrides[head];
  38790. }
  38791. if(out) return out;
  38792. }
  38793. // look for layout attributes contributed by traces on the plot
  38794. var modules = fullLayout._modules;
  38795. if(modules) {
  38796. for(i = 0; i < modules.length; i++) {
  38797. attributes = modules[i].layoutAttributes;
  38798. if(attributes && head in attributes) {
  38799. return attributes[head];
  38800. }
  38801. }
  38802. }
  38803. /*
  38804. * Next look in components.
  38805. * Components that define a schema have already merged this into
  38806. * base and subplot attribute defs, so ignore these.
  38807. * Others (older style) all put all their attributes
  38808. * inside a container matching the module `name`
  38809. * eg `attributes` (array) or `legend` (object)
  38810. */
  38811. for(key in Registry.componentsRegistry) {
  38812. _module = Registry.componentsRegistry[key];
  38813. if(!_module.schema && (head === _module.name)) {
  38814. return _module.layoutAttributes;
  38815. }
  38816. }
  38817. if(head in baseLayoutAttributes) return baseLayoutAttributes[head];
  38818. // Polar doesn't populate _modules or _basePlotModules
  38819. // just fall back on these when the others fail
  38820. if(head === 'radialaxis' || head === 'angularaxis') {
  38821. return polarAxisAttrs[head];
  38822. }
  38823. return polarAxisAttrs.layout[head] || false;
  38824. }
  38825. function recurseIntoValObject(valObject, parts, i) {
  38826. if(!valObject) return false;
  38827. if(valObject._isLinkedToArray) {
  38828. // skip array index, abort if we try to dive into an array without an index
  38829. if(isIndex(parts[i])) i++;
  38830. else if(i < parts.length) return false;
  38831. }
  38832. // now recurse as far as we can. Occasionally we have an attribute
  38833. // setting an internal part below what's in the schema; just return
  38834. // the innermost schema item we find.
  38835. for(; i < parts.length; i++) {
  38836. var newValObject = valObject[parts[i]];
  38837. if(isPlainObject(newValObject)) valObject = newValObject;
  38838. else break;
  38839. if(i === parts.length - 1) break;
  38840. if(valObject._isLinkedToArray) {
  38841. i++;
  38842. if(!isIndex(parts[i])) return false;
  38843. }
  38844. else if(valObject.valType === 'info_array') {
  38845. i++;
  38846. var index = parts[i];
  38847. if(!isIndex(index)) return false;
  38848. var items = valObject.items;
  38849. if(Array.isArray(items)) {
  38850. if(index >= items.length) return false;
  38851. if(valObject.dimensions === 2) {
  38852. i++;
  38853. if(parts.length === i) return valObject;
  38854. var index2 = parts[i];
  38855. if(!isIndex(index2)) return false;
  38856. valObject = items[index][index2];
  38857. }
  38858. else valObject = items[index];
  38859. }
  38860. else {
  38861. valObject = items;
  38862. }
  38863. }
  38864. }
  38865. return valObject;
  38866. }
  38867. // note: this is different from Lib.isIndex, this one doesn't accept numeric
  38868. // strings, only actual numbers.
  38869. function isIndex(val) {
  38870. return val === Math.round(val) && val >= 0;
  38871. }
  38872. function getTraceAttributes(type) {
  38873. var _module, basePlotModule;
  38874. if(type === 'area') {
  38875. _module = { attributes: polarAreaAttrs };
  38876. basePlotModule = {};
  38877. }
  38878. else {
  38879. _module = Registry.modules[type]._module,
  38880. basePlotModule = _module.basePlotModule;
  38881. }
  38882. var attributes = {};
  38883. // make 'type' the first attribute in the object
  38884. attributes.type = null;
  38885. // base attributes (same for all trace types)
  38886. extendDeepAll(attributes, baseAttributes);
  38887. // module attributes
  38888. extendDeepAll(attributes, _module.attributes);
  38889. // subplot attributes
  38890. if(basePlotModule.attributes) {
  38891. extendDeepAll(attributes, basePlotModule.attributes);
  38892. }
  38893. // 'type' gets overwritten by baseAttributes; reset it here
  38894. attributes.type = type;
  38895. var out = {
  38896. meta: _module.meta || {},
  38897. attributes: formatAttributes(attributes),
  38898. };
  38899. // trace-specific layout attributes
  38900. if(_module.layoutAttributes) {
  38901. var layoutAttributes = {};
  38902. extendDeepAll(layoutAttributes, _module.layoutAttributes);
  38903. out.layoutAttributes = formatAttributes(layoutAttributes);
  38904. }
  38905. return out;
  38906. }
  38907. function getLayoutAttributes() {
  38908. var layoutAttributes = {};
  38909. var key, _module;
  38910. // global layout attributes
  38911. extendDeepAll(layoutAttributes, baseLayoutAttributes);
  38912. // add base plot module layout attributes
  38913. for(key in Registry.subplotsRegistry) {
  38914. _module = Registry.subplotsRegistry[key];
  38915. if(!_module.layoutAttributes) continue;
  38916. if(Array.isArray(_module.attr)) {
  38917. for(var i = 0; i < _module.attr.length; i++) {
  38918. handleBasePlotModule(layoutAttributes, _module, _module.attr[i]);
  38919. }
  38920. } else {
  38921. var astr = _module.attr === 'subplot' ? _module.name : _module.attr;
  38922. handleBasePlotModule(layoutAttributes, _module, astr);
  38923. }
  38924. }
  38925. // polar layout attributes
  38926. layoutAttributes = assignPolarLayoutAttrs(layoutAttributes);
  38927. // add registered components layout attributes
  38928. for(key in Registry.componentsRegistry) {
  38929. _module = Registry.componentsRegistry[key];
  38930. var schema = _module.schema;
  38931. /*
  38932. * Components with defined schema have already been merged in at register time
  38933. * but a few components define attributes that apply only to xaxis
  38934. * not yaxis (rangeselector, rangeslider) - delete from y schema.
  38935. * Note that the input attributes for xaxis/yaxis are the same object
  38936. * so it's not possible to only add them to xaxis from the start.
  38937. * If we ever have such asymmetry the other way, or anywhere else,
  38938. * we will need to extend both this code and mergeComponentAttrsToSubplot
  38939. * (which will not find yaxis only for example)
  38940. */
  38941. if(schema && (schema.subplots || schema.layout)) {
  38942. var subplots = schema.subplots;
  38943. if(subplots && subplots.xaxis && !subplots.yaxis) {
  38944. for(var xkey in subplots.xaxis) delete layoutAttributes.yaxis[xkey];
  38945. }
  38946. }
  38947. // older style without schema need to be explicitly merged in now
  38948. else if(_module.layoutAttributes) {
  38949. insertAttrs(layoutAttributes, _module.layoutAttributes, _module.name);
  38950. }
  38951. }
  38952. return {
  38953. layoutAttributes: formatAttributes(layoutAttributes)
  38954. };
  38955. }
  38956. function getTransformAttributes(type) {
  38957. var _module = Registry.transformsRegistry[type];
  38958. var attributes = extendDeepAll({}, _module.attributes);
  38959. // add registered components transform attributes
  38960. Object.keys(Registry.componentsRegistry).forEach(function(k) {
  38961. var _module = Registry.componentsRegistry[k];
  38962. if(_module.schema && _module.schema.transforms && _module.schema.transforms[type]) {
  38963. Object.keys(_module.schema.transforms[type]).forEach(function(v) {
  38964. insertAttrs(attributes, _module.schema.transforms[type][v], v);
  38965. });
  38966. }
  38967. });
  38968. return {
  38969. attributes: formatAttributes(attributes)
  38970. };
  38971. }
  38972. function getFramesAttributes() {
  38973. var attrs = {
  38974. frames: Lib.extendDeepAll({}, frameAttributes)
  38975. };
  38976. formatAttributes(attrs);
  38977. return attrs.frames;
  38978. }
  38979. function formatAttributes(attrs) {
  38980. mergeValTypeAndRole(attrs);
  38981. formatArrayContainers(attrs);
  38982. stringify(attrs);
  38983. return attrs;
  38984. }
  38985. function mergeValTypeAndRole(attrs) {
  38986. function makeSrcAttr(attrName) {
  38987. return {
  38988. valType: 'string',
  38989. editType: 'none'
  38990. };
  38991. }
  38992. function callback(attr, attrName, attrs) {
  38993. if(exports.isValObject(attr)) {
  38994. if(attr.valType === 'data_array') {
  38995. // all 'data_array' attrs have role 'data'
  38996. attr.role = 'data';
  38997. // all 'data_array' attrs have a corresponding 'src' attr
  38998. attrs[attrName + 'src'] = makeSrcAttr(attrName);
  38999. }
  39000. else if(attr.arrayOk === true) {
  39001. // all 'arrayOk' attrs have a corresponding 'src' attr
  39002. attrs[attrName + 'src'] = makeSrcAttr(attrName);
  39003. }
  39004. }
  39005. else if(isPlainObject(attr)) {
  39006. // all attrs container objects get role 'object'
  39007. attr.role = 'object';
  39008. }
  39009. }
  39010. exports.crawl(attrs, callback);
  39011. }
  39012. function formatArrayContainers(attrs) {
  39013. function callback(attr, attrName, attrs) {
  39014. if(!attr) return;
  39015. var itemName = attr[IS_LINKED_TO_ARRAY];
  39016. if(!itemName) return;
  39017. delete attr[IS_LINKED_TO_ARRAY];
  39018. attrs[attrName] = { items: {} };
  39019. attrs[attrName].items[itemName] = attr;
  39020. attrs[attrName].role = 'object';
  39021. }
  39022. exports.crawl(attrs, callback);
  39023. }
  39024. // this can take around 10ms and should only be run from PlotSchema.get(),
  39025. // to ensure JSON.stringify(PlotSchema.get()) gives the intended result.
  39026. function stringify(attrs) {
  39027. function walk(attr) {
  39028. for(var k in attr) {
  39029. if(isPlainObject(attr[k])) {
  39030. walk(attr[k]);
  39031. } else if(Array.isArray(attr[k])) {
  39032. for(var i = 0; i < attr[k].length; i++) {
  39033. walk(attr[k][i]);
  39034. }
  39035. } else {
  39036. // as JSON.stringify(/test/) // => {}
  39037. if(attr[k] instanceof RegExp) {
  39038. attr[k] = attr[k].toString();
  39039. }
  39040. }
  39041. }
  39042. }
  39043. walk(attrs);
  39044. }
  39045. function assignPolarLayoutAttrs(layoutAttributes) {
  39046. extendFlat(layoutAttributes, {
  39047. radialaxis: polarAxisAttrs.radialaxis,
  39048. angularaxis: polarAxisAttrs.angularaxis
  39049. });
  39050. extendFlat(layoutAttributes, polarAxisAttrs.layout);
  39051. return layoutAttributes;
  39052. }
  39053. function handleBasePlotModule(layoutAttributes, _module, astr) {
  39054. var np = Lib.nestedProperty(layoutAttributes, astr),
  39055. attrs = extendDeepAll({}, _module.layoutAttributes);
  39056. attrs[IS_SUBPLOT_OBJ] = true;
  39057. np.set(attrs);
  39058. }
  39059. function insertAttrs(baseAttrs, newAttrs, astr) {
  39060. var np = Lib.nestedProperty(baseAttrs, astr);
  39061. np.set(extendDeepAll(np.get() || {}, newAttrs));
  39062. }
  39063. },{"../lib":169,"../plots/animation_attributes":209,"../plots/attributes":211,"../plots/frame_attributes":241,"../plots/layout_attributes":244,"../plots/polar/legacy/area_attributes":247,"../plots/polar/legacy/axis_attributes":248,"../registry":259,"./edit_types":197}],204:[function(_dereq_,module,exports){
  39064. /**
  39065. * Copyright 2012-2018, Plotly, Inc.
  39066. * All rights reserved.
  39067. *
  39068. * This source code is licensed under the MIT license found in the
  39069. * LICENSE file in the root directory of this source tree.
  39070. */
  39071. 'use strict';
  39072. var Lib = _dereq_('../lib');
  39073. var plotAttributes = _dereq_('../plots/attributes');
  39074. var TEMPLATEITEMNAME = 'templateitemname';
  39075. var templateAttrs = {
  39076. name: {
  39077. valType: 'string',
  39078. editType: 'none',
  39079. }
  39080. };
  39081. templateAttrs[TEMPLATEITEMNAME] = {
  39082. valType: 'string',
  39083. editType: 'calc',
  39084. };
  39085. /**
  39086. * templatedArray: decorate an attributes object with templating (and array)
  39087. * properties.
  39088. *
  39089. * @param {string} name: the singular form of the array name. Sets
  39090. * `_isLinkedToArray` to this, so the schema knows to treat this as an array.
  39091. * @param {object} attrs: the item attributes. Since all callers are expected
  39092. * to be constructing this object on the spot, we mutate it here for
  39093. * performance, rather than extending a new object with it.
  39094. *
  39095. * @returns {object}: the decorated `attrs` object
  39096. */
  39097. exports.templatedArray = function(name, attrs) {
  39098. attrs._isLinkedToArray = name;
  39099. attrs.name = templateAttrs.name;
  39100. attrs[TEMPLATEITEMNAME] = templateAttrs[TEMPLATEITEMNAME];
  39101. return attrs;
  39102. };
  39103. /**
  39104. * traceTemplater: logic for matching traces to trace templates
  39105. *
  39106. * @param {object} dataTemplate: collection of {traceType: [{template}, ...]}
  39107. * ie each type the template applies to contains a list of template objects,
  39108. * to be provided cyclically to data traces of that type.
  39109. *
  39110. * @returns {object}: {newTrace}, a function:
  39111. * newTrace(traceIn): that takes the input traceIn, coerces its type, then
  39112. * uses that type to find the next template to apply. returns the output
  39113. * traceOut with template attached, ready to continue supplyDefaults.
  39114. */
  39115. exports.traceTemplater = function(dataTemplate) {
  39116. var traceCounts = {};
  39117. var traceType, typeTemplates;
  39118. for(traceType in dataTemplate) {
  39119. typeTemplates = dataTemplate[traceType];
  39120. if(Array.isArray(typeTemplates) && typeTemplates.length) {
  39121. traceCounts[traceType] = 0;
  39122. }
  39123. }
  39124. function newTrace(traceIn) {
  39125. traceType = Lib.coerce(traceIn, {}, plotAttributes, 'type');
  39126. var traceOut = {type: traceType, _template: null};
  39127. if(traceType in traceCounts) {
  39128. typeTemplates = dataTemplate[traceType];
  39129. // cycle through traces in the template set for this type
  39130. var typei = traceCounts[traceType] % typeTemplates.length;
  39131. traceCounts[traceType]++;
  39132. traceOut._template = typeTemplates[typei];
  39133. }
  39134. else {
  39135. // TODO: anything we should do for types missing from the template?
  39136. // try to apply some other type? Or just bail as we do here?
  39137. // Actually I think yes, we should apply other types; would be nice
  39138. // if all scatter* could inherit from each other, and if histogram
  39139. // could inherit from bar, etc... but how to specify this? And do we
  39140. // compose them, or if a type is present require it to be complete?
  39141. // Actually this could apply to layout too - 3D annotations
  39142. // inheriting from 2D, axes of different types inheriting from each
  39143. // other...
  39144. }
  39145. return traceOut;
  39146. }
  39147. return {
  39148. newTrace: newTrace
  39149. // TODO: function to figure out what's left & what didn't work
  39150. };
  39151. };
  39152. /**
  39153. * newContainer: Create a new sub-container inside `container` and propagate any
  39154. * applicable template to it. If there's no template, still propagates
  39155. * `undefined` so relinkPrivate will not retain an old template!
  39156. *
  39157. * @param {object} container: the outer container, should already have _template
  39158. * if there *is* a template for this plot
  39159. * @param {string} name: the key of the new container to make
  39160. * @param {string} baseName: if applicable, a base attribute to take the
  39161. * template from, ie for xaxis3 the base would be xaxis
  39162. *
  39163. * @returns {object}: an object for inclusion _full*, empty except for the
  39164. * appropriate template piece
  39165. */
  39166. exports.newContainer = function(container, name, baseName) {
  39167. var template = container._template;
  39168. var part = template && (template[name] || (baseName && template[baseName]));
  39169. if(!Lib.isPlainObject(part)) part = null;
  39170. var out = container[name] = {_template: part};
  39171. return out;
  39172. };
  39173. /**
  39174. * arrayTemplater: special logic for templating both defaults and specific items
  39175. * in a container array (annotations etc)
  39176. *
  39177. * @param {object} container: the outer container, should already have _template
  39178. * if there *is* a template for this plot
  39179. * @param {string} name: the name of the array to template (ie 'annotations')
  39180. * will be used to find default ('annotationdefaults' object) and specific
  39181. * ('annotations' array) template specs.
  39182. * @param {string} inclusionAttr: the attribute determining this item's
  39183. * inclusion in the output, usually 'visible' or 'enabled'
  39184. *
  39185. * @returns {object}: {newItem, defaultItems}, both functions:
  39186. * newItem(itemIn): create an output item, bare except for the correct
  39187. * template and name(s), as the base for supplyDefaults
  39188. * defaultItems(): to be called after all newItem calls, return any
  39189. * specific template items that have not already beeen included,
  39190. * also as bare output items ready for supplyDefaults.
  39191. */
  39192. exports.arrayTemplater = function(container, name, inclusionAttr) {
  39193. var template = container._template;
  39194. var defaultsTemplate = template && template[arrayDefaultKey(name)];
  39195. var templateItems = template && template[name];
  39196. if(!Array.isArray(templateItems) || !templateItems.length) {
  39197. templateItems = [];
  39198. }
  39199. var usedNames = {};
  39200. function newItem(itemIn) {
  39201. // include name and templateitemname in the output object for ALL
  39202. // container array items. Note: you could potentially use different
  39203. // name and templateitemname, if you're using one template to make
  39204. // another template. templateitemname would be the name in the original
  39205. // template, and name is the new "subclassed" item name.
  39206. var out = {name: itemIn.name, _input: itemIn};
  39207. var templateItemName = out[TEMPLATEITEMNAME] = itemIn[TEMPLATEITEMNAME];
  39208. // no itemname: use the default template
  39209. if(!validItemName(templateItemName)) {
  39210. out._template = defaultsTemplate;
  39211. return out;
  39212. }
  39213. // look for an item matching this itemname
  39214. // note these do not inherit from the default template, only the item.
  39215. for(var i = 0; i < templateItems.length; i++) {
  39216. var templateItem = templateItems[i];
  39217. if(templateItem.name === templateItemName) {
  39218. // Note: it's OK to use a template item more than once
  39219. // but using it at least once will stop it from generating
  39220. // a default item at the end.
  39221. usedNames[templateItemName] = 1;
  39222. out._template = templateItem;
  39223. return out;
  39224. }
  39225. }
  39226. // Didn't find a matching template item, so since this item is intended
  39227. // to only be modifications it's most likely broken. Hide it unless
  39228. // it's explicitly marked visible - in which case it gets NO template,
  39229. // not even the default.
  39230. out[inclusionAttr] = itemIn[inclusionAttr] || false;
  39231. // special falsy value we can look for in validateTemplate
  39232. out._template = false;
  39233. return out;
  39234. }
  39235. function defaultItems() {
  39236. var out = [];
  39237. for(var i = 0; i < templateItems.length; i++) {
  39238. var templateItem = templateItems[i];
  39239. var name = templateItem.name;
  39240. // only allow named items to be added as defaults,
  39241. // and only allow each name once
  39242. if(validItemName(name) && !usedNames[name]) {
  39243. var outi = {
  39244. _template: templateItem,
  39245. name: name,
  39246. _input: {_templateitemname: name}
  39247. };
  39248. outi[TEMPLATEITEMNAME] = templateItem[TEMPLATEITEMNAME];
  39249. out.push(outi);
  39250. usedNames[name] = 1;
  39251. }
  39252. }
  39253. return out;
  39254. }
  39255. return {
  39256. newItem: newItem,
  39257. defaultItems: defaultItems
  39258. };
  39259. };
  39260. function validItemName(name) {
  39261. return name && typeof name === 'string';
  39262. }
  39263. function arrayDefaultKey(name) {
  39264. var lastChar = name.length - 1;
  39265. if(name.charAt(lastChar) !== 's') {
  39266. Lib.warn('bad argument to arrayDefaultKey: ' + name);
  39267. }
  39268. return name.substr(0, name.length - 1) + 'defaults';
  39269. }
  39270. exports.arrayDefaultKey = arrayDefaultKey;
  39271. /**
  39272. * arrayEditor: helper for editing array items that may have come from
  39273. * template defaults (in which case they will not exist in the input yet)
  39274. *
  39275. * @param {object} parentIn: the input container (eg gd.layout)
  39276. * @param {string} containerStr: the attribute string for the container inside
  39277. * `parentIn`.
  39278. * @param {object} itemOut: the _full* item (eg gd._fullLayout.annotations[0])
  39279. * that we'll be editing. Assumed to have been created by `arrayTemplater`.
  39280. *
  39281. * @returns {object}: {modifyBase, modifyItem, getUpdateObj, applyUpdate}, all functions:
  39282. * modifyBase(attr, value): Add an update that's *not* related to the item.
  39283. * `attr` is the full attribute string.
  39284. * modifyItem(attr, value): Add an update to the item. `attr` is just the
  39285. * portion of the attribute string inside the item.
  39286. * getUpdateObj(): Get the final constructed update object, to use in
  39287. * `restyle` or `relayout`. Also resets the update object in case this
  39288. * update was canceled.
  39289. * applyUpdate(attr, value): optionally add an update `attr: value`,
  39290. * then apply it to `parent` which should be the parent of `containerIn`,
  39291. * ie the object to which `containerStr` is the attribute string.
  39292. */
  39293. exports.arrayEditor = function(parentIn, containerStr, itemOut) {
  39294. var lengthIn = (Lib.nestedProperty(parentIn, containerStr).get() || []).length;
  39295. var index = itemOut._index;
  39296. // Check that we are indeed off the end of this container.
  39297. // Otherwise a devious user could put a key `_templateitemname` in their
  39298. // own input and break lots of things.
  39299. var templateItemName = (index >= lengthIn) && (itemOut._input || {})._templateitemname;
  39300. if(templateItemName) index = lengthIn;
  39301. var itemStr = containerStr + '[' + index + ']';
  39302. var update;
  39303. function resetUpdate() {
  39304. update = {};
  39305. if(templateItemName) {
  39306. update[itemStr] = {};
  39307. update[itemStr][TEMPLATEITEMNAME] = templateItemName;
  39308. }
  39309. }
  39310. resetUpdate();
  39311. function modifyBase(attr, value) {
  39312. update[attr] = value;
  39313. }
  39314. function modifyItem(attr, value) {
  39315. if(templateItemName) {
  39316. // we're making a new object: edit that object
  39317. Lib.nestedProperty(update[itemStr], attr).set(value);
  39318. }
  39319. else {
  39320. // we're editing an existing object: include *just* the edit
  39321. update[itemStr + '.' + attr] = value;
  39322. }
  39323. }
  39324. function getUpdateObj() {
  39325. var updateOut = update;
  39326. resetUpdate();
  39327. return updateOut;
  39328. }
  39329. function applyUpdate(attr, value) {
  39330. if(attr) modifyItem(attr, value);
  39331. var updateToApply = getUpdateObj();
  39332. for(var key in updateToApply) {
  39333. Lib.nestedProperty(parentIn, key).set(updateToApply[key]);
  39334. }
  39335. }
  39336. return {
  39337. modifyBase: modifyBase,
  39338. modifyItem: modifyItem,
  39339. getUpdateObj: getUpdateObj,
  39340. applyUpdate: applyUpdate
  39341. };
  39342. };
  39343. },{"../lib":169,"../plots/attributes":211}],205:[function(_dereq_,module,exports){
  39344. /**
  39345. * Copyright 2012-2018, Plotly, Inc.
  39346. * All rights reserved.
  39347. *
  39348. * This source code is licensed under the MIT license found in the
  39349. * LICENSE file in the root directory of this source tree.
  39350. */
  39351. 'use strict';
  39352. var d3 = _dereq_('d3');
  39353. var Registry = _dereq_('../registry');
  39354. var Plots = _dereq_('../plots/plots');
  39355. var Lib = _dereq_('../lib');
  39356. var clearGlCanvases = _dereq_('../lib/clear_gl_canvases');
  39357. var Color = _dereq_('../components/color');
  39358. var Drawing = _dereq_('../components/drawing');
  39359. var Titles = _dereq_('../components/titles');
  39360. var ModeBar = _dereq_('../components/modebar');
  39361. var Axes = _dereq_('../plots/cartesian/axes');
  39362. var alignmentConstants = _dereq_('../constants/alignment');
  39363. var axisConstraints = _dereq_('../plots/cartesian/constraints');
  39364. var enforceAxisConstraints = axisConstraints.enforce;
  39365. var cleanAxisConstraints = axisConstraints.clean;
  39366. var doAutoRange = _dereq_('../plots/cartesian/autorange').doAutoRange;
  39367. exports.layoutStyles = function(gd) {
  39368. return Lib.syncOrAsync([Plots.doAutoMargin, lsInner], gd);
  39369. };
  39370. function overlappingDomain(xDomain, yDomain, domains) {
  39371. for(var i = 0; i < domains.length; i++) {
  39372. var existingX = domains[i][0],
  39373. existingY = domains[i][1];
  39374. if(existingX[0] >= xDomain[1] || existingX[1] <= xDomain[0]) {
  39375. continue;
  39376. }
  39377. if(existingY[0] < yDomain[1] && existingY[1] > yDomain[0]) {
  39378. return true;
  39379. }
  39380. }
  39381. return false;
  39382. }
  39383. function lsInner(gd) {
  39384. var fullLayout = gd._fullLayout;
  39385. var gs = fullLayout._size;
  39386. var pad = gs.p;
  39387. var axList = Axes.list(gd, '', true);
  39388. // _has('cartesian') means SVG specifically, not GL2D - but GL2D
  39389. // can still get here because it makes some of the SVG structure
  39390. // for shared features like selections.
  39391. var hasSVGCartesian = fullLayout._has('cartesian');
  39392. var i;
  39393. function getLinePosition(ax, counterAx, side) {
  39394. var lwHalf = ax._lw / 2;
  39395. if(ax._id.charAt(0) === 'x') {
  39396. if(!counterAx) return gs.t + gs.h * (1 - (ax.position || 0)) + (lwHalf % 1);
  39397. else if(side === 'top') return counterAx._offset - pad - lwHalf;
  39398. return counterAx._offset + counterAx._length + pad + lwHalf;
  39399. }
  39400. if(!counterAx) return gs.l + gs.w * (ax.position || 0) + (lwHalf % 1);
  39401. else if(side === 'right') return counterAx._offset + counterAx._length + pad + lwHalf;
  39402. return counterAx._offset - pad - lwHalf;
  39403. }
  39404. // some preparation of axis position info
  39405. for(i = 0; i < axList.length; i++) {
  39406. var ax = axList[i];
  39407. // reset scale in case the margins have changed
  39408. ax.setScale();
  39409. var counterAx = ax._anchorAxis;
  39410. // clear axis line positions, to be set in the subplot loop below
  39411. ax._linepositions = {};
  39412. // stash crispRounded linewidth so we don't need to pass gd all over the place
  39413. ax._lw = Drawing.crispRound(gd, ax.linewidth, 1);
  39414. // figure out the main axis line and main mirror line position.
  39415. // it's easier to follow the logic if we handle these separately from
  39416. // ax._linepositions, which are only used by mirror=allticks
  39417. // for non-main-subplot ticks, and mirror=all(ticks)? for zero line
  39418. // hiding logic
  39419. ax._mainLinePosition = getLinePosition(ax, counterAx, ax.side);
  39420. ax._mainMirrorPosition = (ax.mirror && counterAx) ?
  39421. getLinePosition(ax, counterAx,
  39422. alignmentConstants.OPPOSITE_SIDE[ax.side]) : null;
  39423. // Figure out which subplot to draw ticks, labels, & axis lines on
  39424. // do this as a separate loop so we already have all the
  39425. // _mainAxis and _anchorAxis links set
  39426. ax._mainSubplot = findMainSubplot(ax, fullLayout);
  39427. }
  39428. fullLayout._paperdiv
  39429. .style({
  39430. width: fullLayout.width + 'px',
  39431. height: fullLayout.height + 'px'
  39432. })
  39433. .selectAll('.main-svg')
  39434. .call(Drawing.setSize, fullLayout.width, fullLayout.height);
  39435. gd._context.setBackground(gd, fullLayout.paper_bgcolor);
  39436. var subplotSelection = fullLayout._paper.selectAll('g.subplot');
  39437. // figure out which backgrounds we need to draw, and in which layers
  39438. // to put them
  39439. var lowerBackgroundIDs = [];
  39440. var lowerDomains = [];
  39441. subplotSelection.each(function(d) {
  39442. var subplot = d[0];
  39443. var plotinfo = fullLayout._plots[subplot];
  39444. if(plotinfo.mainplot) {
  39445. // mainplot is a reference to the main plot this one is overlaid on
  39446. // so if it exists, this is an overlaid plot and we don't need to
  39447. // give it its own background
  39448. if(plotinfo.bg) {
  39449. plotinfo.bg.remove();
  39450. }
  39451. plotinfo.bg = undefined;
  39452. return;
  39453. }
  39454. var xDomain = plotinfo.xaxis.domain;
  39455. var yDomain = plotinfo.yaxis.domain;
  39456. var plotgroup = plotinfo.plotgroup;
  39457. if(overlappingDomain(xDomain, yDomain, lowerDomains)) {
  39458. var pgNode = plotgroup.node();
  39459. var plotgroupBg = plotinfo.bg = Lib.ensureSingle(plotgroup, 'rect', 'bg');
  39460. pgNode.insertBefore(plotgroupBg.node(), pgNode.childNodes[0]);
  39461. } else {
  39462. plotgroup.select('rect.bg').remove();
  39463. lowerBackgroundIDs.push(subplot);
  39464. lowerDomains.push([xDomain, yDomain]);
  39465. }
  39466. });
  39467. // now create all the lower-layer backgrounds at once now that
  39468. // we have the list of subplots that need them
  39469. var lowerBackgrounds = fullLayout._bgLayer.selectAll('.bg')
  39470. .data(lowerBackgroundIDs);
  39471. lowerBackgrounds.enter().append('rect')
  39472. .classed('bg', true);
  39473. lowerBackgrounds.exit().remove();
  39474. lowerBackgrounds.each(function(subplot) {
  39475. fullLayout._plots[subplot].bg = d3.select(this);
  39476. });
  39477. subplotSelection.each(function(d) {
  39478. var subplot = d[0];
  39479. var plotinfo = fullLayout._plots[subplot];
  39480. var xa = plotinfo.xaxis;
  39481. var ya = plotinfo.yaxis;
  39482. if(plotinfo.bg && hasSVGCartesian) {
  39483. plotinfo.bg
  39484. .call(Drawing.setRect,
  39485. xa._offset - pad, ya._offset - pad,
  39486. xa._length + 2 * pad, ya._length + 2 * pad)
  39487. .call(Color.fill, fullLayout.plot_bgcolor)
  39488. .style('stroke-width', 0);
  39489. }
  39490. // Clip so that data only shows up on the plot area.
  39491. var clipId = plotinfo.clipId = 'clip' + fullLayout._uid + subplot + 'plot';
  39492. var plotClip = Lib.ensureSingleById(fullLayout._clips, 'clipPath', clipId, function(s) {
  39493. s.classed('plotclip', true)
  39494. .append('rect');
  39495. });
  39496. plotinfo.clipRect = plotClip.select('rect').attr({
  39497. width: xa._length,
  39498. height: ya._length
  39499. });
  39500. Drawing.setTranslate(plotinfo.plot, xa._offset, ya._offset);
  39501. var plotClipId;
  39502. var layerClipId;
  39503. if(plotinfo._hasClipOnAxisFalse) {
  39504. plotClipId = null;
  39505. layerClipId = clipId;
  39506. } else {
  39507. plotClipId = clipId;
  39508. layerClipId = null;
  39509. }
  39510. Drawing.setClipUrl(plotinfo.plot, plotClipId);
  39511. // stash layer clipId value (null or same as clipId)
  39512. // to DRY up Drawing.setClipUrl calls on trace-module and trace layers
  39513. // downstream
  39514. plotinfo.layerClipId = layerClipId;
  39515. // figure out extra axis line and tick positions as needed
  39516. if(!hasSVGCartesian) return;
  39517. var xLinesXLeft, xLinesXRight, xLinesYBottom, xLinesYTop,
  39518. leftYLineWidth, rightYLineWidth;
  39519. var yLinesYBottom, yLinesYTop, yLinesXLeft, yLinesXRight,
  39520. connectYBottom, connectYTop;
  39521. var extraSubplot;
  39522. function xLinePath(y) {
  39523. return 'M' + xLinesXLeft + ',' + y + 'H' + xLinesXRight;
  39524. }
  39525. function xLinePathFree(y) {
  39526. return 'M' + xa._offset + ',' + y + 'h' + xa._length;
  39527. }
  39528. function yLinePath(x) {
  39529. return 'M' + x + ',' + yLinesYTop + 'V' + yLinesYBottom;
  39530. }
  39531. function yLinePathFree(x) {
  39532. return 'M' + x + ',' + ya._offset + 'v' + ya._length;
  39533. }
  39534. function mainPath(ax, pathFn, pathFnFree) {
  39535. if(!ax.showline || subplot !== ax._mainSubplot) return '';
  39536. if(!ax._anchorAxis) return pathFnFree(ax._mainLinePosition);
  39537. var out = pathFn(ax._mainLinePosition);
  39538. if(ax.mirror) out += pathFn(ax._mainMirrorPosition);
  39539. return out;
  39540. }
  39541. /*
  39542. * x lines get longer where they meet y lines, to make a crisp corner.
  39543. * The x lines get the padding (margin.pad) plus the y line width to
  39544. * fill up the corner nicely. Free x lines are excluded - they always
  39545. * span exactly the data area of the plot
  39546. *
  39547. * | XXXXX
  39548. * | XXXXX
  39549. * |
  39550. * +------
  39551. * x1
  39552. * -----
  39553. * x2
  39554. */
  39555. var xPath = 'M0,0';
  39556. if(shouldShowLinesOrTicks(xa, subplot)) {
  39557. leftYLineWidth = findCounterAxisLineWidth(xa, 'left', ya, axList);
  39558. xLinesXLeft = xa._offset - (leftYLineWidth ? (pad + leftYLineWidth) : 0);
  39559. rightYLineWidth = findCounterAxisLineWidth(xa, 'right', ya, axList);
  39560. xLinesXRight = xa._offset + xa._length + (rightYLineWidth ? (pad + rightYLineWidth) : 0);
  39561. xLinesYBottom = getLinePosition(xa, ya, 'bottom');
  39562. xLinesYTop = getLinePosition(xa, ya, 'top');
  39563. // save axis line positions for extra ticks to reference
  39564. // each subplot that gets ticks from "allticks" gets an entry:
  39565. // [left or bottom, right or top]
  39566. extraSubplot = (!xa._anchorAxis || subplot !== xa._mainSubplot);
  39567. if(extraSubplot && (xa.mirror === 'allticks' || xa.mirror === 'all')) {
  39568. xa._linepositions[subplot] = [xLinesYBottom, xLinesYTop];
  39569. }
  39570. xPath = mainPath(xa, xLinePath, xLinePathFree);
  39571. if(extraSubplot && xa.showline && (xa.mirror === 'all' || xa.mirror === 'allticks')) {
  39572. xPath += xLinePath(xLinesYBottom) + xLinePath(xLinesYTop);
  39573. }
  39574. plotinfo.xlines
  39575. .style('stroke-width', xa._lw + 'px')
  39576. .call(Color.stroke, xa.showline ?
  39577. xa.linecolor : 'rgba(0,0,0,0)');
  39578. }
  39579. plotinfo.xlines.attr('d', xPath);
  39580. /*
  39581. * y lines that meet x axes get longer only by margin.pad, because
  39582. * the x axes fill in the corner space. Free y axes, like free x axes,
  39583. * always span exactly the data area of the plot
  39584. *
  39585. * | | XXXX
  39586. * y2| y1| XXXX
  39587. * | | XXXX
  39588. * |
  39589. * +-----
  39590. */
  39591. var yPath = 'M0,0';
  39592. if(shouldShowLinesOrTicks(ya, subplot)) {
  39593. connectYBottom = findCounterAxisLineWidth(ya, 'bottom', xa, axList);
  39594. yLinesYBottom = ya._offset + ya._length + (connectYBottom ? pad : 0);
  39595. connectYTop = findCounterAxisLineWidth(ya, 'top', xa, axList);
  39596. yLinesYTop = ya._offset - (connectYTop ? pad : 0);
  39597. yLinesXLeft = getLinePosition(ya, xa, 'left');
  39598. yLinesXRight = getLinePosition(ya, xa, 'right');
  39599. extraSubplot = (!ya._anchorAxis || subplot !== ya._mainSubplot);
  39600. if(extraSubplot && (ya.mirror === 'allticks' || ya.mirror === 'all')) {
  39601. ya._linepositions[subplot] = [yLinesXLeft, yLinesXRight];
  39602. }
  39603. yPath = mainPath(ya, yLinePath, yLinePathFree);
  39604. if(extraSubplot && ya.showline && (ya.mirror === 'all' || ya.mirror === 'allticks')) {
  39605. yPath += yLinePath(yLinesXLeft) + yLinePath(yLinesXRight);
  39606. }
  39607. plotinfo.ylines
  39608. .style('stroke-width', ya._lw + 'px')
  39609. .call(Color.stroke, ya.showline ?
  39610. ya.linecolor : 'rgba(0,0,0,0)');
  39611. }
  39612. plotinfo.ylines.attr('d', yPath);
  39613. });
  39614. Axes.makeClipPaths(gd);
  39615. exports.drawMainTitle(gd);
  39616. ModeBar.manage(gd);
  39617. return gd._promises.length && Promise.all(gd._promises);
  39618. }
  39619. function findMainSubplot(ax, fullLayout) {
  39620. var subplotList = fullLayout._subplots;
  39621. var ids = subplotList.cartesian.concat(subplotList.gl2d || []);
  39622. var mockGd = {_fullLayout: fullLayout};
  39623. var isX = ax._id.charAt(0) === 'x';
  39624. var anchorAx = ax._mainAxis._anchorAxis;
  39625. var mainSubplotID = '';
  39626. var nextBestMainSubplotID = '';
  39627. var anchorID = '';
  39628. // First try the main ID with the anchor
  39629. if(anchorAx) {
  39630. anchorID = anchorAx._mainAxis._id;
  39631. mainSubplotID = isX ? (ax._id + anchorID) : (anchorID + ax._id);
  39632. }
  39633. // Then look for a subplot with the counteraxis overlaying the anchor
  39634. // If that fails just use the first subplot including this axis
  39635. if(!mainSubplotID || !fullLayout._plots[mainSubplotID]) {
  39636. mainSubplotID = '';
  39637. for(var j = 0; j < ids.length; j++) {
  39638. var id = ids[j];
  39639. var yIndex = id.indexOf('y');
  39640. var idPart = isX ? id.substr(0, yIndex) : id.substr(yIndex);
  39641. var counterPart = isX ? id.substr(yIndex) : id.substr(0, yIndex);
  39642. if(idPart === ax._id) {
  39643. if(!nextBestMainSubplotID) nextBestMainSubplotID = id;
  39644. var counterAx = Axes.getFromId(mockGd, counterPart);
  39645. if(anchorID && counterAx.overlaying === anchorID) {
  39646. mainSubplotID = id;
  39647. break;
  39648. }
  39649. }
  39650. }
  39651. }
  39652. return mainSubplotID || nextBestMainSubplotID;
  39653. }
  39654. function shouldShowLinesOrTicks(ax, subplot) {
  39655. return (ax.ticks || ax.showline) &&
  39656. (subplot === ax._mainSubplot || ax.mirror === 'all' || ax.mirror === 'allticks');
  39657. }
  39658. /*
  39659. * should we draw a line on counterAx at this side of ax?
  39660. * It's assumed that counterAx is known to overlay the subplot we're working on
  39661. * but it may not be its main axis.
  39662. */
  39663. function shouldShowLineThisSide(ax, side, counterAx) {
  39664. // does counterAx get a line at all?
  39665. if(!counterAx.showline || !counterAx._lw) return false;
  39666. // are we drawing *all* lines for counterAx?
  39667. if(counterAx.mirror === 'all' || counterAx.mirror === 'allticks') return true;
  39668. var anchorAx = counterAx._anchorAxis;
  39669. // is this a free axis? free axes can only have a subplot side-line with all(ticks)? mirroring
  39670. if(!anchorAx) return false;
  39671. // in order to handle cases where the user forgot to anchor this axis correctly
  39672. // (because its default anchor has the same domain on the relevant end)
  39673. // check whether the relevant position is the same.
  39674. var sideIndex = alignmentConstants.FROM_BL[side];
  39675. if(counterAx.side === side) {
  39676. return anchorAx.domain[sideIndex] === ax.domain[sideIndex];
  39677. }
  39678. return counterAx.mirror && anchorAx.domain[1 - sideIndex] === ax.domain[1 - sideIndex];
  39679. }
  39680. /*
  39681. * Is there another axis intersecting `side` end of `ax`?
  39682. * First look at `counterAx` (the axis for this subplot),
  39683. * then at all other potential counteraxes on or overlaying this subplot.
  39684. * Take the line width from the first one that has a line.
  39685. */
  39686. function findCounterAxisLineWidth(ax, side, counterAx, axList) {
  39687. if(shouldShowLineThisSide(ax, side, counterAx)) {
  39688. return counterAx._lw;
  39689. }
  39690. for(var i = 0; i < axList.length; i++) {
  39691. var axi = axList[i];
  39692. if(axi._mainAxis === counterAx._mainAxis && shouldShowLineThisSide(ax, side, axi)) {
  39693. return axi._lw;
  39694. }
  39695. }
  39696. return 0;
  39697. }
  39698. exports.drawMainTitle = function(gd) {
  39699. var fullLayout = gd._fullLayout;
  39700. Titles.draw(gd, 'gtitle', {
  39701. propContainer: fullLayout,
  39702. propName: 'title',
  39703. placeholder: fullLayout._dfltTitle.plot,
  39704. attributes: {
  39705. x: fullLayout.width / 2,
  39706. y: fullLayout._size.t / 2,
  39707. 'text-anchor': 'middle'
  39708. }
  39709. });
  39710. };
  39711. // First, see if we need to do arraysToCalcdata
  39712. // call it regardless of what change we made, in case
  39713. // supplyDefaults brought in an array that was already
  39714. // in gd.data but not in gd._fullData previously
  39715. exports.doTraceStyle = function(gd) {
  39716. for(var i = 0; i < gd.calcdata.length; i++) {
  39717. var cdi = gd.calcdata[i],
  39718. _module = ((cdi[0] || {}).trace || {})._module || {},
  39719. arraysToCalcdata = _module.arraysToCalcdata;
  39720. if(arraysToCalcdata) arraysToCalcdata(cdi, cdi[0].trace);
  39721. }
  39722. Plots.style(gd);
  39723. Registry.getComponentMethod('legend', 'draw')(gd);
  39724. return Plots.previousPromises(gd);
  39725. };
  39726. exports.doColorBars = function(gd) {
  39727. for(var i = 0; i < gd.calcdata.length; i++) {
  39728. var cdi0 = gd.calcdata[i][0];
  39729. if((cdi0.t || {}).cb) {
  39730. var trace = cdi0.trace,
  39731. cb = cdi0.t.cb;
  39732. if(Registry.traceIs(trace, 'contour')) {
  39733. cb.line({
  39734. width: trace.contours.showlines !== false ?
  39735. trace.line.width : 0,
  39736. dash: trace.line.dash,
  39737. color: trace.contours.coloring === 'line' ?
  39738. cb._opts.line.color : trace.line.color
  39739. });
  39740. }
  39741. var moduleOpts = trace._module.colorbar;
  39742. var containerName = moduleOpts.container;
  39743. var opts = (containerName ? trace[containerName] : trace).colorbar;
  39744. cb.options(opts)();
  39745. }
  39746. }
  39747. return Plots.previousPromises(gd);
  39748. };
  39749. // force plot() to redo the layout and replot with the modified layout
  39750. exports.layoutReplot = function(gd) {
  39751. var layout = gd.layout;
  39752. gd.layout = undefined;
  39753. return Registry.call('plot', gd, '', layout);
  39754. };
  39755. exports.doLegend = function(gd) {
  39756. Registry.getComponentMethod('legend', 'draw')(gd);
  39757. return Plots.previousPromises(gd);
  39758. };
  39759. exports.doTicksRelayout = function(gd, rangesAltered) {
  39760. if(rangesAltered) {
  39761. Axes.doTicks(gd, Object.keys(rangesAltered), true);
  39762. } else {
  39763. Axes.doTicks(gd, 'redraw');
  39764. }
  39765. if(gd._fullLayout._hasOnlyLargeSploms) {
  39766. clearGlCanvases(gd);
  39767. Registry.subplotsRegistry.splom.plot(gd);
  39768. }
  39769. exports.drawMainTitle(gd);
  39770. return Plots.previousPromises(gd);
  39771. };
  39772. exports.doModeBar = function(gd) {
  39773. var fullLayout = gd._fullLayout;
  39774. ModeBar.manage(gd);
  39775. for(var i = 0; i < fullLayout._basePlotModules.length; i++) {
  39776. var updateFx = fullLayout._basePlotModules[i].updateFx;
  39777. if(updateFx) updateFx(gd);
  39778. }
  39779. return Plots.previousPromises(gd);
  39780. };
  39781. exports.doCamera = function(gd) {
  39782. var fullLayout = gd._fullLayout;
  39783. var sceneIds = fullLayout._subplots.gl3d;
  39784. for(var i = 0; i < sceneIds.length; i++) {
  39785. var sceneLayout = fullLayout[sceneIds[i]];
  39786. var scene = sceneLayout._scene;
  39787. scene.setCamera(sceneLayout.camera);
  39788. }
  39789. };
  39790. exports.drawData = function(gd) {
  39791. var fullLayout = gd._fullLayout;
  39792. var calcdata = gd.calcdata;
  39793. var i;
  39794. // remove old colorbars explicitly
  39795. for(i = 0; i < calcdata.length; i++) {
  39796. var trace = calcdata[i][0].trace;
  39797. if(trace.visible !== true || !trace._module.colorbar) {
  39798. fullLayout._infolayer.select('.cb' + trace.uid).remove();
  39799. }
  39800. }
  39801. clearGlCanvases(gd);
  39802. // loop over the base plot modules present on graph
  39803. var basePlotModules = fullLayout._basePlotModules;
  39804. for(i = 0; i < basePlotModules.length; i++) {
  39805. basePlotModules[i].plot(gd);
  39806. }
  39807. // styling separate from drawing
  39808. Plots.style(gd);
  39809. // show annotations and shapes
  39810. Registry.getComponentMethod('shapes', 'draw')(gd);
  39811. Registry.getComponentMethod('annotations', 'draw')(gd);
  39812. // Mark the first render as complete
  39813. fullLayout._replotting = false;
  39814. return Plots.previousPromises(gd);
  39815. };
  39816. exports.doAutoRangeAndConstraints = function(gd) {
  39817. var axList = Axes.list(gd, '', true);
  39818. for(var i = 0; i < axList.length; i++) {
  39819. var ax = axList[i];
  39820. cleanAxisConstraints(gd, ax);
  39821. doAutoRange(gd, ax);
  39822. }
  39823. enforceAxisConstraints(gd);
  39824. };
  39825. // An initial paint must be completed before these components can be
  39826. // correctly sized and the whole plot re-margined. fullLayout._replotting must
  39827. // be set to false before these will work properly.
  39828. exports.finalDraw = function(gd) {
  39829. Registry.getComponentMethod('shapes', 'draw')(gd);
  39830. Registry.getComponentMethod('images', 'draw')(gd);
  39831. Registry.getComponentMethod('annotations', 'draw')(gd);
  39832. // TODO: rangesliders really belong in marginPushers but they need to be
  39833. // drawn after data - can we at least get the margin pushing part separated
  39834. // out and done earlier?
  39835. Registry.getComponentMethod('rangeslider', 'draw')(gd);
  39836. // TODO: rangeselector only needs to be here (in addition to drawMarginPushers)
  39837. // because the margins need to be fully determined before we can call
  39838. // autorange and update axis ranges (which rangeselector needs to know which
  39839. // button is active). Can we break out its automargin step from its draw step?
  39840. Registry.getComponentMethod('rangeselector', 'draw')(gd);
  39841. };
  39842. exports.drawMarginPushers = function(gd) {
  39843. Registry.getComponentMethod('legend', 'draw')(gd);
  39844. Registry.getComponentMethod('rangeselector', 'draw')(gd);
  39845. Registry.getComponentMethod('sliders', 'draw')(gd);
  39846. Registry.getComponentMethod('updatemenus', 'draw')(gd);
  39847. };
  39848. },{"../components/color":50,"../components/drawing":75,"../components/modebar":113,"../components/titles":141,"../constants/alignment":148,"../lib":169,"../lib/clear_gl_canvases":157,"../plots/cartesian/autorange":213,"../plots/cartesian/axes":214,"../plots/cartesian/constraints":221,"../plots/plots":246,"../registry":259,"d3":16}],206:[function(_dereq_,module,exports){
  39849. /**
  39850. * Copyright 2012-2018, Plotly, Inc.
  39851. * All rights reserved.
  39852. *
  39853. * This source code is licensed under the MIT license found in the
  39854. * LICENSE file in the root directory of this source tree.
  39855. */
  39856. 'use strict';
  39857. var Lib = _dereq_('../lib');
  39858. var isPlainObject = Lib.isPlainObject;
  39859. var PlotSchema = _dereq_('./plot_schema');
  39860. var Plots = _dereq_('../plots/plots');
  39861. var plotAttributes = _dereq_('../plots/attributes');
  39862. var Template = _dereq_('./plot_template');
  39863. var dfltConfig = _dereq_('./plot_config');
  39864. /**
  39865. * Plotly.makeTemplate: create a template off an existing figure to reuse
  39866. * style attributes on other figures.
  39867. *
  39868. * Note: separated from the rest of templates because otherwise we get circular
  39869. * references due to PlotSchema.
  39870. *
  39871. * @param {object|DOM element} figure: The figure to base the template on
  39872. * should contain a trace array `figure.data`
  39873. * and a layout object `figure.layout`
  39874. * @returns {object} template: the extracted template - can then be used as
  39875. * `layout.template` in another figure.
  39876. */
  39877. exports.makeTemplate = function(figure) {
  39878. figure = Lib.extendDeep({_context: dfltConfig}, figure);
  39879. Plots.supplyDefaults(figure);
  39880. var data = figure.data || [];
  39881. var layout = figure.layout || {};
  39882. // copy over a few items to help follow the schema
  39883. layout._basePlotModules = figure._fullLayout._basePlotModules;
  39884. layout._modules = figure._fullLayout._modules;
  39885. var template = {
  39886. data: {},
  39887. layout: {}
  39888. };
  39889. /*
  39890. * Note: we do NOT validate template values, we just take what's in the
  39891. * user inputs data and layout, not the validated values in fullData and
  39892. * fullLayout. Even if we were to validate here, there's no guarantee that
  39893. * these values would still be valid when applied to a new figure, which
  39894. * may contain different trace modes, different axes, etc. So it's
  39895. * important that when applying a template we still validate the template
  39896. * values, rather than just using them as defaults.
  39897. */
  39898. data.forEach(function(trace) {
  39899. // TODO: What if no style info is extracted for this trace. We may
  39900. // not want an empty object as the null value.
  39901. // TODO: allow transforms to contribute to templates?
  39902. // as it stands they are ignored, which may be for the best...
  39903. var traceTemplate = {};
  39904. walkStyleKeys(trace, traceTemplate, getTraceInfo.bind(null, trace));
  39905. var traceType = Lib.coerce(trace, {}, plotAttributes, 'type');
  39906. var typeTemplates = template.data[traceType];
  39907. if(!typeTemplates) typeTemplates = template.data[traceType] = [];
  39908. typeTemplates.push(traceTemplate);
  39909. });
  39910. walkStyleKeys(layout, template.layout, getLayoutInfo.bind(null, layout));
  39911. /*
  39912. * Compose the new template with an existing one to the same effect
  39913. *
  39914. * NOTE: there's a possibility of slightly different behavior: if the plot
  39915. * has an invalid value and the old template has a valid value for the same
  39916. * attribute, the plot will use the old template value but this routine
  39917. * will pull the invalid value (resulting in the original default).
  39918. * In the general case it's not possible to solve this with a single value,
  39919. * since valid options can be context-dependent. It could be solved with
  39920. * a *list* of values, but that would be huge complexity for little gain.
  39921. */
  39922. delete template.layout.template;
  39923. var oldTemplate = layout.template;
  39924. if(isPlainObject(oldTemplate)) {
  39925. var oldLayoutTemplate = oldTemplate.layout;
  39926. var i, traceType, oldTypeTemplates, oldTypeLen, typeTemplates, typeLen;
  39927. if(isPlainObject(oldLayoutTemplate)) {
  39928. mergeTemplates(oldLayoutTemplate, template.layout);
  39929. }
  39930. var oldDataTemplate = oldTemplate.data;
  39931. if(isPlainObject(oldDataTemplate)) {
  39932. for(traceType in template.data) {
  39933. oldTypeTemplates = oldDataTemplate[traceType];
  39934. if(Array.isArray(oldTypeTemplates)) {
  39935. typeTemplates = template.data[traceType];
  39936. typeLen = typeTemplates.length;
  39937. oldTypeLen = oldTypeTemplates.length;
  39938. for(i = 0; i < typeLen; i++) {
  39939. mergeTemplates(oldTypeTemplates[i % oldTypeLen], typeTemplates[i]);
  39940. }
  39941. for(i = typeLen; i < oldTypeLen; i++) {
  39942. typeTemplates.push(Lib.extendDeep({}, oldTypeTemplates[i]));
  39943. }
  39944. }
  39945. }
  39946. for(traceType in oldDataTemplate) {
  39947. if(!(traceType in template.data)) {
  39948. template.data[traceType] = Lib.extendDeep([], oldDataTemplate[traceType]);
  39949. }
  39950. }
  39951. }
  39952. }
  39953. return template;
  39954. };
  39955. function mergeTemplates(oldTemplate, newTemplate) {
  39956. // we don't care about speed here, just make sure we have a totally
  39957. // distinct object from the previous template
  39958. oldTemplate = Lib.extendDeep({}, oldTemplate);
  39959. // sort keys so we always get annotationdefaults before annotations etc
  39960. // so arrayTemplater will work right
  39961. var oldKeys = Object.keys(oldTemplate).sort();
  39962. var i, j;
  39963. function mergeOne(oldVal, newVal, key) {
  39964. if(isPlainObject(newVal) && isPlainObject(oldVal)) {
  39965. mergeTemplates(oldVal, newVal);
  39966. }
  39967. else if(Array.isArray(newVal) && Array.isArray(oldVal)) {
  39968. // Note: omitted `inclusionAttr` from arrayTemplater here,
  39969. // it's irrelevant as we only want the resulting `_template`.
  39970. var templater = Template.arrayTemplater({_template: oldTemplate}, key);
  39971. for(j = 0; j < newVal.length; j++) {
  39972. var item = newVal[j];
  39973. var oldItem = templater.newItem(item)._template;
  39974. if(oldItem) mergeTemplates(oldItem, item);
  39975. }
  39976. var defaultItems = templater.defaultItems();
  39977. for(j = 0; j < defaultItems.length; j++) newVal.push(defaultItems[j]._template);
  39978. // templateitemname only applies to receiving plots
  39979. for(j = 0; j < newVal.length; j++) delete newVal[j].templateitemname;
  39980. }
  39981. }
  39982. for(i = 0; i < oldKeys.length; i++) {
  39983. var key = oldKeys[i];
  39984. var oldVal = oldTemplate[key];
  39985. if(key in newTemplate) {
  39986. mergeOne(oldVal, newTemplate[key], key);
  39987. }
  39988. else newTemplate[key] = oldVal;
  39989. // if this is a base key from the old template (eg xaxis), look for
  39990. // extended keys (eg xaxis2) in the new template to merge into
  39991. if(getBaseKey(key) === key) {
  39992. for(var key2 in newTemplate) {
  39993. var baseKey2 = getBaseKey(key2);
  39994. if(key2 !== baseKey2 && baseKey2 === key && !(key2 in oldTemplate)) {
  39995. mergeOne(oldVal, newTemplate[key2], key);
  39996. }
  39997. }
  39998. }
  39999. }
  40000. }
  40001. function getBaseKey(key) {
  40002. return key.replace(/[0-9]+$/, '');
  40003. }
  40004. function walkStyleKeys(parent, templateOut, getAttributeInfo, path, basePath) {
  40005. var pathAttr = basePath && getAttributeInfo(basePath);
  40006. for(var key in parent) {
  40007. var child = parent[key];
  40008. var nextPath = getNextPath(parent, key, path);
  40009. var nextBasePath = getNextPath(parent, key, basePath);
  40010. var attr = getAttributeInfo(nextBasePath);
  40011. if(!attr) {
  40012. var baseKey = getBaseKey(key);
  40013. if(baseKey !== key) {
  40014. nextBasePath = getNextPath(parent, baseKey, basePath);
  40015. attr = getAttributeInfo(nextBasePath);
  40016. }
  40017. }
  40018. // we'll get an attr if path starts with a valid part, then has an
  40019. // invalid ending. Make sure we got all the way to the end.
  40020. if(pathAttr && (pathAttr === attr)) continue;
  40021. if(!attr || attr._noTemplating ||
  40022. attr.valType === 'data_array' ||
  40023. (attr.arrayOk && Array.isArray(child))
  40024. ) {
  40025. continue;
  40026. }
  40027. if(!attr.valType && isPlainObject(child)) {
  40028. walkStyleKeys(child, templateOut, getAttributeInfo, nextPath, nextBasePath);
  40029. }
  40030. else if(attr._isLinkedToArray && Array.isArray(child)) {
  40031. var dfltDone = false;
  40032. var namedIndex = 0;
  40033. var usedNames = {};
  40034. for(var i = 0; i < child.length; i++) {
  40035. var item = child[i];
  40036. if(isPlainObject(item)) {
  40037. var name = item.name;
  40038. if(name) {
  40039. if(!usedNames[name]) {
  40040. // named array items: allow all attributes except data arrays
  40041. walkStyleKeys(item, templateOut, getAttributeInfo,
  40042. getNextPath(child, namedIndex, nextPath),
  40043. getNextPath(child, namedIndex, nextBasePath));
  40044. namedIndex++;
  40045. usedNames[name] = 1;
  40046. }
  40047. }
  40048. else if(!dfltDone) {
  40049. var dfltKey = Template.arrayDefaultKey(key);
  40050. var dfltPath = getNextPath(parent, dfltKey, path);
  40051. // getAttributeInfo will fail if we try to use dfltKey directly.
  40052. // Instead put this item into the next array element, then
  40053. // pull it out and move it to dfltKey.
  40054. var pathInArray = getNextPath(child, namedIndex, nextPath);
  40055. walkStyleKeys(item, templateOut, getAttributeInfo, pathInArray,
  40056. getNextPath(child, namedIndex, nextBasePath));
  40057. var itemPropInArray = Lib.nestedProperty(templateOut, pathInArray);
  40058. var dfltProp = Lib.nestedProperty(templateOut, dfltPath);
  40059. dfltProp.set(itemPropInArray.get());
  40060. itemPropInArray.set(null);
  40061. dfltDone = true;
  40062. }
  40063. }
  40064. }
  40065. }
  40066. else {
  40067. var templateProp = Lib.nestedProperty(templateOut, nextPath);
  40068. templateProp.set(child);
  40069. }
  40070. }
  40071. }
  40072. function getLayoutInfo(layout, path) {
  40073. return PlotSchema.getLayoutValObject(
  40074. layout, Lib.nestedProperty({}, path).parts
  40075. );
  40076. }
  40077. function getTraceInfo(trace, path) {
  40078. return PlotSchema.getTraceValObject(
  40079. trace, Lib.nestedProperty({}, path).parts
  40080. );
  40081. }
  40082. function getNextPath(parent, key, path) {
  40083. var nextPath;
  40084. if(!path) nextPath = key;
  40085. else if(Array.isArray(parent)) nextPath = path + '[' + key + ']';
  40086. else nextPath = path + '.' + key;
  40087. return nextPath;
  40088. }
  40089. /**
  40090. * validateTemplate: Test for consistency between the given figure and
  40091. * a template, either already included in the figure or given separately.
  40092. * Note that not every issue we identify here is necessarily a problem,
  40093. * it depends on what you're using the template for.
  40094. *
  40095. * @param {object|DOM element} figure: the plot, with {data, layout} members,
  40096. * to test the template against
  40097. * @param {Optional(object)} template: the template, with its own {data, layout},
  40098. * to test. If omitted, we will look for a template already attached as the
  40099. * plot's `layout.template` attribute.
  40100. *
  40101. * @returns {array} array of error objects each containing:
  40102. * - {string} code
  40103. * error code ('missing', 'unused', 'reused', 'noLayout', 'noData')
  40104. * - {string} msg
  40105. * a full readable description of the issue.
  40106. */
  40107. exports.validateTemplate = function(figureIn, template) {
  40108. var figure = Lib.extendDeep({}, {
  40109. _context: dfltConfig,
  40110. data: figureIn.data,
  40111. layout: figureIn.layout
  40112. });
  40113. var layout = figure.layout || {};
  40114. if(!isPlainObject(template)) template = layout.template || {};
  40115. var layoutTemplate = template.layout;
  40116. var dataTemplate = template.data;
  40117. var errorList = [];
  40118. figure.layout = layout;
  40119. figure.layout.template = template;
  40120. Plots.supplyDefaults(figure);
  40121. var fullLayout = figure._fullLayout;
  40122. var fullData = figure._fullData;
  40123. var layoutPaths = {};
  40124. function crawlLayoutForContainers(obj, paths) {
  40125. for(var key in obj) {
  40126. if(key.charAt(0) !== '_' && isPlainObject(obj[key])) {
  40127. var baseKey = getBaseKey(key);
  40128. var nextPaths = [];
  40129. var i;
  40130. for(i = 0; i < paths.length; i++) {
  40131. nextPaths.push(getNextPath(obj, key, paths[i]));
  40132. if(baseKey !== key) nextPaths.push(getNextPath(obj, baseKey, paths[i]));
  40133. }
  40134. for(i = 0; i < nextPaths.length; i++) {
  40135. layoutPaths[nextPaths[i]] = 1;
  40136. }
  40137. crawlLayoutForContainers(obj[key], nextPaths);
  40138. }
  40139. }
  40140. }
  40141. function crawlLayoutTemplateForContainers(obj, path) {
  40142. for(var key in obj) {
  40143. if(key.indexOf('defaults') === -1 && isPlainObject(obj[key])) {
  40144. var nextPath = getNextPath(obj, key, path);
  40145. if(layoutPaths[nextPath]) {
  40146. crawlLayoutTemplateForContainers(obj[key], nextPath);
  40147. }
  40148. else {
  40149. errorList.push({code: 'unused', path: nextPath});
  40150. }
  40151. }
  40152. }
  40153. }
  40154. if(!isPlainObject(layoutTemplate)) {
  40155. errorList.push({code: 'layout'});
  40156. }
  40157. else {
  40158. crawlLayoutForContainers(fullLayout, ['layout']);
  40159. crawlLayoutTemplateForContainers(layoutTemplate, 'layout');
  40160. }
  40161. if(!isPlainObject(dataTemplate)) {
  40162. errorList.push({code: 'data'});
  40163. }
  40164. else {
  40165. var typeCount = {};
  40166. var traceType;
  40167. for(var i = 0; i < fullData.length; i++) {
  40168. var fullTrace = fullData[i];
  40169. traceType = fullTrace.type;
  40170. typeCount[traceType] = (typeCount[traceType] || 0) + 1;
  40171. if(!fullTrace._fullInput._template) {
  40172. // this takes care of the case of traceType in the data but not
  40173. // the template
  40174. errorList.push({
  40175. code: 'missing',
  40176. index: fullTrace._fullInput.index,
  40177. traceType: traceType
  40178. });
  40179. }
  40180. }
  40181. for(traceType in dataTemplate) {
  40182. var templateCount = dataTemplate[traceType].length;
  40183. var dataCount = typeCount[traceType] || 0;
  40184. if(templateCount > dataCount) {
  40185. errorList.push({
  40186. code: 'unused',
  40187. traceType: traceType,
  40188. templateCount: templateCount,
  40189. dataCount: dataCount
  40190. });
  40191. }
  40192. else if(dataCount > templateCount) {
  40193. errorList.push({
  40194. code: 'reused',
  40195. traceType: traceType,
  40196. templateCount: templateCount,
  40197. dataCount: dataCount
  40198. });
  40199. }
  40200. }
  40201. }
  40202. // _template: false is when someone tried to modify an array item
  40203. // but there was no template with matching name
  40204. function crawlForMissingTemplates(obj, path) {
  40205. for(var key in obj) {
  40206. if(key.charAt(0) === '_') continue;
  40207. var val = obj[key];
  40208. var nextPath = getNextPath(obj, key, path);
  40209. if(isPlainObject(val)) {
  40210. if(Array.isArray(obj) && val._template === false && val.templateitemname) {
  40211. errorList.push({
  40212. code: 'missing',
  40213. path: nextPath,
  40214. templateitemname: val.templateitemname
  40215. });
  40216. }
  40217. crawlForMissingTemplates(val, nextPath);
  40218. }
  40219. else if(Array.isArray(val) && hasPlainObject(val)) {
  40220. crawlForMissingTemplates(val, nextPath);
  40221. }
  40222. }
  40223. }
  40224. crawlForMissingTemplates({data: fullData, layout: fullLayout}, '');
  40225. if(errorList.length) return errorList.map(format);
  40226. };
  40227. function hasPlainObject(arr) {
  40228. for(var i = 0; i < arr.length; i++) {
  40229. if(isPlainObject(arr[i])) return true;
  40230. }
  40231. }
  40232. function format(opts) {
  40233. var msg;
  40234. switch(opts.code) {
  40235. case 'data':
  40236. msg = 'The template has no key data.';
  40237. break;
  40238. case 'layout':
  40239. msg = 'The template has no key layout.';
  40240. break;
  40241. case 'missing':
  40242. if(opts.path) {
  40243. msg = 'There are no templates for item ' + opts.path +
  40244. ' with name ' + opts.templateitemname;
  40245. }
  40246. else {
  40247. msg = 'There are no templates for trace ' + opts.index +
  40248. ', of type ' + opts.traceType + '.';
  40249. }
  40250. break;
  40251. case 'unused':
  40252. if(opts.path) {
  40253. msg = 'The template item at ' + opts.path +
  40254. ' was not used in constructing the plot.';
  40255. }
  40256. else if(opts.dataCount) {
  40257. msg = 'Some of the templates of type ' + opts.traceType +
  40258. ' were not used. The template has ' + opts.templateCount +
  40259. ' traces, the data only has ' + opts.dataCount +
  40260. ' of this type.';
  40261. }
  40262. else {
  40263. msg = 'The template has ' + opts.templateCount +
  40264. ' traces of type ' + opts.traceType +
  40265. ' but there are none in the data.';
  40266. }
  40267. break;
  40268. case 'reused':
  40269. msg = 'Some of the templates of type ' + opts.traceType +
  40270. ' were used more than once. The template has ' +
  40271. opts.templateCount + ' traces, the data has ' +
  40272. opts.dataCount + ' of this type.';
  40273. break;
  40274. }
  40275. opts.msg = msg;
  40276. return opts;
  40277. }
  40278. },{"../lib":169,"../plots/attributes":211,"../plots/plots":246,"./plot_config":202,"./plot_schema":203,"./plot_template":204}],207:[function(_dereq_,module,exports){
  40279. /**
  40280. * Copyright 2012-2018, Plotly, Inc.
  40281. * All rights reserved.
  40282. *
  40283. * This source code is licensed under the MIT license found in the
  40284. * LICENSE file in the root directory of this source tree.
  40285. */
  40286. 'use strict';
  40287. var plotApi = _dereq_('./plot_api');
  40288. var Lib = _dereq_('../lib');
  40289. var helpers = _dereq_('../snapshot/helpers');
  40290. var toSVG = _dereq_('../snapshot/tosvg');
  40291. var svgToImg = _dereq_('../snapshot/svgtoimg');
  40292. var attrs = {
  40293. format: {
  40294. valType: 'enumerated',
  40295. values: ['png', 'jpeg', 'webp', 'svg'],
  40296. dflt: 'png',
  40297. },
  40298. width: {
  40299. valType: 'number',
  40300. min: 1,
  40301. },
  40302. height: {
  40303. valType: 'number',
  40304. min: 1,
  40305. },
  40306. scale: {
  40307. valType: 'number',
  40308. min: 0,
  40309. dflt: 1,
  40310. },
  40311. setBackground: {
  40312. valType: 'any',
  40313. dflt: false,
  40314. },
  40315. imageDataOnly: {
  40316. valType: 'boolean',
  40317. dflt: false,
  40318. }
  40319. };
  40320. var IMAGE_URL_PREFIX = /^data:image\/\w+;base64,/;
  40321. /** Plotly.toImage
  40322. *
  40323. * @param {object | string | HTML div} gd
  40324. * can either be a data/layout/config object
  40325. * or an existing graph <div>
  40326. * or an id to an existing graph <div>
  40327. * @param {object} opts (see above)
  40328. * @return {promise}
  40329. */
  40330. function toImage(gd, opts) {
  40331. opts = opts || {};
  40332. var data;
  40333. var layout;
  40334. var config;
  40335. if(Lib.isPlainObject(gd)) {
  40336. data = gd.data || [];
  40337. layout = gd.layout || {};
  40338. config = gd.config || {};
  40339. } else {
  40340. gd = Lib.getGraphDiv(gd);
  40341. data = Lib.extendDeep([], gd.data);
  40342. layout = Lib.extendDeep({}, gd.layout);
  40343. config = gd._context;
  40344. }
  40345. function isImpliedOrValid(attr) {
  40346. return !(attr in opts) || Lib.validate(opts[attr], attrs[attr]);
  40347. }
  40348. if(!isImpliedOrValid('width') || !isImpliedOrValid('height')) {
  40349. throw new Error('Height and width should be pixel values.');
  40350. }
  40351. if(!isImpliedOrValid('format')) {
  40352. throw new Error('Image format is not jpeg, png, svg or webp.');
  40353. }
  40354. var fullOpts = {};
  40355. function coerce(attr, dflt) {
  40356. return Lib.coerce(opts, fullOpts, attrs, attr, dflt);
  40357. }
  40358. var format = coerce('format');
  40359. var width = coerce('width');
  40360. var height = coerce('height');
  40361. var scale = coerce('scale');
  40362. var setBackground = coerce('setBackground');
  40363. var imageDataOnly = coerce('imageDataOnly');
  40364. // put the cloned div somewhere off screen before attaching to DOM
  40365. var clonedGd = document.createElement('div');
  40366. clonedGd.style.position = 'absolute';
  40367. clonedGd.style.left = '-5000px';
  40368. document.body.appendChild(clonedGd);
  40369. // extend layout with image options
  40370. var layoutImage = Lib.extendFlat({}, layout);
  40371. if(width) layoutImage.width = width;
  40372. if(height) layoutImage.height = height;
  40373. // extend config for static plot
  40374. var configImage = Lib.extendFlat({}, config, {
  40375. staticPlot: true,
  40376. setBackground: setBackground
  40377. });
  40378. var redrawFunc = helpers.getRedrawFunc(clonedGd);
  40379. function wait() {
  40380. return new Promise(function(resolve) {
  40381. setTimeout(resolve, helpers.getDelay(clonedGd._fullLayout));
  40382. });
  40383. }
  40384. function convert() {
  40385. return new Promise(function(resolve, reject) {
  40386. var svg = toSVG(clonedGd, format, scale);
  40387. var width = clonedGd._fullLayout.width;
  40388. var height = clonedGd._fullLayout.height;
  40389. plotApi.purge(clonedGd);
  40390. document.body.removeChild(clonedGd);
  40391. if(format === 'svg') {
  40392. if(imageDataOnly) {
  40393. return resolve(svg);
  40394. } else {
  40395. return resolve('data:image/svg+xml,' + encodeURIComponent(svg));
  40396. }
  40397. }
  40398. var canvas = document.createElement('canvas');
  40399. canvas.id = Lib.randstr();
  40400. svgToImg({
  40401. format: format,
  40402. width: width,
  40403. height: height,
  40404. scale: scale,
  40405. canvas: canvas,
  40406. svg: svg,
  40407. // ask svgToImg to return a Promise
  40408. // rather than EventEmitter
  40409. // leave EventEmitter for backward
  40410. // compatibility
  40411. promise: true
  40412. })
  40413. .then(resolve)
  40414. .catch(reject);
  40415. });
  40416. }
  40417. function urlToImageData(url) {
  40418. if(imageDataOnly) {
  40419. return url.replace(IMAGE_URL_PREFIX, '');
  40420. } else {
  40421. return url;
  40422. }
  40423. }
  40424. return new Promise(function(resolve, reject) {
  40425. plotApi.plot(clonedGd, data, layoutImage, configImage)
  40426. .then(redrawFunc)
  40427. .then(wait)
  40428. .then(convert)
  40429. .then(function(url) { resolve(urlToImageData(url)); })
  40430. .catch(function(err) { reject(err); });
  40431. });
  40432. }
  40433. module.exports = toImage;
  40434. },{"../lib":169,"../snapshot/helpers":263,"../snapshot/svgtoimg":265,"../snapshot/tosvg":267,"./plot_api":201}],208:[function(_dereq_,module,exports){
  40435. /**
  40436. * Copyright 2012-2018, Plotly, Inc.
  40437. * All rights reserved.
  40438. *
  40439. * This source code is licensed under the MIT license found in the
  40440. * LICENSE file in the root directory of this source tree.
  40441. */
  40442. 'use strict';
  40443. var Lib = _dereq_('../lib');
  40444. var Plots = _dereq_('../plots/plots');
  40445. var PlotSchema = _dereq_('./plot_schema');
  40446. var dfltConfig = _dereq_('./plot_config');
  40447. var isPlainObject = Lib.isPlainObject;
  40448. var isArray = Array.isArray;
  40449. var isArrayOrTypedArray = Lib.isArrayOrTypedArray;
  40450. /**
  40451. * Validate a data array and layout object.
  40452. *
  40453. * @param {array} data
  40454. * @param {object} layout
  40455. *
  40456. * @return {array} array of error objects each containing:
  40457. * - {string} code
  40458. * error code ('object', 'array', 'schema', 'unused', 'invisible' or 'value')
  40459. * - {string} container
  40460. * container where the error occurs ('data' or 'layout')
  40461. * - {number} trace
  40462. * trace index of the 'data' container where the error occurs
  40463. * - {array} path
  40464. * nested path to the key that causes the error
  40465. * - {string} astr
  40466. * attribute string variant of 'path' compatible with Plotly.restyle and
  40467. * Plotly.relayout.
  40468. * - {string} msg
  40469. * error message (shown in console in logger config argument is enable)
  40470. */
  40471. module.exports = function validate(data, layout) {
  40472. var schema = PlotSchema.get();
  40473. var errorList = [];
  40474. var gd = {_context: Lib.extendFlat({}, dfltConfig)};
  40475. var dataIn, layoutIn;
  40476. if(isArray(data)) {
  40477. gd.data = Lib.extendDeep([], data);
  40478. dataIn = data;
  40479. }
  40480. else {
  40481. gd.data = [];
  40482. dataIn = [];
  40483. errorList.push(format('array', 'data'));
  40484. }
  40485. if(isPlainObject(layout)) {
  40486. gd.layout = Lib.extendDeep({}, layout);
  40487. layoutIn = layout;
  40488. }
  40489. else {
  40490. gd.layout = {};
  40491. layoutIn = {};
  40492. if(arguments.length > 1) {
  40493. errorList.push(format('object', 'layout'));
  40494. }
  40495. }
  40496. // N.B. dataIn and layoutIn are in general not the same as
  40497. // gd.data and gd.layout after supplyDefaults as some attributes
  40498. // in gd.data and gd.layout (still) get mutated during this step.
  40499. Plots.supplyDefaults(gd);
  40500. var dataOut = gd._fullData,
  40501. len = dataIn.length;
  40502. for(var i = 0; i < len; i++) {
  40503. var traceIn = dataIn[i],
  40504. base = ['data', i];
  40505. if(!isPlainObject(traceIn)) {
  40506. errorList.push(format('object', base));
  40507. continue;
  40508. }
  40509. var traceOut = dataOut[i],
  40510. traceType = traceOut.type,
  40511. traceSchema = schema.traces[traceType].attributes;
  40512. // PlotSchema does something fancy with trace 'type', reset it here
  40513. // to make the trace schema compatible with Lib.validate.
  40514. traceSchema.type = {
  40515. valType: 'enumerated',
  40516. values: [traceType]
  40517. };
  40518. if(traceOut.visible === false && traceIn.visible !== false) {
  40519. errorList.push(format('invisible', base));
  40520. }
  40521. crawl(traceIn, traceOut, traceSchema, errorList, base);
  40522. var transformsIn = traceIn.transforms,
  40523. transformsOut = traceOut.transforms;
  40524. if(transformsIn) {
  40525. if(!isArray(transformsIn)) {
  40526. errorList.push(format('array', base, ['transforms']));
  40527. }
  40528. base.push('transforms');
  40529. for(var j = 0; j < transformsIn.length; j++) {
  40530. var path = ['transforms', j],
  40531. transformType = transformsIn[j].type;
  40532. if(!isPlainObject(transformsIn[j])) {
  40533. errorList.push(format('object', base, path));
  40534. continue;
  40535. }
  40536. var transformSchema = schema.transforms[transformType] ?
  40537. schema.transforms[transformType].attributes :
  40538. {};
  40539. // add 'type' to transform schema to validate the transform type
  40540. transformSchema.type = {
  40541. valType: 'enumerated',
  40542. values: Object.keys(schema.transforms)
  40543. };
  40544. crawl(transformsIn[j], transformsOut[j], transformSchema, errorList, base, path);
  40545. }
  40546. }
  40547. }
  40548. var layoutOut = gd._fullLayout,
  40549. layoutSchema = fillLayoutSchema(schema, dataOut);
  40550. crawl(layoutIn, layoutOut, layoutSchema, errorList, 'layout');
  40551. // return undefined if no validation errors were found
  40552. return (errorList.length === 0) ? void(0) : errorList;
  40553. };
  40554. function crawl(objIn, objOut, schema, list, base, path) {
  40555. path = path || [];
  40556. var keys = Object.keys(objIn);
  40557. for(var i = 0; i < keys.length; i++) {
  40558. var k = keys[i];
  40559. // transforms are handled separately
  40560. if(k === 'transforms') continue;
  40561. var p = path.slice();
  40562. p.push(k);
  40563. var valIn = objIn[k],
  40564. valOut = objOut[k];
  40565. var nestedSchema = getNestedSchema(schema, k);
  40566. var isInfoArray = (nestedSchema || {}).valType === 'info_array';
  40567. var isColorscale = (nestedSchema || {}).valType === 'colorscale';
  40568. var items = (nestedSchema || {}).items;
  40569. if(!isInSchema(schema, k)) {
  40570. list.push(format('schema', base, p));
  40571. }
  40572. else if(isPlainObject(valIn) && isPlainObject(valOut)) {
  40573. crawl(valIn, valOut, nestedSchema, list, base, p);
  40574. }
  40575. else if(isInfoArray && isArray(valIn)) {
  40576. if(valIn.length > valOut.length) {
  40577. list.push(format('unused', base, p.concat(valOut.length)));
  40578. }
  40579. var len = valOut.length;
  40580. var arrayItems = Array.isArray(items);
  40581. if(arrayItems) len = Math.min(len, items.length);
  40582. var m, n, item, valInPart, valOutPart;
  40583. if(nestedSchema.dimensions === 2) {
  40584. for(n = 0; n < len; n++) {
  40585. if(isArray(valIn[n])) {
  40586. if(valIn[n].length > valOut[n].length) {
  40587. list.push(format('unused', base, p.concat(n, valOut[n].length)));
  40588. }
  40589. var len2 = valOut[n].length;
  40590. for(m = 0; m < (arrayItems ? Math.min(len2, items[n].length) : len2); m++) {
  40591. item = arrayItems ? items[n][m] : items;
  40592. valInPart = valIn[n][m];
  40593. valOutPart = valOut[n][m];
  40594. if(!Lib.validate(valInPart, item)) {
  40595. list.push(format('value', base, p.concat(n, m), valInPart));
  40596. }
  40597. else if(valOutPart !== valInPart && valOutPart !== +valInPart) {
  40598. list.push(format('dynamic', base, p.concat(n, m), valInPart, valOutPart));
  40599. }
  40600. }
  40601. }
  40602. else {
  40603. list.push(format('array', base, p.concat(n), valIn[n]));
  40604. }
  40605. }
  40606. }
  40607. else {
  40608. for(n = 0; n < len; n++) {
  40609. item = arrayItems ? items[n] : items;
  40610. valInPart = valIn[n];
  40611. valOutPart = valOut[n];
  40612. if(!Lib.validate(valInPart, item)) {
  40613. list.push(format('value', base, p.concat(n), valInPart));
  40614. }
  40615. else if(valOutPart !== valInPart && valOutPart !== +valInPart) {
  40616. list.push(format('dynamic', base, p.concat(n), valInPart, valOutPart));
  40617. }
  40618. }
  40619. }
  40620. }
  40621. else if(nestedSchema.items && !isInfoArray && isArray(valIn)) {
  40622. var _nestedSchema = items[Object.keys(items)[0]],
  40623. indexList = [];
  40624. var j, _p;
  40625. // loop over valOut items while keeping track of their
  40626. // corresponding input container index (given by _index)
  40627. for(j = 0; j < valOut.length; j++) {
  40628. var _index = valOut[j]._index || j;
  40629. _p = p.slice();
  40630. _p.push(_index);
  40631. if(isPlainObject(valIn[_index]) && isPlainObject(valOut[j])) {
  40632. indexList.push(_index);
  40633. var valInj = valIn[_index];
  40634. var valOutj = valOut[j];
  40635. if(isPlainObject(valInj) && valInj.visible !== false && valOutj.visible === false) {
  40636. list.push(format('invisible', base, _p));
  40637. }
  40638. else crawl(valInj, valOutj, _nestedSchema, list, base, _p);
  40639. }
  40640. }
  40641. // loop over valIn to determine where it went wrong for some items
  40642. for(j = 0; j < valIn.length; j++) {
  40643. _p = p.slice();
  40644. _p.push(j);
  40645. if(!isPlainObject(valIn[j])) {
  40646. list.push(format('object', base, _p, valIn[j]));
  40647. }
  40648. else if(indexList.indexOf(j) === -1) {
  40649. list.push(format('unused', base, _p));
  40650. }
  40651. }
  40652. }
  40653. else if(!isPlainObject(valIn) && isPlainObject(valOut)) {
  40654. list.push(format('object', base, p, valIn));
  40655. }
  40656. else if(!isArrayOrTypedArray(valIn) && isArrayOrTypedArray(valOut) && !isInfoArray && !isColorscale) {
  40657. list.push(format('array', base, p, valIn));
  40658. }
  40659. else if(!(k in objOut)) {
  40660. list.push(format('unused', base, p, valIn));
  40661. }
  40662. else if(!Lib.validate(valIn, nestedSchema)) {
  40663. list.push(format('value', base, p, valIn));
  40664. }
  40665. else if(nestedSchema.valType === 'enumerated' &&
  40666. ((nestedSchema.coerceNumber && valIn !== +valOut) || valIn !== valOut)
  40667. ) {
  40668. list.push(format('dynamic', base, p, valIn, valOut));
  40669. }
  40670. }
  40671. return list;
  40672. }
  40673. // the 'full' layout schema depends on the traces types presents
  40674. function fillLayoutSchema(schema, dataOut) {
  40675. var layoutSchema = schema.layout.layoutAttributes;
  40676. for(var i = 0; i < dataOut.length; i++) {
  40677. var traceOut = dataOut[i];
  40678. var traceSchema = schema.traces[traceOut.type];
  40679. var traceLayoutAttr = traceSchema.layoutAttributes;
  40680. if(traceLayoutAttr) {
  40681. if(traceOut.subplot) {
  40682. Lib.extendFlat(layoutSchema[traceSchema.attributes.subplot.dflt], traceLayoutAttr);
  40683. } else {
  40684. Lib.extendFlat(layoutSchema, traceLayoutAttr);
  40685. }
  40686. }
  40687. }
  40688. return layoutSchema;
  40689. }
  40690. // validation error codes
  40691. var code2msgFunc = {
  40692. object: function(base, astr) {
  40693. var prefix;
  40694. if(base === 'layout' && astr === '') prefix = 'The layout argument';
  40695. else if(base[0] === 'data' && astr === '') {
  40696. prefix = 'Trace ' + base[1] + ' in the data argument';
  40697. }
  40698. else prefix = inBase(base) + 'key ' + astr;
  40699. return prefix + ' must be linked to an object container';
  40700. },
  40701. array: function(base, astr) {
  40702. var prefix;
  40703. if(base === 'data') prefix = 'The data argument';
  40704. else prefix = inBase(base) + 'key ' + astr;
  40705. return prefix + ' must be linked to an array container';
  40706. },
  40707. schema: function(base, astr) {
  40708. return inBase(base) + 'key ' + astr + ' is not part of the schema';
  40709. },
  40710. unused: function(base, astr, valIn) {
  40711. var target = isPlainObject(valIn) ? 'container' : 'key';
  40712. return inBase(base) + target + ' ' + astr + ' did not get coerced';
  40713. },
  40714. dynamic: function(base, astr, valIn, valOut) {
  40715. return [
  40716. inBase(base) + 'key',
  40717. astr,
  40718. '(set to \'' + valIn + '\')',
  40719. 'got reset to',
  40720. '\'' + valOut + '\'',
  40721. 'during defaults.'
  40722. ].join(' ');
  40723. },
  40724. invisible: function(base, astr) {
  40725. return (
  40726. astr ? (inBase(base) + 'item ' + astr) : ('Trace ' + base[1])
  40727. ) + ' got defaulted to be not visible';
  40728. },
  40729. value: function(base, astr, valIn) {
  40730. return [
  40731. inBase(base) + 'key ' + astr,
  40732. 'is set to an invalid value (' + valIn + ')'
  40733. ].join(' ');
  40734. }
  40735. };
  40736. function inBase(base) {
  40737. if(isArray(base)) return 'In data trace ' + base[1] + ', ';
  40738. return 'In ' + base + ', ';
  40739. }
  40740. function format(code, base, path, valIn, valOut) {
  40741. path = path || '';
  40742. var container, trace;
  40743. // container is either 'data' or 'layout
  40744. // trace is the trace index if 'data', null otherwise
  40745. if(isArray(base)) {
  40746. container = base[0];
  40747. trace = base[1];
  40748. }
  40749. else {
  40750. container = base;
  40751. trace = null;
  40752. }
  40753. var astr = convertPathToAttributeString(path);
  40754. var msg = code2msgFunc[code](base, astr, valIn, valOut);
  40755. // log to console if logger config option is enabled
  40756. Lib.log(msg);
  40757. return {
  40758. code: code,
  40759. container: container,
  40760. trace: trace,
  40761. path: path,
  40762. astr: astr,
  40763. msg: msg
  40764. };
  40765. }
  40766. function isInSchema(schema, key) {
  40767. var parts = splitKey(key),
  40768. keyMinusId = parts.keyMinusId,
  40769. id = parts.id;
  40770. if((keyMinusId in schema) && schema[keyMinusId]._isSubplotObj && id) {
  40771. return true;
  40772. }
  40773. return (key in schema);
  40774. }
  40775. function getNestedSchema(schema, key) {
  40776. if(key in schema) return schema[key];
  40777. var parts = splitKey(key);
  40778. return schema[parts.keyMinusId];
  40779. }
  40780. var idRegex = Lib.counterRegex('([a-z]+)');
  40781. function splitKey(key) {
  40782. var idMatch = key.match(idRegex);
  40783. return {
  40784. keyMinusId: idMatch && idMatch[1],
  40785. id: idMatch && idMatch[2]
  40786. };
  40787. }
  40788. function convertPathToAttributeString(path) {
  40789. if(!isArray(path)) return String(path);
  40790. var astr = '';
  40791. for(var i = 0; i < path.length; i++) {
  40792. var p = path[i];
  40793. if(typeof p === 'number') {
  40794. astr = astr.substr(0, astr.length - 1) + '[' + p + ']';
  40795. }
  40796. else {
  40797. astr += p;
  40798. }
  40799. if(i < path.length - 1) astr += '.';
  40800. }
  40801. return astr;
  40802. }
  40803. },{"../lib":169,"../plots/plots":246,"./plot_config":202,"./plot_schema":203}],209:[function(_dereq_,module,exports){
  40804. /**
  40805. * Copyright 2012-2018, Plotly, Inc.
  40806. * All rights reserved.
  40807. *
  40808. * This source code is licensed under the MIT license found in the
  40809. * LICENSE file in the root directory of this source tree.
  40810. */
  40811. 'use strict';
  40812. module.exports = {
  40813. mode: {
  40814. valType: 'enumerated',
  40815. dflt: 'afterall',
  40816. values: ['immediate', 'next', 'afterall'],
  40817. },
  40818. direction: {
  40819. valType: 'enumerated',
  40820. values: ['forward', 'reverse'],
  40821. dflt: 'forward',
  40822. },
  40823. fromcurrent: {
  40824. valType: 'boolean',
  40825. dflt: false,
  40826. },
  40827. frame: {
  40828. duration: {
  40829. valType: 'number',
  40830. min: 0,
  40831. dflt: 500,
  40832. },
  40833. redraw: {
  40834. valType: 'boolean',
  40835. dflt: true,
  40836. },
  40837. },
  40838. transition: {
  40839. duration: {
  40840. valType: 'number',
  40841. min: 0,
  40842. dflt: 500,
  40843. },
  40844. easing: {
  40845. valType: 'enumerated',
  40846. dflt: 'cubic-in-out',
  40847. values: [
  40848. 'linear',
  40849. 'quad',
  40850. 'cubic',
  40851. 'sin',
  40852. 'exp',
  40853. 'circle',
  40854. 'elastic',
  40855. 'back',
  40856. 'bounce',
  40857. 'linear-in',
  40858. 'quad-in',
  40859. 'cubic-in',
  40860. 'sin-in',
  40861. 'exp-in',
  40862. 'circle-in',
  40863. 'elastic-in',
  40864. 'back-in',
  40865. 'bounce-in',
  40866. 'linear-out',
  40867. 'quad-out',
  40868. 'cubic-out',
  40869. 'sin-out',
  40870. 'exp-out',
  40871. 'circle-out',
  40872. 'elastic-out',
  40873. 'back-out',
  40874. 'bounce-out',
  40875. 'linear-in-out',
  40876. 'quad-in-out',
  40877. 'cubic-in-out',
  40878. 'sin-in-out',
  40879. 'exp-in-out',
  40880. 'circle-in-out',
  40881. 'elastic-in-out',
  40882. 'back-in-out',
  40883. 'bounce-in-out'
  40884. ],
  40885. },
  40886. }
  40887. };
  40888. },{}],210:[function(_dereq_,module,exports){
  40889. /**
  40890. * Copyright 2012-2018, Plotly, Inc.
  40891. * All rights reserved.
  40892. *
  40893. * This source code is licensed under the MIT license found in the
  40894. * LICENSE file in the root directory of this source tree.
  40895. */
  40896. 'use strict';
  40897. var Lib = _dereq_('../lib');
  40898. var Template = _dereq_('../plot_api/plot_template');
  40899. /** Convenience wrapper for making array container logic DRY and consistent
  40900. *
  40901. * @param {object} parentObjIn
  40902. * user input object where the container in question is linked
  40903. * (i.e. either a user trace object or the user layout object)
  40904. *
  40905. * @param {object} parentObjOut
  40906. * full object where the coerced container will be linked
  40907. * (i.e. either a full trace object or the full layout object)
  40908. *
  40909. * @param {object} opts
  40910. * options object:
  40911. * - name {string}
  40912. * name of the key linking the container in question
  40913. * - inclusionAttr {string}
  40914. * name of the item attribute for inclusion/exclusion. Default is 'visible'.
  40915. * Since inclusion is true, use eg 'enabled' instead of 'disabled'.
  40916. * - handleItemDefaults {function}
  40917. * defaults method to be called on each item in the array container in question
  40918. *
  40919. * Its arguments are:
  40920. * - itemIn {object} item in user layout
  40921. * - itemOut {object} item in full layout
  40922. * - parentObj {object} (as in closure)
  40923. * - opts {object} (as in closure)
  40924. * N.B.
  40925. *
  40926. * - opts is passed to handleItemDefaults so it can also store
  40927. * links to supplementary data (e.g. fullData for layout components)
  40928. *
  40929. */
  40930. module.exports = function handleArrayContainerDefaults(parentObjIn, parentObjOut, opts) {
  40931. var name = opts.name;
  40932. var inclusionAttr = opts.inclusionAttr || 'visible';
  40933. var previousContOut = parentObjOut[name];
  40934. var contIn = Lib.isArrayOrTypedArray(parentObjIn[name]) ? parentObjIn[name] : [];
  40935. var contOut = parentObjOut[name] = [];
  40936. var templater = Template.arrayTemplater(parentObjOut, name, inclusionAttr);
  40937. var i, itemOut;
  40938. for(i = 0; i < contIn.length; i++) {
  40939. var itemIn = contIn[i];
  40940. if(!Lib.isPlainObject(itemIn)) {
  40941. itemOut = templater.newItem({});
  40942. itemOut[inclusionAttr] = false;
  40943. }
  40944. else {
  40945. itemOut = templater.newItem(itemIn);
  40946. }
  40947. itemOut._index = i;
  40948. if(itemOut[inclusionAttr] !== false) {
  40949. opts.handleItemDefaults(itemIn, itemOut, parentObjOut, opts);
  40950. }
  40951. contOut.push(itemOut);
  40952. }
  40953. var defaultItems = templater.defaultItems();
  40954. for(i = 0; i < defaultItems.length; i++) {
  40955. itemOut = defaultItems[i];
  40956. itemOut._index = contOut.length;
  40957. opts.handleItemDefaults({}, itemOut, parentObjOut, opts, {});
  40958. contOut.push(itemOut);
  40959. }
  40960. // in case this array gets its defaults rebuilt independent of the whole layout,
  40961. // relink the private keys just for this array.
  40962. if(Lib.isArrayOrTypedArray(previousContOut)) {
  40963. var len = Math.min(previousContOut.length, contOut.length);
  40964. for(i = 0; i < len; i++) {
  40965. Lib.relinkPrivateKeys(contOut[i], previousContOut[i]);
  40966. }
  40967. }
  40968. return contOut;
  40969. };
  40970. },{"../lib":169,"../plot_api/plot_template":204}],211:[function(_dereq_,module,exports){
  40971. /**
  40972. * Copyright 2012-2018, Plotly, Inc.
  40973. * All rights reserved.
  40974. *
  40975. * This source code is licensed under the MIT license found in the
  40976. * LICENSE file in the root directory of this source tree.
  40977. */
  40978. 'use strict';
  40979. var fxAttrs = _dereq_('../components/fx/attributes');
  40980. module.exports = {
  40981. type: {
  40982. valType: 'enumerated',
  40983. values: [], // listed dynamically
  40984. dflt: 'scatter',
  40985. editType: 'calc+clearAxisTypes',
  40986. _noTemplating: true // we handle this at a higher level
  40987. },
  40988. visible: {
  40989. valType: 'enumerated',
  40990. values: [true, false, 'legendonly'],
  40991. dflt: true,
  40992. editType: 'calc',
  40993. },
  40994. showlegend: {
  40995. valType: 'boolean',
  40996. dflt: true,
  40997. editType: 'style',
  40998. },
  40999. legendgroup: {
  41000. valType: 'string',
  41001. dflt: '',
  41002. editType: 'style',
  41003. },
  41004. opacity: {
  41005. valType: 'number',
  41006. min: 0,
  41007. max: 1,
  41008. dflt: 1,
  41009. editType: 'style',
  41010. },
  41011. name: {
  41012. valType: 'string',
  41013. editType: 'style',
  41014. },
  41015. uid: {
  41016. valType: 'string',
  41017. editType: 'plot'
  41018. },
  41019. ids: {
  41020. valType: 'data_array',
  41021. editType: 'calc',
  41022. },
  41023. customdata: {
  41024. valType: 'data_array',
  41025. editType: 'calc',
  41026. },
  41027. // N.B. these cannot be 'data_array' as they do not have the same length as
  41028. // other data arrays and arrayOk attributes in general
  41029. //
  41030. // Maybe add another valType:
  41031. // https://github.com/plotly/plotly.js/issues/1894
  41032. selectedpoints: {
  41033. valType: 'any',
  41034. editType: 'calc',
  41035. },
  41036. hoverinfo: {
  41037. valType: 'flaglist',
  41038. flags: ['x', 'y', 'z', 'text', 'name'],
  41039. extras: ['all', 'none', 'skip'],
  41040. arrayOk: true,
  41041. dflt: 'all',
  41042. editType: 'none',
  41043. },
  41044. hoverlabel: fxAttrs.hoverlabel,
  41045. stream: {
  41046. token: {
  41047. valType: 'string',
  41048. noBlank: true,
  41049. strict: true,
  41050. editType: 'calc',
  41051. },
  41052. maxpoints: {
  41053. valType: 'number',
  41054. min: 0,
  41055. max: 10000,
  41056. dflt: 500,
  41057. editType: 'calc',
  41058. },
  41059. editType: 'calc'
  41060. },
  41061. transforms: {
  41062. _isLinkedToArray: 'transform',
  41063. editType: 'calc',
  41064. }
  41065. };
  41066. },{"../components/fx/attributes":84}],212:[function(_dereq_,module,exports){
  41067. /**
  41068. * Copyright 2012-2018, Plotly, Inc.
  41069. * All rights reserved.
  41070. *
  41071. * This source code is licensed under the MIT license found in the
  41072. * LICENSE file in the root directory of this source tree.
  41073. */
  41074. 'use strict';
  41075. module.exports = {
  41076. xaxis: {
  41077. valType: 'subplotid',
  41078. dflt: 'x',
  41079. editType: 'calc+clearAxisTypes',
  41080. },
  41081. yaxis: {
  41082. valType: 'subplotid',
  41083. dflt: 'y',
  41084. editType: 'calc+clearAxisTypes',
  41085. }
  41086. };
  41087. },{}],213:[function(_dereq_,module,exports){
  41088. /**
  41089. * Copyright 2012-2018, Plotly, Inc.
  41090. * All rights reserved.
  41091. *
  41092. * This source code is licensed under the MIT license found in the
  41093. * LICENSE file in the root directory of this source tree.
  41094. */
  41095. 'use strict';
  41096. var isNumeric = _dereq_('fast-isnumeric');
  41097. var Lib = _dereq_('../../lib');
  41098. var FP_SAFE = _dereq_('../../constants/numerical').FP_SAFE;
  41099. module.exports = {
  41100. getAutoRange: getAutoRange,
  41101. makePadFn: makePadFn,
  41102. doAutoRange: doAutoRange,
  41103. findExtremes: findExtremes,
  41104. concatExtremes: concatExtremes
  41105. };
  41106. /**
  41107. * getAutoRange
  41108. *
  41109. * Collects all _extremes values corresponding to a given axis
  41110. * and computes its auto range.
  41111. *
  41112. * Note that getAutoRange uses return values from findExtremes.
  41113. *
  41114. * @param {object} gd:
  41115. * graph div object with filled-in fullData and fullLayout, in particular
  41116. * with filled-in '_extremes' containers:
  41117. * {
  41118. * val: calcdata value,
  41119. * pad: extra pixels beyond this value,
  41120. * extrapad: bool, does this point want 5% extra padding
  41121. * }
  41122. * @param {object} ax:
  41123. * full axis object, in particular with filled-in '_traceIndices'
  41124. * and '_annIndices' / '_shapeIndices' if applicable
  41125. * @return {array}
  41126. * an array of [min, max]. These are calcdata for log and category axes
  41127. * and data for linear and date axes.
  41128. *
  41129. * TODO: we want to change log to data as well, but it's hard to do this
  41130. * maintaining backward compatibility. category will always have to use calcdata
  41131. * though, because otherwise values between categories (or outside all categories)
  41132. * would be impossible.
  41133. */
  41134. function getAutoRange(gd, ax) {
  41135. var i, j;
  41136. var newRange = [];
  41137. var getPad = makePadFn(ax);
  41138. var extremes = concatExtremes(gd, ax);
  41139. var minArray = extremes.min;
  41140. var maxArray = extremes.max;
  41141. if(minArray.length === 0 || maxArray.length === 0) {
  41142. return Lib.simpleMap(ax.range, ax.r2l);
  41143. }
  41144. var minmin = minArray[0].val;
  41145. var maxmax = maxArray[0].val;
  41146. for(i = 1; i < minArray.length; i++) {
  41147. if(minmin !== maxmax) break;
  41148. minmin = Math.min(minmin, minArray[i].val);
  41149. }
  41150. for(i = 1; i < maxArray.length; i++) {
  41151. if(minmin !== maxmax) break;
  41152. maxmax = Math.max(maxmax, maxArray[i].val);
  41153. }
  41154. var axReverse = false;
  41155. if(ax.range) {
  41156. var rng = Lib.simpleMap(ax.range, ax.r2l);
  41157. axReverse = rng[1] < rng[0];
  41158. }
  41159. // one-time setting to easily reverse the axis
  41160. // when plotting from code
  41161. if(ax.autorange === 'reversed') {
  41162. axReverse = true;
  41163. ax.autorange = true;
  41164. }
  41165. var rangeMode = ax.rangemode;
  41166. var toZero = rangeMode === 'tozero';
  41167. var nonNegative = rangeMode === 'nonnegative';
  41168. var axLen = ax._length;
  41169. // don't allow padding to reduce the data to < 10% of the length
  41170. var minSpan = axLen / 10;
  41171. var mbest = 0;
  41172. var minpt, maxpt, minbest, maxbest, dp, dv;
  41173. for(i = 0; i < minArray.length; i++) {
  41174. minpt = minArray[i];
  41175. for(j = 0; j < maxArray.length; j++) {
  41176. maxpt = maxArray[j];
  41177. dv = maxpt.val - minpt.val;
  41178. if(dv > 0) {
  41179. dp = axLen - getPad(minpt) - getPad(maxpt);
  41180. if(dp > minSpan) {
  41181. if(dv / dp > mbest) {
  41182. minbest = minpt;
  41183. maxbest = maxpt;
  41184. mbest = dv / dp;
  41185. }
  41186. }
  41187. else if(dv / axLen > mbest) {
  41188. // in case of padding longer than the axis
  41189. // at least include the unpadded data values.
  41190. minbest = {val: minpt.val, pad: 0};
  41191. maxbest = {val: maxpt.val, pad: 0};
  41192. mbest = dv / axLen;
  41193. }
  41194. }
  41195. }
  41196. }
  41197. function getMaxPad(prev, pt) {
  41198. return Math.max(prev, getPad(pt));
  41199. }
  41200. if(minmin === maxmax) {
  41201. var lower = minmin - 1;
  41202. var upper = minmin + 1;
  41203. if(toZero) {
  41204. if(minmin === 0) {
  41205. // The only value we have on this axis is 0, and we want to
  41206. // autorange so zero is one end.
  41207. // In principle this could be [0, 1] or [-1, 0] but usually
  41208. // 'tozero' pins 0 to the low end, so follow that.
  41209. newRange = [0, 1];
  41210. }
  41211. else {
  41212. var maxPad = (minmin > 0 ? maxArray : minArray).reduce(getMaxPad, 0);
  41213. // we're pushing a single value away from the edge due to its
  41214. // padding, with the other end clamped at zero
  41215. // 0.5 means don't push it farther than the center.
  41216. var rangeEnd = minmin / (1 - Math.min(0.5, maxPad / axLen));
  41217. newRange = minmin > 0 ? [0, rangeEnd] : [rangeEnd, 0];
  41218. }
  41219. } else if(nonNegative) {
  41220. newRange = [Math.max(0, lower), Math.max(1, upper)];
  41221. } else {
  41222. newRange = [lower, upper];
  41223. }
  41224. }
  41225. else {
  41226. if(toZero) {
  41227. if(minbest.val >= 0) {
  41228. minbest = {val: 0, pad: 0};
  41229. }
  41230. if(maxbest.val <= 0) {
  41231. maxbest = {val: 0, pad: 0};
  41232. }
  41233. }
  41234. else if(nonNegative) {
  41235. if(minbest.val - mbest * getPad(minbest) < 0) {
  41236. minbest = {val: 0, pad: 0};
  41237. }
  41238. if(maxbest.val <= 0) {
  41239. maxbest = {val: 1, pad: 0};
  41240. }
  41241. }
  41242. // in case it changed again...
  41243. mbest = (maxbest.val - minbest.val) /
  41244. (axLen - getPad(minbest) - getPad(maxbest));
  41245. newRange = [
  41246. minbest.val - mbest * getPad(minbest),
  41247. maxbest.val + mbest * getPad(maxbest)
  41248. ];
  41249. }
  41250. // maintain reversal
  41251. if(axReverse) newRange.reverse();
  41252. return Lib.simpleMap(newRange, ax.l2r || Number);
  41253. }
  41254. /*
  41255. * calculate the pixel padding for ax._min and ax._max entries with
  41256. * optional extrapad as 5% of the total axis length
  41257. */
  41258. function makePadFn(ax) {
  41259. // 5% padding for points that specify extrapad: true
  41260. var extrappad = ax._length / 20;
  41261. // domain-constrained axes: base extrappad on the unconstrained
  41262. // domain so it's consistent as the domain changes
  41263. if((ax.constrain === 'domain') && ax._inputDomain) {
  41264. extrappad *= (ax._inputDomain[1] - ax._inputDomain[0]) /
  41265. (ax.domain[1] - ax.domain[0]);
  41266. }
  41267. return function getPad(pt) { return pt.pad + (pt.extrapad ? extrappad : 0); };
  41268. }
  41269. function concatExtremes(gd, ax) {
  41270. var axId = ax._id;
  41271. var fullData = gd._fullData;
  41272. var fullLayout = gd._fullLayout;
  41273. var minArray = [];
  41274. var maxArray = [];
  41275. var i, j, d;
  41276. function _concat(cont, indices) {
  41277. for(i = 0; i < indices.length; i++) {
  41278. var item = cont[indices[i]];
  41279. var extremes = (item._extremes || {})[axId];
  41280. if(item.visible === true && extremes) {
  41281. for(j = 0; j < extremes.min.length; j++) {
  41282. d = extremes.min[j];
  41283. collapseMinArray(minArray, d.val, d.pad, {extrapad: d.extrapad});
  41284. }
  41285. for(j = 0; j < extremes.max.length; j++) {
  41286. d = extremes.max[j];
  41287. collapseMaxArray(maxArray, d.val, d.pad, {extrapad: d.extrapad});
  41288. }
  41289. }
  41290. }
  41291. }
  41292. _concat(fullData, ax._traceIndices);
  41293. _concat(fullLayout.annotations || [], ax._annIndices || []);
  41294. _concat(fullLayout.shapes || [], ax._shapeIndices || []);
  41295. return {min: minArray, max: maxArray};
  41296. }
  41297. function doAutoRange(gd, ax) {
  41298. if(!ax._length) ax.setScale();
  41299. var axIn;
  41300. if(ax.autorange) {
  41301. ax.range = getAutoRange(gd, ax);
  41302. ax._r = ax.range.slice();
  41303. ax._rl = Lib.simpleMap(ax._r, ax.r2l);
  41304. // doAutoRange will get called on fullLayout,
  41305. // but we want to report its results back to layout
  41306. axIn = ax._input;
  41307. axIn.range = ax.range.slice();
  41308. axIn.autorange = ax.autorange;
  41309. }
  41310. if(ax._anchorAxis && ax._anchorAxis.rangeslider) {
  41311. var axeRangeOpts = ax._anchorAxis.rangeslider[ax._name];
  41312. if(axeRangeOpts) {
  41313. if(axeRangeOpts.rangemode === 'auto') {
  41314. axeRangeOpts.range = getAutoRange(gd, ax);
  41315. }
  41316. }
  41317. axIn = ax._anchorAxis._input;
  41318. axIn.rangeslider[ax._name] = Lib.extendFlat({}, axeRangeOpts);
  41319. }
  41320. }
  41321. /**
  41322. * findExtremes
  41323. *
  41324. * Find min/max extremes of an array of coordinates on a given axis.
  41325. *
  41326. * Note that findExtremes is called during `calc`, when we don't yet know the axis
  41327. * length; all the inputs should be based solely on the trace data, nothing
  41328. * about the axis layout.
  41329. *
  41330. * Note that `ppad` and `vpad` as well as their asymmetric variants refer to
  41331. * the before and after padding of the passed `data` array, not to the whole axis.
  41332. *
  41333. * @param {object} ax: full axis object
  41334. * relies on
  41335. * - ax.type
  41336. * - ax._m (just its sign)
  41337. * - ax.d2l
  41338. * @param {array} data:
  41339. * array of numbers (i.e. already run though ax.d2c)
  41340. * @param {object} options:
  41341. * available keys are:
  41342. * vpad: (number or number array) pad values (data value +-vpad)
  41343. * ppad: (number or number array) pad pixels (pixel location +-ppad)
  41344. * ppadplus, ppadminus, vpadplus, vpadminus:
  41345. * separate padding for each side, overrides symmetric
  41346. * padded: (boolean) add 5% padding to both ends
  41347. * (unless one end is overridden by tozero)
  41348. * tozero: (boolean) make sure to include zero if axis is linear,
  41349. * and make it a tight bound if possible
  41350. *
  41351. * @return {object}
  41352. * - min {array of objects}
  41353. * - max {array of objects}
  41354. * each object item has fields:
  41355. * - val {number}
  41356. * - pad {number}
  41357. * - extrappad {number}
  41358. */
  41359. function findExtremes(ax, data, options) {
  41360. if(!options) options = {};
  41361. if(!ax._m) ax.setScale();
  41362. var minArray = [];
  41363. var maxArray = [];
  41364. var len = data.length;
  41365. var extrapad = options.padded || false;
  41366. var tozero = options.tozero && (ax.type === 'linear' || ax.type === '-');
  41367. var isLog = ax.type === 'log';
  41368. var hasArrayOption = false;
  41369. var i, v, di, dmin, dmax, ppadiplus, ppadiminus, vmin, vmax;
  41370. function makePadAccessor(item) {
  41371. if(Array.isArray(item)) {
  41372. hasArrayOption = true;
  41373. return function(i) { return Math.max(Number(item[i]||0), 0); };
  41374. }
  41375. else {
  41376. var v = Math.max(Number(item||0), 0);
  41377. return function() { return v; };
  41378. }
  41379. }
  41380. var ppadplus = makePadAccessor((ax._m > 0 ?
  41381. options.ppadplus : options.ppadminus) || options.ppad || 0);
  41382. var ppadminus = makePadAccessor((ax._m > 0 ?
  41383. options.ppadminus : options.ppadplus) || options.ppad || 0);
  41384. var vpadplus = makePadAccessor(options.vpadplus || options.vpad);
  41385. var vpadminus = makePadAccessor(options.vpadminus || options.vpad);
  41386. if(!hasArrayOption) {
  41387. // with no arrays other than `data` we don't need to consider
  41388. // every point, only the extreme data points
  41389. vmin = Infinity;
  41390. vmax = -Infinity;
  41391. if(isLog) {
  41392. for(i = 0; i < len; i++) {
  41393. v = data[i];
  41394. // data is not linearized yet so we still have to filter out negative logs
  41395. if(v < vmin && v > 0) vmin = v;
  41396. if(v > vmax && v < FP_SAFE) vmax = v;
  41397. }
  41398. } else {
  41399. for(i = 0; i < len; i++) {
  41400. v = data[i];
  41401. if(v < vmin && v > -FP_SAFE) vmin = v;
  41402. if(v > vmax && v < FP_SAFE) vmax = v;
  41403. }
  41404. }
  41405. data = [vmin, vmax];
  41406. len = 2;
  41407. }
  41408. var collapseOpts = {tozero: tozero, extrapad: extrapad};
  41409. function addItem(i) {
  41410. di = data[i];
  41411. if(!isNumeric(di)) return;
  41412. ppadiplus = ppadplus(i);
  41413. ppadiminus = ppadminus(i);
  41414. vmin = di - vpadminus(i);
  41415. vmax = di + vpadplus(i);
  41416. // special case for log axes: if vpad makes this object span
  41417. // more than an order of mag, clip it to one order. This is so
  41418. // we don't have non-positive errors or absurdly large lower
  41419. // range due to rounding errors
  41420. if(isLog && vmin < vmax / 10) vmin = vmax / 10;
  41421. dmin = ax.c2l(vmin);
  41422. dmax = ax.c2l(vmax);
  41423. if(tozero) {
  41424. dmin = Math.min(0, dmin);
  41425. dmax = Math.max(0, dmax);
  41426. }
  41427. if(goodNumber(dmin)) {
  41428. collapseMinArray(minArray, dmin, ppadiminus, collapseOpts);
  41429. }
  41430. if(goodNumber(dmax)) {
  41431. collapseMaxArray(maxArray, dmax, ppadiplus, collapseOpts);
  41432. }
  41433. }
  41434. // For efficiency covering monotonic or near-monotonic data,
  41435. // check a few points at both ends first and then sweep
  41436. // through the middle
  41437. var iMax = Math.min(6, len);
  41438. for(i = 0; i < iMax; i++) addItem(i);
  41439. for(i = len - 1; i >= iMax; i--) addItem(i);
  41440. return {min: minArray, max: maxArray};
  41441. }
  41442. function collapseMinArray(array, newVal, newPad, opts) {
  41443. collapseArray(array, newVal, newPad, opts, lessOrEqual);
  41444. }
  41445. function collapseMaxArray(array, newVal, newPad, opts) {
  41446. collapseArray(array, newVal, newPad, opts, greaterOrEqual);
  41447. }
  41448. /**
  41449. * collapseArray
  41450. *
  41451. * Takes items from 'array' and compares them to 'newVal', 'newPad'.
  41452. *
  41453. * @param {array} array:
  41454. * current set of min or max extremes
  41455. * @param {number} newVal:
  41456. * new value to compare against
  41457. * @param {number} newPad:
  41458. * pad value associated with 'newVal'
  41459. * @param {object} opts:
  41460. * - tozero {boolean}
  41461. * - extrapad {number}
  41462. * @param {function} atLeastAsExtreme:
  41463. * comparison function, use
  41464. * - lessOrEqual for min 'array' and
  41465. * - greaterOrEqual for max 'array'
  41466. *
  41467. * In practice, 'array' is either
  41468. * - 'extremes[ax._id].min' or
  41469. * - 'extremes[ax._id].max
  41470. * found in traces and layout items that affect autorange.
  41471. *
  41472. * Since we don't yet know the relationship between pixels and values
  41473. * (that's what we're trying to figure out!) AND we don't yet know how
  41474. * many pixels `extrapad` represents (it's going to be 5% of the length,
  41475. * but we don't want to have to redo calc just because length changed)
  41476. * two point must satisfy three criteria simultaneously for one to supersede the other:
  41477. * - at least as extreme a `val`
  41478. * - at least as big a `pad`
  41479. * - an unpadded point cannot supersede a padded point, but any other combination can
  41480. *
  41481. * Then:
  41482. * - If the item supersedes the new point, set includeThis false
  41483. * - If the new pt supersedes the item, delete it from 'array'
  41484. */
  41485. function collapseArray(array, newVal, newPad, opts, atLeastAsExtreme) {
  41486. var tozero = opts.tozero;
  41487. var extrapad = opts.extrapad;
  41488. var includeThis = true;
  41489. for(var j = 0; j < array.length && includeThis; j++) {
  41490. var v = array[j];
  41491. if(atLeastAsExtreme(v.val, newVal) && v.pad >= newPad && (v.extrapad || !extrapad)) {
  41492. includeThis = false;
  41493. break;
  41494. } else if(atLeastAsExtreme(newVal, v.val) && v.pad <= newPad && (extrapad || !v.extrapad)) {
  41495. array.splice(j, 1);
  41496. j--;
  41497. }
  41498. }
  41499. if(includeThis) {
  41500. var clipAtZero = (tozero && newVal === 0);
  41501. array.push({
  41502. val: newVal,
  41503. pad: clipAtZero ? 0 : newPad,
  41504. extrapad: clipAtZero ? false : extrapad
  41505. });
  41506. }
  41507. }
  41508. // In order to stop overflow errors, don't consider points
  41509. // too close to the limits of js floating point
  41510. function goodNumber(v) {
  41511. return isNumeric(v) && Math.abs(v) < FP_SAFE;
  41512. }
  41513. function lessOrEqual(v0, v1) { return v0 <= v1; }
  41514. function greaterOrEqual(v0, v1) { return v0 >= v1; }
  41515. },{"../../constants/numerical":151,"../../lib":169,"fast-isnumeric":18}],214:[function(_dereq_,module,exports){
  41516. /**
  41517. * Copyright 2012-2018, Plotly, Inc.
  41518. * All rights reserved.
  41519. *
  41520. * This source code is licensed under the MIT license found in the
  41521. * LICENSE file in the root directory of this source tree.
  41522. */
  41523. 'use strict';
  41524. var d3 = _dereq_('d3');
  41525. var isNumeric = _dereq_('fast-isnumeric');
  41526. var Plots = _dereq_('../../plots/plots');
  41527. var Registry = _dereq_('../../registry');
  41528. var Lib = _dereq_('../../lib');
  41529. var svgTextUtils = _dereq_('../../lib/svg_text_utils');
  41530. var Titles = _dereq_('../../components/titles');
  41531. var Color = _dereq_('../../components/color');
  41532. var Drawing = _dereq_('../../components/drawing');
  41533. var axAttrs = _dereq_('./layout_attributes');
  41534. var constants = _dereq_('../../constants/numerical');
  41535. var ONEAVGYEAR = constants.ONEAVGYEAR;
  41536. var ONEAVGMONTH = constants.ONEAVGMONTH;
  41537. var ONEDAY = constants.ONEDAY;
  41538. var ONEHOUR = constants.ONEHOUR;
  41539. var ONEMIN = constants.ONEMIN;
  41540. var ONESEC = constants.ONESEC;
  41541. var MINUS_SIGN = constants.MINUS_SIGN;
  41542. var BADNUM = constants.BADNUM;
  41543. var MID_SHIFT = _dereq_('../../constants/alignment').MID_SHIFT;
  41544. var LINE_SPACING = _dereq_('../../constants/alignment').LINE_SPACING;
  41545. var axes = module.exports = {};
  41546. axes.setConvert = _dereq_('./set_convert');
  41547. var autoType = _dereq_('./axis_autotype');
  41548. var axisIds = _dereq_('./axis_ids');
  41549. axes.id2name = axisIds.id2name;
  41550. axes.name2id = axisIds.name2id;
  41551. axes.cleanId = axisIds.cleanId;
  41552. axes.list = axisIds.list;
  41553. axes.listIds = axisIds.listIds;
  41554. axes.getFromId = axisIds.getFromId;
  41555. axes.getFromTrace = axisIds.getFromTrace;
  41556. var autorange = _dereq_('./autorange');
  41557. axes.getAutoRange = autorange.getAutoRange;
  41558. axes.findExtremes = autorange.findExtremes;
  41559. /*
  41560. * find the list of possible axes to reference with an xref or yref attribute
  41561. * and coerce it to that list
  41562. *
  41563. * attr: the attribute we're generating a reference for. Should end in 'x' or 'y'
  41564. * but can be prefixed, like 'ax' for annotation's arrow x
  41565. * dflt: the default to coerce to, or blank to use the first axis (falling back on
  41566. * extraOption if there is no axis)
  41567. * extraOption: aside from existing axes with this letter, what non-axis value is allowed?
  41568. * Only required if it's different from `dflt`
  41569. */
  41570. axes.coerceRef = function(containerIn, containerOut, gd, attr, dflt, extraOption) {
  41571. var axLetter = attr.charAt(attr.length - 1);
  41572. var axlist = gd._fullLayout._subplots[axLetter + 'axis'];
  41573. var refAttr = attr + 'ref';
  41574. var attrDef = {};
  41575. if(!dflt) dflt = axlist[0] || extraOption;
  41576. if(!extraOption) extraOption = dflt;
  41577. // data-ref annotations are not supported in gl2d yet
  41578. attrDef[refAttr] = {
  41579. valType: 'enumerated',
  41580. values: axlist.concat(extraOption ? [extraOption] : []),
  41581. dflt: dflt
  41582. };
  41583. // xref, yref
  41584. return Lib.coerce(containerIn, containerOut, attrDef, refAttr);
  41585. };
  41586. /*
  41587. * coerce position attributes (range-type) that can be either on axes or absolute
  41588. * (paper or pixel) referenced. The biggest complication here is that we don't know
  41589. * before looking at the axis whether the value must be a number or not (it may be
  41590. * a date string), so we can't use the regular valType='number' machinery
  41591. *
  41592. * axRef (string): the axis this position is referenced to, or:
  41593. * paper: fraction of the plot area
  41594. * pixel: pixels relative to some starting position
  41595. * attr (string): the attribute in containerOut we are coercing
  41596. * dflt (number): the default position, as a fraction or pixels. If the attribute
  41597. * is to be axis-referenced, this will be converted to an axis data value
  41598. *
  41599. * Also cleans the values, since the attribute definition itself has to say
  41600. * valType: 'any' to handle date axes. This allows us to accept:
  41601. * - for category axes: category names, and convert them here into serial numbers.
  41602. * Note that this will NOT work for axis range endpoints, because we don't know
  41603. * the category list yet (it's set by ax.makeCalcdata during calc)
  41604. * but it works for component (note, shape, images) positions.
  41605. * - for date axes: JS Dates or milliseconds, and convert to date strings
  41606. * - for other types: coerce them to numbers
  41607. */
  41608. axes.coercePosition = function(containerOut, gd, coerce, axRef, attr, dflt) {
  41609. var cleanPos, pos;
  41610. if(axRef === 'paper' || axRef === 'pixel') {
  41611. cleanPos = Lib.ensureNumber;
  41612. pos = coerce(attr, dflt);
  41613. } else {
  41614. var ax = axes.getFromId(gd, axRef);
  41615. dflt = ax.fraction2r(dflt);
  41616. pos = coerce(attr, dflt);
  41617. cleanPos = ax.cleanPos;
  41618. }
  41619. containerOut[attr] = cleanPos(pos);
  41620. };
  41621. axes.cleanPosition = function(pos, gd, axRef) {
  41622. var cleanPos = (axRef === 'paper' || axRef === 'pixel') ?
  41623. Lib.ensureNumber :
  41624. axes.getFromId(gd, axRef).cleanPos;
  41625. return cleanPos(pos);
  41626. };
  41627. var getDataConversions = axes.getDataConversions = function(gd, trace, target, targetArray) {
  41628. var ax;
  41629. // If target points to an axis, use the type we already have for that
  41630. // axis to find the data type. Otherwise use the values to autotype.
  41631. var d2cTarget = (target === 'x' || target === 'y' || target === 'z') ?
  41632. target :
  41633. targetArray;
  41634. // In the case of an array target, make a mock data array
  41635. // and call supplyDefaults to the data type and
  41636. // setup the data-to-calc method.
  41637. if(Array.isArray(d2cTarget)) {
  41638. ax = {
  41639. type: autoType(targetArray),
  41640. _categories: []
  41641. };
  41642. axes.setConvert(ax);
  41643. // build up ax._categories (usually done during ax.makeCalcdata()
  41644. if(ax.type === 'category') {
  41645. for(var i = 0; i < targetArray.length; i++) {
  41646. ax.d2c(targetArray[i]);
  41647. }
  41648. }
  41649. } else {
  41650. ax = axes.getFromTrace(gd, trace, d2cTarget);
  41651. }
  41652. // if 'target' has corresponding axis
  41653. // -> use setConvert method
  41654. if(ax) return {d2c: ax.d2c, c2d: ax.c2d};
  41655. // special case for 'ids'
  41656. // -> cast to String
  41657. if(d2cTarget === 'ids') return {d2c: toString, c2d: toString};
  41658. // otherwise (e.g. numeric-array of 'marker.color' or 'marker.size')
  41659. // -> cast to Number
  41660. return {d2c: toNum, c2d: toNum};
  41661. };
  41662. function toNum(v) { return +v; }
  41663. function toString(v) { return String(v); }
  41664. axes.getDataToCoordFunc = function(gd, trace, target, targetArray) {
  41665. return getDataConversions(gd, trace, target, targetArray).d2c;
  41666. };
  41667. // get counteraxis letter for this axis (name or id)
  41668. // this can also be used as the id for default counter axis
  41669. axes.counterLetter = function(id) {
  41670. var axLetter = id.charAt(0);
  41671. if(axLetter === 'x') return 'y';
  41672. if(axLetter === 'y') return 'x';
  41673. };
  41674. // incorporate a new minimum difference and first tick into
  41675. // forced
  41676. // note that _forceTick0 is linearized, so needs to be turned into
  41677. // a range value for setting tick0
  41678. axes.minDtick = function(ax, newDiff, newFirst, allow) {
  41679. // doesn't make sense to do forced min dTick on log or category axes,
  41680. // and the plot itself may decide to cancel (ie non-grouped bars)
  41681. if(['log', 'category'].indexOf(ax.type) !== -1 || !allow) {
  41682. ax._minDtick = 0;
  41683. }
  41684. // undefined means there's nothing there yet
  41685. else if(ax._minDtick === undefined) {
  41686. ax._minDtick = newDiff;
  41687. ax._forceTick0 = newFirst;
  41688. }
  41689. else if(ax._minDtick) {
  41690. // existing minDtick is an integer multiple of newDiff
  41691. // (within rounding err)
  41692. // and forceTick0 can be shifted to newFirst
  41693. if((ax._minDtick / newDiff + 1e-6) % 1 < 2e-6 &&
  41694. (((newFirst - ax._forceTick0) / newDiff % 1) +
  41695. 1.000001) % 1 < 2e-6) {
  41696. ax._minDtick = newDiff;
  41697. ax._forceTick0 = newFirst;
  41698. }
  41699. // if the converse is true (newDiff is a multiple of minDtick and
  41700. // newFirst can be shifted to forceTick0) then do nothing - same
  41701. // forcing stands. Otherwise, cancel forced minimum
  41702. else if((newDiff / ax._minDtick + 1e-6) % 1 > 2e-6 ||
  41703. (((newFirst - ax._forceTick0) / ax._minDtick % 1) +
  41704. 1.000001) % 1 > 2e-6) {
  41705. ax._minDtick = 0;
  41706. }
  41707. }
  41708. };
  41709. // save a copy of the initial axis ranges in fullLayout
  41710. // use them in mode bar and dblclick events
  41711. axes.saveRangeInitial = function(gd, overwrite) {
  41712. var axList = axes.list(gd, '', true),
  41713. hasOneAxisChanged = false;
  41714. for(var i = 0; i < axList.length; i++) {
  41715. var ax = axList[i];
  41716. var isNew = (ax._rangeInitial === undefined);
  41717. var hasChanged = (
  41718. isNew || !(
  41719. ax.range[0] === ax._rangeInitial[0] &&
  41720. ax.range[1] === ax._rangeInitial[1]
  41721. )
  41722. );
  41723. if((isNew && ax.autorange === false) || (overwrite && hasChanged)) {
  41724. ax._rangeInitial = ax.range.slice();
  41725. hasOneAxisChanged = true;
  41726. }
  41727. }
  41728. return hasOneAxisChanged;
  41729. };
  41730. // save a copy of the initial spike visibility
  41731. axes.saveShowSpikeInitial = function(gd, overwrite) {
  41732. var axList = axes.list(gd, '', true),
  41733. hasOneAxisChanged = false,
  41734. allSpikesEnabled = 'on';
  41735. for(var i = 0; i < axList.length; i++) {
  41736. var ax = axList[i];
  41737. var isNew = (ax._showSpikeInitial === undefined);
  41738. var hasChanged = (
  41739. isNew || !(
  41740. ax.showspikes === ax._showspikes
  41741. )
  41742. );
  41743. if((isNew) || (overwrite && hasChanged)) {
  41744. ax._showSpikeInitial = ax.showspikes;
  41745. hasOneAxisChanged = true;
  41746. }
  41747. if(allSpikesEnabled === 'on' && !ax.showspikes) {
  41748. allSpikesEnabled = 'off';
  41749. }
  41750. }
  41751. gd._fullLayout._cartesianSpikesEnabled = allSpikesEnabled;
  41752. return hasOneAxisChanged;
  41753. };
  41754. axes.autoBin = function(data, ax, nbins, is2d, calendar) {
  41755. var dataMin = Lib.aggNums(Math.min, null, data),
  41756. dataMax = Lib.aggNums(Math.max, null, data);
  41757. if(!calendar) calendar = ax.calendar;
  41758. if(ax.type === 'category') {
  41759. return {
  41760. start: dataMin - 0.5,
  41761. end: dataMax + 0.5,
  41762. size: 1,
  41763. _dataSpan: dataMax - dataMin,
  41764. };
  41765. }
  41766. var size0;
  41767. if(nbins) size0 = ((dataMax - dataMin) / nbins);
  41768. else {
  41769. // totally auto: scale off std deviation so the highest bin is
  41770. // somewhat taller than the total number of bins, but don't let
  41771. // the size get smaller than the 'nice' rounded down minimum
  41772. // difference between values
  41773. var distinctData = Lib.distinctVals(data),
  41774. msexp = Math.pow(10, Math.floor(
  41775. Math.log(distinctData.minDiff) / Math.LN10)),
  41776. minSize = msexp * Lib.roundUp(
  41777. distinctData.minDiff / msexp, [0.9, 1.9, 4.9, 9.9], true);
  41778. size0 = Math.max(minSize, 2 * Lib.stdev(data) /
  41779. Math.pow(data.length, is2d ? 0.25 : 0.4));
  41780. // fallback if ax.d2c output BADNUMs
  41781. // e.g. when user try to plot categorical bins
  41782. // on a layout.xaxis.type: 'linear'
  41783. if(!isNumeric(size0)) size0 = 1;
  41784. }
  41785. // piggyback off autotick code to make "nice" bin sizes
  41786. var dummyAx;
  41787. if(ax.type === 'log') {
  41788. dummyAx = {
  41789. type: 'linear',
  41790. range: [dataMin, dataMax]
  41791. };
  41792. }
  41793. else {
  41794. dummyAx = {
  41795. type: ax.type,
  41796. range: Lib.simpleMap([dataMin, dataMax], ax.c2r, 0, calendar),
  41797. calendar: calendar
  41798. };
  41799. }
  41800. axes.setConvert(dummyAx);
  41801. axes.autoTicks(dummyAx, size0);
  41802. var binStart = axes.tickIncrement(
  41803. axes.tickFirst(dummyAx), dummyAx.dtick, 'reverse', calendar);
  41804. var binEnd, bincount;
  41805. // check for too many data points right at the edges of bins
  41806. // (>50% within 1% of bin edges) or all data points integral
  41807. // and offset the bins accordingly
  41808. if(typeof dummyAx.dtick === 'number') {
  41809. binStart = autoShiftNumericBins(binStart, data, dummyAx, dataMin, dataMax);
  41810. bincount = 1 + Math.floor((dataMax - binStart) / dummyAx.dtick);
  41811. binEnd = binStart + bincount * dummyAx.dtick;
  41812. }
  41813. else {
  41814. // month ticks - should be the only nonlinear kind we have at this point.
  41815. // dtick (as supplied by axes.autoTick) only has nonlinear values on
  41816. // date and log axes, but even if you display a histogram on a log axis
  41817. // we bin it on a linear axis (which one could argue against, but that's
  41818. // a separate issue)
  41819. if(dummyAx.dtick.charAt(0) === 'M') {
  41820. binStart = autoShiftMonthBins(binStart, data, dummyAx.dtick, dataMin, calendar);
  41821. }
  41822. // calculate the endpoint for nonlinear ticks - you have to
  41823. // just increment until you're done
  41824. binEnd = binStart;
  41825. bincount = 0;
  41826. while(binEnd <= dataMax) {
  41827. binEnd = axes.tickIncrement(binEnd, dummyAx.dtick, false, calendar);
  41828. bincount++;
  41829. }
  41830. }
  41831. return {
  41832. start: ax.c2r(binStart, 0, calendar),
  41833. end: ax.c2r(binEnd, 0, calendar),
  41834. size: dummyAx.dtick,
  41835. _dataSpan: dataMax - dataMin
  41836. };
  41837. };
  41838. function autoShiftNumericBins(binStart, data, ax, dataMin, dataMax) {
  41839. var edgecount = 0,
  41840. midcount = 0,
  41841. intcount = 0,
  41842. blankCount = 0;
  41843. function nearEdge(v) {
  41844. // is a value within 1% of a bin edge?
  41845. return (1 + (v - binStart) * 100 / ax.dtick) % 100 < 2;
  41846. }
  41847. for(var i = 0; i < data.length; i++) {
  41848. if(data[i] % 1 === 0) intcount++;
  41849. else if(!isNumeric(data[i])) blankCount++;
  41850. if(nearEdge(data[i])) edgecount++;
  41851. if(nearEdge(data[i] + ax.dtick / 2)) midcount++;
  41852. }
  41853. var dataCount = data.length - blankCount;
  41854. if(intcount === dataCount && ax.type !== 'date') {
  41855. // all integers: if bin size is <1, it's because
  41856. // that was specifically requested (large nbins)
  41857. // so respect that... but center the bins containing
  41858. // integers on those integers
  41859. if(ax.dtick < 1) {
  41860. binStart = dataMin - 0.5 * ax.dtick;
  41861. }
  41862. // otherwise start half an integer down regardless of
  41863. // the bin size, just enough to clear up endpoint
  41864. // ambiguity about which integers are in which bins.
  41865. else {
  41866. binStart -= 0.5;
  41867. if(binStart + ax.dtick < dataMin) binStart += ax.dtick;
  41868. }
  41869. }
  41870. else if(midcount < dataCount * 0.1) {
  41871. if(edgecount > dataCount * 0.3 ||
  41872. nearEdge(dataMin) || nearEdge(dataMax)) {
  41873. // lots of points at the edge, not many in the middle
  41874. // shift half a bin
  41875. var binshift = ax.dtick / 2;
  41876. binStart += (binStart + binshift < dataMin) ? binshift : -binshift;
  41877. }
  41878. }
  41879. return binStart;
  41880. }
  41881. function autoShiftMonthBins(binStart, data, dtick, dataMin, calendar) {
  41882. var stats = Lib.findExactDates(data, calendar);
  41883. // number of data points that needs to be an exact value
  41884. // to shift that increment to (near) the bin center
  41885. var threshold = 0.8;
  41886. if(stats.exactDays > threshold) {
  41887. var numMonths = Number(dtick.substr(1));
  41888. if((stats.exactYears > threshold) && (numMonths % 12 === 0)) {
  41889. // The exact middle of a non-leap-year is 1.5 days into July
  41890. // so if we start the bins here, all but leap years will
  41891. // get hover-labeled as exact years.
  41892. binStart = axes.tickIncrement(binStart, 'M6', 'reverse') + ONEDAY * 1.5;
  41893. }
  41894. else if(stats.exactMonths > threshold) {
  41895. // Months are not as clean, but if we shift half the *longest*
  41896. // month (31/2 days) then 31-day months will get labeled exactly
  41897. // and shorter months will get labeled with the correct month
  41898. // but shifted 12-36 hours into it.
  41899. binStart = axes.tickIncrement(binStart, 'M1', 'reverse') + ONEDAY * 15.5;
  41900. }
  41901. else {
  41902. // Shifting half a day is exact, but since these are month bins it
  41903. // will always give a somewhat odd-looking label, until we do something
  41904. // smarter like showing the bin boundaries (or the bounds of the actual
  41905. // data in each bin)
  41906. binStart -= ONEDAY / 2;
  41907. }
  41908. var nextBinStart = axes.tickIncrement(binStart, dtick);
  41909. if(nextBinStart <= dataMin) return nextBinStart;
  41910. }
  41911. return binStart;
  41912. }
  41913. // ----------------------------------------------------
  41914. // Ticks and grids
  41915. // ----------------------------------------------------
  41916. // ensure we have tick0, dtick, and tick rounding calculated
  41917. axes.prepTicks = function(ax) {
  41918. var rng = Lib.simpleMap(ax.range, ax.r2l);
  41919. // calculate max number of (auto) ticks to display based on plot size
  41920. if(ax.tickmode === 'auto' || !ax.dtick) {
  41921. var nt = ax.nticks,
  41922. minPx;
  41923. if(!nt) {
  41924. if(ax.type === 'category') {
  41925. minPx = ax.tickfont ? (ax.tickfont.size || 12) * 1.2 : 15;
  41926. nt = ax._length / minPx;
  41927. }
  41928. else {
  41929. minPx = ax._id.charAt(0) === 'y' ? 40 : 80;
  41930. nt = Lib.constrain(ax._length / minPx, 4, 9) + 1;
  41931. }
  41932. // radial axes span half their domain,
  41933. // multiply nticks value by two to get correct number of auto ticks.
  41934. if(ax._name === 'radialaxis') nt *= 2;
  41935. }
  41936. // add a couple of extra digits for filling in ticks when we
  41937. // have explicit tickvals without tick text
  41938. if(ax.tickmode === 'array') nt *= 100;
  41939. axes.autoTicks(ax, Math.abs(rng[1] - rng[0]) / nt);
  41940. // check for a forced minimum dtick
  41941. if(ax._minDtick > 0 && ax.dtick < ax._minDtick * 2) {
  41942. ax.dtick = ax._minDtick;
  41943. ax.tick0 = ax.l2r(ax._forceTick0);
  41944. }
  41945. }
  41946. // check for missing tick0
  41947. if(!ax.tick0) {
  41948. ax.tick0 = (ax.type === 'date') ? '2000-01-01' : 0;
  41949. }
  41950. // ensure we don't try to make ticks below our minimum precision
  41951. // see https://github.com/plotly/plotly.js/issues/2892
  41952. if(ax.type === 'date' && ax.dtick < 0.1) ax.dtick = 0.1;
  41953. // now figure out rounding of tick values
  41954. autoTickRound(ax);
  41955. };
  41956. // calculate the ticks: text, values, positioning
  41957. // if ticks are set to automatic, determine the right values (tick0,dtick)
  41958. // in any case, set tickround to # of digits to round tick labels to,
  41959. // or codes to this effect for log and date scales
  41960. axes.calcTicks = function calcTicks(ax) {
  41961. axes.prepTicks(ax);
  41962. var rng = Lib.simpleMap(ax.range, ax.r2l);
  41963. // now that we've figured out the auto values for formatting
  41964. // in case we're missing some ticktext, we can break out for array ticks
  41965. if(ax.tickmode === 'array') return arrayTicks(ax);
  41966. // find the first tick
  41967. ax._tmin = axes.tickFirst(ax);
  41968. // add a tiny bit so we get ticks which may have rounded out
  41969. var startTick = rng[0] * 1.0001 - rng[1] * 0.0001;
  41970. var endTick = rng[1] * 1.0001 - rng[0] * 0.0001;
  41971. // check for reversed axis
  41972. var axrev = (rng[1] < rng[0]);
  41973. // No visible ticks? Quit.
  41974. // I've only seen this on category axes with all categories off the edge.
  41975. if((ax._tmin < startTick) !== axrev) return [];
  41976. // return the full set of tick vals
  41977. var vals = [];
  41978. if(ax.type === 'category') {
  41979. endTick = (axrev) ? Math.max(-0.5, endTick) :
  41980. Math.min(ax._categories.length - 0.5, endTick);
  41981. }
  41982. var xPrevious = null;
  41983. var maxTicks = Math.max(1000, ax._length || 0);
  41984. for(var x = ax._tmin;
  41985. (axrev) ? (x >= endTick) : (x <= endTick);
  41986. x = axes.tickIncrement(x, ax.dtick, axrev, ax.calendar)) {
  41987. // prevent infinite loops - no more than one tick per pixel,
  41988. // and make sure each value is different from the previous
  41989. if(vals.length > maxTicks || x === xPrevious) break;
  41990. xPrevious = x;
  41991. vals.push(x);
  41992. }
  41993. // If same angle over a full circle, the last tick vals is a duplicate.
  41994. // TODO must do something similar for angular date axes.
  41995. if(isAngular(ax) && Math.abs(rng[1] - rng[0]) === 360) {
  41996. vals.pop();
  41997. }
  41998. // save the last tick as well as first, so we can
  41999. // show the exponent only on the last one
  42000. ax._tmax = vals[vals.length - 1];
  42001. // for showing the rest of a date when the main tick label is only the
  42002. // latter part: ax._prevDateHead holds what we showed most recently.
  42003. // Start with it cleared and mark that we're in calcTicks (ie calculating a
  42004. // whole string of these so we should care what the previous date head was!)
  42005. ax._prevDateHead = '';
  42006. ax._inCalcTicks = true;
  42007. var ticksOut = new Array(vals.length);
  42008. for(var i = 0; i < vals.length; i++) ticksOut[i] = axes.tickText(ax, vals[i]);
  42009. ax._inCalcTicks = false;
  42010. return ticksOut;
  42011. };
  42012. function arrayTicks(ax) {
  42013. var vals = ax.tickvals,
  42014. text = ax.ticktext,
  42015. ticksOut = new Array(vals.length),
  42016. rng = Lib.simpleMap(ax.range, ax.r2l),
  42017. r0expanded = rng[0] * 1.0001 - rng[1] * 0.0001,
  42018. r1expanded = rng[1] * 1.0001 - rng[0] * 0.0001,
  42019. tickMin = Math.min(r0expanded, r1expanded),
  42020. tickMax = Math.max(r0expanded, r1expanded),
  42021. vali,
  42022. i,
  42023. j = 0;
  42024. // without a text array, just format the given values as any other ticks
  42025. // except with more precision to the numbers
  42026. if(!Array.isArray(text)) text = [];
  42027. // make sure showing ticks doesn't accidentally add new categories
  42028. var tickVal2l = ax.type === 'category' ? ax.d2l_noadd : ax.d2l;
  42029. // array ticks on log axes always show the full number
  42030. // (if no explicit ticktext overrides it)
  42031. if(ax.type === 'log' && String(ax.dtick).charAt(0) !== 'L') {
  42032. ax.dtick = 'L' + Math.pow(10, Math.floor(Math.min(ax.range[0], ax.range[1])) - 1);
  42033. }
  42034. for(i = 0; i < vals.length; i++) {
  42035. vali = tickVal2l(vals[i]);
  42036. if(vali > tickMin && vali < tickMax) {
  42037. if(text[i] === undefined) ticksOut[j] = axes.tickText(ax, vali);
  42038. else ticksOut[j] = tickTextObj(ax, vali, String(text[i]));
  42039. j++;
  42040. }
  42041. }
  42042. if(j < vals.length) ticksOut.splice(j, vals.length - j);
  42043. return ticksOut;
  42044. }
  42045. var roundBase10 = [2, 5, 10],
  42046. roundBase24 = [1, 2, 3, 6, 12],
  42047. roundBase60 = [1, 2, 5, 10, 15, 30],
  42048. // 2&3 day ticks are weird, but need something btwn 1&7
  42049. roundDays = [1, 2, 3, 7, 14],
  42050. // approx. tick positions for log axes, showing all (1) and just 1, 2, 5 (2)
  42051. // these don't have to be exact, just close enough to round to the right value
  42052. roundLog1 = [-0.046, 0, 0.301, 0.477, 0.602, 0.699, 0.778, 0.845, 0.903, 0.954, 1],
  42053. roundLog2 = [-0.301, 0, 0.301, 0.699, 1],
  42054. // N.B. `thetaunit; 'radians' angular axes must be converted to degrees
  42055. roundAngles = [15, 30, 45, 90, 180];
  42056. function roundDTick(roughDTick, base, roundingSet) {
  42057. return base * Lib.roundUp(roughDTick / base, roundingSet);
  42058. }
  42059. // autoTicks: calculate best guess at pleasant ticks for this axis
  42060. // inputs:
  42061. // ax - an axis object
  42062. // roughDTick - rough tick spacing (to be turned into a nice round number)
  42063. // outputs (into ax):
  42064. // tick0: starting point for ticks (not necessarily on the graph)
  42065. // usually 0 for numeric (=10^0=1 for log) or jan 1, 2000 for dates
  42066. // dtick: the actual, nice round tick spacing, usually a little larger than roughDTick
  42067. // if the ticks are spaced linearly (linear scale, categories,
  42068. // log with only full powers, date ticks < month),
  42069. // this will just be a number
  42070. // months: M#
  42071. // years: M# where # is 12*number of years
  42072. // log with linear ticks: L# where # is the linear tick spacing
  42073. // log showing powers plus some intermediates:
  42074. // D1 shows all digits, D2 shows 2 and 5
  42075. axes.autoTicks = function(ax, roughDTick) {
  42076. var base;
  42077. function getBase(v) {
  42078. return Math.pow(v, Math.floor(Math.log(roughDTick) / Math.LN10));
  42079. }
  42080. if(ax.type === 'date') {
  42081. ax.tick0 = Lib.dateTick0(ax.calendar);
  42082. // the criteria below are all based on the rough spacing we calculate
  42083. // being > half of the final unit - so precalculate twice the rough val
  42084. var roughX2 = 2 * roughDTick;
  42085. if(roughX2 > ONEAVGYEAR) {
  42086. roughDTick /= ONEAVGYEAR;
  42087. base = getBase(10);
  42088. ax.dtick = 'M' + (12 * roundDTick(roughDTick, base, roundBase10));
  42089. }
  42090. else if(roughX2 > ONEAVGMONTH) {
  42091. roughDTick /= ONEAVGMONTH;
  42092. ax.dtick = 'M' + roundDTick(roughDTick, 1, roundBase24);
  42093. }
  42094. else if(roughX2 > ONEDAY) {
  42095. ax.dtick = roundDTick(roughDTick, ONEDAY, roundDays);
  42096. // get week ticks on sunday
  42097. // this will also move the base tick off 2000-01-01 if dtick is
  42098. // 2 or 3 days... but that's a weird enough case that we'll ignore it.
  42099. ax.tick0 = Lib.dateTick0(ax.calendar, true);
  42100. }
  42101. else if(roughX2 > ONEHOUR) {
  42102. ax.dtick = roundDTick(roughDTick, ONEHOUR, roundBase24);
  42103. }
  42104. else if(roughX2 > ONEMIN) {
  42105. ax.dtick = roundDTick(roughDTick, ONEMIN, roundBase60);
  42106. }
  42107. else if(roughX2 > ONESEC) {
  42108. ax.dtick = roundDTick(roughDTick, ONESEC, roundBase60);
  42109. }
  42110. else {
  42111. // milliseconds
  42112. base = getBase(10);
  42113. ax.dtick = roundDTick(roughDTick, base, roundBase10);
  42114. }
  42115. }
  42116. else if(ax.type === 'log') {
  42117. ax.tick0 = 0;
  42118. var rng = Lib.simpleMap(ax.range, ax.r2l);
  42119. if(roughDTick > 0.7) {
  42120. // only show powers of 10
  42121. ax.dtick = Math.ceil(roughDTick);
  42122. }
  42123. else if(Math.abs(rng[1] - rng[0]) < 1) {
  42124. // span is less than one power of 10
  42125. var nt = 1.5 * Math.abs((rng[1] - rng[0]) / roughDTick);
  42126. // ticks on a linear scale, labeled fully
  42127. roughDTick = Math.abs(Math.pow(10, rng[1]) -
  42128. Math.pow(10, rng[0])) / nt;
  42129. base = getBase(10);
  42130. ax.dtick = 'L' + roundDTick(roughDTick, base, roundBase10);
  42131. }
  42132. else {
  42133. // include intermediates between powers of 10,
  42134. // labeled with small digits
  42135. // ax.dtick = "D2" (show 2 and 5) or "D1" (show all digits)
  42136. ax.dtick = (roughDTick > 0.3) ? 'D2' : 'D1';
  42137. }
  42138. }
  42139. else if(ax.type === 'category') {
  42140. ax.tick0 = 0;
  42141. ax.dtick = Math.ceil(Math.max(roughDTick, 1));
  42142. }
  42143. else if(isAngular(ax)) {
  42144. ax.tick0 = 0;
  42145. base = 1;
  42146. ax.dtick = roundDTick(roughDTick, base, roundAngles);
  42147. }
  42148. else {
  42149. // auto ticks always start at 0
  42150. ax.tick0 = 0;
  42151. base = getBase(10);
  42152. ax.dtick = roundDTick(roughDTick, base, roundBase10);
  42153. }
  42154. // prevent infinite loops
  42155. if(ax.dtick === 0) ax.dtick = 1;
  42156. // TODO: this is from log axis histograms with autorange off
  42157. if(!isNumeric(ax.dtick) && typeof ax.dtick !== 'string') {
  42158. var olddtick = ax.dtick;
  42159. ax.dtick = 1;
  42160. throw 'ax.dtick error: ' + String(olddtick);
  42161. }
  42162. };
  42163. // after dtick is already known, find tickround = precision
  42164. // to display in tick labels
  42165. // for numeric ticks, integer # digits after . to round to
  42166. // for date ticks, the last date part to show (y,m,d,H,M,S)
  42167. // or an integer # digits past seconds
  42168. function autoTickRound(ax) {
  42169. var dtick = ax.dtick;
  42170. ax._tickexponent = 0;
  42171. if(!isNumeric(dtick) && typeof dtick !== 'string') {
  42172. dtick = 1;
  42173. }
  42174. if(ax.type === 'category') {
  42175. ax._tickround = null;
  42176. }
  42177. if(ax.type === 'date') {
  42178. // If tick0 is unusual, give tickround a bit more information
  42179. // not necessarily *all* the information in tick0 though, if it's really odd
  42180. // minimal string length for tick0: 'd' is 10, 'M' is 16, 'S' is 19
  42181. // take off a leading minus (year < 0) and i (intercalary month) so length is consistent
  42182. var tick0ms = ax.r2l(ax.tick0),
  42183. tick0str = ax.l2r(tick0ms).replace(/(^-|i)/g, ''),
  42184. tick0len = tick0str.length;
  42185. if(String(dtick).charAt(0) === 'M') {
  42186. // any tick0 more specific than a year: alway show the full date
  42187. if(tick0len > 10 || tick0str.substr(5) !== '01-01') ax._tickround = 'd';
  42188. // show the month unless ticks are full multiples of a year
  42189. else ax._tickround = (+(dtick.substr(1)) % 12 === 0) ? 'y' : 'm';
  42190. }
  42191. else if((dtick >= ONEDAY && tick0len <= 10) || (dtick >= ONEDAY * 15)) ax._tickround = 'd';
  42192. else if((dtick >= ONEMIN && tick0len <= 16) || (dtick >= ONEHOUR)) ax._tickround = 'M';
  42193. else if((dtick >= ONESEC && tick0len <= 19) || (dtick >= ONEMIN)) ax._tickround = 'S';
  42194. else {
  42195. // tickround is a number of digits of fractional seconds
  42196. // of any two adjacent ticks, at least one will have the maximum fractional digits
  42197. // of all possible ticks - so take the max. length of tick0 and the next one
  42198. var tick1len = ax.l2r(tick0ms + dtick).replace(/^-/, '').length;
  42199. ax._tickround = Math.max(tick0len, tick1len) - 20;
  42200. // We shouldn't get here... but in case there's a situation I'm
  42201. // not thinking of where tick0str and tick1str are identical or
  42202. // something, fall back on maximum precision
  42203. if(ax._tickround < 0) ax._tickround = 4;
  42204. }
  42205. }
  42206. else if(isNumeric(dtick) || dtick.charAt(0) === 'L') {
  42207. // linear or log (except D1, D2)
  42208. var rng = ax.range.map(ax.r2d || Number);
  42209. if(!isNumeric(dtick)) dtick = Number(dtick.substr(1));
  42210. // 2 digits past largest digit of dtick
  42211. ax._tickround = 2 - Math.floor(Math.log(dtick) / Math.LN10 + 0.01);
  42212. var maxend = Math.max(Math.abs(rng[0]), Math.abs(rng[1]));
  42213. var rangeexp = Math.floor(Math.log(maxend) / Math.LN10 + 0.01);
  42214. if(Math.abs(rangeexp) > 3) {
  42215. if(isSIFormat(ax.exponentformat) && !beyondSI(rangeexp)) {
  42216. ax._tickexponent = 3 * Math.round((rangeexp - 1) / 3);
  42217. }
  42218. else ax._tickexponent = rangeexp;
  42219. }
  42220. }
  42221. // D1 or D2 (log)
  42222. else ax._tickround = null;
  42223. }
  42224. // months and years don't have constant millisecond values
  42225. // (but a year is always 12 months so we only need months)
  42226. // log-scale ticks are also not consistently spaced, except
  42227. // for pure powers of 10
  42228. // numeric ticks always have constant differences, other datetime ticks
  42229. // can all be calculated as constant number of milliseconds
  42230. axes.tickIncrement = function(x, dtick, axrev, calendar) {
  42231. var axSign = axrev ? -1 : 1;
  42232. // includes linear, all dates smaller than month, and pure 10^n in log
  42233. if(isNumeric(dtick)) return x + axSign * dtick;
  42234. // everything else is a string, one character plus a number
  42235. var tType = dtick.charAt(0),
  42236. dtSigned = axSign * Number(dtick.substr(1));
  42237. // Dates: months (or years - see Lib.incrementMonth)
  42238. if(tType === 'M') return Lib.incrementMonth(x, dtSigned, calendar);
  42239. // Log scales: Linear, Digits
  42240. else if(tType === 'L') return Math.log(Math.pow(10, x) + dtSigned) / Math.LN10;
  42241. // log10 of 2,5,10, or all digits (logs just have to be
  42242. // close enough to round)
  42243. else if(tType === 'D') {
  42244. var tickset = (dtick === 'D2') ? roundLog2 : roundLog1,
  42245. x2 = x + axSign * 0.01,
  42246. frac = Lib.roundUp(Lib.mod(x2, 1), tickset, axrev);
  42247. return Math.floor(x2) +
  42248. Math.log(d3.round(Math.pow(10, frac), 1)) / Math.LN10;
  42249. }
  42250. else throw 'unrecognized dtick ' + String(dtick);
  42251. };
  42252. // calculate the first tick on an axis
  42253. axes.tickFirst = function(ax) {
  42254. var r2l = ax.r2l || Number,
  42255. rng = Lib.simpleMap(ax.range, r2l),
  42256. axrev = rng[1] < rng[0],
  42257. sRound = axrev ? Math.floor : Math.ceil,
  42258. // add a tiny extra bit to make sure we get ticks
  42259. // that may have been rounded out
  42260. r0 = rng[0] * 1.0001 - rng[1] * 0.0001,
  42261. dtick = ax.dtick,
  42262. tick0 = r2l(ax.tick0);
  42263. if(isNumeric(dtick)) {
  42264. var tmin = sRound((r0 - tick0) / dtick) * dtick + tick0;
  42265. // make sure no ticks outside the category list
  42266. if(ax.type === 'category') {
  42267. tmin = Lib.constrain(tmin, 0, ax._categories.length - 1);
  42268. }
  42269. return tmin;
  42270. }
  42271. var tType = dtick.charAt(0),
  42272. dtNum = Number(dtick.substr(1));
  42273. // Dates: months (or years)
  42274. if(tType === 'M') {
  42275. var cnt = 0,
  42276. t0 = tick0,
  42277. t1,
  42278. mult,
  42279. newDTick;
  42280. // This algorithm should work for *any* nonlinear (but close to linear!)
  42281. // tick spacing. Limit to 10 iterations, for gregorian months it's normally <=3.
  42282. while(cnt < 10) {
  42283. t1 = axes.tickIncrement(t0, dtick, axrev, ax.calendar);
  42284. if((t1 - r0) * (t0 - r0) <= 0) {
  42285. // t1 and t0 are on opposite sides of r0! we've succeeded!
  42286. if(axrev) return Math.min(t0, t1);
  42287. return Math.max(t0, t1);
  42288. }
  42289. mult = (r0 - ((t0 + t1) / 2)) / (t1 - t0);
  42290. newDTick = tType + ((Math.abs(Math.round(mult)) || 1) * dtNum);
  42291. t0 = axes.tickIncrement(t0, newDTick, mult < 0 ? !axrev : axrev, ax.calendar);
  42292. cnt++;
  42293. }
  42294. Lib.error('tickFirst did not converge', ax);
  42295. return t0;
  42296. }
  42297. // Log scales: Linear, Digits
  42298. else if(tType === 'L') {
  42299. return Math.log(sRound(
  42300. (Math.pow(10, r0) - tick0) / dtNum) * dtNum + tick0) / Math.LN10;
  42301. }
  42302. else if(tType === 'D') {
  42303. var tickset = (dtick === 'D2') ? roundLog2 : roundLog1,
  42304. frac = Lib.roundUp(Lib.mod(r0, 1), tickset, axrev);
  42305. return Math.floor(r0) +
  42306. Math.log(d3.round(Math.pow(10, frac), 1)) / Math.LN10;
  42307. }
  42308. else throw 'unrecognized dtick ' + String(dtick);
  42309. };
  42310. // draw the text for one tick.
  42311. // px,py are the location on gd.paper
  42312. // prefix is there so the x axis ticks can be dropped a line
  42313. // ax is the axis layout, x is the tick value
  42314. // hover is a (truthy) flag for whether to show numbers with a bit
  42315. // more precision for hovertext
  42316. axes.tickText = function(ax, x, hover) {
  42317. var out = tickTextObj(ax, x),
  42318. hideexp,
  42319. arrayMode = ax.tickmode === 'array',
  42320. extraPrecision = hover || arrayMode,
  42321. i,
  42322. tickVal2l = ax.type === 'category' ? ax.d2l_noadd : ax.d2l;
  42323. if(arrayMode && Array.isArray(ax.ticktext)) {
  42324. var rng = Lib.simpleMap(ax.range, ax.r2l),
  42325. minDiff = Math.abs(rng[1] - rng[0]) / 10000;
  42326. for(i = 0; i < ax.ticktext.length; i++) {
  42327. if(Math.abs(x - tickVal2l(ax.tickvals[i])) < minDiff) break;
  42328. }
  42329. if(i < ax.ticktext.length) {
  42330. out.text = String(ax.ticktext[i]);
  42331. return out;
  42332. }
  42333. }
  42334. function isHidden(showAttr) {
  42335. var first_or_last;
  42336. if(showAttr === undefined) return true;
  42337. if(hover) return showAttr === 'none';
  42338. first_or_last = {
  42339. first: ax._tmin,
  42340. last: ax._tmax
  42341. }[showAttr];
  42342. return showAttr !== 'all' && x !== first_or_last;
  42343. }
  42344. if(hover) {
  42345. hideexp = 'never';
  42346. } else {
  42347. hideexp = ax.exponentformat !== 'none' && isHidden(ax.showexponent) ? 'hide' : '';
  42348. }
  42349. if(ax.type === 'date') formatDate(ax, out, hover, extraPrecision);
  42350. else if(ax.type === 'log') formatLog(ax, out, hover, extraPrecision, hideexp);
  42351. else if(ax.type === 'category') formatCategory(ax, out);
  42352. else if(isAngular(ax)) formatAngle(ax, out, hover, extraPrecision, hideexp);
  42353. else formatLinear(ax, out, hover, extraPrecision, hideexp);
  42354. // add prefix and suffix
  42355. if(ax.tickprefix && !isHidden(ax.showtickprefix)) out.text = ax.tickprefix + out.text;
  42356. if(ax.ticksuffix && !isHidden(ax.showticksuffix)) out.text += ax.ticksuffix;
  42357. return out;
  42358. };
  42359. /**
  42360. * create text for a hover label on this axis, with special handling of
  42361. * log axes (where negative values can't be displayed but can appear in hover text)
  42362. *
  42363. * @param {object} ax: the axis to format text for
  42364. * @param {number} val: calcdata value to format
  42365. * @param {Optional(number)} val2: a second value to display
  42366. *
  42367. * @returns {string} `val` formatted as a string appropriate to this axis, or
  42368. * `val` and `val2` as a range (ie '<val> - <val2>') if `val2` is provided and
  42369. * it's different from `val`.
  42370. */
  42371. axes.hoverLabelText = function(ax, val, val2) {
  42372. if(val2 !== BADNUM && val2 !== val) {
  42373. return axes.hoverLabelText(ax, val) + ' - ' + axes.hoverLabelText(ax, val2);
  42374. }
  42375. var logOffScale = (ax.type === 'log' && val <= 0);
  42376. var tx = axes.tickText(ax, ax.c2l(logOffScale ? -val : val), 'hover').text;
  42377. if(logOffScale) {
  42378. return val === 0 ? '0' : MINUS_SIGN + tx;
  42379. }
  42380. // TODO: should we do something special if the axis calendar and
  42381. // the data calendar are different? Somehow display both dates with
  42382. // their system names? Right now it will just display in the axis calendar
  42383. // but users could add the other one as text.
  42384. return tx;
  42385. };
  42386. function tickTextObj(ax, x, text) {
  42387. var tf = ax.tickfont || {};
  42388. return {
  42389. x: x,
  42390. dx: 0,
  42391. dy: 0,
  42392. text: text || '',
  42393. fontSize: tf.size,
  42394. font: tf.family,
  42395. fontColor: tf.color
  42396. };
  42397. }
  42398. function formatDate(ax, out, hover, extraPrecision) {
  42399. var tr = ax._tickround,
  42400. fmt = (hover && ax.hoverformat) || axes.getTickFormat(ax);
  42401. if(extraPrecision) {
  42402. // second or sub-second precision: extra always shows max digits.
  42403. // for other fields, extra precision just adds one field.
  42404. if(isNumeric(tr)) tr = 4;
  42405. else tr = {y: 'm', m: 'd', d: 'M', M: 'S', S: 4}[tr];
  42406. }
  42407. var dateStr = Lib.formatDate(out.x, fmt, tr, ax._dateFormat, ax.calendar, ax._extraFormat),
  42408. headStr;
  42409. var splitIndex = dateStr.indexOf('\n');
  42410. if(splitIndex !== -1) {
  42411. headStr = dateStr.substr(splitIndex + 1);
  42412. dateStr = dateStr.substr(0, splitIndex);
  42413. }
  42414. if(extraPrecision) {
  42415. // if extraPrecision led to trailing zeros, strip them off
  42416. // actually, this can lead to removing even more zeros than
  42417. // in the original rounding, but that's fine because in these
  42418. // contexts uniformity is not so important (if there's even
  42419. // anything to be uniform with!)
  42420. // can we remove the whole time part?
  42421. if(dateStr === '00:00:00' || dateStr === '00:00') {
  42422. dateStr = headStr;
  42423. headStr = '';
  42424. }
  42425. else if(dateStr.length === 8) {
  42426. // strip off seconds if they're zero (zero fractional seconds
  42427. // are already omitted)
  42428. // but we never remove minutes and leave just hours
  42429. dateStr = dateStr.replace(/:00$/, '');
  42430. }
  42431. }
  42432. if(headStr) {
  42433. if(hover) {
  42434. // hover puts it all on one line, so headPart works best up front
  42435. // except for year headPart: turn this into "Jan 1, 2000" etc.
  42436. if(tr === 'd') dateStr += ', ' + headStr;
  42437. else dateStr = headStr + (dateStr ? ', ' + dateStr : '');
  42438. }
  42439. else if(!ax._inCalcTicks || (headStr !== ax._prevDateHead)) {
  42440. dateStr += '<br>' + headStr;
  42441. ax._prevDateHead = headStr;
  42442. }
  42443. }
  42444. out.text = dateStr;
  42445. }
  42446. function formatLog(ax, out, hover, extraPrecision, hideexp) {
  42447. var dtick = ax.dtick;
  42448. var x = out.x;
  42449. var tickformat = ax.tickformat;
  42450. var dtChar0 = typeof dtick === 'string' && dtick.charAt(0);
  42451. if(hideexp === 'never') {
  42452. // If this is a hover label, then we must *never* hide the exponent
  42453. // for the sake of display, which could give the wrong value by
  42454. // potentially many orders of magnitude. If hideexp was 'never', then
  42455. // it's now succeeded by preventing the other condition from automating
  42456. // this choice. Thus we can unset it so that the axis formatting takes
  42457. // precedence.
  42458. hideexp = '';
  42459. }
  42460. if(extraPrecision && (dtChar0 !== 'L')) {
  42461. dtick = 'L3';
  42462. dtChar0 = 'L';
  42463. }
  42464. if(tickformat || (dtChar0 === 'L')) {
  42465. out.text = numFormat(Math.pow(10, x), ax, hideexp, extraPrecision);
  42466. }
  42467. else if(isNumeric(dtick) || ((dtChar0 === 'D') && (Lib.mod(x + 0.01, 1) < 0.1))) {
  42468. var p = Math.round(x);
  42469. var absP = Math.abs(p);
  42470. var exponentFormat = ax.exponentformat;
  42471. if(exponentFormat === 'power' || (isSIFormat(exponentFormat) && beyondSI(p))) {
  42472. if(p === 0) out.text = 1;
  42473. else if(p === 1) out.text = '10';
  42474. else out.text = '10<sup>' + (p > 1 ? '' : MINUS_SIGN) + absP + '</sup>';
  42475. out.fontSize *= 1.25;
  42476. }
  42477. else if((exponentFormat === 'e' || exponentFormat === 'E') && absP > 2) {
  42478. out.text = '1' + exponentFormat + (p > 0 ? '+' : MINUS_SIGN) + absP;
  42479. }
  42480. else {
  42481. out.text = numFormat(Math.pow(10, x), ax, '', 'fakehover');
  42482. if(dtick === 'D1' && ax._id.charAt(0) === 'y') {
  42483. out.dy -= out.fontSize / 6;
  42484. }
  42485. }
  42486. }
  42487. else if(dtChar0 === 'D') {
  42488. out.text = String(Math.round(Math.pow(10, Lib.mod(x, 1))));
  42489. out.fontSize *= 0.75;
  42490. }
  42491. else throw 'unrecognized dtick ' + String(dtick);
  42492. // if 9's are printed on log scale, move the 10's away a bit
  42493. if(ax.dtick === 'D1') {
  42494. var firstChar = String(out.text).charAt(0);
  42495. if(firstChar === '0' || firstChar === '1') {
  42496. if(ax._id.charAt(0) === 'y') {
  42497. out.dx -= out.fontSize / 4;
  42498. }
  42499. else {
  42500. out.dy += out.fontSize / 2;
  42501. out.dx += (ax.range[1] > ax.range[0] ? 1 : -1) *
  42502. out.fontSize * (x < 0 ? 0.5 : 0.25);
  42503. }
  42504. }
  42505. }
  42506. }
  42507. function formatCategory(ax, out) {
  42508. var tt = ax._categories[Math.round(out.x)];
  42509. if(tt === undefined) tt = '';
  42510. out.text = String(tt);
  42511. }
  42512. function formatLinear(ax, out, hover, extraPrecision, hideexp) {
  42513. if(hideexp === 'never') {
  42514. // If this is a hover label, then we must *never* hide the exponent
  42515. // for the sake of display, which could give the wrong value by
  42516. // potentially many orders of magnitude. If hideexp was 'never', then
  42517. // it's now succeeded by preventing the other condition from automating
  42518. // this choice. Thus we can unset it so that the axis formatting takes
  42519. // precedence.
  42520. hideexp = '';
  42521. } else if(ax.showexponent === 'all' && Math.abs(out.x / ax.dtick) < 1e-6) {
  42522. // don't add an exponent to zero if we're showing all exponents
  42523. // so the only reason you'd show an exponent on zero is if it's the
  42524. // ONLY tick to get an exponent (first or last)
  42525. hideexp = 'hide';
  42526. }
  42527. out.text = numFormat(out.x, ax, hideexp, extraPrecision);
  42528. }
  42529. function formatAngle(ax, out, hover, extraPrecision, hideexp) {
  42530. if(ax.thetaunit === 'radians' && !hover) {
  42531. var num = out.x / 180;
  42532. if(num === 0) {
  42533. out.text = '0';
  42534. } else {
  42535. var frac = num2frac(num);
  42536. if(frac[1] >= 100) {
  42537. out.text = numFormat(Lib.deg2rad(out.x), ax, hideexp, extraPrecision);
  42538. } else {
  42539. var isNeg = out.x < 0;
  42540. if(frac[1] === 1) {
  42541. if(frac[0] === 1) out.text = 'π';
  42542. else out.text = frac[0] + 'π';
  42543. } else {
  42544. out.text = [
  42545. '<sup>', frac[0], '</sup>',
  42546. '⁄',
  42547. '<sub>', frac[1], '</sub>',
  42548. 'π'
  42549. ].join('');
  42550. }
  42551. if(isNeg) out.text = MINUS_SIGN + out.text;
  42552. }
  42553. }
  42554. } else {
  42555. out.text = numFormat(out.x, ax, hideexp, extraPrecision);
  42556. }
  42557. }
  42558. // inspired by
  42559. // https://github.com/yisibl/num2fraction/blob/master/index.js
  42560. function num2frac(num) {
  42561. function almostEq(a, b) {
  42562. return Math.abs(a - b) <= 1e-6;
  42563. }
  42564. function findGCD(a, b) {
  42565. return almostEq(b, 0) ? a : findGCD(b, a % b);
  42566. }
  42567. function findPrecision(n) {
  42568. var e = 1;
  42569. while(!almostEq(Math.round(n * e) / e, n)) {
  42570. e *= 10;
  42571. }
  42572. return e;
  42573. }
  42574. var precision = findPrecision(num);
  42575. var number = num * precision;
  42576. var gcd = Math.abs(findGCD(number, precision));
  42577. return [
  42578. // numerator
  42579. Math.round(number / gcd),
  42580. // denominator
  42581. Math.round(precision / gcd)
  42582. ];
  42583. }
  42584. // format a number (tick value) according to the axis settings
  42585. // new, more reliable procedure than d3.round or similar:
  42586. // add half the rounding increment, then stringify and truncate
  42587. // also automatically switch to sci. notation
  42588. var SIPREFIXES = ['f', 'p', 'n', 'μ', 'm', '', 'k', 'M', 'G', 'T'];
  42589. function isSIFormat(exponentFormat) {
  42590. return exponentFormat === 'SI' || exponentFormat === 'B';
  42591. }
  42592. // are we beyond the range of common SI prefixes?
  42593. // 10^-16 -> 1x10^-16
  42594. // 10^-15 -> 1f
  42595. // ...
  42596. // 10^14 -> 100T
  42597. // 10^15 -> 1x10^15
  42598. // 10^16 -> 1x10^16
  42599. function beyondSI(exponent) {
  42600. return exponent > 14 || exponent < -15;
  42601. }
  42602. function numFormat(v, ax, fmtoverride, hover) {
  42603. // negative?
  42604. var isNeg = v < 0,
  42605. // max number of digits past decimal point to show
  42606. tickRound = ax._tickround,
  42607. exponentFormat = fmtoverride || ax.exponentformat || 'B',
  42608. exponent = ax._tickexponent,
  42609. tickformat = axes.getTickFormat(ax),
  42610. separatethousands = ax.separatethousands;
  42611. // special case for hover: set exponent just for this value, and
  42612. // add a couple more digits of precision over tick labels
  42613. if(hover) {
  42614. // make a dummy axis obj to get the auto rounding and exponent
  42615. var ah = {
  42616. exponentformat: exponentFormat,
  42617. dtick: ax.showexponent === 'none' ? ax.dtick :
  42618. (isNumeric(v) ? Math.abs(v) || 1 : 1),
  42619. // if not showing any exponents, don't change the exponent
  42620. // from what we calculate
  42621. range: ax.showexponent === 'none' ? ax.range.map(ax.r2d) : [0, v || 1]
  42622. };
  42623. autoTickRound(ah);
  42624. tickRound = (Number(ah._tickround) || 0) + 4;
  42625. exponent = ah._tickexponent;
  42626. if(ax.hoverformat) tickformat = ax.hoverformat;
  42627. }
  42628. if(tickformat) return ax._numFormat(tickformat)(v).replace(/-/g, MINUS_SIGN);
  42629. // 'epsilon' - rounding increment
  42630. var e = Math.pow(10, -tickRound) / 2;
  42631. // exponentFormat codes:
  42632. // 'e' (1.2e+6, default)
  42633. // 'E' (1.2E+6)
  42634. // 'SI' (1.2M)
  42635. // 'B' (same as SI except 10^9=B not G)
  42636. // 'none' (1200000)
  42637. // 'power' (1.2x10^6)
  42638. // 'hide' (1.2, use 3rd argument=='hide' to eg
  42639. // only show exponent on last tick)
  42640. if(exponentFormat === 'none') exponent = 0;
  42641. // take the sign out, put it back manually at the end
  42642. // - makes cases easier
  42643. v = Math.abs(v);
  42644. if(v < e) {
  42645. // 0 is just 0, but may get exponent if it's the last tick
  42646. v = '0';
  42647. isNeg = false;
  42648. }
  42649. else {
  42650. v += e;
  42651. // take out a common exponent, if any
  42652. if(exponent) {
  42653. v *= Math.pow(10, -exponent);
  42654. tickRound += exponent;
  42655. }
  42656. // round the mantissa
  42657. if(tickRound === 0) v = String(Math.floor(v));
  42658. else if(tickRound < 0) {
  42659. v = String(Math.round(v));
  42660. v = v.substr(0, v.length + tickRound);
  42661. for(var i = tickRound; i < 0; i++) v += '0';
  42662. }
  42663. else {
  42664. v = String(v);
  42665. var dp = v.indexOf('.') + 1;
  42666. if(dp) v = v.substr(0, dp + tickRound).replace(/\.?0+$/, '');
  42667. }
  42668. // insert appropriate decimal point and thousands separator
  42669. v = Lib.numSeparate(v, ax._separators, separatethousands);
  42670. }
  42671. // add exponent
  42672. if(exponent && exponentFormat !== 'hide') {
  42673. if(isSIFormat(exponentFormat) && beyondSI(exponent)) exponentFormat = 'power';
  42674. var signedExponent;
  42675. if(exponent < 0) signedExponent = MINUS_SIGN + -exponent;
  42676. else if(exponentFormat !== 'power') signedExponent = '+' + exponent;
  42677. else signedExponent = String(exponent);
  42678. if(exponentFormat === 'e' || exponentFormat === 'E') {
  42679. v += exponentFormat + signedExponent;
  42680. }
  42681. else if(exponentFormat === 'power') {
  42682. v += '×10<sup>' + signedExponent + '</sup>';
  42683. }
  42684. else if(exponentFormat === 'B' && exponent === 9) {
  42685. v += 'B';
  42686. }
  42687. else if(isSIFormat(exponentFormat)) {
  42688. v += SIPREFIXES[exponent / 3 + 5];
  42689. }
  42690. }
  42691. // put sign back in and return
  42692. // replace standard minus character (which is technically a hyphen)
  42693. // with a true minus sign
  42694. if(isNeg) return MINUS_SIGN + v;
  42695. return v;
  42696. }
  42697. axes.getTickFormat = function(ax) {
  42698. var i;
  42699. function convertToMs(dtick) {
  42700. return typeof dtick !== 'string' ? dtick : Number(dtick.replace('M', '')) * ONEAVGMONTH;
  42701. }
  42702. function compareLogTicks(left, right) {
  42703. var priority = ['L', 'D'];
  42704. if(typeof left === typeof right) {
  42705. if(typeof left === 'number') {
  42706. return left - right;
  42707. } else {
  42708. var leftPriority = priority.indexOf(left.charAt(0));
  42709. var rightPriority = priority.indexOf(right.charAt(0));
  42710. if(leftPriority === rightPriority) {
  42711. return Number(left.replace(/(L|D)/g, '')) - Number(right.replace(/(L|D)/g, ''));
  42712. } else {
  42713. return leftPriority - rightPriority;
  42714. }
  42715. }
  42716. } else {
  42717. return typeof left === 'number' ? 1 : -1;
  42718. }
  42719. }
  42720. function isProperStop(dtick, range, convert) {
  42721. var convertFn = convert || function(x) { return x;};
  42722. var leftDtick = range[0];
  42723. var rightDtick = range[1];
  42724. return ((!leftDtick && typeof leftDtick !== 'number') || convertFn(leftDtick) <= convertFn(dtick)) &&
  42725. ((!rightDtick && typeof rightDtick !== 'number') || convertFn(rightDtick) >= convertFn(dtick));
  42726. }
  42727. function isProperLogStop(dtick, range) {
  42728. var isLeftDtickNull = range[0] === null;
  42729. var isRightDtickNull = range[1] === null;
  42730. var isDtickInRangeLeft = compareLogTicks(dtick, range[0]) >= 0;
  42731. var isDtickInRangeRight = compareLogTicks(dtick, range[1]) <= 0;
  42732. return (isLeftDtickNull || isDtickInRangeLeft) && (isRightDtickNull || isDtickInRangeRight);
  42733. }
  42734. var tickstop, stopi;
  42735. if(ax.tickformatstops && ax.tickformatstops.length > 0) {
  42736. switch(ax.type) {
  42737. case 'date':
  42738. case 'linear': {
  42739. for(i = 0; i < ax.tickformatstops.length; i++) {
  42740. stopi = ax.tickformatstops[i];
  42741. if(stopi.enabled && isProperStop(ax.dtick, stopi.dtickrange, convertToMs)) {
  42742. tickstop = stopi;
  42743. break;
  42744. }
  42745. }
  42746. break;
  42747. }
  42748. case 'log': {
  42749. for(i = 0; i < ax.tickformatstops.length; i++) {
  42750. stopi = ax.tickformatstops[i];
  42751. if(stopi.enabled && isProperLogStop(ax.dtick, stopi.dtickrange)) {
  42752. tickstop = stopi;
  42753. break;
  42754. }
  42755. }
  42756. break;
  42757. }
  42758. default:
  42759. }
  42760. }
  42761. return tickstop ? tickstop.value : ax.tickformat;
  42762. };
  42763. // getSubplots - extract all subplot IDs we need
  42764. // as an array of items like 'xy', 'x2y', 'x2y2'...
  42765. // sorted by x (x,x2,x3...) then y
  42766. // optionally restrict to only subplots containing axis object ax
  42767. axes.getSubplots = function(gd, ax) {
  42768. var subplotObj = gd._fullLayout._subplots;
  42769. var allSubplots = subplotObj.cartesian.concat(subplotObj.gl2d || []);
  42770. var out = ax ? axes.findSubplotsWithAxis(allSubplots, ax) : allSubplots;
  42771. out.sort(function(a, b) {
  42772. var aParts = a.substr(1).split('y');
  42773. var bParts = b.substr(1).split('y');
  42774. if(aParts[0] === bParts[0]) return +aParts[1] - +bParts[1];
  42775. return +aParts[0] - +bParts[0];
  42776. });
  42777. return out;
  42778. };
  42779. // find all subplots with axis 'ax'
  42780. axes.findSubplotsWithAxis = function(subplots, ax) {
  42781. var axMatch = new RegExp(
  42782. (ax._id.charAt(0) === 'x') ? ('^' + ax._id + 'y') : (ax._id + '$')
  42783. );
  42784. var subplotsWithAxis = [];
  42785. for(var i = 0; i < subplots.length; i++) {
  42786. var sp = subplots[i];
  42787. if(axMatch.test(sp)) subplotsWithAxis.push(sp);
  42788. }
  42789. return subplotsWithAxis;
  42790. };
  42791. // makeClipPaths: prepare clipPaths for all single axes and all possible xy pairings
  42792. axes.makeClipPaths = function(gd) {
  42793. var fullLayout = gd._fullLayout;
  42794. // for more info: https://github.com/plotly/plotly.js/issues/2595
  42795. if(fullLayout._hasOnlyLargeSploms) return;
  42796. var fullWidth = {_offset: 0, _length: fullLayout.width, _id: ''};
  42797. var fullHeight = {_offset: 0, _length: fullLayout.height, _id: ''};
  42798. var xaList = axes.list(gd, 'x', true);
  42799. var yaList = axes.list(gd, 'y', true);
  42800. var clipList = [];
  42801. var i, j;
  42802. for(i = 0; i < xaList.length; i++) {
  42803. clipList.push({x: xaList[i], y: fullHeight});
  42804. for(j = 0; j < yaList.length; j++) {
  42805. if(i === 0) clipList.push({x: fullWidth, y: yaList[j]});
  42806. clipList.push({x: xaList[i], y: yaList[j]});
  42807. }
  42808. }
  42809. // selectors don't work right with camelCase tags,
  42810. // have to use class instead
  42811. // https://groups.google.com/forum/#!topic/d3-js/6EpAzQ2gU9I
  42812. var axClips = fullLayout._clips.selectAll('.axesclip')
  42813. .data(clipList, function(d) { return d.x._id + d.y._id; });
  42814. axClips.enter().append('clipPath')
  42815. .classed('axesclip', true)
  42816. .attr('id', function(d) { return 'clip' + fullLayout._uid + d.x._id + d.y._id; })
  42817. .append('rect');
  42818. axClips.exit().remove();
  42819. axClips.each(function(d) {
  42820. d3.select(this).select('rect').attr({
  42821. x: d.x._offset || 0,
  42822. y: d.y._offset || 0,
  42823. width: d.x._length || 1,
  42824. height: d.y._length || 1
  42825. });
  42826. });
  42827. };
  42828. /**
  42829. * Main multi-axis drawing routine!
  42830. *
  42831. * @param {DOM element} gd : graph div
  42832. * @param {string or array of strings} arg : polymorphic argument
  42833. * @param {boolean} skipTitle : optional flag to skip axis title draw/update
  42834. *
  42835. * Signature 1: Axes.doTicks(gd, 'redraw')
  42836. * use this to clear and redraw all axes on graph
  42837. *
  42838. * Signature 2: Axes.doTicks(gd, '')
  42839. * use this to draw all axes on graph w/o the selectAll().remove()
  42840. * of the 'redraw' signature
  42841. *
  42842. * Signature 3: Axes.doTicks(gd, [axId, axId2, ...])
  42843. * where the items are axis id string,
  42844. * use this to update multiple axes in one call
  42845. *
  42846. * N.B doTicks updates:
  42847. * - ax._r (stored range for use by zoom/pan)
  42848. * - ax._rl (stored linearized range for use by zoom/pan)
  42849. */
  42850. axes.doTicks = function(gd, arg, skipTitle) {
  42851. var fullLayout = gd._fullLayout;
  42852. if(arg === 'redraw') {
  42853. fullLayout._paper.selectAll('g.subplot').each(function(d) {
  42854. var id = d[0];
  42855. var plotinfo = fullLayout._plots[id];
  42856. var xa = plotinfo.xaxis;
  42857. var ya = plotinfo.yaxis;
  42858. plotinfo.xaxislayer.selectAll('.' + xa._id + 'tick').remove();
  42859. plotinfo.yaxislayer.selectAll('.' + ya._id + 'tick').remove();
  42860. if(plotinfo.gridlayer) plotinfo.gridlayer.selectAll('path').remove();
  42861. if(plotinfo.zerolinelayer) plotinfo.zerolinelayer.selectAll('path').remove();
  42862. fullLayout._infolayer.select('.g-' + xa._id + 'title').remove();
  42863. fullLayout._infolayer.select('.g-' + ya._id + 'title').remove();
  42864. });
  42865. }
  42866. var axList = (!arg || arg === 'redraw') ? axes.listIds(gd) : arg;
  42867. Lib.syncOrAsync(axList.map(function(axid) {
  42868. return function() {
  42869. if(!axid) return;
  42870. var axDone = axes.doTicksSingle(gd, axid, skipTitle);
  42871. var ax = axes.getFromId(gd, axid);
  42872. ax._r = ax.range.slice();
  42873. ax._rl = Lib.simpleMap(ax._r, ax.r2l);
  42874. return axDone;
  42875. };
  42876. }));
  42877. };
  42878. /**
  42879. * Per-axis drawing routine!
  42880. *
  42881. * This routine draws axis ticks and much more (... grids, labels, title etc.)
  42882. * Supports multiple argument signatures.
  42883. * N.B. this thing is async in general (because of MathJax rendering)
  42884. *
  42885. * @param {DOM element} gd : graph div
  42886. * @param {string or object} arg : polymorphic argument
  42887. * @param {boolean} skipTitle : optional flag to skip axis title draw/update
  42888. * @return {promise}
  42889. *
  42890. * Signature 1: Axes.doTicks(gd, ax)
  42891. * where ax is an axis object as in fullLayout
  42892. *
  42893. * Signature 2: Axes.doTicks(gd, axId)
  42894. * where axId is a axis id string
  42895. */
  42896. axes.doTicksSingle = function(gd, arg, skipTitle) {
  42897. var fullLayout = gd._fullLayout;
  42898. var independent = false;
  42899. var ax;
  42900. if(Lib.isPlainObject(arg)) {
  42901. ax = arg;
  42902. independent = true;
  42903. } else {
  42904. ax = axes.getFromId(gd, arg);
  42905. }
  42906. // set scaling to pixels
  42907. ax.setScale();
  42908. var axid = ax._id;
  42909. var axLetter = axid.charAt(0);
  42910. var counterLetter = axes.counterLetter(axid);
  42911. var vals = ax._vals = axes.calcTicks(ax);
  42912. var datafn = function(d) { return [d.text, d.x, ax.mirror, d.font, d.fontSize, d.fontColor].join('_'); };
  42913. var tcls = axid + 'tick';
  42914. var gcls = axid + 'grid';
  42915. var zcls = axid + 'zl';
  42916. var pad = (ax.linewidth || 1) / 2;
  42917. var labelStandoff = (ax.ticks === 'outside' ? ax.ticklen : 0);
  42918. var labelShift = 0;
  42919. var gridWidth = Drawing.crispRound(gd, ax.gridwidth, 1);
  42920. var zeroLineWidth = Drawing.crispRound(gd, ax.zerolinewidth, gridWidth);
  42921. var tickWidth = Drawing.crispRound(gd, ax.tickwidth, 1);
  42922. var sides, transfn, tickpathfn, subplots;
  42923. var tickLabels;
  42924. var i;
  42925. if(ax._counterangle && ax.ticks === 'outside') {
  42926. var caRad = ax._counterangle * Math.PI / 180;
  42927. labelStandoff = ax.ticklen * Math.cos(caRad) + 1;
  42928. labelShift = ax.ticklen * Math.sin(caRad);
  42929. }
  42930. if(ax.showticklabels && (ax.ticks === 'outside' || ax.showline)) {
  42931. labelStandoff += 0.2 * ax.tickfont.size;
  42932. }
  42933. // positioning arguments for x vs y axes
  42934. if(axLetter === 'x') {
  42935. sides = ['bottom', 'top'];
  42936. transfn = ax._transfn || function(d) {
  42937. return 'translate(' + (ax._offset + ax.l2p(d.x)) + ',0)';
  42938. };
  42939. tickpathfn = function(shift, len) {
  42940. if(ax._counterangle) {
  42941. var caRad = ax._counterangle * Math.PI / 180;
  42942. return 'M0,' + shift + 'l' + (Math.sin(caRad) * len) + ',' + (Math.cos(caRad) * len);
  42943. }
  42944. else return 'M0,' + shift + 'v' + len;
  42945. };
  42946. }
  42947. else if(axLetter === 'y') {
  42948. sides = ['left', 'right'];
  42949. transfn = ax._transfn || function(d) {
  42950. return 'translate(0,' + (ax._offset + ax.l2p(d.x)) + ')';
  42951. };
  42952. tickpathfn = function(shift, len) {
  42953. if(ax._counterangle) {
  42954. var caRad = ax._counterangle * Math.PI / 180;
  42955. return 'M' + shift + ',0l' + (Math.cos(caRad) * len) + ',' + (-Math.sin(caRad) * len);
  42956. }
  42957. else return 'M' + shift + ',0h' + len;
  42958. };
  42959. }
  42960. else if(isAngular(ax)) {
  42961. sides = ['left', 'right'];
  42962. transfn = ax._transfn;
  42963. tickpathfn = function(shift, len) {
  42964. return 'M' + shift + ',0h' + len;
  42965. };
  42966. }
  42967. else {
  42968. Lib.warn('Unrecognized doTicks axis:', axid);
  42969. return;
  42970. }
  42971. var axside = ax.side || sides[0];
  42972. // which direction do the side[0], side[1], and free ticks go?
  42973. // then we flip if outside XOR y axis
  42974. var ticksign = [-1, 1, axside === sides[1] ? 1 : -1];
  42975. if((ax.ticks !== 'inside') === (axLetter === 'x')) {
  42976. ticksign = ticksign.map(function(v) { return -v; });
  42977. }
  42978. if(!ax.visible) return;
  42979. if(ax._tickFilter) {
  42980. vals = vals.filter(ax._tickFilter);
  42981. }
  42982. // Remove zero lines, grid lines, and inside ticks if they're within
  42983. // 1 pixel of the end.
  42984. // The key case here is removing zero lines when the axis bound is zero.
  42985. // Don't clip angular values.
  42986. var valsClipped = ax._valsClipped = isAngular(ax) ?
  42987. vals :
  42988. vals.filter(function(d) { return clipEnds(ax, d.x); });
  42989. function drawTicks(container, tickpath) {
  42990. var ticks = container.selectAll('path.' + tcls)
  42991. .data(ax.ticks === 'inside' ? valsClipped : vals, datafn);
  42992. if(tickpath && ax.ticks) {
  42993. ticks.enter().append('path').classed(tcls, 1).classed('ticks', 1)
  42994. .classed('crisp', 1)
  42995. .call(Color.stroke, ax.tickcolor)
  42996. .style('stroke-width', tickWidth + 'px')
  42997. .attr('d', tickpath);
  42998. ticks.attr('transform', transfn);
  42999. ticks.exit().remove();
  43000. }
  43001. else ticks.remove();
  43002. }
  43003. function drawLabels(container, position) {
  43004. // tick labels - for now just the main labels.
  43005. // TODO: mirror labels, esp for subplots
  43006. tickLabels = container.selectAll('g.' + tcls).data(vals, datafn);
  43007. if(!isNumeric(position)) {
  43008. tickLabels.remove();
  43009. drawAxTitle();
  43010. return;
  43011. }
  43012. if(!ax.showticklabels) {
  43013. tickLabels.remove();
  43014. drawAxTitle();
  43015. calcBoundingBox();
  43016. return;
  43017. }
  43018. var labelx, labely, labelanchor, labelpos0, flipit;
  43019. if(axLetter === 'x') {
  43020. flipit = (axside === 'bottom') ? 1 : -1;
  43021. labelx = function(d) { return d.dx + labelShift * flipit; };
  43022. labelpos0 = position + (labelStandoff + pad) * flipit;
  43023. labely = function(d) {
  43024. return d.dy + labelpos0 + d.fontSize *
  43025. ((axside === 'bottom') ? 1 : -0.2);
  43026. };
  43027. labelanchor = function(angle) {
  43028. if(!isNumeric(angle) || angle === 0 || angle === 180) {
  43029. return 'middle';
  43030. }
  43031. return (angle * flipit < 0) ? 'end' : 'start';
  43032. };
  43033. }
  43034. else if(axLetter === 'y') {
  43035. flipit = (axside === 'right') ? 1 : -1;
  43036. labely = function(d) {
  43037. return d.dy + d.fontSize * MID_SHIFT - labelShift * flipit;
  43038. };
  43039. labelx = function(d) {
  43040. return d.dx + position + (labelStandoff + pad +
  43041. ((Math.abs(ax.tickangle) === 90) ? d.fontSize / 2 : 0)) * flipit;
  43042. };
  43043. labelanchor = function(angle) {
  43044. if(isNumeric(angle) && Math.abs(angle) === 90) {
  43045. return 'middle';
  43046. }
  43047. return axside === 'right' ? 'start' : 'end';
  43048. };
  43049. }
  43050. else if(isAngular(ax)) {
  43051. ax._labelShift = labelShift;
  43052. ax._labelStandoff = labelStandoff;
  43053. ax._pad = pad;
  43054. labelx = ax._labelx;
  43055. labely = ax._labely;
  43056. labelanchor = ax._labelanchor;
  43057. }
  43058. var maxFontSize = 0,
  43059. autoangle = 0,
  43060. labelsReady = [];
  43061. tickLabels.enter().append('g').classed(tcls, 1)
  43062. .append('text')
  43063. // only so tex has predictable alignment that we can
  43064. // alter later
  43065. .attr('text-anchor', 'middle')
  43066. .each(function(d) {
  43067. var thisLabel = d3.select(this),
  43068. newPromise = gd._promises.length;
  43069. thisLabel
  43070. .call(svgTextUtils.positionText, labelx(d), labely(d))
  43071. .call(Drawing.font, d.font, d.fontSize, d.fontColor)
  43072. .text(d.text)
  43073. .call(svgTextUtils.convertToTspans, gd);
  43074. newPromise = gd._promises[newPromise];
  43075. if(newPromise) {
  43076. // if we have an async label, we'll deal with that
  43077. // all here so take it out of gd._promises and
  43078. // instead position the label and promise this in
  43079. // labelsReady
  43080. labelsReady.push(gd._promises.pop().then(function() {
  43081. positionLabels(thisLabel, ax.tickangle);
  43082. }));
  43083. }
  43084. else {
  43085. // sync label: just position it now.
  43086. positionLabels(thisLabel, ax.tickangle);
  43087. }
  43088. });
  43089. tickLabels.exit().remove();
  43090. tickLabels.each(function(d) {
  43091. maxFontSize = Math.max(maxFontSize, d.fontSize);
  43092. });
  43093. if(isAngular(ax)) {
  43094. tickLabels.each(function(d) {
  43095. d3.select(this).select('text')
  43096. .call(svgTextUtils.positionText, labelx(d), labely(d));
  43097. });
  43098. }
  43099. // How much to shift a multi-line label to center it vertically.
  43100. function getAnchorHeight(lineCount, lineHeight, angle) {
  43101. var h = (lineCount - 1) * lineHeight;
  43102. if(axLetter === 'x') {
  43103. if(angle < -60 || 60 < angle) {
  43104. return -0.5 * h;
  43105. } else if(axside === 'top') {
  43106. return -h;
  43107. }
  43108. } else {
  43109. angle *= axside === 'left' ? 1 : -1;
  43110. if(angle < -30) {
  43111. return -h;
  43112. } else if(angle < 30) {
  43113. return -0.5 * h;
  43114. }
  43115. }
  43116. return 0;
  43117. }
  43118. function positionLabels(s, angle) {
  43119. s.each(function(d) {
  43120. var anchor = labelanchor(angle, d);
  43121. var thisLabel = d3.select(this),
  43122. mathjaxGroup = thisLabel.select('.text-math-group'),
  43123. transform = transfn.call(thisLabel.node(), d) +
  43124. ((isNumeric(angle) && +angle !== 0) ?
  43125. (' rotate(' + angle + ',' + labelx(d) + ',' +
  43126. (labely(d) - d.fontSize / 2) + ')') :
  43127. '');
  43128. var anchorHeight = getAnchorHeight(
  43129. svgTextUtils.lineCount(thisLabel),
  43130. LINE_SPACING * d.fontSize,
  43131. isNumeric(angle) ? +angle : 0);
  43132. if(anchorHeight) {
  43133. transform += ' translate(0, ' + anchorHeight + ')';
  43134. }
  43135. if(mathjaxGroup.empty()) {
  43136. thisLabel.select('text').attr({
  43137. transform: transform,
  43138. 'text-anchor': anchor
  43139. });
  43140. }
  43141. else {
  43142. var mjShift =
  43143. Drawing.bBox(mathjaxGroup.node()).width *
  43144. {end: -0.5, start: 0.5}[anchor];
  43145. mathjaxGroup.attr('transform', transform +
  43146. (mjShift ? 'translate(' + mjShift + ',0)' : ''));
  43147. }
  43148. });
  43149. }
  43150. // make sure all labels are correctly positioned at their base angle
  43151. // the positionLabels call above is only for newly drawn labels.
  43152. // do this without waiting, using the last calculated angle to
  43153. // minimize flicker, then do it again when we know all labels are
  43154. // there, putting back the prescribed angle to check for overlaps.
  43155. positionLabels(tickLabels, ax._lastangle || ax.tickangle);
  43156. function allLabelsReady() {
  43157. return labelsReady.length && Promise.all(labelsReady);
  43158. }
  43159. function fixLabelOverlaps() {
  43160. positionLabels(tickLabels, ax.tickangle);
  43161. // check for auto-angling if x labels overlap
  43162. // don't auto-angle at all for log axes with
  43163. // base and digit format
  43164. if(axLetter === 'x' && !isNumeric(ax.tickangle) &&
  43165. (ax.type !== 'log' || String(ax.dtick).charAt(0) !== 'D')) {
  43166. var lbbArray = [];
  43167. tickLabels.each(function(d) {
  43168. var s = d3.select(this),
  43169. thisLabel = s.select('.text-math-group'),
  43170. x = ax.l2p(d.x);
  43171. if(thisLabel.empty()) thisLabel = s.select('text');
  43172. var bb = Drawing.bBox(thisLabel.node());
  43173. lbbArray.push({
  43174. // ignore about y, just deal with x overlaps
  43175. top: 0,
  43176. bottom: 10,
  43177. height: 10,
  43178. left: x - bb.width / 2,
  43179. // impose a 2px gap
  43180. right: x + bb.width / 2 + 2,
  43181. width: bb.width + 2
  43182. });
  43183. });
  43184. for(i = 0; i < lbbArray.length - 1; i++) {
  43185. if(Lib.bBoxIntersect(lbbArray[i], lbbArray[i + 1])) {
  43186. // any overlap at all - set 30 degrees
  43187. autoangle = 30;
  43188. break;
  43189. }
  43190. }
  43191. if(autoangle) {
  43192. var tickspacing = Math.abs(
  43193. (vals[vals.length - 1].x - vals[0].x) * ax._m
  43194. ) / (vals.length - 1);
  43195. if(tickspacing < maxFontSize * 2.5) {
  43196. autoangle = 90;
  43197. }
  43198. positionLabels(tickLabels, autoangle);
  43199. }
  43200. ax._lastangle = autoangle;
  43201. }
  43202. // update the axis title
  43203. // (so it can move out of the way if needed)
  43204. // TODO: separate out scoot so we don't need to do
  43205. // a full redraw of the title (mostly relevant for MathJax)
  43206. drawAxTitle();
  43207. return axid + ' done';
  43208. }
  43209. function calcBoundingBox() {
  43210. if(ax.showticklabels) {
  43211. var gdBB = gd.getBoundingClientRect();
  43212. var bBox = container.node().getBoundingClientRect();
  43213. /*
  43214. * the way we're going to use this, the positioning that matters
  43215. * is relative to the origin of gd. This is important particularly
  43216. * if gd is scrollable, and may have been scrolled between the time
  43217. * we calculate this and the time we use it
  43218. */
  43219. ax._boundingBox = {
  43220. width: bBox.width,
  43221. height: bBox.height,
  43222. left: bBox.left - gdBB.left,
  43223. right: bBox.right - gdBB.left,
  43224. top: bBox.top - gdBB.top,
  43225. bottom: bBox.bottom - gdBB.top
  43226. };
  43227. } else {
  43228. var gs = fullLayout._size;
  43229. var pos;
  43230. // set dummy bbox for ticklabel-less axes
  43231. if(axLetter === 'x') {
  43232. pos = ax.anchor === 'free' ?
  43233. gs.t + gs.h * (1 - ax.position) :
  43234. gs.t + gs.h * (1 - ax._anchorAxis.domain[{bottom: 0, top: 1}[ax.side]]);
  43235. ax._boundingBox = {
  43236. top: pos,
  43237. bottom: pos,
  43238. left: ax._offset,
  43239. right: ax._offset + ax._length,
  43240. width: ax._length,
  43241. height: 0
  43242. };
  43243. } else {
  43244. pos = ax.anchor === 'free' ?
  43245. gs.l + gs.w * ax.position :
  43246. gs.l + gs.w * ax._anchorAxis.domain[{left: 0, right: 1}[ax.side]];
  43247. ax._boundingBox = {
  43248. left: pos,
  43249. right: pos,
  43250. bottom: ax._offset + ax._length,
  43251. top: ax._offset,
  43252. height: ax._length,
  43253. width: 0
  43254. };
  43255. }
  43256. }
  43257. /*
  43258. * for spikelines: what's the full domain of positions in the
  43259. * opposite direction that are associated with this axis?
  43260. * This means any axes that we make a subplot with, plus the
  43261. * position of the axis itself if it's free.
  43262. */
  43263. if(subplots) {
  43264. var fullRange = ax._counterSpan = [Infinity, -Infinity];
  43265. for(i = 0; i < subplots.length; i++) {
  43266. var subplot = fullLayout._plots[subplots[i]];
  43267. var counterAxis = subplot[(axLetter === 'x') ? 'yaxis' : 'xaxis'];
  43268. extendRange(fullRange, [
  43269. counterAxis._offset,
  43270. counterAxis._offset + counterAxis._length
  43271. ]);
  43272. }
  43273. if(ax.anchor === 'free') {
  43274. extendRange(fullRange, (axLetter === 'x') ?
  43275. [ax._boundingBox.bottom, ax._boundingBox.top] :
  43276. [ax._boundingBox.right, ax._boundingBox.left]);
  43277. }
  43278. }
  43279. function extendRange(range, newRange) {
  43280. range[0] = Math.min(range[0], newRange[0]);
  43281. range[1] = Math.max(range[1], newRange[1]);
  43282. }
  43283. }
  43284. function doAutoMargins() {
  43285. var pushKey = ax._name + '.automargin';
  43286. if(axLetter !== 'x' && axLetter !== 'y') { return; }
  43287. if(!ax.automargin) {
  43288. Plots.autoMargin(gd, pushKey);
  43289. return;
  43290. }
  43291. var s = ax.side[0];
  43292. var push = {x: 0, y: 0, r: 0, l: 0, t: 0, b: 0};
  43293. if(axLetter === 'x') {
  43294. push.y = (ax.anchor === 'free' ? ax.position :
  43295. ax._anchorAxis.domain[s === 't' ? 1 : 0]);
  43296. push[s] += ax._boundingBox.height;
  43297. }
  43298. else {
  43299. push.x = (ax.anchor === 'free' ? ax.position :
  43300. ax._anchorAxis.domain[s === 'r' ? 1 : 0]);
  43301. push[s] += ax._boundingBox.width;
  43302. }
  43303. if(ax.title !== fullLayout._dfltTitle[axLetter]) {
  43304. push[s] += ax.titlefont.size;
  43305. }
  43306. Plots.autoMargin(gd, pushKey, push);
  43307. }
  43308. var done = Lib.syncOrAsync([
  43309. allLabelsReady,
  43310. fixLabelOverlaps,
  43311. calcBoundingBox,
  43312. doAutoMargins
  43313. ]);
  43314. if(done && done.then) gd._promises.push(done);
  43315. return done;
  43316. }
  43317. function drawAxTitle() {
  43318. if(skipTitle) return;
  43319. // now this only applies to regular cartesian axes; colorbars and
  43320. // others ALWAYS call doTicks with skipTitle=true so they can
  43321. // configure their own titles.
  43322. // rangeslider takes over a bottom title so drop it here
  43323. if(ax.rangeslider && ax.rangeslider.visible && ax._boundingBox && ax.side === 'bottom') return;
  43324. var avoid = {
  43325. selection: tickLabels,
  43326. side: ax.side
  43327. };
  43328. var axLetter = axid.charAt(0);
  43329. var gs = gd._fullLayout._size;
  43330. var offsetBase = 1.5;
  43331. var fontSize = ax.titlefont.size;
  43332. var transform, counterAxis, x, y;
  43333. if(tickLabels.size()) {
  43334. var translation = Drawing.getTranslate(tickLabels.node().parentNode);
  43335. avoid.offsetLeft = translation.x;
  43336. avoid.offsetTop = translation.y;
  43337. }
  43338. var titleStandoff = 10 + fontSize * offsetBase +
  43339. (ax.linewidth ? ax.linewidth - 1 : 0);
  43340. if(axLetter === 'x') {
  43341. counterAxis = (ax.anchor === 'free') ?
  43342. {_offset: gs.t + (1 - (ax.position || 0)) * gs.h, _length: 0} :
  43343. axisIds.getFromId(gd, ax.anchor);
  43344. x = ax._offset + ax._length / 2;
  43345. if(ax.side === 'top') {
  43346. y = -titleStandoff - fontSize * (ax.showticklabels ? 1 : 0);
  43347. }
  43348. else {
  43349. y = counterAxis._length + titleStandoff +
  43350. fontSize * (ax.showticklabels ? 1.5 : 0.5);
  43351. }
  43352. y += counterAxis._offset;
  43353. if(!avoid.side) avoid.side = 'bottom';
  43354. }
  43355. else {
  43356. counterAxis = (ax.anchor === 'free') ?
  43357. {_offset: gs.l + (ax.position || 0) * gs.w, _length: 0} :
  43358. axisIds.getFromId(gd, ax.anchor);
  43359. y = ax._offset + ax._length / 2;
  43360. if(ax.side === 'right') {
  43361. x = counterAxis._length + titleStandoff +
  43362. fontSize * (ax.showticklabels ? 1 : 0.5);
  43363. }
  43364. else {
  43365. x = -titleStandoff - fontSize * (ax.showticklabels ? 0.5 : 0);
  43366. }
  43367. x += counterAxis._offset;
  43368. transform = {rotate: '-90', offset: 0};
  43369. if(!avoid.side) avoid.side = 'left';
  43370. }
  43371. Titles.draw(gd, axid + 'title', {
  43372. propContainer: ax,
  43373. propName: ax._name + '.title',
  43374. placeholder: fullLayout._dfltTitle[axLetter],
  43375. avoid: avoid,
  43376. transform: transform,
  43377. attributes: {x: x, y: y, 'text-anchor': 'middle'}
  43378. });
  43379. }
  43380. function drawGrid(plotinfo, counteraxis) {
  43381. if(fullLayout._hasOnlyLargeSploms) return;
  43382. var gridcontainer = plotinfo.gridlayer.selectAll('.' + axid);
  43383. var zlcontainer = plotinfo.zerolinelayer;
  43384. var gridpath = ax._gridpath || ((axLetter === 'x' ?
  43385. ('M0,' + counteraxis._offset + 'v') :
  43386. ('M' + counteraxis._offset + ',0h')
  43387. ) + counteraxis._length);
  43388. var grid = gridcontainer.selectAll('path.' + gcls)
  43389. .data((ax.showgrid === false) ? [] : valsClipped, datafn);
  43390. grid.enter().append('path').classed(gcls, 1)
  43391. .classed('crisp', 1)
  43392. .attr('d', gridpath)
  43393. .each(function(d) {
  43394. if(ax.zeroline && (ax.type === 'linear' || ax.type === '-') &&
  43395. Math.abs(d.x) < ax.dtick / 100) {
  43396. d3.select(this).remove();
  43397. }
  43398. });
  43399. grid.attr('transform', transfn)
  43400. .call(Color.stroke, ax.gridcolor || '#ddd')
  43401. .style('stroke-width', gridWidth + 'px');
  43402. if(typeof gridpath === 'function') grid.attr('d', gridpath);
  43403. grid.exit().remove();
  43404. // zero line
  43405. if(zlcontainer) {
  43406. var zlData = {x: 0, id: axid};
  43407. var showZl = axes.shouldShowZeroLine(gd, ax, counteraxis);
  43408. var zl = zlcontainer.selectAll('path.' + zcls)
  43409. .data(showZl ? [zlData] : []);
  43410. zl.enter().append('path').classed(zcls, 1).classed('zl', 1)
  43411. .classed('crisp', 1)
  43412. .attr('d', gridpath)
  43413. .each(function() {
  43414. // use the fact that only one element can enter to trigger a sort.
  43415. // If several zerolines enter at the same time we will sort once per,
  43416. // but generally this should be a minimal overhead.
  43417. zlcontainer.selectAll('path').sort(function(da, db) {
  43418. return axisIds.idSort(da.id, db.id);
  43419. });
  43420. });
  43421. zl.attr('transform', transfn)
  43422. .call(Color.stroke, ax.zerolinecolor || Color.defaultLine)
  43423. .style('stroke-width', zeroLineWidth + 'px');
  43424. zl.exit().remove();
  43425. }
  43426. }
  43427. if(independent) {
  43428. drawTicks(ax._axislayer, tickpathfn(ax._pos + pad * ticksign[2], ticksign[2] * ax.ticklen));
  43429. if(ax._counteraxis) {
  43430. var fictionalPlotinfo = {
  43431. gridlayer: ax._gridlayer,
  43432. zerolinelayer: ax._zerolinelayer
  43433. };
  43434. drawGrid(fictionalPlotinfo, ax._counteraxis);
  43435. }
  43436. return drawLabels(ax._axislayer, ax._pos);
  43437. }
  43438. else if(fullLayout._has('cartesian')) {
  43439. subplots = axes.getSubplots(gd, ax);
  43440. // keep track of which subplots (by main conteraxis) we've already
  43441. // drawn grids for, so we don't overdraw overlaying subplots
  43442. var finishedGrids = {};
  43443. subplots.map(function(subplot) {
  43444. var plotinfo = fullLayout._plots[subplot];
  43445. var counterAxis = plotinfo[counterLetter + 'axis'];
  43446. var mainCounterID = counterAxis._mainAxis._id;
  43447. if(finishedGrids[mainCounterID]) return;
  43448. finishedGrids[mainCounterID] = 1;
  43449. drawGrid(plotinfo, counterAxis, subplot);
  43450. });
  43451. var mainSubplot = ax._mainSubplot;
  43452. var mainPlotinfo = fullLayout._plots[mainSubplot];
  43453. var tickSubplots = [];
  43454. if(ax.ticks) {
  43455. var mainSign = ticksign[2];
  43456. var tickpath = tickpathfn(ax._mainLinePosition + pad * mainSign, mainSign * ax.ticklen);
  43457. if(ax._anchorAxis && ax.mirror && ax.mirror !== true) {
  43458. tickpath += tickpathfn(ax._mainMirrorPosition - pad * mainSign, -mainSign * ax.ticklen);
  43459. }
  43460. drawTicks(mainPlotinfo[axLetter + 'axislayer'], tickpath);
  43461. tickSubplots = Object.keys(ax._linepositions || {});
  43462. }
  43463. tickSubplots.map(function(subplot) {
  43464. var plotinfo = fullLayout._plots[subplot];
  43465. var container = plotinfo[axLetter + 'axislayer'];
  43466. // [bottom or left, top or right]
  43467. // free and main are handled above
  43468. var linepositions = ax._linepositions[subplot] || [];
  43469. function tickPathSide(sidei) {
  43470. var tsign = ticksign[sidei];
  43471. return tickpathfn(linepositions[sidei] + pad * tsign, tsign * ax.ticklen);
  43472. }
  43473. drawTicks(container, tickPathSide(0) + tickPathSide(1));
  43474. });
  43475. var mainContainer = mainPlotinfo[axLetter + 'axislayer'];
  43476. return drawLabels(mainContainer, ax._mainLinePosition);
  43477. }
  43478. };
  43479. axes.shouldShowZeroLine = function(gd, ax, counterAxis) {
  43480. var rng = Lib.simpleMap(ax.range, ax.r2l);
  43481. return (
  43482. (rng[0] * rng[1] <= 0) &&
  43483. ax.zeroline &&
  43484. (ax.type === 'linear' || ax.type === '-') &&
  43485. ax._valsClipped.length &&
  43486. (
  43487. clipEnds(ax, 0) ||
  43488. !anyCounterAxLineAtZero(gd, ax, counterAxis, rng) ||
  43489. hasBarsOrFill(gd, ax)
  43490. )
  43491. );
  43492. };
  43493. function clipEnds(ax, l) {
  43494. var p = ax.l2p(l);
  43495. return (p > 1 && p < ax._length - 1);
  43496. }
  43497. function anyCounterAxLineAtZero(gd, ax, counterAxis, rng) {
  43498. var mainCounterAxis = counterAxis._mainAxis;
  43499. if(!mainCounterAxis) return;
  43500. var fullLayout = gd._fullLayout;
  43501. var axLetter = ax._id.charAt(0);
  43502. var counterLetter = axes.counterLetter(ax._id);
  43503. var zeroPosition = ax._offset + (
  43504. ((Math.abs(rng[0]) < Math.abs(rng[1])) === (axLetter === 'x')) ?
  43505. 0 : ax._length
  43506. );
  43507. function lineNearZero(ax2) {
  43508. if(!ax2.showline || !ax2.linewidth) return false;
  43509. var tolerance = Math.max((ax2.linewidth + ax.zerolinewidth) / 2, 1);
  43510. function closeEnough(pos2) {
  43511. return typeof pos2 === 'number' && Math.abs(pos2 - zeroPosition) < tolerance;
  43512. }
  43513. if(closeEnough(ax2._mainLinePosition) || closeEnough(ax2._mainMirrorPosition)) {
  43514. return true;
  43515. }
  43516. var linePositions = ax2._linepositions || {};
  43517. for(var k in linePositions) {
  43518. if(closeEnough(linePositions[k][0]) || closeEnough(linePositions[k][1])) {
  43519. return true;
  43520. }
  43521. }
  43522. }
  43523. var plotinfo = fullLayout._plots[counterAxis._mainSubplot];
  43524. if(!(plotinfo.mainplotinfo || plotinfo).overlays.length) {
  43525. return lineNearZero(counterAxis, zeroPosition);
  43526. }
  43527. var counterLetterAxes = axes.list(gd, counterLetter);
  43528. for(var i = 0; i < counterLetterAxes.length; i++) {
  43529. var counterAxis2 = counterLetterAxes[i];
  43530. if(
  43531. counterAxis2._mainAxis === mainCounterAxis &&
  43532. lineNearZero(counterAxis2, zeroPosition)
  43533. ) {
  43534. return true;
  43535. }
  43536. }
  43537. }
  43538. function hasBarsOrFill(gd, ax) {
  43539. var fullData = gd._fullData;
  43540. var subplot = ax._mainSubplot;
  43541. var axLetter = ax._id.charAt(0);
  43542. for(var i = 0; i < fullData.length; i++) {
  43543. var trace = fullData[i];
  43544. if(trace.visible === true &&
  43545. (trace.xaxis + trace.yaxis) === subplot &&
  43546. (
  43547. Registry.traceIs(trace, 'bar') && trace.orientation === {x: 'h', y: 'v'}[axLetter] ||
  43548. trace.fill && trace.fill.charAt(trace.fill.length - 1) === axLetter
  43549. )
  43550. ) {
  43551. return true;
  43552. }
  43553. }
  43554. return false;
  43555. }
  43556. /**
  43557. * Find all margin pushers for 2D axes and reserve them for later use
  43558. * Both label and rangeslider automargin calculations happen later so
  43559. * we need to explicitly allow their ids in order to not delete them.
  43560. *
  43561. * TODO: can we pull the actual automargin calls forward to avoid this hack?
  43562. * We're probably also doing multiple redraws in this case, would be faster
  43563. * if we can just do the whole calculation ahead of time and draw once.
  43564. */
  43565. axes.allowAutoMargin = function(gd) {
  43566. var axList = axes.list(gd, '', true);
  43567. for(var i = 0; i < axList.length; i++) {
  43568. var ax = axList[i];
  43569. if(ax.automargin) {
  43570. Plots.allowAutoMargin(gd, ax._name + '.automargin');
  43571. }
  43572. if(ax.rangeslider && ax.rangeslider.visible) {
  43573. Plots.allowAutoMargin(gd, 'rangeslider' + ax._id);
  43574. }
  43575. }
  43576. };
  43577. // swap all the presentation attributes of the axes showing these traces
  43578. axes.swap = function(gd, traces) {
  43579. var axGroups = makeAxisGroups(gd, traces);
  43580. for(var i = 0; i < axGroups.length; i++) {
  43581. swapAxisGroup(gd, axGroups[i].x, axGroups[i].y);
  43582. }
  43583. };
  43584. function makeAxisGroups(gd, traces) {
  43585. var groups = [],
  43586. i,
  43587. j;
  43588. for(i = 0; i < traces.length; i++) {
  43589. var groupsi = [],
  43590. xi = gd._fullData[traces[i]].xaxis,
  43591. yi = gd._fullData[traces[i]].yaxis;
  43592. if(!xi || !yi) continue; // not a 2D cartesian trace?
  43593. for(j = 0; j < groups.length; j++) {
  43594. if(groups[j].x.indexOf(xi) !== -1 || groups[j].y.indexOf(yi) !== -1) {
  43595. groupsi.push(j);
  43596. }
  43597. }
  43598. if(!groupsi.length) {
  43599. groups.push({x: [xi], y: [yi]});
  43600. continue;
  43601. }
  43602. var group0 = groups[groupsi[0]],
  43603. groupj;
  43604. if(groupsi.length > 1) {
  43605. for(j = 1; j < groupsi.length; j++) {
  43606. groupj = groups[groupsi[j]];
  43607. mergeAxisGroups(group0.x, groupj.x);
  43608. mergeAxisGroups(group0.y, groupj.y);
  43609. }
  43610. }
  43611. mergeAxisGroups(group0.x, [xi]);
  43612. mergeAxisGroups(group0.y, [yi]);
  43613. }
  43614. return groups;
  43615. }
  43616. function mergeAxisGroups(intoSet, fromSet) {
  43617. for(var i = 0; i < fromSet.length; i++) {
  43618. if(intoSet.indexOf(fromSet[i]) === -1) intoSet.push(fromSet[i]);
  43619. }
  43620. }
  43621. function swapAxisGroup(gd, xIds, yIds) {
  43622. var i,
  43623. j,
  43624. xFullAxes = [],
  43625. yFullAxes = [],
  43626. layout = gd.layout;
  43627. for(i = 0; i < xIds.length; i++) xFullAxes.push(axes.getFromId(gd, xIds[i]));
  43628. for(i = 0; i < yIds.length; i++) yFullAxes.push(axes.getFromId(gd, yIds[i]));
  43629. var allAxKeys = Object.keys(axAttrs);
  43630. var noSwapAttrs = [
  43631. 'anchor', 'domain', 'overlaying', 'position', 'side', 'tickangle', 'editType'
  43632. ];
  43633. var numericTypes = ['linear', 'log'];
  43634. for(i = 0; i < allAxKeys.length; i++) {
  43635. var keyi = allAxKeys[i],
  43636. xVal = xFullAxes[0][keyi],
  43637. yVal = yFullAxes[0][keyi],
  43638. allEqual = true,
  43639. coerceLinearX = false,
  43640. coerceLinearY = false;
  43641. if(keyi.charAt(0) === '_' || typeof xVal === 'function' ||
  43642. noSwapAttrs.indexOf(keyi) !== -1) {
  43643. continue;
  43644. }
  43645. for(j = 1; j < xFullAxes.length && allEqual; j++) {
  43646. var xVali = xFullAxes[j][keyi];
  43647. if(keyi === 'type' && numericTypes.indexOf(xVal) !== -1 &&
  43648. numericTypes.indexOf(xVali) !== -1 && xVal !== xVali) {
  43649. // type is special - if we find a mixture of linear and log,
  43650. // coerce them all to linear on flipping
  43651. coerceLinearX = true;
  43652. }
  43653. else if(xVali !== xVal) allEqual = false;
  43654. }
  43655. for(j = 1; j < yFullAxes.length && allEqual; j++) {
  43656. var yVali = yFullAxes[j][keyi];
  43657. if(keyi === 'type' && numericTypes.indexOf(yVal) !== -1 &&
  43658. numericTypes.indexOf(yVali) !== -1 && yVal !== yVali) {
  43659. // type is special - if we find a mixture of linear and log,
  43660. // coerce them all to linear on flipping
  43661. coerceLinearY = true;
  43662. }
  43663. else if(yFullAxes[j][keyi] !== yVal) allEqual = false;
  43664. }
  43665. if(allEqual) {
  43666. if(coerceLinearX) layout[xFullAxes[0]._name].type = 'linear';
  43667. if(coerceLinearY) layout[yFullAxes[0]._name].type = 'linear';
  43668. swapAxisAttrs(layout, keyi, xFullAxes, yFullAxes, gd._fullLayout._dfltTitle);
  43669. }
  43670. }
  43671. // now swap x&y for any annotations anchored to these x & y
  43672. for(i = 0; i < gd._fullLayout.annotations.length; i++) {
  43673. var ann = gd._fullLayout.annotations[i];
  43674. if(xIds.indexOf(ann.xref) !== -1 &&
  43675. yIds.indexOf(ann.yref) !== -1) {
  43676. Lib.swapAttrs(layout.annotations[i], ['?']);
  43677. }
  43678. }
  43679. }
  43680. function swapAxisAttrs(layout, key, xFullAxes, yFullAxes, dfltTitle) {
  43681. // in case the value is the default for either axis,
  43682. // look at the first axis in each list and see if
  43683. // this key's value is undefined
  43684. var np = Lib.nestedProperty,
  43685. xVal = np(layout[xFullAxes[0]._name], key).get(),
  43686. yVal = np(layout[yFullAxes[0]._name], key).get(),
  43687. i;
  43688. if(key === 'title') {
  43689. // special handling of placeholder titles
  43690. if(xVal === dfltTitle.x) {
  43691. xVal = dfltTitle.y;
  43692. }
  43693. if(yVal === dfltTitle.y) {
  43694. yVal = dfltTitle.x;
  43695. }
  43696. }
  43697. for(i = 0; i < xFullAxes.length; i++) {
  43698. np(layout, xFullAxes[i]._name + '.' + key).set(yVal);
  43699. }
  43700. for(i = 0; i < yFullAxes.length; i++) {
  43701. np(layout, yFullAxes[i]._name + '.' + key).set(xVal);
  43702. }
  43703. }
  43704. function isAngular(ax) {
  43705. return ax._id === 'angularaxis';
  43706. }
  43707. },{"../../components/color":50,"../../components/drawing":75,"../../components/titles":141,"../../constants/alignment":148,"../../constants/numerical":151,"../../lib":169,"../../lib/svg_text_utils":191,"../../plots/plots":246,"../../registry":259,"./autorange":213,"./axis_autotype":215,"./axis_ids":217,"./layout_attributes":226,"./set_convert":232,"d3":16,"fast-isnumeric":18}],215:[function(_dereq_,module,exports){
  43708. /**
  43709. * Copyright 2012-2018, Plotly, Inc.
  43710. * All rights reserved.
  43711. *
  43712. * This source code is licensed under the MIT license found in the
  43713. * LICENSE file in the root directory of this source tree.
  43714. */
  43715. 'use strict';
  43716. var isNumeric = _dereq_('fast-isnumeric');
  43717. var Lib = _dereq_('../../lib');
  43718. var BADNUM = _dereq_('../../constants/numerical').BADNUM;
  43719. module.exports = function autoType(array, calendar) {
  43720. if(moreDates(array, calendar)) return 'date';
  43721. if(category(array)) return 'category';
  43722. if(linearOK(array)) return 'linear';
  43723. else return '-';
  43724. };
  43725. // is there at least one number in array? If not, we should leave
  43726. // ax.type empty so it can be autoset later
  43727. function linearOK(array) {
  43728. if(!array) return false;
  43729. for(var i = 0; i < array.length; i++) {
  43730. if(isNumeric(array[i])) return true;
  43731. }
  43732. return false;
  43733. }
  43734. // does the array a have mostly dates rather than numbers?
  43735. // note: some values can be neither (such as blanks, text)
  43736. // 2- or 4-digit integers can be both, so require twice as many
  43737. // dates as non-dates, to exclude cases with mostly 2 & 4 digit
  43738. // numbers and a few dates
  43739. function moreDates(a, calendar) {
  43740. var dcnt = 0,
  43741. ncnt = 0,
  43742. // test at most 1000 points, evenly spaced
  43743. inc = Math.max(1, (a.length - 1) / 1000),
  43744. ai;
  43745. for(var i = 0; i < a.length; i += inc) {
  43746. ai = a[Math.round(i)];
  43747. if(Lib.isDateTime(ai, calendar)) dcnt += 1;
  43748. if(isNumeric(ai)) ncnt += 1;
  43749. }
  43750. return (dcnt > ncnt * 2);
  43751. }
  43752. // are the (x,y)-values in gd.data mostly text?
  43753. // require twice as many categories as numbers
  43754. function category(a) {
  43755. // test at most 1000 points
  43756. var inc = Math.max(1, (a.length - 1) / 1000),
  43757. curvenums = 0,
  43758. curvecats = 0,
  43759. ai;
  43760. for(var i = 0; i < a.length; i += inc) {
  43761. ai = a[Math.round(i)];
  43762. if(Lib.cleanNumber(ai) !== BADNUM) curvenums++;
  43763. else if(typeof ai === 'string' && ai !== '' && ai !== 'None') curvecats++;
  43764. }
  43765. return curvecats > curvenums * 2;
  43766. }
  43767. },{"../../constants/numerical":151,"../../lib":169,"fast-isnumeric":18}],216:[function(_dereq_,module,exports){
  43768. /**
  43769. * Copyright 2012-2018, Plotly, Inc.
  43770. * All rights reserved.
  43771. *
  43772. * This source code is licensed under the MIT license found in the
  43773. * LICENSE file in the root directory of this source tree.
  43774. */
  43775. 'use strict';
  43776. var Registry = _dereq_('../../registry');
  43777. var Lib = _dereq_('../../lib');
  43778. var layoutAttributes = _dereq_('./layout_attributes');
  43779. var handleTickValueDefaults = _dereq_('./tick_value_defaults');
  43780. var handleTickMarkDefaults = _dereq_('./tick_mark_defaults');
  43781. var handleTickLabelDefaults = _dereq_('./tick_label_defaults');
  43782. var handleCategoryOrderDefaults = _dereq_('./category_order_defaults');
  43783. var handleLineGridDefaults = _dereq_('./line_grid_defaults');
  43784. var setConvert = _dereq_('./set_convert');
  43785. /**
  43786. * options: object containing:
  43787. *
  43788. * letter: 'x' or 'y'
  43789. * title: name of the axis (ie 'Colorbar') to go in default title
  43790. * font: the default font to inherit
  43791. * outerTicks: boolean, should ticks default to outside?
  43792. * showGrid: boolean, should gridlines be shown by default?
  43793. * noHover: boolean, this axis doesn't support hover effects?
  43794. * data: the plot data, used to manage categories
  43795. * bgColor: the plot background color, to calculate default gridline colors
  43796. */
  43797. module.exports = function handleAxisDefaults(containerIn, containerOut, coerce, options, layoutOut) {
  43798. var letter = options.letter;
  43799. var font = options.font || {};
  43800. var splomStash = options.splomStash || {};
  43801. var visible = coerce('visible', !options.cheateronly);
  43802. var axType = containerOut.type;
  43803. if(axType === 'date') {
  43804. var handleCalendarDefaults = Registry.getComponentMethod('calendars', 'handleDefaults');
  43805. handleCalendarDefaults(containerIn, containerOut, 'calendar', options.calendar);
  43806. }
  43807. setConvert(containerOut, layoutOut);
  43808. var autoRange = coerce('autorange', !containerOut.isValidRange(containerIn.range));
  43809. if(autoRange && (axType === 'linear' || axType === '-')) coerce('rangemode');
  43810. coerce('range');
  43811. containerOut.cleanRange();
  43812. handleCategoryOrderDefaults(containerIn, containerOut, coerce, options);
  43813. if(axType !== 'category' && !options.noHover) coerce('hoverformat');
  43814. if(!visible) return containerOut;
  43815. var dfltColor = coerce('color');
  43816. // if axis.color was provided, use it for fonts too; otherwise,
  43817. // inherit from global font color in case that was provided.
  43818. // Compare to dflt rather than to containerIn, so we can provide color via
  43819. // template too.
  43820. var dfltFontColor = (dfltColor !== layoutAttributes.color.dflt) ? dfltColor : font.color;
  43821. // try to get default title from splom trace, fallback to graph-wide value
  43822. var dfltTitle = splomStash.label || layoutOut._dfltTitle[letter];
  43823. coerce('title', dfltTitle);
  43824. Lib.coerceFont(coerce, 'titlefont', {
  43825. family: font.family,
  43826. size: Math.round(font.size * 1.2),
  43827. color: dfltFontColor
  43828. });
  43829. handleTickValueDefaults(containerIn, containerOut, coerce, axType);
  43830. handleTickLabelDefaults(containerIn, containerOut, coerce, axType, options);
  43831. handleTickMarkDefaults(containerIn, containerOut, coerce, options);
  43832. handleLineGridDefaults(containerIn, containerOut, coerce, {
  43833. dfltColor: dfltColor,
  43834. bgColor: options.bgColor,
  43835. showGrid: options.showGrid,
  43836. attributes: layoutAttributes
  43837. });
  43838. if(containerOut.showline || containerOut.ticks) coerce('mirror');
  43839. if(options.automargin) coerce('automargin');
  43840. return containerOut;
  43841. };
  43842. },{"../../lib":169,"../../registry":259,"./category_order_defaults":218,"./layout_attributes":226,"./line_grid_defaults":228,"./set_convert":232,"./tick_label_defaults":233,"./tick_mark_defaults":234,"./tick_value_defaults":235}],217:[function(_dereq_,module,exports){
  43843. /**
  43844. * Copyright 2012-2018, Plotly, Inc.
  43845. * All rights reserved.
  43846. *
  43847. * This source code is licensed under the MIT license found in the
  43848. * LICENSE file in the root directory of this source tree.
  43849. */
  43850. 'use strict';
  43851. var Registry = _dereq_('../../registry');
  43852. var constants = _dereq_('./constants');
  43853. // convert between axis names (xaxis, xaxis2, etc, elements of gd.layout)
  43854. // and axis id's (x, x2, etc). Would probably have ditched 'xaxis'
  43855. // completely in favor of just 'x' if it weren't ingrained in the API etc.
  43856. exports.id2name = function id2name(id) {
  43857. if(typeof id !== 'string' || !id.match(constants.AX_ID_PATTERN)) return;
  43858. var axNum = id.substr(1);
  43859. if(axNum === '1') axNum = '';
  43860. return id.charAt(0) + 'axis' + axNum;
  43861. };
  43862. exports.name2id = function name2id(name) {
  43863. if(!name.match(constants.AX_NAME_PATTERN)) return;
  43864. var axNum = name.substr(5);
  43865. if(axNum === '1') axNum = '';
  43866. return name.charAt(0) + axNum;
  43867. };
  43868. exports.cleanId = function cleanId(id, axLetter) {
  43869. if(!id.match(constants.AX_ID_PATTERN)) return;
  43870. if(axLetter && id.charAt(0) !== axLetter) return;
  43871. var axNum = id.substr(1).replace(/^0+/, '');
  43872. if(axNum === '1') axNum = '';
  43873. return id.charAt(0) + axNum;
  43874. };
  43875. // get all axis objects, as restricted in listNames
  43876. exports.list = function(gd, axLetter, only2d) {
  43877. var fullLayout = gd._fullLayout;
  43878. if(!fullLayout) return [];
  43879. var idList = exports.listIds(gd, axLetter);
  43880. var out = new Array(idList.length);
  43881. var i;
  43882. for(i = 0; i < idList.length; i++) {
  43883. var idi = idList[i];
  43884. out[i] = fullLayout[idi.charAt(0) + 'axis' + idi.substr(1)];
  43885. }
  43886. if(!only2d) {
  43887. var sceneIds3D = fullLayout._subplots.gl3d || [];
  43888. for(i = 0; i < sceneIds3D.length; i++) {
  43889. var scene = fullLayout[sceneIds3D[i]];
  43890. if(axLetter) out.push(scene[axLetter + 'axis']);
  43891. else out.push(scene.xaxis, scene.yaxis, scene.zaxis);
  43892. }
  43893. }
  43894. return out;
  43895. };
  43896. // get all axis ids, optionally restricted by letter
  43897. // this only makes sense for 2d axes
  43898. exports.listIds = function(gd, axLetter) {
  43899. var fullLayout = gd._fullLayout;
  43900. if(!fullLayout) return [];
  43901. var subplotLists = fullLayout._subplots;
  43902. if(axLetter) return subplotLists[axLetter + 'axis'];
  43903. return subplotLists.xaxis.concat(subplotLists.yaxis);
  43904. };
  43905. // get an axis object from its id 'x','x2' etc
  43906. // optionally, id can be a subplot (ie 'x2y3') and type gets x or y from it
  43907. exports.getFromId = function(gd, id, type) {
  43908. var fullLayout = gd._fullLayout;
  43909. if(type === 'x') id = id.replace(/y[0-9]*/, '');
  43910. else if(type === 'y') id = id.replace(/x[0-9]*/, '');
  43911. return fullLayout[exports.id2name(id)];
  43912. };
  43913. // get an axis object of specified type from the containing trace
  43914. exports.getFromTrace = function(gd, fullTrace, type) {
  43915. var fullLayout = gd._fullLayout;
  43916. var ax = null;
  43917. if(Registry.traceIs(fullTrace, 'gl3d')) {
  43918. var scene = fullTrace.scene;
  43919. if(scene.substr(0, 5) === 'scene') {
  43920. ax = fullLayout[scene][type + 'axis'];
  43921. }
  43922. }
  43923. else {
  43924. ax = exports.getFromId(gd, fullTrace[type + 'axis'] || type);
  43925. }
  43926. return ax;
  43927. };
  43928. // sort x, x2, x10, y, y2, y10...
  43929. exports.idSort = function(id1, id2) {
  43930. var letter1 = id1.charAt(0);
  43931. var letter2 = id2.charAt(0);
  43932. if(letter1 !== letter2) return letter1 > letter2 ? 1 : -1;
  43933. return +(id1.substr(1) || 1) - +(id2.substr(1) || 1);
  43934. };
  43935. },{"../../registry":259,"./constants":219}],218:[function(_dereq_,module,exports){
  43936. /**
  43937. * Copyright 2012-2018, Plotly, Inc.
  43938. * All rights reserved.
  43939. *
  43940. * This source code is licensed under the MIT license found in the
  43941. * LICENSE file in the root directory of this source tree.
  43942. */
  43943. 'use strict';
  43944. function findCategories(ax, opts) {
  43945. var dataAttr = opts.dataAttr || ax._id.charAt(0);
  43946. var lookup = {};
  43947. var axData;
  43948. var i, j;
  43949. if(opts.axData) {
  43950. // non-x/y case
  43951. axData = opts.axData;
  43952. } else {
  43953. // x/y case
  43954. axData = [];
  43955. for(i = 0; i < opts.data.length; i++) {
  43956. var trace = opts.data[i];
  43957. if(trace[dataAttr + 'axis'] === ax._id) {
  43958. axData.push(trace);
  43959. }
  43960. }
  43961. }
  43962. for(i = 0; i < axData.length; i++) {
  43963. var vals = axData[i][dataAttr];
  43964. for(j = 0; j < vals.length; j++) {
  43965. var v = vals[j];
  43966. if(v !== null && v !== undefined) {
  43967. lookup[v] = 1;
  43968. }
  43969. }
  43970. }
  43971. return Object.keys(lookup);
  43972. }
  43973. /**
  43974. * Fills in category* default and initial categories.
  43975. *
  43976. * @param {object} containerIn : input axis object
  43977. * @param {object} containerOut : full axis object
  43978. * @param {function} coerce : Lib.coerce fn wrapper
  43979. * @param {object} opts :
  43980. * - data {array} : (full) data trace
  43981. * OR
  43982. * - axData {array} : (full) data associated with axis being coerced here
  43983. * - dataAttr {string} : attribute name corresponding to coordinate array
  43984. */
  43985. module.exports = function handleCategoryOrderDefaults(containerIn, containerOut, coerce, opts) {
  43986. if(containerOut.type !== 'category') return;
  43987. var arrayIn = containerIn.categoryarray;
  43988. var isValidArray = (Array.isArray(arrayIn) && arrayIn.length > 0);
  43989. // override default 'categoryorder' value when non-empty array is supplied
  43990. var orderDefault;
  43991. if(isValidArray) orderDefault = 'array';
  43992. var order = coerce('categoryorder', orderDefault);
  43993. var array;
  43994. // coerce 'categoryarray' only in array order case
  43995. if(order === 'array') {
  43996. array = coerce('categoryarray');
  43997. }
  43998. // cannot set 'categoryorder' to 'array' with an invalid 'categoryarray'
  43999. if(!isValidArray && order === 'array') {
  44000. order = containerOut.categoryorder = 'trace';
  44001. }
  44002. // set up things for makeCalcdata
  44003. if(order === 'trace') {
  44004. containerOut._initialCategories = [];
  44005. } else if(order === 'array') {
  44006. containerOut._initialCategories = array.slice();
  44007. } else {
  44008. array = findCategories(containerOut, opts).sort();
  44009. if(order === 'category ascending') {
  44010. containerOut._initialCategories = array;
  44011. } else if(order === 'category descending') {
  44012. containerOut._initialCategories = array.reverse();
  44013. }
  44014. }
  44015. };
  44016. },{}],219:[function(_dereq_,module,exports){
  44017. /**
  44018. * Copyright 2012-2018, Plotly, Inc.
  44019. * All rights reserved.
  44020. *
  44021. * This source code is licensed under the MIT license found in the
  44022. * LICENSE file in the root directory of this source tree.
  44023. */
  44024. 'use strict';
  44025. var counterRegex = _dereq_('../../lib/regex').counter;
  44026. module.exports = {
  44027. idRegex: {
  44028. x: counterRegex('x'),
  44029. y: counterRegex('y')
  44030. },
  44031. attrRegex: counterRegex('[xy]axis'),
  44032. // axis match regular expression
  44033. xAxisMatch: counterRegex('xaxis'),
  44034. yAxisMatch: counterRegex('yaxis'),
  44035. // pattern matching axis ids and names
  44036. // note that this is more permissive than counterRegex, as
  44037. // id2name, name2id, and cleanId accept "x1" etc
  44038. AX_ID_PATTERN: /^[xyz][0-9]*$/,
  44039. AX_NAME_PATTERN: /^[xyz]axis[0-9]*$/,
  44040. // and for 2D subplots
  44041. SUBPLOT_PATTERN: /^x([0-9]*)y([0-9]*)$/,
  44042. // pixels to move mouse before you stop clamping to starting point
  44043. MINDRAG: 8,
  44044. // smallest dimension allowed for a select box
  44045. MINSELECT: 12,
  44046. // smallest dimension allowed for a zoombox
  44047. MINZOOM: 20,
  44048. // width of axis drag regions
  44049. DRAGGERSIZE: 20,
  44050. // max pixels off straight before a lasso select line counts as bent
  44051. BENDPX: 1.5,
  44052. // delay before a redraw (relayout) after smooth panning and zooming
  44053. REDRAWDELAY: 50,
  44054. // throttling limit (ms) for selectPoints calls
  44055. SELECTDELAY: 100,
  44056. // cache ID suffix for throttle
  44057. SELECTID: '-select',
  44058. // last resort axis ranges for x and y axes if we have no data
  44059. DFLTRANGEX: [-1, 6],
  44060. DFLTRANGEY: [-1, 4],
  44061. // Layers to keep trace types in the right order
  44062. // N.B. each 'unique' plot method must have its own layer
  44063. traceLayerClasses: [
  44064. 'heatmaplayer',
  44065. 'contourcarpetlayer', 'contourlayer',
  44066. 'barlayer',
  44067. 'carpetlayer',
  44068. 'violinlayer',
  44069. 'boxlayer',
  44070. 'ohlclayer',
  44071. 'scattercarpetlayer', 'scatterlayer'
  44072. ],
  44073. layerValue2layerClass: {
  44074. 'above traces': 'above',
  44075. 'below traces': 'below'
  44076. }
  44077. };
  44078. },{"../../lib/regex":185}],220:[function(_dereq_,module,exports){
  44079. /**
  44080. * Copyright 2012-2018, Plotly, Inc.
  44081. * All rights reserved.
  44082. *
  44083. * This source code is licensed under the MIT license found in the
  44084. * LICENSE file in the root directory of this source tree.
  44085. */
  44086. 'use strict';
  44087. var Lib = _dereq_('../../lib');
  44088. var id2name = _dereq_('./axis_ids').id2name;
  44089. module.exports = function handleConstraintDefaults(containerIn, containerOut, coerce, allAxisIds, layoutOut) {
  44090. var constraintGroups = layoutOut._axisConstraintGroups;
  44091. var thisID = containerOut._id;
  44092. var letter = thisID.charAt(0);
  44093. if(containerOut.fixedrange) return;
  44094. // coerce the constraint mechanics even if this axis has no scaleanchor
  44095. // because it may be the anchor of another axis.
  44096. coerce('constrain');
  44097. Lib.coerce(containerIn, containerOut, {
  44098. constraintoward: {
  44099. valType: 'enumerated',
  44100. values: letter === 'x' ? ['left', 'center', 'right'] : ['bottom', 'middle', 'top'],
  44101. dflt: letter === 'x' ? 'center' : 'middle'
  44102. }
  44103. }, 'constraintoward');
  44104. if(!containerIn.scaleanchor) return;
  44105. var constraintOpts = getConstraintOpts(constraintGroups, thisID, allAxisIds, layoutOut);
  44106. var scaleanchor = Lib.coerce(containerIn, containerOut, {
  44107. scaleanchor: {
  44108. valType: 'enumerated',
  44109. values: constraintOpts.linkableAxes
  44110. }
  44111. }, 'scaleanchor');
  44112. if(scaleanchor) {
  44113. var scaleratio = coerce('scaleratio');
  44114. // TODO: I suppose I could do attribute.min: Number.MIN_VALUE to avoid zero,
  44115. // but that seems hacky. Better way to say "must be a positive number"?
  44116. // Of course if you use several super-tiny values you could eventually
  44117. // force a product of these to zero and all hell would break loose...
  44118. // Likewise with super-huge values.
  44119. if(!scaleratio) scaleratio = containerOut.scaleratio = 1;
  44120. updateConstraintGroups(constraintGroups, constraintOpts.thisGroup,
  44121. thisID, scaleanchor, scaleratio);
  44122. }
  44123. else if(allAxisIds.indexOf(containerIn.scaleanchor) !== -1) {
  44124. Lib.warn('ignored ' + containerOut._name + '.scaleanchor: "' +
  44125. containerIn.scaleanchor + '" to avoid either an infinite loop ' +
  44126. 'and possibly inconsistent scaleratios, or because the target' +
  44127. 'axis has fixed range.');
  44128. }
  44129. };
  44130. function getConstraintOpts(constraintGroups, thisID, allAxisIds, layoutOut) {
  44131. // If this axis is already part of a constraint group, we can't
  44132. // scaleanchor any other axis in that group, or we'd make a loop.
  44133. // Filter allAxisIds to enforce this, also matching axis types.
  44134. var thisType = layoutOut[id2name(thisID)].type;
  44135. var i, j, idj, axj;
  44136. var linkableAxes = [];
  44137. for(j = 0; j < allAxisIds.length; j++) {
  44138. idj = allAxisIds[j];
  44139. if(idj === thisID) continue;
  44140. axj = layoutOut[id2name(idj)];
  44141. if(axj.type === thisType && !axj.fixedrange) linkableAxes.push(idj);
  44142. }
  44143. for(i = 0; i < constraintGroups.length; i++) {
  44144. if(constraintGroups[i][thisID]) {
  44145. var thisGroup = constraintGroups[i];
  44146. var linkableAxesNoLoops = [];
  44147. for(j = 0; j < linkableAxes.length; j++) {
  44148. idj = linkableAxes[j];
  44149. if(!thisGroup[idj]) linkableAxesNoLoops.push(idj);
  44150. }
  44151. return {linkableAxes: linkableAxesNoLoops, thisGroup: thisGroup};
  44152. }
  44153. }
  44154. return {linkableAxes: linkableAxes, thisGroup: null};
  44155. }
  44156. /*
  44157. * Add this axis to the axis constraint groups, which is the collection
  44158. * of axes that are all constrained together on scale.
  44159. *
  44160. * constraintGroups: a list of objects. each object is
  44161. * {axis_id: scale_within_group}, where scale_within_group is
  44162. * only important relative to the rest of the group, and defines
  44163. * the relative scales between all axes in the group
  44164. *
  44165. * thisGroup: the group the current axis is already in
  44166. * thisID: the id if the current axis
  44167. * scaleanchor: the id of the axis to scale it with
  44168. * scaleratio: the ratio of this axis to the scaleanchor axis
  44169. */
  44170. function updateConstraintGroups(constraintGroups, thisGroup, thisID, scaleanchor, scaleratio) {
  44171. var i, j, groupi, keyj, thisGroupIndex;
  44172. if(thisGroup === null) {
  44173. thisGroup = {};
  44174. thisGroup[thisID] = 1;
  44175. thisGroupIndex = constraintGroups.length;
  44176. constraintGroups.push(thisGroup);
  44177. }
  44178. else {
  44179. thisGroupIndex = constraintGroups.indexOf(thisGroup);
  44180. }
  44181. var thisGroupKeys = Object.keys(thisGroup);
  44182. // we know that this axis isn't in any other groups, but we don't know
  44183. // about the scaleanchor axis. If it is, we need to merge the groups.
  44184. for(i = 0; i < constraintGroups.length; i++) {
  44185. groupi = constraintGroups[i];
  44186. if(i !== thisGroupIndex && groupi[scaleanchor]) {
  44187. var baseScale = groupi[scaleanchor];
  44188. for(j = 0; j < thisGroupKeys.length; j++) {
  44189. keyj = thisGroupKeys[j];
  44190. groupi[keyj] = baseScale * scaleratio * thisGroup[keyj];
  44191. }
  44192. constraintGroups.splice(thisGroupIndex, 1);
  44193. return;
  44194. }
  44195. }
  44196. // otherwise, we insert the new scaleanchor axis as the base scale (1)
  44197. // in its group, and scale the rest of the group to it
  44198. if(scaleratio !== 1) {
  44199. for(j = 0; j < thisGroupKeys.length; j++) {
  44200. thisGroup[thisGroupKeys[j]] *= scaleratio;
  44201. }
  44202. }
  44203. thisGroup[scaleanchor] = 1;
  44204. }
  44205. },{"../../lib":169,"./axis_ids":217}],221:[function(_dereq_,module,exports){
  44206. /**
  44207. * Copyright 2012-2018, Plotly, Inc.
  44208. * All rights reserved.
  44209. *
  44210. * This source code is licensed under the MIT license found in the
  44211. * LICENSE file in the root directory of this source tree.
  44212. */
  44213. 'use strict';
  44214. var id2name = _dereq_('./axis_ids').id2name;
  44215. var scaleZoom = _dereq_('./scale_zoom');
  44216. var makePadFn = _dereq_('./autorange').makePadFn;
  44217. var concatExtremes = _dereq_('./autorange').concatExtremes;
  44218. var ALMOST_EQUAL = _dereq_('../../constants/numerical').ALMOST_EQUAL;
  44219. var FROM_BL = _dereq_('../../constants/alignment').FROM_BL;
  44220. exports.enforce = function enforceAxisConstraints(gd) {
  44221. var fullLayout = gd._fullLayout;
  44222. var constraintGroups = fullLayout._axisConstraintGroups || [];
  44223. var i, j, axisID, ax, normScale, mode, factor;
  44224. for(i = 0; i < constraintGroups.length; i++) {
  44225. var group = constraintGroups[i];
  44226. var axisIDs = Object.keys(group);
  44227. var minScale = Infinity;
  44228. var maxScale = 0;
  44229. // mostly matchScale will be the same as minScale
  44230. // ie we expand axis ranges to encompass *everything*
  44231. // that's currently in any of their ranges, but during
  44232. // autorange of a subset of axes we will ignore other
  44233. // axes for this purpose.
  44234. var matchScale = Infinity;
  44235. var normScales = {};
  44236. var axes = {};
  44237. var hasAnyDomainConstraint = false;
  44238. // find the (normalized) scale of each axis in the group
  44239. for(j = 0; j < axisIDs.length; j++) {
  44240. axisID = axisIDs[j];
  44241. axes[axisID] = ax = fullLayout[id2name(axisID)];
  44242. if(ax._inputDomain) ax.domain = ax._inputDomain.slice();
  44243. else ax._inputDomain = ax.domain.slice();
  44244. if(!ax._inputRange) ax._inputRange = ax.range.slice();
  44245. // set axis scale here so we can use _m rather than
  44246. // having to calculate it from length and range
  44247. ax.setScale();
  44248. // abs: inverted scales still satisfy the constraint
  44249. normScales[axisID] = normScale = Math.abs(ax._m) / group[axisID];
  44250. minScale = Math.min(minScale, normScale);
  44251. if(ax.constrain === 'domain' || !ax._constraintShrinkable) {
  44252. matchScale = Math.min(matchScale, normScale);
  44253. }
  44254. // this has served its purpose, so remove it
  44255. delete ax._constraintShrinkable;
  44256. maxScale = Math.max(maxScale, normScale);
  44257. if(ax.constrain === 'domain') hasAnyDomainConstraint = true;
  44258. }
  44259. // Do we have a constraint mismatch? Give a small buffer for rounding errors
  44260. if(minScale > ALMOST_EQUAL * maxScale && !hasAnyDomainConstraint) continue;
  44261. // now increase any ranges we need to until all normalized scales are equal
  44262. for(j = 0; j < axisIDs.length; j++) {
  44263. axisID = axisIDs[j];
  44264. normScale = normScales[axisID];
  44265. ax = axes[axisID];
  44266. mode = ax.constrain;
  44267. // even if the scale didn't change, if we're shrinking domain
  44268. // we need to recalculate in case `constraintoward` changed
  44269. if(normScale !== matchScale || mode === 'domain') {
  44270. factor = normScale / matchScale;
  44271. if(mode === 'range') {
  44272. scaleZoom(ax, factor);
  44273. }
  44274. else {
  44275. // mode === 'domain'
  44276. var inputDomain = ax._inputDomain;
  44277. var domainShrunk = (ax.domain[1] - ax.domain[0]) /
  44278. (inputDomain[1] - inputDomain[0]);
  44279. var rangeShrunk = (ax.r2l(ax.range[1]) - ax.r2l(ax.range[0])) /
  44280. (ax.r2l(ax._inputRange[1]) - ax.r2l(ax._inputRange[0]));
  44281. factor /= domainShrunk;
  44282. if(factor * rangeShrunk < 1) {
  44283. // we've asked to magnify the axis more than we can just by
  44284. // enlarging the domain - so we need to constrict range
  44285. ax.domain = ax._input.domain = inputDomain.slice();
  44286. scaleZoom(ax, factor);
  44287. continue;
  44288. }
  44289. if(rangeShrunk < 1) {
  44290. // the range has previously been constricted by ^^, but we've
  44291. // switched to the domain-constricted regime, so reset range
  44292. ax.range = ax._input.range = ax._inputRange.slice();
  44293. factor *= rangeShrunk;
  44294. }
  44295. if(ax.autorange) {
  44296. /*
  44297. * range & factor may need to change because range was
  44298. * calculated for the larger scaling, so some pixel
  44299. * paddings may get cut off when we reduce the domain.
  44300. *
  44301. * This is easier than the regular autorange calculation
  44302. * because we already know the scaling `m`, but we still
  44303. * need to cut out impossible constraints (like
  44304. * annotations with super-long arrows). That's what
  44305. * outerMin/Max are for - if the expansion was going to
  44306. * go beyond the original domain, it must be impossible
  44307. */
  44308. var rl0 = ax.r2l(ax.range[0]);
  44309. var rl1 = ax.r2l(ax.range[1]);
  44310. var rangeCenter = (rl0 + rl1) / 2;
  44311. var rangeMin = rangeCenter;
  44312. var rangeMax = rangeCenter;
  44313. var halfRange = Math.abs(rl1 - rangeCenter);
  44314. // extra tiny bit for rounding errors, in case we actually
  44315. // *are* expanding to the full domain
  44316. var outerMin = rangeCenter - halfRange * factor * 1.0001;
  44317. var outerMax = rangeCenter + halfRange * factor * 1.0001;
  44318. var getPad = makePadFn(ax);
  44319. updateDomain(ax, factor);
  44320. ax.setScale();
  44321. var m = Math.abs(ax._m);
  44322. var extremes = concatExtremes(gd, ax);
  44323. var minArray = extremes.min;
  44324. var maxArray = extremes.max;
  44325. var newVal;
  44326. var k;
  44327. for(k = 0; k < minArray.length; k++) {
  44328. newVal = minArray[k].val - getPad(minArray[k]) / m;
  44329. if(newVal > outerMin && newVal < rangeMin) {
  44330. rangeMin = newVal;
  44331. }
  44332. }
  44333. for(k = 0; k < maxArray.length; k++) {
  44334. newVal = maxArray[k].val + getPad(maxArray[k]) / m;
  44335. if(newVal < outerMax && newVal > rangeMax) {
  44336. rangeMax = newVal;
  44337. }
  44338. }
  44339. var domainExpand = (rangeMax - rangeMin) / (2 * halfRange);
  44340. factor /= domainExpand;
  44341. rangeMin = ax.l2r(rangeMin);
  44342. rangeMax = ax.l2r(rangeMax);
  44343. ax.range = ax._input.range = (rl0 < rl1) ?
  44344. [rangeMin, rangeMax] : [rangeMax, rangeMin];
  44345. }
  44346. updateDomain(ax, factor);
  44347. }
  44348. }
  44349. }
  44350. }
  44351. };
  44352. // For use before autoranging, check if this axis was previously constrained
  44353. // by domain but no longer is
  44354. exports.clean = function cleanConstraints(gd, ax) {
  44355. if(ax._inputDomain) {
  44356. var isConstrained = false;
  44357. var axId = ax._id;
  44358. var constraintGroups = gd._fullLayout._axisConstraintGroups;
  44359. for(var j = 0; j < constraintGroups.length; j++) {
  44360. if(constraintGroups[j][axId]) {
  44361. isConstrained = true;
  44362. break;
  44363. }
  44364. }
  44365. if(!isConstrained || ax.constrain !== 'domain') {
  44366. ax._input.domain = ax.domain = ax._inputDomain;
  44367. delete ax._inputDomain;
  44368. }
  44369. }
  44370. };
  44371. function updateDomain(ax, factor) {
  44372. var inputDomain = ax._inputDomain;
  44373. var centerFraction = FROM_BL[ax.constraintoward];
  44374. var center = inputDomain[0] + (inputDomain[1] - inputDomain[0]) * centerFraction;
  44375. ax.domain = ax._input.domain = [
  44376. center + (inputDomain[0] - center) / factor,
  44377. center + (inputDomain[1] - center) / factor
  44378. ];
  44379. }
  44380. },{"../../constants/alignment":148,"../../constants/numerical":151,"./autorange":213,"./axis_ids":217,"./scale_zoom":230}],222:[function(_dereq_,module,exports){
  44381. /**
  44382. * Copyright 2012-2018, Plotly, Inc.
  44383. * All rights reserved.
  44384. *
  44385. * This source code is licensed under the MIT license found in the
  44386. * LICENSE file in the root directory of this source tree.
  44387. */
  44388. 'use strict';
  44389. var d3 = _dereq_('d3');
  44390. var tinycolor = _dereq_('tinycolor2');
  44391. var supportsPassive = _dereq_('has-passive-events');
  44392. var Registry = _dereq_('../../registry');
  44393. var Lib = _dereq_('../../lib');
  44394. var svgTextUtils = _dereq_('../../lib/svg_text_utils');
  44395. var clearGlCanvases = _dereq_('../../lib/clear_gl_canvases');
  44396. var Color = _dereq_('../../components/color');
  44397. var Drawing = _dereq_('../../components/drawing');
  44398. var Fx = _dereq_('../../components/fx');
  44399. var setCursor = _dereq_('../../lib/setcursor');
  44400. var dragElement = _dereq_('../../components/dragelement');
  44401. var FROM_TL = _dereq_('../../constants/alignment').FROM_TL;
  44402. var Plots = _dereq_('../plots');
  44403. var doTicksSingle = _dereq_('./axes').doTicksSingle;
  44404. var getFromId = _dereq_('./axis_ids').getFromId;
  44405. var prepSelect = _dereq_('./select').prepSelect;
  44406. var clearSelect = _dereq_('./select').clearSelect;
  44407. var selectOnClick = _dereq_('./select').selectOnClick;
  44408. var scaleZoom = _dereq_('./scale_zoom');
  44409. var constants = _dereq_('./constants');
  44410. var MINDRAG = constants.MINDRAG;
  44411. var MINZOOM = constants.MINZOOM;
  44412. // flag for showing "doubleclick to zoom out" only at the beginning
  44413. var SHOWZOOMOUTTIP = true;
  44414. // dragBox: create an element to drag one or more axis ends
  44415. // inputs:
  44416. // plotinfo - which subplot are we making dragboxes on?
  44417. // x,y,w,h - left, top, width, height of the box
  44418. // ns - how does this drag the vertical axis?
  44419. // 'n' - top only
  44420. // 's' - bottom only
  44421. // 'ns' - top and bottom together, difference unchanged
  44422. // ew - same for horizontal axis
  44423. function makeDragBox(gd, plotinfo, x, y, w, h, ns, ew) {
  44424. // mouseDown stores ms of first mousedown event in the last
  44425. // DBLCLICKDELAY ms on the drag bars
  44426. // numClicks stores how many mousedowns have been seen
  44427. // within DBLCLICKDELAY so we can check for click or doubleclick events
  44428. // dragged stores whether a drag has occurred, so we don't have to
  44429. // redraw unnecessarily, ie if no move bigger than MINDRAG or MINZOOM px
  44430. var zoomlayer = gd._fullLayout._zoomlayer;
  44431. var isMainDrag = (ns + ew === 'nsew');
  44432. var singleEnd = (ns + ew).length === 1;
  44433. // main subplot x and y (i.e. found in plotinfo - the main ones)
  44434. var xa0, ya0;
  44435. // {ax._id: ax} hash objects
  44436. var xaHash, yaHash;
  44437. // xaHash/yaHash values (arrays)
  44438. var xaxes, yaxes;
  44439. // main axis offsets
  44440. var xs, ys;
  44441. // main axis lengths
  44442. var pw, ph;
  44443. // contains keys 'xaHash', 'yaHash', 'xaxes', and 'yaxes'
  44444. // which are the x/y {ax._id: ax} hash objects and their values
  44445. // for linked axis relative to this subplot
  44446. var links;
  44447. // set to ew/ns val when active, set to '' when inactive
  44448. var xActive, yActive;
  44449. // are all axes in this subplot are fixed?
  44450. var allFixedRanges;
  44451. // is subplot constrained?
  44452. var isSubplotConstrained;
  44453. // do we need to edit x/y ranges?
  44454. var editX, editY;
  44455. // graph-wide optimization flags
  44456. var hasScatterGl, hasOnlyLargeSploms, hasSplom, hasSVG;
  44457. // collected changes to be made to the plot by relayout at the end
  44458. var updates;
  44459. function recomputeAxisLists() {
  44460. xa0 = plotinfo.xaxis;
  44461. ya0 = plotinfo.yaxis;
  44462. pw = xa0._length;
  44463. ph = ya0._length;
  44464. xs = xa0._offset;
  44465. ys = ya0._offset;
  44466. xaHash = {};
  44467. xaHash[xa0._id] = xa0;
  44468. yaHash = {};
  44469. yaHash[ya0._id] = ya0;
  44470. // if we're dragging two axes at once, also drag overlays
  44471. if(ns && ew) {
  44472. var overlays = plotinfo.overlays;
  44473. for(var i = 0; i < overlays.length; i++) {
  44474. var xa = overlays[i].xaxis;
  44475. xaHash[xa._id] = xa;
  44476. var ya = overlays[i].yaxis;
  44477. yaHash[ya._id] = ya;
  44478. }
  44479. }
  44480. xaxes = hashValues(xaHash);
  44481. yaxes = hashValues(yaHash);
  44482. xActive = isDirectionActive(xaxes, ew);
  44483. yActive = isDirectionActive(yaxes, ns);
  44484. allFixedRanges = !yActive && !xActive;
  44485. links = calcLinks(gd, xaHash, yaHash);
  44486. isSubplotConstrained = links.isSubplotConstrained;
  44487. editX = ew || isSubplotConstrained;
  44488. editY = ns || isSubplotConstrained;
  44489. var fullLayout = gd._fullLayout;
  44490. hasScatterGl = fullLayout._has('scattergl');
  44491. hasOnlyLargeSploms = fullLayout._hasOnlyLargeSploms;
  44492. hasSplom = hasOnlyLargeSploms || fullLayout._has('splom');
  44493. hasSVG = fullLayout._has('svg');
  44494. }
  44495. recomputeAxisLists();
  44496. var cursor = getDragCursor(yActive + xActive, gd._fullLayout.dragmode, isMainDrag);
  44497. var dragger = makeRectDragger(plotinfo, ns + ew + 'drag', cursor, x, y, w, h);
  44498. // still need to make the element if the axes are disabled
  44499. // but nuke its events (except for maindrag which needs them for hover)
  44500. // and stop there
  44501. if(allFixedRanges && !isMainDrag) {
  44502. dragger.onmousedown = null;
  44503. dragger.style.pointerEvents = 'none';
  44504. return dragger;
  44505. }
  44506. var dragOptions = {
  44507. element: dragger,
  44508. gd: gd,
  44509. plotinfo: plotinfo
  44510. };
  44511. dragOptions.prepFn = function(e, startX, startY) {
  44512. var dragModePrev = dragOptions.dragmode;
  44513. var dragModeNow = gd._fullLayout.dragmode;
  44514. if(dragModeNow !== dragModePrev) {
  44515. dragOptions.dragmode = dragModeNow;
  44516. }
  44517. recomputeAxisLists();
  44518. if(!allFixedRanges) {
  44519. if(isMainDrag) {
  44520. // main dragger handles all drag modes, and changes
  44521. // to pan (or to zoom if it already is pan) on shift
  44522. if(e.shiftKey) {
  44523. if(dragModeNow === 'pan') dragModeNow = 'zoom';
  44524. else if(!isSelectOrLasso(dragModeNow)) dragModeNow = 'pan';
  44525. }
  44526. else if(e.ctrlKey) {
  44527. dragModeNow = 'pan';
  44528. }
  44529. }
  44530. // all other draggers just pan
  44531. else dragModeNow = 'pan';
  44532. }
  44533. if(dragModeNow === 'lasso') dragOptions.minDrag = 1;
  44534. else dragOptions.minDrag = undefined;
  44535. if(isSelectOrLasso(dragModeNow)) {
  44536. dragOptions.xaxes = xaxes;
  44537. dragOptions.yaxes = yaxes;
  44538. // this attaches moveFn, clickFn, doneFn on dragOptions
  44539. prepSelect(e, startX, startY, dragOptions, dragModeNow);
  44540. } else {
  44541. dragOptions.clickFn = clickFn;
  44542. if(isSelectOrLasso(dragModePrev)) {
  44543. // TODO Fix potential bug
  44544. // Note: clearing / resetting selection state only happens, when user
  44545. // triggers at least one interaction in pan/zoom mode. Otherwise, the
  44546. // select/lasso outlines are deleted (in plots.js.cleanPlot) but the selection
  44547. // cache isn't cleared. So when the user switches back to select/lasso and
  44548. // 'adds to a selection' with Shift, the "old", seemingly removed outlines
  44549. // are redrawn again because the selection cache still holds their coordinates.
  44550. // However, this isn't easily solved, since plots.js would need
  44551. // to have a reference to the dragOptions object (which holds the
  44552. // selection cache).
  44553. clearAndResetSelect();
  44554. }
  44555. if(!allFixedRanges) {
  44556. if(dragModeNow === 'zoom') {
  44557. dragOptions.moveFn = zoomMove;
  44558. dragOptions.doneFn = zoomDone;
  44559. // zoomMove takes care of the threshold, but we need to
  44560. // minimize this so that constrained zoom boxes will flip
  44561. // orientation at the right place
  44562. dragOptions.minDrag = 1;
  44563. zoomPrep(e, startX, startY);
  44564. } else if(dragModeNow === 'pan') {
  44565. dragOptions.moveFn = plotDrag;
  44566. dragOptions.doneFn = dragTail;
  44567. }
  44568. }
  44569. }
  44570. };
  44571. function clearAndResetSelect() {
  44572. // clear selection polygon cache (if any)
  44573. dragOptions.plotinfo.selection = false;
  44574. // clear selection outlines
  44575. clearSelect(zoomlayer);
  44576. }
  44577. function clickFn(numClicks, evt) {
  44578. var clickmode = gd._fullLayout.clickmode;
  44579. removeZoombox(gd);
  44580. if(numClicks === 2 && !singleEnd) doubleClick();
  44581. if(isMainDrag) {
  44582. if(clickmode.indexOf('select') > -1) {
  44583. selectOnClick(evt, gd, xaxes, yaxes, plotinfo.id, dragOptions);
  44584. }
  44585. if(clickmode.indexOf('event') > -1) {
  44586. Fx.click(gd, evt, plotinfo.id);
  44587. }
  44588. }
  44589. else if(numClicks === 1 && singleEnd) {
  44590. var ax = ns ? ya0 : xa0,
  44591. end = (ns === 's' || ew === 'w') ? 0 : 1,
  44592. attrStr = ax._name + '.range[' + end + ']',
  44593. initialText = getEndText(ax, end),
  44594. hAlign = 'left',
  44595. vAlign = 'middle';
  44596. if(ax.fixedrange) return;
  44597. if(ns) {
  44598. vAlign = (ns === 'n') ? 'top' : 'bottom';
  44599. if(ax.side === 'right') hAlign = 'right';
  44600. }
  44601. else if(ew === 'e') hAlign = 'right';
  44602. if(gd._context.showAxisRangeEntryBoxes) {
  44603. d3.select(dragger)
  44604. .call(svgTextUtils.makeEditable, {
  44605. gd: gd,
  44606. immediate: true,
  44607. background: gd._fullLayout.paper_bgcolor,
  44608. text: String(initialText),
  44609. fill: ax.tickfont ? ax.tickfont.color : '#444',
  44610. horizontalAlign: hAlign,
  44611. verticalAlign: vAlign
  44612. })
  44613. .on('edit', function(text) {
  44614. var v = ax.d2r(text);
  44615. if(v !== undefined) {
  44616. Registry.call('relayout', gd, attrStr, v);
  44617. }
  44618. });
  44619. }
  44620. }
  44621. }
  44622. dragElement.init(dragOptions);
  44623. var x0,
  44624. y0,
  44625. box,
  44626. lum,
  44627. path0,
  44628. dimmed,
  44629. zoomMode,
  44630. zb,
  44631. corners;
  44632. // zoom takes over minDrag, so it also has to take over gd._dragged
  44633. var zoomDragged;
  44634. function zoomPrep(e, startX, startY) {
  44635. var dragBBox = dragger.getBoundingClientRect();
  44636. x0 = startX - dragBBox.left;
  44637. y0 = startY - dragBBox.top;
  44638. box = {l: x0, r: x0, w: 0, t: y0, b: y0, h: 0};
  44639. lum = gd._hmpixcount ?
  44640. (gd._hmlumcount / gd._hmpixcount) :
  44641. tinycolor(gd._fullLayout.plot_bgcolor).getLuminance();
  44642. path0 = 'M0,0H' + pw + 'V' + ph + 'H0V0';
  44643. dimmed = false;
  44644. zoomMode = 'xy';
  44645. zoomDragged = false;
  44646. zb = makeZoombox(zoomlayer, lum, xs, ys, path0);
  44647. corners = makeCorners(zoomlayer, xs, ys);
  44648. }
  44649. function zoomMove(dx0, dy0) {
  44650. if(gd._transitioningWithDuration) {
  44651. return false;
  44652. }
  44653. var x1 = Math.max(0, Math.min(pw, dx0 + x0)),
  44654. y1 = Math.max(0, Math.min(ph, dy0 + y0)),
  44655. dx = Math.abs(x1 - x0),
  44656. dy = Math.abs(y1 - y0);
  44657. box.l = Math.min(x0, x1);
  44658. box.r = Math.max(x0, x1);
  44659. box.t = Math.min(y0, y1);
  44660. box.b = Math.max(y0, y1);
  44661. function noZoom() {
  44662. zoomMode = '';
  44663. box.r = box.l;
  44664. box.t = box.b;
  44665. corners.attr('d', 'M0,0Z');
  44666. }
  44667. if(isSubplotConstrained) {
  44668. if(dx > MINZOOM || dy > MINZOOM) {
  44669. zoomMode = 'xy';
  44670. if(dx / pw > dy / ph) {
  44671. dy = dx * ph / pw;
  44672. if(y0 > y1) box.t = y0 - dy;
  44673. else box.b = y0 + dy;
  44674. }
  44675. else {
  44676. dx = dy * pw / ph;
  44677. if(x0 > x1) box.l = x0 - dx;
  44678. else box.r = x0 + dx;
  44679. }
  44680. corners.attr('d', xyCorners(box));
  44681. }
  44682. else {
  44683. noZoom();
  44684. }
  44685. }
  44686. // look for small drags in one direction or the other,
  44687. // and only drag the other axis
  44688. else if(!yActive || dy < Math.min(Math.max(dx * 0.6, MINDRAG), MINZOOM)) {
  44689. if(dx < MINDRAG || !xActive) {
  44690. noZoom();
  44691. } else {
  44692. box.t = 0;
  44693. box.b = ph;
  44694. zoomMode = 'x';
  44695. corners.attr('d', xCorners(box, y0));
  44696. }
  44697. }
  44698. else if(!xActive || dx < Math.min(dy * 0.6, MINZOOM)) {
  44699. box.l = 0;
  44700. box.r = pw;
  44701. zoomMode = 'y';
  44702. corners.attr('d', yCorners(box, x0));
  44703. }
  44704. else {
  44705. zoomMode = 'xy';
  44706. corners.attr('d', xyCorners(box));
  44707. }
  44708. box.w = box.r - box.l;
  44709. box.h = box.b - box.t;
  44710. if(zoomMode) zoomDragged = true;
  44711. gd._dragged = zoomDragged;
  44712. updateZoombox(zb, corners, box, path0, dimmed, lum);
  44713. dimmed = true;
  44714. }
  44715. function zoomDone() {
  44716. updates = {};
  44717. // more strict than dragged, which allows you to come back to where you started
  44718. // and still count as dragged
  44719. if(Math.min(box.h, box.w) < MINDRAG * 2) {
  44720. return removeZoombox(gd);
  44721. }
  44722. // TODO: edit linked axes in zoomAxRanges and in dragTail
  44723. if(zoomMode === 'xy' || zoomMode === 'x') {
  44724. zoomAxRanges(xaxes, box.l / pw, box.r / pw, updates, links.xaxes);
  44725. }
  44726. if(zoomMode === 'xy' || zoomMode === 'y') {
  44727. zoomAxRanges(yaxes, (ph - box.b) / ph, (ph - box.t) / ph, updates, links.yaxes);
  44728. }
  44729. removeZoombox(gd);
  44730. dragTail();
  44731. showDoubleClickNotifier(gd);
  44732. }
  44733. // scroll zoom, on all draggers except corners
  44734. var scrollViewBox = [0, 0, pw, ph];
  44735. // wait a little after scrolling before redrawing
  44736. var redrawTimer = null;
  44737. var REDRAWDELAY = constants.REDRAWDELAY;
  44738. var mainplot = plotinfo.mainplot ? gd._fullLayout._plots[plotinfo.mainplot] : plotinfo;
  44739. function zoomWheel(e) {
  44740. // deactivate mousewheel scrolling on embedded graphs
  44741. // devs can override this with layout._enablescrollzoom,
  44742. // but _ ensures this setting won't leave their page
  44743. if(!gd._context.scrollZoom && !gd._fullLayout._enablescrollzoom) {
  44744. return;
  44745. }
  44746. clearAndResetSelect();
  44747. // If a transition is in progress, then disable any behavior:
  44748. if(gd._transitioningWithDuration) {
  44749. e.preventDefault();
  44750. e.stopPropagation();
  44751. return;
  44752. }
  44753. var pc = gd.querySelector('.plotly');
  44754. recomputeAxisLists();
  44755. // if the plot has scrollbars (more than a tiny excess)
  44756. // disable scrollzoom too.
  44757. if(pc.scrollHeight - pc.clientHeight > 10 ||
  44758. pc.scrollWidth - pc.clientWidth > 10) {
  44759. return;
  44760. }
  44761. clearTimeout(redrawTimer);
  44762. var wheelDelta = -e.deltaY;
  44763. if(!isFinite(wheelDelta)) wheelDelta = e.wheelDelta / 10;
  44764. if(!isFinite(wheelDelta)) {
  44765. Lib.log('Did not find wheel motion attributes: ', e);
  44766. return;
  44767. }
  44768. var zoom = Math.exp(-Math.min(Math.max(wheelDelta, -20), 20) / 200),
  44769. gbb = mainplot.draglayer.select('.nsewdrag')
  44770. .node().getBoundingClientRect(),
  44771. xfrac = (e.clientX - gbb.left) / gbb.width,
  44772. yfrac = (gbb.bottom - e.clientY) / gbb.height,
  44773. i;
  44774. function zoomWheelOneAxis(ax, centerFraction, zoom) {
  44775. if(ax.fixedrange) return;
  44776. var axRange = Lib.simpleMap(ax.range, ax.r2l),
  44777. v0 = axRange[0] + (axRange[1] - axRange[0]) * centerFraction;
  44778. function doZoom(v) { return ax.l2r(v0 + (v - v0) * zoom); }
  44779. ax.range = axRange.map(doZoom);
  44780. }
  44781. if(editX) {
  44782. // if we're only zooming this axis because of constraints,
  44783. // zoom it about the center
  44784. if(!ew) xfrac = 0.5;
  44785. for(i = 0; i < xaxes.length; i++) {
  44786. zoomWheelOneAxis(xaxes[i], xfrac, zoom);
  44787. }
  44788. scrollViewBox[2] *= zoom;
  44789. scrollViewBox[0] += scrollViewBox[2] * xfrac * (1 / zoom - 1);
  44790. }
  44791. if(editY) {
  44792. if(!ns) yfrac = 0.5;
  44793. for(i = 0; i < yaxes.length; i++) {
  44794. zoomWheelOneAxis(yaxes[i], yfrac, zoom);
  44795. }
  44796. scrollViewBox[3] *= zoom;
  44797. scrollViewBox[1] += scrollViewBox[3] * (1 - yfrac) * (1 / zoom - 1);
  44798. }
  44799. // viewbox redraw at first
  44800. updateSubplots(scrollViewBox);
  44801. ticksAndAnnotations(ns, ew);
  44802. // then replot after a delay to make sure
  44803. // no more scrolling is coming
  44804. redrawTimer = setTimeout(function() {
  44805. scrollViewBox = [0, 0, pw, ph];
  44806. dragTail();
  44807. }, REDRAWDELAY);
  44808. e.preventDefault();
  44809. return;
  44810. }
  44811. // everything but the corners gets wheel zoom
  44812. if(ns.length * ew.length !== 1) {
  44813. attachWheelEventHandler(dragger, zoomWheel);
  44814. }
  44815. // plotDrag: move the plot in response to a drag
  44816. function plotDrag(dx, dy) {
  44817. // If a transition is in progress, then disable any behavior:
  44818. if(gd._transitioningWithDuration) {
  44819. return;
  44820. }
  44821. if(xActive === 'ew' || yActive === 'ns') {
  44822. if(xActive) dragAxList(xaxes, dx);
  44823. if(yActive) dragAxList(yaxes, dy);
  44824. updateSubplots([xActive ? -dx : 0, yActive ? -dy : 0, pw, ph]);
  44825. ticksAndAnnotations(yActive, xActive);
  44826. return;
  44827. }
  44828. // dz: set a new value for one end (0 or 1) of an axis array axArray,
  44829. // and return a pixel shift for that end for the viewbox
  44830. // based on pixel drag distance d
  44831. // TODO: this makes (generally non-fatal) errors when you get
  44832. // near floating point limits
  44833. function dz(axArray, end, d) {
  44834. var otherEnd = 1 - end,
  44835. movedAx,
  44836. newLinearizedEnd;
  44837. for(var i = 0; i < axArray.length; i++) {
  44838. var axi = axArray[i];
  44839. if(axi.fixedrange) continue;
  44840. movedAx = axi;
  44841. newLinearizedEnd = axi._rl[otherEnd] +
  44842. (axi._rl[end] - axi._rl[otherEnd]) / dZoom(d / axi._length);
  44843. var newEnd = axi.l2r(newLinearizedEnd);
  44844. // if l2r comes back false or undefined, it means we've dragged off
  44845. // the end of valid ranges - so stop.
  44846. if(newEnd !== false && newEnd !== undefined) axi.range[end] = newEnd;
  44847. }
  44848. return movedAx._length * (movedAx._rl[end] - newLinearizedEnd) /
  44849. (movedAx._rl[end] - movedAx._rl[otherEnd]);
  44850. }
  44851. if(isSubplotConstrained && xActive && yActive) {
  44852. // dragging a corner of a constrained subplot:
  44853. // respect the fixed corner, but harmonize dx and dy
  44854. var dxySign = ((xActive === 'w') === (yActive === 'n')) ? 1 : -1;
  44855. var dxyFraction = (dx / pw + dxySign * dy / ph) / 2;
  44856. dx = dxyFraction * pw;
  44857. dy = dxySign * dxyFraction * ph;
  44858. }
  44859. if(xActive === 'w') dx = dz(xaxes, 0, dx);
  44860. else if(xActive === 'e') dx = dz(xaxes, 1, -dx);
  44861. else if(!xActive) dx = 0;
  44862. if(yActive === 'n') dy = dz(yaxes, 1, dy);
  44863. else if(yActive === 's') dy = dz(yaxes, 0, -dy);
  44864. else if(!yActive) dy = 0;
  44865. var x0 = (xActive === 'w') ? dx : 0;
  44866. var y0 = (yActive === 'n') ? dy : 0;
  44867. if(isSubplotConstrained) {
  44868. var i;
  44869. if(!xActive && yActive.length === 1) {
  44870. // dragging one end of the y axis of a constrained subplot
  44871. // scale the other axis the same about its middle
  44872. for(i = 0; i < xaxes.length; i++) {
  44873. xaxes[i].range = xaxes[i]._r.slice();
  44874. scaleZoom(xaxes[i], 1 - dy / ph);
  44875. }
  44876. dx = dy * pw / ph;
  44877. x0 = dx / 2;
  44878. }
  44879. if(!yActive && xActive.length === 1) {
  44880. for(i = 0; i < yaxes.length; i++) {
  44881. yaxes[i].range = yaxes[i]._r.slice();
  44882. scaleZoom(yaxes[i], 1 - dx / pw);
  44883. }
  44884. dy = dx * ph / pw;
  44885. y0 = dy / 2;
  44886. }
  44887. }
  44888. updateSubplots([x0, y0, pw - dx, ph - dy]);
  44889. ticksAndAnnotations(yActive, xActive);
  44890. }
  44891. // Draw ticks and annotations (and other components) when ranges change.
  44892. // Also records the ranges that have changed for use by update at the end.
  44893. function ticksAndAnnotations(ns, ew) {
  44894. var activeAxIds = [],
  44895. i;
  44896. function pushActiveAxIds(axList) {
  44897. for(i = 0; i < axList.length; i++) {
  44898. if(!axList[i].fixedrange) activeAxIds.push(axList[i]._id);
  44899. }
  44900. }
  44901. if(editX) {
  44902. pushActiveAxIds(xaxes);
  44903. pushActiveAxIds(links.xaxes);
  44904. }
  44905. if(editY) {
  44906. pushActiveAxIds(yaxes);
  44907. pushActiveAxIds(links.yaxes);
  44908. }
  44909. updates = {};
  44910. for(i = 0; i < activeAxIds.length; i++) {
  44911. var axId = activeAxIds[i];
  44912. doTicksSingle(gd, axId, true);
  44913. var ax = getFromId(gd, axId);
  44914. updates[ax._name + '.range[0]'] = ax.range[0];
  44915. updates[ax._name + '.range[1]'] = ax.range[1];
  44916. }
  44917. function redrawObjs(objArray, method, shortCircuit) {
  44918. for(i = 0; i < objArray.length; i++) {
  44919. var obji = objArray[i];
  44920. if((ew && activeAxIds.indexOf(obji.xref) !== -1) ||
  44921. (ns && activeAxIds.indexOf(obji.yref) !== -1)) {
  44922. method(gd, i);
  44923. // once is enough for images (which doesn't use the `i` arg anyway)
  44924. if(shortCircuit) return;
  44925. }
  44926. }
  44927. }
  44928. // annotations and shapes 'draw' method is slow,
  44929. // use the finer-grained 'drawOne' method instead
  44930. redrawObjs(gd._fullLayout.annotations || [], Registry.getComponentMethod('annotations', 'drawOne'));
  44931. redrawObjs(gd._fullLayout.shapes || [], Registry.getComponentMethod('shapes', 'drawOne'));
  44932. redrawObjs(gd._fullLayout.images || [], Registry.getComponentMethod('images', 'draw'), true);
  44933. }
  44934. function doubleClick() {
  44935. if(gd._transitioningWithDuration) return;
  44936. var doubleClickConfig = gd._context.doubleClick,
  44937. axList = (xActive ? xaxes : []).concat(yActive ? yaxes : []),
  44938. attrs = {};
  44939. var ax, i, rangeInitial;
  44940. // For reset+autosize mode:
  44941. // If *any* of the main axes is not at its initial range
  44942. // (or autoranged, if we have no initial range, to match the logic in
  44943. // doubleClickConfig === 'reset' below), we reset.
  44944. // If they are *all* at their initial ranges, then we autosize.
  44945. if(doubleClickConfig === 'reset+autosize') {
  44946. doubleClickConfig = 'autosize';
  44947. for(i = 0; i < axList.length; i++) {
  44948. ax = axList[i];
  44949. if((ax._rangeInitial && (
  44950. ax.range[0] !== ax._rangeInitial[0] ||
  44951. ax.range[1] !== ax._rangeInitial[1]
  44952. )) ||
  44953. (!ax._rangeInitial && !ax.autorange)
  44954. ) {
  44955. doubleClickConfig = 'reset';
  44956. break;
  44957. }
  44958. }
  44959. }
  44960. if(doubleClickConfig === 'autosize') {
  44961. // don't set the linked axes here, so relayout marks them as shrinkable
  44962. // and we autosize just to the requested axis/axes
  44963. for(i = 0; i < axList.length; i++) {
  44964. ax = axList[i];
  44965. if(!ax.fixedrange) attrs[ax._name + '.autorange'] = true;
  44966. }
  44967. }
  44968. else if(doubleClickConfig === 'reset') {
  44969. // when we're resetting, reset all linked axes too, so we get back
  44970. // to the fully-auto-with-constraints situation
  44971. if(xActive || isSubplotConstrained) axList = axList.concat(links.xaxes);
  44972. if(yActive && !isSubplotConstrained) axList = axList.concat(links.yaxes);
  44973. if(isSubplotConstrained) {
  44974. if(!xActive) axList = axList.concat(xaxes);
  44975. else if(!yActive) axList = axList.concat(yaxes);
  44976. }
  44977. for(i = 0; i < axList.length; i++) {
  44978. ax = axList[i];
  44979. if(!ax._rangeInitial) {
  44980. attrs[ax._name + '.autorange'] = true;
  44981. }
  44982. else {
  44983. rangeInitial = ax._rangeInitial;
  44984. attrs[ax._name + '.range[0]'] = rangeInitial[0];
  44985. attrs[ax._name + '.range[1]'] = rangeInitial[1];
  44986. }
  44987. }
  44988. }
  44989. gd.emit('plotly_doubleclick', null);
  44990. Registry.call('relayout', gd, attrs);
  44991. }
  44992. // dragTail - finish a drag event with a redraw
  44993. function dragTail() {
  44994. // put the subplot viewboxes back to default (Because we're going to)
  44995. // be repositioning the data in the relayout. But DON'T call
  44996. // ticksAndAnnotations again - it's unnecessary and would overwrite `updates`
  44997. updateSubplots([0, 0, pw, ph]);
  44998. // since we may have been redrawing some things during the drag, we may have
  44999. // accumulated MathJax promises - wait for them before we relayout.
  45000. Lib.syncOrAsync([
  45001. Plots.previousPromises,
  45002. function() { Registry.call('relayout', gd, updates); }
  45003. ], gd);
  45004. }
  45005. // x/y scaleFactor stash,
  45006. // minimizes number of per-point DOM updates in updateSubplots below
  45007. var xScaleFactorOld, yScaleFactorOld;
  45008. // updateSubplots - find all plot viewboxes that should be
  45009. // affected by this drag, and update them. look for all plots
  45010. // sharing an affected axis (including the one being dragged),
  45011. // includes also scattergl and splom logic.
  45012. function updateSubplots(viewBox) {
  45013. var fullLayout = gd._fullLayout;
  45014. var plotinfos = fullLayout._plots;
  45015. var subplots = fullLayout._subplots.cartesian;
  45016. var i, sp, xa, ya;
  45017. if(hasSplom || hasScatterGl) {
  45018. clearGlCanvases(gd);
  45019. }
  45020. if(hasSplom) {
  45021. Registry.subplotsRegistry.splom.drag(gd);
  45022. if(hasOnlyLargeSploms) return;
  45023. }
  45024. if(hasScatterGl) {
  45025. // loop over all subplots (w/o exceptions) here,
  45026. // as we cleared the gl canvases above
  45027. for(i = 0; i < subplots.length; i++) {
  45028. sp = plotinfos[subplots[i]];
  45029. xa = sp.xaxis;
  45030. ya = sp.yaxis;
  45031. var scene = sp._scene;
  45032. if(scene) {
  45033. // FIXME: possibly we could update axis internal _r and _rl here
  45034. var xrng = Lib.simpleMap(xa.range, xa.r2l);
  45035. var yrng = Lib.simpleMap(ya.range, ya.r2l);
  45036. scene.update({range: [xrng[0], yrng[0], xrng[1], yrng[1]]});
  45037. }
  45038. }
  45039. }
  45040. if(hasSVG) {
  45041. var xScaleFactor = viewBox[2] / xa0._length;
  45042. var yScaleFactor = viewBox[3] / ya0._length;
  45043. for(i = 0; i < subplots.length; i++) {
  45044. sp = plotinfos[subplots[i]];
  45045. xa = sp.xaxis;
  45046. ya = sp.yaxis;
  45047. var editX2 = editX && !xa.fixedrange && xaHash[xa._id];
  45048. var editY2 = editY && !ya.fixedrange && yaHash[ya._id];
  45049. var xScaleFactor2, yScaleFactor2;
  45050. var clipDx, clipDy;
  45051. if(editX2) {
  45052. xScaleFactor2 = xScaleFactor;
  45053. clipDx = ew ? viewBox[0] : getShift(xa, xScaleFactor2);
  45054. } else {
  45055. xScaleFactor2 = getLinkedScaleFactor(xa, xScaleFactor, yScaleFactor);
  45056. clipDx = scaleAndGetShift(xa, xScaleFactor2);
  45057. }
  45058. if(editY2) {
  45059. yScaleFactor2 = yScaleFactor;
  45060. clipDy = ns ? viewBox[1] : getShift(ya, yScaleFactor2);
  45061. } else {
  45062. yScaleFactor2 = getLinkedScaleFactor(ya, xScaleFactor, yScaleFactor);
  45063. clipDy = scaleAndGetShift(ya, yScaleFactor2);
  45064. }
  45065. // don't scale at all if neither axis is scalable here
  45066. if(!xScaleFactor2 && !yScaleFactor2) {
  45067. continue;
  45068. }
  45069. // but if only one is, reset the other axis scaling
  45070. if(!xScaleFactor2) xScaleFactor2 = 1;
  45071. if(!yScaleFactor2) yScaleFactor2 = 1;
  45072. var plotDx = xa._offset - clipDx / xScaleFactor2;
  45073. var plotDy = ya._offset - clipDy / yScaleFactor2;
  45074. // TODO could be more efficient here:
  45075. // setTranslate and setScale do a lot of extra work
  45076. // when working independently, should perhaps combine
  45077. // them into a single routine.
  45078. sp.clipRect
  45079. .call(Drawing.setTranslate, clipDx, clipDy)
  45080. .call(Drawing.setScale, xScaleFactor2, yScaleFactor2);
  45081. sp.plot
  45082. .call(Drawing.setTranslate, plotDx, plotDy)
  45083. .call(Drawing.setScale, 1 / xScaleFactor2, 1 / yScaleFactor2);
  45084. // apply an inverse scale to individual points to counteract
  45085. // the scale of the trace group.
  45086. // apply only when scale changes, as adjusting the scale of
  45087. // all the points can be expansive.
  45088. if(xScaleFactor2 !== xScaleFactorOld || yScaleFactor2 !== yScaleFactorOld) {
  45089. Drawing.setPointGroupScale(sp.zoomScalePts, xScaleFactor2, yScaleFactor2);
  45090. Drawing.setTextPointsScale(sp.zoomScaleTxt, xScaleFactor2, yScaleFactor2);
  45091. }
  45092. Drawing.hideOutsideRangePoints(sp.clipOnAxisFalseTraces, sp);
  45093. // update x/y scaleFactor stash
  45094. xScaleFactorOld = xScaleFactor2;
  45095. yScaleFactorOld = yScaleFactor2;
  45096. }
  45097. }
  45098. }
  45099. // Find the appropriate scaling for this axis, if it's linked to the
  45100. // dragged axes by constraints. 0 is special, it means this axis shouldn't
  45101. // ever be scaled (will be converted to 1 if the other axis is scaled)
  45102. function getLinkedScaleFactor(ax, xScaleFactor, yScaleFactor) {
  45103. if(ax.fixedrange) return 0;
  45104. if(editX && links.xaHash[ax._id]) {
  45105. return xScaleFactor;
  45106. }
  45107. if(editY && (isSubplotConstrained ? links.xaHash : links.yaHash)[ax._id]) {
  45108. return yScaleFactor;
  45109. }
  45110. return 0;
  45111. }
  45112. function scaleAndGetShift(ax, scaleFactor) {
  45113. if(scaleFactor) {
  45114. ax.range = ax._r.slice();
  45115. scaleZoom(ax, scaleFactor);
  45116. return getShift(ax, scaleFactor);
  45117. }
  45118. return 0;
  45119. }
  45120. function getShift(ax, scaleFactor) {
  45121. return ax._length * (1 - scaleFactor) * FROM_TL[ax.constraintoward || 'middle'];
  45122. }
  45123. return dragger;
  45124. }
  45125. function makeDragger(plotinfo, nodeName, dragClass, cursor) {
  45126. var dragger3 = Lib.ensureSingle(plotinfo.draglayer, nodeName, dragClass, function(s) {
  45127. s.classed('drag', true)
  45128. .style({fill: 'transparent', 'stroke-width': 0})
  45129. .attr('data-subplot', plotinfo.id);
  45130. });
  45131. dragger3.call(setCursor, cursor);
  45132. return dragger3.node();
  45133. }
  45134. function makeRectDragger(plotinfo, dragClass, cursor, x, y, w, h) {
  45135. var dragger = makeDragger(plotinfo, 'rect', dragClass, cursor);
  45136. d3.select(dragger).call(Drawing.setRect, x, y, w, h);
  45137. return dragger;
  45138. }
  45139. function isDirectionActive(axList, activeVal) {
  45140. for(var i = 0; i < axList.length; i++) {
  45141. if(!axList[i].fixedrange) return activeVal;
  45142. }
  45143. return '';
  45144. }
  45145. function getEndText(ax, end) {
  45146. var initialVal = ax.range[end],
  45147. diff = Math.abs(initialVal - ax.range[1 - end]),
  45148. dig;
  45149. // TODO: this should basically be ax.r2d but we're doing extra
  45150. // rounding here... can we clean up at all?
  45151. if(ax.type === 'date') {
  45152. return initialVal;
  45153. }
  45154. else if(ax.type === 'log') {
  45155. dig = Math.ceil(Math.max(0, -Math.log(diff) / Math.LN10)) + 3;
  45156. return d3.format('.' + dig + 'g')(Math.pow(10, initialVal));
  45157. }
  45158. else { // linear numeric (or category... but just show numbers here)
  45159. dig = Math.floor(Math.log(Math.abs(initialVal)) / Math.LN10) -
  45160. Math.floor(Math.log(diff) / Math.LN10) + 4;
  45161. return d3.format('.' + String(dig) + 'g')(initialVal);
  45162. }
  45163. }
  45164. function zoomAxRanges(axList, r0Fraction, r1Fraction, updates, linkedAxes) {
  45165. var i,
  45166. axi,
  45167. axRangeLinear0,
  45168. axRangeLinearSpan;
  45169. for(i = 0; i < axList.length; i++) {
  45170. axi = axList[i];
  45171. if(axi.fixedrange) continue;
  45172. axRangeLinear0 = axi._rl[0];
  45173. axRangeLinearSpan = axi._rl[1] - axRangeLinear0;
  45174. axi.range = [
  45175. axi.l2r(axRangeLinear0 + axRangeLinearSpan * r0Fraction),
  45176. axi.l2r(axRangeLinear0 + axRangeLinearSpan * r1Fraction)
  45177. ];
  45178. updates[axi._name + '.range[0]'] = axi.range[0];
  45179. updates[axi._name + '.range[1]'] = axi.range[1];
  45180. }
  45181. // zoom linked axes about their centers
  45182. if(linkedAxes && linkedAxes.length) {
  45183. var linkedR0Fraction = (r0Fraction + (1 - r1Fraction)) / 2;
  45184. zoomAxRanges(linkedAxes, linkedR0Fraction, 1 - linkedR0Fraction, updates);
  45185. }
  45186. }
  45187. function dragAxList(axList, pix) {
  45188. for(var i = 0; i < axList.length; i++) {
  45189. var axi = axList[i];
  45190. if(!axi.fixedrange) {
  45191. axi.range = [
  45192. axi.l2r(axi._rl[0] - pix / axi._m),
  45193. axi.l2r(axi._rl[1] - pix / axi._m)
  45194. ];
  45195. }
  45196. }
  45197. }
  45198. // common transform for dragging one end of an axis
  45199. // d>0 is compressing scale (cursor is over the plot,
  45200. // the axis end should move with the cursor)
  45201. // d<0 is expanding (cursor is off the plot, axis end moves
  45202. // nonlinearly so you can expand far)
  45203. function dZoom(d) {
  45204. return 1 - ((d >= 0) ? Math.min(d, 0.9) :
  45205. 1 / (1 / Math.max(d, -0.3) + 3.222));
  45206. }
  45207. function getDragCursor(nsew, dragmode, isMainDrag) {
  45208. if(!nsew) return 'pointer';
  45209. if(nsew === 'nsew') {
  45210. // in this case here, clear cursor and
  45211. // use the cursor style set on <g .draglayer>
  45212. if(isMainDrag) return '';
  45213. if(dragmode === 'pan') return 'move';
  45214. return 'crosshair';
  45215. }
  45216. return nsew.toLowerCase() + '-resize';
  45217. }
  45218. function makeZoombox(zoomlayer, lum, xs, ys, path0) {
  45219. return zoomlayer.append('path')
  45220. .attr('class', 'zoombox')
  45221. .style({
  45222. 'fill': lum > 0.2 ? 'rgba(0,0,0,0)' : 'rgba(255,255,255,0)',
  45223. 'stroke-width': 0
  45224. })
  45225. .attr('transform', 'translate(' + xs + ', ' + ys + ')')
  45226. .attr('d', path0 + 'Z');
  45227. }
  45228. function makeCorners(zoomlayer, xs, ys) {
  45229. return zoomlayer.append('path')
  45230. .attr('class', 'zoombox-corners')
  45231. .style({
  45232. fill: Color.background,
  45233. stroke: Color.defaultLine,
  45234. 'stroke-width': 1,
  45235. opacity: 0
  45236. })
  45237. .attr('transform', 'translate(' + xs + ', ' + ys + ')')
  45238. .attr('d', 'M0,0Z');
  45239. }
  45240. function updateZoombox(zb, corners, box, path0, dimmed, lum) {
  45241. zb.attr('d',
  45242. path0 + 'M' + (box.l) + ',' + (box.t) + 'v' + (box.h) +
  45243. 'h' + (box.w) + 'v-' + (box.h) + 'h-' + (box.w) + 'Z');
  45244. transitionZoombox(zb, corners, dimmed, lum);
  45245. }
  45246. function transitionZoombox(zb, corners, dimmed, lum) {
  45247. if(!dimmed) {
  45248. zb.transition()
  45249. .style('fill', lum > 0.2 ? 'rgba(0,0,0,0.4)' :
  45250. 'rgba(255,255,255,0.3)')
  45251. .duration(200);
  45252. corners.transition()
  45253. .style('opacity', 1)
  45254. .duration(200);
  45255. }
  45256. }
  45257. function removeZoombox(gd) {
  45258. d3.select(gd)
  45259. .selectAll('.zoombox,.js-zoombox-backdrop,.js-zoombox-menu,.zoombox-corners')
  45260. .remove();
  45261. }
  45262. function showDoubleClickNotifier(gd) {
  45263. if(SHOWZOOMOUTTIP && gd.data && gd._context.showTips) {
  45264. Lib.notifier(Lib._(gd, 'Double-click to zoom back out'), 'long');
  45265. SHOWZOOMOUTTIP = false;
  45266. }
  45267. }
  45268. function isSelectOrLasso(dragmode) {
  45269. return dragmode === 'lasso' || dragmode === 'select';
  45270. }
  45271. function xCorners(box, y0) {
  45272. return 'M' +
  45273. (box.l - 0.5) + ',' + (y0 - MINZOOM - 0.5) +
  45274. 'h-3v' + (2 * MINZOOM + 1) + 'h3ZM' +
  45275. (box.r + 0.5) + ',' + (y0 - MINZOOM - 0.5) +
  45276. 'h3v' + (2 * MINZOOM + 1) + 'h-3Z';
  45277. }
  45278. function yCorners(box, x0) {
  45279. return 'M' +
  45280. (x0 - MINZOOM - 0.5) + ',' + (box.t - 0.5) +
  45281. 'v-3h' + (2 * MINZOOM + 1) + 'v3ZM' +
  45282. (x0 - MINZOOM - 0.5) + ',' + (box.b + 0.5) +
  45283. 'v3h' + (2 * MINZOOM + 1) + 'v-3Z';
  45284. }
  45285. function xyCorners(box) {
  45286. var clen = Math.floor(Math.min(box.b - box.t, box.r - box.l, MINZOOM) / 2);
  45287. return 'M' +
  45288. (box.l - 3.5) + ',' + (box.t - 0.5 + clen) + 'h3v' + (-clen) +
  45289. 'h' + clen + 'v-3h-' + (clen + 3) + 'ZM' +
  45290. (box.r + 3.5) + ',' + (box.t - 0.5 + clen) + 'h-3v' + (-clen) +
  45291. 'h' + (-clen) + 'v-3h' + (clen + 3) + 'ZM' +
  45292. (box.r + 3.5) + ',' + (box.b + 0.5 - clen) + 'h-3v' + clen +
  45293. 'h' + (-clen) + 'v3h' + (clen + 3) + 'ZM' +
  45294. (box.l - 3.5) + ',' + (box.b + 0.5 - clen) + 'h3v' + clen +
  45295. 'h' + clen + 'v3h-' + (clen + 3) + 'Z';
  45296. }
  45297. function calcLinks(gd, xaHash, yaHash) {
  45298. var constraintGroups = gd._fullLayout._axisConstraintGroups;
  45299. var isSubplotConstrained = false;
  45300. var xLinks = {};
  45301. var yLinks = {};
  45302. var xID, yID, xLinkID, yLinkID;
  45303. for(var i = 0; i < constraintGroups.length; i++) {
  45304. var group = constraintGroups[i];
  45305. // check if any of the x axes we're dragging is in this constraint group
  45306. for(xID in xaHash) {
  45307. if(group[xID]) {
  45308. // put the rest of these axes into xLinks, if we're not already
  45309. // dragging them, so we know to scale these axes automatically too
  45310. // to match the changes in the dragged x axes
  45311. for(xLinkID in group) {
  45312. if(!(xLinkID.charAt(0) === 'x' ? xaHash : yaHash)[xLinkID]) {
  45313. xLinks[xLinkID] = 1;
  45314. }
  45315. }
  45316. // check if the x and y axes of THIS drag are linked
  45317. for(yID in yaHash) {
  45318. if(group[yID]) isSubplotConstrained = true;
  45319. }
  45320. }
  45321. }
  45322. // now check if any of the y axes we're dragging is in this constraint group
  45323. // only look for outside links, as we've already checked for links within the dragger
  45324. for(yID in yaHash) {
  45325. if(group[yID]) {
  45326. for(yLinkID in group) {
  45327. if(!(yLinkID.charAt(0) === 'x' ? xaHash : yaHash)[yLinkID]) {
  45328. yLinks[yLinkID] = 1;
  45329. }
  45330. }
  45331. }
  45332. }
  45333. }
  45334. if(isSubplotConstrained) {
  45335. // merge xLinks and yLinks if the subplot is constrained,
  45336. // since we'll always apply both anyway and the two will contain
  45337. // duplicates
  45338. Lib.extendFlat(xLinks, yLinks);
  45339. yLinks = {};
  45340. }
  45341. var xaHashLinked = {};
  45342. var xaxesLinked = [];
  45343. for(xLinkID in xLinks) {
  45344. var xa = getFromId(gd, xLinkID);
  45345. xaxesLinked.push(xa);
  45346. xaHashLinked[xa._id] = xa;
  45347. }
  45348. var yaHashLinked = {};
  45349. var yaxesLinked = [];
  45350. for(yLinkID in yLinks) {
  45351. var ya = getFromId(gd, yLinkID);
  45352. yaxesLinked.push(ya);
  45353. yaHashLinked[ya._id] = ya;
  45354. }
  45355. return {
  45356. xaHash: xaHashLinked,
  45357. yaHash: yaHashLinked,
  45358. xaxes: xaxesLinked,
  45359. yaxes: yaxesLinked,
  45360. isSubplotConstrained: isSubplotConstrained
  45361. };
  45362. }
  45363. // still seems to be some confusion about onwheel vs onmousewheel...
  45364. function attachWheelEventHandler(element, handler) {
  45365. if(!supportsPassive) {
  45366. if(element.onwheel !== undefined) element.onwheel = handler;
  45367. else if(element.onmousewheel !== undefined) element.onmousewheel = handler;
  45368. }
  45369. else {
  45370. var wheelEventName = element.onwheel !== undefined ? 'wheel' : 'mousewheel';
  45371. if(element._onwheel) {
  45372. element.removeEventListener(wheelEventName, element._onwheel);
  45373. }
  45374. element._onwheel = handler;
  45375. element.addEventListener(wheelEventName, handler, {passive: false});
  45376. }
  45377. }
  45378. function hashValues(hash) {
  45379. var out = [];
  45380. for(var k in hash) out.push(hash[k]);
  45381. return out;
  45382. }
  45383. module.exports = {
  45384. makeDragBox: makeDragBox,
  45385. makeDragger: makeDragger,
  45386. makeRectDragger: makeRectDragger,
  45387. makeZoombox: makeZoombox,
  45388. makeCorners: makeCorners,
  45389. updateZoombox: updateZoombox,
  45390. xyCorners: xyCorners,
  45391. transitionZoombox: transitionZoombox,
  45392. removeZoombox: removeZoombox,
  45393. showDoubleClickNotifier: showDoubleClickNotifier,
  45394. attachWheelEventHandler: attachWheelEventHandler
  45395. };
  45396. },{"../../components/color":50,"../../components/dragelement":72,"../../components/drawing":75,"../../components/fx":92,"../../constants/alignment":148,"../../lib":169,"../../lib/clear_gl_canvases":157,"../../lib/setcursor":189,"../../lib/svg_text_utils":191,"../../registry":259,"../plots":246,"./axes":214,"./axis_ids":217,"./constants":219,"./scale_zoom":230,"./select":231,"d3":16,"has-passive-events":21,"tinycolor2":33}],223:[function(_dereq_,module,exports){
  45397. /**
  45398. * Copyright 2012-2018, Plotly, Inc.
  45399. * All rights reserved.
  45400. *
  45401. * This source code is licensed under the MIT license found in the
  45402. * LICENSE file in the root directory of this source tree.
  45403. */
  45404. 'use strict';
  45405. var d3 = _dereq_('d3');
  45406. var Fx = _dereq_('../../components/fx');
  45407. var dragElement = _dereq_('../../components/dragelement');
  45408. var setCursor = _dereq_('../../lib/setcursor');
  45409. var makeDragBox = _dereq_('./dragbox').makeDragBox;
  45410. var DRAGGERSIZE = _dereq_('./constants').DRAGGERSIZE;
  45411. exports.initInteractions = function initInteractions(gd) {
  45412. var fullLayout = gd._fullLayout;
  45413. if(gd._context.staticPlot) {
  45414. // this sweeps up more than just cartesian drag elements...
  45415. d3.select(gd).selectAll('.drag').remove();
  45416. return;
  45417. }
  45418. if(!fullLayout._has('cartesian') && !fullLayout._has('splom')) return;
  45419. var subplots = Object.keys(fullLayout._plots || {}).sort(function(a, b) {
  45420. // sort overlays last, then by x axis number, then y axis number
  45421. if((fullLayout._plots[a].mainplot && true) ===
  45422. (fullLayout._plots[b].mainplot && true)) {
  45423. var aParts = a.split('y'),
  45424. bParts = b.split('y');
  45425. return (aParts[0] === bParts[0]) ?
  45426. (Number(aParts[1] || 1) - Number(bParts[1] || 1)) :
  45427. (Number(aParts[0] || 1) - Number(bParts[0] || 1));
  45428. }
  45429. return fullLayout._plots[a].mainplot ? 1 : -1;
  45430. });
  45431. subplots.forEach(function(subplot) {
  45432. var plotinfo = fullLayout._plots[subplot];
  45433. var xa = plotinfo.xaxis;
  45434. var ya = plotinfo.yaxis;
  45435. // main and corner draggers need not be repeated for
  45436. // overlaid subplots - these draggers drag them all
  45437. if(!plotinfo.mainplot) {
  45438. // main dragger goes over the grids and data, so we use its
  45439. // mousemove events for all data hover effects
  45440. var maindrag = makeDragBox(gd, plotinfo, xa._offset, ya._offset,
  45441. xa._length, ya._length, 'ns', 'ew');
  45442. maindrag.onmousemove = function(evt) {
  45443. // This is on `gd._fullLayout`, *not* fullLayout because the reference
  45444. // changes by the time this is called again.
  45445. gd._fullLayout._rehover = function() {
  45446. if(gd._fullLayout._hoversubplot === subplot) {
  45447. Fx.hover(gd, evt, subplot);
  45448. }
  45449. };
  45450. Fx.hover(gd, evt, subplot);
  45451. // Note that we have *not* used the cached fullLayout variable here
  45452. // since that may be outdated when this is called as a callback later on
  45453. gd._fullLayout._lasthover = maindrag;
  45454. gd._fullLayout._hoversubplot = subplot;
  45455. };
  45456. /*
  45457. * IMPORTANT:
  45458. * We must check for the presence of the drag cover here.
  45459. * If we don't, a 'mouseout' event is triggered on the
  45460. * maindrag before each 'click' event, which has the effect
  45461. * of clearing the hoverdata; thus, cancelling the click event.
  45462. */
  45463. maindrag.onmouseout = function(evt) {
  45464. if(gd._dragging) return;
  45465. // When the mouse leaves this maindrag, unset the hovered subplot.
  45466. // This may cause problems if it leaves the subplot directly *onto*
  45467. // another subplot, but that's a tiny corner case at the moment.
  45468. gd._fullLayout._hoversubplot = null;
  45469. dragElement.unhover(gd, evt);
  45470. };
  45471. // corner draggers
  45472. if(gd._context.showAxisDragHandles) {
  45473. makeDragBox(gd, plotinfo, xa._offset - DRAGGERSIZE, ya._offset - DRAGGERSIZE,
  45474. DRAGGERSIZE, DRAGGERSIZE, 'n', 'w');
  45475. makeDragBox(gd, plotinfo, xa._offset + xa._length, ya._offset - DRAGGERSIZE,
  45476. DRAGGERSIZE, DRAGGERSIZE, 'n', 'e');
  45477. makeDragBox(gd, plotinfo, xa._offset - DRAGGERSIZE, ya._offset + ya._length,
  45478. DRAGGERSIZE, DRAGGERSIZE, 's', 'w');
  45479. makeDragBox(gd, plotinfo, xa._offset + xa._length, ya._offset + ya._length,
  45480. DRAGGERSIZE, DRAGGERSIZE, 's', 'e');
  45481. }
  45482. }
  45483. if(gd._context.showAxisDragHandles) {
  45484. // x axis draggers - if you have overlaid plots,
  45485. // these drag each axis separately
  45486. if(subplot === xa._mainSubplot) {
  45487. // the y position of the main x axis line
  45488. var y0 = xa._mainLinePosition;
  45489. if(xa.side === 'top') y0 -= DRAGGERSIZE;
  45490. makeDragBox(gd, plotinfo, xa._offset + xa._length * 0.1, y0,
  45491. xa._length * 0.8, DRAGGERSIZE, '', 'ew');
  45492. makeDragBox(gd, plotinfo, xa._offset, y0,
  45493. xa._length * 0.1, DRAGGERSIZE, '', 'w');
  45494. makeDragBox(gd, plotinfo, xa._offset + xa._length * 0.9, y0,
  45495. xa._length * 0.1, DRAGGERSIZE, '', 'e');
  45496. }
  45497. // y axis draggers
  45498. if(subplot === ya._mainSubplot) {
  45499. // the x position of the main y axis line
  45500. var x0 = ya._mainLinePosition;
  45501. if(ya.side !== 'right') x0 -= DRAGGERSIZE;
  45502. makeDragBox(gd, plotinfo, x0, ya._offset + ya._length * 0.1,
  45503. DRAGGERSIZE, ya._length * 0.8, 'ns', '');
  45504. makeDragBox(gd, plotinfo, x0, ya._offset + ya._length * 0.9,
  45505. DRAGGERSIZE, ya._length * 0.1, 's', '');
  45506. makeDragBox(gd, plotinfo, x0, ya._offset,
  45507. DRAGGERSIZE, ya._length * 0.1, 'n', '');
  45508. }
  45509. }
  45510. });
  45511. // In case you mousemove over some hovertext, send it to Fx.hover too
  45512. // we do this so that we can put the hover text in front of everything,
  45513. // but still be able to interact with everything as if it isn't there
  45514. var hoverLayer = fullLayout._hoverlayer.node();
  45515. hoverLayer.onmousemove = function(evt) {
  45516. evt.target = gd._fullLayout._lasthover;
  45517. Fx.hover(gd, evt, fullLayout._hoversubplot);
  45518. };
  45519. hoverLayer.onclick = function(evt) {
  45520. evt.target = gd._fullLayout._lasthover;
  45521. Fx.click(gd, evt);
  45522. };
  45523. // also delegate mousedowns... TODO: does this actually work?
  45524. hoverLayer.onmousedown = function(evt) {
  45525. gd._fullLayout._lasthover.onmousedown(evt);
  45526. };
  45527. exports.updateFx(gd);
  45528. };
  45529. // Minimal set of update needed on 'modebar' edits.
  45530. // We only need to update the <g .draglayer> cursor style.
  45531. //
  45532. // Note that changing the axis configuration and/or the fixedrange attribute
  45533. // should trigger a full initInteractions.
  45534. exports.updateFx = function(gd) {
  45535. var fullLayout = gd._fullLayout;
  45536. var cursor = fullLayout.dragmode === 'pan' ? 'move' : 'crosshair';
  45537. setCursor(fullLayout._draggers, cursor);
  45538. };
  45539. },{"../../components/dragelement":72,"../../components/fx":92,"../../lib/setcursor":189,"./constants":219,"./dragbox":222,"d3":16}],224:[function(_dereq_,module,exports){
  45540. /**
  45541. * Copyright 2012-2018, Plotly, Inc.
  45542. * All rights reserved.
  45543. *
  45544. * This source code is licensed under the MIT license found in the
  45545. * LICENSE file in the root directory of this source tree.
  45546. */
  45547. 'use strict';
  45548. var Registry = _dereq_('../../registry');
  45549. var Lib = _dereq_('../../lib');
  45550. /**
  45551. * Factory function for checking component arrays for subplot references.
  45552. *
  45553. * @param {string} containerArrayName: the top-level array in gd.layout to check
  45554. * If an item in this container is found that references a cartesian x and/or y axis,
  45555. * ensure cartesian is marked as a base plot module and record the axes (and subplot
  45556. * if both refs are axes) in gd._fullLayout
  45557. *
  45558. * @return {function}: with args layoutIn (gd.layout) and layoutOut (gd._fullLayout)
  45559. * as expected of a component includeBasePlot method
  45560. */
  45561. module.exports = function makeIncludeComponents(containerArrayName) {
  45562. return function includeComponents(layoutIn, layoutOut) {
  45563. var array = layoutIn[containerArrayName];
  45564. if(!Array.isArray(array)) return;
  45565. var Cartesian = Registry.subplotsRegistry.cartesian;
  45566. var idRegex = Cartesian.idRegex;
  45567. var subplots = layoutOut._subplots;
  45568. var xaList = subplots.xaxis;
  45569. var yaList = subplots.yaxis;
  45570. var cartesianList = subplots.cartesian;
  45571. var hasCartesianOrGL2D = layoutOut._has('cartesian') || layoutOut._has('gl2d');
  45572. for(var i = 0; i < array.length; i++) {
  45573. var itemi = array[i];
  45574. if(!Lib.isPlainObject(itemi)) continue;
  45575. var xref = itemi.xref;
  45576. var yref = itemi.yref;
  45577. var hasXref = idRegex.x.test(xref);
  45578. var hasYref = idRegex.y.test(yref);
  45579. if(hasXref || hasYref) {
  45580. if(!hasCartesianOrGL2D) Lib.pushUnique(layoutOut._basePlotModules, Cartesian);
  45581. var newAxis = false;
  45582. if(hasXref && xaList.indexOf(xref) === -1) {
  45583. xaList.push(xref);
  45584. newAxis = true;
  45585. }
  45586. if(hasYref && yaList.indexOf(yref) === -1) {
  45587. yaList.push(yref);
  45588. newAxis = true;
  45589. }
  45590. /*
  45591. * Notice the logic here: only add a subplot for a component if
  45592. * it's referencing both x and y axes AND it's creating a new axis
  45593. * so for example if your plot already has xy and x2y2, an annotation
  45594. * on x2y or xy2 will not create a new subplot.
  45595. */
  45596. if(newAxis && hasXref && hasYref) {
  45597. cartesianList.push(xref + yref);
  45598. }
  45599. }
  45600. }
  45601. };
  45602. };
  45603. },{"../../lib":169,"../../registry":259}],225:[function(_dereq_,module,exports){
  45604. /**
  45605. * Copyright 2012-2018, Plotly, Inc.
  45606. * All rights reserved.
  45607. *
  45608. * This source code is licensed under the MIT license found in the
  45609. * LICENSE file in the root directory of this source tree.
  45610. */
  45611. 'use strict';
  45612. var d3 = _dereq_('d3');
  45613. var Registry = _dereq_('../../registry');
  45614. var Lib = _dereq_('../../lib');
  45615. var Plots = _dereq_('../plots');
  45616. var Drawing = _dereq_('../../components/drawing');
  45617. var getModuleCalcData = _dereq_('../get_data').getModuleCalcData;
  45618. var axisIds = _dereq_('./axis_ids');
  45619. var constants = _dereq_('./constants');
  45620. var xmlnsNamespaces = _dereq_('../../constants/xmlns_namespaces');
  45621. var ensureSingle = Lib.ensureSingle;
  45622. function ensureSingleAndAddDatum(parent, nodeType, className) {
  45623. return Lib.ensureSingle(parent, nodeType, className, function(s) {
  45624. s.datum(className);
  45625. });
  45626. }
  45627. exports.name = 'cartesian';
  45628. exports.attr = ['xaxis', 'yaxis'];
  45629. exports.idRoot = ['x', 'y'];
  45630. exports.idRegex = constants.idRegex;
  45631. exports.attrRegex = constants.attrRegex;
  45632. exports.attributes = _dereq_('./attributes');
  45633. exports.layoutAttributes = _dereq_('./layout_attributes');
  45634. exports.supplyLayoutDefaults = _dereq_('./layout_defaults');
  45635. exports.transitionAxes = _dereq_('./transition_axes');
  45636. exports.finalizeSubplots = function(layoutIn, layoutOut) {
  45637. var subplots = layoutOut._subplots;
  45638. var xList = subplots.xaxis;
  45639. var yList = subplots.yaxis;
  45640. var spSVG = subplots.cartesian;
  45641. var spAll = spSVG.concat(subplots.gl2d || []);
  45642. var allX = {};
  45643. var allY = {};
  45644. var i, xi, yi;
  45645. for(i = 0; i < spAll.length; i++) {
  45646. var parts = spAll[i].split('y');
  45647. allX[parts[0]] = 1;
  45648. allY['y' + parts[1]] = 1;
  45649. }
  45650. // check for x axes with no subplot, and make one from the anchor of that x axis
  45651. for(i = 0; i < xList.length; i++) {
  45652. xi = xList[i];
  45653. if(!allX[xi]) {
  45654. yi = (layoutIn[axisIds.id2name(xi)] || {}).anchor;
  45655. if(!constants.idRegex.y.test(yi)) yi = 'y';
  45656. spSVG.push(xi + yi);
  45657. spAll.push(xi + yi);
  45658. if(!allY[yi]) {
  45659. allY[yi] = 1;
  45660. Lib.pushUnique(yList, yi);
  45661. }
  45662. }
  45663. }
  45664. // same for y axes with no subplot
  45665. for(i = 0; i < yList.length; i++) {
  45666. yi = yList[i];
  45667. if(!allY[yi]) {
  45668. xi = (layoutIn[axisIds.id2name(yi)] || {}).anchor;
  45669. if(!constants.idRegex.x.test(xi)) xi = 'x';
  45670. spSVG.push(xi + yi);
  45671. spAll.push(xi + yi);
  45672. if(!allX[xi]) {
  45673. allX[xi] = 1;
  45674. Lib.pushUnique(xList, xi);
  45675. }
  45676. }
  45677. }
  45678. // finally, if we've gotten here we're supposed to show cartesian...
  45679. // so if there are NO subplots at all, make one from the first
  45680. // x & y axes in the input layout
  45681. if(!spAll.length) {
  45682. xi = '';
  45683. yi = '';
  45684. for(var ki in layoutIn) {
  45685. if(constants.attrRegex.test(ki)) {
  45686. var axLetter = ki.charAt(0);
  45687. if(axLetter === 'x') {
  45688. if(!xi || (+ki.substr(5) < +xi.substr(5))) {
  45689. xi = ki;
  45690. }
  45691. }
  45692. else if(!yi || (+ki.substr(5) < +yi.substr(5))) {
  45693. yi = ki;
  45694. }
  45695. }
  45696. }
  45697. xi = xi ? axisIds.name2id(xi) : 'x';
  45698. yi = yi ? axisIds.name2id(yi) : 'y';
  45699. xList.push(xi);
  45700. yList.push(yi);
  45701. spSVG.push(xi + yi);
  45702. }
  45703. };
  45704. /**
  45705. * Cartesian.plot
  45706. *
  45707. * @param {DOM div | object} gd
  45708. * @param {array | null} (optional) traces
  45709. * array of traces indices to plot
  45710. * if undefined, plots all cartesian traces,
  45711. * if null, plots no traces
  45712. * @param {object} (optional) transitionOpts
  45713. * transition option object
  45714. * @param {function} (optional) makeOnCompleteCallback
  45715. * transition make callback function from Plots.transition
  45716. */
  45717. exports.plot = function(gd, traces, transitionOpts, makeOnCompleteCallback) {
  45718. var fullLayout = gd._fullLayout;
  45719. var subplots = fullLayout._subplots.cartesian;
  45720. var calcdata = gd.calcdata;
  45721. var i;
  45722. if(traces === null) {
  45723. // this means no updates required, must return here
  45724. // so that plotOne doesn't remove the trace layers
  45725. return;
  45726. } else if(!Array.isArray(traces)) {
  45727. // If traces is not provided, then it's a complete replot and missing
  45728. // traces are removed
  45729. traces = [];
  45730. for(i = 0; i < calcdata.length; i++) traces.push(i);
  45731. }
  45732. for(i = 0; i < subplots.length; i++) {
  45733. var subplot = subplots[i];
  45734. var subplotInfo = fullLayout._plots[subplot];
  45735. // Get all calcdata for this subplot:
  45736. var cdSubplot = [];
  45737. var pcd;
  45738. for(var j = 0; j < calcdata.length; j++) {
  45739. var cd = calcdata[j];
  45740. var trace = cd[0].trace;
  45741. // Skip trace if whitelist provided and it's not whitelisted:
  45742. // if (Array.isArray(traces) && traces.indexOf(i) === -1) continue;
  45743. if(trace.xaxis + trace.yaxis === subplot) {
  45744. // XXX: Should trace carpet dependencies. Only replot all carpet plots if the carpet
  45745. // axis has actually changed:
  45746. //
  45747. // If this trace is specifically requested, add it to the list:
  45748. if(traces.indexOf(trace.index) !== -1 || trace.carpet) {
  45749. // Okay, so example: traces 0, 1, and 2 have fill = tonext. You animate
  45750. // traces 0 and 2. Trace 1 also needs to be updated, otherwise its fill
  45751. // is outdated. So this retroactively adds the previous trace if the
  45752. // traces are interdependent.
  45753. if(
  45754. pcd &&
  45755. pcd[0].trace.xaxis + pcd[0].trace.yaxis === subplot &&
  45756. ['tonextx', 'tonexty', 'tonext'].indexOf(trace.fill) !== -1 &&
  45757. cdSubplot.indexOf(pcd) === -1
  45758. ) {
  45759. cdSubplot.push(pcd);
  45760. }
  45761. cdSubplot.push(cd);
  45762. }
  45763. // Track the previous trace on this subplot for the retroactive-add step
  45764. // above:
  45765. pcd = cd;
  45766. }
  45767. }
  45768. plotOne(gd, subplotInfo, cdSubplot, transitionOpts, makeOnCompleteCallback);
  45769. }
  45770. };
  45771. function plotOne(gd, plotinfo, cdSubplot, transitionOpts, makeOnCompleteCallback) {
  45772. var traceLayerClasses = constants.traceLayerClasses;
  45773. var fullLayout = gd._fullLayout;
  45774. var modules = fullLayout._modules;
  45775. var _module, cdModuleAndOthers, cdModule;
  45776. var layerData = [];
  45777. var zoomScaleQueryParts = [];
  45778. for(var i = 0; i < modules.length; i++) {
  45779. _module = modules[i];
  45780. var name = _module.name;
  45781. var categories = Registry.modules[name].categories;
  45782. if(categories.svg) {
  45783. var className = (_module.layerName || name + 'layer');
  45784. var plotMethod = _module.plot;
  45785. // plot all visible traces of this type on this subplot at once
  45786. cdModuleAndOthers = getModuleCalcData(cdSubplot, plotMethod);
  45787. cdModule = cdModuleAndOthers[0];
  45788. // don't need to search the found traces again - in fact we need to NOT
  45789. // so that if two modules share the same plotter we don't double-plot
  45790. cdSubplot = cdModuleAndOthers[1];
  45791. if(cdModule.length) {
  45792. layerData.push({
  45793. i: traceLayerClasses.indexOf(className),
  45794. className: className,
  45795. plotMethod: plotMethod,
  45796. cdModule: cdModule
  45797. });
  45798. }
  45799. if(categories.zoomScale) {
  45800. zoomScaleQueryParts.push('.' + className);
  45801. }
  45802. }
  45803. }
  45804. layerData.sort(function(a, b) { return a.i - b.i; });
  45805. var layers = plotinfo.plot.selectAll('g.mlayer')
  45806. .data(layerData, function(d) { return d.className; });
  45807. layers.enter().append('g')
  45808. .attr('class', function(d) { return d.className; })
  45809. .classed('mlayer', true);
  45810. layers.exit().remove();
  45811. layers.order();
  45812. layers.each(function(d) {
  45813. var sel = d3.select(this);
  45814. var className = d.className;
  45815. d.plotMethod(
  45816. gd, plotinfo, d.cdModule, sel,
  45817. transitionOpts, makeOnCompleteCallback
  45818. );
  45819. // layers that allow `cliponaxis: false`
  45820. if(className !== 'scatterlayer' && className !== 'barlayer') {
  45821. Drawing.setClipUrl(sel, plotinfo.layerClipId);
  45822. }
  45823. });
  45824. // call Scattergl.plot separately
  45825. if(fullLayout._has('scattergl')) {
  45826. _module = Registry.getModule('scattergl');
  45827. cdModule = getModuleCalcData(cdSubplot, _module)[0];
  45828. _module.plot(gd, plotinfo, cdModule);
  45829. }
  45830. // stash "hot" selections for faster interaction on drag and scroll
  45831. if(!gd._context.staticPlot) {
  45832. if(plotinfo._hasClipOnAxisFalse) {
  45833. plotinfo.clipOnAxisFalseTraces = plotinfo.plot
  45834. .selectAll('.scatterlayer, .barlayer')
  45835. .selectAll('.trace');
  45836. }
  45837. if(zoomScaleQueryParts.length) {
  45838. var traces = plotinfo.plot
  45839. .selectAll(zoomScaleQueryParts.join(','))
  45840. .selectAll('.trace');
  45841. plotinfo.zoomScalePts = traces.selectAll('path.point');
  45842. plotinfo.zoomScaleTxt = traces.selectAll('.textpoint');
  45843. }
  45844. }
  45845. }
  45846. exports.clean = function(newFullData, newFullLayout, oldFullData, oldFullLayout) {
  45847. var oldPlots = oldFullLayout._plots || {};
  45848. var newPlots = newFullLayout._plots || {};
  45849. var oldSubplotList = oldFullLayout._subplots || {};
  45850. var plotinfo;
  45851. var i, k;
  45852. // when going from a large splom graph to something else,
  45853. // we need to clear <g subplot> so that the new cartesian subplot
  45854. // can have the correct layer ordering
  45855. if(oldFullLayout._hasOnlyLargeSploms && !newFullLayout._hasOnlyLargeSploms) {
  45856. for(k in oldPlots) {
  45857. plotinfo = oldPlots[k];
  45858. if(plotinfo.plotgroup) plotinfo.plotgroup.remove();
  45859. }
  45860. }
  45861. var hadGl = (oldFullLayout._has && oldFullLayout._has('gl'));
  45862. var hasGl = (newFullLayout._has && newFullLayout._has('gl'));
  45863. if(hadGl && !hasGl) {
  45864. for(k in oldPlots) {
  45865. plotinfo = oldPlots[k];
  45866. if(plotinfo._scene) plotinfo._scene.destroy();
  45867. }
  45868. }
  45869. // delete any titles we don't need anymore
  45870. // check if axis list has changed, and if so clear old titles
  45871. if(oldSubplotList.xaxis && oldSubplotList.yaxis) {
  45872. var oldAxIDs = axisIds.listIds({_fullLayout: oldFullLayout});
  45873. for(i = 0; i < oldAxIDs.length; i++) {
  45874. var oldAxId = oldAxIDs[i];
  45875. if(!newFullLayout[axisIds.id2name(oldAxId)]) {
  45876. oldFullLayout._infolayer.selectAll('.g-' + oldAxId + 'title').remove();
  45877. }
  45878. }
  45879. }
  45880. // if we've gotten rid of all cartesian traces, remove all the subplot svg items
  45881. var hadCartesian = (oldFullLayout._has && oldFullLayout._has('cartesian'));
  45882. var hasCartesian = (newFullLayout._has && newFullLayout._has('cartesian'));
  45883. if(hadCartesian && !hasCartesian) {
  45884. purgeSubplotLayers(oldFullLayout._cartesianlayer.selectAll('.subplot'), oldFullLayout);
  45885. oldFullLayout._defs.selectAll('.axesclip').remove();
  45886. delete oldFullLayout._axisConstraintGroups;
  45887. }
  45888. // otherwise look for subplots we need to remove
  45889. else if(oldSubplotList.cartesian) {
  45890. for(i = 0; i < oldSubplotList.cartesian.length; i++) {
  45891. var oldSubplotId = oldSubplotList.cartesian[i];
  45892. if(!newPlots[oldSubplotId]) {
  45893. var selector = '.' + oldSubplotId + ',.' + oldSubplotId + '-x,.' + oldSubplotId + '-y';
  45894. oldFullLayout._cartesianlayer.selectAll(selector).remove();
  45895. removeSubplotExtras(oldSubplotId, oldFullLayout);
  45896. }
  45897. }
  45898. }
  45899. };
  45900. exports.drawFramework = function(gd) {
  45901. var fullLayout = gd._fullLayout;
  45902. var subplotData = makeSubplotData(gd);
  45903. var subplotLayers = fullLayout._cartesianlayer.selectAll('.subplot')
  45904. .data(subplotData, String);
  45905. subplotLayers.enter().append('g')
  45906. .attr('class', function(d) { return 'subplot ' + d[0]; });
  45907. subplotLayers.order();
  45908. subplotLayers.exit()
  45909. .call(purgeSubplotLayers, fullLayout);
  45910. subplotLayers.each(function(d) {
  45911. var id = d[0];
  45912. var plotinfo = fullLayout._plots[id];
  45913. plotinfo.plotgroup = d3.select(this);
  45914. makeSubplotLayer(gd, plotinfo);
  45915. // make separate drag layers for each subplot,
  45916. // but append them to paper rather than the plot groups,
  45917. // so they end up on top of the rest
  45918. plotinfo.draglayer = ensureSingle(fullLayout._draggers, 'g', id);
  45919. });
  45920. };
  45921. exports.rangePlot = function(gd, plotinfo, cdSubplot) {
  45922. makeSubplotLayer(gd, plotinfo);
  45923. plotOne(gd, plotinfo, cdSubplot);
  45924. Plots.style(gd);
  45925. };
  45926. function makeSubplotData(gd) {
  45927. var fullLayout = gd._fullLayout;
  45928. var ids = fullLayout._subplots.cartesian;
  45929. var len = ids.length;
  45930. var i, j, id, plotinfo, xa, ya;
  45931. // split 'regular' and 'overlaying' subplots
  45932. var regulars = [];
  45933. var overlays = [];
  45934. for(i = 0; i < len; i++) {
  45935. id = ids[i];
  45936. plotinfo = fullLayout._plots[id];
  45937. xa = plotinfo.xaxis;
  45938. ya = plotinfo.yaxis;
  45939. var xa2 = xa._mainAxis;
  45940. var ya2 = ya._mainAxis;
  45941. var mainplot = xa2._id + ya2._id;
  45942. var mainplotinfo = fullLayout._plots[mainplot];
  45943. plotinfo.overlays = [];
  45944. if(mainplot !== id && mainplotinfo) {
  45945. plotinfo.mainplot = mainplot;
  45946. plotinfo.mainplotinfo = mainplotinfo;
  45947. overlays.push(id);
  45948. } else {
  45949. plotinfo.mainplot = undefined;
  45950. plotinfo.mainPlotinfo = undefined;
  45951. regulars.push(id);
  45952. }
  45953. }
  45954. // fill in list of overlaying subplots in 'main plot'
  45955. for(i = 0; i < overlays.length; i++) {
  45956. id = overlays[i];
  45957. plotinfo = fullLayout._plots[id];
  45958. plotinfo.mainplotinfo.overlays.push(plotinfo);
  45959. }
  45960. // put 'regular' subplot data before 'overlaying'
  45961. var subplotIds = regulars.concat(overlays);
  45962. var subplotData = new Array(len);
  45963. for(i = 0; i < len; i++) {
  45964. id = subplotIds[i];
  45965. plotinfo = fullLayout._plots[id];
  45966. xa = plotinfo.xaxis;
  45967. ya = plotinfo.yaxis;
  45968. // use info about axis layer and overlaying pattern
  45969. // to clean what need to be cleaned up in exit selection
  45970. var d = [id, xa.layer, ya.layer, xa.overlaying || '', ya.overlaying || ''];
  45971. for(j = 0; j < plotinfo.overlays.length; j++) {
  45972. d.push(plotinfo.overlays[j].id);
  45973. }
  45974. subplotData[i] = d;
  45975. }
  45976. return subplotData;
  45977. }
  45978. function makeSubplotLayer(gd, plotinfo) {
  45979. var plotgroup = plotinfo.plotgroup;
  45980. var id = plotinfo.id;
  45981. var xLayer = constants.layerValue2layerClass[plotinfo.xaxis.layer];
  45982. var yLayer = constants.layerValue2layerClass[plotinfo.yaxis.layer];
  45983. var hasOnlyLargeSploms = gd._fullLayout._hasOnlyLargeSploms;
  45984. if(!plotinfo.mainplot) {
  45985. if(hasOnlyLargeSploms) {
  45986. // TODO could do even better
  45987. // - we don't need plot (but we would have to mock it in lsInner
  45988. // and other places
  45989. // - we don't (x|y)lines and (x|y)axislayer for most subplots
  45990. // usually just the bottom x and left y axes.
  45991. plotinfo.plot = ensureSingle(plotgroup, 'g', 'plot');
  45992. plotinfo.xlines = ensureSingle(plotgroup, 'path', 'xlines-above');
  45993. plotinfo.ylines = ensureSingle(plotgroup, 'path', 'ylines-above');
  45994. plotinfo.xaxislayer = ensureSingle(plotgroup, 'g', 'xaxislayer-above');
  45995. plotinfo.yaxislayer = ensureSingle(plotgroup, 'g', 'yaxislayer-above');
  45996. }
  45997. else {
  45998. var backLayer = ensureSingle(plotgroup, 'g', 'layer-subplot');
  45999. plotinfo.shapelayer = ensureSingle(backLayer, 'g', 'shapelayer');
  46000. plotinfo.imagelayer = ensureSingle(backLayer, 'g', 'imagelayer');
  46001. plotinfo.gridlayer = ensureSingle(plotgroup, 'g', 'gridlayer');
  46002. plotinfo.zerolinelayer = ensureSingle(plotgroup, 'g', 'zerolinelayer');
  46003. ensureSingle(plotgroup, 'path', 'xlines-below');
  46004. ensureSingle(plotgroup, 'path', 'ylines-below');
  46005. plotinfo.overlinesBelow = ensureSingle(plotgroup, 'g', 'overlines-below');
  46006. ensureSingle(plotgroup, 'g', 'xaxislayer-below');
  46007. ensureSingle(plotgroup, 'g', 'yaxislayer-below');
  46008. plotinfo.overaxesBelow = ensureSingle(plotgroup, 'g', 'overaxes-below');
  46009. plotinfo.plot = ensureSingle(plotgroup, 'g', 'plot');
  46010. plotinfo.overplot = ensureSingle(plotgroup, 'g', 'overplot');
  46011. plotinfo.xlines = ensureSingle(plotgroup, 'path', 'xlines-above');
  46012. plotinfo.ylines = ensureSingle(plotgroup, 'path', 'ylines-above');
  46013. plotinfo.overlinesAbove = ensureSingle(plotgroup, 'g', 'overlines-above');
  46014. ensureSingle(plotgroup, 'g', 'xaxislayer-above');
  46015. ensureSingle(plotgroup, 'g', 'yaxislayer-above');
  46016. plotinfo.overaxesAbove = ensureSingle(plotgroup, 'g', 'overaxes-above');
  46017. // set refs to correct layers as determined by 'axis.layer'
  46018. plotinfo.xlines = plotgroup.select('.xlines-' + xLayer);
  46019. plotinfo.ylines = plotgroup.select('.ylines-' + yLayer);
  46020. plotinfo.xaxislayer = plotgroup.select('.xaxislayer-' + xLayer);
  46021. plotinfo.yaxislayer = plotgroup.select('.yaxislayer-' + yLayer);
  46022. }
  46023. }
  46024. else {
  46025. var mainplotinfo = plotinfo.mainplotinfo;
  46026. var mainplotgroup = mainplotinfo.plotgroup;
  46027. var xId = id + '-x';
  46028. var yId = id + '-y';
  46029. // now make the components of overlaid subplots
  46030. // overlays don't have backgrounds, and append all
  46031. // their other components to the corresponding
  46032. // extra groups of their main plots.
  46033. plotinfo.gridlayer = mainplotinfo.gridlayer;
  46034. plotinfo.zerolinelayer = mainplotinfo.zerolinelayer;
  46035. ensureSingle(mainplotinfo.overlinesBelow, 'path', xId);
  46036. ensureSingle(mainplotinfo.overlinesBelow, 'path', yId);
  46037. ensureSingle(mainplotinfo.overaxesBelow, 'g', xId);
  46038. ensureSingle(mainplotinfo.overaxesBelow, 'g', yId);
  46039. plotinfo.plot = ensureSingle(mainplotinfo.overplot, 'g', id);
  46040. ensureSingle(mainplotinfo.overlinesAbove, 'path', xId);
  46041. ensureSingle(mainplotinfo.overlinesAbove, 'path', yId);
  46042. ensureSingle(mainplotinfo.overaxesAbove, 'g', xId);
  46043. ensureSingle(mainplotinfo.overaxesAbove, 'g', yId);
  46044. // set refs to correct layers as determined by 'abovetraces'
  46045. plotinfo.xlines = mainplotgroup.select('.overlines-' + xLayer).select('.' + xId);
  46046. plotinfo.ylines = mainplotgroup.select('.overlines-' + yLayer).select('.' + yId);
  46047. plotinfo.xaxislayer = mainplotgroup.select('.overaxes-' + xLayer).select('.' + xId);
  46048. plotinfo.yaxislayer = mainplotgroup.select('.overaxes-' + yLayer).select('.' + yId);
  46049. }
  46050. // common attributes for all subplots, overlays or not
  46051. if(!hasOnlyLargeSploms) {
  46052. ensureSingleAndAddDatum(plotinfo.gridlayer, 'g', plotinfo.xaxis._id);
  46053. ensureSingleAndAddDatum(plotinfo.gridlayer, 'g', plotinfo.yaxis._id);
  46054. plotinfo.gridlayer.selectAll('g')
  46055. .map(function(d) { return d[0]; })
  46056. .sort(axisIds.idSort);
  46057. }
  46058. plotinfo.xlines
  46059. .style('fill', 'none')
  46060. .classed('crisp', true);
  46061. plotinfo.ylines
  46062. .style('fill', 'none')
  46063. .classed('crisp', true);
  46064. }
  46065. function purgeSubplotLayers(layers, fullLayout) {
  46066. if(!layers) return;
  46067. var overlayIdsToRemove = {};
  46068. layers.each(function(d) {
  46069. var id = d[0];
  46070. var plotgroup = d3.select(this);
  46071. plotgroup.remove();
  46072. removeSubplotExtras(id, fullLayout);
  46073. overlayIdsToRemove[id] = true;
  46074. // do not remove individual axis <clipPath>s here
  46075. // as other subplots may need them
  46076. });
  46077. // must remove overlaid subplot trace layers 'manually'
  46078. for(var k in fullLayout._plots) {
  46079. var subplotInfo = fullLayout._plots[k];
  46080. var overlays = subplotInfo.overlays || [];
  46081. for(var j = 0; j < overlays.length; j++) {
  46082. var overlayInfo = overlays[j];
  46083. if(overlayIdsToRemove[overlayInfo.id]) {
  46084. overlayInfo.plot.selectAll('.trace').remove();
  46085. }
  46086. }
  46087. }
  46088. }
  46089. function removeSubplotExtras(subplotId, fullLayout) {
  46090. fullLayout._draggers.selectAll('g.' + subplotId).remove();
  46091. fullLayout._defs.select('#clip' + fullLayout._uid + subplotId + 'plot').remove();
  46092. }
  46093. exports.toSVG = function(gd) {
  46094. var imageRoot = gd._fullLayout._glimages;
  46095. var root = d3.select(gd).selectAll('.svg-container');
  46096. var canvases = root.filter(function(d, i) {return i === root.size() - 1;})
  46097. .selectAll('.gl-canvas-context, .gl-canvas-focus');
  46098. function canvasToImage() {
  46099. var canvas = this;
  46100. var imageData = canvas.toDataURL('image/png');
  46101. var image = imageRoot.append('svg:image');
  46102. image.attr({
  46103. xmlns: xmlnsNamespaces.svg,
  46104. 'xlink:href': imageData,
  46105. preserveAspectRatio: 'none',
  46106. x: 0,
  46107. y: 0,
  46108. width: canvas.width,
  46109. height: canvas.height
  46110. });
  46111. }
  46112. canvases.each(canvasToImage);
  46113. };
  46114. exports.updateFx = _dereq_('./graph_interact').updateFx;
  46115. },{"../../components/drawing":75,"../../constants/xmlns_namespaces":152,"../../lib":169,"../../registry":259,"../get_data":242,"../plots":246,"./attributes":212,"./axis_ids":217,"./constants":219,"./graph_interact":223,"./layout_attributes":226,"./layout_defaults":227,"./transition_axes":236,"d3":16}],226:[function(_dereq_,module,exports){
  46116. /**
  46117. * Copyright 2012-2018, Plotly, Inc.
  46118. * All rights reserved.
  46119. *
  46120. * This source code is licensed under the MIT license found in the
  46121. * LICENSE file in the root directory of this source tree.
  46122. */
  46123. 'use strict';
  46124. var fontAttrs = _dereq_('../font_attributes');
  46125. var colorAttrs = _dereq_('../../components/color/attributes');
  46126. var dash = _dereq_('../../components/drawing/attributes').dash;
  46127. var extendFlat = _dereq_('../../lib/extend').extendFlat;
  46128. var templatedArray = _dereq_('../../plot_api/plot_template').templatedArray;
  46129. var constants = _dereq_('./constants');
  46130. module.exports = {
  46131. visible: {
  46132. valType: 'boolean',
  46133. editType: 'plot',
  46134. },
  46135. color: {
  46136. valType: 'color',
  46137. dflt: colorAttrs.defaultLine,
  46138. editType: 'ticks',
  46139. },
  46140. title: {
  46141. valType: 'string',
  46142. editType: 'ticks',
  46143. },
  46144. titlefont: fontAttrs({
  46145. editType: 'ticks',
  46146. }),
  46147. type: {
  46148. valType: 'enumerated',
  46149. // '-' means we haven't yet run autotype or couldn't find any data
  46150. // it gets turned into linear in gd._fullLayout but not copied back
  46151. // to gd.data like the others are.
  46152. values: ['-', 'linear', 'log', 'date', 'category'],
  46153. dflt: '-',
  46154. editType: 'calc',
  46155. // we forget when an axis has been autotyped, just writing the auto
  46156. // value back to the input - so it doesn't make sense to template this.
  46157. // Note: we do NOT prohibit this in `coerce`, so if someone enters a
  46158. // type in the template explicitly it will be honored as the default.
  46159. _noTemplating: true,
  46160. },
  46161. autorange: {
  46162. valType: 'enumerated',
  46163. values: [true, false, 'reversed'],
  46164. dflt: true,
  46165. editType: 'axrange',
  46166. impliedEdits: {'range[0]': undefined, 'range[1]': undefined},
  46167. },
  46168. rangemode: {
  46169. valType: 'enumerated',
  46170. values: ['normal', 'tozero', 'nonnegative'],
  46171. dflt: 'normal',
  46172. editType: 'plot',
  46173. },
  46174. range: {
  46175. valType: 'info_array',
  46176. items: [
  46177. {valType: 'any', editType: 'axrange', impliedEdits: {'^autorange': false}},
  46178. {valType: 'any', editType: 'axrange', impliedEdits: {'^autorange': false}}
  46179. ],
  46180. editType: 'axrange',
  46181. impliedEdits: {'autorange': false},
  46182. },
  46183. fixedrange: {
  46184. valType: 'boolean',
  46185. dflt: false,
  46186. editType: 'calc',
  46187. },
  46188. // scaleanchor: not used directly, just put here for reference
  46189. // values are any opposite-letter axis id
  46190. scaleanchor: {
  46191. valType: 'enumerated',
  46192. values: [
  46193. constants.idRegex.x.toString(),
  46194. constants.idRegex.y.toString()
  46195. ],
  46196. editType: 'plot',
  46197. },
  46198. scaleratio: {
  46199. valType: 'number',
  46200. min: 0,
  46201. dflt: 1,
  46202. editType: 'plot',
  46203. },
  46204. constrain: {
  46205. valType: 'enumerated',
  46206. values: ['range', 'domain'],
  46207. dflt: 'range',
  46208. editType: 'plot',
  46209. },
  46210. // constraintoward: not used directly, just put here for reference
  46211. constraintoward: {
  46212. valType: 'enumerated',
  46213. values: ['left', 'center', 'right', 'top', 'middle', 'bottom'],
  46214. editType: 'plot',
  46215. },
  46216. // ticks
  46217. tickmode: {
  46218. valType: 'enumerated',
  46219. values: ['auto', 'linear', 'array'],
  46220. editType: 'ticks',
  46221. impliedEdits: {tick0: undefined, dtick: undefined},
  46222. },
  46223. nticks: {
  46224. valType: 'integer',
  46225. min: 0,
  46226. dflt: 0,
  46227. editType: 'ticks',
  46228. },
  46229. tick0: {
  46230. valType: 'any',
  46231. editType: 'ticks',
  46232. impliedEdits: {tickmode: 'linear'},
  46233. },
  46234. dtick: {
  46235. valType: 'any',
  46236. editType: 'ticks',
  46237. impliedEdits: {tickmode: 'linear'},
  46238. },
  46239. tickvals: {
  46240. valType: 'data_array',
  46241. editType: 'ticks',
  46242. },
  46243. ticktext: {
  46244. valType: 'data_array',
  46245. editType: 'ticks',
  46246. },
  46247. ticks: {
  46248. valType: 'enumerated',
  46249. values: ['outside', 'inside', ''],
  46250. editType: 'ticks',
  46251. },
  46252. mirror: {
  46253. valType: 'enumerated',
  46254. values: [true, 'ticks', false, 'all', 'allticks'],
  46255. dflt: false,
  46256. editType: 'ticks+layoutstyle',
  46257. },
  46258. ticklen: {
  46259. valType: 'number',
  46260. min: 0,
  46261. dflt: 5,
  46262. editType: 'ticks',
  46263. },
  46264. tickwidth: {
  46265. valType: 'number',
  46266. min: 0,
  46267. dflt: 1,
  46268. editType: 'ticks',
  46269. },
  46270. tickcolor: {
  46271. valType: 'color',
  46272. dflt: colorAttrs.defaultLine,
  46273. editType: 'ticks',
  46274. },
  46275. showticklabels: {
  46276. valType: 'boolean',
  46277. dflt: true,
  46278. editType: 'ticks',
  46279. },
  46280. automargin: {
  46281. valType: 'boolean',
  46282. dflt: false,
  46283. editType: 'ticks',
  46284. },
  46285. showspikes: {
  46286. valType: 'boolean',
  46287. dflt: false,
  46288. editType: 'modebar',
  46289. },
  46290. spikecolor: {
  46291. valType: 'color',
  46292. dflt: null,
  46293. editType: 'none',
  46294. },
  46295. spikethickness: {
  46296. valType: 'number',
  46297. dflt: 3,
  46298. editType: 'none',
  46299. },
  46300. spikedash: extendFlat({}, dash, {dflt: 'dash', editType: 'none'}),
  46301. spikemode: {
  46302. valType: 'flaglist',
  46303. flags: ['toaxis', 'across', 'marker'],
  46304. dflt: 'toaxis',
  46305. editType: 'none',
  46306. },
  46307. spikesnap: {
  46308. valType: 'enumerated',
  46309. values: ['data', 'cursor'],
  46310. dflt: 'data',
  46311. editType: 'none',
  46312. },
  46313. tickfont: fontAttrs({
  46314. editType: 'ticks',
  46315. }),
  46316. tickangle: {
  46317. valType: 'angle',
  46318. dflt: 'auto',
  46319. editType: 'ticks',
  46320. },
  46321. tickprefix: {
  46322. valType: 'string',
  46323. dflt: '',
  46324. editType: 'ticks',
  46325. },
  46326. showtickprefix: {
  46327. valType: 'enumerated',
  46328. values: ['all', 'first', 'last', 'none'],
  46329. dflt: 'all',
  46330. editType: 'ticks',
  46331. },
  46332. ticksuffix: {
  46333. valType: 'string',
  46334. dflt: '',
  46335. editType: 'ticks',
  46336. },
  46337. showticksuffix: {
  46338. valType: 'enumerated',
  46339. values: ['all', 'first', 'last', 'none'],
  46340. dflt: 'all',
  46341. editType: 'ticks',
  46342. },
  46343. showexponent: {
  46344. valType: 'enumerated',
  46345. values: ['all', 'first', 'last', 'none'],
  46346. dflt: 'all',
  46347. editType: 'ticks',
  46348. },
  46349. exponentformat: {
  46350. valType: 'enumerated',
  46351. values: ['none', 'e', 'E', 'power', 'SI', 'B'],
  46352. dflt: 'B',
  46353. editType: 'ticks',
  46354. },
  46355. separatethousands: {
  46356. valType: 'boolean',
  46357. dflt: false,
  46358. editType: 'ticks',
  46359. },
  46360. tickformat: {
  46361. valType: 'string',
  46362. dflt: '',
  46363. editType: 'ticks',
  46364. },
  46365. tickformatstops: templatedArray('tickformatstop', {
  46366. enabled: {
  46367. valType: 'boolean',
  46368. dflt: true,
  46369. editType: 'ticks',
  46370. },
  46371. dtickrange: {
  46372. valType: 'info_array',
  46373. items: [
  46374. {valType: 'any', editType: 'ticks'},
  46375. {valType: 'any', editType: 'ticks'}
  46376. ],
  46377. editType: 'ticks',
  46378. },
  46379. value: {
  46380. valType: 'string',
  46381. dflt: '',
  46382. editType: 'ticks',
  46383. },
  46384. editType: 'ticks'
  46385. }),
  46386. hoverformat: {
  46387. valType: 'string',
  46388. dflt: '',
  46389. editType: 'none',
  46390. },
  46391. // lines and grids
  46392. showline: {
  46393. valType: 'boolean',
  46394. dflt: false,
  46395. editType: 'ticks+layoutstyle',
  46396. },
  46397. linecolor: {
  46398. valType: 'color',
  46399. dflt: colorAttrs.defaultLine,
  46400. editType: 'layoutstyle',
  46401. },
  46402. linewidth: {
  46403. valType: 'number',
  46404. min: 0,
  46405. dflt: 1,
  46406. editType: 'ticks+layoutstyle',
  46407. },
  46408. showgrid: {
  46409. valType: 'boolean',
  46410. editType: 'ticks',
  46411. },
  46412. gridcolor: {
  46413. valType: 'color',
  46414. dflt: colorAttrs.lightLine,
  46415. editType: 'ticks',
  46416. },
  46417. gridwidth: {
  46418. valType: 'number',
  46419. min: 0,
  46420. dflt: 1,
  46421. editType: 'ticks',
  46422. },
  46423. zeroline: {
  46424. valType: 'boolean',
  46425. editType: 'ticks',
  46426. },
  46427. zerolinecolor: {
  46428. valType: 'color',
  46429. dflt: colorAttrs.defaultLine,
  46430. editType: 'ticks',
  46431. },
  46432. zerolinewidth: {
  46433. valType: 'number',
  46434. dflt: 1,
  46435. editType: 'ticks',
  46436. },
  46437. // positioning attributes
  46438. // anchor: not used directly, just put here for reference
  46439. // values are any opposite-letter axis id
  46440. anchor: {
  46441. valType: 'enumerated',
  46442. values: [
  46443. 'free',
  46444. constants.idRegex.x.toString(),
  46445. constants.idRegex.y.toString()
  46446. ],
  46447. editType: 'plot',
  46448. },
  46449. // side: not used directly, as values depend on direction
  46450. // values are top, bottom for x axes, and left, right for y
  46451. side: {
  46452. valType: 'enumerated',
  46453. values: ['top', 'bottom', 'left', 'right'],
  46454. editType: 'plot',
  46455. },
  46456. // overlaying: not used directly, just put here for reference
  46457. // values are false and any other same-letter axis id that's not
  46458. // itself overlaying anything
  46459. overlaying: {
  46460. valType: 'enumerated',
  46461. values: [
  46462. 'free',
  46463. constants.idRegex.x.toString(),
  46464. constants.idRegex.y.toString()
  46465. ],
  46466. editType: 'plot',
  46467. },
  46468. layer: {
  46469. valType: 'enumerated',
  46470. values: ['above traces', 'below traces'],
  46471. dflt: 'above traces',
  46472. editType: 'plot',
  46473. },
  46474. domain: {
  46475. valType: 'info_array',
  46476. items: [
  46477. {valType: 'number', min: 0, max: 1, editType: 'plot'},
  46478. {valType: 'number', min: 0, max: 1, editType: 'plot'}
  46479. ],
  46480. dflt: [0, 1],
  46481. editType: 'plot',
  46482. },
  46483. position: {
  46484. valType: 'number',
  46485. min: 0,
  46486. max: 1,
  46487. dflt: 0,
  46488. editType: 'plot',
  46489. },
  46490. categoryorder: {
  46491. valType: 'enumerated',
  46492. values: [
  46493. 'trace', 'category ascending', 'category descending', 'array'
  46494. /* , 'value ascending', 'value descending'*/ // value ascending / descending to be implemented later
  46495. ],
  46496. dflt: 'trace',
  46497. editType: 'calc',
  46498. },
  46499. categoryarray: {
  46500. valType: 'data_array',
  46501. editType: 'calc',
  46502. },
  46503. editType: 'calc',
  46504. _deprecated: {
  46505. autotick: {
  46506. valType: 'boolean',
  46507. editType: 'ticks',
  46508. }
  46509. }
  46510. };
  46511. },{"../../components/color/attributes":49,"../../components/drawing/attributes":74,"../../lib/extend":163,"../../plot_api/plot_template":204,"../font_attributes":240,"./constants":219}],227:[function(_dereq_,module,exports){
  46512. /**
  46513. * Copyright 2012-2018, Plotly, Inc.
  46514. * All rights reserved.
  46515. *
  46516. * This source code is licensed under the MIT license found in the
  46517. * LICENSE file in the root directory of this source tree.
  46518. */
  46519. 'use strict';
  46520. var Lib = _dereq_('../../lib');
  46521. var Color = _dereq_('../../components/color');
  46522. var Template = _dereq_('../../plot_api/plot_template');
  46523. var basePlotLayoutAttributes = _dereq_('../layout_attributes');
  46524. var layoutAttributes = _dereq_('./layout_attributes');
  46525. var handleTypeDefaults = _dereq_('./type_defaults');
  46526. var handleAxisDefaults = _dereq_('./axis_defaults');
  46527. var handleConstraintDefaults = _dereq_('./constraint_defaults');
  46528. var handlePositionDefaults = _dereq_('./position_defaults');
  46529. var axisIds = _dereq_('./axis_ids');
  46530. var id2name = axisIds.id2name;
  46531. var name2id = axisIds.name2id;
  46532. var Registry = _dereq_('../../registry');
  46533. var traceIs = Registry.traceIs;
  46534. var getComponentMethod = Registry.getComponentMethod;
  46535. function appendList(cont, k, item) {
  46536. if(Array.isArray(cont[k])) cont[k].push(item);
  46537. else cont[k] = [item];
  46538. }
  46539. module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {
  46540. var ax2traces = {};
  46541. var xaCheater = {};
  46542. var xaNonCheater = {};
  46543. var outerTicks = {};
  46544. var noGrids = {};
  46545. var i, j;
  46546. // look for axes in the data
  46547. for(i = 0; i < fullData.length; i++) {
  46548. var trace = fullData[i];
  46549. if(!traceIs(trace, 'cartesian') && !traceIs(trace, 'gl2d')) continue;
  46550. var xaName;
  46551. if(trace.xaxis) {
  46552. xaName = id2name(trace.xaxis);
  46553. appendList(ax2traces, xaName, trace);
  46554. } else if(trace.xaxes) {
  46555. for(j = 0; j < trace.xaxes.length; j++) {
  46556. appendList(ax2traces, id2name(trace.xaxes[j]), trace);
  46557. }
  46558. }
  46559. var yaName;
  46560. if(trace.yaxis) {
  46561. yaName = id2name(trace.yaxis);
  46562. appendList(ax2traces, yaName, trace);
  46563. } else if(trace.yaxes) {
  46564. for(j = 0; j < trace.yaxes.length; j++) {
  46565. appendList(ax2traces, id2name(trace.yaxes[j]), trace);
  46566. }
  46567. }
  46568. // Two things trigger axis visibility:
  46569. // 1. is not carpet
  46570. // 2. carpet that's not cheater
  46571. if(!traceIs(trace, 'carpet') || (trace.type === 'carpet' && !trace._cheater)) {
  46572. if(xaName) xaNonCheater[xaName] = 1;
  46573. }
  46574. // The above check for definitely-not-cheater is not adequate. This
  46575. // second list tracks which axes *could* be a cheater so that the
  46576. // full condition triggering hiding is:
  46577. // *could* be a cheater and *is not definitely visible*
  46578. if(trace.type === 'carpet' && trace._cheater) {
  46579. if(xaName) xaCheater[xaName] = 1;
  46580. }
  46581. // check for default formatting tweaks
  46582. if(traceIs(trace, '2dMap')) {
  46583. outerTicks[xaName] = 1;
  46584. outerTicks[yaName] = 1;
  46585. }
  46586. if(traceIs(trace, 'oriented')) {
  46587. var positionAxis = trace.orientation === 'h' ? yaName : xaName;
  46588. noGrids[positionAxis] = 1;
  46589. }
  46590. }
  46591. var subplots = layoutOut._subplots;
  46592. var xIds = subplots.xaxis;
  46593. var yIds = subplots.yaxis;
  46594. var xNames = Lib.simpleMap(xIds, id2name);
  46595. var yNames = Lib.simpleMap(yIds, id2name);
  46596. var axNames = xNames.concat(yNames);
  46597. // plot_bgcolor only makes sense if there's a (2D) plot!
  46598. // TODO: bgcolor for each subplot, to inherit from the main one
  46599. var plot_bgcolor = Color.background;
  46600. if(xIds.length && yIds.length) {
  46601. plot_bgcolor = Lib.coerce(layoutIn, layoutOut, basePlotLayoutAttributes, 'plot_bgcolor');
  46602. }
  46603. var bgColor = Color.combine(plot_bgcolor, layoutOut.paper_bgcolor);
  46604. var axName, axLetter, axLayoutIn, axLayoutOut;
  46605. function coerce(attr, dflt) {
  46606. return Lib.coerce(axLayoutIn, axLayoutOut, layoutAttributes, attr, dflt);
  46607. }
  46608. function coerce2(attr, dflt) {
  46609. return Lib.coerce2(axLayoutIn, axLayoutOut, layoutAttributes, attr, dflt);
  46610. }
  46611. function getCounterAxes(axLetter) {
  46612. return (axLetter === 'x') ? yIds : xIds;
  46613. }
  46614. var counterAxes = {x: getCounterAxes('x'), y: getCounterAxes('y')};
  46615. function getOverlayableAxes(axLetter, axName) {
  46616. var list = (axLetter === 'x') ? xNames : yNames;
  46617. var out = [];
  46618. for(var j = 0; j < list.length; j++) {
  46619. var axName2 = list[j];
  46620. if(axName2 !== axName && !(layoutIn[axName2] || {}).overlaying) {
  46621. out.push(name2id(axName2));
  46622. }
  46623. }
  46624. return out;
  46625. }
  46626. // first pass creates the containers, determines types, and handles most of the settings
  46627. for(i = 0; i < axNames.length; i++) {
  46628. axName = axNames[i];
  46629. axLetter = axName.charAt(0);
  46630. if(!Lib.isPlainObject(layoutIn[axName])) {
  46631. layoutIn[axName] = {};
  46632. }
  46633. axLayoutIn = layoutIn[axName];
  46634. axLayoutOut = Template.newContainer(layoutOut, axName, axLetter + 'axis');
  46635. var traces = ax2traces[axName] || [];
  46636. axLayoutOut._traceIndices = traces.map(function(t) { return t._expandedIndex; });
  46637. axLayoutOut._annIndices = [];
  46638. axLayoutOut._shapeIndices = [];
  46639. // set up some private properties
  46640. axLayoutOut._name = axName;
  46641. var id = axLayoutOut._id = name2id(axName);
  46642. var overlayableAxes = getOverlayableAxes(axLetter, axName);
  46643. var defaultOptions = {
  46644. letter: axLetter,
  46645. font: layoutOut.font,
  46646. outerTicks: outerTicks[axName],
  46647. showGrid: !noGrids[axName],
  46648. data: traces,
  46649. bgColor: bgColor,
  46650. calendar: layoutOut.calendar,
  46651. automargin: true,
  46652. cheateronly: axLetter === 'x' && xaCheater[axName] && !xaNonCheater[axName],
  46653. splomStash: ((layoutOut._splomAxes || {})[axLetter] || {})[id]
  46654. };
  46655. handleTypeDefaults(axLayoutIn, axLayoutOut, coerce, defaultOptions);
  46656. handleAxisDefaults(axLayoutIn, axLayoutOut, coerce, defaultOptions, layoutOut);
  46657. var spikecolor = coerce2('spikecolor'),
  46658. spikethickness = coerce2('spikethickness'),
  46659. spikedash = coerce2('spikedash'),
  46660. spikemode = coerce2('spikemode'),
  46661. spikesnap = coerce2('spikesnap'),
  46662. showSpikes = coerce('showspikes', !!spikecolor || !!spikethickness || !!spikedash || !!spikemode || !!spikesnap);
  46663. if(!showSpikes) {
  46664. delete axLayoutOut.spikecolor;
  46665. delete axLayoutOut.spikethickness;
  46666. delete axLayoutOut.spikedash;
  46667. delete axLayoutOut.spikemode;
  46668. delete axLayoutOut.spikesnap;
  46669. }
  46670. var positioningOptions = {
  46671. letter: axLetter,
  46672. counterAxes: counterAxes[axLetter],
  46673. overlayableAxes: overlayableAxes,
  46674. grid: layoutOut.grid
  46675. };
  46676. handlePositionDefaults(axLayoutIn, axLayoutOut, coerce, positioningOptions);
  46677. axLayoutOut._input = axLayoutIn;
  46678. }
  46679. // quick second pass for range slider and selector defaults
  46680. var rangeSliderDefaults = getComponentMethod('rangeslider', 'handleDefaults');
  46681. var rangeSelectorDefaults = getComponentMethod('rangeselector', 'handleDefaults');
  46682. for(i = 0; i < xNames.length; i++) {
  46683. axName = xNames[i];
  46684. axLayoutIn = layoutIn[axName];
  46685. axLayoutOut = layoutOut[axName];
  46686. rangeSliderDefaults(layoutIn, layoutOut, axName);
  46687. if(axLayoutOut.type === 'date') {
  46688. rangeSelectorDefaults(
  46689. axLayoutIn,
  46690. axLayoutOut,
  46691. layoutOut,
  46692. yNames,
  46693. axLayoutOut.calendar
  46694. );
  46695. }
  46696. coerce('fixedrange');
  46697. }
  46698. for(i = 0; i < yNames.length; i++) {
  46699. axName = yNames[i];
  46700. axLayoutIn = layoutIn[axName];
  46701. axLayoutOut = layoutOut[axName];
  46702. var anchoredAxis = layoutOut[id2name(axLayoutOut.anchor)];
  46703. var fixedRangeDflt = (
  46704. anchoredAxis &&
  46705. anchoredAxis.rangeslider &&
  46706. anchoredAxis.rangeslider.visible
  46707. );
  46708. coerce('fixedrange', fixedRangeDflt);
  46709. }
  46710. // Finally, handle scale constraints. We need to do this after all axes have
  46711. // coerced both `type` (so we link only axes of the same type) and
  46712. // `fixedrange` (so we can avoid linking from OR TO a fixed axis).
  46713. // sets of axes linked by `scaleanchor` along with the scaleratios compounded
  46714. // together, populated in handleConstraintDefaults
  46715. layoutOut._axisConstraintGroups = [];
  46716. var allAxisIds = counterAxes.x.concat(counterAxes.y);
  46717. for(i = 0; i < axNames.length; i++) {
  46718. axName = axNames[i];
  46719. axLetter = axName.charAt(0);
  46720. axLayoutIn = layoutIn[axName];
  46721. axLayoutOut = layoutOut[axName];
  46722. handleConstraintDefaults(axLayoutIn, axLayoutOut, coerce, allAxisIds, layoutOut);
  46723. }
  46724. };
  46725. },{"../../components/color":50,"../../lib":169,"../../plot_api/plot_template":204,"../../registry":259,"../layout_attributes":244,"./axis_defaults":216,"./axis_ids":217,"./constraint_defaults":220,"./layout_attributes":226,"./position_defaults":229,"./type_defaults":237}],228:[function(_dereq_,module,exports){
  46726. /**
  46727. * Copyright 2012-2018, Plotly, Inc.
  46728. * All rights reserved.
  46729. *
  46730. * This source code is licensed under the MIT license found in the
  46731. * LICENSE file in the root directory of this source tree.
  46732. */
  46733. 'use strict';
  46734. var colorMix = _dereq_('tinycolor2').mix;
  46735. var lightFraction = _dereq_('../../components/color/attributes').lightFraction;
  46736. var Lib = _dereq_('../../lib');
  46737. /**
  46738. * @param {object} opts :
  46739. * - dfltColor {string} : default axis color
  46740. * - bgColor {string} : combined subplot bg color
  46741. * - blend {number, optional} : blend percentage (to compute dflt grid color)
  46742. * - showLine {boolean} : show line by default
  46743. * - showGrid {boolean} : show grid by default
  46744. * - noZeroLine {boolean} : don't coerce zeroline* attributes
  46745. * - attributes {object} : attribute object associated with input containers
  46746. */
  46747. module.exports = function handleLineGridDefaults(containerIn, containerOut, coerce, opts) {
  46748. opts = opts || {};
  46749. var dfltColor = opts.dfltColor;
  46750. function coerce2(attr, dflt) {
  46751. return Lib.coerce2(containerIn, containerOut, opts.attributes, attr, dflt);
  46752. }
  46753. var lineColor = coerce2('linecolor', dfltColor);
  46754. var lineWidth = coerce2('linewidth');
  46755. var showLine = coerce('showline', opts.showLine || !!lineColor || !!lineWidth);
  46756. if(!showLine) {
  46757. delete containerOut.linecolor;
  46758. delete containerOut.linewidth;
  46759. }
  46760. var gridColorDflt = colorMix(dfltColor, opts.bgColor, opts.blend || lightFraction).toRgbString();
  46761. var gridColor = coerce2('gridcolor', gridColorDflt);
  46762. var gridWidth = coerce2('gridwidth');
  46763. var showGridLines = coerce('showgrid', opts.showGrid || !!gridColor || !!gridWidth);
  46764. if(!showGridLines) {
  46765. delete containerOut.gridcolor;
  46766. delete containerOut.gridwidth;
  46767. }
  46768. if(!opts.noZeroLine) {
  46769. var zeroLineColor = coerce2('zerolinecolor', dfltColor);
  46770. var zeroLineWidth = coerce2('zerolinewidth');
  46771. var showZeroLine = coerce('zeroline', opts.showGrid || !!zeroLineColor || !!zeroLineWidth);
  46772. if(!showZeroLine) {
  46773. delete containerOut.zerolinecolor;
  46774. delete containerOut.zerolinewidth;
  46775. }
  46776. }
  46777. };
  46778. },{"../../components/color/attributes":49,"../../lib":169,"tinycolor2":33}],229:[function(_dereq_,module,exports){
  46779. /**
  46780. * Copyright 2012-2018, Plotly, Inc.
  46781. * All rights reserved.
  46782. *
  46783. * This source code is licensed under the MIT license found in the
  46784. * LICENSE file in the root directory of this source tree.
  46785. */
  46786. 'use strict';
  46787. var isNumeric = _dereq_('fast-isnumeric');
  46788. var Lib = _dereq_('../../lib');
  46789. module.exports = function handlePositionDefaults(containerIn, containerOut, coerce, options) {
  46790. var counterAxes = options.counterAxes || [];
  46791. var overlayableAxes = options.overlayableAxes || [];
  46792. var letter = options.letter;
  46793. var grid = options.grid;
  46794. var dfltAnchor, dfltDomain, dfltSide, dfltPosition;
  46795. if(grid) {
  46796. dfltDomain = grid._domains[letter][grid._axisMap[containerOut._id]];
  46797. dfltAnchor = grid._anchors[containerOut._id];
  46798. if(dfltDomain) {
  46799. dfltSide = grid[letter + 'side'].split(' ')[0];
  46800. dfltPosition = grid.domain[letter][dfltSide === 'right' || dfltSide === 'top' ? 1 : 0];
  46801. }
  46802. }
  46803. // Even if there's a grid, this axis may not be in it - fall back on non-grid defaults
  46804. dfltDomain = dfltDomain || [0, 1];
  46805. dfltAnchor = dfltAnchor || (isNumeric(containerIn.position) ? 'free' : (counterAxes[0] || 'free'));
  46806. dfltSide = dfltSide || (letter === 'x' ? 'bottom' : 'left');
  46807. dfltPosition = dfltPosition || 0;
  46808. var anchor = Lib.coerce(containerIn, containerOut, {
  46809. anchor: {
  46810. valType: 'enumerated',
  46811. values: ['free'].concat(counterAxes),
  46812. dflt: dfltAnchor
  46813. }
  46814. }, 'anchor');
  46815. if(anchor === 'free') coerce('position', dfltPosition);
  46816. Lib.coerce(containerIn, containerOut, {
  46817. side: {
  46818. valType: 'enumerated',
  46819. values: letter === 'x' ? ['bottom', 'top'] : ['left', 'right'],
  46820. dflt: dfltSide
  46821. }
  46822. }, 'side');
  46823. var overlaying = false;
  46824. if(overlayableAxes.length) {
  46825. overlaying = Lib.coerce(containerIn, containerOut, {
  46826. overlaying: {
  46827. valType: 'enumerated',
  46828. values: [false].concat(overlayableAxes),
  46829. dflt: false
  46830. }
  46831. }, 'overlaying');
  46832. }
  46833. if(!overlaying) {
  46834. // TODO: right now I'm copying this domain over to overlaying axes
  46835. // in ax.setscale()... but this means we still need (imperfect) logic
  46836. // in the axes popover to hide domain for the overlaying axis.
  46837. // perhaps I should make a private version _domain that all axes get???
  46838. var domain = coerce('domain', dfltDomain);
  46839. if(domain[0] > domain[1] - 0.01) containerOut.domain = dfltDomain;
  46840. Lib.noneOrAll(containerIn.domain, containerOut.domain, dfltDomain);
  46841. }
  46842. coerce('layer');
  46843. return containerOut;
  46844. };
  46845. },{"../../lib":169,"fast-isnumeric":18}],230:[function(_dereq_,module,exports){
  46846. /**
  46847. * Copyright 2012-2018, Plotly, Inc.
  46848. * All rights reserved.
  46849. *
  46850. * This source code is licensed under the MIT license found in the
  46851. * LICENSE file in the root directory of this source tree.
  46852. */
  46853. 'use strict';
  46854. var FROM_BL = _dereq_('../../constants/alignment').FROM_BL;
  46855. module.exports = function scaleZoom(ax, factor, centerFraction) {
  46856. if(centerFraction === undefined) {
  46857. centerFraction = FROM_BL[ax.constraintoward || 'center'];
  46858. }
  46859. var rangeLinear = [ax.r2l(ax.range[0]), ax.r2l(ax.range[1])];
  46860. var center = rangeLinear[0] + (rangeLinear[1] - rangeLinear[0]) * centerFraction;
  46861. ax.range = ax._input.range = [
  46862. ax.l2r(center + (rangeLinear[0] - center) * factor),
  46863. ax.l2r(center + (rangeLinear[1] - center) * factor)
  46864. ];
  46865. };
  46866. },{"../../constants/alignment":148}],231:[function(_dereq_,module,exports){
  46867. /**
  46868. * Copyright 2012-2018, Plotly, Inc.
  46869. * All rights reserved.
  46870. *
  46871. * This source code is licensed under the MIT license found in the
  46872. * LICENSE file in the root directory of this source tree.
  46873. */
  46874. 'use strict';
  46875. var polybool = _dereq_('polybooljs');
  46876. var Registry = _dereq_('../../registry');
  46877. var Color = _dereq_('../../components/color');
  46878. var Fx = _dereq_('../../components/fx');
  46879. var polygon = _dereq_('../../lib/polygon');
  46880. var throttle = _dereq_('../../lib/throttle');
  46881. var makeEventData = _dereq_('../../components/fx/helpers').makeEventData;
  46882. var getFromId = _dereq_('./axis_ids').getFromId;
  46883. var sortModules = _dereq_('../sort_modules').sortModules;
  46884. var constants = _dereq_('./constants');
  46885. var MINSELECT = constants.MINSELECT;
  46886. var filteredPolygon = polygon.filter;
  46887. var polygonTester = polygon.tester;
  46888. function getAxId(ax) { return ax._id; }
  46889. function prepSelect(e, startX, startY, dragOptions, mode) {
  46890. var gd = dragOptions.gd;
  46891. var fullLayout = gd._fullLayout;
  46892. var zoomLayer = fullLayout._zoomlayer;
  46893. var dragBBox = dragOptions.element.getBoundingClientRect();
  46894. var plotinfo = dragOptions.plotinfo;
  46895. var xs = plotinfo.xaxis._offset;
  46896. var ys = plotinfo.yaxis._offset;
  46897. var x0 = startX - dragBBox.left;
  46898. var y0 = startY - dragBBox.top;
  46899. var x1 = x0;
  46900. var y1 = y0;
  46901. var path0 = 'M' + x0 + ',' + y0;
  46902. var pw = dragOptions.xaxes[0]._length;
  46903. var ph = dragOptions.yaxes[0]._length;
  46904. var allAxes = dragOptions.xaxes.concat(dragOptions.yaxes);
  46905. var subtract = e.altKey;
  46906. var filterPoly, selectionTester, mergedPolygons, currentPolygon;
  46907. var i, searchInfo, eventData;
  46908. coerceSelectionsCache(e, gd, dragOptions);
  46909. if(mode === 'lasso') {
  46910. filterPoly = filteredPolygon([[x0, y0]], constants.BENDPX);
  46911. }
  46912. var outlines = zoomLayer.selectAll('path.select-outline-' + plotinfo.id).data([1, 2]);
  46913. outlines.enter()
  46914. .append('path')
  46915. .attr('class', function(d) { return 'select-outline select-outline-' + d + ' select-outline-' + plotinfo.id; })
  46916. .attr('transform', 'translate(' + xs + ', ' + ys + ')')
  46917. .attr('d', path0 + 'Z');
  46918. var corners = zoomLayer.append('path')
  46919. .attr('class', 'zoombox-corners')
  46920. .style({
  46921. fill: Color.background,
  46922. stroke: Color.defaultLine,
  46923. 'stroke-width': 1
  46924. })
  46925. .attr('transform', 'translate(' + xs + ', ' + ys + ')')
  46926. .attr('d', 'M0,0Z');
  46927. var throttleID = fullLayout._uid + constants.SELECTID;
  46928. var selection = [];
  46929. // find the traces to search for selection points
  46930. var searchTraces = determineSearchTraces(gd, dragOptions.xaxes,
  46931. dragOptions.yaxes, dragOptions.subplot);
  46932. function axValue(ax) {
  46933. var index = (ax._id.charAt(0) === 'y') ? 1 : 0;
  46934. return function(v) { return ax.p2d(v[index]); };
  46935. }
  46936. function ascending(a, b) { return a - b; }
  46937. // allow subplots to override fillRangeItems routine
  46938. var fillRangeItems;
  46939. if(plotinfo.fillRangeItems) {
  46940. fillRangeItems = plotinfo.fillRangeItems;
  46941. } else {
  46942. if(mode === 'select') {
  46943. fillRangeItems = function(eventData, poly) {
  46944. var ranges = eventData.range = {};
  46945. for(i = 0; i < allAxes.length; i++) {
  46946. var ax = allAxes[i];
  46947. var axLetter = ax._id.charAt(0);
  46948. ranges[ax._id] = [
  46949. ax.p2d(poly[axLetter + 'min']),
  46950. ax.p2d(poly[axLetter + 'max'])
  46951. ].sort(ascending);
  46952. }
  46953. };
  46954. } else {
  46955. fillRangeItems = function(eventData, poly, filterPoly) {
  46956. var dataPts = eventData.lassoPoints = {};
  46957. for(i = 0; i < allAxes.length; i++) {
  46958. var ax = allAxes[i];
  46959. dataPts[ax._id] = filterPoly.filtered.map(axValue(ax));
  46960. }
  46961. };
  46962. }
  46963. }
  46964. dragOptions.moveFn = function(dx0, dy0) {
  46965. x1 = Math.max(0, Math.min(pw, dx0 + x0));
  46966. y1 = Math.max(0, Math.min(ph, dy0 + y0));
  46967. var dx = Math.abs(x1 - x0),
  46968. dy = Math.abs(y1 - y0);
  46969. if(mode === 'select') {
  46970. var direction = fullLayout.selectdirection;
  46971. if(fullLayout.selectdirection === 'any') {
  46972. if(dy < Math.min(dx * 0.6, MINSELECT)) direction = 'h';
  46973. else if(dx < Math.min(dy * 0.6, MINSELECT)) direction = 'v';
  46974. else direction = 'd';
  46975. }
  46976. else {
  46977. direction = fullLayout.selectdirection;
  46978. }
  46979. if(direction === 'h') {
  46980. // horizontal motion: make a vertical box
  46981. currentPolygon = [[x0, 0], [x0, ph], [x1, ph], [x1, 0]];
  46982. currentPolygon.xmin = Math.min(x0, x1);
  46983. currentPolygon.xmax = Math.max(x0, x1);
  46984. currentPolygon.ymin = Math.min(0, ph);
  46985. currentPolygon.ymax = Math.max(0, ph);
  46986. // extras to guide users in keeping a straight selection
  46987. corners.attr('d', 'M' + currentPolygon.xmin + ',' + (y0 - MINSELECT) +
  46988. 'h-4v' + (2 * MINSELECT) + 'h4Z' +
  46989. 'M' + (currentPolygon.xmax - 1) + ',' + (y0 - MINSELECT) +
  46990. 'h4v' + (2 * MINSELECT) + 'h-4Z');
  46991. }
  46992. else if(direction === 'v') {
  46993. // vertical motion: make a horizontal box
  46994. currentPolygon = [[0, y0], [0, y1], [pw, y1], [pw, y0]];
  46995. currentPolygon.xmin = Math.min(0, pw);
  46996. currentPolygon.xmax = Math.max(0, pw);
  46997. currentPolygon.ymin = Math.min(y0, y1);
  46998. currentPolygon.ymax = Math.max(y0, y1);
  46999. corners.attr('d', 'M' + (x0 - MINSELECT) + ',' + currentPolygon.ymin +
  47000. 'v-4h' + (2 * MINSELECT) + 'v4Z' +
  47001. 'M' + (x0 - MINSELECT) + ',' + (currentPolygon.ymax - 1) +
  47002. 'v4h' + (2 * MINSELECT) + 'v-4Z');
  47003. }
  47004. else if(direction === 'd') {
  47005. // diagonal motion
  47006. currentPolygon = [[x0, y0], [x0, y1], [x1, y1], [x1, y0]];
  47007. currentPolygon.xmin = Math.min(x0, x1);
  47008. currentPolygon.xmax = Math.max(x0, x1);
  47009. currentPolygon.ymin = Math.min(y0, y1);
  47010. currentPolygon.ymax = Math.max(y0, y1);
  47011. corners.attr('d', 'M0,0Z');
  47012. }
  47013. }
  47014. else if(mode === 'lasso') {
  47015. filterPoly.addPt([x1, y1]);
  47016. currentPolygon = filterPoly.filtered;
  47017. }
  47018. // create outline & tester
  47019. if(dragOptions.selectionDefs && dragOptions.selectionDefs.length) {
  47020. mergedPolygons = mergePolygons(dragOptions.mergedPolygons, currentPolygon, subtract);
  47021. currentPolygon.subtract = subtract;
  47022. selectionTester = multiTester(dragOptions.selectionDefs.concat([currentPolygon]));
  47023. }
  47024. else {
  47025. mergedPolygons = [currentPolygon];
  47026. selectionTester = polygonTester(currentPolygon);
  47027. }
  47028. // draw selection
  47029. drawSelection(mergedPolygons, outlines);
  47030. throttle.throttle(
  47031. throttleID,
  47032. constants.SELECTDELAY,
  47033. function() {
  47034. selection = [];
  47035. var thisSelection, traceSelections = [], traceSelection;
  47036. for(i = 0; i < searchTraces.length; i++) {
  47037. searchInfo = searchTraces[i];
  47038. traceSelection = searchInfo._module.selectPoints(searchInfo, selectionTester);
  47039. traceSelections.push(traceSelection);
  47040. thisSelection = fillSelectionItem(traceSelection, searchInfo);
  47041. if(selection.length) {
  47042. for(var j = 0; j < thisSelection.length; j++) {
  47043. selection.push(thisSelection[j]);
  47044. }
  47045. }
  47046. else selection = thisSelection;
  47047. }
  47048. eventData = {points: selection};
  47049. updateSelectedState(gd, searchTraces, eventData);
  47050. fillRangeItems(eventData, currentPolygon, filterPoly);
  47051. dragOptions.gd.emit('plotly_selecting', eventData);
  47052. }
  47053. );
  47054. };
  47055. dragOptions.clickFn = function(numClicks, evt) {
  47056. var clickmode = fullLayout.clickmode;
  47057. corners.remove();
  47058. throttle.done(throttleID).then(function() {
  47059. throttle.clear(throttleID);
  47060. if(numClicks === 2) {
  47061. // clear selection on doubleclick
  47062. outlines.remove();
  47063. for(i = 0; i < searchTraces.length; i++) {
  47064. searchInfo = searchTraces[i];
  47065. searchInfo._module.selectPoints(searchInfo, false);
  47066. }
  47067. updateSelectedState(gd, searchTraces);
  47068. clearSelectionsCache(dragOptions);
  47069. gd.emit('plotly_deselect', null);
  47070. } else {
  47071. if(clickmode.indexOf('select') > -1) {
  47072. selectOnClick(evt, gd, dragOptions.xaxes, dragOptions.yaxes,
  47073. dragOptions.subplot, dragOptions, outlines);
  47074. }
  47075. if(clickmode === 'event') {
  47076. // TODO: remove in v2 - this was probably never intended to work as it does,
  47077. // but in case anyone depends on it we don't want to break it now.
  47078. // Note that click-to-select introduced pre v2 also emitts proper
  47079. // event data when clickmode is having 'select' in its flag list.
  47080. gd.emit('plotly_selected', undefined);
  47081. }
  47082. }
  47083. Fx.click(gd, evt);
  47084. });
  47085. };
  47086. dragOptions.doneFn = function() {
  47087. corners.remove();
  47088. throttle.done(throttleID).then(function() {
  47089. throttle.clear(throttleID);
  47090. dragOptions.gd.emit('plotly_selected', eventData);
  47091. if(currentPolygon && dragOptions.selectionDefs) {
  47092. // save last polygons
  47093. currentPolygon.subtract = subtract;
  47094. dragOptions.selectionDefs.push(currentPolygon);
  47095. // we have to keep reference to arrays container
  47096. dragOptions.mergedPolygons.length = 0;
  47097. [].push.apply(dragOptions.mergedPolygons, mergedPolygons);
  47098. }
  47099. });
  47100. };
  47101. }
  47102. function selectOnClick(evt, gd, xAxes, yAxes, subplot, dragOptions, polygonOutlines) {
  47103. var hoverData = gd._hoverdata;
  47104. var clickmode = gd._fullLayout.clickmode;
  47105. var sendEvents = clickmode.indexOf('event') > -1;
  47106. var selection = [];
  47107. var searchTraces, searchInfo, currentSelectionDef, selectionTester, traceSelection;
  47108. var thisTracesSelection, pointOrBinSelected, subtract, eventData, i;
  47109. if(isHoverDataSet(hoverData)) {
  47110. coerceSelectionsCache(evt, gd, dragOptions);
  47111. searchTraces = determineSearchTraces(gd, xAxes, yAxes, subplot);
  47112. var clickedPtInfo = extractClickedPtInfo(hoverData, searchTraces);
  47113. var isBinnedTrace = clickedPtInfo.pointNumbers.length > 0;
  47114. // Note: potentially costly operation isPointOrBinSelected is
  47115. // called as late as possible through the use of an assignment
  47116. // in an if condition.
  47117. if(isBinnedTrace ?
  47118. isOnlyThisBinSelected(searchTraces, clickedPtInfo) :
  47119. isOnlyOnePointSelected(searchTraces) &&
  47120. (pointOrBinSelected = isPointOrBinSelected(clickedPtInfo)))
  47121. {
  47122. if(polygonOutlines) polygonOutlines.remove();
  47123. for(i = 0; i < searchTraces.length; i++) {
  47124. searchInfo = searchTraces[i];
  47125. searchInfo._module.selectPoints(searchInfo, false);
  47126. }
  47127. updateSelectedState(gd, searchTraces);
  47128. clearSelectionsCache(dragOptions);
  47129. if(sendEvents) {
  47130. gd.emit('plotly_deselect', null);
  47131. }
  47132. } else {
  47133. subtract = evt.shiftKey &&
  47134. (pointOrBinSelected !== undefined ?
  47135. pointOrBinSelected :
  47136. isPointOrBinSelected(clickedPtInfo));
  47137. currentSelectionDef = newPointSelectionDef(clickedPtInfo.pointNumber, clickedPtInfo.searchInfo, subtract);
  47138. var allSelectionDefs = dragOptions.selectionDefs.concat([currentSelectionDef]);
  47139. selectionTester = multiTester(allSelectionDefs);
  47140. for(i = 0; i < searchTraces.length; i++) {
  47141. traceSelection = searchTraces[i]._module.selectPoints(searchTraces[i], selectionTester);
  47142. thisTracesSelection = fillSelectionItem(traceSelection, searchTraces[i]);
  47143. if(selection.length) {
  47144. for(var j = 0; j < thisTracesSelection.length; j++) {
  47145. selection.push(thisTracesSelection[j]);
  47146. }
  47147. }
  47148. else selection = thisTracesSelection;
  47149. }
  47150. eventData = {points: selection};
  47151. updateSelectedState(gd, searchTraces, eventData);
  47152. if(currentSelectionDef && dragOptions) {
  47153. dragOptions.selectionDefs.push(currentSelectionDef);
  47154. }
  47155. if(polygonOutlines) drawSelection(dragOptions.mergedPolygons, polygonOutlines);
  47156. if(sendEvents) {
  47157. gd.emit('plotly_selected', eventData);
  47158. }
  47159. }
  47160. }
  47161. }
  47162. /**
  47163. * Constructs a new point selection definition object.
  47164. */
  47165. function newPointSelectionDef(pointNumber, searchInfo, subtract) {
  47166. return {
  47167. pointNumber: pointNumber,
  47168. searchInfo: searchInfo,
  47169. subtract: subtract
  47170. };
  47171. }
  47172. function isPointSelectionDef(o) {
  47173. return 'pointNumber' in o && 'searchInfo' in o;
  47174. }
  47175. /*
  47176. * Constructs a new point number tester.
  47177. */
  47178. function newPointNumTester(pointSelectionDef) {
  47179. return {
  47180. xmin: 0,
  47181. xmax: 0,
  47182. ymin: 0,
  47183. ymax: 0,
  47184. pts: [],
  47185. contains: function(pt, omitFirstEdge, pointNumber, searchInfo) {
  47186. var idxWantedTrace = pointSelectionDef.searchInfo.cd[0].trace._expandedIndex;
  47187. var idxActualTrace = searchInfo.cd[0].trace._expandedIndex;
  47188. return idxActualTrace === idxWantedTrace &&
  47189. pointNumber === pointSelectionDef.pointNumber;
  47190. },
  47191. isRect: false,
  47192. degenerate: false,
  47193. subtract: pointSelectionDef.subtract
  47194. };
  47195. }
  47196. /**
  47197. * Wraps multiple selection testers.
  47198. *
  47199. * @param {Array} list - An array of selection testers.
  47200. *
  47201. * @return a selection tester object with a contains function
  47202. * that can be called to evaluate a point against all wrapped
  47203. * selection testers that were passed in list.
  47204. */
  47205. function multiTester(list) {
  47206. var testers = [];
  47207. var xmin = isPointSelectionDef(list[0]) ? 0 : list[0][0][0];
  47208. var xmax = xmin;
  47209. var ymin = isPointSelectionDef(list[0]) ? 0 : list[0][0][1];
  47210. var ymax = ymin;
  47211. for(var i = 0; i < list.length; i++) {
  47212. if(isPointSelectionDef(list[i])) {
  47213. testers.push(newPointNumTester(list[i]));
  47214. } else {
  47215. var tester = polygon.tester(list[i]);
  47216. tester.subtract = list[i].subtract;
  47217. testers.push(tester);
  47218. xmin = Math.min(xmin, tester.xmin);
  47219. xmax = Math.max(xmax, tester.xmax);
  47220. ymin = Math.min(ymin, tester.ymin);
  47221. ymax = Math.max(ymax, tester.ymax);
  47222. }
  47223. }
  47224. /**
  47225. * Tests if the given point is within this tester.
  47226. *
  47227. * @param {Array} pt - [0] is the x coordinate, [1] is the y coordinate of the point.
  47228. * @param {*} arg - An optional parameter to pass down to wrapped testers.
  47229. * @param {number} pointNumber - The point number of the point within the underlying data array.
  47230. * @param {number} searchInfo - An object identifying the trace the point is contained in.
  47231. *
  47232. * @return {boolean} true if point is considered to be selected, false otherwise.
  47233. */
  47234. function contains(pt, arg, pointNumber, searchInfo) {
  47235. var contained = false;
  47236. for(var i = 0; i < testers.length; i++) {
  47237. if(testers[i].contains(pt, arg, pointNumber, searchInfo)) {
  47238. // if contained by subtract tester - exclude the point
  47239. contained = testers[i].subtract === false;
  47240. }
  47241. }
  47242. return contained;
  47243. }
  47244. return {
  47245. xmin: xmin,
  47246. xmax: xmax,
  47247. ymin: ymin,
  47248. ymax: ymax,
  47249. pts: [],
  47250. contains: contains,
  47251. isRect: false,
  47252. degenerate: false
  47253. };
  47254. }
  47255. function coerceSelectionsCache(evt, gd, dragOptions) {
  47256. var fullLayout = gd._fullLayout;
  47257. var zoomLayer = fullLayout._zoomlayer;
  47258. var plotinfo = dragOptions.plotinfo;
  47259. var selectingOnSameSubplot = (
  47260. fullLayout._lastSelectedSubplot &&
  47261. fullLayout._lastSelectedSubplot === plotinfo.id
  47262. );
  47263. var hasModifierKey = evt.shiftKey || evt.altKey;
  47264. if(selectingOnSameSubplot && hasModifierKey &&
  47265. (plotinfo.selection && plotinfo.selection.selectionDefs) && !dragOptions.selectionDefs) {
  47266. // take over selection definitions from prev mode, if any
  47267. dragOptions.selectionDefs = plotinfo.selection.selectionDefs;
  47268. dragOptions.mergedPolygons = plotinfo.selection.mergedPolygons;
  47269. } else if(!hasModifierKey || !plotinfo.selection) {
  47270. clearSelectionsCache(dragOptions);
  47271. }
  47272. // clear selection outline when selecting a different subplot
  47273. if(!selectingOnSameSubplot) {
  47274. clearSelect(zoomLayer);
  47275. fullLayout._lastSelectedSubplot = plotinfo.id;
  47276. }
  47277. }
  47278. function clearSelectionsCache(dragOptions) {
  47279. var plotinfo = dragOptions.plotinfo;
  47280. plotinfo.selection = {};
  47281. plotinfo.selection.selectionDefs = dragOptions.selectionDefs = [];
  47282. plotinfo.selection.mergedPolygons = dragOptions.mergedPolygons = [];
  47283. }
  47284. function determineSearchTraces(gd, xAxes, yAxes, subplot) {
  47285. var searchTraces = [];
  47286. var xAxisIds = xAxes.map(getAxId);
  47287. var yAxisIds = yAxes.map(getAxId);
  47288. var cd, trace, i;
  47289. for(i = 0; i < gd.calcdata.length; i++) {
  47290. cd = gd.calcdata[i];
  47291. trace = cd[0].trace;
  47292. if(trace.visible !== true || !trace._module || !trace._module.selectPoints) continue;
  47293. if(subplot && (trace.subplot === subplot || trace.geo === subplot)) {
  47294. searchTraces.push(createSearchInfo(trace._module, cd, xAxes[0], yAxes[0]));
  47295. } else if(
  47296. trace.type === 'splom' &&
  47297. // FIXME: make sure we don't have more than single axis for splom
  47298. trace._xaxes[xAxisIds[0]] && trace._yaxes[yAxisIds[0]]
  47299. ) {
  47300. searchTraces.push(createSearchInfo(trace._module, cd, xAxes[0], yAxes[0]));
  47301. } else {
  47302. if(xAxisIds.indexOf(trace.xaxis) === -1) continue;
  47303. if(yAxisIds.indexOf(trace.yaxis) === -1) continue;
  47304. searchTraces.push(createSearchInfo(trace._module, cd,
  47305. getFromId(gd, trace.xaxis), getFromId(gd, trace.yaxis)));
  47306. }
  47307. }
  47308. return searchTraces;
  47309. function createSearchInfo(module, calcData, xaxis, yaxis) {
  47310. return {
  47311. _module: module,
  47312. cd: calcData,
  47313. xaxis: xaxis,
  47314. yaxis: yaxis
  47315. };
  47316. }
  47317. }
  47318. function drawSelection(polygons, outlines) {
  47319. var paths = [];
  47320. var i, d;
  47321. for(i = 0; i < polygons.length; i++) {
  47322. var ppts = polygons[i];
  47323. paths.push(ppts.join('L') + 'L' + ppts[0]);
  47324. }
  47325. d = polygons.length > 0 ?
  47326. 'M' + paths.join('M') + 'Z' :
  47327. 'M0,0Z';
  47328. outlines.attr('d', d);
  47329. }
  47330. function isHoverDataSet(hoverData) {
  47331. return hoverData &&
  47332. Array.isArray(hoverData) &&
  47333. hoverData[0].hoverOnBox !== true;
  47334. }
  47335. function extractClickedPtInfo(hoverData, searchTraces) {
  47336. var hoverDatum = hoverData[0];
  47337. var pointNumber = -1;
  47338. var pointNumbers = [];
  47339. var searchInfo, i;
  47340. for(i = 0; i < searchTraces.length; i++) {
  47341. searchInfo = searchTraces[i];
  47342. if(hoverDatum.fullData._expandedIndex === searchInfo.cd[0].trace._expandedIndex) {
  47343. // Special case for box (and violin)
  47344. if(hoverDatum.hoverOnBox === true) {
  47345. break;
  47346. }
  47347. // Hint: in some traces like histogram, one graphical element
  47348. // doesn't correspond to one particular data point, but to
  47349. // bins of data points. Thus, hoverDatum can have a binNumber
  47350. // property instead of pointNumber.
  47351. if(hoverDatum.pointNumber !== undefined) {
  47352. pointNumber = hoverDatum.pointNumber;
  47353. } else if(hoverDatum.binNumber !== undefined) {
  47354. pointNumber = hoverDatum.binNumber;
  47355. pointNumbers = hoverDatum.pointNumbers;
  47356. }
  47357. break;
  47358. }
  47359. }
  47360. return {
  47361. pointNumber: pointNumber,
  47362. pointNumbers: pointNumbers,
  47363. searchInfo: searchInfo
  47364. };
  47365. }
  47366. function isPointOrBinSelected(clickedPtInfo) {
  47367. var trace = clickedPtInfo.searchInfo.cd[0].trace;
  47368. var ptNum = clickedPtInfo.pointNumber;
  47369. var ptNums = clickedPtInfo.pointNumbers;
  47370. var ptNumsSet = ptNums.length > 0;
  47371. // When pointsNumbers is set (e.g. histogram's binning),
  47372. // it is assumed that when the first point of
  47373. // a bin is selected, all others are as well
  47374. var ptNumToTest = ptNumsSet ? ptNums[0] : ptNum;
  47375. // TODO potential performance improvement
  47376. // Primarily we need this function to determine if a click adds
  47377. // or subtracts from a selection.
  47378. // In cases `trace.selectedpoints` is a huge array, indexOf
  47379. // might be slow. One remedy would be to introduce a hash somewhere.
  47380. return trace.selectedpoints ? trace.selectedpoints.indexOf(ptNumToTest) > -1 : false;
  47381. }
  47382. function isOnlyThisBinSelected(searchTraces, clickedPtInfo) {
  47383. var tracesWithSelectedPts = [];
  47384. var searchInfo, trace, isSameTrace, i;
  47385. for(i = 0; i < searchTraces.length; i++) {
  47386. searchInfo = searchTraces[i];
  47387. if(searchInfo.cd[0].trace.selectedpoints && searchInfo.cd[0].trace.selectedpoints.length > 0) {
  47388. tracesWithSelectedPts.push(searchInfo);
  47389. }
  47390. }
  47391. if(tracesWithSelectedPts.length === 1) {
  47392. isSameTrace = tracesWithSelectedPts[0] === clickedPtInfo.searchInfo;
  47393. if(isSameTrace) {
  47394. trace = clickedPtInfo.searchInfo.cd[0].trace;
  47395. if(trace.selectedpoints.length === clickedPtInfo.pointNumbers.length) {
  47396. for(i = 0; i < clickedPtInfo.pointNumbers.length; i++) {
  47397. if(trace.selectedpoints.indexOf(clickedPtInfo.pointNumbers[i]) < 0) {
  47398. return false;
  47399. }
  47400. }
  47401. return true;
  47402. }
  47403. }
  47404. }
  47405. return false;
  47406. }
  47407. function isOnlyOnePointSelected(searchTraces) {
  47408. var len = 0;
  47409. var searchInfo, trace, i;
  47410. for(i = 0; i < searchTraces.length; i++) {
  47411. searchInfo = searchTraces[i];
  47412. trace = searchInfo.cd[0].trace;
  47413. if(trace.selectedpoints) {
  47414. if(trace.selectedpoints.length > 1) return false;
  47415. len += trace.selectedpoints.length;
  47416. if(len > 1) return false;
  47417. }
  47418. }
  47419. return len === 1;
  47420. }
  47421. function updateSelectedState(gd, searchTraces, eventData) {
  47422. var i, j, searchInfo, trace;
  47423. if(eventData) {
  47424. var pts = eventData.points || [];
  47425. for(i = 0; i < searchTraces.length; i++) {
  47426. trace = searchTraces[i].cd[0].trace;
  47427. trace.selectedpoints = [];
  47428. trace._input.selectedpoints = [];
  47429. }
  47430. for(i = 0; i < pts.length; i++) {
  47431. var pt = pts[i];
  47432. var data = pt.data;
  47433. var fullData = pt.fullData;
  47434. if(pt.pointIndices) {
  47435. [].push.apply(data.selectedpoints, pt.pointIndices);
  47436. [].push.apply(fullData.selectedpoints, pt.pointIndices);
  47437. } else {
  47438. data.selectedpoints.push(pt.pointIndex);
  47439. fullData.selectedpoints.push(pt.pointIndex);
  47440. }
  47441. }
  47442. }
  47443. else {
  47444. for(i = 0; i < searchTraces.length; i++) {
  47445. trace = searchTraces[i].cd[0].trace;
  47446. delete trace.selectedpoints;
  47447. delete trace._input.selectedpoints;
  47448. }
  47449. }
  47450. // group searchInfo traces by trace modules
  47451. var lookup = {};
  47452. for(i = 0; i < searchTraces.length; i++) {
  47453. searchInfo = searchTraces[i];
  47454. var name = searchInfo._module.name;
  47455. if(lookup[name]) {
  47456. lookup[name].push(searchInfo);
  47457. } else {
  47458. lookup[name] = [searchInfo];
  47459. }
  47460. }
  47461. var keys = Object.keys(lookup).sort(sortModules);
  47462. for(i = 0; i < keys.length; i++) {
  47463. var items = lookup[keys[i]];
  47464. var len = items.length;
  47465. var item0 = items[0];
  47466. var trace0 = item0.cd[0].trace;
  47467. var _module = item0._module;
  47468. var styleSelection = _module.styleOnSelect || _module.style;
  47469. if(Registry.traceIs(trace0, 'regl')) {
  47470. // plot regl traces per module
  47471. var cds = new Array(len);
  47472. for(j = 0; j < len; j++) {
  47473. cds[j] = items[j].cd;
  47474. }
  47475. styleSelection(gd, cds);
  47476. } else {
  47477. // plot svg trace per trace
  47478. for(j = 0; j < len; j++) {
  47479. styleSelection(gd, items[j].cd);
  47480. }
  47481. }
  47482. }
  47483. }
  47484. function mergePolygons(list, poly, subtract) {
  47485. var res;
  47486. if(subtract) {
  47487. res = polybool.difference({
  47488. regions: list,
  47489. inverted: false
  47490. }, {
  47491. regions: [poly],
  47492. inverted: false
  47493. });
  47494. return res.regions;
  47495. }
  47496. res = polybool.union({
  47497. regions: list,
  47498. inverted: false
  47499. }, {
  47500. regions: [poly],
  47501. inverted: false
  47502. });
  47503. return res.regions;
  47504. }
  47505. function fillSelectionItem(selection, searchInfo) {
  47506. if(Array.isArray(selection)) {
  47507. var cd = searchInfo.cd;
  47508. var trace = searchInfo.cd[0].trace;
  47509. for(var i = 0; i < selection.length; i++) {
  47510. selection[i] = makeEventData(selection[i], trace, cd);
  47511. }
  47512. }
  47513. return selection;
  47514. }
  47515. function clearSelect(zoomlayer) {
  47516. // until we get around to persistent selections, remove the outline
  47517. // here. The selection itself will be removed when the plot redraws
  47518. // at the end.
  47519. zoomlayer.selectAll('.select-outline').remove();
  47520. }
  47521. module.exports = {
  47522. prepSelect: prepSelect,
  47523. clearSelect: clearSelect,
  47524. selectOnClick: selectOnClick
  47525. };
  47526. },{"../../components/color":50,"../../components/fx":92,"../../components/fx/helpers":89,"../../lib/polygon":182,"../../lib/throttle":192,"../../registry":259,"../sort_modules":253,"./axis_ids":217,"./constants":219,"polybooljs":24}],232:[function(_dereq_,module,exports){
  47527. /**
  47528. * Copyright 2012-2018, Plotly, Inc.
  47529. * All rights reserved.
  47530. *
  47531. * This source code is licensed under the MIT license found in the
  47532. * LICENSE file in the root directory of this source tree.
  47533. */
  47534. 'use strict';
  47535. var d3 = _dereq_('d3');
  47536. var isNumeric = _dereq_('fast-isnumeric');
  47537. var Lib = _dereq_('../../lib');
  47538. var cleanNumber = Lib.cleanNumber;
  47539. var ms2DateTime = Lib.ms2DateTime;
  47540. var dateTime2ms = Lib.dateTime2ms;
  47541. var ensureNumber = Lib.ensureNumber;
  47542. var numConstants = _dereq_('../../constants/numerical');
  47543. var FP_SAFE = numConstants.FP_SAFE;
  47544. var BADNUM = numConstants.BADNUM;
  47545. var LOG_CLIP = numConstants.LOG_CLIP;
  47546. var constants = _dereq_('./constants');
  47547. var axisIds = _dereq_('./axis_ids');
  47548. function fromLog(v) {
  47549. return Math.pow(10, v);
  47550. }
  47551. /**
  47552. * Define the conversion functions for an axis data is used in 5 ways:
  47553. *
  47554. * d: data, in whatever form it's provided
  47555. * c: calcdata: turned into numbers, but not linearized
  47556. * l: linearized - same as c except for log axes (and other nonlinear
  47557. * mappings later?) this is used when we need to know if it's
  47558. * *possible* to show some data on this axis, without caring about
  47559. * the current range
  47560. * p: pixel value - mapped to the screen with current size and zoom
  47561. * r: ranges, tick0, and annotation positions match one of the above
  47562. * but are handled differently for different types:
  47563. * - linear and date: data format (d)
  47564. * - category: calcdata format (c), and will stay that way because
  47565. * the data format has no continuous mapping
  47566. * - log: linearized (l) format
  47567. * TODO: in v2.0 we plan to change it to data format. At that point
  47568. * shapes will work the same way as ranges, tick0, and annotations
  47569. * so they can use this conversion too.
  47570. *
  47571. * Creates/updates these conversion functions, and a few more utilities
  47572. * like cleanRange, and makeCalcdata
  47573. *
  47574. * also clears the autotick constraints ._minDtick, ._forceTick0
  47575. */
  47576. module.exports = function setConvert(ax, fullLayout) {
  47577. fullLayout = fullLayout || {};
  47578. var axLetter = (ax._id || 'x').charAt(0);
  47579. function toLog(v, clip) {
  47580. if(v > 0) return Math.log(v) / Math.LN10;
  47581. else if(v <= 0 && clip && ax.range && ax.range.length === 2) {
  47582. // clip NaN (ie past negative infinity) to LOG_CLIP axis
  47583. // length past the negative edge
  47584. var r0 = ax.range[0],
  47585. r1 = ax.range[1];
  47586. return 0.5 * (r0 + r1 - 2 * LOG_CLIP * Math.abs(r0 - r1));
  47587. }
  47588. else return BADNUM;
  47589. }
  47590. /*
  47591. * wrapped dateTime2ms that:
  47592. * - accepts ms numbers for backward compatibility
  47593. * - inserts a dummy arg so calendar is the 3rd arg (see notes below).
  47594. * - defaults to ax.calendar
  47595. */
  47596. function dt2ms(v, _, calendar) {
  47597. // NOTE: Changed this behavior: previously we took any numeric value
  47598. // to be a ms, even if it was a string that could be a bare year.
  47599. // Now we convert it as a date if at all possible, and only try
  47600. // as (local) ms if that fails.
  47601. var ms = dateTime2ms(v, calendar || ax.calendar);
  47602. if(ms === BADNUM) {
  47603. if(isNumeric(v)) {
  47604. v = +v;
  47605. // keep track of tenths of ms, that `new Date` will drop
  47606. // same logic as in Lib.ms2DateTime
  47607. var msecTenths = Math.floor(Lib.mod(v + 0.05, 1) * 10);
  47608. var msRounded = Math.round(v - msecTenths / 10);
  47609. ms = dateTime2ms(new Date(msRounded)) + msecTenths / 10;
  47610. }
  47611. else return BADNUM;
  47612. }
  47613. return ms;
  47614. }
  47615. // wrapped ms2DateTime to insert default ax.calendar
  47616. function ms2dt(v, r, calendar) {
  47617. return ms2DateTime(v, r, calendar || ax.calendar);
  47618. }
  47619. function getCategoryName(v) {
  47620. return ax._categories[Math.round(v)];
  47621. }
  47622. /*
  47623. * setCategoryIndex: return the index of category v,
  47624. * inserting it in the list if it's not already there
  47625. *
  47626. * this will enter the categories in the order it
  47627. * encounters them, ie all the categories from the
  47628. * first data set, then all the ones from the second
  47629. * that aren't in the first etc.
  47630. *
  47631. * it is assumed that this function is being invoked in the
  47632. * already sorted category order; otherwise there would be
  47633. * a disconnect between the array and the index returned
  47634. */
  47635. function setCategoryIndex(v) {
  47636. if(v !== null && v !== undefined) {
  47637. if(ax._categoriesMap === undefined) {
  47638. ax._categoriesMap = {};
  47639. }
  47640. if(ax._categoriesMap[v] !== undefined) {
  47641. return ax._categoriesMap[v];
  47642. } else {
  47643. ax._categories.push(v);
  47644. var curLength = ax._categories.length - 1;
  47645. ax._categoriesMap[v] = curLength;
  47646. return curLength;
  47647. }
  47648. }
  47649. return BADNUM;
  47650. }
  47651. function getCategoryIndex(v) {
  47652. // d2l/d2c variant that that won't add categories but will also
  47653. // allow numbers to be mapped to the linearized axis positions
  47654. if(ax._categoriesMap) {
  47655. var index = ax._categoriesMap[v];
  47656. if(index !== undefined) return index;
  47657. }
  47658. if(isNumeric(v)) return +v;
  47659. }
  47660. function l2p(v) {
  47661. if(!isNumeric(v)) return BADNUM;
  47662. // include 2 fractional digits on pixel, for PDF zooming etc
  47663. return d3.round(ax._b + ax._m * v, 2);
  47664. }
  47665. function p2l(px) { return (px - ax._b) / ax._m; }
  47666. // conversions among c/l/p are fairly simple - do them together for all axis types
  47667. ax.c2l = (ax.type === 'log') ? toLog : ensureNumber;
  47668. ax.l2c = (ax.type === 'log') ? fromLog : ensureNumber;
  47669. ax.l2p = l2p;
  47670. ax.p2l = p2l;
  47671. ax.c2p = (ax.type === 'log') ? function(v, clip) { return l2p(toLog(v, clip)); } : l2p;
  47672. ax.p2c = (ax.type === 'log') ? function(px) { return fromLog(p2l(px)); } : p2l;
  47673. /*
  47674. * now type-specific conversions for **ALL** other combinations
  47675. * they're all written out, instead of being combinations of each other, for
  47676. * both clarity and speed.
  47677. */
  47678. if(['linear', '-'].indexOf(ax.type) !== -1) {
  47679. // all are data vals, but d and r need cleaning
  47680. ax.d2r = ax.r2d = ax.d2c = ax.r2c = ax.d2l = ax.r2l = cleanNumber;
  47681. ax.c2d = ax.c2r = ax.l2d = ax.l2r = ensureNumber;
  47682. ax.d2p = ax.r2p = function(v) { return ax.l2p(cleanNumber(v)); };
  47683. ax.p2d = ax.p2r = p2l;
  47684. ax.cleanPos = ensureNumber;
  47685. }
  47686. else if(ax.type === 'log') {
  47687. // d and c are data vals, r and l are logged (but d and r need cleaning)
  47688. ax.d2r = ax.d2l = function(v, clip) { return toLog(cleanNumber(v), clip); };
  47689. ax.r2d = ax.r2c = function(v) { return fromLog(cleanNumber(v)); };
  47690. ax.d2c = ax.r2l = cleanNumber;
  47691. ax.c2d = ax.l2r = ensureNumber;
  47692. ax.c2r = toLog;
  47693. ax.l2d = fromLog;
  47694. ax.d2p = function(v, clip) { return ax.l2p(ax.d2r(v, clip)); };
  47695. ax.p2d = function(px) { return fromLog(p2l(px)); };
  47696. ax.r2p = function(v) { return ax.l2p(cleanNumber(v)); };
  47697. ax.p2r = p2l;
  47698. ax.cleanPos = ensureNumber;
  47699. }
  47700. else if(ax.type === 'date') {
  47701. // r and d are date strings, l and c are ms
  47702. /*
  47703. * Any of these functions with r and d on either side, calendar is the
  47704. * **3rd** argument. log has reserved the second argument.
  47705. *
  47706. * Unless you need the special behavior of the second arg (ms2DateTime
  47707. * uses this to limit precision, toLog uses true to clip negatives
  47708. * to offscreen low rather than undefined), it's safe to pass 0.
  47709. */
  47710. ax.d2r = ax.r2d = Lib.identity;
  47711. ax.d2c = ax.r2c = ax.d2l = ax.r2l = dt2ms;
  47712. ax.c2d = ax.c2r = ax.l2d = ax.l2r = ms2dt;
  47713. ax.d2p = ax.r2p = function(v, _, calendar) { return ax.l2p(dt2ms(v, 0, calendar)); };
  47714. ax.p2d = ax.p2r = function(px, r, calendar) { return ms2dt(p2l(px), r, calendar); };
  47715. ax.cleanPos = function(v) { return Lib.cleanDate(v, BADNUM, ax.calendar); };
  47716. }
  47717. else if(ax.type === 'category') {
  47718. // d is categories (string)
  47719. // c and l are indices (numbers)
  47720. // r is categories or numbers
  47721. ax.d2c = ax.d2l = setCategoryIndex;
  47722. ax.r2d = ax.c2d = ax.l2d = getCategoryName;
  47723. ax.d2r = ax.d2l_noadd = getCategoryIndex;
  47724. ax.r2c = function(v) {
  47725. var index = getCategoryIndex(v);
  47726. return index !== undefined ? index : ax.fraction2r(0.5);
  47727. };
  47728. ax.l2r = ax.c2r = ensureNumber;
  47729. ax.r2l = getCategoryIndex;
  47730. ax.d2p = function(v) { return ax.l2p(ax.r2c(v)); };
  47731. ax.p2d = function(px) { return getCategoryName(p2l(px)); };
  47732. ax.r2p = ax.d2p;
  47733. ax.p2r = p2l;
  47734. ax.cleanPos = function(v) {
  47735. if(typeof v === 'string' && v !== '') return v;
  47736. return ensureNumber(v);
  47737. };
  47738. }
  47739. // find the range value at the specified (linear) fraction of the axis
  47740. ax.fraction2r = function(v) {
  47741. var rl0 = ax.r2l(ax.range[0]),
  47742. rl1 = ax.r2l(ax.range[1]);
  47743. return ax.l2r(rl0 + v * (rl1 - rl0));
  47744. };
  47745. // find the fraction of the range at the specified range value
  47746. ax.r2fraction = function(v) {
  47747. var rl0 = ax.r2l(ax.range[0]),
  47748. rl1 = ax.r2l(ax.range[1]);
  47749. return (ax.r2l(v) - rl0) / (rl1 - rl0);
  47750. };
  47751. /*
  47752. * cleanRange: make sure range is a couplet of valid & distinct values
  47753. * keep numbers away from the limits of floating point numbers,
  47754. * and dates away from the ends of our date system (+/- 9999 years)
  47755. *
  47756. * optional param rangeAttr: operate on a different attribute, like
  47757. * ax._r, rather than ax.range
  47758. */
  47759. ax.cleanRange = function(rangeAttr, opts) {
  47760. if(!opts) opts = {};
  47761. if(!rangeAttr) rangeAttr = 'range';
  47762. var range = Lib.nestedProperty(ax, rangeAttr).get();
  47763. var i, dflt;
  47764. if(ax.type === 'date') dflt = Lib.dfltRange(ax.calendar);
  47765. else if(axLetter === 'y') dflt = constants.DFLTRANGEY;
  47766. else dflt = opts.dfltRange || constants.DFLTRANGEX;
  47767. // make sure we don't later mutate the defaults
  47768. dflt = dflt.slice();
  47769. if(!range || range.length !== 2) {
  47770. Lib.nestedProperty(ax, rangeAttr).set(dflt);
  47771. return;
  47772. }
  47773. if(ax.type === 'date') {
  47774. // check if milliseconds or js date objects are provided for range
  47775. // and convert to date strings
  47776. range[0] = Lib.cleanDate(range[0], BADNUM, ax.calendar);
  47777. range[1] = Lib.cleanDate(range[1], BADNUM, ax.calendar);
  47778. }
  47779. for(i = 0; i < 2; i++) {
  47780. if(ax.type === 'date') {
  47781. if(!Lib.isDateTime(range[i], ax.calendar)) {
  47782. ax[rangeAttr] = dflt;
  47783. break;
  47784. }
  47785. if(ax.r2l(range[0]) === ax.r2l(range[1])) {
  47786. // split by +/- 1 second
  47787. var linCenter = Lib.constrain(ax.r2l(range[0]),
  47788. Lib.MIN_MS + 1000, Lib.MAX_MS - 1000);
  47789. range[0] = ax.l2r(linCenter - 1000);
  47790. range[1] = ax.l2r(linCenter + 1000);
  47791. break;
  47792. }
  47793. }
  47794. else {
  47795. if(!isNumeric(range[i])) {
  47796. if(isNumeric(range[1 - i])) {
  47797. range[i] = range[1 - i] * (i ? 10 : 0.1);
  47798. }
  47799. else {
  47800. ax[rangeAttr] = dflt;
  47801. break;
  47802. }
  47803. }
  47804. if(range[i] < -FP_SAFE) range[i] = -FP_SAFE;
  47805. else if(range[i] > FP_SAFE) range[i] = FP_SAFE;
  47806. if(range[0] === range[1]) {
  47807. // somewhat arbitrary: split by 1 or 1ppm, whichever is bigger
  47808. var inc = Math.max(1, Math.abs(range[0] * 1e-6));
  47809. range[0] -= inc;
  47810. range[1] += inc;
  47811. }
  47812. }
  47813. }
  47814. };
  47815. // set scaling to pixels
  47816. ax.setScale = function(usePrivateRange) {
  47817. var gs = fullLayout._size;
  47818. // TODO cleaner way to handle this case
  47819. if(!ax._categories) ax._categories = [];
  47820. // Add a map to optimize the performance of category collection
  47821. if(!ax._categoriesMap) ax._categoriesMap = {};
  47822. // make sure we have a domain (pull it in from the axis
  47823. // this one is overlaying if necessary)
  47824. if(ax.overlaying) {
  47825. var ax2 = axisIds.getFromId({ _fullLayout: fullLayout }, ax.overlaying);
  47826. ax.domain = ax2.domain;
  47827. }
  47828. // While transitions are occuring, occurring, we get a double-transform
  47829. // issue if we transform the drawn layer *and* use the new axis range to
  47830. // draw the data. This allows us to construct setConvert using the pre-
  47831. // interaction values of the range:
  47832. var rangeAttr = (usePrivateRange && ax._r) ? '_r' : 'range',
  47833. calendar = ax.calendar;
  47834. ax.cleanRange(rangeAttr);
  47835. var rl0 = ax.r2l(ax[rangeAttr][0], calendar),
  47836. rl1 = ax.r2l(ax[rangeAttr][1], calendar);
  47837. if(axLetter === 'y') {
  47838. ax._offset = gs.t + (1 - ax.domain[1]) * gs.h;
  47839. ax._length = gs.h * (ax.domain[1] - ax.domain[0]);
  47840. ax._m = ax._length / (rl0 - rl1);
  47841. ax._b = -ax._m * rl1;
  47842. }
  47843. else {
  47844. ax._offset = gs.l + ax.domain[0] * gs.w;
  47845. ax._length = gs.w * (ax.domain[1] - ax.domain[0]);
  47846. ax._m = ax._length / (rl1 - rl0);
  47847. ax._b = -ax._m * rl0;
  47848. }
  47849. if(!isFinite(ax._m) || !isFinite(ax._b)) {
  47850. fullLayout._replotting = false;
  47851. throw new Error('Something went wrong with axis scaling');
  47852. }
  47853. };
  47854. // makeCalcdata: takes an x or y array and converts it
  47855. // to a position on the axis object "ax"
  47856. // inputs:
  47857. // trace - a data object from gd.data
  47858. // axLetter - a string, either 'x' or 'y', for which item
  47859. // to convert (TODO: is this now always the same as
  47860. // the first letter of ax._id?)
  47861. // in case the expected data isn't there, make a list of
  47862. // integers based on the opposite data
  47863. ax.makeCalcdata = function(trace, axLetter) {
  47864. var arrayIn, arrayOut, i, len;
  47865. var axType = ax.type;
  47866. var cal = axType === 'date' && trace[axLetter + 'calendar'];
  47867. if(axLetter in trace) {
  47868. arrayIn = trace[axLetter];
  47869. len = trace._length || arrayIn.length;
  47870. if(Lib.isTypedArray(arrayIn) && (axType === 'linear' || axType === 'log')) {
  47871. if(len === arrayIn.length) {
  47872. return arrayIn;
  47873. } else if(arrayIn.subarray) {
  47874. return arrayIn.subarray(0, len);
  47875. }
  47876. }
  47877. arrayOut = new Array(len);
  47878. for(i = 0; i < len; i++) {
  47879. arrayOut[i] = ax.d2c(arrayIn[i], 0, cal);
  47880. }
  47881. }
  47882. else {
  47883. var v0 = ((axLetter + '0') in trace) ? ax.d2c(trace[axLetter + '0'], 0, cal) : 0;
  47884. var dv = (trace['d' + axLetter]) ? Number(trace['d' + axLetter]) : 1;
  47885. // the opposing data, for size if we have x and dx etc
  47886. arrayIn = trace[{x: 'y', y: 'x'}[axLetter]];
  47887. len = trace._length || arrayIn.length;
  47888. arrayOut = new Array(len);
  47889. for(i = 0; i < len; i++) {
  47890. arrayOut[i] = v0 + i * dv;
  47891. }
  47892. }
  47893. return arrayOut;
  47894. };
  47895. ax.isValidRange = function(range) {
  47896. return (
  47897. Array.isArray(range) &&
  47898. range.length === 2 &&
  47899. isNumeric(ax.r2l(range[0])) &&
  47900. isNumeric(ax.r2l(range[1]))
  47901. );
  47902. };
  47903. ax.isPtWithinRange = function(d, calendar) {
  47904. var coord = ax.c2l(d[axLetter], null, calendar);
  47905. var r0 = ax.r2l(ax.range[0]);
  47906. var r1 = ax.r2l(ax.range[1]);
  47907. if(r0 < r1) {
  47908. return r0 <= coord && coord <= r1;
  47909. } else {
  47910. // Reversed axis case.
  47911. return r1 <= coord && coord <= r0;
  47912. }
  47913. };
  47914. ax.clearCalc = function() {
  47915. // initialize the category list, if there is one, so we start over
  47916. // to be filled in later by ax.d2c
  47917. ax._categories = (ax._initialCategories || []).slice();
  47918. // Build the lookup map for initialized categories
  47919. ax._categoriesMap = {};
  47920. for(var j = 0; j < ax._categories.length; j++) {
  47921. ax._categoriesMap[ax._categories[j]] = j;
  47922. }
  47923. };
  47924. // Propagate localization into the axis so that
  47925. // methods in Axes can use it w/o having to pass fullLayout
  47926. // Default (non-d3) number formatting uses separators directly
  47927. // dates and d3-formatted numbers use the d3 locale
  47928. // Fall back on default format for dummy axes that don't care about formatting
  47929. var locale = fullLayout._d3locale;
  47930. if(ax.type === 'date') {
  47931. ax._dateFormat = locale ? locale.timeFormat.utc : d3.time.format.utc;
  47932. ax._extraFormat = fullLayout._extraFormat;
  47933. }
  47934. // occasionally we need _numFormat to pass through
  47935. // even though it won't be needed by this axis
  47936. ax._separators = fullLayout.separators;
  47937. ax._numFormat = locale ? locale.numberFormat : d3.format;
  47938. // and for bar charts and box plots: reset forced minimum tick spacing
  47939. delete ax._minDtick;
  47940. delete ax._forceTick0;
  47941. };
  47942. },{"../../constants/numerical":151,"../../lib":169,"./axis_ids":217,"./constants":219,"d3":16,"fast-isnumeric":18}],233:[function(_dereq_,module,exports){
  47943. /**
  47944. * Copyright 2012-2018, Plotly, Inc.
  47945. * All rights reserved.
  47946. *
  47947. * This source code is licensed under the MIT license found in the
  47948. * LICENSE file in the root directory of this source tree.
  47949. */
  47950. 'use strict';
  47951. var Lib = _dereq_('../../lib');
  47952. var layoutAttributes = _dereq_('./layout_attributes');
  47953. var handleArrayContainerDefaults = _dereq_('../array_container_defaults');
  47954. module.exports = function handleTickLabelDefaults(containerIn, containerOut, coerce, axType, options) {
  47955. var showAttrDflt = getShowAttrDflt(containerIn);
  47956. var tickPrefix = coerce('tickprefix');
  47957. if(tickPrefix) coerce('showtickprefix', showAttrDflt);
  47958. var tickSuffix = coerce('ticksuffix', options.tickSuffixDflt);
  47959. if(tickSuffix) coerce('showticksuffix', showAttrDflt);
  47960. var showTickLabels = coerce('showticklabels');
  47961. if(showTickLabels) {
  47962. var font = options.font || {};
  47963. var contColor = containerOut.color;
  47964. // as with titlefont.color, inherit axis.color only if one was
  47965. // explicitly provided
  47966. var dfltFontColor = (contColor && contColor !== layoutAttributes.color.dflt) ?
  47967. contColor : font.color;
  47968. Lib.coerceFont(coerce, 'tickfont', {
  47969. family: font.family,
  47970. size: font.size,
  47971. color: dfltFontColor
  47972. });
  47973. coerce('tickangle');
  47974. if(axType !== 'category') {
  47975. var tickFormat = coerce('tickformat');
  47976. var tickformatStops = containerIn.tickformatstops;
  47977. if(Array.isArray(tickformatStops) && tickformatStops.length) {
  47978. handleArrayContainerDefaults(containerIn, containerOut, {
  47979. name: 'tickformatstops',
  47980. inclusionAttr: 'enabled',
  47981. handleItemDefaults: tickformatstopDefaults
  47982. });
  47983. }
  47984. if(!tickFormat && axType !== 'date') {
  47985. coerce('showexponent', showAttrDflt);
  47986. coerce('exponentformat');
  47987. coerce('separatethousands');
  47988. }
  47989. }
  47990. }
  47991. };
  47992. /*
  47993. * Attributes 'showexponent', 'showtickprefix' and 'showticksuffix'
  47994. * share values.
  47995. *
  47996. * If only 1 attribute is set,
  47997. * the remaining attributes inherit that value.
  47998. *
  47999. * If 2 attributes are set to the same value,
  48000. * the remaining attribute inherits that value.
  48001. *
  48002. * If 2 attributes are set to different values,
  48003. * the remaining is set to its dflt value.
  48004. *
  48005. */
  48006. function getShowAttrDflt(containerIn) {
  48007. var showAttrsAll = ['showexponent',
  48008. 'showtickprefix',
  48009. 'showticksuffix'],
  48010. showAttrs = showAttrsAll.filter(function(a) {
  48011. return containerIn[a] !== undefined;
  48012. }),
  48013. sameVal = function(a) {
  48014. return containerIn[a] === containerIn[showAttrs[0]];
  48015. };
  48016. if(showAttrs.every(sameVal) || showAttrs.length === 1) {
  48017. return containerIn[showAttrs[0]];
  48018. }
  48019. }
  48020. function tickformatstopDefaults(valueIn, valueOut) {
  48021. function coerce(attr, dflt) {
  48022. return Lib.coerce(valueIn, valueOut, layoutAttributes.tickformatstops, attr, dflt);
  48023. }
  48024. var enabled = coerce('enabled');
  48025. if(enabled) {
  48026. coerce('dtickrange');
  48027. coerce('value');
  48028. }
  48029. }
  48030. },{"../../lib":169,"../array_container_defaults":210,"./layout_attributes":226}],234:[function(_dereq_,module,exports){
  48031. /**
  48032. * Copyright 2012-2018, Plotly, Inc.
  48033. * All rights reserved.
  48034. *
  48035. * This source code is licensed under the MIT license found in the
  48036. * LICENSE file in the root directory of this source tree.
  48037. */
  48038. 'use strict';
  48039. var Lib = _dereq_('../../lib');
  48040. var layoutAttributes = _dereq_('./layout_attributes');
  48041. /**
  48042. * options: inherits outerTicks from axes.handleAxisDefaults
  48043. */
  48044. module.exports = function handleTickDefaults(containerIn, containerOut, coerce, options) {
  48045. var tickLen = Lib.coerce2(containerIn, containerOut, layoutAttributes, 'ticklen'),
  48046. tickWidth = Lib.coerce2(containerIn, containerOut, layoutAttributes, 'tickwidth'),
  48047. tickColor = Lib.coerce2(containerIn, containerOut, layoutAttributes, 'tickcolor', containerOut.color),
  48048. showTicks = coerce('ticks', (options.outerTicks || tickLen || tickWidth || tickColor) ? 'outside' : '');
  48049. if(!showTicks) {
  48050. delete containerOut.ticklen;
  48051. delete containerOut.tickwidth;
  48052. delete containerOut.tickcolor;
  48053. }
  48054. };
  48055. },{"../../lib":169,"./layout_attributes":226}],235:[function(_dereq_,module,exports){
  48056. /**
  48057. * Copyright 2012-2018, Plotly, Inc.
  48058. * All rights reserved.
  48059. *
  48060. * This source code is licensed under the MIT license found in the
  48061. * LICENSE file in the root directory of this source tree.
  48062. */
  48063. 'use strict';
  48064. var isNumeric = _dereq_('fast-isnumeric');
  48065. var Lib = _dereq_('../../lib');
  48066. var ONEDAY = _dereq_('../../constants/numerical').ONEDAY;
  48067. module.exports = function handleTickValueDefaults(containerIn, containerOut, coerce, axType) {
  48068. var tickmode;
  48069. if(containerIn.tickmode === 'array' &&
  48070. (axType === 'log' || axType === 'date')) {
  48071. tickmode = containerOut.tickmode = 'auto';
  48072. }
  48073. else {
  48074. var tickmodeDefault =
  48075. Array.isArray(containerIn.tickvals) ? 'array' :
  48076. containerIn.dtick ? 'linear' :
  48077. 'auto';
  48078. tickmode = coerce('tickmode', tickmodeDefault);
  48079. }
  48080. if(tickmode === 'auto') coerce('nticks');
  48081. else if(tickmode === 'linear') {
  48082. // dtick is usually a positive number, but there are some
  48083. // special strings available for log or date axes
  48084. // default is 1 day for dates, otherwise 1
  48085. var dtickDflt = (axType === 'date') ? ONEDAY : 1;
  48086. var dtick = coerce('dtick', dtickDflt);
  48087. if(isNumeric(dtick)) {
  48088. containerOut.dtick = (dtick > 0) ? Number(dtick) : dtickDflt;
  48089. }
  48090. else if(typeof dtick !== 'string') {
  48091. containerOut.dtick = dtickDflt;
  48092. }
  48093. else {
  48094. // date and log special cases are all one character plus a number
  48095. var prefix = dtick.charAt(0),
  48096. dtickNum = dtick.substr(1);
  48097. dtickNum = isNumeric(dtickNum) ? Number(dtickNum) : 0;
  48098. if((dtickNum <= 0) || !(
  48099. // "M<n>" gives ticks every (integer) n months
  48100. (axType === 'date' && prefix === 'M' && dtickNum === Math.round(dtickNum)) ||
  48101. // "L<f>" gives ticks linearly spaced in data (not in position) every (float) f
  48102. (axType === 'log' && prefix === 'L') ||
  48103. // "D1" gives powers of 10 with all small digits between, "D2" gives only 2 and 5
  48104. (axType === 'log' && prefix === 'D' && (dtickNum === 1 || dtickNum === 2))
  48105. )) {
  48106. containerOut.dtick = dtickDflt;
  48107. }
  48108. }
  48109. // tick0 can have different valType for different axis types, so
  48110. // validate that now. Also for dates, change milliseconds to date strings
  48111. var tick0Dflt = (axType === 'date') ? Lib.dateTick0(containerOut.calendar) : 0;
  48112. var tick0 = coerce('tick0', tick0Dflt);
  48113. if(axType === 'date') {
  48114. containerOut.tick0 = Lib.cleanDate(tick0, tick0Dflt);
  48115. }
  48116. // Aside from date axes, dtick must be numeric; D1 and D2 modes ignore tick0 entirely
  48117. else if(isNumeric(tick0) && dtick !== 'D1' && dtick !== 'D2') {
  48118. containerOut.tick0 = Number(tick0);
  48119. }
  48120. else {
  48121. containerOut.tick0 = tick0Dflt;
  48122. }
  48123. }
  48124. else {
  48125. var tickvals = coerce('tickvals');
  48126. if(tickvals === undefined) containerOut.tickmode = 'auto';
  48127. else coerce('ticktext');
  48128. }
  48129. };
  48130. },{"../../constants/numerical":151,"../../lib":169,"fast-isnumeric":18}],236:[function(_dereq_,module,exports){
  48131. /**
  48132. * Copyright 2012-2018, Plotly, Inc.
  48133. * All rights reserved.
  48134. *
  48135. * This source code is licensed under the MIT license found in the
  48136. * LICENSE file in the root directory of this source tree.
  48137. */
  48138. 'use strict';
  48139. var d3 = _dereq_('d3');
  48140. var Registry = _dereq_('../../registry');
  48141. var Drawing = _dereq_('../../components/drawing');
  48142. var Axes = _dereq_('./axes');
  48143. var axisRegex = _dereq_('./constants').attrRegex;
  48144. module.exports = function transitionAxes(gd, newLayout, transitionOpts, makeOnCompleteCallback) {
  48145. var fullLayout = gd._fullLayout;
  48146. var axes = [];
  48147. function computeUpdates(layout) {
  48148. var ai, attrList, match, axis, update;
  48149. var updates = {};
  48150. for(ai in layout) {
  48151. attrList = ai.split('.');
  48152. match = attrList[0].match(axisRegex);
  48153. if(match) {
  48154. var axisLetter = ai.charAt(0);
  48155. var axisName = attrList[0];
  48156. axis = fullLayout[axisName];
  48157. update = {};
  48158. if(Array.isArray(layout[ai])) {
  48159. update.to = layout[ai].slice(0);
  48160. } else {
  48161. if(Array.isArray(layout[ai].range)) {
  48162. update.to = layout[ai].range.slice(0);
  48163. }
  48164. }
  48165. if(!update.to) continue;
  48166. update.axisName = axisName;
  48167. update.length = axis._length;
  48168. axes.push(axisLetter);
  48169. updates[axisLetter] = update;
  48170. }
  48171. }
  48172. return updates;
  48173. }
  48174. function computeAffectedSubplots(fullLayout, updatedAxisIds, updates) {
  48175. var plotName;
  48176. var plotinfos = fullLayout._plots;
  48177. var affectedSubplots = [];
  48178. var toX, toY;
  48179. for(plotName in plotinfos) {
  48180. var plotinfo = plotinfos[plotName];
  48181. if(affectedSubplots.indexOf(plotinfo) !== -1) continue;
  48182. var x = plotinfo.xaxis._id;
  48183. var y = plotinfo.yaxis._id;
  48184. var fromX = plotinfo.xaxis.range;
  48185. var fromY = plotinfo.yaxis.range;
  48186. // Store the initial range at the beginning of this transition:
  48187. plotinfo.xaxis._r = plotinfo.xaxis.range.slice();
  48188. plotinfo.yaxis._r = plotinfo.yaxis.range.slice();
  48189. if(updates[x]) {
  48190. toX = updates[x].to;
  48191. } else {
  48192. toX = fromX;
  48193. }
  48194. if(updates[y]) {
  48195. toY = updates[y].to;
  48196. } else {
  48197. toY = fromY;
  48198. }
  48199. if(fromX[0] === toX[0] && fromX[1] === toX[1] && fromY[0] === toY[0] && fromY[1] === toY[1]) continue;
  48200. if(updatedAxisIds.indexOf(x) !== -1 || updatedAxisIds.indexOf(y) !== -1) {
  48201. affectedSubplots.push(plotinfo);
  48202. }
  48203. }
  48204. return affectedSubplots;
  48205. }
  48206. var updates = computeUpdates(newLayout);
  48207. var updatedAxisIds = Object.keys(updates);
  48208. var affectedSubplots = computeAffectedSubplots(fullLayout, updatedAxisIds, updates);
  48209. function updateLayoutObjs() {
  48210. function redrawObjs(objArray, method, shortCircuit) {
  48211. for(var i = 0; i < objArray.length; i++) {
  48212. method(gd, i);
  48213. // once is enough for images (which doesn't use the `i` arg anyway)
  48214. if(shortCircuit) return;
  48215. }
  48216. }
  48217. redrawObjs(fullLayout.annotations || [], Registry.getComponentMethod('annotations', 'drawOne'));
  48218. redrawObjs(fullLayout.shapes || [], Registry.getComponentMethod('shapes', 'drawOne'));
  48219. redrawObjs(fullLayout.images || [], Registry.getComponentMethod('images', 'draw'), true);
  48220. }
  48221. if(!affectedSubplots.length) {
  48222. updateLayoutObjs();
  48223. return false;
  48224. }
  48225. function ticksAndAnnotations(xa, ya) {
  48226. var activeAxIds = [],
  48227. i;
  48228. activeAxIds = [xa._id, ya._id];
  48229. for(i = 0; i < activeAxIds.length; i++) {
  48230. Axes.doTicksSingle(gd, activeAxIds[i], true);
  48231. }
  48232. function redrawObjs(objArray, method, shortCircuit) {
  48233. for(i = 0; i < objArray.length; i++) {
  48234. var obji = objArray[i];
  48235. if((activeAxIds.indexOf(obji.xref) !== -1) ||
  48236. (activeAxIds.indexOf(obji.yref) !== -1)) {
  48237. method(gd, i);
  48238. }
  48239. // once is enough for images (which doesn't use the `i` arg anyway)
  48240. if(shortCircuit) return;
  48241. }
  48242. }
  48243. redrawObjs(fullLayout.annotations || [], Registry.getComponentMethod('annotations', 'drawOne'));
  48244. redrawObjs(fullLayout.shapes || [], Registry.getComponentMethod('shapes', 'drawOne'));
  48245. redrawObjs(fullLayout.images || [], Registry.getComponentMethod('images', 'draw'), true);
  48246. }
  48247. function unsetSubplotTransform(subplot) {
  48248. var xa2 = subplot.xaxis;
  48249. var ya2 = subplot.yaxis;
  48250. fullLayout._defs.select('#' + subplot.clipId + '> rect')
  48251. .call(Drawing.setTranslate, 0, 0)
  48252. .call(Drawing.setScale, 1, 1);
  48253. subplot.plot
  48254. .call(Drawing.setTranslate, xa2._offset, ya2._offset)
  48255. .call(Drawing.setScale, 1, 1);
  48256. var traceGroups = subplot.plot.selectAll('.scatterlayer .trace');
  48257. // This is specifically directed at scatter traces, applying an inverse
  48258. // scale to individual points to counteract the scale of the trace
  48259. // as a whole:
  48260. traceGroups.selectAll('.point')
  48261. .call(Drawing.setPointGroupScale, 1, 1);
  48262. traceGroups.selectAll('.textpoint')
  48263. .call(Drawing.setTextPointsScale, 1, 1);
  48264. traceGroups
  48265. .call(Drawing.hideOutsideRangePoints, subplot);
  48266. }
  48267. function updateSubplot(subplot, progress) {
  48268. var axis, r0, r1;
  48269. var xUpdate = updates[subplot.xaxis._id];
  48270. var yUpdate = updates[subplot.yaxis._id];
  48271. var viewBox = [];
  48272. if(xUpdate) {
  48273. axis = gd._fullLayout[xUpdate.axisName];
  48274. r0 = axis._r;
  48275. r1 = xUpdate.to;
  48276. viewBox[0] = (r0[0] * (1 - progress) + progress * r1[0] - r0[0]) / (r0[1] - r0[0]) * subplot.xaxis._length;
  48277. var dx1 = r0[1] - r0[0];
  48278. var dx2 = r1[1] - r1[0];
  48279. axis.range[0] = r0[0] * (1 - progress) + progress * r1[0];
  48280. axis.range[1] = r0[1] * (1 - progress) + progress * r1[1];
  48281. viewBox[2] = subplot.xaxis._length * ((1 - progress) + progress * dx2 / dx1);
  48282. } else {
  48283. viewBox[0] = 0;
  48284. viewBox[2] = subplot.xaxis._length;
  48285. }
  48286. if(yUpdate) {
  48287. axis = gd._fullLayout[yUpdate.axisName];
  48288. r0 = axis._r;
  48289. r1 = yUpdate.to;
  48290. viewBox[1] = (r0[1] * (1 - progress) + progress * r1[1] - r0[1]) / (r0[0] - r0[1]) * subplot.yaxis._length;
  48291. var dy1 = r0[1] - r0[0];
  48292. var dy2 = r1[1] - r1[0];
  48293. axis.range[0] = r0[0] * (1 - progress) + progress * r1[0];
  48294. axis.range[1] = r0[1] * (1 - progress) + progress * r1[1];
  48295. viewBox[3] = subplot.yaxis._length * ((1 - progress) + progress * dy2 / dy1);
  48296. } else {
  48297. viewBox[1] = 0;
  48298. viewBox[3] = subplot.yaxis._length;
  48299. }
  48300. ticksAndAnnotations(subplot.xaxis, subplot.yaxis);
  48301. var xa2 = subplot.xaxis;
  48302. var ya2 = subplot.yaxis;
  48303. var editX = !!xUpdate;
  48304. var editY = !!yUpdate;
  48305. var xScaleFactor = editX ? xa2._length / viewBox[2] : 1,
  48306. yScaleFactor = editY ? ya2._length / viewBox[3] : 1;
  48307. var clipDx = editX ? viewBox[0] : 0,
  48308. clipDy = editY ? viewBox[1] : 0;
  48309. var fracDx = editX ? (viewBox[0] / viewBox[2] * xa2._length) : 0,
  48310. fracDy = editY ? (viewBox[1] / viewBox[3] * ya2._length) : 0;
  48311. var plotDx = xa2._offset - fracDx,
  48312. plotDy = ya2._offset - fracDy;
  48313. subplot.clipRect
  48314. .call(Drawing.setTranslate, clipDx, clipDy)
  48315. .call(Drawing.setScale, 1 / xScaleFactor, 1 / yScaleFactor);
  48316. subplot.plot
  48317. .call(Drawing.setTranslate, plotDx, plotDy)
  48318. .call(Drawing.setScale, xScaleFactor, yScaleFactor);
  48319. // apply an inverse scale to individual points to counteract
  48320. // the scale of the trace group.
  48321. Drawing.setPointGroupScale(subplot.zoomScalePts, 1 / xScaleFactor, 1 / yScaleFactor);
  48322. Drawing.setTextPointsScale(subplot.zoomScaleTxt, 1 / xScaleFactor, 1 / yScaleFactor);
  48323. }
  48324. var onComplete;
  48325. if(makeOnCompleteCallback) {
  48326. // This module makes the choice whether or not it notifies Plotly.transition
  48327. // about completion:
  48328. onComplete = makeOnCompleteCallback();
  48329. }
  48330. function transitionComplete() {
  48331. var aobj = {};
  48332. for(var i = 0; i < updatedAxisIds.length; i++) {
  48333. var axi = gd._fullLayout[updates[updatedAxisIds[i]].axisName];
  48334. var to = updates[updatedAxisIds[i]].to;
  48335. aobj[axi._name + '.range[0]'] = to[0];
  48336. aobj[axi._name + '.range[1]'] = to[1];
  48337. axi.range = to.slice();
  48338. }
  48339. // Signal that this transition has completed:
  48340. onComplete && onComplete();
  48341. return Registry.call('relayout', gd, aobj).then(function() {
  48342. for(var i = 0; i < affectedSubplots.length; i++) {
  48343. unsetSubplotTransform(affectedSubplots[i]);
  48344. }
  48345. });
  48346. }
  48347. function transitionInterrupt() {
  48348. var aobj = {};
  48349. for(var i = 0; i < updatedAxisIds.length; i++) {
  48350. var axi = gd._fullLayout[updatedAxisIds[i] + 'axis'];
  48351. aobj[axi._name + '.range[0]'] = axi.range[0];
  48352. aobj[axi._name + '.range[1]'] = axi.range[1];
  48353. axi.range = axi._r.slice();
  48354. }
  48355. return Registry.call('relayout', gd, aobj).then(function() {
  48356. for(var i = 0; i < affectedSubplots.length; i++) {
  48357. unsetSubplotTransform(affectedSubplots[i]);
  48358. }
  48359. });
  48360. }
  48361. var t1, t2, raf;
  48362. var easeFn = d3.ease(transitionOpts.easing);
  48363. gd._transitionData._interruptCallbacks.push(function() {
  48364. window.cancelAnimationFrame(raf);
  48365. raf = null;
  48366. return transitionInterrupt();
  48367. });
  48368. function doFrame() {
  48369. t2 = Date.now();
  48370. var tInterp = Math.min(1, (t2 - t1) / transitionOpts.duration);
  48371. var progress = easeFn(tInterp);
  48372. for(var i = 0; i < affectedSubplots.length; i++) {
  48373. updateSubplot(affectedSubplots[i], progress);
  48374. }
  48375. if(t2 - t1 > transitionOpts.duration) {
  48376. transitionComplete();
  48377. raf = window.cancelAnimationFrame(doFrame);
  48378. } else {
  48379. raf = window.requestAnimationFrame(doFrame);
  48380. }
  48381. }
  48382. t1 = Date.now();
  48383. raf = window.requestAnimationFrame(doFrame);
  48384. return Promise.resolve();
  48385. };
  48386. },{"../../components/drawing":75,"../../registry":259,"./axes":214,"./constants":219,"d3":16}],237:[function(_dereq_,module,exports){
  48387. /**
  48388. * Copyright 2012-2018, Plotly, Inc.
  48389. * All rights reserved.
  48390. *
  48391. * This source code is licensed under the MIT license found in the
  48392. * LICENSE file in the root directory of this source tree.
  48393. */
  48394. 'use strict';
  48395. var Registry = _dereq_('../../registry');
  48396. var autoType = _dereq_('./axis_autotype');
  48397. /*
  48398. * data: the plot data to use in choosing auto type
  48399. * name: axis object name (ie 'xaxis') if one should be stored
  48400. */
  48401. module.exports = function handleTypeDefaults(containerIn, containerOut, coerce, options) {
  48402. var axType = coerce('type', (options.splomStash || {}).type);
  48403. if(axType === '-') {
  48404. setAutoType(containerOut, options.data);
  48405. if(containerOut.type === '-') {
  48406. containerOut.type = 'linear';
  48407. } else {
  48408. // copy autoType back to input axis
  48409. // note that if this object didn't exist
  48410. // in the input layout, we have to put it in
  48411. // this happens in the main supplyDefaults function
  48412. containerIn.type = containerOut.type;
  48413. }
  48414. }
  48415. };
  48416. function setAutoType(ax, data) {
  48417. // new logic: let people specify any type they want,
  48418. // only autotype if type is '-'
  48419. if(ax.type !== '-') return;
  48420. var id = ax._id;
  48421. var axLetter = id.charAt(0);
  48422. // support 3d
  48423. if(id.indexOf('scene') !== -1) id = axLetter;
  48424. var d0 = getFirstNonEmptyTrace(data, id, axLetter);
  48425. if(!d0) return;
  48426. // first check for histograms, as the count direction
  48427. // should always default to a linear axis
  48428. if(d0.type === 'histogram' &&
  48429. axLetter === {v: 'y', h: 'x'}[d0.orientation || 'v']) {
  48430. ax.type = 'linear';
  48431. return;
  48432. }
  48433. var calAttr = axLetter + 'calendar';
  48434. var calendar = d0[calAttr];
  48435. var i;
  48436. // check all boxes on this x axis to see
  48437. // if they're dates, numbers, or categories
  48438. if(isBoxWithoutPositionCoords(d0, axLetter)) {
  48439. var posLetter = getBoxPosLetter(d0);
  48440. var boxPositions = [];
  48441. for(i = 0; i < data.length; i++) {
  48442. var trace = data[i];
  48443. if(!Registry.traceIs(trace, 'box-violin') ||
  48444. (trace[axLetter + 'axis'] || axLetter) !== id) continue;
  48445. if(trace[posLetter] !== undefined) boxPositions.push(trace[posLetter][0]);
  48446. else if(trace.name !== undefined) boxPositions.push(trace.name);
  48447. else boxPositions.push('text');
  48448. if(trace[calAttr] !== calendar) calendar = undefined;
  48449. }
  48450. ax.type = autoType(boxPositions, calendar);
  48451. }
  48452. else if(d0.type === 'splom') {
  48453. var dimensions = d0.dimensions;
  48454. var diag = d0._diag;
  48455. for(i = 0; i < dimensions.length; i++) {
  48456. var dim = dimensions[i];
  48457. if(dim.visible && (diag[i][0] === id || diag[i][1] === id)) {
  48458. ax.type = autoType(dim.values, calendar);
  48459. break;
  48460. }
  48461. }
  48462. }
  48463. else {
  48464. ax.type = autoType(d0[axLetter] || [d0[axLetter + '0']], calendar);
  48465. }
  48466. }
  48467. function getFirstNonEmptyTrace(data, id, axLetter) {
  48468. for(var i = 0; i < data.length; i++) {
  48469. var trace = data[i];
  48470. if(trace.type === 'splom' &&
  48471. trace._length > 0 &&
  48472. (trace['_' + axLetter + 'axes'] || {})[id]
  48473. ) {
  48474. return trace;
  48475. }
  48476. if((trace[axLetter + 'axis'] || axLetter) === id) {
  48477. if(isBoxWithoutPositionCoords(trace, axLetter)) {
  48478. return trace;
  48479. }
  48480. else if((trace[axLetter] || []).length || trace[axLetter + '0']) {
  48481. return trace;
  48482. }
  48483. }
  48484. }
  48485. }
  48486. function getBoxPosLetter(trace) {
  48487. return {v: 'x', h: 'y'}[trace.orientation || 'v'];
  48488. }
  48489. function isBoxWithoutPositionCoords(trace, axLetter) {
  48490. var posLetter = getBoxPosLetter(trace),
  48491. isBox = Registry.traceIs(trace, 'box-violin'),
  48492. isCandlestick = Registry.traceIs(trace._fullInput || {}, 'candlestick');
  48493. return (
  48494. isBox &&
  48495. !isCandlestick &&
  48496. axLetter === posLetter &&
  48497. trace[posLetter] === undefined &&
  48498. trace[posLetter + '0'] === undefined
  48499. );
  48500. }
  48501. },{"../../registry":259,"./axis_autotype":215}],238:[function(_dereq_,module,exports){
  48502. /**
  48503. * Copyright 2012-2018, Plotly, Inc.
  48504. * All rights reserved.
  48505. *
  48506. * This source code is licensed under the MIT license found in the
  48507. * LICENSE file in the root directory of this source tree.
  48508. */
  48509. 'use strict';
  48510. var Registry = _dereq_('../registry');
  48511. var Lib = _dereq_('../lib');
  48512. /*
  48513. * Create or update an observer. This function is designed to be
  48514. * idempotent so that it can be called over and over as the component
  48515. * updates, and will attach and detach listeners as needed.
  48516. *
  48517. * @param {optional object} container
  48518. * An object on which the observer is stored. This is the mechanism
  48519. * by which it is idempotent. If it already exists, another won't be
  48520. * added. Each time it's called, the value lookup table is updated.
  48521. * @param {array} commandList
  48522. * An array of commands, following either `buttons` of `updatemenus`
  48523. * or `steps` of `sliders`.
  48524. * @param {function} onchange
  48525. * A listener called when the value is changed. Receives data object
  48526. * with information about the new state.
  48527. */
  48528. exports.manageCommandObserver = function(gd, container, commandList, onchange) {
  48529. var ret = {};
  48530. var enabled = true;
  48531. if(container && container._commandObserver) {
  48532. ret = container._commandObserver;
  48533. }
  48534. if(!ret.cache) {
  48535. ret.cache = {};
  48536. }
  48537. // Either create or just recompute this:
  48538. ret.lookupTable = {};
  48539. var binding = exports.hasSimpleAPICommandBindings(gd, commandList, ret.lookupTable);
  48540. if(container && container._commandObserver) {
  48541. if(!binding) {
  48542. // If container exists and there are no longer any bindings,
  48543. // remove existing:
  48544. if(container._commandObserver.remove) {
  48545. container._commandObserver.remove();
  48546. container._commandObserver = null;
  48547. return ret;
  48548. }
  48549. } else {
  48550. // If container exists and there *are* bindings, then the lookup
  48551. // table should have been updated and check is already attached,
  48552. // so there's nothing to be done:
  48553. return ret;
  48554. }
  48555. }
  48556. // Determine whether there's anything to do for this binding:
  48557. if(binding) {
  48558. // Build the cache:
  48559. bindingValueHasChanged(gd, binding, ret.cache);
  48560. ret.check = function check() {
  48561. if(!enabled) return;
  48562. var update = bindingValueHasChanged(gd, binding, ret.cache);
  48563. if(update.changed && onchange) {
  48564. // Disable checks for the duration of this command in order to avoid
  48565. // infinite loops:
  48566. if(ret.lookupTable[update.value] !== undefined) {
  48567. ret.disable();
  48568. Promise.resolve(onchange({
  48569. value: update.value,
  48570. type: binding.type,
  48571. prop: binding.prop,
  48572. traces: binding.traces,
  48573. index: ret.lookupTable[update.value]
  48574. })).then(ret.enable, ret.enable);
  48575. }
  48576. }
  48577. return update.changed;
  48578. };
  48579. var checkEvents = [
  48580. 'plotly_relayout',
  48581. 'plotly_redraw',
  48582. 'plotly_restyle',
  48583. 'plotly_update',
  48584. 'plotly_animatingframe',
  48585. 'plotly_afterplot'
  48586. ];
  48587. for(var i = 0; i < checkEvents.length; i++) {
  48588. gd._internalOn(checkEvents[i], ret.check);
  48589. }
  48590. ret.remove = function() {
  48591. for(var i = 0; i < checkEvents.length; i++) {
  48592. gd._removeInternalListener(checkEvents[i], ret.check);
  48593. }
  48594. };
  48595. } else {
  48596. // TODO: It'd be really neat to actually give a *reason* for this, but at least a warning
  48597. // is a start
  48598. Lib.log('Unable to automatically bind plot updates to API command');
  48599. ret.lookupTable = {};
  48600. ret.remove = function() {};
  48601. }
  48602. ret.disable = function disable() {
  48603. enabled = false;
  48604. };
  48605. ret.enable = function enable() {
  48606. enabled = true;
  48607. };
  48608. if(container) {
  48609. container._commandObserver = ret;
  48610. }
  48611. return ret;
  48612. };
  48613. /*
  48614. * This function checks to see if an array of objects containing
  48615. * method and args properties is compatible with automatic two-way
  48616. * binding. The criteria right now are that
  48617. *
  48618. * 1. multiple traces may be affected
  48619. * 2. only one property may be affected
  48620. * 3. the same property must be affected by all commands
  48621. */
  48622. exports.hasSimpleAPICommandBindings = function(gd, commandList, bindingsByValue) {
  48623. var i;
  48624. var n = commandList.length;
  48625. var refBinding;
  48626. for(i = 0; i < n; i++) {
  48627. var binding;
  48628. var command = commandList[i];
  48629. var method = command.method;
  48630. var args = command.args;
  48631. if(!Array.isArray(args)) args = [];
  48632. // If any command has no method, refuse to bind:
  48633. if(!method) {
  48634. return false;
  48635. }
  48636. var bindings = exports.computeAPICommandBindings(gd, method, args);
  48637. // Right now, handle one and *only* one property being set:
  48638. if(bindings.length !== 1) {
  48639. return false;
  48640. }
  48641. if(!refBinding) {
  48642. refBinding = bindings[0];
  48643. if(Array.isArray(refBinding.traces)) {
  48644. refBinding.traces.sort();
  48645. }
  48646. } else {
  48647. binding = bindings[0];
  48648. if(binding.type !== refBinding.type) {
  48649. return false;
  48650. }
  48651. if(binding.prop !== refBinding.prop) {
  48652. return false;
  48653. }
  48654. if(Array.isArray(refBinding.traces)) {
  48655. if(Array.isArray(binding.traces)) {
  48656. binding.traces.sort();
  48657. for(var j = 0; j < refBinding.traces.length; j++) {
  48658. if(refBinding.traces[j] !== binding.traces[j]) {
  48659. return false;
  48660. }
  48661. }
  48662. } else {
  48663. return false;
  48664. }
  48665. } else {
  48666. if(binding.prop !== refBinding.prop) {
  48667. return false;
  48668. }
  48669. }
  48670. }
  48671. binding = bindings[0];
  48672. var value = binding.value;
  48673. if(Array.isArray(value)) {
  48674. if(value.length === 1) {
  48675. value = value[0];
  48676. } else {
  48677. return false;
  48678. }
  48679. }
  48680. if(bindingsByValue) {
  48681. bindingsByValue[value] = i;
  48682. }
  48683. }
  48684. return refBinding;
  48685. };
  48686. function bindingValueHasChanged(gd, binding, cache) {
  48687. var container, value, obj;
  48688. var changed = false;
  48689. if(binding.type === 'data') {
  48690. // If it's data, we need to get a trace. Based on the limited scope
  48691. // of what we cover, we can just take the first trace from the list,
  48692. // or otherwise just the first trace:
  48693. container = gd._fullData[binding.traces !== null ? binding.traces[0] : 0];
  48694. } else if(binding.type === 'layout') {
  48695. container = gd._fullLayout;
  48696. } else {
  48697. return false;
  48698. }
  48699. value = Lib.nestedProperty(container, binding.prop).get();
  48700. obj = cache[binding.type] = cache[binding.type] || {};
  48701. if(obj.hasOwnProperty(binding.prop)) {
  48702. if(obj[binding.prop] !== value) {
  48703. changed = true;
  48704. }
  48705. }
  48706. obj[binding.prop] = value;
  48707. return {
  48708. changed: changed,
  48709. value: value
  48710. };
  48711. }
  48712. /*
  48713. * Execute an API command. There's really not much to this; it just provides
  48714. * a common hook so that implementations don't need to be synchronized across
  48715. * multiple components with the ability to invoke API commands.
  48716. *
  48717. * @param {string} method
  48718. * The name of the plotly command to execute. Must be one of 'animate',
  48719. * 'restyle', 'relayout', 'update'.
  48720. * @param {array} args
  48721. * A list of arguments passed to the API command
  48722. */
  48723. exports.executeAPICommand = function(gd, method, args) {
  48724. if(method === 'skip') return Promise.resolve();
  48725. var _method = Registry.apiMethodRegistry[method];
  48726. var allArgs = [gd];
  48727. if(!Array.isArray(args)) args = [];
  48728. for(var i = 0; i < args.length; i++) {
  48729. allArgs.push(args[i]);
  48730. }
  48731. return _method.apply(null, allArgs).catch(function(err) {
  48732. Lib.warn('API call to Plotly.' + method + ' rejected.', err);
  48733. return Promise.reject(err);
  48734. });
  48735. };
  48736. exports.computeAPICommandBindings = function(gd, method, args) {
  48737. var bindings;
  48738. if(!Array.isArray(args)) args = [];
  48739. switch(method) {
  48740. case 'restyle':
  48741. bindings = computeDataBindings(gd, args);
  48742. break;
  48743. case 'relayout':
  48744. bindings = computeLayoutBindings(gd, args);
  48745. break;
  48746. case 'update':
  48747. bindings = computeDataBindings(gd, [args[0], args[2]])
  48748. .concat(computeLayoutBindings(gd, [args[1]]));
  48749. break;
  48750. case 'animate':
  48751. bindings = computeAnimateBindings(gd, args);
  48752. break;
  48753. default:
  48754. // This is the case where intelligent logic about what affects
  48755. // this command is not implemented. It causes no ill effects.
  48756. // For example, addFrames simply won't bind to a control component.
  48757. bindings = [];
  48758. }
  48759. return bindings;
  48760. };
  48761. function computeAnimateBindings(gd, args) {
  48762. // We'll assume that the only relevant modification an animation
  48763. // makes that's meaningfully tracked is the frame:
  48764. if(Array.isArray(args[0]) && args[0].length === 1 && ['string', 'number'].indexOf(typeof args[0][0]) !== -1) {
  48765. return [{type: 'layout', prop: '_currentFrame', value: args[0][0].toString()}];
  48766. } else {
  48767. return [];
  48768. }
  48769. }
  48770. function computeLayoutBindings(gd, args) {
  48771. var bindings = [];
  48772. var astr = args[0];
  48773. var aobj = {};
  48774. if(typeof astr === 'string') {
  48775. aobj[astr] = args[1];
  48776. } else if(Lib.isPlainObject(astr)) {
  48777. aobj = astr;
  48778. } else {
  48779. return bindings;
  48780. }
  48781. crawl(aobj, function(path, attrName, attr) {
  48782. bindings.push({type: 'layout', prop: path, value: attr});
  48783. }, '', 0);
  48784. return bindings;
  48785. }
  48786. function computeDataBindings(gd, args) {
  48787. var traces, astr, val, aobj;
  48788. var bindings = [];
  48789. // Logic copied from Plotly.restyle:
  48790. astr = args[0];
  48791. val = args[1];
  48792. traces = args[2];
  48793. aobj = {};
  48794. if(typeof astr === 'string') {
  48795. aobj[astr] = val;
  48796. } else if(Lib.isPlainObject(astr)) {
  48797. // the 3-arg form
  48798. aobj = astr;
  48799. if(traces === undefined) {
  48800. traces = val;
  48801. }
  48802. } else {
  48803. return bindings;
  48804. }
  48805. if(traces === undefined) {
  48806. // Explicitly assign this to null instead of undefined:
  48807. traces = null;
  48808. }
  48809. crawl(aobj, function(path, attrName, attr) {
  48810. var thisTraces;
  48811. if(Array.isArray(attr)) {
  48812. var nAttr = Math.min(attr.length, gd.data.length);
  48813. if(traces) {
  48814. nAttr = Math.min(nAttr, traces.length);
  48815. }
  48816. thisTraces = [];
  48817. for(var j = 0; j < nAttr; j++) {
  48818. thisTraces[j] = traces ? traces[j] : j;
  48819. }
  48820. } else {
  48821. thisTraces = traces ? traces.slice(0) : null;
  48822. }
  48823. // Convert [7] to just 7 when traces is null:
  48824. if(thisTraces === null) {
  48825. if(Array.isArray(attr)) {
  48826. attr = attr[0];
  48827. }
  48828. } else if(Array.isArray(thisTraces)) {
  48829. if(!Array.isArray(attr)) {
  48830. var tmp = attr;
  48831. attr = [];
  48832. for(var i = 0; i < thisTraces.length; i++) {
  48833. attr[i] = tmp;
  48834. }
  48835. }
  48836. attr.length = Math.min(thisTraces.length, attr.length);
  48837. }
  48838. bindings.push({
  48839. type: 'data',
  48840. prop: path,
  48841. traces: thisTraces,
  48842. value: attr
  48843. });
  48844. }, '', 0);
  48845. return bindings;
  48846. }
  48847. function crawl(attrs, callback, path, depth) {
  48848. Object.keys(attrs).forEach(function(attrName) {
  48849. var attr = attrs[attrName];
  48850. if(attrName[0] === '_') return;
  48851. var thisPath = path + (depth > 0 ? '.' : '') + attrName;
  48852. if(Lib.isPlainObject(attr)) {
  48853. crawl(attr, callback, thisPath, depth + 1);
  48854. } else {
  48855. // Only execute the callback on leaf nodes:
  48856. callback(thisPath, attrName, attr);
  48857. }
  48858. });
  48859. }
  48860. },{"../lib":169,"../registry":259}],239:[function(_dereq_,module,exports){
  48861. /**
  48862. * Copyright 2012-2018, Plotly, Inc.
  48863. * All rights reserved.
  48864. *
  48865. * This source code is licensed under the MIT license found in the
  48866. * LICENSE file in the root directory of this source tree.
  48867. */
  48868. 'use strict';
  48869. var extendFlat = _dereq_('../lib/extend').extendFlat;
  48870. /**
  48871. * Make a xy domain attribute group
  48872. *
  48873. * @param {object} opts
  48874. * @param {string}
  48875. * opts.name: name to be inserted in the default description
  48876. * @param {boolean}
  48877. * opts.trace: set to true for trace containers
  48878. * @param {string}
  48879. * opts.editType: editType for all pieces
  48880. * @param {boolean}
  48881. * opts.noGridCell: set to true to omit `row` and `column`
  48882. *
  48883. * @param {object} extra
  48884. * @param {string}
  48885. * extra.description: extra description. N.B we use
  48886. * a separate extra container to make it compatible with
  48887. * the compress_attributes transform.
  48888. *
  48889. * @return {object} attributes object containing {x,y} as specified
  48890. */
  48891. exports.attributes = function(opts, extra) {
  48892. opts = opts || {};
  48893. extra = extra || {};
  48894. var base = {
  48895. valType: 'info_array',
  48896. editType: opts.editType,
  48897. items: [
  48898. {valType: 'number', min: 0, max: 1, editType: opts.editType},
  48899. {valType: 'number', min: 0, max: 1, editType: opts.editType}
  48900. ],
  48901. dflt: [0, 1]
  48902. };
  48903. var namePart = opts.name ? opts.name + ' ' : '';
  48904. var contPart = opts.trace ? 'trace ' : 'subplot ';
  48905. var descPart = extra.description ? ' ' + extra.description : '';
  48906. var out = {
  48907. x: extendFlat({}, base, {
  48908. }),
  48909. y: extendFlat({}, base, {
  48910. }),
  48911. editType: opts.editType
  48912. };
  48913. if(!opts.noGridCell) {
  48914. out.row = {
  48915. valType: 'integer',
  48916. min: 0,
  48917. dflt: 0,
  48918. editType: opts.editType,
  48919. };
  48920. out.column = {
  48921. valType: 'integer',
  48922. min: 0,
  48923. dflt: 0,
  48924. editType: opts.editType,
  48925. };
  48926. }
  48927. return out;
  48928. };
  48929. exports.defaults = function(containerOut, layout, coerce, dfltDomains) {
  48930. var dfltX = (dfltDomains && dfltDomains.x) || [0, 1];
  48931. var dfltY = (dfltDomains && dfltDomains.y) || [0, 1];
  48932. var grid = layout.grid;
  48933. if(grid) {
  48934. var column = coerce('domain.column');
  48935. if(column !== undefined) {
  48936. if(column < grid.columns) dfltX = grid._domains.x[column];
  48937. else delete containerOut.domain.column;
  48938. }
  48939. var row = coerce('domain.row');
  48940. if(row !== undefined) {
  48941. if(row < grid.rows) dfltY = grid._domains.y[row];
  48942. else delete containerOut.domain.row;
  48943. }
  48944. }
  48945. coerce('domain.x', dfltX);
  48946. coerce('domain.y', dfltY);
  48947. };
  48948. },{"../lib/extend":163}],240:[function(_dereq_,module,exports){
  48949. /**
  48950. * Copyright 2012-2018, Plotly, Inc.
  48951. * All rights reserved.
  48952. *
  48953. * This source code is licensed under the MIT license found in the
  48954. * LICENSE file in the root directory of this source tree.
  48955. */
  48956. 'use strict';
  48957. /*
  48958. * make a font attribute group
  48959. *
  48960. * @param {object} opts
  48961. * @param {string}
  48962. * opts.description: where & how this font is used
  48963. * @param {optional bool} arrayOk:
  48964. * should each part (family, size, color) be arrayOk? default false.
  48965. * @param {string} editType:
  48966. * the editType for all pieces of this font
  48967. * @param {optional string} colorEditType:
  48968. * a separate editType just for color
  48969. *
  48970. * @return {object} attributes object containing {family, size, color} as specified
  48971. */
  48972. module.exports = function(opts) {
  48973. var editType = opts.editType;
  48974. var colorEditType = opts.colorEditType;
  48975. if(colorEditType === undefined) colorEditType = editType;
  48976. var attrs = {
  48977. family: {
  48978. valType: 'string',
  48979. noBlank: true,
  48980. strict: true,
  48981. editType: editType,
  48982. },
  48983. size: {
  48984. valType: 'number',
  48985. min: 1,
  48986. editType: editType
  48987. },
  48988. color: {
  48989. valType: 'color',
  48990. editType: colorEditType
  48991. },
  48992. editType: editType,
  48993. // blank strings so compress_attributes can remove
  48994. // TODO - that's uber hacky... better solution?
  48995. };
  48996. if(opts.arrayOk) {
  48997. attrs.family.arrayOk = true;
  48998. attrs.size.arrayOk = true;
  48999. attrs.color.arrayOk = true;
  49000. }
  49001. return attrs;
  49002. };
  49003. },{}],241:[function(_dereq_,module,exports){
  49004. /**
  49005. * Copyright 2012-2018, Plotly, Inc.
  49006. * All rights reserved.
  49007. *
  49008. * This source code is licensed under the MIT license found in the
  49009. * LICENSE file in the root directory of this source tree.
  49010. */
  49011. 'use strict';
  49012. module.exports = {
  49013. _isLinkedToArray: 'frames_entry',
  49014. group: {
  49015. valType: 'string',
  49016. },
  49017. name: {
  49018. valType: 'string',
  49019. },
  49020. traces: {
  49021. valType: 'any',
  49022. },
  49023. baseframe: {
  49024. valType: 'string',
  49025. },
  49026. data: {
  49027. valType: 'any',
  49028. },
  49029. layout: {
  49030. valType: 'any',
  49031. }
  49032. };
  49033. },{}],242:[function(_dereq_,module,exports){
  49034. /**
  49035. * Copyright 2012-2018, Plotly, Inc.
  49036. * All rights reserved.
  49037. *
  49038. * This source code is licensed under the MIT license found in the
  49039. * LICENSE file in the root directory of this source tree.
  49040. */
  49041. 'use strict';
  49042. var Registry = _dereq_('../registry');
  49043. var SUBPLOT_PATTERN = _dereq_('./cartesian/constants').SUBPLOT_PATTERN;
  49044. /**
  49045. * Get calcdata trace(s) associated with a given subplot
  49046. *
  49047. * @param {array} calcData: as in gd.calcdata
  49048. * @param {string} type: subplot type
  49049. * @param {string} subplotId: subplot id to look for
  49050. *
  49051. * @return {array} array of calcdata traces
  49052. */
  49053. exports.getSubplotCalcData = function(calcData, type, subplotId) {
  49054. var basePlotModule = Registry.subplotsRegistry[type];
  49055. if(!basePlotModule) return [];
  49056. var attr = basePlotModule.attr;
  49057. var subplotCalcData = [];
  49058. for(var i = 0; i < calcData.length; i++) {
  49059. var calcTrace = calcData[i];
  49060. var trace = calcTrace[0].trace;
  49061. if(trace[attr] === subplotId) subplotCalcData.push(calcTrace);
  49062. }
  49063. return subplotCalcData;
  49064. };
  49065. /**
  49066. * Get calcdata trace(s) that can be plotted with a given module
  49067. * NOTE: this isn't necessarily just exactly matching trace type,
  49068. * if multiple trace types use the same plotting routine, they will be
  49069. * collected here.
  49070. * In order to not plot the same thing multiple times, we return two arrays,
  49071. * the calcdata we *will* plot with this module, and the ones we *won't*
  49072. *
  49073. * @param {array} calcdata: as in gd.calcdata
  49074. * @param {object|string|fn} arg1:
  49075. * the plotting module, or its name, or its plot method
  49076. *
  49077. * @return {array[array]} [foundCalcdata, remainingCalcdata]
  49078. */
  49079. exports.getModuleCalcData = function(calcdata, arg1) {
  49080. var moduleCalcData = [];
  49081. var remainingCalcData = [];
  49082. var plotMethod;
  49083. if(typeof arg1 === 'string') {
  49084. plotMethod = Registry.getModule(arg1).plot;
  49085. } else if(typeof arg1 === 'function') {
  49086. plotMethod = arg1;
  49087. } else {
  49088. plotMethod = arg1.plot;
  49089. }
  49090. if(!plotMethod) {
  49091. return [moduleCalcData, calcdata];
  49092. }
  49093. for(var i = 0; i < calcdata.length; i++) {
  49094. var cd = calcdata[i];
  49095. var trace = cd[0].trace;
  49096. // N.B. 'legendonly' traces do not make it past here
  49097. if(trace.visible !== true) continue;
  49098. // group calcdata trace not by 'module' (as the name of this function
  49099. // would suggest), but by 'module plot method' so that if some traces
  49100. // share the same module plot method (e.g. bar and histogram), we
  49101. // only call it one!
  49102. if(trace._module.plot === plotMethod) {
  49103. moduleCalcData.push(cd);
  49104. } else {
  49105. remainingCalcData.push(cd);
  49106. }
  49107. }
  49108. return [moduleCalcData, remainingCalcData];
  49109. };
  49110. /**
  49111. * Get the data trace(s) associated with a given subplot.
  49112. *
  49113. * @param {array} data plotly full data array.
  49114. * @param {string} type subplot type to look for.
  49115. * @param {string} subplotId subplot id to look for.
  49116. *
  49117. * @return {array} list of trace objects.
  49118. *
  49119. */
  49120. exports.getSubplotData = function getSubplotData(data, type, subplotId) {
  49121. if(!Registry.subplotsRegistry[type]) return [];
  49122. var attr = Registry.subplotsRegistry[type].attr;
  49123. var subplotData = [];
  49124. var trace, subplotX, subplotY;
  49125. if(type === 'gl2d') {
  49126. var spmatch = subplotId.match(SUBPLOT_PATTERN);
  49127. subplotX = 'x' + spmatch[1];
  49128. subplotY = 'y' + spmatch[2];
  49129. }
  49130. for(var i = 0; i < data.length; i++) {
  49131. trace = data[i];
  49132. if(type === 'gl2d' && Registry.traceIs(trace, 'gl2d')) {
  49133. if(trace[attr[0]] === subplotX && trace[attr[1]] === subplotY) {
  49134. subplotData.push(trace);
  49135. }
  49136. }
  49137. else {
  49138. if(trace[attr] === subplotId) subplotData.push(trace);
  49139. }
  49140. }
  49141. return subplotData;
  49142. };
  49143. },{"../registry":259,"./cartesian/constants":219}],243:[function(_dereq_,module,exports){
  49144. /**
  49145. * Copyright 2012-2018, Plotly, Inc.
  49146. * All rights reserved.
  49147. *
  49148. * This source code is licensed under the MIT license found in the
  49149. * LICENSE file in the root directory of this source tree.
  49150. */
  49151. 'use strict';
  49152. function xformMatrix(m, v) {
  49153. var out = [0, 0, 0, 0];
  49154. var i, j;
  49155. for(i = 0; i < 4; ++i) {
  49156. for(j = 0; j < 4; ++j) {
  49157. out[j] += m[4 * i + j] * v[i];
  49158. }
  49159. }
  49160. return out;
  49161. }
  49162. function project(camera, v) {
  49163. var p = xformMatrix(camera.projection,
  49164. xformMatrix(camera.view,
  49165. xformMatrix(camera.model, [v[0], v[1], v[2], 1])));
  49166. return p;
  49167. }
  49168. module.exports = project;
  49169. },{}],244:[function(_dereq_,module,exports){
  49170. /**
  49171. * Copyright 2012-2018, Plotly, Inc.
  49172. * All rights reserved.
  49173. *
  49174. * This source code is licensed under the MIT license found in the
  49175. * LICENSE file in the root directory of this source tree.
  49176. */
  49177. 'use strict';
  49178. var fontAttrs = _dereq_('./font_attributes');
  49179. var colorAttrs = _dereq_('../components/color/attributes');
  49180. var globalFont = fontAttrs({
  49181. editType: 'calc',
  49182. });
  49183. globalFont.family.dflt = '"Open Sans", verdana, arial, sans-serif';
  49184. globalFont.size.dflt = 12;
  49185. globalFont.color.dflt = colorAttrs.defaultLine;
  49186. module.exports = {
  49187. font: globalFont,
  49188. title: {
  49189. valType: 'string',
  49190. editType: 'layoutstyle',
  49191. },
  49192. titlefont: fontAttrs({
  49193. editType: 'layoutstyle',
  49194. }),
  49195. autosize: {
  49196. valType: 'boolean',
  49197. dflt: false,
  49198. // autosize, width, and height get special editType treatment in _relayout
  49199. // so we can handle noop resizes more efficiently
  49200. editType: 'none',
  49201. },
  49202. width: {
  49203. valType: 'number',
  49204. min: 10,
  49205. dflt: 700,
  49206. editType: 'plot',
  49207. },
  49208. height: {
  49209. valType: 'number',
  49210. min: 10,
  49211. dflt: 450,
  49212. editType: 'plot',
  49213. },
  49214. margin: {
  49215. l: {
  49216. valType: 'number',
  49217. min: 0,
  49218. dflt: 80,
  49219. editType: 'plot',
  49220. },
  49221. r: {
  49222. valType: 'number',
  49223. min: 0,
  49224. dflt: 80,
  49225. editType: 'plot',
  49226. },
  49227. t: {
  49228. valType: 'number',
  49229. min: 0,
  49230. dflt: 100,
  49231. editType: 'plot',
  49232. },
  49233. b: {
  49234. valType: 'number',
  49235. min: 0,
  49236. dflt: 80,
  49237. editType: 'plot',
  49238. },
  49239. pad: {
  49240. valType: 'number',
  49241. min: 0,
  49242. dflt: 0,
  49243. editType: 'plot',
  49244. },
  49245. autoexpand: {
  49246. valType: 'boolean',
  49247. dflt: true,
  49248. editType: 'plot'
  49249. },
  49250. editType: 'plot'
  49251. },
  49252. paper_bgcolor: {
  49253. valType: 'color',
  49254. dflt: colorAttrs.background,
  49255. editType: 'plot',
  49256. },
  49257. plot_bgcolor: {
  49258. // defined here, but set in cartesian.supplyLayoutDefaults
  49259. // because it needs to know if there are (2D) axes or not
  49260. valType: 'color',
  49261. dflt: colorAttrs.background,
  49262. editType: 'layoutstyle',
  49263. },
  49264. separators: {
  49265. valType: 'string',
  49266. editType: 'plot',
  49267. },
  49268. hidesources: {
  49269. valType: 'boolean',
  49270. dflt: false,
  49271. editType: 'plot',
  49272. },
  49273. showlegend: {
  49274. // handled in legend.supplyLayoutDefaults
  49275. // but included here because it's not in the legend object
  49276. valType: 'boolean',
  49277. editType: 'legend',
  49278. },
  49279. colorway: {
  49280. valType: 'colorlist',
  49281. dflt: colorAttrs.defaults,
  49282. editType: 'calc',
  49283. },
  49284. datarevision: {
  49285. valType: 'any',
  49286. editType: 'calc',
  49287. },
  49288. template: {
  49289. valType: 'any',
  49290. editType: 'calc',
  49291. }
  49292. };
  49293. },{"../components/color/attributes":49,"./font_attributes":240}],245:[function(_dereq_,module,exports){
  49294. /**
  49295. * Copyright 2012-2018, Plotly, Inc.
  49296. * All rights reserved.
  49297. *
  49298. * This source code is licensed under the MIT license found in the
  49299. * LICENSE file in the root directory of this source tree.
  49300. */
  49301. 'use strict';
  49302. // This is used exclusively by components inside component arrays,
  49303. // hence the 'arraydraw' editType. If this ever gets used elsewhere
  49304. // we could generalize it as a function ala font_attributes
  49305. module.exports = {
  49306. t: {
  49307. valType: 'number',
  49308. dflt: 0,
  49309. editType: 'arraydraw',
  49310. },
  49311. r: {
  49312. valType: 'number',
  49313. dflt: 0,
  49314. editType: 'arraydraw',
  49315. },
  49316. b: {
  49317. valType: 'number',
  49318. dflt: 0,
  49319. editType: 'arraydraw',
  49320. },
  49321. l: {
  49322. valType: 'number',
  49323. dflt: 0,
  49324. editType: 'arraydraw',
  49325. },
  49326. editType: 'arraydraw'
  49327. };
  49328. },{}],246:[function(_dereq_,module,exports){
  49329. /**
  49330. * Copyright 2012-2018, Plotly, Inc.
  49331. * All rights reserved.
  49332. *
  49333. * This source code is licensed under the MIT license found in the
  49334. * LICENSE file in the root directory of this source tree.
  49335. */
  49336. 'use strict';
  49337. var d3 = _dereq_('d3');
  49338. var isNumeric = _dereq_('fast-isnumeric');
  49339. var Registry = _dereq_('../registry');
  49340. var PlotSchema = _dereq_('../plot_api/plot_schema');
  49341. var Template = _dereq_('../plot_api/plot_template');
  49342. var Lib = _dereq_('../lib');
  49343. var Color = _dereq_('../components/color');
  49344. var BADNUM = _dereq_('../constants/numerical').BADNUM;
  49345. var axisIDs = _dereq_('../plots/cartesian/axis_ids');
  49346. var sortBasePlotModules = _dereq_('./sort_modules').sortBasePlotModules;
  49347. var animationAttrs = _dereq_('./animation_attributes');
  49348. var frameAttrs = _dereq_('./frame_attributes');
  49349. var relinkPrivateKeys = Lib.relinkPrivateKeys;
  49350. var _ = Lib._;
  49351. var plots = module.exports = {};
  49352. // Expose registry methods on Plots for backward-compatibility
  49353. Lib.extendFlat(plots, Registry);
  49354. plots.attributes = _dereq_('./attributes');
  49355. plots.attributes.type.values = plots.allTypes;
  49356. plots.fontAttrs = _dereq_('./font_attributes');
  49357. plots.layoutAttributes = _dereq_('./layout_attributes');
  49358. // TODO make this a plot attribute?
  49359. plots.fontWeight = 'normal';
  49360. var transformsRegistry = plots.transformsRegistry;
  49361. var commandModule = _dereq_('./command');
  49362. plots.executeAPICommand = commandModule.executeAPICommand;
  49363. plots.computeAPICommandBindings = commandModule.computeAPICommandBindings;
  49364. plots.manageCommandObserver = commandModule.manageCommandObserver;
  49365. plots.hasSimpleAPICommandBindings = commandModule.hasSimpleAPICommandBindings;
  49366. // in some cases the browser doesn't seem to know how big
  49367. // the text is at first, so it needs to draw it,
  49368. // then wait a little, then draw it again
  49369. plots.redrawText = function(gd) {
  49370. gd = Lib.getGraphDiv(gd);
  49371. // do not work if polar is present
  49372. if((gd.data && gd.data[0] && gd.data[0].r)) return;
  49373. return new Promise(function(resolve) {
  49374. setTimeout(function() {
  49375. Registry.getComponentMethod('annotations', 'draw')(gd);
  49376. Registry.getComponentMethod('legend', 'draw')(gd);
  49377. (gd.calcdata || []).forEach(function(d) {
  49378. if(d[0] && d[0].t && d[0].t.cb) d[0].t.cb();
  49379. });
  49380. resolve(plots.previousPromises(gd));
  49381. }, 300);
  49382. });
  49383. };
  49384. // resize plot about the container size
  49385. plots.resize = function(gd) {
  49386. gd = Lib.getGraphDiv(gd);
  49387. return new Promise(function(resolve, reject) {
  49388. function isHidden(gd) {
  49389. var display = window.getComputedStyle(gd).display;
  49390. return !display || display === 'none';
  49391. }
  49392. if(!gd || isHidden(gd)) {
  49393. reject(new Error('Resize must be passed a displayed plot div element.'));
  49394. }
  49395. if(gd._redrawTimer) clearTimeout(gd._redrawTimer);
  49396. gd._redrawTimer = setTimeout(function() {
  49397. // return if there is nothing to resize or is hidden
  49398. if(!gd.layout || (gd.layout.width && gd.layout.height) || isHidden(gd)) {
  49399. resolve(gd);
  49400. return;
  49401. }
  49402. delete gd.layout.width;
  49403. delete gd.layout.height;
  49404. // autosizing doesn't count as a change that needs saving
  49405. var oldchanged = gd.changed;
  49406. // nor should it be included in the undo queue
  49407. gd.autoplay = true;
  49408. Registry.call('relayout', gd, {autosize: true}).then(function() {
  49409. gd.changed = oldchanged;
  49410. resolve(gd);
  49411. });
  49412. }, 100);
  49413. });
  49414. };
  49415. // for use in Lib.syncOrAsync, check if there are any
  49416. // pending promises in this plot and wait for them
  49417. plots.previousPromises = function(gd) {
  49418. if((gd._promises || []).length) {
  49419. return Promise.all(gd._promises)
  49420. .then(function() { gd._promises = []; });
  49421. }
  49422. };
  49423. /**
  49424. * Adds the 'Edit chart' link.
  49425. * Note that now Plotly.plot() calls this so it can regenerate whenever it replots
  49426. *
  49427. * Add source links to your graph inside the 'showSources' config argument.
  49428. */
  49429. plots.addLinks = function(gd) {
  49430. // Do not do anything if showLink and showSources are not set to true in config
  49431. if(!gd._context.showLink && !gd._context.showSources) return;
  49432. var fullLayout = gd._fullLayout;
  49433. var linkContainer = Lib.ensureSingle(fullLayout._paper, 'text', 'js-plot-link-container', function(s) {
  49434. s.style({
  49435. 'font-family': '"Open Sans", Arial, sans-serif',
  49436. 'font-size': '12px',
  49437. 'fill': Color.defaultLine,
  49438. 'pointer-events': 'all'
  49439. })
  49440. .each(function() {
  49441. var links = d3.select(this);
  49442. links.append('tspan').classed('js-link-to-tool', true);
  49443. links.append('tspan').classed('js-link-spacer', true);
  49444. links.append('tspan').classed('js-sourcelinks', true);
  49445. });
  49446. });
  49447. // The text node inside svg
  49448. var text = linkContainer.node();
  49449. var attrs = {y: fullLayout._paper.attr('height') - 9};
  49450. // If text's width is bigger than the layout
  49451. // Check that text is a child node or document.body
  49452. // because otherwise IE/Edge might throw an exception
  49453. // when calling getComputedTextLength().
  49454. // Apparently offsetParent is null for invisibles.
  49455. if(document.body.contains(text) && text.getComputedTextLength() >= (fullLayout.width - 20)) {
  49456. // Align the text at the left
  49457. attrs['text-anchor'] = 'start';
  49458. attrs.x = 5;
  49459. }
  49460. else {
  49461. // Align the text at the right
  49462. attrs['text-anchor'] = 'end';
  49463. attrs.x = fullLayout._paper.attr('width') - 7;
  49464. }
  49465. linkContainer.attr(attrs);
  49466. var toolspan = linkContainer.select('.js-link-to-tool'),
  49467. spacespan = linkContainer.select('.js-link-spacer'),
  49468. sourcespan = linkContainer.select('.js-sourcelinks');
  49469. if(gd._context.showSources) gd._context.showSources(gd);
  49470. // 'view in plotly' link for embedded plots
  49471. if(gd._context.showLink) positionPlayWithData(gd, toolspan);
  49472. // separator if we have both sources and tool link
  49473. spacespan.text((toolspan.text() && sourcespan.text()) ? ' - ' : '');
  49474. };
  49475. // note that now this function is only adding the brand in
  49476. // iframes and 3rd-party apps
  49477. function positionPlayWithData(gd, container) {
  49478. container.text('');
  49479. var link = container.append('a')
  49480. .attr({
  49481. 'xlink:xlink:href': '#',
  49482. 'class': 'link--impt link--embedview',
  49483. 'font-weight': 'bold'
  49484. })
  49485. .text(gd._context.linkText + ' ' + String.fromCharCode(187));
  49486. if(gd._context.sendData) {
  49487. link.on('click', function() {
  49488. plots.sendDataToCloud(gd);
  49489. });
  49490. }
  49491. else {
  49492. var path = window.location.pathname.split('/');
  49493. var query = window.location.search;
  49494. link.attr({
  49495. 'xlink:xlink:show': 'new',
  49496. 'xlink:xlink:href': '/' + path[2].split('.')[0] + '/' + path[1] + query
  49497. });
  49498. }
  49499. }
  49500. plots.sendDataToCloud = function(gd) {
  49501. gd.emit('plotly_beforeexport');
  49502. var baseUrl = (window.PLOTLYENV || {}).BASE_URL || gd._context.plotlyServerURL;
  49503. var hiddenformDiv = d3.select(gd)
  49504. .append('div')
  49505. .attr('id', 'hiddenform')
  49506. .style('display', 'none');
  49507. var hiddenform = hiddenformDiv
  49508. .append('form')
  49509. .attr({
  49510. action: baseUrl + '/external',
  49511. method: 'post',
  49512. target: '_blank'
  49513. });
  49514. var hiddenformInput = hiddenform
  49515. .append('input')
  49516. .attr({
  49517. type: 'text',
  49518. name: 'data'
  49519. });
  49520. hiddenformInput.node().value = plots.graphJson(gd, false, 'keepdata');
  49521. hiddenform.node().submit();
  49522. hiddenformDiv.remove();
  49523. gd.emit('plotly_afterexport');
  49524. return false;
  49525. };
  49526. var d3FormatKeys = [
  49527. 'days', 'shortDays', 'months', 'shortMonths', 'periods',
  49528. 'dateTime', 'date', 'time',
  49529. 'decimal', 'thousands', 'grouping', 'currency'
  49530. ];
  49531. var extraFormatKeys = [
  49532. 'year', 'month', 'dayMonth', 'dayMonthYear'
  49533. ];
  49534. /*
  49535. * Fill in default values
  49536. * @param {DOM element} gd
  49537. * @param {object} opts
  49538. * @param {boolean} opts.skipUpdateCalc: normally if the existing gd.calcdata looks
  49539. * compatible with the new gd._fullData we finish by linking the new _fullData traces
  49540. * to the old gd.calcdata, so it's correctly set if we're not going to recalc. But also,
  49541. * if there are calcTransforms on the trace, we first remap data arrays from the old full
  49542. * trace into the new one. Use skipUpdateCalc to defer this (needed by Plotly.react)
  49543. *
  49544. * gd.data, gd.layout:
  49545. * are precisely what the user specified (except as modified by cleanData/cleanLayout),
  49546. * these fields shouldn't be modified (except for filling in some auto values)
  49547. * nor used directly after the supply defaults step.
  49548. *
  49549. * gd._fullData, gd._fullLayout:
  49550. * are complete descriptions of how to draw the plot,
  49551. * use these fields in all required computations.
  49552. *
  49553. * gd._fullLayout._modules
  49554. * is a list of all the trace modules required to draw the plot.
  49555. *
  49556. * gd._fullLayout._visibleModules
  49557. * subset of _modules, a list of modules corresponding to visible:true traces.
  49558. *
  49559. * gd._fullLayout._basePlotModules
  49560. * is a list of all the plot modules required to draw the plot.
  49561. *
  49562. * gd._fullLayout._transformModules
  49563. * is a list of all the transform modules invoked.
  49564. *
  49565. */
  49566. plots.supplyDefaults = function(gd, opts) {
  49567. var skipUpdateCalc = opts && opts.skipUpdateCalc;
  49568. var oldFullLayout = gd._fullLayout || {};
  49569. if(oldFullLayout._skipDefaults) {
  49570. delete oldFullLayout._skipDefaults;
  49571. return;
  49572. }
  49573. var newFullLayout = gd._fullLayout = {};
  49574. var newLayout = gd.layout || {};
  49575. var oldFullData = gd._fullData || [];
  49576. var newFullData = gd._fullData = [];
  49577. var newData = gd.data || [];
  49578. var oldCalcdata = gd.calcdata || [];
  49579. var context = gd._context || {};
  49580. var i;
  49581. // Create all the storage space for frames, but only if doesn't already exist
  49582. if(!gd._transitionData) plots.createTransitionData(gd);
  49583. // So we only need to do this once (and since we have gd here)
  49584. // get the translated placeholder titles.
  49585. // These ones get used as default values so need to be known at supplyDefaults
  49586. // others keep their blank defaults but render the placeholder as desired later
  49587. // TODO: make these work the same way, only inserting the placeholder text at draw time?
  49588. // The challenge is that this has slightly different behavior right now in editable mode:
  49589. // using the placeholder as default makes this text permanently (but lightly) visible,
  49590. // but explicit '' for these titles gives you a placeholder that's hidden until you mouse
  49591. // over it - so you're not distracted by it if you really don't want a title, but if you do
  49592. // and you're new to plotly you may not be able to find it.
  49593. // When editable=false the two behave the same, no title is drawn.
  49594. newFullLayout._dfltTitle = {
  49595. plot: _(gd, 'Click to enter Plot title'),
  49596. x: _(gd, 'Click to enter X axis title'),
  49597. y: _(gd, 'Click to enter Y axis title'),
  49598. colorbar: _(gd, 'Click to enter Colorscale title'),
  49599. annotation: _(gd, 'new text')
  49600. };
  49601. newFullLayout._traceWord = _(gd, 'trace');
  49602. var formatObj = getFormatObj(gd, d3FormatKeys);
  49603. // stash the token from context so mapbox subplots can use it as default
  49604. newFullLayout._mapboxAccessToken = context.mapboxAccessToken;
  49605. // first fill in what we can of layout without looking at data
  49606. // because fullData needs a few things from layout
  49607. if(oldFullLayout._initialAutoSizeIsDone) {
  49608. // coerce the updated layout while preserving width and height
  49609. var oldWidth = oldFullLayout.width,
  49610. oldHeight = oldFullLayout.height;
  49611. plots.supplyLayoutGlobalDefaults(newLayout, newFullLayout, formatObj);
  49612. if(!newLayout.width) newFullLayout.width = oldWidth;
  49613. if(!newLayout.height) newFullLayout.height = oldHeight;
  49614. plots.sanitizeMargins(newFullLayout);
  49615. }
  49616. else {
  49617. // coerce the updated layout and autosize if needed
  49618. plots.supplyLayoutGlobalDefaults(newLayout, newFullLayout, formatObj);
  49619. var missingWidthOrHeight = (!newLayout.width || !newLayout.height),
  49620. autosize = newFullLayout.autosize,
  49621. autosizable = context.autosizable,
  49622. initialAutoSize = missingWidthOrHeight && (autosize || autosizable);
  49623. if(initialAutoSize) plots.plotAutoSize(gd, newLayout, newFullLayout);
  49624. else if(missingWidthOrHeight) plots.sanitizeMargins(newFullLayout);
  49625. // for backwards-compatibility with Plotly v1.x.x
  49626. if(!autosize && missingWidthOrHeight) {
  49627. newLayout.width = newFullLayout.width;
  49628. newLayout.height = newFullLayout.height;
  49629. }
  49630. }
  49631. newFullLayout._d3locale = getFormatter(formatObj, newFullLayout.separators);
  49632. newFullLayout._extraFormat = getFormatObj(gd, extraFormatKeys);
  49633. newFullLayout._initialAutoSizeIsDone = true;
  49634. // keep track of how many traces are inputted
  49635. newFullLayout._dataLength = newData.length;
  49636. // clear the lists of trace and baseplot modules, and subplots
  49637. newFullLayout._modules = [];
  49638. newFullLayout._visibleModules = [];
  49639. newFullLayout._basePlotModules = [];
  49640. var subplots = newFullLayout._subplots = emptySubplotLists();
  49641. // initialize axis and subplot hash objects for splom-generated grids
  49642. var splomAxes = newFullLayout._splomAxes = {x: {}, y: {}};
  49643. var splomSubplots = newFullLayout._splomSubplots = {};
  49644. // initialize splom grid defaults
  49645. newFullLayout._splomGridDflt = {};
  49646. // for stacked area traces to share config across traces
  49647. newFullLayout._scatterStackOpts = {};
  49648. // for the first scatter trace on each subplot (so it knows tonext->tozero)
  49649. newFullLayout._firstScatter = {};
  49650. // for traces to request a default rangeslider on their x axes
  49651. // eg set `_requestRangeslider.x2 = true` for xaxis2
  49652. newFullLayout._requestRangeslider = {};
  49653. // pull uids from old data to use as new defaults
  49654. newFullLayout._traceUids = getTraceUids(oldFullData, newData);
  49655. // then do the data
  49656. newFullLayout._globalTransforms = (gd._context || {}).globalTransforms;
  49657. plots.supplyDataDefaults(newData, newFullData, newLayout, newFullLayout);
  49658. // redo grid size defaults with info about splom x/y axes,
  49659. // and fill in generated cartesian axes and subplots
  49660. var splomXa = Object.keys(splomAxes.x);
  49661. var splomYa = Object.keys(splomAxes.y);
  49662. if(splomXa.length > 1 && splomYa.length > 1) {
  49663. Registry.getComponentMethod('grid', 'sizeDefaults')(newLayout, newFullLayout);
  49664. for(i = 0; i < splomXa.length; i++) {
  49665. Lib.pushUnique(subplots.xaxis, splomXa[i]);
  49666. }
  49667. for(i = 0; i < splomYa.length; i++) {
  49668. Lib.pushUnique(subplots.yaxis, splomYa[i]);
  49669. }
  49670. for(var k in splomSubplots) {
  49671. Lib.pushUnique(subplots.cartesian, k);
  49672. }
  49673. }
  49674. // attach helper method to check whether a plot type is present on graph
  49675. newFullLayout._has = plots._hasPlotType.bind(newFullLayout);
  49676. // special cases that introduce interactions between traces
  49677. var _modules = newFullLayout._visibleModules;
  49678. for(i = 0; i < _modules.length; i++) {
  49679. var _module = _modules[i];
  49680. if(_module.cleanData) _module.cleanData(newFullData);
  49681. }
  49682. if(oldFullData.length === newFullData.length) {
  49683. for(i = 0; i < newFullData.length; i++) {
  49684. relinkPrivateKeys(newFullData[i], oldFullData[i]);
  49685. }
  49686. }
  49687. // finally, fill in the pieces of layout that may need to look at data
  49688. plots.supplyLayoutModuleDefaults(newLayout, newFullLayout, newFullData, gd._transitionData);
  49689. // turn on flag to optimize large splom-only graphs
  49690. // mostly by omitting SVG layers during Cartesian.drawFramework
  49691. newFullLayout._hasOnlyLargeSploms = (
  49692. newFullLayout._basePlotModules.length === 1 &&
  49693. newFullLayout._basePlotModules[0].name === 'splom' &&
  49694. splomXa.length > 15 &&
  49695. splomYa.length > 15 &&
  49696. newFullLayout.shapes.length === 0 &&
  49697. newFullLayout.images.length === 0
  49698. );
  49699. // TODO remove in v2.0.0
  49700. // add has-plot-type refs to fullLayout for backward compatibility
  49701. newFullLayout._hasCartesian = newFullLayout._has('cartesian');
  49702. newFullLayout._hasGeo = newFullLayout._has('geo');
  49703. newFullLayout._hasGL3D = newFullLayout._has('gl3d');
  49704. newFullLayout._hasGL2D = newFullLayout._has('gl2d');
  49705. newFullLayout._hasTernary = newFullLayout._has('ternary');
  49706. newFullLayout._hasPie = newFullLayout._has('pie');
  49707. // relink / initialize subplot axis objects
  49708. plots.linkSubplots(newFullData, newFullLayout, oldFullData, oldFullLayout);
  49709. // clean subplots and other artifacts from previous plot calls
  49710. plots.cleanPlot(newFullData, newFullLayout, oldFullData, oldFullLayout, oldCalcdata);
  49711. // relink functions and _ attributes to promote consistency between plots
  49712. relinkPrivateKeys(newFullLayout, oldFullLayout);
  49713. // TODO may return a promise
  49714. plots.doAutoMargin(gd);
  49715. // set scale after auto margin routine
  49716. var axList = axisIDs.list(gd);
  49717. for(i = 0; i < axList.length; i++) {
  49718. var ax = axList[i];
  49719. ax.setScale();
  49720. }
  49721. // update object references in calcdata
  49722. if(!skipUpdateCalc && oldCalcdata.length === newFullData.length) {
  49723. plots.supplyDefaultsUpdateCalc(oldCalcdata, newFullData);
  49724. }
  49725. // sort base plot modules for consistent ordering
  49726. newFullLayout._basePlotModules.sort(sortBasePlotModules);
  49727. };
  49728. plots.supplyDefaultsUpdateCalc = function(oldCalcdata, newFullData) {
  49729. for(var i = 0; i < newFullData.length; i++) {
  49730. var newTrace = newFullData[i];
  49731. var cd0 = oldCalcdata[i][0];
  49732. if(cd0 && cd0.trace) {
  49733. var oldTrace = cd0.trace;
  49734. if(oldTrace._hasCalcTransform) {
  49735. var arrayAttrs = oldTrace._arrayAttrs;
  49736. var j, astr, oldArrayVal;
  49737. for(j = 0; j < arrayAttrs.length; j++) {
  49738. astr = arrayAttrs[j];
  49739. oldArrayVal = Lib.nestedProperty(oldTrace, astr).get().slice();
  49740. Lib.nestedProperty(newTrace, astr).set(oldArrayVal);
  49741. }
  49742. }
  49743. cd0.trace = newTrace;
  49744. }
  49745. }
  49746. };
  49747. /**
  49748. * Create a list of uid strings satisfying (in this order of importance):
  49749. * 1. all unique, all strings
  49750. * 2. matches input uids if provided
  49751. * 3. matches previous data uids
  49752. */
  49753. function getTraceUids(oldFullData, newData) {
  49754. var len = newData.length;
  49755. var oldFullInput = [];
  49756. var i, prevFullInput;
  49757. for(i = 0; i < oldFullData.length; i++) {
  49758. var thisFullInput = oldFullData[i]._fullInput;
  49759. if(thisFullInput !== prevFullInput) oldFullInput.push(thisFullInput);
  49760. prevFullInput = thisFullInput;
  49761. }
  49762. var oldLen = oldFullInput.length;
  49763. var out = new Array(len);
  49764. var seenUids = {};
  49765. function setUid(uid, i) {
  49766. out[i] = uid;
  49767. seenUids[uid] = 1;
  49768. }
  49769. function tryUid(uid, i) {
  49770. if(uid && typeof uid === 'string' && !seenUids[uid]) {
  49771. setUid(uid, i);
  49772. return true;
  49773. }
  49774. }
  49775. for(i = 0; i < len; i++) {
  49776. if(tryUid(newData[i].uid, i)) continue;
  49777. if(i < oldLen && tryUid(oldFullInput[i].uid, i)) continue;
  49778. setUid(Lib.randstr(seenUids), i);
  49779. }
  49780. return out;
  49781. }
  49782. /**
  49783. * Make a container for collecting subplots we need to display.
  49784. *
  49785. * Finds all subplot types we need to enumerate once and caches it,
  49786. * but makes a new output object each time.
  49787. * Single-trace subplots (which have no `id`) such as pie, table, etc
  49788. * do not need to be collected because we just draw all visible traces.
  49789. */
  49790. var collectableSubplotTypes;
  49791. function emptySubplotLists() {
  49792. var out = {};
  49793. var i, j;
  49794. if(!collectableSubplotTypes) {
  49795. collectableSubplotTypes = [];
  49796. var subplotsRegistry = Registry.subplotsRegistry;
  49797. for(var subplotType in subplotsRegistry) {
  49798. var subplotModule = subplotsRegistry[subplotType];
  49799. var subplotAttr = subplotModule.attr;
  49800. if(subplotAttr) {
  49801. collectableSubplotTypes.push(subplotType);
  49802. // special case, currently just for cartesian:
  49803. // we need to enumerate axes, not just subplots
  49804. if(Array.isArray(subplotAttr)) {
  49805. for(j = 0; j < subplotAttr.length; j++) {
  49806. Lib.pushUnique(collectableSubplotTypes, subplotAttr[j]);
  49807. }
  49808. }
  49809. }
  49810. }
  49811. }
  49812. for(i = 0; i < collectableSubplotTypes.length; i++) {
  49813. out[collectableSubplotTypes[i]] = [];
  49814. }
  49815. return out;
  49816. }
  49817. /**
  49818. * getFormatObj: use _context to get the format object from locale.
  49819. * Used to get d3.locale argument object and extraFormat argument object
  49820. *
  49821. * Regarding d3.locale argument :
  49822. * decimal and thousands can be overridden later by layout.separators
  49823. * grouping and currency are not presently used by our automatic number
  49824. * formatting system but can be used by custom formats.
  49825. *
  49826. * @returns {object} d3.locale format object
  49827. */
  49828. function getFormatObj(gd, formatKeys) {
  49829. var locale = gd._context.locale;
  49830. if(!locale) locale === 'en-US';
  49831. var formatDone = false;
  49832. var formatObj = {};
  49833. function includeFormat(newFormat) {
  49834. var formatFinished = true;
  49835. for(var i = 0; i < formatKeys.length; i++) {
  49836. var formatKey = formatKeys[i];
  49837. if(!formatObj[formatKey]) {
  49838. if(newFormat[formatKey]) {
  49839. formatObj[formatKey] = newFormat[formatKey];
  49840. }
  49841. else formatFinished = false;
  49842. }
  49843. }
  49844. if(formatFinished) formatDone = true;
  49845. }
  49846. // same as localize, look for format parts in each format spec in the chain
  49847. for(var i = 0; i < 2; i++) {
  49848. var locales = gd._context.locales;
  49849. for(var j = 0; j < 2; j++) {
  49850. var formatj = (locales[locale] || {}).format;
  49851. if(formatj) {
  49852. includeFormat(formatj);
  49853. if(formatDone) break;
  49854. }
  49855. locales = Registry.localeRegistry;
  49856. }
  49857. var baseLocale = locale.split('-')[0];
  49858. if(formatDone || baseLocale === locale) break;
  49859. locale = baseLocale;
  49860. }
  49861. // lastly pick out defaults from english (non-US, as DMY is so much more common)
  49862. if(!formatDone) includeFormat(Registry.localeRegistry.en.format);
  49863. return formatObj;
  49864. }
  49865. /**
  49866. * getFormatter: combine the final separators with the locale formatting object
  49867. * we pulled earlier to generate number and time formatters
  49868. * TODO: remove separators in v2, only use locale, so we don't need this step?
  49869. *
  49870. * @param {object} formatObj: d3.locale format object
  49871. * @param {string} separators: length-2 string to override decimal and thousands
  49872. * separators in number formatting
  49873. *
  49874. * @returns {object} {numberFormat, timeFormat} d3 formatter factory functions
  49875. * for numbers and time
  49876. */
  49877. function getFormatter(formatObj, separators) {
  49878. formatObj.decimal = separators.charAt(0);
  49879. formatObj.thousands = separators.charAt(1);
  49880. return d3.locale(formatObj);
  49881. }
  49882. // Create storage for all of the data related to frames and transitions:
  49883. plots.createTransitionData = function(gd) {
  49884. // Set up the default keyframe if it doesn't exist:
  49885. if(!gd._transitionData) {
  49886. gd._transitionData = {};
  49887. }
  49888. if(!gd._transitionData._frames) {
  49889. gd._transitionData._frames = [];
  49890. }
  49891. if(!gd._transitionData._frameHash) {
  49892. gd._transitionData._frameHash = {};
  49893. }
  49894. if(!gd._transitionData._counter) {
  49895. gd._transitionData._counter = 0;
  49896. }
  49897. if(!gd._transitionData._interruptCallbacks) {
  49898. gd._transitionData._interruptCallbacks = [];
  49899. }
  49900. };
  49901. // helper function to be bound to fullLayout to check
  49902. // whether a certain plot type is present on plot
  49903. // or trace has a category
  49904. plots._hasPlotType = function(category) {
  49905. var i;
  49906. // check base plot modules
  49907. var basePlotModules = this._basePlotModules || [];
  49908. for(i = 0; i < basePlotModules.length; i++) {
  49909. if(basePlotModules[i].name === category) return true;
  49910. }
  49911. // check trace modules (including non-visible:true)
  49912. var modules = this._modules || [];
  49913. for(i = 0; i < modules.length; i++) {
  49914. var name = modules[i].name;
  49915. if(name === category) return true;
  49916. // N.B. this is modules[i] along with 'categories' as a hash object
  49917. var _module = Registry.modules[name];
  49918. if(_module && _module.categories[category]) return true;
  49919. }
  49920. return false;
  49921. };
  49922. plots.cleanPlot = function(newFullData, newFullLayout, oldFullData, oldFullLayout, oldCalcdata) {
  49923. var i, j;
  49924. var basePlotModules = oldFullLayout._basePlotModules || [];
  49925. for(i = 0; i < basePlotModules.length; i++) {
  49926. var _module = basePlotModules[i];
  49927. if(_module.clean) {
  49928. _module.clean(newFullData, newFullLayout, oldFullData, oldFullLayout, oldCalcdata);
  49929. }
  49930. }
  49931. var hadGl = oldFullLayout._has && oldFullLayout._has('gl');
  49932. var hasGl = newFullLayout._has && newFullLayout._has('gl');
  49933. if(hadGl && !hasGl) {
  49934. if(oldFullLayout._glcontainer !== undefined) {
  49935. oldFullLayout._glcontainer.selectAll('.gl-canvas').remove();
  49936. oldFullLayout._glcontainer.selectAll('.no-webgl').remove();
  49937. oldFullLayout._glcanvas = null;
  49938. }
  49939. }
  49940. var hasInfoLayer = !!oldFullLayout._infolayer;
  49941. oldLoop:
  49942. for(i = 0; i < oldFullData.length; i++) {
  49943. var oldTrace = oldFullData[i],
  49944. oldUid = oldTrace.uid;
  49945. for(j = 0; j < newFullData.length; j++) {
  49946. var newTrace = newFullData[j];
  49947. if(oldUid === newTrace.uid) continue oldLoop;
  49948. }
  49949. // clean old colorbars
  49950. if(hasInfoLayer) {
  49951. oldFullLayout._infolayer.select('.cb' + oldUid).remove();
  49952. }
  49953. }
  49954. if(oldFullLayout._zoomlayer) {
  49955. oldFullLayout._zoomlayer.selectAll('.select-outline').remove();
  49956. }
  49957. };
  49958. plots.linkSubplots = function(newFullData, newFullLayout, oldFullData, oldFullLayout) {
  49959. var i, j;
  49960. var oldSubplots = oldFullLayout._plots || {};
  49961. var newSubplots = newFullLayout._plots = {};
  49962. var newSubplotList = newFullLayout._subplots;
  49963. var mockGd = {
  49964. _fullData: newFullData,
  49965. _fullLayout: newFullLayout
  49966. };
  49967. var ids = newSubplotList.cartesian.concat(newSubplotList.gl2d || []);
  49968. for(i = 0; i < ids.length; i++) {
  49969. var id = ids[i];
  49970. var oldSubplot = oldSubplots[id];
  49971. var xaxis = axisIDs.getFromId(mockGd, id, 'x');
  49972. var yaxis = axisIDs.getFromId(mockGd, id, 'y');
  49973. var plotinfo;
  49974. // link or create subplot object
  49975. if(oldSubplot) {
  49976. plotinfo = newSubplots[id] = oldSubplot;
  49977. } else {
  49978. plotinfo = newSubplots[id] = {};
  49979. plotinfo.id = id;
  49980. }
  49981. // update x and y axis layout object refs
  49982. plotinfo.xaxis = xaxis;
  49983. plotinfo.yaxis = yaxis;
  49984. // By default, we clip at the subplot level,
  49985. // but if one trace on a given subplot has *cliponaxis* set to false,
  49986. // we need to clip at the trace module layer level;
  49987. // find this out here, once of for all.
  49988. plotinfo._hasClipOnAxisFalse = false;
  49989. for(j = 0; j < newFullData.length; j++) {
  49990. var trace = newFullData[j];
  49991. if(
  49992. trace.xaxis === plotinfo.xaxis._id &&
  49993. trace.yaxis === plotinfo.yaxis._id &&
  49994. trace.cliponaxis === false
  49995. ) {
  49996. plotinfo._hasClipOnAxisFalse = true;
  49997. break;
  49998. }
  49999. }
  50000. }
  50001. // while we're at it, link overlaying axes to their main axes and
  50002. // anchored axes to the axes they're anchored to
  50003. var axList = axisIDs.list(mockGd, null, true);
  50004. for(i = 0; i < axList.length; i++) {
  50005. var ax = axList[i];
  50006. var mainAx = null;
  50007. if(ax.overlaying) {
  50008. mainAx = axisIDs.getFromId(mockGd, ax.overlaying);
  50009. // you cannot overlay an axis that's already overlaying another
  50010. if(mainAx && mainAx.overlaying) {
  50011. ax.overlaying = false;
  50012. mainAx = null;
  50013. }
  50014. }
  50015. ax._mainAxis = mainAx || ax;
  50016. /*
  50017. * For now force overlays to overlay completely... so they
  50018. * can drag together correctly and share backgrounds.
  50019. * Later perhaps we make separate axis domain and
  50020. * tick/line domain or something, so they can still share
  50021. * the (possibly larger) dragger and background but don't
  50022. * have to both be drawn over that whole domain
  50023. */
  50024. if(mainAx) ax.domain = mainAx.domain.slice();
  50025. ax._anchorAxis = ax.anchor === 'free' ?
  50026. null :
  50027. axisIDs.getFromId(mockGd, ax.anchor);
  50028. }
  50029. };
  50030. // This function clears any trace attributes with valType: color and
  50031. // no set dflt filed in the plot schema. This is needed because groupby (which
  50032. // is the only transform for which this currently applies) supplies parent
  50033. // trace defaults, then expanded trace defaults. The result is that `null`
  50034. // colors are default-supplied and inherited as a color instead of a null.
  50035. // The result is that expanded trace default colors have no effect, with
  50036. // the final result that groups are indistinguishable. This function clears
  50037. // those colors so that individual groupby groups get unique colors.
  50038. plots.clearExpandedTraceDefaultColors = function(trace) {
  50039. var colorAttrs, path, i;
  50040. // This uses weird closure state in order to satisfy the linter rule
  50041. // that we can't create functions in a loop.
  50042. function locateColorAttrs(attr, attrName, attrs, level) {
  50043. path[level] = attrName;
  50044. path.length = level + 1;
  50045. if(attr.valType === 'color' && attr.dflt === undefined) {
  50046. colorAttrs.push(path.join('.'));
  50047. }
  50048. }
  50049. path = [];
  50050. // Get the cached colorAttrs:
  50051. colorAttrs = trace._module._colorAttrs;
  50052. // Or else compute and cache the colorAttrs on the module:
  50053. if(!colorAttrs) {
  50054. trace._module._colorAttrs = colorAttrs = [];
  50055. PlotSchema.crawl(
  50056. trace._module.attributes,
  50057. locateColorAttrs
  50058. );
  50059. }
  50060. for(i = 0; i < colorAttrs.length; i++) {
  50061. var origprop = Lib.nestedProperty(trace, '_input.' + colorAttrs[i]);
  50062. if(!origprop.get()) {
  50063. Lib.nestedProperty(trace, colorAttrs[i]).set(null);
  50064. }
  50065. }
  50066. };
  50067. plots.supplyDataDefaults = function(dataIn, dataOut, layout, fullLayout) {
  50068. var modules = fullLayout._modules;
  50069. var visibleModules = fullLayout._visibleModules;
  50070. var basePlotModules = fullLayout._basePlotModules;
  50071. var cnt = 0;
  50072. var colorCnt = 0;
  50073. var i, fullTrace, trace;
  50074. fullLayout._transformModules = [];
  50075. function pushModule(fullTrace) {
  50076. dataOut.push(fullTrace);
  50077. var _module = fullTrace._module;
  50078. if(!_module) return;
  50079. Lib.pushUnique(modules, _module);
  50080. if(fullTrace.visible === true) Lib.pushUnique(visibleModules, _module);
  50081. Lib.pushUnique(basePlotModules, fullTrace._module.basePlotModule);
  50082. cnt++;
  50083. // TODO: do we really want color not to increment for explicitly invisible traces?
  50084. // This logic is weird, but matches previous behavior: traces that you explicitly
  50085. // set to visible:false do not increment the color, but traces WE determine to be
  50086. // empty or invalid (and thus set to visible:false) DO increment color.
  50087. // I kind of think we should just let all traces increment color, visible or not.
  50088. // see mock: axes-autotype-empty vs. a test of restyling visible: false that
  50089. // I can't find right now...
  50090. if(fullTrace._input.visible !== false) colorCnt++;
  50091. }
  50092. var carpetIndex = {};
  50093. var carpetDependents = [];
  50094. var dataTemplate = (layout.template || {}).data || {};
  50095. var templater = Template.traceTemplater(dataTemplate);
  50096. for(i = 0; i < dataIn.length; i++) {
  50097. trace = dataIn[i];
  50098. // reuse uid we may have pulled out of oldFullData
  50099. // Note: templater supplies trace type
  50100. fullTrace = templater.newTrace(trace);
  50101. fullTrace.uid = fullLayout._traceUids[i];
  50102. plots.supplyTraceDefaults(trace, fullTrace, colorCnt, fullLayout, i);
  50103. fullTrace.index = i;
  50104. fullTrace._input = trace;
  50105. fullTrace._expandedIndex = cnt;
  50106. if(fullTrace.transforms && fullTrace.transforms.length) {
  50107. var expandedTraces = applyTransforms(fullTrace, dataOut, layout, fullLayout);
  50108. for(var j = 0; j < expandedTraces.length; j++) {
  50109. var expandedTrace = expandedTraces[j];
  50110. // No further templating during transforms.
  50111. var fullExpandedTrace = {
  50112. _template: fullTrace._template,
  50113. type: fullTrace.type,
  50114. // set uid using parent uid and expanded index
  50115. // to promote consistency between update calls
  50116. uid: fullTrace.uid + j
  50117. };
  50118. plots.supplyTraceDefaults(expandedTrace, fullExpandedTrace, cnt, fullLayout, i);
  50119. // relink private (i.e. underscore) keys expanded trace to full expanded trace so
  50120. // that transform supply-default methods can set _ keys for future use.
  50121. relinkPrivateKeys(fullExpandedTrace, expandedTrace);
  50122. // add info about parent data trace
  50123. fullExpandedTrace.index = i;
  50124. fullExpandedTrace._input = trace;
  50125. fullExpandedTrace._fullInput = fullTrace;
  50126. // add info about the expanded data
  50127. fullExpandedTrace._expandedIndex = cnt;
  50128. fullExpandedTrace._expandedInput = expandedTrace;
  50129. pushModule(fullExpandedTrace);
  50130. }
  50131. }
  50132. else {
  50133. // add identify refs for consistency with transformed traces
  50134. fullTrace._fullInput = fullTrace;
  50135. fullTrace._expandedInput = fullTrace;
  50136. pushModule(fullTrace);
  50137. }
  50138. if(Registry.traceIs(fullTrace, 'carpetAxis')) {
  50139. carpetIndex[fullTrace.carpet] = fullTrace;
  50140. }
  50141. if(Registry.traceIs(fullTrace, 'carpetDependent')) {
  50142. carpetDependents.push(i);
  50143. }
  50144. }
  50145. for(i = 0; i < carpetDependents.length; i++) {
  50146. fullTrace = dataOut[carpetDependents[i]];
  50147. if(!fullTrace.visible) continue;
  50148. var carpetAxis = carpetIndex[fullTrace.carpet];
  50149. fullTrace._carpet = carpetAxis;
  50150. if(!carpetAxis || !carpetAxis.visible) {
  50151. fullTrace.visible = false;
  50152. continue;
  50153. }
  50154. fullTrace.xaxis = carpetAxis.xaxis;
  50155. fullTrace.yaxis = carpetAxis.yaxis;
  50156. }
  50157. };
  50158. plots.supplyAnimationDefaults = function(opts) {
  50159. opts = opts || {};
  50160. var i;
  50161. var optsOut = {};
  50162. function coerce(attr, dflt) {
  50163. return Lib.coerce(opts || {}, optsOut, animationAttrs, attr, dflt);
  50164. }
  50165. coerce('mode');
  50166. coerce('direction');
  50167. coerce('fromcurrent');
  50168. if(Array.isArray(opts.frame)) {
  50169. optsOut.frame = [];
  50170. for(i = 0; i < opts.frame.length; i++) {
  50171. optsOut.frame[i] = plots.supplyAnimationFrameDefaults(opts.frame[i] || {});
  50172. }
  50173. } else {
  50174. optsOut.frame = plots.supplyAnimationFrameDefaults(opts.frame || {});
  50175. }
  50176. if(Array.isArray(opts.transition)) {
  50177. optsOut.transition = [];
  50178. for(i = 0; i < opts.transition.length; i++) {
  50179. optsOut.transition[i] = plots.supplyAnimationTransitionDefaults(opts.transition[i] || {});
  50180. }
  50181. } else {
  50182. optsOut.transition = plots.supplyAnimationTransitionDefaults(opts.transition || {});
  50183. }
  50184. return optsOut;
  50185. };
  50186. plots.supplyAnimationFrameDefaults = function(opts) {
  50187. var optsOut = {};
  50188. function coerce(attr, dflt) {
  50189. return Lib.coerce(opts || {}, optsOut, animationAttrs.frame, attr, dflt);
  50190. }
  50191. coerce('duration');
  50192. coerce('redraw');
  50193. return optsOut;
  50194. };
  50195. plots.supplyAnimationTransitionDefaults = function(opts) {
  50196. var optsOut = {};
  50197. function coerce(attr, dflt) {
  50198. return Lib.coerce(opts || {}, optsOut, animationAttrs.transition, attr, dflt);
  50199. }
  50200. coerce('duration');
  50201. coerce('easing');
  50202. return optsOut;
  50203. };
  50204. plots.supplyFrameDefaults = function(frameIn) {
  50205. var frameOut = {};
  50206. function coerce(attr, dflt) {
  50207. return Lib.coerce(frameIn, frameOut, frameAttrs, attr, dflt);
  50208. }
  50209. coerce('group');
  50210. coerce('name');
  50211. coerce('traces');
  50212. coerce('baseframe');
  50213. coerce('data');
  50214. coerce('layout');
  50215. return frameOut;
  50216. };
  50217. plots.supplyTraceDefaults = function(traceIn, traceOut, colorIndex, layout, traceInIndex) {
  50218. var colorway = layout.colorway || Color.defaults;
  50219. var defaultColor = colorway[colorIndex % colorway.length];
  50220. var i;
  50221. function coerce(attr, dflt) {
  50222. return Lib.coerce(traceIn, traceOut, plots.attributes, attr, dflt);
  50223. }
  50224. var visible = coerce('visible');
  50225. coerce('type');
  50226. coerce('name', layout._traceWord + ' ' + traceInIndex);
  50227. // we want even invisible traces to make their would-be subplots visible
  50228. // so coerce the subplot id(s) now no matter what
  50229. var _module = plots.getModule(traceOut);
  50230. traceOut._module = _module;
  50231. if(_module) {
  50232. var basePlotModule = _module.basePlotModule;
  50233. var subplotAttr = basePlotModule.attr;
  50234. var subplotAttrs = basePlotModule.attributes;
  50235. if(subplotAttr && subplotAttrs) {
  50236. var subplots = layout._subplots;
  50237. var subplotId = '';
  50238. // TODO - currently if we draw an empty gl2d subplot, it draws
  50239. // nothing then gets stuck and you can't get it back without newPlot
  50240. // sort this out in the regl refactor? but for now just drop empty gl2d subplots
  50241. if(basePlotModule.name !== 'gl2d' || visible) {
  50242. if(Array.isArray(subplotAttr)) {
  50243. for(i = 0; i < subplotAttr.length; i++) {
  50244. var attri = subplotAttr[i];
  50245. var vali = Lib.coerce(traceIn, traceOut, subplotAttrs, attri);
  50246. if(subplots[attri]) Lib.pushUnique(subplots[attri], vali);
  50247. subplotId += vali;
  50248. }
  50249. }
  50250. else {
  50251. subplotId = Lib.coerce(traceIn, traceOut, subplotAttrs, subplotAttr);
  50252. }
  50253. if(subplots[basePlotModule.name]) {
  50254. Lib.pushUnique(subplots[basePlotModule.name], subplotId);
  50255. }
  50256. }
  50257. }
  50258. }
  50259. if(visible) {
  50260. coerce('customdata');
  50261. coerce('ids');
  50262. if(Registry.traceIs(traceOut, 'showLegend')) {
  50263. traceOut._dfltShowLegend = true;
  50264. coerce('showlegend');
  50265. coerce('legendgroup');
  50266. }
  50267. else {
  50268. traceOut._dfltShowLegend = false;
  50269. }
  50270. Registry.getComponentMethod(
  50271. 'fx',
  50272. 'supplyDefaults'
  50273. )(traceIn, traceOut, defaultColor, layout);
  50274. // TODO add per-base-plot-module trace defaults step
  50275. if(_module) {
  50276. _module.supplyDefaults(traceIn, traceOut, defaultColor, layout);
  50277. Lib.coerceHoverinfo(traceIn, traceOut, layout);
  50278. }
  50279. if(!Registry.traceIs(traceOut, 'noOpacity')) coerce('opacity');
  50280. if(Registry.traceIs(traceOut, 'notLegendIsolatable')) {
  50281. // This clears out the legendonly state for traces like carpet that
  50282. // cannot be isolated in the legend
  50283. traceOut.visible = !!traceOut.visible;
  50284. }
  50285. if(_module && _module.selectPoints) {
  50286. coerce('selectedpoints');
  50287. }
  50288. plots.supplyTransformDefaults(traceIn, traceOut, layout);
  50289. }
  50290. return traceOut;
  50291. };
  50292. /**
  50293. * hasMakesDataTransform: does this trace have a transform that makes its own
  50294. * data, either by grabbing it from somewhere else or by creating it from input
  50295. * parameters? If so, we should still keep going with supplyDefaults
  50296. * even if the trace is invisible, which may just be because it has no data yet.
  50297. */
  50298. function hasMakesDataTransform(trace) {
  50299. var transforms = trace.transforms;
  50300. if(Array.isArray(transforms) && transforms.length) {
  50301. for(var i = 0; i < transforms.length; i++) {
  50302. var ti = transforms[i];
  50303. var _module = ti._module || transformsRegistry[ti.type];
  50304. if(_module && _module.makesData) return true;
  50305. }
  50306. }
  50307. return false;
  50308. }
  50309. plots.hasMakesDataTransform = hasMakesDataTransform;
  50310. plots.supplyTransformDefaults = function(traceIn, traceOut, layout) {
  50311. // For now we only allow transforms on 1D traces, ie those that specify a _length.
  50312. // If we were to implement 2D transforms, we'd need to have each transform
  50313. // describe its own applicability and disable itself when it doesn't apply.
  50314. // Also allow transforms that make their own data, but not in globalTransforms
  50315. if(!(traceOut._length || hasMakesDataTransform(traceIn))) return;
  50316. var globalTransforms = layout._globalTransforms || [];
  50317. var transformModules = layout._transformModules || [];
  50318. if(!Array.isArray(traceIn.transforms) && globalTransforms.length === 0) return;
  50319. var containerIn = traceIn.transforms || [],
  50320. transformList = globalTransforms.concat(containerIn),
  50321. containerOut = traceOut.transforms = [];
  50322. for(var i = 0; i < transformList.length; i++) {
  50323. var transformIn = transformList[i],
  50324. type = transformIn.type,
  50325. _module = transformsRegistry[type],
  50326. transformOut;
  50327. /*
  50328. * Supply defaults may run twice. First pass runs all supply defaults steps
  50329. * and adds the _module to any output transforms.
  50330. * If transforms exist another pass is run so that any generated traces also
  50331. * go through supply defaults. This has the effect of rerunning
  50332. * supplyTransformDefaults. If the transform does not have a `transform`
  50333. * function it could not have generated any new traces and the second stage
  50334. * is unnecessary. We detect this case with the following variables.
  50335. */
  50336. var isFirstStage = !(transformIn._module && transformIn._module === _module),
  50337. doLaterStages = _module && typeof _module.transform === 'function';
  50338. if(!_module) Lib.warn('Unrecognized transform type ' + type + '.');
  50339. if(_module && _module.supplyDefaults && (isFirstStage || doLaterStages)) {
  50340. transformOut = _module.supplyDefaults(transformIn, traceOut, layout, traceIn);
  50341. transformOut.type = type;
  50342. transformOut._module = _module;
  50343. Lib.pushUnique(transformModules, _module);
  50344. }
  50345. else {
  50346. transformOut = Lib.extendFlat({}, transformIn);
  50347. }
  50348. containerOut.push(transformOut);
  50349. }
  50350. };
  50351. function applyTransforms(fullTrace, fullData, layout, fullLayout) {
  50352. var container = fullTrace.transforms,
  50353. dataOut = [fullTrace];
  50354. for(var i = 0; i < container.length; i++) {
  50355. var transform = container[i],
  50356. _module = transformsRegistry[transform.type];
  50357. if(_module && _module.transform) {
  50358. dataOut = _module.transform(dataOut, {
  50359. transform: transform,
  50360. fullTrace: fullTrace,
  50361. fullData: fullData,
  50362. layout: layout,
  50363. fullLayout: fullLayout,
  50364. transformIndex: i
  50365. });
  50366. }
  50367. }
  50368. return dataOut;
  50369. }
  50370. plots.supplyLayoutGlobalDefaults = function(layoutIn, layoutOut, formatObj) {
  50371. function coerce(attr, dflt) {
  50372. return Lib.coerce(layoutIn, layoutOut, plots.layoutAttributes, attr, dflt);
  50373. }
  50374. var template = layoutIn.template;
  50375. if(Lib.isPlainObject(template)) {
  50376. layoutOut.template = template;
  50377. layoutOut._template = template.layout;
  50378. layoutOut._dataTemplate = template.data;
  50379. }
  50380. var globalFont = Lib.coerceFont(coerce, 'font');
  50381. coerce('title', layoutOut._dfltTitle.plot);
  50382. Lib.coerceFont(coerce, 'titlefont', {
  50383. family: globalFont.family,
  50384. size: Math.round(globalFont.size * 1.4),
  50385. color: globalFont.color
  50386. });
  50387. // Make sure that autosize is defaulted to *true*
  50388. // on layouts with no set width and height for backward compatibly,
  50389. // in particular https://plot.ly/javascript/responsive-fluid-layout/
  50390. //
  50391. // Before https://github.com/plotly/plotly.js/pull/635 ,
  50392. // layouts with no set width and height were set temporary set to 'initial'
  50393. // to pass through the autosize routine
  50394. //
  50395. // This behavior is subject to change in v2.
  50396. coerce('autosize', !(layoutIn.width && layoutIn.height));
  50397. coerce('width');
  50398. coerce('height');
  50399. coerce('margin.l');
  50400. coerce('margin.r');
  50401. coerce('margin.t');
  50402. coerce('margin.b');
  50403. coerce('margin.pad');
  50404. coerce('margin.autoexpand');
  50405. if(layoutIn.width && layoutIn.height) plots.sanitizeMargins(layoutOut);
  50406. Registry.getComponentMethod('grid', 'sizeDefaults')(layoutIn, layoutOut);
  50407. coerce('paper_bgcolor');
  50408. coerce('separators', formatObj.decimal + formatObj.thousands);
  50409. coerce('hidesources');
  50410. coerce('colorway');
  50411. coerce('datarevision');
  50412. Registry.getComponentMethod(
  50413. 'calendars',
  50414. 'handleDefaults'
  50415. )(layoutIn, layoutOut, 'calendar');
  50416. Registry.getComponentMethod(
  50417. 'fx',
  50418. 'supplyLayoutGlobalDefaults'
  50419. )(layoutIn, layoutOut, coerce);
  50420. };
  50421. plots.plotAutoSize = function plotAutoSize(gd, layout, fullLayout) {
  50422. var context = gd._context || {},
  50423. frameMargins = context.frameMargins,
  50424. newWidth,
  50425. newHeight;
  50426. var isPlotDiv = Lib.isPlotDiv(gd);
  50427. if(isPlotDiv) gd.emit('plotly_autosize');
  50428. // embedded in an iframe - just take the full iframe size
  50429. // if we get to this point, with no aspect ratio restrictions
  50430. if(context.fillFrame) {
  50431. newWidth = window.innerWidth;
  50432. newHeight = window.innerHeight;
  50433. // somehow we get a few extra px height sometimes...
  50434. // just hide it
  50435. document.body.style.overflow = 'hidden';
  50436. }
  50437. else if(isNumeric(frameMargins) && frameMargins > 0) {
  50438. var reservedMargins = calculateReservedMargins(gd._boundingBoxMargins),
  50439. reservedWidth = reservedMargins.left + reservedMargins.right,
  50440. reservedHeight = reservedMargins.bottom + reservedMargins.top,
  50441. factor = 1 - 2 * frameMargins;
  50442. var gdBB = fullLayout._container && fullLayout._container.node ?
  50443. fullLayout._container.node().getBoundingClientRect() : {
  50444. width: fullLayout.width,
  50445. height: fullLayout.height
  50446. };
  50447. newWidth = Math.round(factor * (gdBB.width - reservedWidth));
  50448. newHeight = Math.round(factor * (gdBB.height - reservedHeight));
  50449. }
  50450. else {
  50451. // plotly.js - let the developers do what they want, either
  50452. // provide height and width for the container div,
  50453. // specify size in layout, or take the defaults,
  50454. // but don't enforce any ratio restrictions
  50455. var computedStyle = isPlotDiv ? window.getComputedStyle(gd) : {};
  50456. newWidth = parseFloat(computedStyle.width) || parseFloat(computedStyle.maxWidth) || fullLayout.width;
  50457. newHeight = parseFloat(computedStyle.height) || parseFloat(computedStyle.maxHeight) || fullLayout.height;
  50458. }
  50459. var minWidth = plots.layoutAttributes.width.min,
  50460. minHeight = plots.layoutAttributes.height.min;
  50461. if(newWidth < minWidth) newWidth = minWidth;
  50462. if(newHeight < minHeight) newHeight = minHeight;
  50463. var widthHasChanged = !layout.width &&
  50464. (Math.abs(fullLayout.width - newWidth) > 1),
  50465. heightHasChanged = !layout.height &&
  50466. (Math.abs(fullLayout.height - newHeight) > 1);
  50467. if(heightHasChanged || widthHasChanged) {
  50468. if(widthHasChanged) fullLayout.width = newWidth;
  50469. if(heightHasChanged) fullLayout.height = newHeight;
  50470. }
  50471. // cache initial autosize value, used in relayout when
  50472. // width or height values are set to null
  50473. if(!gd._initialAutoSize) {
  50474. gd._initialAutoSize = { width: newWidth, height: newHeight };
  50475. }
  50476. plots.sanitizeMargins(fullLayout);
  50477. };
  50478. /**
  50479. * Reduce all reserved margin objects to a single required margin reservation.
  50480. *
  50481. * @param {Object} margins
  50482. * @returns {{left: number, right: number, bottom: number, top: number}}
  50483. */
  50484. function calculateReservedMargins(margins) {
  50485. var resultingMargin = {left: 0, right: 0, bottom: 0, top: 0},
  50486. marginName;
  50487. if(margins) {
  50488. for(marginName in margins) {
  50489. if(margins.hasOwnProperty(marginName)) {
  50490. resultingMargin.left += margins[marginName].left || 0;
  50491. resultingMargin.right += margins[marginName].right || 0;
  50492. resultingMargin.bottom += margins[marginName].bottom || 0;
  50493. resultingMargin.top += margins[marginName].top || 0;
  50494. }
  50495. }
  50496. }
  50497. return resultingMargin;
  50498. }
  50499. plots.supplyLayoutModuleDefaults = function(layoutIn, layoutOut, fullData, transitionData) {
  50500. var componentsRegistry = Registry.componentsRegistry;
  50501. var basePlotModules = layoutOut._basePlotModules;
  50502. var component, i, _module;
  50503. var Cartesian = Registry.subplotsRegistry.cartesian;
  50504. // check if any components need to add more base plot modules
  50505. // that weren't captured by traces
  50506. for(component in componentsRegistry) {
  50507. _module = componentsRegistry[component];
  50508. if(_module.includeBasePlot) {
  50509. _module.includeBasePlot(layoutIn, layoutOut);
  50510. }
  50511. }
  50512. // make sure we *at least* have some cartesian axes
  50513. if(!basePlotModules.length) {
  50514. basePlotModules.push(Cartesian);
  50515. }
  50516. // ensure all cartesian axes have at least one subplot
  50517. if(layoutOut._has('cartesian')) {
  50518. Registry.getComponentMethod('grid', 'contentDefaults')(layoutIn, layoutOut);
  50519. Cartesian.finalizeSubplots(layoutIn, layoutOut);
  50520. }
  50521. // sort subplot lists
  50522. for(var subplotType in layoutOut._subplots) {
  50523. layoutOut._subplots[subplotType].sort(Lib.subplotSort);
  50524. }
  50525. // base plot module layout defaults
  50526. for(i = 0; i < basePlotModules.length; i++) {
  50527. _module = basePlotModules[i];
  50528. // e.g. pie does not have a layout-defaults step
  50529. if(_module.supplyLayoutDefaults) {
  50530. _module.supplyLayoutDefaults(layoutIn, layoutOut, fullData);
  50531. }
  50532. }
  50533. // trace module layout defaults
  50534. var modules = layoutOut._visibleModules;
  50535. for(i = 0; i < modules.length; i++) {
  50536. _module = modules[i];
  50537. if(_module.supplyLayoutDefaults) {
  50538. _module.supplyLayoutDefaults(layoutIn, layoutOut, fullData);
  50539. }
  50540. }
  50541. // transform module layout defaults
  50542. var transformModules = layoutOut._transformModules;
  50543. for(i = 0; i < transformModules.length; i++) {
  50544. _module = transformModules[i];
  50545. if(_module.supplyLayoutDefaults) {
  50546. _module.supplyLayoutDefaults(layoutIn, layoutOut, fullData, transitionData);
  50547. }
  50548. }
  50549. for(component in componentsRegistry) {
  50550. _module = componentsRegistry[component];
  50551. if(_module.supplyLayoutDefaults) {
  50552. _module.supplyLayoutDefaults(layoutIn, layoutOut, fullData);
  50553. }
  50554. }
  50555. };
  50556. // Remove all plotly attributes from a div so it can be replotted fresh
  50557. // TODO: these really need to be encapsulated into a much smaller set...
  50558. plots.purge = function(gd) {
  50559. // note: we DO NOT remove _context because it doesn't change when we insert
  50560. // a new plot, and may have been set outside of our scope.
  50561. var fullLayout = gd._fullLayout || {};
  50562. if(fullLayout._glcontainer !== undefined) {
  50563. fullLayout._glcontainer.selectAll('.gl-canvas').remove();
  50564. fullLayout._glcontainer.remove();
  50565. fullLayout._glcanvas = null;
  50566. }
  50567. if(fullLayout._geocontainer !== undefined) fullLayout._geocontainer.remove();
  50568. // remove modebar
  50569. if(fullLayout._modeBar) fullLayout._modeBar.destroy();
  50570. if(gd._transitionData) {
  50571. // Ensure any dangling callbacks are simply dropped if the plot is purged.
  50572. // This is more or less only actually important for testing.
  50573. if(gd._transitionData._interruptCallbacks) {
  50574. gd._transitionData._interruptCallbacks.length = 0;
  50575. }
  50576. if(gd._transitionData._animationRaf) {
  50577. window.cancelAnimationFrame(gd._transitionData._animationRaf);
  50578. }
  50579. }
  50580. // remove any planned throttles
  50581. Lib.clearThrottle();
  50582. // remove responsive handler
  50583. Lib.clearResponsive(gd);
  50584. // data and layout
  50585. delete gd.data;
  50586. delete gd.layout;
  50587. delete gd._fullData;
  50588. delete gd._fullLayout;
  50589. delete gd.calcdata;
  50590. delete gd.framework;
  50591. delete gd.empty;
  50592. delete gd.fid;
  50593. delete gd.undoqueue; // action queue
  50594. delete gd.undonum;
  50595. delete gd.autoplay; // are we doing an action that doesn't go in undo queue?
  50596. delete gd.changed;
  50597. // these get recreated on Plotly.plot anyway, but just to be safe
  50598. // (and to have a record of them...)
  50599. delete gd._promises;
  50600. delete gd._redrawTimer;
  50601. delete gd._hmlumcount;
  50602. delete gd._hmpixcount;
  50603. delete gd._transitionData;
  50604. delete gd._transitioning;
  50605. delete gd._initialAutoSize;
  50606. delete gd._transitioningWithDuration;
  50607. // created during certain events, that *should* clean them up
  50608. // themselves, but may not if there was an error
  50609. delete gd._dragging;
  50610. delete gd._dragged;
  50611. delete gd._hoverdata;
  50612. delete gd._snapshotInProgress;
  50613. delete gd._editing;
  50614. delete gd._replotPending;
  50615. delete gd._mouseDownTime;
  50616. delete gd._legendMouseDownTime;
  50617. // remove all event listeners
  50618. if(gd.removeAllListeners) gd.removeAllListeners();
  50619. };
  50620. plots.style = function(gd) {
  50621. var _modules = gd._fullLayout._visibleModules;
  50622. var styleModules = [];
  50623. var i;
  50624. // some trace modules reuse the same style method,
  50625. // make sure to not unnecessary call them multiple times.
  50626. for(i = 0; i < _modules.length; i++) {
  50627. var _module = _modules[i];
  50628. if(_module.style) {
  50629. Lib.pushUnique(styleModules, _module.style);
  50630. }
  50631. }
  50632. for(i = 0; i < styleModules.length; i++) {
  50633. styleModules[i](gd);
  50634. }
  50635. };
  50636. plots.sanitizeMargins = function(fullLayout) {
  50637. // polar doesn't do margins...
  50638. if(!fullLayout || !fullLayout.margin) return;
  50639. var width = fullLayout.width,
  50640. height = fullLayout.height,
  50641. margin = fullLayout.margin,
  50642. plotWidth = width - (margin.l + margin.r),
  50643. plotHeight = height - (margin.t + margin.b),
  50644. correction;
  50645. // if margin.l + margin.r = 0 then plotWidth > 0
  50646. // as width >= 10 by supplyDefaults
  50647. // similarly for margin.t + margin.b
  50648. if(plotWidth < 0) {
  50649. correction = (width - 1) / (margin.l + margin.r);
  50650. margin.l = Math.floor(correction * margin.l);
  50651. margin.r = Math.floor(correction * margin.r);
  50652. }
  50653. if(plotHeight < 0) {
  50654. correction = (height - 1) / (margin.t + margin.b);
  50655. margin.t = Math.floor(correction * margin.t);
  50656. margin.b = Math.floor(correction * margin.b);
  50657. }
  50658. };
  50659. plots.clearAutoMarginIds = function(gd) {
  50660. gd._fullLayout._pushmarginIds = {};
  50661. };
  50662. plots.allowAutoMargin = function(gd, id) {
  50663. gd._fullLayout._pushmarginIds[id] = 1;
  50664. };
  50665. function setupAutoMargin(fullLayout) {
  50666. if(!fullLayout._pushmargin) fullLayout._pushmargin = {};
  50667. if(!fullLayout._pushmarginIds) fullLayout._pushmarginIds = {};
  50668. }
  50669. /**
  50670. * autoMargin: called by components that may need to expand the margins to
  50671. * be rendered on-plot.
  50672. *
  50673. * @param {DOM element} gd
  50674. * @param {string} id - an identifier unique (within this plot) to this object,
  50675. * so we can remove a previous margin expansion from the same object.
  50676. * @param {object} o - the margin requirements of this object, or omit to delete
  50677. * this entry (like if it's hidden). Keys are:
  50678. * x, y: plot fraction of the anchor point.
  50679. * xl, xr, yt, yb: if the object has an extent defined in plot fraction,
  50680. * you can specify both edges as plot fractions in each dimension
  50681. * l, r, t, b: the pixels to pad past the plot fraction x[l|r] and y[t|b]
  50682. * pad: extra pixels to add in all directions, default 12 (why?)
  50683. */
  50684. plots.autoMargin = function(gd, id, o) {
  50685. var fullLayout = gd._fullLayout;
  50686. setupAutoMargin(fullLayout);
  50687. var pushMargin = fullLayout._pushmargin;
  50688. var pushMarginIds = fullLayout._pushmarginIds;
  50689. if(fullLayout.margin.autoexpand !== false) {
  50690. if(!o) {
  50691. delete pushMargin[id];
  50692. delete pushMarginIds[id];
  50693. }
  50694. else {
  50695. var pad = o.pad;
  50696. if(pad === undefined) {
  50697. var margin = fullLayout.margin;
  50698. // if no explicit pad is given, use 12px unless there's a
  50699. // specified margin that's smaller than that
  50700. pad = Math.min(12, margin.l, margin.r, margin.t, margin.b);
  50701. }
  50702. // if the item is too big, just give it enough automargin to
  50703. // make sure you can still grab it and bring it back
  50704. if(o.l + o.r > fullLayout.width * 0.5) o.l = o.r = 0;
  50705. if(o.b + o.t > fullLayout.height * 0.5) o.b = o.t = 0;
  50706. var xl = o.xl !== undefined ? o.xl : o.x;
  50707. var xr = o.xr !== undefined ? o.xr : o.x;
  50708. var yt = o.yt !== undefined ? o.yt : o.y;
  50709. var yb = o.yb !== undefined ? o.yb : o.y;
  50710. pushMargin[id] = {
  50711. l: {val: xl, size: o.l + pad},
  50712. r: {val: xr, size: o.r + pad},
  50713. b: {val: yb, size: o.b + pad},
  50714. t: {val: yt, size: o.t + pad}
  50715. };
  50716. pushMarginIds[id] = 1;
  50717. }
  50718. if(!fullLayout._replotting) plots.doAutoMargin(gd);
  50719. }
  50720. };
  50721. plots.doAutoMargin = function(gd) {
  50722. var fullLayout = gd._fullLayout;
  50723. if(!fullLayout._size) fullLayout._size = {};
  50724. setupAutoMargin(fullLayout);
  50725. var gs = fullLayout._size,
  50726. oldmargins = JSON.stringify(gs);
  50727. // adjust margins for outside components
  50728. // fullLayout.margin is the requested margin,
  50729. // fullLayout._size has margins and plotsize after adjustment
  50730. var ml = Math.max(fullLayout.margin.l || 0, 0);
  50731. var mr = Math.max(fullLayout.margin.r || 0, 0);
  50732. var mt = Math.max(fullLayout.margin.t || 0, 0);
  50733. var mb = Math.max(fullLayout.margin.b || 0, 0);
  50734. var pushMargin = fullLayout._pushmargin;
  50735. var pushMarginIds = fullLayout._pushmarginIds;
  50736. if(fullLayout.margin.autoexpand !== false) {
  50737. for(var k in pushMargin) {
  50738. if(!pushMarginIds[k]) delete pushMargin[k];
  50739. }
  50740. // fill in the requested margins
  50741. pushMargin.base = {
  50742. l: {val: 0, size: ml},
  50743. r: {val: 1, size: mr},
  50744. t: {val: 1, size: mt},
  50745. b: {val: 0, size: mb}
  50746. };
  50747. // now cycle through all the combinations of l and r
  50748. // (and t and b) to find the required margins
  50749. for(var k1 in pushMargin) {
  50750. var pushleft = pushMargin[k1].l || {},
  50751. pushbottom = pushMargin[k1].b || {},
  50752. fl = pushleft.val,
  50753. pl = pushleft.size,
  50754. fb = pushbottom.val,
  50755. pb = pushbottom.size;
  50756. for(var k2 in pushMargin) {
  50757. if(isNumeric(pl) && pushMargin[k2].r) {
  50758. var fr = pushMargin[k2].r.val,
  50759. pr = pushMargin[k2].r.size;
  50760. if(fr > fl) {
  50761. var newl = (pl * fr +
  50762. (pr - fullLayout.width) * fl) / (fr - fl),
  50763. newr = (pr * (1 - fl) +
  50764. (pl - fullLayout.width) * (1 - fr)) / (fr - fl);
  50765. if(newl >= 0 && newr >= 0 && newl + newr > ml + mr) {
  50766. ml = newl;
  50767. mr = newr;
  50768. }
  50769. }
  50770. }
  50771. if(isNumeric(pb) && pushMargin[k2].t) {
  50772. var ft = pushMargin[k2].t.val,
  50773. pt = pushMargin[k2].t.size;
  50774. if(ft > fb) {
  50775. var newb = (pb * ft +
  50776. (pt - fullLayout.height) * fb) / (ft - fb),
  50777. newt = (pt * (1 - fb) +
  50778. (pb - fullLayout.height) * (1 - ft)) / (ft - fb);
  50779. if(newb >= 0 && newt >= 0 && newb + newt > mb + mt) {
  50780. mb = newb;
  50781. mt = newt;
  50782. }
  50783. }
  50784. }
  50785. }
  50786. }
  50787. }
  50788. gs.l = Math.round(ml);
  50789. gs.r = Math.round(mr);
  50790. gs.t = Math.round(mt);
  50791. gs.b = Math.round(mb);
  50792. gs.p = Math.round(fullLayout.margin.pad);
  50793. gs.w = Math.round(fullLayout.width) - gs.l - gs.r;
  50794. gs.h = Math.round(fullLayout.height) - gs.t - gs.b;
  50795. // if things changed and we're not already redrawing, trigger a redraw
  50796. if(!fullLayout._replotting &&
  50797. oldmargins !== '{}' &&
  50798. oldmargins !== JSON.stringify(fullLayout._size)
  50799. ) {
  50800. if('_redrawFromAutoMarginCount' in fullLayout) {
  50801. fullLayout._redrawFromAutoMarginCount++;
  50802. } else {
  50803. fullLayout._redrawFromAutoMarginCount = 1;
  50804. }
  50805. return Registry.call('plot', gd);
  50806. }
  50807. };
  50808. /**
  50809. * JSONify the graph data and layout
  50810. *
  50811. * This function needs to recurse because some src can be inside
  50812. * sub-objects.
  50813. *
  50814. * It also strips out functions and private (starts with _) elements.
  50815. * Therefore, we can add temporary things to data and layout that don't
  50816. * get saved.
  50817. *
  50818. * @param gd The graphDiv
  50819. * @param {Boolean} dataonly If true, don't return layout.
  50820. * @param {'keepref'|'keepdata'|'keepall'} [mode='keepref'] Filter what's kept
  50821. * keepref: remove data for which there's a src present
  50822. * eg if there's xsrc present (and xsrc is well-formed,
  50823. * ie has : and some chars before it), strip out x
  50824. * keepdata: remove all src tags, don't remove the data itself
  50825. * keepall: keep data and src
  50826. * @param {String} output If you specify 'object', the result will not be stringified
  50827. * @param {Boolean} useDefaults If truthy, use _fullLayout and _fullData
  50828. * @returns {Object|String}
  50829. */
  50830. plots.graphJson = function(gd, dataonly, mode, output, useDefaults) {
  50831. // if the defaults aren't supplied yet, we need to do that...
  50832. if((useDefaults && dataonly && !gd._fullData) ||
  50833. (useDefaults && !dataonly && !gd._fullLayout)) {
  50834. plots.supplyDefaults(gd);
  50835. }
  50836. var data = (useDefaults) ? gd._fullData : gd.data,
  50837. layout = (useDefaults) ? gd._fullLayout : gd.layout,
  50838. frames = (gd._transitionData || {})._frames;
  50839. function stripObj(d) {
  50840. if(typeof d === 'function') {
  50841. return null;
  50842. }
  50843. if(Lib.isPlainObject(d)) {
  50844. var o = {}, v, src;
  50845. for(v in d) {
  50846. // remove private elements and functions
  50847. // _ is for private, [ is a mistake ie [object Object]
  50848. if(typeof d[v] === 'function' ||
  50849. ['_', '['].indexOf(v.charAt(0)) !== -1) {
  50850. continue;
  50851. }
  50852. // look for src/data matches and remove the appropriate one
  50853. if(mode === 'keepdata') {
  50854. // keepdata: remove all ...src tags
  50855. if(v.substr(v.length - 3) === 'src') {
  50856. continue;
  50857. }
  50858. }
  50859. else if(mode === 'keepstream') {
  50860. // keep sourced data if it's being streamed.
  50861. // similar to keepref, but if the 'stream' object exists
  50862. // in a trace, we will keep the data array.
  50863. src = d[v + 'src'];
  50864. if(typeof src === 'string' && src.indexOf(':') > 0) {
  50865. if(!Lib.isPlainObject(d.stream)) {
  50866. continue;
  50867. }
  50868. }
  50869. }
  50870. else if(mode !== 'keepall') {
  50871. // keepref: remove sourced data but only
  50872. // if the source tag is well-formed
  50873. src = d[v + 'src'];
  50874. if(typeof src === 'string' && src.indexOf(':') > 0) {
  50875. continue;
  50876. }
  50877. }
  50878. // OK, we're including this... recurse into it
  50879. o[v] = stripObj(d[v]);
  50880. }
  50881. return o;
  50882. }
  50883. if(Array.isArray(d)) {
  50884. return d.map(stripObj);
  50885. }
  50886. if(Lib.isTypedArray(d)) {
  50887. return Lib.simpleMap(d, Lib.identity);
  50888. }
  50889. // convert native dates to date strings...
  50890. // mostly for external users exporting to plotly
  50891. if(Lib.isJSDate(d)) return Lib.ms2DateTimeLocal(+d);
  50892. return d;
  50893. }
  50894. var obj = {
  50895. data: (data || []).map(function(v) {
  50896. var d = stripObj(v);
  50897. // fit has some little arrays in it that don't contain data,
  50898. // just fit params and meta
  50899. if(dataonly) { delete d.fit; }
  50900. return d;
  50901. })
  50902. };
  50903. if(!dataonly) { obj.layout = stripObj(layout); }
  50904. if(gd.framework && gd.framework.isPolar) obj = gd.framework.getConfig();
  50905. if(frames) obj.frames = stripObj(frames);
  50906. return (output === 'object') ? obj : JSON.stringify(obj);
  50907. };
  50908. /**
  50909. * Modify a keyframe using a list of operations:
  50910. *
  50911. * @param {array of objects} operations
  50912. * Sequence of operations to be performed on the keyframes
  50913. */
  50914. plots.modifyFrames = function(gd, operations) {
  50915. var i, op, frame;
  50916. var _frames = gd._transitionData._frames;
  50917. var _frameHash = gd._transitionData._frameHash;
  50918. for(i = 0; i < operations.length; i++) {
  50919. op = operations[i];
  50920. switch(op.type) {
  50921. // No reason this couldn't exist, but is currently unused/untested:
  50922. /* case 'rename':
  50923. frame = _frames[op.index];
  50924. delete _frameHash[frame.name];
  50925. _frameHash[op.name] = frame;
  50926. frame.name = op.name;
  50927. break;*/
  50928. case 'replace':
  50929. frame = op.value;
  50930. var oldName = (_frames[op.index] || {}).name;
  50931. var newName = frame.name;
  50932. _frames[op.index] = _frameHash[newName] = frame;
  50933. if(newName !== oldName) {
  50934. // If name has changed in addition to replacement, then update
  50935. // the lookup table:
  50936. delete _frameHash[oldName];
  50937. _frameHash[newName] = frame;
  50938. }
  50939. break;
  50940. case 'insert':
  50941. frame = op.value;
  50942. _frameHash[frame.name] = frame;
  50943. _frames.splice(op.index, 0, frame);
  50944. break;
  50945. case 'delete':
  50946. frame = _frames[op.index];
  50947. delete _frameHash[frame.name];
  50948. _frames.splice(op.index, 1);
  50949. break;
  50950. }
  50951. }
  50952. return Promise.resolve();
  50953. };
  50954. /*
  50955. * Compute a keyframe. Merge a keyframe into its base frame(s) and
  50956. * expand properties.
  50957. *
  50958. * @param {object} frameLookup
  50959. * An object containing frames keyed by name (i.e. gd._transitionData._frameHash)
  50960. * @param {string} frame
  50961. * The name of the keyframe to be computed
  50962. *
  50963. * Returns: a new object with the merged content
  50964. */
  50965. plots.computeFrame = function(gd, frameName) {
  50966. var frameLookup = gd._transitionData._frameHash;
  50967. var i, traceIndices, traceIndex, destIndex;
  50968. // Null or undefined will fail on .toString(). We'll allow numbers since we
  50969. // make it clear frames must be given string names, but we'll allow numbers
  50970. // here since they're otherwise fine for looking up frames as long as they're
  50971. // properly cast to strings. We really just want to ensure here that this
  50972. // 1) doesn't fail, and
  50973. // 2) doens't give an incorrect answer (which String(frameName) would)
  50974. if(!frameName) {
  50975. throw new Error('computeFrame must be given a string frame name');
  50976. }
  50977. var framePtr = frameLookup[frameName.toString()];
  50978. // Return false if the name is invalid:
  50979. if(!framePtr) {
  50980. return false;
  50981. }
  50982. var frameStack = [framePtr];
  50983. var frameNameStack = [framePtr.name];
  50984. // Follow frame pointers:
  50985. while(framePtr.baseframe && (framePtr = frameLookup[framePtr.baseframe.toString()])) {
  50986. // Avoid infinite loops:
  50987. if(frameNameStack.indexOf(framePtr.name) !== -1) break;
  50988. frameStack.push(framePtr);
  50989. frameNameStack.push(framePtr.name);
  50990. }
  50991. // A new object for the merged result:
  50992. var result = {};
  50993. // Merge, starting with the last and ending with the desired frame:
  50994. while((framePtr = frameStack.pop())) {
  50995. if(framePtr.layout) {
  50996. result.layout = plots.extendLayout(result.layout, framePtr.layout);
  50997. }
  50998. if(framePtr.data) {
  50999. if(!result.data) {
  51000. result.data = [];
  51001. }
  51002. traceIndices = framePtr.traces;
  51003. if(!traceIndices) {
  51004. // If not defined, assume serial order starting at zero
  51005. traceIndices = [];
  51006. for(i = 0; i < framePtr.data.length; i++) {
  51007. traceIndices[i] = i;
  51008. }
  51009. }
  51010. if(!result.traces) {
  51011. result.traces = [];
  51012. }
  51013. for(i = 0; i < framePtr.data.length; i++) {
  51014. // Loop through this frames data, find out where it should go,
  51015. // and merge it!
  51016. traceIndex = traceIndices[i];
  51017. if(traceIndex === undefined || traceIndex === null) {
  51018. continue;
  51019. }
  51020. destIndex = result.traces.indexOf(traceIndex);
  51021. if(destIndex === -1) {
  51022. destIndex = result.data.length;
  51023. result.traces[destIndex] = traceIndex;
  51024. }
  51025. result.data[destIndex] = plots.extendTrace(result.data[destIndex], framePtr.data[i]);
  51026. }
  51027. }
  51028. }
  51029. return result;
  51030. };
  51031. /*
  51032. * Recompute the lookup table that maps frame name -> frame object. addFrames/
  51033. * deleteFrames already manages this data one at a time, so the only time this
  51034. * is necessary is if you poke around manually in `gd._transitionData._frames`
  51035. * and create and haven't updated the lookup table.
  51036. */
  51037. plots.recomputeFrameHash = function(gd) {
  51038. var hash = gd._transitionData._frameHash = {};
  51039. var frames = gd._transitionData._frames;
  51040. for(var i = 0; i < frames.length; i++) {
  51041. var frame = frames[i];
  51042. if(frame && frame.name) {
  51043. hash[frame.name] = frame;
  51044. }
  51045. }
  51046. };
  51047. /**
  51048. * Extend an object, treating container arrays very differently by extracting
  51049. * their contents and merging them separately.
  51050. *
  51051. * This exists so that we can extendDeepNoArrays and avoid stepping into data
  51052. * arrays without knowledge of the plot schema, but so that we may also manually
  51053. * recurse into known container arrays, such as transforms.
  51054. *
  51055. * See extendTrace and extendLayout below for usage.
  51056. */
  51057. plots.extendObjectWithContainers = function(dest, src, containerPaths) {
  51058. var containerProp, containerVal, i, j, srcProp, destProp, srcContainer, destContainer;
  51059. var copy = Lib.extendDeepNoArrays({}, src || {});
  51060. var expandedObj = Lib.expandObjectPaths(copy);
  51061. var containerObj = {};
  51062. // Step through and extract any container properties. Otherwise extendDeepNoArrays
  51063. // will clobber any existing properties with an empty array and then supplyDefaults
  51064. // will reset everything to defaults.
  51065. if(containerPaths && containerPaths.length) {
  51066. for(i = 0; i < containerPaths.length; i++) {
  51067. containerProp = Lib.nestedProperty(expandedObj, containerPaths[i]);
  51068. containerVal = containerProp.get();
  51069. if(containerVal === undefined) {
  51070. Lib.nestedProperty(containerObj, containerPaths[i]).set(null);
  51071. }
  51072. else {
  51073. containerProp.set(null);
  51074. Lib.nestedProperty(containerObj, containerPaths[i]).set(containerVal);
  51075. }
  51076. }
  51077. }
  51078. dest = Lib.extendDeepNoArrays(dest || {}, expandedObj);
  51079. if(containerPaths && containerPaths.length) {
  51080. for(i = 0; i < containerPaths.length; i++) {
  51081. srcProp = Lib.nestedProperty(containerObj, containerPaths[i]);
  51082. srcContainer = srcProp.get();
  51083. if(!srcContainer) continue;
  51084. destProp = Lib.nestedProperty(dest, containerPaths[i]);
  51085. destContainer = destProp.get();
  51086. if(!Array.isArray(destContainer)) {
  51087. destContainer = [];
  51088. destProp.set(destContainer);
  51089. }
  51090. for(j = 0; j < srcContainer.length; j++) {
  51091. var srcObj = srcContainer[j];
  51092. if(srcObj === null) destContainer[j] = null;
  51093. else {
  51094. destContainer[j] = plots.extendObjectWithContainers(destContainer[j], srcObj);
  51095. }
  51096. }
  51097. destProp.set(destContainer);
  51098. }
  51099. }
  51100. return dest;
  51101. };
  51102. plots.dataArrayContainers = ['transforms', 'dimensions'];
  51103. plots.layoutArrayContainers = Registry.layoutArrayContainers;
  51104. /*
  51105. * Extend a trace definition. This method:
  51106. *
  51107. * 1. directly transfers any array references
  51108. * 2. manually recurses into container arrays like transforms
  51109. *
  51110. * The result is the original object reference with the new contents merged in.
  51111. */
  51112. plots.extendTrace = function(destTrace, srcTrace) {
  51113. return plots.extendObjectWithContainers(destTrace, srcTrace, plots.dataArrayContainers);
  51114. };
  51115. /*
  51116. * Extend a layout definition. This method:
  51117. *
  51118. * 1. directly transfers any array references (not critically important for
  51119. * layout since there aren't really data arrays)
  51120. * 2. manually recurses into container arrays like annotations
  51121. *
  51122. * The result is the original object reference with the new contents merged in.
  51123. */
  51124. plots.extendLayout = function(destLayout, srcLayout) {
  51125. return plots.extendObjectWithContainers(destLayout, srcLayout, plots.layoutArrayContainers);
  51126. };
  51127. /**
  51128. * Transition to a set of new data and layout properties
  51129. *
  51130. * @param {DOM element} gd
  51131. * the DOM element of the graph container div
  51132. * @param {Object[]} data
  51133. * an array of data objects following the normal Plotly data definition format
  51134. * @param {Object} layout
  51135. * a layout object, following normal Plotly layout format
  51136. * @param {Number[]} traces
  51137. * indices of the corresponding traces specified in `data`
  51138. * @param {Object} frameOpts
  51139. * options for the frame (i.e. whether to redraw post-transition)
  51140. * @param {Object} transitionOpts
  51141. * options for the transition
  51142. */
  51143. plots.transition = function(gd, data, layout, traces, frameOpts, transitionOpts) {
  51144. var i, traceIdx;
  51145. var dataLength = Array.isArray(data) ? data.length : 0;
  51146. var traceIndices = traces.slice(0, dataLength);
  51147. var transitionedTraces = [];
  51148. function prepareTransitions() {
  51149. var i;
  51150. for(i = 0; i < traceIndices.length; i++) {
  51151. var traceIdx = traceIndices[i];
  51152. var trace = gd._fullData[traceIdx];
  51153. var module = trace._module;
  51154. // There's nothing to do if this module is not defined:
  51155. if(!module) continue;
  51156. // Don't register the trace as transitioned if it doesn't know what to do.
  51157. // If it *is* registered, it will receive a callback that it's responsible
  51158. // for calling in order to register the transition as having completed.
  51159. if(module.animatable) {
  51160. transitionedTraces.push(traceIdx);
  51161. }
  51162. gd.data[traceIndices[i]] = plots.extendTrace(gd.data[traceIndices[i]], data[i]);
  51163. }
  51164. // Follow the same procedure. Clone it so we don't mangle the input, then
  51165. // expand any object paths so we can merge deep into gd.layout:
  51166. var layoutUpdate = Lib.expandObjectPaths(Lib.extendDeepNoArrays({}, layout));
  51167. // Before merging though, we need to modify the incoming layout. We only
  51168. // know how to *transition* layout ranges, so it's imperative that a new
  51169. // range not be sent to the layout before the transition has started. So
  51170. // we must remove the things we can transition:
  51171. var axisAttrRe = /^[xy]axis[0-9]*$/;
  51172. for(var attr in layoutUpdate) {
  51173. if(!axisAttrRe.test(attr)) continue;
  51174. delete layoutUpdate[attr].range;
  51175. }
  51176. plots.extendLayout(gd.layout, layoutUpdate);
  51177. // Supply defaults after applying the incoming properties. Note that any attempt
  51178. // to simplify this step and reduce the amount of work resulted in the reconstruction
  51179. // of essentially the whole supplyDefaults step, so that it seems sensible to just use
  51180. // supplyDefaults even though it's heavier than would otherwise be desired for
  51181. // transitions:
  51182. // first delete calcdata so supplyDefaults knows a calc step is coming
  51183. delete gd.calcdata;
  51184. plots.supplyDefaults(gd);
  51185. plots.doCalcdata(gd);
  51186. return Promise.resolve();
  51187. }
  51188. function executeCallbacks(list) {
  51189. var p = Promise.resolve();
  51190. if(!list) return p;
  51191. while(list.length) {
  51192. p = p.then((list.shift()));
  51193. }
  51194. return p;
  51195. }
  51196. function flushCallbacks(list) {
  51197. if(!list) return;
  51198. while(list.length) {
  51199. list.shift();
  51200. }
  51201. }
  51202. var aborted = false;
  51203. function executeTransitions() {
  51204. gd.emit('plotly_transitioning', []);
  51205. return new Promise(function(resolve) {
  51206. // This flag is used to disabled things like autorange:
  51207. gd._transitioning = true;
  51208. // When instantaneous updates are coming through quickly, it's too much to simply disable
  51209. // all interaction, so store this flag so we can disambiguate whether mouse interactions
  51210. // should be fully disabled or not:
  51211. if(transitionOpts.duration > 0) {
  51212. gd._transitioningWithDuration = true;
  51213. }
  51214. // If another transition is triggered, this callback will be executed simply because it's
  51215. // in the interruptCallbacks queue. If this transition completes, it will instead flush
  51216. // that queue and forget about this callback.
  51217. gd._transitionData._interruptCallbacks.push(function() {
  51218. aborted = true;
  51219. });
  51220. if(frameOpts.redraw) {
  51221. gd._transitionData._interruptCallbacks.push(function() {
  51222. return Registry.call('redraw', gd);
  51223. });
  51224. }
  51225. // Emit this and make sure it happens last:
  51226. gd._transitionData._interruptCallbacks.push(function() {
  51227. gd.emit('plotly_transitioninterrupted', []);
  51228. });
  51229. // Construct callbacks that are executed on transition end. This ensures the d3 transitions
  51230. // are *complete* before anything else is done.
  51231. var numCallbacks = 0;
  51232. var numCompleted = 0;
  51233. function makeCallback() {
  51234. numCallbacks++;
  51235. return function() {
  51236. numCompleted++;
  51237. // When all are complete, perform a redraw:
  51238. if(!aborted && numCompleted === numCallbacks) {
  51239. completeTransition(resolve);
  51240. }
  51241. };
  51242. }
  51243. var traceTransitionOpts;
  51244. var j;
  51245. var basePlotModules = gd._fullLayout._basePlotModules;
  51246. var hasAxisTransition = false;
  51247. if(layout) {
  51248. for(j = 0; j < basePlotModules.length; j++) {
  51249. if(basePlotModules[j].transitionAxes) {
  51250. var newLayout = Lib.expandObjectPaths(layout);
  51251. hasAxisTransition = basePlotModules[j].transitionAxes(gd, newLayout, transitionOpts, makeCallback) || hasAxisTransition;
  51252. }
  51253. }
  51254. }
  51255. // Here handle the exception that we refuse to animate scales and axes at the same
  51256. // time. In other words, if there's an axis transition, then set the data transition
  51257. // to instantaneous.
  51258. if(hasAxisTransition) {
  51259. traceTransitionOpts = Lib.extendFlat({}, transitionOpts);
  51260. traceTransitionOpts.duration = 0;
  51261. // This means do not transition traces,
  51262. // this happens on layout-only (e.g. axis range) animations
  51263. transitionedTraces = null;
  51264. } else {
  51265. traceTransitionOpts = transitionOpts;
  51266. }
  51267. for(j = 0; j < basePlotModules.length; j++) {
  51268. // Note that we pass a callback to *create* the callback that must be invoked on completion.
  51269. // This is since not all traces know about transitions, so it greatly simplifies matters if
  51270. // the trace is responsible for creating a callback, if needed, and then executing it when
  51271. // the time is right.
  51272. basePlotModules[j].plot(gd, transitionedTraces, traceTransitionOpts, makeCallback);
  51273. }
  51274. // If nothing else creates a callback, then this will trigger the completion in the next tick:
  51275. setTimeout(makeCallback());
  51276. });
  51277. }
  51278. function completeTransition(callback) {
  51279. // This a simple workaround for tests which purge the graph before animations
  51280. // have completed. That's not a very common case, so this is the simplest
  51281. // fix.
  51282. if(!gd._transitionData) return;
  51283. flushCallbacks(gd._transitionData._interruptCallbacks);
  51284. return Promise.resolve().then(function() {
  51285. if(frameOpts.redraw) {
  51286. return Registry.call('redraw', gd);
  51287. }
  51288. }).then(function() {
  51289. // Set transitioning false again once the redraw has occurred. This is used, for example,
  51290. // to prevent the trailing redraw from autoranging:
  51291. gd._transitioning = false;
  51292. gd._transitioningWithDuration = false;
  51293. gd.emit('plotly_transitioned', []);
  51294. }).then(callback);
  51295. }
  51296. function interruptPreviousTransitions() {
  51297. // Fail-safe against purged plot:
  51298. if(!gd._transitionData) return;
  51299. // If a transition is interrupted, set this to false. At the moment, the only thing that would
  51300. // interrupt a transition is another transition, so that it will momentarily be set to true
  51301. // again, but this determines whether autorange or dragbox work, so it's for the sake of
  51302. // cleanliness:
  51303. gd._transitioning = false;
  51304. return executeCallbacks(gd._transitionData._interruptCallbacks);
  51305. }
  51306. for(i = 0; i < traceIndices.length; i++) {
  51307. traceIdx = traceIndices[i];
  51308. var contFull = gd._fullData[traceIdx];
  51309. var module = contFull._module;
  51310. if(!module) continue;
  51311. }
  51312. var seq = [plots.previousPromises, interruptPreviousTransitions, prepareTransitions, plots.rehover, executeTransitions];
  51313. var transitionStarting = Lib.syncOrAsync(seq, gd);
  51314. if(!transitionStarting || !transitionStarting.then) {
  51315. transitionStarting = Promise.resolve();
  51316. }
  51317. return transitionStarting.then(function() {
  51318. return gd;
  51319. });
  51320. };
  51321. plots.doCalcdata = function(gd, traces) {
  51322. var axList = axisIDs.list(gd),
  51323. fullData = gd._fullData,
  51324. fullLayout = gd._fullLayout;
  51325. var trace, _module, i, j;
  51326. // XXX: Is this correct? Needs a closer look so that *some* traces can be recomputed without
  51327. // *all* needing doCalcdata:
  51328. var calcdata = new Array(fullData.length);
  51329. var oldCalcdata = (gd.calcdata || []).slice(0);
  51330. gd.calcdata = calcdata;
  51331. // extra helper variables
  51332. // how many box/violins plots do we have (in case they're grouped)
  51333. fullLayout._numBoxes = 0;
  51334. fullLayout._numViolins = 0;
  51335. // initialize violin per-scale-group stats container
  51336. fullLayout._violinScaleGroupStats = {};
  51337. // for calculating avg luminosity of heatmaps
  51338. gd._hmpixcount = 0;
  51339. gd._hmlumcount = 0;
  51340. // for sharing colors across pies (and for legend)
  51341. fullLayout._piecolormap = {};
  51342. // If traces were specified and this trace was not included,
  51343. // then transfer it over from the old calcdata:
  51344. for(i = 0; i < fullData.length; i++) {
  51345. if(Array.isArray(traces) && traces.indexOf(i) === -1) {
  51346. calcdata[i] = oldCalcdata[i];
  51347. continue;
  51348. }
  51349. }
  51350. for(i = 0; i < fullData.length; i++) {
  51351. trace = fullData[i];
  51352. trace._arrayAttrs = PlotSchema.findArrayAttributes(trace);
  51353. // keep track of trace extremes (for autorange) in here
  51354. trace._extremes = {};
  51355. }
  51356. // add polar axes to axis list
  51357. var polarIds = fullLayout._subplots.polar || [];
  51358. for(i = 0; i < polarIds.length; i++) {
  51359. axList.push(
  51360. fullLayout[polarIds[i]].radialaxis,
  51361. fullLayout[polarIds[i]].angularaxis
  51362. );
  51363. }
  51364. clearAxesCalc(axList);
  51365. var hasCalcTransform = false;
  51366. // transform loop
  51367. for(i = 0; i < fullData.length; i++) {
  51368. trace = fullData[i];
  51369. if(trace.visible === true && trace.transforms) {
  51370. _module = trace._module;
  51371. // we need one round of trace module calc before
  51372. // the calc transform to 'fill in' the categories list
  51373. // used for example in the data-to-coordinate method
  51374. if(_module && _module.calc) {
  51375. var cdi = _module.calc(gd, trace);
  51376. // must clear scene 'batches', so that 2nd
  51377. // _module.calc call starts from scratch
  51378. if(cdi[0] && cdi[0].t && cdi[0].t._scene) {
  51379. delete cdi[0].t._scene.dirty;
  51380. }
  51381. }
  51382. for(j = 0; j < trace.transforms.length; j++) {
  51383. var transform = trace.transforms[j];
  51384. _module = transformsRegistry[transform.type];
  51385. if(_module && _module.calcTransform) {
  51386. trace._hasCalcTransform = true;
  51387. hasCalcTransform = true;
  51388. _module.calcTransform(gd, trace, transform);
  51389. }
  51390. }
  51391. }
  51392. }
  51393. // clear stuff that should recomputed in 'regular' loop
  51394. if(hasCalcTransform) clearAxesCalc(axList);
  51395. function calci(i, isContainer) {
  51396. trace = fullData[i];
  51397. _module = trace._module;
  51398. if(!!_module.isContainer !== isContainer) return;
  51399. var cd = [];
  51400. if(trace.visible === true) {
  51401. // clear existing ref in case it got relinked
  51402. delete trace._indexToPoints;
  51403. // keep ref of index-to-points map object of the *last* enabled transform,
  51404. // this index-to-points map object is required to determine the calcdata indices
  51405. // that correspond to input indices (e.g. from 'selectedpoints')
  51406. var transforms = trace.transforms || [];
  51407. for(j = transforms.length - 1; j >= 0; j--) {
  51408. if(transforms[j].enabled) {
  51409. trace._indexToPoints = transforms[j]._indexToPoints;
  51410. break;
  51411. }
  51412. }
  51413. if(_module && _module.calc) {
  51414. cd = _module.calc(gd, trace);
  51415. }
  51416. }
  51417. // Make sure there is a first point.
  51418. //
  51419. // This ensures there is a calcdata item for every trace,
  51420. // even if cartesian logic doesn't handle it (for things like legends).
  51421. if(!Array.isArray(cd) || !cd[0]) {
  51422. cd = [{x: BADNUM, y: BADNUM}];
  51423. }
  51424. // add the trace-wide properties to the first point,
  51425. // per point properties to every point
  51426. // t is the holder for trace-wide properties
  51427. if(!cd[0].t) cd[0].t = {};
  51428. cd[0].trace = trace;
  51429. calcdata[i] = cd;
  51430. }
  51431. // 'regular' loop - make sure container traces (eg carpet) calc before
  51432. // contained traces (eg contourcarpet)
  51433. for(i = 0; i < fullData.length; i++) calci(i, true);
  51434. for(i = 0; i < fullData.length; i++) calci(i, false);
  51435. doCrossTraceCalc(gd);
  51436. Registry.getComponentMethod('fx', 'calc')(gd);
  51437. Registry.getComponentMethod('errorbars', 'calc')(gd);
  51438. };
  51439. function clearAxesCalc(axList) {
  51440. for(var i = 0; i < axList.length; i++) {
  51441. axList[i].clearCalc();
  51442. }
  51443. }
  51444. function doCrossTraceCalc(gd) {
  51445. var fullLayout = gd._fullLayout;
  51446. var modules = fullLayout._visibleModules;
  51447. var hash = {};
  51448. var i, j, k;
  51449. // position and range calculations for traces that
  51450. // depend on each other ie bars (stacked or grouped)
  51451. // and boxes (grouped) push each other out of the way
  51452. for(j = 0; j < modules.length; j++) {
  51453. var _module = modules[j];
  51454. var fn = _module.crossTraceCalc;
  51455. if(fn) {
  51456. var spType = _module.basePlotModule.name;
  51457. if(hash[spType]) {
  51458. Lib.pushUnique(hash[spType], fn);
  51459. } else {
  51460. hash[spType] = [fn];
  51461. }
  51462. }
  51463. }
  51464. for(k in hash) {
  51465. var methods = hash[k];
  51466. var subplots = fullLayout._subplots[k];
  51467. if(Array.isArray(subplots)) {
  51468. for(i = 0; i < subplots.length; i++) {
  51469. var sp = subplots[i];
  51470. var spInfo = k === 'cartesian' ?
  51471. fullLayout._plots[sp] :
  51472. fullLayout[sp];
  51473. for(j = 0; j < methods.length; j++) {
  51474. methods[j](gd, spInfo, sp);
  51475. }
  51476. }
  51477. }
  51478. else {
  51479. for(j = 0; j < methods.length; j++) {
  51480. methods[j](gd);
  51481. }
  51482. }
  51483. }
  51484. }
  51485. plots.rehover = function(gd) {
  51486. if(gd._fullLayout._rehover) {
  51487. gd._fullLayout._rehover();
  51488. }
  51489. };
  51490. plots.generalUpdatePerTraceModule = function(gd, subplot, subplotCalcData, subplotLayout) {
  51491. var traceHashOld = subplot.traceHash;
  51492. var traceHash = {};
  51493. var i;
  51494. // build up moduleName -> calcData hash
  51495. for(i = 0; i < subplotCalcData.length; i++) {
  51496. var calcTraces = subplotCalcData[i],
  51497. trace = calcTraces[0].trace;
  51498. // skip over visible === false traces
  51499. // as they don't have `_module` ref
  51500. if(trace.visible) {
  51501. traceHash[trace.type] = traceHash[trace.type] || [];
  51502. traceHash[trace.type].push(calcTraces);
  51503. }
  51504. }
  51505. // when a trace gets deleted, make sure that its module's
  51506. // plot method is called so that it is properly
  51507. // removed from the DOM.
  51508. for(var moduleNameOld in traceHashOld) {
  51509. if(!traceHash[moduleNameOld]) {
  51510. var fakeCalcTrace = traceHashOld[moduleNameOld][0],
  51511. fakeTrace = fakeCalcTrace[0].trace;
  51512. fakeTrace.visible = false;
  51513. traceHash[moduleNameOld] = [fakeCalcTrace];
  51514. }
  51515. }
  51516. // call module plot method
  51517. for(var moduleName in traceHash) {
  51518. var moduleCalcData = traceHash[moduleName];
  51519. var _module = moduleCalcData[0][0].trace._module;
  51520. _module.plot(gd, subplot, Lib.filterVisible(moduleCalcData), subplotLayout);
  51521. }
  51522. // update moduleName -> calcData hash
  51523. subplot.traceHash = traceHash;
  51524. };
  51525. },{"../components/color":50,"../constants/numerical":151,"../lib":169,"../plot_api/plot_schema":203,"../plot_api/plot_template":204,"../plots/cartesian/axis_ids":217,"../registry":259,"./animation_attributes":209,"./attributes":211,"./command":238,"./font_attributes":240,"./frame_attributes":241,"./layout_attributes":244,"./sort_modules":253,"d3":16,"fast-isnumeric":18}],247:[function(_dereq_,module,exports){
  51526. /**
  51527. * Copyright 2012-2018, Plotly, Inc.
  51528. * All rights reserved.
  51529. *
  51530. * This source code is licensed under the MIT license found in the
  51531. * LICENSE file in the root directory of this source tree.
  51532. */
  51533. 'use strict';
  51534. var scatterAttrs = _dereq_('../../../traces/scatter/attributes');
  51535. var scatterMarkerAttrs = scatterAttrs.marker;
  51536. var extendFlat = _dereq_('../../../lib/extend').extendFlat;
  51537. var deprecationWarning = [
  51538. 'Area traces are deprecated!',
  51539. 'Please switch to the *barpolar* trace type.'
  51540. ].join(' ');
  51541. module.exports = {
  51542. r: extendFlat({}, scatterAttrs.r, {
  51543. }),
  51544. t: extendFlat({}, scatterAttrs.t, {
  51545. }),
  51546. marker: {
  51547. color: extendFlat({}, scatterMarkerAttrs.color, {
  51548. }),
  51549. size: extendFlat({}, scatterMarkerAttrs.size, {
  51550. }),
  51551. symbol: extendFlat({}, scatterMarkerAttrs.symbol, {
  51552. }),
  51553. opacity: extendFlat({}, scatterMarkerAttrs.opacity, {
  51554. }),
  51555. editType: 'calc'
  51556. }
  51557. };
  51558. },{"../../../lib/extend":163,"../../../traces/scatter/attributes":366}],248:[function(_dereq_,module,exports){
  51559. /**
  51560. * Copyright 2012-2018, Plotly, Inc.
  51561. * All rights reserved.
  51562. *
  51563. * This source code is licensed under the MIT license found in the
  51564. * LICENSE file in the root directory of this source tree.
  51565. */
  51566. 'use strict';
  51567. var axesAttrs = _dereq_('../../cartesian/layout_attributes');
  51568. var extendFlat = _dereq_('../../../lib/extend').extendFlat;
  51569. var overrideAll = _dereq_('../../../plot_api/edit_types').overrideAll;
  51570. var deprecationWarning = [
  51571. 'Legacy polar charts are deprecated!',
  51572. 'Please switch to *polar* subplots.'
  51573. ].join(' ');
  51574. var domainAttr = extendFlat({}, axesAttrs.domain, {
  51575. });
  51576. function mergeAttrs(axisName, nonCommonAttrs) {
  51577. var commonAttrs = {
  51578. showline: {
  51579. valType: 'boolean',
  51580. },
  51581. showticklabels: {
  51582. valType: 'boolean',
  51583. },
  51584. tickorientation: {
  51585. valType: 'enumerated',
  51586. values: ['horizontal', 'vertical'],
  51587. },
  51588. ticklen: {
  51589. valType: 'number',
  51590. min: 0,
  51591. },
  51592. tickcolor: {
  51593. valType: 'color',
  51594. },
  51595. ticksuffix: {
  51596. valType: 'string',
  51597. },
  51598. endpadding: {
  51599. valType: 'number',
  51600. description: deprecationWarning,
  51601. },
  51602. visible: {
  51603. valType: 'boolean',
  51604. }
  51605. };
  51606. return extendFlat({}, nonCommonAttrs, commonAttrs);
  51607. }
  51608. module.exports = overrideAll({
  51609. radialaxis: mergeAttrs('radial', {
  51610. range: {
  51611. valType: 'info_array',
  51612. items: [
  51613. { valType: 'number' },
  51614. { valType: 'number' }
  51615. ],
  51616. },
  51617. domain: domainAttr,
  51618. orientation: {
  51619. valType: 'number',
  51620. }
  51621. }),
  51622. angularaxis: mergeAttrs('angular', {
  51623. range: {
  51624. valType: 'info_array',
  51625. items: [
  51626. { valType: 'number', dflt: 0 },
  51627. { valType: 'number', dflt: 360 }
  51628. ],
  51629. },
  51630. domain: domainAttr
  51631. }),
  51632. // attributes that appear at layout root
  51633. layout: {
  51634. direction: {
  51635. valType: 'enumerated',
  51636. values: ['clockwise', 'counterclockwise'],
  51637. },
  51638. orientation: {
  51639. valType: 'angle',
  51640. }
  51641. }
  51642. }, 'plot', 'nested');
  51643. },{"../../../lib/extend":163,"../../../plot_api/edit_types":197,"../../cartesian/layout_attributes":226}],249:[function(_dereq_,module,exports){
  51644. /**
  51645. * Copyright 2012-2018, Plotly, Inc.
  51646. * All rights reserved.
  51647. *
  51648. * This source code is licensed under the MIT license found in the
  51649. * LICENSE file in the root directory of this source tree.
  51650. */
  51651. 'use strict';
  51652. var Polar = module.exports = _dereq_('./micropolar');
  51653. Polar.manager = _dereq_('./micropolar_manager');
  51654. },{"./micropolar":250,"./micropolar_manager":251}],250:[function(_dereq_,module,exports){
  51655. /**
  51656. * Copyright 2012-2018, Plotly, Inc.
  51657. * All rights reserved.
  51658. *
  51659. * This source code is licensed under the MIT license found in the
  51660. * LICENSE file in the root directory of this source tree.
  51661. */
  51662. var d3 = _dereq_('d3');
  51663. var Lib = _dereq_('../../../lib');
  51664. var extendDeepAll = Lib.extendDeepAll;
  51665. var MID_SHIFT = _dereq_('../../../constants/alignment').MID_SHIFT;
  51666. var µ = module.exports = { version: '0.2.2' };
  51667. µ.Axis = function module() {
  51668. var config = {
  51669. data: [],
  51670. layout: {}
  51671. }, inputConfig = {}, liveConfig = {};
  51672. var svg, container, dispatch = d3.dispatch('hover'), radialScale, angularScale;
  51673. var exports = {};
  51674. function render(_container) {
  51675. container = _container || container;
  51676. var data = config.data;
  51677. var axisConfig = config.layout;
  51678. if (typeof container == 'string' || container.nodeName) container = d3.select(container);
  51679. container.datum(data).each(function(_data, _index) {
  51680. var dataOriginal = _data.slice();
  51681. liveConfig = {
  51682. data: µ.util.cloneJson(dataOriginal),
  51683. layout: µ.util.cloneJson(axisConfig)
  51684. };
  51685. var colorIndex = 0;
  51686. dataOriginal.forEach(function(d, i) {
  51687. if (!d.color) {
  51688. d.color = axisConfig.defaultColorRange[colorIndex];
  51689. colorIndex = (colorIndex + 1) % axisConfig.defaultColorRange.length;
  51690. }
  51691. if (!d.strokeColor) {
  51692. d.strokeColor = d.geometry === 'LinePlot' ? d.color : d3.rgb(d.color).darker().toString();
  51693. }
  51694. liveConfig.data[i].color = d.color;
  51695. liveConfig.data[i].strokeColor = d.strokeColor;
  51696. liveConfig.data[i].strokeDash = d.strokeDash;
  51697. liveConfig.data[i].strokeSize = d.strokeSize;
  51698. });
  51699. var data = dataOriginal.filter(function(d, i) {
  51700. var visible = d.visible;
  51701. return typeof visible === 'undefined' || visible === true;
  51702. });
  51703. var isStacked = false;
  51704. var dataWithGroupId = data.map(function(d, i) {
  51705. isStacked = isStacked || typeof d.groupId !== 'undefined';
  51706. return d;
  51707. });
  51708. if (isStacked) {
  51709. var grouped = d3.nest().key(function(d, i) {
  51710. return typeof d.groupId != 'undefined' ? d.groupId : 'unstacked';
  51711. }).entries(dataWithGroupId);
  51712. var dataYStack = [];
  51713. var stacked = grouped.map(function(d, i) {
  51714. if (d.key === 'unstacked') return d.values; else {
  51715. var prevArray = d.values[0].r.map(function(d, i) {
  51716. return 0;
  51717. });
  51718. d.values.forEach(function(d, i, a) {
  51719. d.yStack = [ prevArray ];
  51720. dataYStack.push(prevArray);
  51721. prevArray = µ.util.sumArrays(d.r, prevArray);
  51722. });
  51723. return d.values;
  51724. }
  51725. });
  51726. data = d3.merge(stacked);
  51727. }
  51728. data.forEach(function(d, i) {
  51729. d.t = Array.isArray(d.t[0]) ? d.t : [ d.t ];
  51730. d.r = Array.isArray(d.r[0]) ? d.r : [ d.r ];
  51731. });
  51732. var radius = Math.min(axisConfig.width - axisConfig.margin.left - axisConfig.margin.right, axisConfig.height - axisConfig.margin.top - axisConfig.margin.bottom) / 2;
  51733. radius = Math.max(10, radius);
  51734. var chartCenter = [ axisConfig.margin.left + radius, axisConfig.margin.top + radius ];
  51735. var extent;
  51736. if (isStacked) {
  51737. var highestStackedValue = d3.max(µ.util.sumArrays(µ.util.arrayLast(data).r[0], µ.util.arrayLast(dataYStack)));
  51738. extent = [ 0, highestStackedValue ];
  51739. } else extent = d3.extent(µ.util.flattenArray(data.map(function(d, i) {
  51740. return d.r;
  51741. })));
  51742. if (axisConfig.radialAxis.domain != µ.DATAEXTENT) extent[0] = 0;
  51743. radialScale = d3.scale.linear().domain(axisConfig.radialAxis.domain != µ.DATAEXTENT && axisConfig.radialAxis.domain ? axisConfig.radialAxis.domain : extent).range([ 0, radius ]);
  51744. liveConfig.layout.radialAxis.domain = radialScale.domain();
  51745. var angularDataMerged = µ.util.flattenArray(data.map(function(d, i) {
  51746. return d.t;
  51747. }));
  51748. var isOrdinal = typeof angularDataMerged[0] === 'string';
  51749. var ticks;
  51750. if (isOrdinal) {
  51751. angularDataMerged = µ.util.deduplicate(angularDataMerged);
  51752. ticks = angularDataMerged.slice();
  51753. angularDataMerged = d3.range(angularDataMerged.length);
  51754. data = data.map(function(d, i) {
  51755. var result = d;
  51756. d.t = [ angularDataMerged ];
  51757. if (isStacked) result.yStack = d.yStack;
  51758. return result;
  51759. });
  51760. }
  51761. var hasOnlyLineOrDotPlot = data.filter(function(d, i) {
  51762. return d.geometry === 'LinePlot' || d.geometry === 'DotPlot';
  51763. }).length === data.length;
  51764. var needsEndSpacing = axisConfig.needsEndSpacing === null ? isOrdinal || !hasOnlyLineOrDotPlot : axisConfig.needsEndSpacing;
  51765. var useProvidedDomain = axisConfig.angularAxis.domain && axisConfig.angularAxis.domain != µ.DATAEXTENT && !isOrdinal && axisConfig.angularAxis.domain[0] >= 0;
  51766. var angularDomain = useProvidedDomain ? axisConfig.angularAxis.domain : d3.extent(angularDataMerged);
  51767. var angularDomainStep = Math.abs(angularDataMerged[1] - angularDataMerged[0]);
  51768. if (hasOnlyLineOrDotPlot && !isOrdinal) angularDomainStep = 0;
  51769. var angularDomainWithPadding = angularDomain.slice();
  51770. if (needsEndSpacing && isOrdinal) angularDomainWithPadding[1] += angularDomainStep;
  51771. var tickCount = axisConfig.angularAxis.ticksCount || 4;
  51772. if (tickCount > 8) tickCount = tickCount / (tickCount / 8) + tickCount % 8;
  51773. if (axisConfig.angularAxis.ticksStep) {
  51774. tickCount = (angularDomainWithPadding[1] - angularDomainWithPadding[0]) / tickCount;
  51775. }
  51776. var angularTicksStep = axisConfig.angularAxis.ticksStep || (angularDomainWithPadding[1] - angularDomainWithPadding[0]) / (tickCount * (axisConfig.minorTicks + 1));
  51777. if (ticks) angularTicksStep = Math.max(Math.round(angularTicksStep), 1);
  51778. if (!angularDomainWithPadding[2]) angularDomainWithPadding[2] = angularTicksStep;
  51779. var angularAxisRange = d3.range.apply(this, angularDomainWithPadding);
  51780. angularAxisRange = angularAxisRange.map(function(d, i) {
  51781. return parseFloat(d.toPrecision(12));
  51782. });
  51783. angularScale = d3.scale.linear().domain(angularDomainWithPadding.slice(0, 2)).range(axisConfig.direction === 'clockwise' ? [ 0, 360 ] : [ 360, 0 ]);
  51784. liveConfig.layout.angularAxis.domain = angularScale.domain();
  51785. liveConfig.layout.angularAxis.endPadding = needsEndSpacing ? angularDomainStep : 0;
  51786. svg = d3.select(this).select('svg.chart-root');
  51787. if (typeof svg === 'undefined' || svg.empty()) {
  51788. var skeleton = "<svg xmlns='http://www.w3.org/2000/svg' class='chart-root'>' + '<g class='outer-group'>' + '<g class='chart-group'>' + '<circle class='background-circle'></circle>' + '<g class='geometry-group'></g>' + '<g class='radial axis-group'>' + '<circle class='outside-circle'></circle>' + '</g>' + '<g class='angular axis-group'></g>' + '<g class='guides-group'><line></line><circle r='0'></circle></g>' + '</g>' + '<g class='legend-group'></g>' + '<g class='tooltips-group'></g>' + '<g class='title-group'><text></text></g>' + '</g>' + '</svg>";
  51789. var doc = new DOMParser().parseFromString(skeleton, 'application/xml');
  51790. var newSvg = this.appendChild(this.ownerDocument.importNode(doc.documentElement, true));
  51791. svg = d3.select(newSvg);
  51792. }
  51793. svg.select('.guides-group').style({
  51794. 'pointer-events': 'none'
  51795. });
  51796. svg.select('.angular.axis-group').style({
  51797. 'pointer-events': 'none'
  51798. });
  51799. svg.select('.radial.axis-group').style({
  51800. 'pointer-events': 'none'
  51801. });
  51802. var chartGroup = svg.select('.chart-group');
  51803. var lineStyle = {
  51804. fill: 'none',
  51805. stroke: axisConfig.tickColor
  51806. };
  51807. var fontStyle = {
  51808. 'font-size': axisConfig.font.size,
  51809. 'font-family': axisConfig.font.family,
  51810. fill: axisConfig.font.color,
  51811. 'text-shadow': [ '-1px 0px', '1px -1px', '-1px 1px', '1px 1px' ].map(function(d, i) {
  51812. return ' ' + d + ' 0 ' + axisConfig.font.outlineColor;
  51813. }).join(',')
  51814. };
  51815. var legendContainer;
  51816. if (axisConfig.showLegend) {
  51817. legendContainer = svg.select('.legend-group').attr({
  51818. transform: 'translate(' + [ radius, axisConfig.margin.top ] + ')'
  51819. }).style({
  51820. display: 'block'
  51821. });
  51822. var elements = data.map(function(d, i) {
  51823. var datumClone = µ.util.cloneJson(d);
  51824. datumClone.symbol = d.geometry === 'DotPlot' ? d.dotType || 'circle' : d.geometry != 'LinePlot' ? 'square' : 'line';
  51825. datumClone.visibleInLegend = typeof d.visibleInLegend === 'undefined' || d.visibleInLegend;
  51826. datumClone.color = d.geometry === 'LinePlot' ? d.strokeColor : d.color;
  51827. return datumClone;
  51828. });
  51829. µ.Legend().config({
  51830. data: data.map(function(d, i) {
  51831. return d.name || 'Element' + i;
  51832. }),
  51833. legendConfig: extendDeepAll({},
  51834. µ.Legend.defaultConfig().legendConfig,
  51835. {
  51836. container: legendContainer,
  51837. elements: elements,
  51838. reverseOrder: axisConfig.legend.reverseOrder
  51839. }
  51840. )
  51841. })();
  51842. var legendBBox = legendContainer.node().getBBox();
  51843. radius = Math.min(axisConfig.width - legendBBox.width - axisConfig.margin.left - axisConfig.margin.right, axisConfig.height - axisConfig.margin.top - axisConfig.margin.bottom) / 2;
  51844. radius = Math.max(10, radius);
  51845. chartCenter = [ axisConfig.margin.left + radius, axisConfig.margin.top + radius ];
  51846. radialScale.range([ 0, radius ]);
  51847. liveConfig.layout.radialAxis.domain = radialScale.domain();
  51848. legendContainer.attr('transform', 'translate(' + [ chartCenter[0] + radius, chartCenter[1] - radius ] + ')');
  51849. } else {
  51850. legendContainer = svg.select('.legend-group').style({
  51851. display: 'none'
  51852. });
  51853. }
  51854. svg.attr({
  51855. width: axisConfig.width,
  51856. height: axisConfig.height
  51857. }).style({
  51858. opacity: axisConfig.opacity
  51859. });
  51860. chartGroup.attr('transform', 'translate(' + chartCenter + ')').style({
  51861. cursor: 'crosshair'
  51862. });
  51863. var centeringOffset = [ (axisConfig.width - (axisConfig.margin.left + axisConfig.margin.right + radius * 2 + (legendBBox ? legendBBox.width : 0))) / 2, (axisConfig.height - (axisConfig.margin.top + axisConfig.margin.bottom + radius * 2)) / 2 ];
  51864. centeringOffset[0] = Math.max(0, centeringOffset[0]);
  51865. centeringOffset[1] = Math.max(0, centeringOffset[1]);
  51866. svg.select('.outer-group').attr('transform', 'translate(' + centeringOffset + ')');
  51867. if (axisConfig.title) {
  51868. var title = svg.select('g.title-group text').style(fontStyle).text(axisConfig.title);
  51869. var titleBBox = title.node().getBBox();
  51870. title.attr({
  51871. x: chartCenter[0] - titleBBox.width / 2,
  51872. y: chartCenter[1] - radius - 20
  51873. });
  51874. }
  51875. var radialAxis = svg.select('.radial.axis-group');
  51876. if (axisConfig.radialAxis.gridLinesVisible) {
  51877. var gridCircles = radialAxis.selectAll('circle.grid-circle').data(radialScale.ticks(5));
  51878. gridCircles.enter().append('circle').attr({
  51879. 'class': 'grid-circle'
  51880. }).style(lineStyle);
  51881. gridCircles.attr('r', radialScale);
  51882. gridCircles.exit().remove();
  51883. }
  51884. radialAxis.select('circle.outside-circle').attr({
  51885. r: radius
  51886. }).style(lineStyle);
  51887. var backgroundCircle = svg.select('circle.background-circle').attr({
  51888. r: radius
  51889. }).style({
  51890. fill: axisConfig.backgroundColor,
  51891. stroke: axisConfig.stroke
  51892. });
  51893. function currentAngle(d, i) {
  51894. return angularScale(d) % 360 + axisConfig.orientation;
  51895. }
  51896. if (axisConfig.radialAxis.visible) {
  51897. var axis = d3.svg.axis().scale(radialScale).ticks(5).tickSize(5);
  51898. radialAxis.call(axis).attr({
  51899. transform: 'rotate(' + axisConfig.radialAxis.orientation + ')'
  51900. });
  51901. radialAxis.selectAll('.domain').style(lineStyle);
  51902. radialAxis.selectAll('g>text').text(function(d, i) {
  51903. return this.textContent + axisConfig.radialAxis.ticksSuffix;
  51904. }).style(fontStyle).style({
  51905. 'text-anchor': 'start'
  51906. }).attr({
  51907. x: 0,
  51908. y: 0,
  51909. dx: 0,
  51910. dy: 0,
  51911. transform: function(d, i) {
  51912. if (axisConfig.radialAxis.tickOrientation === 'horizontal') {
  51913. return 'rotate(' + -axisConfig.radialAxis.orientation + ') translate(' + [ 0, fontStyle['font-size'] ] + ')';
  51914. } else return 'translate(' + [ 0, fontStyle['font-size'] ] + ')';
  51915. }
  51916. });
  51917. radialAxis.selectAll('g>line').style({
  51918. stroke: 'black'
  51919. });
  51920. }
  51921. var angularAxis = svg.select('.angular.axis-group').selectAll('g.angular-tick').data(angularAxisRange);
  51922. var angularAxisEnter = angularAxis.enter().append('g').classed('angular-tick', true);
  51923. angularAxis.attr({
  51924. transform: function(d, i) {
  51925. return 'rotate(' + currentAngle(d, i) + ')';
  51926. }
  51927. }).style({
  51928. display: axisConfig.angularAxis.visible ? 'block' : 'none'
  51929. });
  51930. angularAxis.exit().remove();
  51931. angularAxisEnter.append('line').classed('grid-line', true).classed('major', function(d, i) {
  51932. return i % (axisConfig.minorTicks + 1) == 0;
  51933. }).classed('minor', function(d, i) {
  51934. return !(i % (axisConfig.minorTicks + 1) == 0);
  51935. }).style(lineStyle);
  51936. angularAxisEnter.selectAll('.minor').style({
  51937. stroke: axisConfig.minorTickColor
  51938. });
  51939. angularAxis.select('line.grid-line').attr({
  51940. x1: axisConfig.tickLength ? radius - axisConfig.tickLength : 0,
  51941. x2: radius
  51942. }).style({
  51943. display: axisConfig.angularAxis.gridLinesVisible ? 'block' : 'none'
  51944. });
  51945. angularAxisEnter.append('text').classed('axis-text', true).style(fontStyle);
  51946. var ticksText = angularAxis.select('text.axis-text').attr({
  51947. x: radius + axisConfig.labelOffset,
  51948. dy: MID_SHIFT + 'em',
  51949. transform: function(d, i) {
  51950. var angle = currentAngle(d, i);
  51951. var rad = radius + axisConfig.labelOffset;
  51952. var orient = axisConfig.angularAxis.tickOrientation;
  51953. if (orient == 'horizontal') return 'rotate(' + -angle + ' ' + rad + ' 0)'; else if (orient == 'radial') return angle < 270 && angle > 90 ? 'rotate(180 ' + rad + ' 0)' : null; else return 'rotate(' + (angle <= 180 && angle > 0 ? -90 : 90) + ' ' + rad + ' 0)';
  51954. }
  51955. }).style({
  51956. 'text-anchor': 'middle',
  51957. display: axisConfig.angularAxis.labelsVisible ? 'block' : 'none'
  51958. }).text(function(d, i) {
  51959. if (i % (axisConfig.minorTicks + 1) != 0) return '';
  51960. if (ticks) {
  51961. return ticks[d] + axisConfig.angularAxis.ticksSuffix;
  51962. } else return d + axisConfig.angularAxis.ticksSuffix;
  51963. }).style(fontStyle);
  51964. if (axisConfig.angularAxis.rewriteTicks) ticksText.text(function(d, i) {
  51965. if (i % (axisConfig.minorTicks + 1) != 0) return '';
  51966. return axisConfig.angularAxis.rewriteTicks(this.textContent, i);
  51967. });
  51968. var rightmostTickEndX = d3.max(chartGroup.selectAll('.angular-tick text')[0].map(function(d, i) {
  51969. return d.getCTM().e + d.getBBox().width;
  51970. }));
  51971. legendContainer.attr({
  51972. transform: 'translate(' + [ radius + rightmostTickEndX, axisConfig.margin.top ] + ')'
  51973. });
  51974. var hasGeometry = svg.select('g.geometry-group').selectAll('g').size() > 0;
  51975. var geometryContainer = svg.select('g.geometry-group').selectAll('g.geometry').data(data);
  51976. geometryContainer.enter().append('g').attr({
  51977. 'class': function(d, i) {
  51978. return 'geometry geometry' + i;
  51979. }
  51980. });
  51981. geometryContainer.exit().remove();
  51982. if (data[0] || hasGeometry) {
  51983. var geometryConfigs = [];
  51984. data.forEach(function(d, i) {
  51985. var geometryConfig = {};
  51986. geometryConfig.radialScale = radialScale;
  51987. geometryConfig.angularScale = angularScale;
  51988. geometryConfig.container = geometryContainer.filter(function(dB, iB) {
  51989. return iB == i;
  51990. });
  51991. geometryConfig.geometry = d.geometry;
  51992. geometryConfig.orientation = axisConfig.orientation;
  51993. geometryConfig.direction = axisConfig.direction;
  51994. geometryConfig.index = i;
  51995. geometryConfigs.push({
  51996. data: d,
  51997. geometryConfig: geometryConfig
  51998. });
  51999. });
  52000. var geometryConfigsGrouped = d3.nest().key(function(d, i) {
  52001. return typeof d.data.groupId != 'undefined' || 'unstacked';
  52002. }).entries(geometryConfigs);
  52003. var geometryConfigsGrouped2 = [];
  52004. geometryConfigsGrouped.forEach(function(d, i) {
  52005. if (d.key === 'unstacked') geometryConfigsGrouped2 = geometryConfigsGrouped2.concat(d.values.map(function(d, i) {
  52006. return [ d ];
  52007. })); else geometryConfigsGrouped2.push(d.values);
  52008. });
  52009. geometryConfigsGrouped2.forEach(function(d, i) {
  52010. var geometry;
  52011. if (Array.isArray(d)) geometry = d[0].geometryConfig.geometry; else geometry = d.geometryConfig.geometry;
  52012. var finalGeometryConfig = d.map(function(dB, iB) {
  52013. return extendDeepAll(µ[geometry].defaultConfig(), dB);
  52014. });
  52015. µ[geometry]().config(finalGeometryConfig)();
  52016. });
  52017. }
  52018. var guides = svg.select('.guides-group');
  52019. var tooltipContainer = svg.select('.tooltips-group');
  52020. var angularTooltip = µ.tooltipPanel().config({
  52021. container: tooltipContainer,
  52022. fontSize: 8
  52023. })();
  52024. var radialTooltip = µ.tooltipPanel().config({
  52025. container: tooltipContainer,
  52026. fontSize: 8
  52027. })();
  52028. var geometryTooltip = µ.tooltipPanel().config({
  52029. container: tooltipContainer,
  52030. hasTick: true
  52031. })();
  52032. var angularValue, radialValue;
  52033. if (!isOrdinal) {
  52034. var angularGuideLine = guides.select('line').attr({
  52035. x1: 0,
  52036. y1: 0,
  52037. y2: 0
  52038. }).style({
  52039. stroke: 'grey',
  52040. 'pointer-events': 'none'
  52041. });
  52042. chartGroup.on('mousemove.angular-guide', function(d, i) {
  52043. var mouseAngle = µ.util.getMousePos(backgroundCircle).angle;
  52044. angularGuideLine.attr({
  52045. x2: -radius,
  52046. transform: 'rotate(' + mouseAngle + ')'
  52047. }).style({
  52048. opacity: .5
  52049. });
  52050. var angleWithOriginOffset = (mouseAngle + 180 + 360 - axisConfig.orientation) % 360;
  52051. angularValue = angularScale.invert(angleWithOriginOffset);
  52052. var pos = µ.util.convertToCartesian(radius + 12, mouseAngle + 180);
  52053. angularTooltip.text(µ.util.round(angularValue)).move([ pos[0] + chartCenter[0], pos[1] + chartCenter[1] ]);
  52054. }).on('mouseout.angular-guide', function(d, i) {
  52055. guides.select('line').style({
  52056. opacity: 0
  52057. });
  52058. });
  52059. }
  52060. var angularGuideCircle = guides.select('circle').style({
  52061. stroke: 'grey',
  52062. fill: 'none'
  52063. });
  52064. chartGroup.on('mousemove.radial-guide', function(d, i) {
  52065. var r = µ.util.getMousePos(backgroundCircle).radius;
  52066. angularGuideCircle.attr({
  52067. r: r
  52068. }).style({
  52069. opacity: .5
  52070. });
  52071. radialValue = radialScale.invert(µ.util.getMousePos(backgroundCircle).radius);
  52072. var pos = µ.util.convertToCartesian(r, axisConfig.radialAxis.orientation);
  52073. radialTooltip.text(µ.util.round(radialValue)).move([ pos[0] + chartCenter[0], pos[1] + chartCenter[1] ]);
  52074. }).on('mouseout.radial-guide', function(d, i) {
  52075. angularGuideCircle.style({
  52076. opacity: 0
  52077. });
  52078. geometryTooltip.hide();
  52079. angularTooltip.hide();
  52080. radialTooltip.hide();
  52081. });
  52082. svg.selectAll('.geometry-group .mark').on('mouseover.tooltip', function(d, i) {
  52083. var el = d3.select(this);
  52084. var color = this.style.fill;
  52085. var newColor = 'black';
  52086. var opacity = this.style.opacity || 1;
  52087. el.attr({
  52088. 'data-opacity': opacity
  52089. });
  52090. if (color && color !== 'none') {
  52091. el.attr({
  52092. 'data-fill': color
  52093. });
  52094. newColor = d3.hsl(color).darker().toString();
  52095. el.style({
  52096. fill: newColor,
  52097. opacity: 1
  52098. });
  52099. var textData = {
  52100. t: µ.util.round(d[0]),
  52101. r: µ.util.round(d[1])
  52102. };
  52103. if (isOrdinal) textData.t = ticks[d[0]];
  52104. var text = 't: ' + textData.t + ', r: ' + textData.r;
  52105. var bbox = this.getBoundingClientRect();
  52106. var svgBBox = svg.node().getBoundingClientRect();
  52107. var pos = [ bbox.left + bbox.width / 2 - centeringOffset[0] - svgBBox.left, bbox.top + bbox.height / 2 - centeringOffset[1] - svgBBox.top ];
  52108. geometryTooltip.config({
  52109. color: newColor
  52110. }).text(text);
  52111. geometryTooltip.move(pos);
  52112. } else {
  52113. color = this.style.stroke || 'black';
  52114. el.attr({
  52115. 'data-stroke': color
  52116. });
  52117. newColor = d3.hsl(color).darker().toString();
  52118. el.style({
  52119. stroke: newColor,
  52120. opacity: 1
  52121. });
  52122. }
  52123. }).on('mousemove.tooltip', function(d, i) {
  52124. if (d3.event.which != 0) return false;
  52125. if (d3.select(this).attr('data-fill')) geometryTooltip.show();
  52126. }).on('mouseout.tooltip', function(d, i) {
  52127. geometryTooltip.hide();
  52128. var el = d3.select(this);
  52129. var fillColor = el.attr('data-fill');
  52130. if (fillColor) el.style({
  52131. fill: fillColor,
  52132. opacity: el.attr('data-opacity')
  52133. }); else el.style({
  52134. stroke: el.attr('data-stroke'),
  52135. opacity: el.attr('data-opacity')
  52136. });
  52137. });
  52138. });
  52139. return exports;
  52140. }
  52141. exports.render = function(_container) {
  52142. render(_container);
  52143. return this;
  52144. };
  52145. exports.config = function(_x) {
  52146. if (!arguments.length) return config;
  52147. var xClone = µ.util.cloneJson(_x);
  52148. xClone.data.forEach(function(d, i) {
  52149. if (!config.data[i]) config.data[i] = {};
  52150. extendDeepAll(config.data[i], µ.Axis.defaultConfig().data[0]);
  52151. extendDeepAll(config.data[i], d);
  52152. });
  52153. extendDeepAll(config.layout, µ.Axis.defaultConfig().layout);
  52154. extendDeepAll(config.layout, xClone.layout);
  52155. return this;
  52156. };
  52157. exports.getLiveConfig = function() {
  52158. return liveConfig;
  52159. };
  52160. exports.getinputConfig = function() {
  52161. return inputConfig;
  52162. };
  52163. exports.radialScale = function(_x) {
  52164. return radialScale;
  52165. };
  52166. exports.angularScale = function(_x) {
  52167. return angularScale;
  52168. };
  52169. exports.svg = function() {
  52170. return svg;
  52171. };
  52172. d3.rebind(exports, dispatch, 'on');
  52173. return exports;
  52174. };
  52175. µ.Axis.defaultConfig = function(d, i) {
  52176. var config = {
  52177. data: [ {
  52178. t: [ 1, 2, 3, 4 ],
  52179. r: [ 10, 11, 12, 13 ],
  52180. name: 'Line1',
  52181. geometry: 'LinePlot',
  52182. color: null,
  52183. strokeDash: 'solid',
  52184. strokeColor: null,
  52185. strokeSize: '1',
  52186. visibleInLegend: true,
  52187. opacity: 1
  52188. } ],
  52189. layout: {
  52190. defaultColorRange: d3.scale.category10().range(),
  52191. title: null,
  52192. height: 450,
  52193. width: 500,
  52194. margin: {
  52195. top: 40,
  52196. right: 40,
  52197. bottom: 40,
  52198. left: 40
  52199. },
  52200. font: {
  52201. size: 12,
  52202. color: 'gray',
  52203. outlineColor: 'white',
  52204. family: 'Tahoma, sans-serif'
  52205. },
  52206. direction: 'clockwise',
  52207. orientation: 0,
  52208. labelOffset: 10,
  52209. radialAxis: {
  52210. domain: null,
  52211. orientation: -45,
  52212. ticksSuffix: '',
  52213. visible: true,
  52214. gridLinesVisible: true,
  52215. tickOrientation: 'horizontal',
  52216. rewriteTicks: null
  52217. },
  52218. angularAxis: {
  52219. domain: [ 0, 360 ],
  52220. ticksSuffix: '',
  52221. visible: true,
  52222. gridLinesVisible: true,
  52223. labelsVisible: true,
  52224. tickOrientation: 'horizontal',
  52225. rewriteTicks: null,
  52226. ticksCount: null,
  52227. ticksStep: null
  52228. },
  52229. minorTicks: 0,
  52230. tickLength: null,
  52231. tickColor: 'silver',
  52232. minorTickColor: '#eee',
  52233. backgroundColor: 'none',
  52234. needsEndSpacing: null,
  52235. showLegend: true,
  52236. legend: {
  52237. reverseOrder: false
  52238. },
  52239. opacity: 1
  52240. }
  52241. };
  52242. return config;
  52243. };
  52244. µ.util = {};
  52245. µ.DATAEXTENT = 'dataExtent';
  52246. µ.AREA = 'AreaChart';
  52247. µ.LINE = 'LinePlot';
  52248. µ.DOT = 'DotPlot';
  52249. µ.BAR = 'BarChart';
  52250. µ.util._override = function(_objA, _objB) {
  52251. for (var x in _objA) if (x in _objB) _objB[x] = _objA[x];
  52252. };
  52253. µ.util._extend = function(_objA, _objB) {
  52254. for (var x in _objA) _objB[x] = _objA[x];
  52255. };
  52256. µ.util._rndSnd = function() {
  52257. return Math.random() * 2 - 1 + (Math.random() * 2 - 1) + (Math.random() * 2 - 1);
  52258. };
  52259. µ.util.dataFromEquation2 = function(_equation, _step) {
  52260. var step = _step || 6;
  52261. var data = d3.range(0, 360 + step, step).map(function(deg, index) {
  52262. var theta = deg * Math.PI / 180;
  52263. var radius = _equation(theta);
  52264. return [ deg, radius ];
  52265. });
  52266. return data;
  52267. };
  52268. µ.util.dataFromEquation = function(_equation, _step, _name) {
  52269. var step = _step || 6;
  52270. var t = [], r = [];
  52271. d3.range(0, 360 + step, step).forEach(function(deg, index) {
  52272. var theta = deg * Math.PI / 180;
  52273. var radius = _equation(theta);
  52274. t.push(deg);
  52275. r.push(radius);
  52276. });
  52277. var result = {
  52278. t: t,
  52279. r: r
  52280. };
  52281. if (_name) result.name = _name;
  52282. return result;
  52283. };
  52284. µ.util.ensureArray = function(_val, _count) {
  52285. if (typeof _val === 'undefined') return null;
  52286. var arr = [].concat(_val);
  52287. return d3.range(_count).map(function(d, i) {
  52288. return arr[i] || arr[0];
  52289. });
  52290. };
  52291. µ.util.fillArrays = function(_obj, _valueNames, _count) {
  52292. _valueNames.forEach(function(d, i) {
  52293. _obj[d] = µ.util.ensureArray(_obj[d], _count);
  52294. });
  52295. return _obj;
  52296. };
  52297. µ.util.cloneJson = function(json) {
  52298. return JSON.parse(JSON.stringify(json));
  52299. };
  52300. µ.util.validateKeys = function(obj, keys) {
  52301. if (typeof keys === 'string') keys = keys.split('.');
  52302. var next = keys.shift();
  52303. return obj[next] && (!keys.length || objHasKeys(obj[next], keys));
  52304. };
  52305. µ.util.sumArrays = function(a, b) {
  52306. return d3.zip(a, b).map(function(d, i) {
  52307. return d3.sum(d);
  52308. });
  52309. };
  52310. µ.util.arrayLast = function(a) {
  52311. return a[a.length - 1];
  52312. };
  52313. µ.util.arrayEqual = function(a, b) {
  52314. var i = Math.max(a.length, b.length, 1);
  52315. while (i-- >= 0 && a[i] === b[i]) ;
  52316. return i === -2;
  52317. };
  52318. µ.util.flattenArray = function(arr) {
  52319. var r = [];
  52320. while (!µ.util.arrayEqual(r, arr)) {
  52321. r = arr;
  52322. arr = [].concat.apply([], arr);
  52323. }
  52324. return arr;
  52325. };
  52326. µ.util.deduplicate = function(arr) {
  52327. return arr.filter(function(v, i, a) {
  52328. return a.indexOf(v) == i;
  52329. });
  52330. };
  52331. µ.util.convertToCartesian = function(radius, theta) {
  52332. var thetaRadians = theta * Math.PI / 180;
  52333. var x = radius * Math.cos(thetaRadians);
  52334. var y = radius * Math.sin(thetaRadians);
  52335. return [ x, y ];
  52336. };
  52337. µ.util.round = function(_value, _digits) {
  52338. var digits = _digits || 2;
  52339. var mult = Math.pow(10, digits);
  52340. return Math.round(_value * mult) / mult;
  52341. };
  52342. µ.util.getMousePos = function(_referenceElement) {
  52343. var mousePos = d3.mouse(_referenceElement.node());
  52344. var mouseX = mousePos[0];
  52345. var mouseY = mousePos[1];
  52346. var mouse = {};
  52347. mouse.x = mouseX;
  52348. mouse.y = mouseY;
  52349. mouse.pos = mousePos;
  52350. mouse.angle = (Math.atan2(mouseY, mouseX) + Math.PI) * 180 / Math.PI;
  52351. mouse.radius = Math.sqrt(mouseX * mouseX + mouseY * mouseY);
  52352. return mouse;
  52353. };
  52354. µ.util.duplicatesCount = function(arr) {
  52355. var uniques = {}, val;
  52356. var dups = {};
  52357. for (var i = 0, len = arr.length; i < len; i++) {
  52358. val = arr[i];
  52359. if (val in uniques) {
  52360. uniques[val]++;
  52361. dups[val] = uniques[val];
  52362. } else {
  52363. uniques[val] = 1;
  52364. }
  52365. }
  52366. return dups;
  52367. };
  52368. µ.util.duplicates = function(arr) {
  52369. return Object.keys(µ.util.duplicatesCount(arr));
  52370. };
  52371. µ.util.translator = function(obj, sourceBranch, targetBranch, reverse) {
  52372. if (reverse) {
  52373. var targetBranchCopy = targetBranch.slice();
  52374. targetBranch = sourceBranch;
  52375. sourceBranch = targetBranchCopy;
  52376. }
  52377. var value = sourceBranch.reduce(function(previousValue, currentValue) {
  52378. if (typeof previousValue != 'undefined') return previousValue[currentValue];
  52379. }, obj);
  52380. if (typeof value === 'undefined') return;
  52381. sourceBranch.reduce(function(previousValue, currentValue, index) {
  52382. if (typeof previousValue == 'undefined') return;
  52383. if (index === sourceBranch.length - 1) delete previousValue[currentValue];
  52384. return previousValue[currentValue];
  52385. }, obj);
  52386. targetBranch.reduce(function(previousValue, currentValue, index) {
  52387. if (typeof previousValue[currentValue] === 'undefined') previousValue[currentValue] = {};
  52388. if (index === targetBranch.length - 1) previousValue[currentValue] = value;
  52389. return previousValue[currentValue];
  52390. }, obj);
  52391. };
  52392. µ.PolyChart = function module() {
  52393. var config = [ µ.PolyChart.defaultConfig() ];
  52394. var dispatch = d3.dispatch('hover');
  52395. var dashArray = {
  52396. solid: 'none',
  52397. dash: [ 5, 2 ],
  52398. dot: [ 2, 5 ]
  52399. };
  52400. var colorScale;
  52401. function exports() {
  52402. var geometryConfig = config[0].geometryConfig;
  52403. var container = geometryConfig.container;
  52404. if (typeof container == 'string') container = d3.select(container);
  52405. container.datum(config).each(function(_config, _index) {
  52406. var isStack = !!_config[0].data.yStack;
  52407. var data = _config.map(function(d, i) {
  52408. if (isStack) return d3.zip(d.data.t[0], d.data.r[0], d.data.yStack[0]); else return d3.zip(d.data.t[0], d.data.r[0]);
  52409. });
  52410. var angularScale = geometryConfig.angularScale;
  52411. var domainMin = geometryConfig.radialScale.domain()[0];
  52412. var generator = {};
  52413. generator.bar = function(d, i, pI) {
  52414. var dataConfig = _config[pI].data;
  52415. var h = geometryConfig.radialScale(d[1]) - geometryConfig.radialScale(0);
  52416. var stackTop = geometryConfig.radialScale(d[2] || 0);
  52417. var w = dataConfig.barWidth;
  52418. d3.select(this).attr({
  52419. 'class': 'mark bar',
  52420. d: 'M' + [ [ h + stackTop, -w / 2 ], [ h + stackTop, w / 2 ], [ stackTop, w / 2 ], [ stackTop, -w / 2 ] ].join('L') + 'Z',
  52421. transform: function(d, i) {
  52422. return 'rotate(' + (geometryConfig.orientation + angularScale(d[0])) + ')';
  52423. }
  52424. });
  52425. };
  52426. generator.dot = function(d, i, pI) {
  52427. var stackedData = d[2] ? [ d[0], d[1] + d[2] ] : d;
  52428. var symbol = d3.svg.symbol().size(_config[pI].data.dotSize).type(_config[pI].data.dotType)(d, i);
  52429. d3.select(this).attr({
  52430. 'class': 'mark dot',
  52431. d: symbol,
  52432. transform: function(d, i) {
  52433. var coord = convertToCartesian(getPolarCoordinates(stackedData));
  52434. return 'translate(' + [ coord.x, coord.y ] + ')';
  52435. }
  52436. });
  52437. };
  52438. var line = d3.svg.line.radial().interpolate(_config[0].data.lineInterpolation).radius(function(d) {
  52439. return geometryConfig.radialScale(d[1]);
  52440. }).angle(function(d) {
  52441. return geometryConfig.angularScale(d[0]) * Math.PI / 180;
  52442. });
  52443. generator.line = function(d, i, pI) {
  52444. var lineData = d[2] ? data[pI].map(function(d, i) {
  52445. return [ d[0], d[1] + d[2] ];
  52446. }) : data[pI];
  52447. d3.select(this).each(generator['dot']).style({
  52448. opacity: function(dB, iB) {
  52449. return +_config[pI].data.dotVisible;
  52450. },
  52451. fill: markStyle.stroke(d, i, pI)
  52452. }).attr({
  52453. 'class': 'mark dot'
  52454. });
  52455. if (i > 0) return;
  52456. var lineSelection = d3.select(this.parentNode).selectAll('path.line').data([ 0 ]);
  52457. lineSelection.enter().insert('path');
  52458. lineSelection.attr({
  52459. 'class': 'line',
  52460. d: line(lineData),
  52461. transform: function(dB, iB) {
  52462. return 'rotate(' + (geometryConfig.orientation + 90) + ')';
  52463. },
  52464. 'pointer-events': 'none'
  52465. }).style({
  52466. fill: function(dB, iB) {
  52467. return markStyle.fill(d, i, pI);
  52468. },
  52469. 'fill-opacity': 0,
  52470. stroke: function(dB, iB) {
  52471. return markStyle.stroke(d, i, pI);
  52472. },
  52473. 'stroke-width': function(dB, iB) {
  52474. return markStyle['stroke-width'](d, i, pI);
  52475. },
  52476. 'stroke-dasharray': function(dB, iB) {
  52477. return markStyle['stroke-dasharray'](d, i, pI);
  52478. },
  52479. opacity: function(dB, iB) {
  52480. return markStyle.opacity(d, i, pI);
  52481. },
  52482. display: function(dB, iB) {
  52483. return markStyle.display(d, i, pI);
  52484. }
  52485. });
  52486. };
  52487. var angularRange = geometryConfig.angularScale.range();
  52488. var triangleAngle = Math.abs(angularRange[1] - angularRange[0]) / data[0].length * Math.PI / 180;
  52489. var arc = d3.svg.arc().startAngle(function(d) {
  52490. return -triangleAngle / 2;
  52491. }).endAngle(function(d) {
  52492. return triangleAngle / 2;
  52493. }).innerRadius(function(d) {
  52494. return geometryConfig.radialScale(domainMin + (d[2] || 0));
  52495. }).outerRadius(function(d) {
  52496. return geometryConfig.radialScale(domainMin + (d[2] || 0)) + geometryConfig.radialScale(d[1]);
  52497. });
  52498. generator.arc = function(d, i, pI) {
  52499. d3.select(this).attr({
  52500. 'class': 'mark arc',
  52501. d: arc,
  52502. transform: function(d, i) {
  52503. return 'rotate(' + (geometryConfig.orientation + angularScale(d[0]) + 90) + ')';
  52504. }
  52505. });
  52506. };
  52507. var markStyle = {
  52508. fill: function(d, i, pI) {
  52509. return _config[pI].data.color;
  52510. },
  52511. stroke: function(d, i, pI) {
  52512. return _config[pI].data.strokeColor;
  52513. },
  52514. 'stroke-width': function(d, i, pI) {
  52515. return _config[pI].data.strokeSize + 'px';
  52516. },
  52517. 'stroke-dasharray': function(d, i, pI) {
  52518. return dashArray[_config[pI].data.strokeDash];
  52519. },
  52520. opacity: function(d, i, pI) {
  52521. return _config[pI].data.opacity;
  52522. },
  52523. display: function(d, i, pI) {
  52524. return typeof _config[pI].data.visible === 'undefined' || _config[pI].data.visible ? 'block' : 'none';
  52525. }
  52526. };
  52527. var geometryLayer = d3.select(this).selectAll('g.layer').data(data);
  52528. geometryLayer.enter().append('g').attr({
  52529. 'class': 'layer'
  52530. });
  52531. var geometry = geometryLayer.selectAll('path.mark').data(function(d, i) {
  52532. return d;
  52533. });
  52534. geometry.enter().append('path').attr({
  52535. 'class': 'mark'
  52536. });
  52537. geometry.style(markStyle).each(generator[geometryConfig.geometryType]);
  52538. geometry.exit().remove();
  52539. geometryLayer.exit().remove();
  52540. function getPolarCoordinates(d, i) {
  52541. var r = geometryConfig.radialScale(d[1]);
  52542. var t = (geometryConfig.angularScale(d[0]) + geometryConfig.orientation) * Math.PI / 180;
  52543. return {
  52544. r: r,
  52545. t: t
  52546. };
  52547. }
  52548. function convertToCartesian(polarCoordinates) {
  52549. var x = polarCoordinates.r * Math.cos(polarCoordinates.t);
  52550. var y = polarCoordinates.r * Math.sin(polarCoordinates.t);
  52551. return {
  52552. x: x,
  52553. y: y
  52554. };
  52555. }
  52556. });
  52557. }
  52558. exports.config = function(_x) {
  52559. if (!arguments.length) return config;
  52560. _x.forEach(function(d, i) {
  52561. if (!config[i]) config[i] = {};
  52562. extendDeepAll(config[i], µ.PolyChart.defaultConfig());
  52563. extendDeepAll(config[i], d);
  52564. });
  52565. return this;
  52566. };
  52567. exports.getColorScale = function() {
  52568. return colorScale;
  52569. };
  52570. d3.rebind(exports, dispatch, 'on');
  52571. return exports;
  52572. };
  52573. µ.PolyChart.defaultConfig = function() {
  52574. var config = {
  52575. data: {
  52576. name: 'geom1',
  52577. t: [ [ 1, 2, 3, 4 ] ],
  52578. r: [ [ 1, 2, 3, 4 ] ],
  52579. dotType: 'circle',
  52580. dotSize: 64,
  52581. dotVisible: false,
  52582. barWidth: 20,
  52583. color: '#ffa500',
  52584. strokeSize: 1,
  52585. strokeColor: 'silver',
  52586. strokeDash: 'solid',
  52587. opacity: 1,
  52588. index: 0,
  52589. visible: true,
  52590. visibleInLegend: true
  52591. },
  52592. geometryConfig: {
  52593. geometry: 'LinePlot',
  52594. geometryType: 'arc',
  52595. direction: 'clockwise',
  52596. orientation: 0,
  52597. container: 'body',
  52598. radialScale: null,
  52599. angularScale: null,
  52600. colorScale: d3.scale.category20()
  52601. }
  52602. };
  52603. return config;
  52604. };
  52605. µ.BarChart = function module() {
  52606. return µ.PolyChart();
  52607. };
  52608. µ.BarChart.defaultConfig = function() {
  52609. var config = {
  52610. geometryConfig: {
  52611. geometryType: 'bar'
  52612. }
  52613. };
  52614. return config;
  52615. };
  52616. µ.AreaChart = function module() {
  52617. return µ.PolyChart();
  52618. };
  52619. µ.AreaChart.defaultConfig = function() {
  52620. var config = {
  52621. geometryConfig: {
  52622. geometryType: 'arc'
  52623. }
  52624. };
  52625. return config;
  52626. };
  52627. µ.DotPlot = function module() {
  52628. return µ.PolyChart();
  52629. };
  52630. µ.DotPlot.defaultConfig = function() {
  52631. var config = {
  52632. geometryConfig: {
  52633. geometryType: 'dot',
  52634. dotType: 'circle'
  52635. }
  52636. };
  52637. return config;
  52638. };
  52639. µ.LinePlot = function module() {
  52640. return µ.PolyChart();
  52641. };
  52642. µ.LinePlot.defaultConfig = function() {
  52643. var config = {
  52644. geometryConfig: {
  52645. geometryType: 'line'
  52646. }
  52647. };
  52648. return config;
  52649. };
  52650. µ.Legend = function module() {
  52651. var config = µ.Legend.defaultConfig();
  52652. var dispatch = d3.dispatch('hover');
  52653. function exports() {
  52654. var legendConfig = config.legendConfig;
  52655. var flattenData = config.data.map(function(d, i) {
  52656. return [].concat(d).map(function(dB, iB) {
  52657. var element = extendDeepAll({}, legendConfig.elements[i]);
  52658. element.name = dB;
  52659. element.color = [].concat(legendConfig.elements[i].color)[iB];
  52660. return element;
  52661. });
  52662. });
  52663. var data = d3.merge(flattenData);
  52664. data = data.filter(function(d, i) {
  52665. return legendConfig.elements[i] && (legendConfig.elements[i].visibleInLegend || typeof legendConfig.elements[i].visibleInLegend === 'undefined');
  52666. });
  52667. if (legendConfig.reverseOrder) data = data.reverse();
  52668. var container = legendConfig.container;
  52669. if (typeof container == 'string' || container.nodeName) container = d3.select(container);
  52670. var colors = data.map(function(d, i) {
  52671. return d.color;
  52672. });
  52673. var lineHeight = legendConfig.fontSize;
  52674. var isContinuous = legendConfig.isContinuous == null ? typeof data[0] === 'number' : legendConfig.isContinuous;
  52675. var height = isContinuous ? legendConfig.height : lineHeight * data.length;
  52676. var legendContainerGroup = container.classed('legend-group', true);
  52677. var svg = legendContainerGroup.selectAll('svg').data([ 0 ]);
  52678. var svgEnter = svg.enter().append('svg').attr({
  52679. width: 300,
  52680. height: height + lineHeight,
  52681. xmlns: 'http://www.w3.org/2000/svg',
  52682. 'xmlns:xlink': 'http://www.w3.org/1999/xlink',
  52683. version: '1.1'
  52684. });
  52685. svgEnter.append('g').classed('legend-axis', true);
  52686. svgEnter.append('g').classed('legend-marks', true);
  52687. var dataNumbered = d3.range(data.length);
  52688. var colorScale = d3.scale[isContinuous ? 'linear' : 'ordinal']().domain(dataNumbered).range(colors);
  52689. var dataScale = d3.scale[isContinuous ? 'linear' : 'ordinal']().domain(dataNumbered)[isContinuous ? 'range' : 'rangePoints']([ 0, height ]);
  52690. var shapeGenerator = function(_type, _size) {
  52691. var squareSize = _size * 3;
  52692. if (_type === 'line') {
  52693. return 'M' + [ [ -_size / 2, -_size / 12 ], [ _size / 2, -_size / 12 ], [ _size / 2, _size / 12 ], [ -_size / 2, _size / 12 ] ] + 'Z';
  52694. } else if (d3.svg.symbolTypes.indexOf(_type) != -1) return d3.svg.symbol().type(_type).size(squareSize)(); else return d3.svg.symbol().type('square').size(squareSize)();
  52695. };
  52696. if (isContinuous) {
  52697. var gradient = svg.select('.legend-marks').append('defs').append('linearGradient').attr({
  52698. id: 'grad1',
  52699. x1: '0%',
  52700. y1: '0%',
  52701. x2: '0%',
  52702. y2: '100%'
  52703. }).selectAll('stop').data(colors);
  52704. gradient.enter().append('stop');
  52705. gradient.attr({
  52706. offset: function(d, i) {
  52707. return i / (colors.length - 1) * 100 + '%';
  52708. }
  52709. }).style({
  52710. 'stop-color': function(d, i) {
  52711. return d;
  52712. }
  52713. });
  52714. svg.append('rect').classed('legend-mark', true).attr({
  52715. height: legendConfig.height,
  52716. width: legendConfig.colorBandWidth,
  52717. fill: 'url(#grad1)'
  52718. });
  52719. } else {
  52720. var legendElement = svg.select('.legend-marks').selectAll('path.legend-mark').data(data);
  52721. legendElement.enter().append('path').classed('legend-mark', true);
  52722. legendElement.attr({
  52723. transform: function(d, i) {
  52724. return 'translate(' + [ lineHeight / 2, dataScale(i) + lineHeight / 2 ] + ')';
  52725. },
  52726. d: function(d, i) {
  52727. var symbolType = d.symbol;
  52728. return shapeGenerator(symbolType, lineHeight);
  52729. },
  52730. fill: function(d, i) {
  52731. return colorScale(i);
  52732. }
  52733. });
  52734. legendElement.exit().remove();
  52735. }
  52736. var legendAxis = d3.svg.axis().scale(dataScale).orient('right');
  52737. var axis = svg.select('g.legend-axis').attr({
  52738. transform: 'translate(' + [ isContinuous ? legendConfig.colorBandWidth : lineHeight, lineHeight / 2 ] + ')'
  52739. }).call(legendAxis);
  52740. axis.selectAll('.domain').style({
  52741. fill: 'none',
  52742. stroke: 'none'
  52743. });
  52744. axis.selectAll('line').style({
  52745. fill: 'none',
  52746. stroke: isContinuous ? legendConfig.textColor : 'none'
  52747. });
  52748. axis.selectAll('text').style({
  52749. fill: legendConfig.textColor,
  52750. 'font-size': legendConfig.fontSize
  52751. }).text(function(d, i) {
  52752. return data[i].name;
  52753. });
  52754. return exports;
  52755. }
  52756. exports.config = function(_x) {
  52757. if (!arguments.length) return config;
  52758. extendDeepAll(config, _x);
  52759. return this;
  52760. };
  52761. d3.rebind(exports, dispatch, 'on');
  52762. return exports;
  52763. };
  52764. µ.Legend.defaultConfig = function(d, i) {
  52765. var config = {
  52766. data: [ 'a', 'b', 'c' ],
  52767. legendConfig: {
  52768. elements: [ {
  52769. symbol: 'line',
  52770. color: 'red'
  52771. }, {
  52772. symbol: 'square',
  52773. color: 'yellow'
  52774. }, {
  52775. symbol: 'diamond',
  52776. color: 'limegreen'
  52777. } ],
  52778. height: 150,
  52779. colorBandWidth: 30,
  52780. fontSize: 12,
  52781. container: 'body',
  52782. isContinuous: null,
  52783. textColor: 'grey',
  52784. reverseOrder: false
  52785. }
  52786. };
  52787. return config;
  52788. };
  52789. µ.tooltipPanel = function() {
  52790. var tooltipEl, tooltipTextEl, backgroundEl;
  52791. var config = {
  52792. container: null,
  52793. hasTick: false,
  52794. fontSize: 12,
  52795. color: 'white',
  52796. padding: 5
  52797. };
  52798. var id = 'tooltip-' + µ.tooltipPanel.uid++;
  52799. var tickSize = 10;
  52800. var exports = function() {
  52801. tooltipEl = config.container.selectAll('g.' + id).data([ 0 ]);
  52802. var tooltipEnter = tooltipEl.enter().append('g').classed(id, true).style({
  52803. 'pointer-events': 'none',
  52804. display: 'none'
  52805. });
  52806. backgroundEl = tooltipEnter.append('path').style({
  52807. fill: 'white',
  52808. 'fill-opacity': .9
  52809. }).attr({
  52810. d: 'M0 0'
  52811. });
  52812. tooltipTextEl = tooltipEnter.append('text').attr({
  52813. dx: config.padding + tickSize,
  52814. dy: +config.fontSize * .3
  52815. });
  52816. return exports;
  52817. };
  52818. exports.text = function(_text) {
  52819. var l = d3.hsl(config.color).l;
  52820. var strokeColor = l >= .5 ? '#aaa' : 'white';
  52821. var fillColor = l >= .5 ? 'black' : 'white';
  52822. var text = _text || '';
  52823. tooltipTextEl.style({
  52824. fill: fillColor,
  52825. 'font-size': config.fontSize + 'px'
  52826. }).text(text);
  52827. var padding = config.padding;
  52828. var bbox = tooltipTextEl.node().getBBox();
  52829. var boxStyle = {
  52830. fill: config.color,
  52831. stroke: strokeColor,
  52832. 'stroke-width': '2px'
  52833. };
  52834. var backGroundW = bbox.width + padding * 2 + tickSize;
  52835. var backGroundH = bbox.height + padding * 2;
  52836. backgroundEl.attr({
  52837. d: 'M' + [ [ tickSize, -backGroundH / 2 ], [ tickSize, -backGroundH / 4 ], [ config.hasTick ? 0 : tickSize, 0 ], [ tickSize, backGroundH / 4 ], [ tickSize, backGroundH / 2 ], [ backGroundW, backGroundH / 2 ], [ backGroundW, -backGroundH / 2 ] ].join('L') + 'Z'
  52838. }).style(boxStyle);
  52839. tooltipEl.attr({
  52840. transform: 'translate(' + [ tickSize, -backGroundH / 2 + padding * 2 ] + ')'
  52841. });
  52842. tooltipEl.style({
  52843. display: 'block'
  52844. });
  52845. return exports;
  52846. };
  52847. exports.move = function(_pos) {
  52848. if (!tooltipEl) return;
  52849. tooltipEl.attr({
  52850. transform: 'translate(' + [ _pos[0], _pos[1] ] + ')'
  52851. }).style({
  52852. display: 'block'
  52853. });
  52854. return exports;
  52855. };
  52856. exports.hide = function() {
  52857. if (!tooltipEl) return;
  52858. tooltipEl.style({
  52859. display: 'none'
  52860. });
  52861. return exports;
  52862. };
  52863. exports.show = function() {
  52864. if (!tooltipEl) return;
  52865. tooltipEl.style({
  52866. display: 'block'
  52867. });
  52868. return exports;
  52869. };
  52870. exports.config = function(_x) {
  52871. extendDeepAll(config, _x);
  52872. return exports;
  52873. };
  52874. return exports;
  52875. };
  52876. µ.tooltipPanel.uid = 1;
  52877. µ.adapter = {};
  52878. µ.adapter.plotly = function module() {
  52879. var exports = {};
  52880. exports.convert = function(_inputConfig, reverse) {
  52881. var outputConfig = {};
  52882. if (_inputConfig.data) {
  52883. outputConfig.data = _inputConfig.data.map(function(d, i) {
  52884. var r = extendDeepAll({}, d);
  52885. var toTranslate = [
  52886. [ r, [ 'marker', 'color' ], [ 'color' ] ],
  52887. [ r, [ 'marker', 'opacity' ], [ 'opacity' ] ],
  52888. [ r, [ 'marker', 'line', 'color' ], [ 'strokeColor' ] ],
  52889. [ r, [ 'marker', 'line', 'dash' ], [ 'strokeDash' ] ],
  52890. [ r, [ 'marker', 'line', 'width' ], [ 'strokeSize' ] ],
  52891. [ r, [ 'marker', 'symbol' ], [ 'dotType' ] ],
  52892. [ r, [ 'marker', 'size' ], [ 'dotSize' ] ],
  52893. [ r, [ 'marker', 'barWidth' ], [ 'barWidth' ] ],
  52894. [ r, [ 'line', 'interpolation' ], [ 'lineInterpolation' ] ],
  52895. [ r, [ 'showlegend' ], [ 'visibleInLegend' ] ]
  52896. ];
  52897. toTranslate.forEach(function(d, i) {
  52898. µ.util.translator.apply(null, d.concat(reverse));
  52899. });
  52900. if (!reverse) delete r.marker;
  52901. if (reverse) delete r.groupId;
  52902. if (!reverse) {
  52903. if (r.type === 'scatter') {
  52904. if (r.mode === 'lines') r.geometry = 'LinePlot'; else if (r.mode === 'markers') r.geometry = 'DotPlot'; else if (r.mode === 'lines+markers') {
  52905. r.geometry = 'LinePlot';
  52906. r.dotVisible = true;
  52907. }
  52908. } else if (r.type === 'area') r.geometry = 'AreaChart'; else if (r.type === 'bar') r.geometry = 'BarChart';
  52909. delete r.mode;
  52910. delete r.type;
  52911. } else {
  52912. if (r.geometry === 'LinePlot') {
  52913. r.type = 'scatter';
  52914. if (r.dotVisible === true) {
  52915. delete r.dotVisible;
  52916. r.mode = 'lines+markers';
  52917. } else r.mode = 'lines';
  52918. } else if (r.geometry === 'DotPlot') {
  52919. r.type = 'scatter';
  52920. r.mode = 'markers';
  52921. } else if (r.geometry === 'AreaChart') r.type = 'area'; else if (r.geometry === 'BarChart') r.type = 'bar';
  52922. delete r.geometry;
  52923. }
  52924. return r;
  52925. });
  52926. if (!reverse && _inputConfig.layout && _inputConfig.layout.barmode === 'stack') {
  52927. var duplicates = µ.util.duplicates(outputConfig.data.map(function(d, i) {
  52928. return d.geometry;
  52929. }));
  52930. outputConfig.data.forEach(function(d, i) {
  52931. var idx = duplicates.indexOf(d.geometry);
  52932. if (idx != -1) outputConfig.data[i].groupId = idx;
  52933. });
  52934. }
  52935. }
  52936. if (_inputConfig.layout) {
  52937. var r = extendDeepAll({}, _inputConfig.layout);
  52938. var toTranslate = [
  52939. [ r, [ 'plot_bgcolor' ], [ 'backgroundColor' ] ],
  52940. [ r, [ 'showlegend' ], [ 'showLegend' ] ],
  52941. [ r, [ 'radialaxis' ], [ 'radialAxis' ] ],
  52942. [ r, [ 'angularaxis' ], [ 'angularAxis' ] ],
  52943. [ r.angularaxis, [ 'showline' ], [ 'gridLinesVisible' ] ],
  52944. [ r.angularaxis, [ 'showticklabels' ], [ 'labelsVisible' ] ],
  52945. [ r.angularaxis, [ 'nticks' ], [ 'ticksCount' ] ],
  52946. [ r.angularaxis, [ 'tickorientation' ], [ 'tickOrientation' ] ],
  52947. [ r.angularaxis, [ 'ticksuffix' ], [ 'ticksSuffix' ] ],
  52948. [ r.angularaxis, [ 'range' ], [ 'domain' ] ],
  52949. [ r.angularaxis, [ 'endpadding' ], [ 'endPadding' ] ],
  52950. [ r.radialaxis, [ 'showline' ], [ 'gridLinesVisible' ] ],
  52951. [ r.radialaxis, [ 'tickorientation' ], [ 'tickOrientation' ] ],
  52952. [ r.radialaxis, [ 'ticksuffix' ], [ 'ticksSuffix' ] ],
  52953. [ r.radialaxis, [ 'range' ], [ 'domain' ] ],
  52954. [ r.angularAxis, [ 'showline' ], [ 'gridLinesVisible' ] ],
  52955. [ r.angularAxis, [ 'showticklabels' ], [ 'labelsVisible' ] ],
  52956. [ r.angularAxis, [ 'nticks' ], [ 'ticksCount' ] ],
  52957. [ r.angularAxis, [ 'tickorientation' ], [ 'tickOrientation' ] ],
  52958. [ r.angularAxis, [ 'ticksuffix' ], [ 'ticksSuffix' ] ],
  52959. [ r.angularAxis, [ 'range' ], [ 'domain' ] ],
  52960. [ r.angularAxis, [ 'endpadding' ], [ 'endPadding' ] ],
  52961. [ r.radialAxis, [ 'showline' ], [ 'gridLinesVisible' ] ],
  52962. [ r.radialAxis, [ 'tickorientation' ], [ 'tickOrientation' ] ],
  52963. [ r.radialAxis, [ 'ticksuffix' ], [ 'ticksSuffix' ] ],
  52964. [ r.radialAxis, [ 'range' ], [ 'domain' ] ],
  52965. [ r.font, [ 'outlinecolor' ], [ 'outlineColor' ] ],
  52966. [ r.legend, [ 'traceorder' ], [ 'reverseOrder' ] ],
  52967. [ r, [ 'labeloffset' ], [ 'labelOffset' ] ],
  52968. [ r, [ 'defaultcolorrange' ], [ 'defaultColorRange' ] ]
  52969. ];
  52970. toTranslate.forEach(function(d, i) {
  52971. µ.util.translator.apply(null, d.concat(reverse));
  52972. });
  52973. if (!reverse) {
  52974. if (r.angularAxis && typeof r.angularAxis.ticklen !== 'undefined') r.tickLength = r.angularAxis.ticklen;
  52975. if (r.angularAxis && typeof r.angularAxis.tickcolor !== 'undefined') r.tickColor = r.angularAxis.tickcolor;
  52976. } else {
  52977. if (typeof r.tickLength !== 'undefined') {
  52978. r.angularaxis.ticklen = r.tickLength;
  52979. delete r.tickLength;
  52980. }
  52981. if (r.tickColor) {
  52982. r.angularaxis.tickcolor = r.tickColor;
  52983. delete r.tickColor;
  52984. }
  52985. }
  52986. if (r.legend && typeof r.legend.reverseOrder != 'boolean') {
  52987. r.legend.reverseOrder = r.legend.reverseOrder != 'normal';
  52988. }
  52989. if (r.legend && typeof r.legend.traceorder == 'boolean') {
  52990. r.legend.traceorder = r.legend.traceorder ? 'reversed' : 'normal';
  52991. delete r.legend.reverseOrder;
  52992. }
  52993. if (r.margin && typeof r.margin.t != 'undefined') {
  52994. var source = [ 't', 'r', 'b', 'l', 'pad' ];
  52995. var target = [ 'top', 'right', 'bottom', 'left', 'pad' ];
  52996. var margin = {};
  52997. d3.entries(r.margin).forEach(function(dB, iB) {
  52998. margin[target[source.indexOf(dB.key)]] = dB.value;
  52999. });
  53000. r.margin = margin;
  53001. }
  53002. if (reverse) {
  53003. delete r.needsEndSpacing;
  53004. delete r.minorTickColor;
  53005. delete r.minorTicks;
  53006. delete r.angularaxis.ticksCount;
  53007. delete r.angularaxis.ticksCount;
  53008. delete r.angularaxis.ticksStep;
  53009. delete r.angularaxis.rewriteTicks;
  53010. delete r.angularaxis.nticks;
  53011. delete r.radialaxis.ticksCount;
  53012. delete r.radialaxis.ticksCount;
  53013. delete r.radialaxis.ticksStep;
  53014. delete r.radialaxis.rewriteTicks;
  53015. delete r.radialaxis.nticks;
  53016. }
  53017. outputConfig.layout = r;
  53018. }
  53019. return outputConfig;
  53020. };
  53021. return exports;
  53022. };
  53023. },{"../../../constants/alignment":148,"../../../lib":169,"d3":16}],251:[function(_dereq_,module,exports){
  53024. /**
  53025. * Copyright 2012-2018, Plotly, Inc.
  53026. * All rights reserved.
  53027. *
  53028. * This source code is licensed under the MIT license found in the
  53029. * LICENSE file in the root directory of this source tree.
  53030. */
  53031. /* eslint-disable new-cap */
  53032. 'use strict';
  53033. var d3 = _dereq_('d3');
  53034. var Lib = _dereq_('../../../lib');
  53035. var Color = _dereq_('../../../components/color');
  53036. var micropolar = _dereq_('./micropolar');
  53037. var UndoManager = _dereq_('./undo_manager');
  53038. var extendDeepAll = Lib.extendDeepAll;
  53039. var manager = module.exports = {};
  53040. manager.framework = function(_gd) {
  53041. var config, previousConfigClone, plot, convertedInput, container;
  53042. var undoManager = new UndoManager();
  53043. function exports(_inputConfig, _container) {
  53044. if(_container) container = _container;
  53045. d3.select(d3.select(container).node().parentNode).selectAll('.svg-container>*:not(.chart-root)').remove();
  53046. config = (!config) ?
  53047. _inputConfig :
  53048. extendDeepAll(config, _inputConfig);
  53049. if(!plot) plot = micropolar.Axis();
  53050. convertedInput = micropolar.adapter.plotly().convert(config);
  53051. plot.config(convertedInput).render(container);
  53052. _gd.data = config.data;
  53053. _gd.layout = config.layout;
  53054. manager.fillLayout(_gd);
  53055. return config;
  53056. }
  53057. exports.isPolar = true;
  53058. exports.svg = function() { return plot.svg(); };
  53059. exports.getConfig = function() { return config; };
  53060. exports.getLiveConfig = function() {
  53061. return micropolar.adapter.plotly().convert(plot.getLiveConfig(), true);
  53062. };
  53063. exports.getLiveScales = function() { return {t: plot.angularScale(), r: plot.radialScale()}; };
  53064. exports.setUndoPoint = function() {
  53065. var that = this;
  53066. var configClone = micropolar.util.cloneJson(config);
  53067. (function(_configClone, _previousConfigClone) {
  53068. undoManager.add({
  53069. undo: function() {
  53070. if(_previousConfigClone) that(_previousConfigClone);
  53071. },
  53072. redo: function() {
  53073. that(_configClone);
  53074. }
  53075. });
  53076. })(configClone, previousConfigClone);
  53077. previousConfigClone = micropolar.util.cloneJson(configClone);
  53078. };
  53079. exports.undo = function() { undoManager.undo(); };
  53080. exports.redo = function() { undoManager.redo(); };
  53081. return exports;
  53082. };
  53083. manager.fillLayout = function(_gd) {
  53084. var container = d3.select(_gd).selectAll('.plot-container'),
  53085. paperDiv = container.selectAll('.svg-container'),
  53086. paper = _gd.framework && _gd.framework.svg && _gd.framework.svg(),
  53087. dflts = {
  53088. width: 800,
  53089. height: 600,
  53090. paper_bgcolor: Color.background,
  53091. _container: container,
  53092. _paperdiv: paperDiv,
  53093. _paper: paper
  53094. };
  53095. _gd._fullLayout = extendDeepAll(dflts, _gd.layout);
  53096. };
  53097. },{"../../../components/color":50,"../../../lib":169,"./micropolar":250,"./undo_manager":252,"d3":16}],252:[function(_dereq_,module,exports){
  53098. /**
  53099. * Copyright 2012-2018, Plotly, Inc.
  53100. * All rights reserved.
  53101. *
  53102. * This source code is licensed under the MIT license found in the
  53103. * LICENSE file in the root directory of this source tree.
  53104. */
  53105. 'use strict';
  53106. // Modified from https://github.com/ArthurClemens/Javascript-Undo-Manager
  53107. // Copyright (c) 2010-2013 Arthur Clemens, arthur@visiblearea.com
  53108. module.exports = function UndoManager() {
  53109. var undoCommands = [],
  53110. index = -1,
  53111. isExecuting = false,
  53112. callback;
  53113. function execute(command, action) {
  53114. if(!command) return this;
  53115. isExecuting = true;
  53116. command[action]();
  53117. isExecuting = false;
  53118. return this;
  53119. }
  53120. return {
  53121. add: function(command) {
  53122. if(isExecuting) return this;
  53123. undoCommands.splice(index + 1, undoCommands.length - index);
  53124. undoCommands.push(command);
  53125. index = undoCommands.length - 1;
  53126. return this;
  53127. },
  53128. setCallback: function(callbackFunc) { callback = callbackFunc; },
  53129. undo: function() {
  53130. var command = undoCommands[index];
  53131. if(!command) return this;
  53132. execute(command, 'undo');
  53133. index -= 1;
  53134. if(callback) callback(command.undo);
  53135. return this;
  53136. },
  53137. redo: function() {
  53138. var command = undoCommands[index + 1];
  53139. if(!command) return this;
  53140. execute(command, 'redo');
  53141. index += 1;
  53142. if(callback) callback(command.redo);
  53143. return this;
  53144. },
  53145. clear: function() {
  53146. undoCommands = [];
  53147. index = -1;
  53148. },
  53149. hasUndo: function() { return index !== -1; },
  53150. hasRedo: function() { return index < (undoCommands.length - 1); },
  53151. getCommands: function() { return undoCommands; },
  53152. getPreviousCommand: function() { return undoCommands[index - 1]; },
  53153. getIndex: function() { return index; }
  53154. };
  53155. };
  53156. },{}],253:[function(_dereq_,module,exports){
  53157. /**
  53158. * Copyright 2012-2018, Plotly, Inc.
  53159. * All rights reserved.
  53160. *
  53161. * This source code is licensed under the MIT license found in the
  53162. * LICENSE file in the root directory of this source tree.
  53163. */
  53164. 'use strict';
  53165. // always plot splom before cartesian (i.e. scattergl traces)
  53166. function sortModules(a, b) {
  53167. if(a === 'splom') return -1;
  53168. if(b === 'splom') return 1;
  53169. return 0;
  53170. }
  53171. function sortBasePlotModules(a, b) {
  53172. return sortModules(a.name, b.name);
  53173. }
  53174. module.exports = {
  53175. sortBasePlotModules: sortBasePlotModules,
  53176. sortModules: sortModules
  53177. };
  53178. },{}],254:[function(_dereq_,module,exports){
  53179. /**
  53180. * Copyright 2012-2018, Plotly, Inc.
  53181. * All rights reserved.
  53182. *
  53183. * This source code is licensed under the MIT license found in the
  53184. * LICENSE file in the root directory of this source tree.
  53185. */
  53186. 'use strict';
  53187. var Lib = _dereq_('../lib');
  53188. var Template = _dereq_('../plot_api/plot_template');
  53189. var handleDomainDefaults = _dereq_('./domain').defaults;
  53190. /**
  53191. * Find and supply defaults to all subplots of a given type
  53192. * This handles subplots that are contained within one container - so
  53193. * gl3d, geo, ternary... but not 2d axes which have separate x and y axes
  53194. * finds subplots, coerces their `domain` attributes, then calls the
  53195. * given handleDefaults function to fill in everything else.
  53196. *
  53197. * layoutIn: the complete user-supplied input layout
  53198. * layoutOut: the complete finished layout
  53199. * fullData: the finished data array, used only to find subplots
  53200. * opts: {
  53201. * type: subplot type string
  53202. * attributes: subplot attributes object
  53203. * partition: 'x' or 'y', which direction to divide domain space by default
  53204. * (default 'x', ie side-by-side subplots)
  53205. * TODO: this option is only here because 3D and geo made opposite
  53206. * choices in this regard previously and I didn't want to change it.
  53207. * Instead we should do:
  53208. * - something consistent
  53209. * - something more square (4 cuts 2x2, 5/6 cuts 2x3, etc.)
  53210. * - something that includes all subplot types in one arrangement,
  53211. * now that we can have them together!
  53212. * handleDefaults: function of (subplotLayoutIn, subplotLayoutOut, coerce, opts)
  53213. * this opts object is passed through to handleDefaults, so attach any
  53214. * additional items needed by this function here as well
  53215. * }
  53216. */
  53217. module.exports = function handleSubplotDefaults(layoutIn, layoutOut, fullData, opts) {
  53218. var subplotType = opts.type;
  53219. var subplotAttributes = opts.attributes;
  53220. var handleDefaults = opts.handleDefaults;
  53221. var partition = opts.partition || 'x';
  53222. var ids = layoutOut._subplots[subplotType];
  53223. var idsLength = ids.length;
  53224. var baseId = idsLength && ids[0].replace(/\d+$/, '');
  53225. var subplotLayoutIn, subplotLayoutOut;
  53226. function coerce(attr, dflt) {
  53227. return Lib.coerce(subplotLayoutIn, subplotLayoutOut, subplotAttributes, attr, dflt);
  53228. }
  53229. for(var i = 0; i < idsLength; i++) {
  53230. var id = ids[i];
  53231. // ternary traces get a layout ternary for free!
  53232. if(layoutIn[id]) subplotLayoutIn = layoutIn[id];
  53233. else subplotLayoutIn = layoutIn[id] = {};
  53234. subplotLayoutOut = Template.newContainer(layoutOut, id, baseId);
  53235. var dfltDomains = {};
  53236. dfltDomains[partition] = [i / idsLength, (i + 1) / idsLength];
  53237. handleDomainDefaults(subplotLayoutOut, layoutOut, coerce, dfltDomains);
  53238. opts.id = id;
  53239. handleDefaults(subplotLayoutIn, subplotLayoutOut, coerce, opts);
  53240. }
  53241. };
  53242. },{"../lib":169,"../plot_api/plot_template":204,"./domain":239}],255:[function(_dereq_,module,exports){
  53243. /**
  53244. * Copyright 2012-2018, Plotly, Inc.
  53245. * All rights reserved.
  53246. *
  53247. * This source code is licensed under the MIT license found in the
  53248. * LICENSE file in the root directory of this source tree.
  53249. */
  53250. 'use strict';
  53251. var Ternary = _dereq_('./ternary');
  53252. var getSubplotCalcData = _dereq_('../../plots/get_data').getSubplotCalcData;
  53253. var counterRegex = _dereq_('../../lib').counterRegex;
  53254. var TERNARY = 'ternary';
  53255. exports.name = TERNARY;
  53256. var attr = exports.attr = 'subplot';
  53257. exports.idRoot = TERNARY;
  53258. exports.idRegex = exports.attrRegex = counterRegex(TERNARY);
  53259. var attributes = exports.attributes = {};
  53260. attributes[attr] = {
  53261. valType: 'subplotid',
  53262. dflt: 'ternary',
  53263. editType: 'calc',
  53264. };
  53265. exports.layoutAttributes = _dereq_('./layout_attributes');
  53266. exports.supplyLayoutDefaults = _dereq_('./layout_defaults');
  53267. exports.plot = function plotTernary(gd) {
  53268. var fullLayout = gd._fullLayout;
  53269. var calcData = gd.calcdata;
  53270. var ternaryIds = fullLayout._subplots[TERNARY];
  53271. for(var i = 0; i < ternaryIds.length; i++) {
  53272. var ternaryId = ternaryIds[i],
  53273. ternaryCalcData = getSubplotCalcData(calcData, TERNARY, ternaryId),
  53274. ternary = fullLayout[ternaryId]._subplot;
  53275. // If ternary is not instantiated, create one!
  53276. if(!ternary) {
  53277. ternary = new Ternary({
  53278. id: ternaryId,
  53279. graphDiv: gd,
  53280. container: fullLayout._ternarylayer.node()
  53281. },
  53282. fullLayout
  53283. );
  53284. fullLayout[ternaryId]._subplot = ternary;
  53285. }
  53286. ternary.plot(ternaryCalcData, fullLayout, gd._promises);
  53287. }
  53288. };
  53289. exports.clean = function(newFullData, newFullLayout, oldFullData, oldFullLayout) {
  53290. var oldTernaryKeys = oldFullLayout._subplots[TERNARY] || [];
  53291. for(var i = 0; i < oldTernaryKeys.length; i++) {
  53292. var oldTernaryKey = oldTernaryKeys[i];
  53293. var oldTernary = oldFullLayout[oldTernaryKey]._subplot;
  53294. if(!newFullLayout[oldTernaryKey] && !!oldTernary) {
  53295. oldTernary.plotContainer.remove();
  53296. oldTernary.clipDef.remove();
  53297. oldTernary.clipDefRelative.remove();
  53298. oldTernary.layers['a-title'].remove();
  53299. oldTernary.layers['b-title'].remove();
  53300. oldTernary.layers['c-title'].remove();
  53301. }
  53302. }
  53303. };
  53304. },{"../../lib":169,"../../plots/get_data":242,"./layout_attributes":256,"./layout_defaults":257,"./ternary":258}],256:[function(_dereq_,module,exports){
  53305. /**
  53306. * Copyright 2012-2018, Plotly, Inc.
  53307. * All rights reserved.
  53308. *
  53309. * This source code is licensed under the MIT license found in the
  53310. * LICENSE file in the root directory of this source tree.
  53311. */
  53312. 'use strict';
  53313. var colorAttrs = _dereq_('../../components/color/attributes');
  53314. var domainAttrs = _dereq_('../domain').attributes;
  53315. var axesAttrs = _dereq_('../cartesian/layout_attributes');
  53316. var overrideAll = _dereq_('../../plot_api/edit_types').overrideAll;
  53317. var extendFlat = _dereq_('../../lib/extend').extendFlat;
  53318. var ternaryAxesAttrs = {
  53319. title: axesAttrs.title,
  53320. titlefont: axesAttrs.titlefont,
  53321. color: axesAttrs.color,
  53322. // ticks
  53323. tickmode: axesAttrs.tickmode,
  53324. nticks: extendFlat({}, axesAttrs.nticks, {dflt: 6, min: 1}),
  53325. tick0: axesAttrs.tick0,
  53326. dtick: axesAttrs.dtick,
  53327. tickvals: axesAttrs.tickvals,
  53328. ticktext: axesAttrs.ticktext,
  53329. ticks: axesAttrs.ticks,
  53330. ticklen: axesAttrs.ticklen,
  53331. tickwidth: axesAttrs.tickwidth,
  53332. tickcolor: axesAttrs.tickcolor,
  53333. showticklabels: axesAttrs.showticklabels,
  53334. showtickprefix: axesAttrs.showtickprefix,
  53335. tickprefix: axesAttrs.tickprefix,
  53336. showticksuffix: axesAttrs.showticksuffix,
  53337. ticksuffix: axesAttrs.ticksuffix,
  53338. showexponent: axesAttrs.showexponent,
  53339. exponentformat: axesAttrs.exponentformat,
  53340. separatethousands: axesAttrs.separatethousands,
  53341. tickfont: axesAttrs.tickfont,
  53342. tickangle: axesAttrs.tickangle,
  53343. tickformat: axesAttrs.tickformat,
  53344. tickformatstops: axesAttrs.tickformatstops,
  53345. hoverformat: axesAttrs.hoverformat,
  53346. // lines and grids
  53347. showline: extendFlat({}, axesAttrs.showline, {dflt: true}),
  53348. linecolor: axesAttrs.linecolor,
  53349. linewidth: axesAttrs.linewidth,
  53350. showgrid: extendFlat({}, axesAttrs.showgrid, {dflt: true}),
  53351. gridcolor: axesAttrs.gridcolor,
  53352. gridwidth: axesAttrs.gridwidth,
  53353. layer: axesAttrs.layer,
  53354. // range
  53355. min: {
  53356. valType: 'number',
  53357. dflt: 0,
  53358. min: 0,
  53359. }
  53360. };
  53361. module.exports = overrideAll({
  53362. domain: domainAttrs({name: 'ternary'}),
  53363. bgcolor: {
  53364. valType: 'color',
  53365. dflt: colorAttrs.background,
  53366. },
  53367. sum: {
  53368. valType: 'number',
  53369. dflt: 1,
  53370. min: 0,
  53371. },
  53372. aaxis: ternaryAxesAttrs,
  53373. baxis: ternaryAxesAttrs,
  53374. caxis: ternaryAxesAttrs
  53375. }, 'plot', 'from-root');
  53376. },{"../../components/color/attributes":49,"../../lib/extend":163,"../../plot_api/edit_types":197,"../cartesian/layout_attributes":226,"../domain":239}],257:[function(_dereq_,module,exports){
  53377. /**
  53378. * Copyright 2012-2018, Plotly, Inc.
  53379. * All rights reserved.
  53380. *
  53381. * This source code is licensed under the MIT license found in the
  53382. * LICENSE file in the root directory of this source tree.
  53383. */
  53384. 'use strict';
  53385. var Color = _dereq_('../../components/color');
  53386. var Template = _dereq_('../../plot_api/plot_template');
  53387. var Lib = _dereq_('../../lib');
  53388. var handleSubplotDefaults = _dereq_('../subplot_defaults');
  53389. var handleTickLabelDefaults = _dereq_('../cartesian/tick_label_defaults');
  53390. var handleTickMarkDefaults = _dereq_('../cartesian/tick_mark_defaults');
  53391. var handleTickValueDefaults = _dereq_('../cartesian/tick_value_defaults');
  53392. var handleLineGridDefaults = _dereq_('../cartesian/line_grid_defaults');
  53393. var layoutAttributes = _dereq_('./layout_attributes');
  53394. var axesNames = ['aaxis', 'baxis', 'caxis'];
  53395. module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {
  53396. handleSubplotDefaults(layoutIn, layoutOut, fullData, {
  53397. type: 'ternary',
  53398. attributes: layoutAttributes,
  53399. handleDefaults: handleTernaryDefaults,
  53400. font: layoutOut.font,
  53401. paper_bgcolor: layoutOut.paper_bgcolor
  53402. });
  53403. };
  53404. function handleTernaryDefaults(ternaryLayoutIn, ternaryLayoutOut, coerce, options) {
  53405. var bgColor = coerce('bgcolor');
  53406. var sum = coerce('sum');
  53407. options.bgColor = Color.combine(bgColor, options.paper_bgcolor);
  53408. var axName, containerIn, containerOut;
  53409. // TODO: allow most (if not all) axis attributes to be set
  53410. // in the outer container and used as defaults in the individual axes?
  53411. for(var j = 0; j < axesNames.length; j++) {
  53412. axName = axesNames[j];
  53413. containerIn = ternaryLayoutIn[axName] || {};
  53414. containerOut = Template.newContainer(ternaryLayoutOut, axName);
  53415. containerOut._name = axName;
  53416. handleAxisDefaults(containerIn, containerOut, options);
  53417. }
  53418. // if the min values contradict each other, set them all to default (0)
  53419. // and delete *all* the inputs so the user doesn't get confused later by
  53420. // changing one and having them all change.
  53421. var aaxis = ternaryLayoutOut.aaxis,
  53422. baxis = ternaryLayoutOut.baxis,
  53423. caxis = ternaryLayoutOut.caxis;
  53424. if(aaxis.min + baxis.min + caxis.min >= sum) {
  53425. aaxis.min = 0;
  53426. baxis.min = 0;
  53427. caxis.min = 0;
  53428. if(ternaryLayoutIn.aaxis) delete ternaryLayoutIn.aaxis.min;
  53429. if(ternaryLayoutIn.baxis) delete ternaryLayoutIn.baxis.min;
  53430. if(ternaryLayoutIn.caxis) delete ternaryLayoutIn.caxis.min;
  53431. }
  53432. }
  53433. function handleAxisDefaults(containerIn, containerOut, options) {
  53434. var axAttrs = layoutAttributes[containerOut._name];
  53435. function coerce(attr, dflt) {
  53436. return Lib.coerce(containerIn, containerOut, axAttrs, attr, dflt);
  53437. }
  53438. containerOut.type = 'linear'; // no other types allowed for ternary
  53439. var dfltColor = coerce('color');
  53440. // if axis.color was provided, use it for fonts too; otherwise,
  53441. // inherit from global font color in case that was provided.
  53442. var dfltFontColor = (dfltColor !== axAttrs.color.dflt) ? dfltColor : options.font.color;
  53443. var axName = containerOut._name,
  53444. letterUpper = axName.charAt(0).toUpperCase(),
  53445. dfltTitle = 'Component ' + letterUpper;
  53446. var title = coerce('title', dfltTitle);
  53447. containerOut._hovertitle = title === dfltTitle ? title : letterUpper;
  53448. Lib.coerceFont(coerce, 'titlefont', {
  53449. family: options.font.family,
  53450. size: Math.round(options.font.size * 1.2),
  53451. color: dfltFontColor
  53452. });
  53453. // range is just set by 'min' - max is determined by the other axes mins
  53454. coerce('min');
  53455. handleTickValueDefaults(containerIn, containerOut, coerce, 'linear');
  53456. handleTickLabelDefaults(containerIn, containerOut, coerce, 'linear', {});
  53457. handleTickMarkDefaults(containerIn, containerOut, coerce,
  53458. { outerTicks: true });
  53459. var showTickLabels = coerce('showticklabels');
  53460. if(showTickLabels) {
  53461. Lib.coerceFont(coerce, 'tickfont', {
  53462. family: options.font.family,
  53463. size: options.font.size,
  53464. color: dfltFontColor
  53465. });
  53466. coerce('tickangle');
  53467. coerce('tickformat');
  53468. }
  53469. handleLineGridDefaults(containerIn, containerOut, coerce, {
  53470. dfltColor: dfltColor,
  53471. bgColor: options.bgColor,
  53472. // default grid color is darker here (60%, vs cartesian default ~91%)
  53473. // because the grid is not square so the eye needs heavier cues to follow
  53474. blend: 60,
  53475. showLine: true,
  53476. showGrid: true,
  53477. noZeroLine: true,
  53478. attributes: axAttrs
  53479. });
  53480. coerce('hoverformat');
  53481. coerce('layer');
  53482. }
  53483. },{"../../components/color":50,"../../lib":169,"../../plot_api/plot_template":204,"../cartesian/line_grid_defaults":228,"../cartesian/tick_label_defaults":233,"../cartesian/tick_mark_defaults":234,"../cartesian/tick_value_defaults":235,"../subplot_defaults":254,"./layout_attributes":256}],258:[function(_dereq_,module,exports){
  53484. /**
  53485. * Copyright 2012-2018, Plotly, Inc.
  53486. * All rights reserved.
  53487. *
  53488. * This source code is licensed under the MIT license found in the
  53489. * LICENSE file in the root directory of this source tree.
  53490. */
  53491. 'use strict';
  53492. var d3 = _dereq_('d3');
  53493. var tinycolor = _dereq_('tinycolor2');
  53494. var Registry = _dereq_('../../registry');
  53495. var Lib = _dereq_('../../lib');
  53496. var _ = Lib._;
  53497. var Color = _dereq_('../../components/color');
  53498. var Drawing = _dereq_('../../components/drawing');
  53499. var setConvert = _dereq_('../cartesian/set_convert');
  53500. var extendFlat = _dereq_('../../lib/extend').extendFlat;
  53501. var Plots = _dereq_('../plots');
  53502. var Axes = _dereq_('../cartesian/axes');
  53503. var dragElement = _dereq_('../../components/dragelement');
  53504. var Fx = _dereq_('../../components/fx');
  53505. var Titles = _dereq_('../../components/titles');
  53506. var prepSelect = _dereq_('../cartesian/select').prepSelect;
  53507. var selectOnClick = _dereq_('../cartesian/select').selectOnClick;
  53508. var clearSelect = _dereq_('../cartesian/select').clearSelect;
  53509. var constants = _dereq_('../cartesian/constants');
  53510. function Ternary(options, fullLayout) {
  53511. this.id = options.id;
  53512. this.graphDiv = options.graphDiv;
  53513. this.init(fullLayout);
  53514. this.makeFramework(fullLayout);
  53515. // unfortunately, we have to keep track of some axis tick settings
  53516. // as ternary subplots do not implement the 'ticks' editType
  53517. this.aTickLayout = null;
  53518. this.bTickLayout = null;
  53519. this.cTickLayout = null;
  53520. }
  53521. module.exports = Ternary;
  53522. var proto = Ternary.prototype;
  53523. proto.init = function(fullLayout) {
  53524. this.container = fullLayout._ternarylayer;
  53525. this.defs = fullLayout._defs;
  53526. this.layoutId = fullLayout._uid;
  53527. this.traceHash = {};
  53528. this.layers = {};
  53529. };
  53530. proto.plot = function(ternaryCalcData, fullLayout) {
  53531. var _this = this;
  53532. var ternaryLayout = fullLayout[_this.id];
  53533. var graphSize = fullLayout._size;
  53534. _this._hasClipOnAxisFalse = false;
  53535. for(var i = 0; i < ternaryCalcData.length; i++) {
  53536. var trace = ternaryCalcData[i][0].trace;
  53537. if(trace.cliponaxis === false) {
  53538. _this._hasClipOnAxisFalse = true;
  53539. break;
  53540. }
  53541. }
  53542. _this.updateLayers(ternaryLayout);
  53543. _this.adjustLayout(ternaryLayout, graphSize);
  53544. Plots.generalUpdatePerTraceModule(_this.graphDiv, _this, ternaryCalcData, ternaryLayout);
  53545. _this.layers.plotbg.select('path').call(Color.fill, ternaryLayout.bgcolor);
  53546. };
  53547. proto.makeFramework = function(fullLayout) {
  53548. var _this = this;
  53549. var ternaryLayout = fullLayout[_this.id];
  53550. var clipId = _this.clipId = 'clip' + _this.layoutId + _this.id;
  53551. var clipIdRelative = _this.clipIdRelative = 'clip-relative' + _this.layoutId + _this.id;
  53552. // clippath for this ternary subplot
  53553. _this.clipDef = Lib.ensureSingleById(fullLayout._clips, 'clipPath', clipId, function(s) {
  53554. s.append('path').attr('d', 'M0,0Z');
  53555. });
  53556. // 'relative' clippath (i.e. no translation) for this ternary subplot
  53557. _this.clipDefRelative = Lib.ensureSingleById(fullLayout._clips, 'clipPath', clipIdRelative, function(s) {
  53558. s.append('path').attr('d', 'M0,0Z');
  53559. });
  53560. // container for everything in this ternary subplot
  53561. _this.plotContainer = Lib.ensureSingle(_this.container, 'g', _this.id);
  53562. _this.updateLayers(ternaryLayout);
  53563. Drawing.setClipUrl(_this.layers.backplot, clipId);
  53564. Drawing.setClipUrl(_this.layers.grids, clipId);
  53565. };
  53566. proto.updateLayers = function(ternaryLayout) {
  53567. var _this = this;
  53568. var layers = _this.layers;
  53569. // inside that container, we have one container for the data, and
  53570. // one each for the three axes around it.
  53571. var plotLayers = ['draglayer', 'plotbg', 'backplot', 'grids'];
  53572. if(ternaryLayout.aaxis.layer === 'below traces') {
  53573. plotLayers.push('aaxis', 'aline');
  53574. }
  53575. if(ternaryLayout.baxis.layer === 'below traces') {
  53576. plotLayers.push('baxis', 'bline');
  53577. }
  53578. if(ternaryLayout.caxis.layer === 'below traces') {
  53579. plotLayers.push('caxis', 'cline');
  53580. }
  53581. plotLayers.push('frontplot');
  53582. if(ternaryLayout.aaxis.layer === 'above traces') {
  53583. plotLayers.push('aaxis', 'aline');
  53584. }
  53585. if(ternaryLayout.baxis.layer === 'above traces') {
  53586. plotLayers.push('baxis', 'bline');
  53587. }
  53588. if(ternaryLayout.caxis.layer === 'above traces') {
  53589. plotLayers.push('caxis', 'cline');
  53590. }
  53591. var toplevel = _this.plotContainer.selectAll('g.toplevel')
  53592. .data(plotLayers, String);
  53593. var grids = ['agrid', 'bgrid', 'cgrid'];
  53594. toplevel.enter().append('g')
  53595. .attr('class', function(d) { return 'toplevel ' + d; })
  53596. .each(function(d) {
  53597. var s = d3.select(this);
  53598. layers[d] = s;
  53599. // containers for different trace types.
  53600. // NOTE - this is different from cartesian, where all traces
  53601. // are in front of grids. Here I'm putting maps behind the grids
  53602. // so the grids will always be visible if they're requested.
  53603. // Perhaps we want that for cartesian too?
  53604. if(d === 'frontplot') {
  53605. s.append('g').classed('scatterlayer', true);
  53606. } else if(d === 'backplot') {
  53607. s.append('g').classed('maplayer', true);
  53608. } else if(d === 'plotbg') {
  53609. s.append('path').attr('d', 'M0,0Z');
  53610. } else if(d === 'aline' || d === 'bline' || d === 'cline') {
  53611. s.append('path');
  53612. } else if(d === 'grids') {
  53613. grids.forEach(function(d) {
  53614. layers[d] = s.append('g').classed('grid ' + d, true);
  53615. var fictID = (d === 'bgrid') ? 'x' : 'y';
  53616. layers[d].append('g').classed(fictID, true);
  53617. });
  53618. }
  53619. });
  53620. toplevel.order();
  53621. };
  53622. var w_over_h = Math.sqrt(4 / 3);
  53623. proto.adjustLayout = function(ternaryLayout, graphSize) {
  53624. var _this = this,
  53625. domain = ternaryLayout.domain,
  53626. xDomainCenter = (domain.x[0] + domain.x[1]) / 2,
  53627. yDomainCenter = (domain.y[0] + domain.y[1]) / 2,
  53628. xDomain = domain.x[1] - domain.x[0],
  53629. yDomain = domain.y[1] - domain.y[0],
  53630. wmax = xDomain * graphSize.w,
  53631. hmax = yDomain * graphSize.h,
  53632. sum = ternaryLayout.sum,
  53633. amin = ternaryLayout.aaxis.min,
  53634. bmin = ternaryLayout.baxis.min,
  53635. cmin = ternaryLayout.caxis.min;
  53636. var x0, y0, w, h, xDomainFinal, yDomainFinal;
  53637. if(wmax > w_over_h * hmax) {
  53638. h = hmax;
  53639. w = h * w_over_h;
  53640. }
  53641. else {
  53642. w = wmax;
  53643. h = w / w_over_h;
  53644. }
  53645. xDomainFinal = xDomain * w / wmax;
  53646. yDomainFinal = yDomain * h / hmax;
  53647. x0 = graphSize.l + graphSize.w * xDomainCenter - w / 2;
  53648. y0 = graphSize.t + graphSize.h * (1 - yDomainCenter) - h / 2;
  53649. _this.x0 = x0;
  53650. _this.y0 = y0;
  53651. _this.w = w;
  53652. _this.h = h;
  53653. _this.sum = sum;
  53654. // set up the x and y axis objects we'll use to lay out the points
  53655. _this.xaxis = {
  53656. type: 'linear',
  53657. range: [amin + 2 * cmin - sum, sum - amin - 2 * bmin],
  53658. domain: [
  53659. xDomainCenter - xDomainFinal / 2,
  53660. xDomainCenter + xDomainFinal / 2
  53661. ],
  53662. _id: 'x'
  53663. };
  53664. setConvert(_this.xaxis, _this.graphDiv._fullLayout);
  53665. _this.xaxis.setScale();
  53666. _this.xaxis.isPtWithinRange = function(d) {
  53667. return (
  53668. d.a >= _this.aaxis.range[0] &&
  53669. d.a <= _this.aaxis.range[1] &&
  53670. d.b >= _this.baxis.range[1] &&
  53671. d.b <= _this.baxis.range[0] &&
  53672. d.c >= _this.caxis.range[1] &&
  53673. d.c <= _this.caxis.range[0]
  53674. );
  53675. };
  53676. _this.yaxis = {
  53677. type: 'linear',
  53678. range: [amin, sum - bmin - cmin],
  53679. domain: [
  53680. yDomainCenter - yDomainFinal / 2,
  53681. yDomainCenter + yDomainFinal / 2
  53682. ],
  53683. _id: 'y'
  53684. };
  53685. setConvert(_this.yaxis, _this.graphDiv._fullLayout);
  53686. _this.yaxis.setScale();
  53687. _this.yaxis.isPtWithinRange = function() { return true; };
  53688. // set up the modified axes for tick drawing
  53689. var yDomain0 = _this.yaxis.domain[0];
  53690. // aaxis goes up the left side. Set it up as a y axis, but with
  53691. // fictitious angles and domain, but then rotate and translate
  53692. // it into place at the end
  53693. var aaxis = _this.aaxis = extendFlat({}, ternaryLayout.aaxis, {
  53694. visible: true,
  53695. range: [amin, sum - bmin - cmin],
  53696. side: 'left',
  53697. _counterangle: 30,
  53698. // tickangle = 'auto' means 0 anyway for a y axis, need to coerce to 0 here
  53699. // so we can shift by 30.
  53700. tickangle: (+ternaryLayout.aaxis.tickangle || 0) - 30,
  53701. domain: [yDomain0, yDomain0 + yDomainFinal * w_over_h],
  53702. _axislayer: _this.layers.aaxis,
  53703. _gridlayer: _this.layers.agrid,
  53704. anchor: 'free',
  53705. position: 0,
  53706. _pos: 0, // _this.xaxis.domain[0] * graphSize.w,
  53707. _id: 'y',
  53708. _length: w,
  53709. _gridpath: 'M0,0l' + h + ',-' + (w / 2),
  53710. automargin: false // don't use automargins routine for labels
  53711. });
  53712. setConvert(aaxis, _this.graphDiv._fullLayout);
  53713. aaxis.setScale();
  53714. // baxis goes across the bottom (backward). We can set it up as an x axis
  53715. // without any enclosing transformation.
  53716. var baxis = _this.baxis = extendFlat({}, ternaryLayout.baxis, {
  53717. visible: true,
  53718. range: [sum - amin - cmin, bmin],
  53719. side: 'bottom',
  53720. _counterangle: 30,
  53721. domain: _this.xaxis.domain,
  53722. _axislayer: _this.layers.baxis,
  53723. _gridlayer: _this.layers.bgrid,
  53724. _counteraxis: _this.aaxis,
  53725. anchor: 'free',
  53726. position: 0,
  53727. _pos: 0, // (1 - yDomain0) * graphSize.h,
  53728. _id: 'x',
  53729. _length: w,
  53730. _gridpath: 'M0,0l-' + (w / 2) + ',-' + h,
  53731. automargin: false // don't use automargins routine for labels
  53732. });
  53733. setConvert(baxis, _this.graphDiv._fullLayout);
  53734. baxis.setScale();
  53735. aaxis._counteraxis = baxis;
  53736. // caxis goes down the right side. Set it up as a y axis, with
  53737. // post-transformation similar to aaxis
  53738. var caxis = _this.caxis = extendFlat({}, ternaryLayout.caxis, {
  53739. visible: true,
  53740. range: [sum - amin - bmin, cmin],
  53741. side: 'right',
  53742. _counterangle: 30,
  53743. tickangle: (+ternaryLayout.caxis.tickangle || 0) + 30,
  53744. domain: [yDomain0, yDomain0 + yDomainFinal * w_over_h],
  53745. _axislayer: _this.layers.caxis,
  53746. _gridlayer: _this.layers.cgrid,
  53747. _counteraxis: _this.baxis,
  53748. anchor: 'free',
  53749. position: 0,
  53750. _pos: 0, // _this.xaxis.domain[1] * graphSize.w,
  53751. _id: 'y',
  53752. _length: w,
  53753. _gridpath: 'M0,0l-' + h + ',' + (w / 2),
  53754. automargin: false // don't use automargins routine for labels
  53755. });
  53756. setConvert(caxis, _this.graphDiv._fullLayout);
  53757. caxis.setScale();
  53758. var triangleClip = 'M' + x0 + ',' + (y0 + h) + 'h' + w + 'l-' + (w / 2) + ',-' + h + 'Z';
  53759. _this.clipDef.select('path').attr('d', triangleClip);
  53760. _this.layers.plotbg.select('path').attr('d', triangleClip);
  53761. var triangleClipRelative = 'M0,' + h + 'h' + w + 'l-' + (w / 2) + ',-' + h + 'Z';
  53762. _this.clipDefRelative.select('path').attr('d', triangleClipRelative);
  53763. var plotTransform = 'translate(' + x0 + ',' + y0 + ')';
  53764. _this.plotContainer.selectAll('.scatterlayer,.maplayer')
  53765. .attr('transform', plotTransform);
  53766. _this.clipDefRelative.select('path').attr('transform', null);
  53767. // TODO: shift axes to accommodate linewidth*sin(30) tick mark angle
  53768. // TODO: there's probably an easier way to handle these translations/offsets now...
  53769. var bTransform = 'translate(' + (x0 - baxis._offset) + ',' + (y0 + h) + ')';
  53770. _this.layers.baxis.attr('transform', bTransform);
  53771. _this.layers.bgrid.attr('transform', bTransform);
  53772. var aTransform = 'translate(' + (x0 + w / 2) + ',' + y0 +
  53773. ')rotate(30)translate(0,' + -aaxis._offset + ')';
  53774. _this.layers.aaxis.attr('transform', aTransform);
  53775. _this.layers.agrid.attr('transform', aTransform);
  53776. var cTransform = 'translate(' + (x0 + w / 2) + ',' + y0 +
  53777. ')rotate(-30)translate(0,' + -caxis._offset + ')';
  53778. _this.layers.caxis.attr('transform', cTransform);
  53779. _this.layers.cgrid.attr('transform', cTransform);
  53780. _this.drawAxes(true);
  53781. // remove crispEdges - all the off-square angles in ternary plots
  53782. // make these counterproductive.
  53783. _this.plotContainer.selectAll('.crisp').classed('crisp', false);
  53784. _this.layers.aline.select('path')
  53785. .attr('d', aaxis.showline ?
  53786. 'M' + x0 + ',' + (y0 + h) + 'l' + (w / 2) + ',-' + h : 'M0,0')
  53787. .call(Color.stroke, aaxis.linecolor || '#000')
  53788. .style('stroke-width', (aaxis.linewidth || 0) + 'px');
  53789. _this.layers.bline.select('path')
  53790. .attr('d', baxis.showline ?
  53791. 'M' + x0 + ',' + (y0 + h) + 'h' + w : 'M0,0')
  53792. .call(Color.stroke, baxis.linecolor || '#000')
  53793. .style('stroke-width', (baxis.linewidth || 0) + 'px');
  53794. _this.layers.cline.select('path')
  53795. .attr('d', caxis.showline ?
  53796. 'M' + (x0 + w / 2) + ',' + y0 + 'l' + (w / 2) + ',' + h : 'M0,0')
  53797. .call(Color.stroke, caxis.linecolor || '#000')
  53798. .style('stroke-width', (caxis.linewidth || 0) + 'px');
  53799. if(!_this.graphDiv._context.staticPlot) {
  53800. _this.initInteractions();
  53801. }
  53802. Drawing.setClipUrl(
  53803. _this.layers.frontplot,
  53804. _this._hasClipOnAxisFalse ? null : _this.clipId
  53805. );
  53806. };
  53807. proto.drawAxes = function(doTitles) {
  53808. var _this = this;
  53809. var gd = _this.graphDiv;
  53810. var titlesuffix = _this.id.substr(7) + 'title';
  53811. var layers = _this.layers;
  53812. var aaxis = _this.aaxis;
  53813. var baxis = _this.baxis;
  53814. var caxis = _this.caxis;
  53815. var newTickLayout;
  53816. newTickLayout = strTickLayout(aaxis);
  53817. if(_this.aTickLayout !== newTickLayout) {
  53818. layers.aaxis.selectAll('.ytick').remove();
  53819. _this.aTickLayout = newTickLayout;
  53820. }
  53821. newTickLayout = strTickLayout(baxis);
  53822. if(_this.bTickLayout !== newTickLayout) {
  53823. layers.baxis.selectAll('.xtick').remove();
  53824. _this.bTickLayout = newTickLayout;
  53825. }
  53826. newTickLayout = strTickLayout(caxis);
  53827. if(_this.cTickLayout !== newTickLayout) {
  53828. layers.caxis.selectAll('.ytick').remove();
  53829. _this.cTickLayout = newTickLayout;
  53830. }
  53831. // 3rd arg true below skips titles, so we can configure them
  53832. // correctly later on.
  53833. Axes.doTicksSingle(gd, aaxis, true);
  53834. Axes.doTicksSingle(gd, baxis, true);
  53835. Axes.doTicksSingle(gd, caxis, true);
  53836. if(doTitles) {
  53837. var apad = Math.max(aaxis.showticklabels ? aaxis.tickfont.size / 2 : 0,
  53838. (caxis.showticklabels ? caxis.tickfont.size * 0.75 : 0) +
  53839. (caxis.ticks === 'outside' ? caxis.ticklen * 0.87 : 0));
  53840. _this.layers['a-title'] = Titles.draw(gd, 'a' + titlesuffix, {
  53841. propContainer: aaxis,
  53842. propName: _this.id + '.aaxis.title',
  53843. placeholder: _(gd, 'Click to enter Component A title'),
  53844. attributes: {
  53845. x: _this.x0 + _this.w / 2,
  53846. y: _this.y0 - aaxis.titlefont.size / 3 - apad,
  53847. 'text-anchor': 'middle'
  53848. }
  53849. });
  53850. var bpad = (baxis.showticklabels ? baxis.tickfont.size : 0) +
  53851. (baxis.ticks === 'outside' ? baxis.ticklen : 0) + 3;
  53852. _this.layers['b-title'] = Titles.draw(gd, 'b' + titlesuffix, {
  53853. propContainer: baxis,
  53854. propName: _this.id + '.baxis.title',
  53855. placeholder: _(gd, 'Click to enter Component B title'),
  53856. attributes: {
  53857. x: _this.x0 - bpad,
  53858. y: _this.y0 + _this.h + baxis.titlefont.size * 0.83 + bpad,
  53859. 'text-anchor': 'middle'
  53860. }
  53861. });
  53862. _this.layers['c-title'] = Titles.draw(gd, 'c' + titlesuffix, {
  53863. propContainer: caxis,
  53864. propName: _this.id + '.caxis.title',
  53865. placeholder: _(gd, 'Click to enter Component C title'),
  53866. attributes: {
  53867. x: _this.x0 + _this.w + bpad,
  53868. y: _this.y0 + _this.h + caxis.titlefont.size * 0.83 + bpad,
  53869. 'text-anchor': 'middle'
  53870. }
  53871. });
  53872. }
  53873. };
  53874. function strTickLayout(axLayout) {
  53875. return axLayout.ticks + String(axLayout.ticklen) + String(axLayout.showticklabels);
  53876. }
  53877. // hard coded paths for zoom corners
  53878. // uses the same sizing as cartesian, length is MINZOOM/2, width is 3px
  53879. var CLEN = constants.MINZOOM / 2 + 0.87;
  53880. var BLPATH = 'm-0.87,.5h' + CLEN + 'v3h-' + (CLEN + 5.2) +
  53881. 'l' + (CLEN / 2 + 2.6) + ',-' + (CLEN * 0.87 + 4.5) +
  53882. 'l2.6,1.5l-' + (CLEN / 2) + ',' + (CLEN * 0.87) + 'Z';
  53883. var BRPATH = 'm0.87,.5h-' + CLEN + 'v3h' + (CLEN + 5.2) +
  53884. 'l-' + (CLEN / 2 + 2.6) + ',-' + (CLEN * 0.87 + 4.5) +
  53885. 'l-2.6,1.5l' + (CLEN / 2) + ',' + (CLEN * 0.87) + 'Z';
  53886. var TOPPATH = 'm0,1l' + (CLEN / 2) + ',' + (CLEN * 0.87) +
  53887. 'l2.6,-1.5l-' + (CLEN / 2 + 2.6) + ',-' + (CLEN * 0.87 + 4.5) +
  53888. 'l-' + (CLEN / 2 + 2.6) + ',' + (CLEN * 0.87 + 4.5) +
  53889. 'l2.6,1.5l' + (CLEN / 2) + ',-' + (CLEN * 0.87) + 'Z';
  53890. var STARTMARKER = 'm0.5,0.5h5v-2h-5v-5h-2v5h-5v2h5v5h2Z';
  53891. // I guess this could be shared with cartesian... but for now it's separate.
  53892. var SHOWZOOMOUTTIP = true;
  53893. proto.initInteractions = function() {
  53894. var _this = this,
  53895. dragger = _this.layers.plotbg.select('path').node(),
  53896. gd = _this.graphDiv,
  53897. zoomContainer = gd._fullLayout._zoomlayer;
  53898. // use plotbg for the main interactions
  53899. var dragOptions = {
  53900. element: dragger,
  53901. gd: gd,
  53902. plotinfo: {
  53903. id: _this.id,
  53904. xaxis: _this.xaxis,
  53905. yaxis: _this.yaxis
  53906. },
  53907. subplot: _this.id,
  53908. prepFn: function(e, startX, startY) {
  53909. // these aren't available yet when initInteractions
  53910. // is called
  53911. dragOptions.xaxes = [_this.xaxis];
  53912. dragOptions.yaxes = [_this.yaxis];
  53913. var dragModeNow = gd._fullLayout.dragmode;
  53914. if(dragModeNow === 'lasso') dragOptions.minDrag = 1;
  53915. else dragOptions.minDrag = undefined;
  53916. if(dragModeNow === 'zoom') {
  53917. dragOptions.moveFn = zoomMove;
  53918. dragOptions.clickFn = clickZoomPan;
  53919. dragOptions.doneFn = zoomDone;
  53920. zoomPrep(e, startX, startY);
  53921. }
  53922. else if(dragModeNow === 'pan') {
  53923. dragOptions.moveFn = plotDrag;
  53924. dragOptions.clickFn = clickZoomPan;
  53925. dragOptions.doneFn = dragDone;
  53926. panPrep();
  53927. clearSelect(zoomContainer);
  53928. }
  53929. else if(dragModeNow === 'select' || dragModeNow === 'lasso') {
  53930. prepSelect(e, startX, startY, dragOptions, dragModeNow);
  53931. }
  53932. }
  53933. };
  53934. var x0, y0, mins0, span0, mins, lum, path0, dimmed, zb, corners;
  53935. function clickZoomPan(numClicks, evt) {
  53936. var clickMode = gd._fullLayout.clickmode;
  53937. removeZoombox(gd);
  53938. if(numClicks === 2) {
  53939. var attrs = {};
  53940. attrs[_this.id + '.aaxis.min'] = 0;
  53941. attrs[_this.id + '.baxis.min'] = 0;
  53942. attrs[_this.id + '.caxis.min'] = 0;
  53943. gd.emit('plotly_doubleclick', null);
  53944. Registry.call('relayout', gd, attrs);
  53945. }
  53946. if(clickMode.indexOf('select') > -1 && numClicks === 1) {
  53947. selectOnClick(evt, gd, [_this.xaxis], [_this.yaxis], _this.id, dragOptions);
  53948. }
  53949. if(clickMode.indexOf('event') > -1) {
  53950. Fx.click(gd, evt, _this.id);
  53951. }
  53952. }
  53953. function zoomPrep(e, startX, startY) {
  53954. var dragBBox = dragger.getBoundingClientRect();
  53955. x0 = startX - dragBBox.left;
  53956. y0 = startY - dragBBox.top;
  53957. mins0 = {
  53958. a: _this.aaxis.range[0],
  53959. b: _this.baxis.range[1],
  53960. c: _this.caxis.range[1]
  53961. };
  53962. mins = mins0;
  53963. span0 = _this.aaxis.range[1] - mins0.a;
  53964. lum = tinycolor(_this.graphDiv._fullLayout[_this.id].bgcolor).getLuminance();
  53965. path0 = 'M0,' + _this.h + 'L' + (_this.w / 2) + ', 0L' + _this.w + ',' + _this.h + 'Z';
  53966. dimmed = false;
  53967. zb = zoomContainer.append('path')
  53968. .attr('class', 'zoombox')
  53969. .attr('transform', 'translate(' + _this.x0 + ', ' + _this.y0 + ')')
  53970. .style({
  53971. 'fill': lum > 0.2 ? 'rgba(0,0,0,0)' : 'rgba(255,255,255,0)',
  53972. 'stroke-width': 0
  53973. })
  53974. .attr('d', path0);
  53975. corners = zoomContainer.append('path')
  53976. .attr('class', 'zoombox-corners')
  53977. .attr('transform', 'translate(' + _this.x0 + ', ' + _this.y0 + ')')
  53978. .style({
  53979. fill: Color.background,
  53980. stroke: Color.defaultLine,
  53981. 'stroke-width': 1,
  53982. opacity: 0
  53983. })
  53984. .attr('d', 'M0,0Z');
  53985. clearSelect(zoomContainer);
  53986. }
  53987. function getAFrac(x, y) { return 1 - (y / _this.h); }
  53988. function getBFrac(x, y) { return 1 - ((x + (_this.h - y) / Math.sqrt(3)) / _this.w); }
  53989. function getCFrac(x, y) { return ((x - (_this.h - y) / Math.sqrt(3)) / _this.w); }
  53990. function zoomMove(dx0, dy0) {
  53991. var x1 = x0 + dx0,
  53992. y1 = y0 + dy0,
  53993. afrac = Math.max(0, Math.min(1, getAFrac(x0, y0), getAFrac(x1, y1))),
  53994. bfrac = Math.max(0, Math.min(1, getBFrac(x0, y0), getBFrac(x1, y1))),
  53995. cfrac = Math.max(0, Math.min(1, getCFrac(x0, y0), getCFrac(x1, y1))),
  53996. xLeft = ((afrac / 2) + cfrac) * _this.w,
  53997. xRight = (1 - (afrac / 2) - bfrac) * _this.w,
  53998. xCenter = (xLeft + xRight) / 2,
  53999. xSpan = xRight - xLeft,
  54000. yBottom = (1 - afrac) * _this.h,
  54001. yTop = yBottom - xSpan / w_over_h;
  54002. if(xSpan < constants.MINZOOM) {
  54003. mins = mins0;
  54004. zb.attr('d', path0);
  54005. corners.attr('d', 'M0,0Z');
  54006. }
  54007. else {
  54008. mins = {
  54009. a: mins0.a + afrac * span0,
  54010. b: mins0.b + bfrac * span0,
  54011. c: mins0.c + cfrac * span0
  54012. };
  54013. zb.attr('d', path0 + 'M' + xLeft + ',' + yBottom +
  54014. 'H' + xRight + 'L' + xCenter + ',' + yTop +
  54015. 'L' + xLeft + ',' + yBottom + 'Z');
  54016. corners.attr('d', 'M' + x0 + ',' + y0 + STARTMARKER +
  54017. 'M' + xLeft + ',' + yBottom + BLPATH +
  54018. 'M' + xRight + ',' + yBottom + BRPATH +
  54019. 'M' + xCenter + ',' + yTop + TOPPATH);
  54020. }
  54021. if(!dimmed) {
  54022. zb.transition()
  54023. .style('fill', lum > 0.2 ? 'rgba(0,0,0,0.4)' :
  54024. 'rgba(255,255,255,0.3)')
  54025. .duration(200);
  54026. corners.transition()
  54027. .style('opacity', 1)
  54028. .duration(200);
  54029. dimmed = true;
  54030. }
  54031. }
  54032. function zoomDone() {
  54033. removeZoombox(gd);
  54034. if(mins === mins0) return;
  54035. var attrs = {};
  54036. attrs[_this.id + '.aaxis.min'] = mins.a;
  54037. attrs[_this.id + '.baxis.min'] = mins.b;
  54038. attrs[_this.id + '.caxis.min'] = mins.c;
  54039. Registry.call('relayout', gd, attrs);
  54040. if(SHOWZOOMOUTTIP && gd.data && gd._context.showTips) {
  54041. Lib.notifier(_(gd, 'Double-click to zoom back out'), 'long');
  54042. SHOWZOOMOUTTIP = false;
  54043. }
  54044. }
  54045. function panPrep() {
  54046. mins0 = {
  54047. a: _this.aaxis.range[0],
  54048. b: _this.baxis.range[1],
  54049. c: _this.caxis.range[1]
  54050. };
  54051. mins = mins0;
  54052. }
  54053. function plotDrag(dx, dy) {
  54054. var dxScaled = dx / _this.xaxis._m,
  54055. dyScaled = dy / _this.yaxis._m;
  54056. mins = {
  54057. a: mins0.a - dyScaled,
  54058. b: mins0.b + (dxScaled + dyScaled) / 2,
  54059. c: mins0.c - (dxScaled - dyScaled) / 2
  54060. };
  54061. var minsorted = [mins.a, mins.b, mins.c].sort(),
  54062. minindices = {
  54063. a: minsorted.indexOf(mins.a),
  54064. b: minsorted.indexOf(mins.b),
  54065. c: minsorted.indexOf(mins.c)
  54066. };
  54067. if(minsorted[0] < 0) {
  54068. if(minsorted[1] + minsorted[0] / 2 < 0) {
  54069. minsorted[2] += minsorted[0] + minsorted[1];
  54070. minsorted[0] = minsorted[1] = 0;
  54071. }
  54072. else {
  54073. minsorted[2] += minsorted[0] / 2;
  54074. minsorted[1] += minsorted[0] / 2;
  54075. minsorted[0] = 0;
  54076. }
  54077. mins = {
  54078. a: minsorted[minindices.a],
  54079. b: minsorted[minindices.b],
  54080. c: minsorted[minindices.c]
  54081. };
  54082. dy = (mins0.a - mins.a) * _this.yaxis._m;
  54083. dx = (mins0.c - mins.c - mins0.b + mins.b) * _this.xaxis._m;
  54084. }
  54085. // move the data (translate, don't redraw)
  54086. var plotTransform = 'translate(' + (_this.x0 + dx) + ',' + (_this.y0 + dy) + ')';
  54087. _this.plotContainer.selectAll('.scatterlayer,.maplayer')
  54088. .attr('transform', plotTransform);
  54089. var plotTransform2 = 'translate(' + -dx + ',' + -dy + ')';
  54090. _this.clipDefRelative.select('path').attr('transform', plotTransform2);
  54091. // move the ticks
  54092. _this.aaxis.range = [mins.a, _this.sum - mins.b - mins.c];
  54093. _this.baxis.range = [_this.sum - mins.a - mins.c, mins.b];
  54094. _this.caxis.range = [_this.sum - mins.a - mins.b, mins.c];
  54095. _this.drawAxes(false);
  54096. _this.plotContainer.selectAll('.crisp').classed('crisp', false);
  54097. if(_this._hasClipOnAxisFalse) {
  54098. _this.plotContainer
  54099. .select('.scatterlayer').selectAll('.trace')
  54100. .call(Drawing.hideOutsideRangePoints, _this);
  54101. }
  54102. }
  54103. function dragDone() {
  54104. var attrs = {};
  54105. attrs[_this.id + '.aaxis.min'] = mins.a;
  54106. attrs[_this.id + '.baxis.min'] = mins.b;
  54107. attrs[_this.id + '.caxis.min'] = mins.c;
  54108. Registry.call('relayout', gd, attrs);
  54109. }
  54110. // finally, set up hover and click
  54111. // these event handlers must already be set before dragElement.init
  54112. // so it can stash them and override them.
  54113. dragger.onmousemove = function(evt) {
  54114. Fx.hover(gd, evt, _this.id);
  54115. gd._fullLayout._lasthover = dragger;
  54116. gd._fullLayout._hoversubplot = _this.id;
  54117. };
  54118. dragger.onmouseout = function(evt) {
  54119. if(gd._dragging) return;
  54120. dragElement.unhover(gd, evt);
  54121. };
  54122. dragElement.init(dragOptions);
  54123. };
  54124. function removeZoombox(gd) {
  54125. d3.select(gd)
  54126. .selectAll('.zoombox,.js-zoombox-backdrop,.js-zoombox-menu,.zoombox-corners')
  54127. .remove();
  54128. }
  54129. },{"../../components/color":50,"../../components/dragelement":72,"../../components/drawing":75,"../../components/fx":92,"../../components/titles":141,"../../lib":169,"../../lib/extend":163,"../../registry":259,"../cartesian/axes":214,"../cartesian/constants":219,"../cartesian/select":231,"../cartesian/set_convert":232,"../plots":246,"d3":16,"tinycolor2":33}],259:[function(_dereq_,module,exports){
  54130. /**
  54131. * Copyright 2012-2018, Plotly, Inc.
  54132. * All rights reserved.
  54133. *
  54134. * This source code is licensed under the MIT license found in the
  54135. * LICENSE file in the root directory of this source tree.
  54136. */
  54137. 'use strict';
  54138. var Loggers = _dereq_('./lib/loggers');
  54139. var noop = _dereq_('./lib/noop');
  54140. var pushUnique = _dereq_('./lib/push_unique');
  54141. var isPlainObject = _dereq_('./lib/is_plain_object');
  54142. var ExtendModule = _dereq_('./lib/extend');
  54143. var basePlotAttributes = _dereq_('./plots/attributes');
  54144. var baseLayoutAttributes = _dereq_('./plots/layout_attributes');
  54145. var extendFlat = ExtendModule.extendFlat;
  54146. var extendDeepAll = ExtendModule.extendDeepAll;
  54147. exports.modules = {};
  54148. exports.allCategories = {};
  54149. exports.allTypes = [];
  54150. exports.subplotsRegistry = {};
  54151. exports.transformsRegistry = {};
  54152. exports.componentsRegistry = {};
  54153. exports.layoutArrayContainers = [];
  54154. exports.layoutArrayRegexes = [];
  54155. exports.traceLayoutAttributes = {};
  54156. exports.localeRegistry = {};
  54157. exports.apiMethodRegistry = {};
  54158. /**
  54159. * Top-level register routine, exported as Plotly.register
  54160. *
  54161. * @param {object array or array of objects} _modules :
  54162. * module object or list of module object to register.
  54163. *
  54164. * A valid `moduleType: 'trace'` module has fields:
  54165. * - name {string} : the trace type
  54166. * - categories {array} : categories associated with this trace type,
  54167. * tested with Register.traceIs()
  54168. * - meta {object} : meta info (mostly for plot-schema)
  54169. *
  54170. * A valid `moduleType: 'locale'` module has fields:
  54171. * - name {string} : the locale name. Should be a 2-digit language string ('en', 'de')
  54172. * optionally with a country/region code ('en-GB', 'de-CH'). If a country
  54173. * code is used but the base language locale has not yet been supplied,
  54174. * we will use this locale for the base as well.
  54175. * - dictionary {object} : the dictionary mapping input strings to localized strings
  54176. * generally the keys should be the literal input strings, but
  54177. * if default translations are provided you can use any string as a key.
  54178. * - format {object} : a `d3.locale` format specifier for this locale
  54179. * any omitted keys we'll fall back on en-US.
  54180. *
  54181. * A valid `moduleType: 'transform'` module has fields:
  54182. * - name {string} : transform name
  54183. * - transform {function} : default-level transform function
  54184. * - calcTransform {function} : calc-level transform function
  54185. * - attributes {object} : transform attributes declarations
  54186. * - supplyDefaults {function} : attributes default-supply function
  54187. *
  54188. * A valid `moduleType: 'component'` module has fields:
  54189. * - name {string} : the component name, used it with Register.getComponentMethod()
  54190. * to employ component method.
  54191. *
  54192. * A valid `moduleType: 'apiMethod'` module has fields:
  54193. * - name {string} : the api method name.
  54194. * - fn {function} : the api method called with Register.call();
  54195. *
  54196. */
  54197. exports.register = function register(_modules) {
  54198. if(!_modules) {
  54199. throw new Error('No argument passed to Plotly.register.');
  54200. } else if(_modules && !Array.isArray(_modules)) {
  54201. _modules = [_modules];
  54202. }
  54203. for(var i = 0; i < _modules.length; i++) {
  54204. var newModule = _modules[i];
  54205. if(!newModule) {
  54206. throw new Error('Invalid module was attempted to be registered!');
  54207. }
  54208. switch(newModule.moduleType) {
  54209. case 'trace':
  54210. registerTraceModule(newModule);
  54211. break;
  54212. case 'transform':
  54213. registerTransformModule(newModule);
  54214. break;
  54215. case 'component':
  54216. registerComponentModule(newModule);
  54217. break;
  54218. case 'locale':
  54219. registerLocale(newModule);
  54220. break;
  54221. case 'apiMethod':
  54222. var name = newModule.name;
  54223. exports.apiMethodRegistry[name] = newModule.fn;
  54224. break;
  54225. default:
  54226. throw new Error('Invalid module was attempted to be registered!');
  54227. }
  54228. }
  54229. };
  54230. /**
  54231. * Get registered module using trace object or trace type
  54232. *
  54233. * @param {object||string} trace
  54234. * trace object with prop 'type' or trace type as a string
  54235. * @return {object}
  54236. * module object corresponding to trace type
  54237. */
  54238. exports.getModule = function(trace) {
  54239. var _module = exports.modules[getTraceType(trace)];
  54240. if(!_module) return false;
  54241. return _module._module;
  54242. };
  54243. /**
  54244. * Determine if this trace type is in a given category
  54245. *
  54246. * @param {object||string} traceType
  54247. * a trace (object) or trace type (string)
  54248. * @param {string} category
  54249. * category in question
  54250. * @return {boolean}
  54251. */
  54252. exports.traceIs = function(traceType, category) {
  54253. traceType = getTraceType(traceType);
  54254. // old plot.ly workspace hack, nothing to see here
  54255. if(traceType === 'various') return false;
  54256. var _module = exports.modules[traceType];
  54257. if(!_module) {
  54258. if(traceType && traceType !== 'area') {
  54259. Loggers.log('Unrecognized trace type ' + traceType + '.');
  54260. }
  54261. _module = exports.modules[basePlotAttributes.type.dflt];
  54262. }
  54263. return !!_module.categories[category];
  54264. };
  54265. /**
  54266. * Determine if this trace has a transform of the given type and return
  54267. * array of matching indices.
  54268. *
  54269. * @param {object} data
  54270. * a trace object (member of data or fullData)
  54271. * @param {string} type
  54272. * type of trace to test
  54273. * @return {array}
  54274. * array of matching indices. If none found, returns []
  54275. */
  54276. exports.getTransformIndices = function(data, type) {
  54277. var indices = [];
  54278. var transforms = data.transforms || [];
  54279. for(var i = 0; i < transforms.length; i++) {
  54280. if(transforms[i].type === type) {
  54281. indices.push(i);
  54282. }
  54283. }
  54284. return indices;
  54285. };
  54286. /**
  54287. * Determine if this trace has a transform of the given type
  54288. *
  54289. * @param {object} data
  54290. * a trace object (member of data or fullData)
  54291. * @param {string} type
  54292. * type of trace to test
  54293. * @return {boolean}
  54294. */
  54295. exports.hasTransform = function(data, type) {
  54296. var transforms = data.transforms || [];
  54297. for(var i = 0; i < transforms.length; i++) {
  54298. if(transforms[i].type === type) {
  54299. return true;
  54300. }
  54301. }
  54302. return false;
  54303. };
  54304. /**
  54305. * Retrieve component module method. Falls back on noop if either the
  54306. * module or the method is missing, so the result can always be safely called
  54307. *
  54308. * @param {string} name
  54309. * name of component (as declared in component module)
  54310. * @param {string} method
  54311. * name of component module method
  54312. * @return {function}
  54313. */
  54314. exports.getComponentMethod = function(name, method) {
  54315. var _module = exports.componentsRegistry[name];
  54316. if(!_module) return noop;
  54317. return _module[method] || noop;
  54318. };
  54319. /**
  54320. * Call registered api method.
  54321. *
  54322. * @param {string} name : api method name
  54323. * @param {...array} args : arguments passed to api method
  54324. * @return {any} : returns api method output
  54325. */
  54326. exports.call = function() {
  54327. var name = arguments[0];
  54328. var args = [].slice.call(arguments, 1);
  54329. return exports.apiMethodRegistry[name].apply(null, args);
  54330. };
  54331. function registerTraceModule(_module) {
  54332. var thisType = _module.name;
  54333. var categoriesIn = _module.categories;
  54334. var meta = _module.meta;
  54335. if(exports.modules[thisType]) {
  54336. Loggers.log('Type ' + thisType + ' already registered');
  54337. return;
  54338. }
  54339. if(!exports.subplotsRegistry[_module.basePlotModule.name]) {
  54340. registerSubplot(_module.basePlotModule);
  54341. }
  54342. var categoryObj = {};
  54343. for(var i = 0; i < categoriesIn.length; i++) {
  54344. categoryObj[categoriesIn[i]] = true;
  54345. exports.allCategories[categoriesIn[i]] = true;
  54346. }
  54347. exports.modules[thisType] = {
  54348. _module: _module,
  54349. categories: categoryObj
  54350. };
  54351. if(meta && Object.keys(meta).length) {
  54352. exports.modules[thisType].meta = meta;
  54353. }
  54354. exports.allTypes.push(thisType);
  54355. for(var componentName in exports.componentsRegistry) {
  54356. mergeComponentAttrsToTrace(componentName, thisType);
  54357. }
  54358. /*
  54359. * Collect all trace layout attributes in one place for easier lookup later
  54360. * but don't merge them into the base schema as it would confuse the docs
  54361. * (at least after https://github.com/plotly/documentation/issues/202 gets done!)
  54362. */
  54363. if(_module.layoutAttributes) {
  54364. extendFlat(exports.traceLayoutAttributes, _module.layoutAttributes);
  54365. }
  54366. }
  54367. function registerSubplot(_module) {
  54368. var plotType = _module.name;
  54369. if(exports.subplotsRegistry[plotType]) {
  54370. Loggers.log('Plot type ' + plotType + ' already registered.');
  54371. return;
  54372. }
  54373. // relayout array handling will look for component module methods with this
  54374. // name and won't find them because this is a subplot module... but that
  54375. // should be fine, it will just fall back on redrawing the plot.
  54376. findArrayRegexps(_module);
  54377. // not sure what's best for the 'cartesian' type at this point
  54378. exports.subplotsRegistry[plotType] = _module;
  54379. for(var componentName in exports.componentsRegistry) {
  54380. mergeComponentAttrsToSubplot(componentName, _module.name);
  54381. }
  54382. }
  54383. function registerComponentModule(_module) {
  54384. if(typeof _module.name !== 'string') {
  54385. throw new Error('Component module *name* must be a string.');
  54386. }
  54387. var name = _module.name;
  54388. exports.componentsRegistry[name] = _module;
  54389. if(_module.layoutAttributes) {
  54390. if(_module.layoutAttributes._isLinkedToArray) {
  54391. pushUnique(exports.layoutArrayContainers, name);
  54392. }
  54393. findArrayRegexps(_module);
  54394. }
  54395. for(var traceType in exports.modules) {
  54396. mergeComponentAttrsToTrace(name, traceType);
  54397. }
  54398. for(var subplotName in exports.subplotsRegistry) {
  54399. mergeComponentAttrsToSubplot(name, subplotName);
  54400. }
  54401. for(var transformType in exports.transformsRegistry) {
  54402. mergeComponentAttrsToTransform(name, transformType);
  54403. }
  54404. if(_module.schema && _module.schema.layout) {
  54405. extendDeepAll(baseLayoutAttributes, _module.schema.layout);
  54406. }
  54407. }
  54408. function registerTransformModule(_module) {
  54409. if(typeof _module.name !== 'string') {
  54410. throw new Error('Transform module *name* must be a string.');
  54411. }
  54412. var prefix = 'Transform module ' + _module.name;
  54413. var hasTransform = typeof _module.transform === 'function';
  54414. var hasCalcTransform = typeof _module.calcTransform === 'function';
  54415. if(!hasTransform && !hasCalcTransform) {
  54416. throw new Error(prefix + ' is missing a *transform* or *calcTransform* method.');
  54417. }
  54418. if(hasTransform && hasCalcTransform) {
  54419. Loggers.log([
  54420. prefix + ' has both a *transform* and *calcTransform* methods.',
  54421. 'Please note that all *transform* methods are executed',
  54422. 'before all *calcTransform* methods.'
  54423. ].join(' '));
  54424. }
  54425. if(!isPlainObject(_module.attributes)) {
  54426. Loggers.log(prefix + ' registered without an *attributes* object.');
  54427. }
  54428. if(typeof _module.supplyDefaults !== 'function') {
  54429. Loggers.log(prefix + ' registered without a *supplyDefaults* method.');
  54430. }
  54431. exports.transformsRegistry[_module.name] = _module;
  54432. for(var componentName in exports.componentsRegistry) {
  54433. mergeComponentAttrsToTransform(componentName, _module.name);
  54434. }
  54435. }
  54436. function registerLocale(_module) {
  54437. var locale = _module.name;
  54438. var baseLocale = locale.split('-')[0];
  54439. var newDict = _module.dictionary;
  54440. var newFormat = _module.format;
  54441. var hasDict = newDict && Object.keys(newDict).length;
  54442. var hasFormat = newFormat && Object.keys(newFormat).length;
  54443. var locales = exports.localeRegistry;
  54444. var localeObj = locales[locale];
  54445. if(!localeObj) locales[locale] = localeObj = {};
  54446. // Should we use this dict for the base locale?
  54447. // In case we're overwriting a previous dict for this locale, check
  54448. // whether the base matches the full locale dict now. If we're not
  54449. // overwriting, locales[locale] is undefined so this just checks if
  54450. // baseLocale already had a dict or not.
  54451. // Same logic for dateFormats
  54452. if(baseLocale !== locale) {
  54453. var baseLocaleObj = locales[baseLocale];
  54454. if(!baseLocaleObj) locales[baseLocale] = baseLocaleObj = {};
  54455. if(hasDict && baseLocaleObj.dictionary === localeObj.dictionary) {
  54456. baseLocaleObj.dictionary = newDict;
  54457. }
  54458. if(hasFormat && baseLocaleObj.format === localeObj.format) {
  54459. baseLocaleObj.format = newFormat;
  54460. }
  54461. }
  54462. if(hasDict) localeObj.dictionary = newDict;
  54463. if(hasFormat) localeObj.format = newFormat;
  54464. }
  54465. function findArrayRegexps(_module) {
  54466. if(_module.layoutAttributes) {
  54467. var arrayAttrRegexps = _module.layoutAttributes._arrayAttrRegexps;
  54468. if(arrayAttrRegexps) {
  54469. for(var i = 0; i < arrayAttrRegexps.length; i++) {
  54470. pushUnique(exports.layoutArrayRegexes, arrayAttrRegexps[i]);
  54471. }
  54472. }
  54473. }
  54474. }
  54475. function mergeComponentAttrsToTrace(componentName, traceType) {
  54476. var componentSchema = exports.componentsRegistry[componentName].schema;
  54477. if(!componentSchema || !componentSchema.traces) return;
  54478. var traceAttrs = componentSchema.traces[traceType];
  54479. if(traceAttrs) {
  54480. extendDeepAll(exports.modules[traceType]._module.attributes, traceAttrs);
  54481. }
  54482. }
  54483. function mergeComponentAttrsToTransform(componentName, transformType) {
  54484. var componentSchema = exports.componentsRegistry[componentName].schema;
  54485. if(!componentSchema || !componentSchema.transforms) return;
  54486. var transformAttrs = componentSchema.transforms[transformType];
  54487. if(transformAttrs) {
  54488. extendDeepAll(exports.transformsRegistry[transformType].attributes, transformAttrs);
  54489. }
  54490. }
  54491. function mergeComponentAttrsToSubplot(componentName, subplotName) {
  54492. var componentSchema = exports.componentsRegistry[componentName].schema;
  54493. if(!componentSchema || !componentSchema.subplots) return;
  54494. var subplotModule = exports.subplotsRegistry[subplotName];
  54495. var subplotAttrs = subplotModule.layoutAttributes;
  54496. var subplotAttr = subplotModule.attr === 'subplot' ? subplotModule.name : subplotModule.attr;
  54497. if(Array.isArray(subplotAttr)) subplotAttr = subplotAttr[0];
  54498. var componentLayoutAttrs = componentSchema.subplots[subplotAttr];
  54499. if(subplotAttrs && componentLayoutAttrs) {
  54500. extendDeepAll(subplotAttrs, componentLayoutAttrs);
  54501. }
  54502. }
  54503. function getTraceType(traceType) {
  54504. if(typeof traceType === 'object') traceType = traceType.type;
  54505. return traceType;
  54506. }
  54507. },{"./lib/extend":163,"./lib/is_plain_object":171,"./lib/loggers":174,"./lib/noop":179,"./lib/push_unique":183,"./plots/attributes":211,"./plots/layout_attributes":244}],260:[function(_dereq_,module,exports){
  54508. /**
  54509. * Copyright 2012-2018, Plotly, Inc.
  54510. * All rights reserved.
  54511. *
  54512. * This source code is licensed under the MIT license found in the
  54513. * LICENSE file in the root directory of this source tree.
  54514. */
  54515. 'use strict';
  54516. var Lib = _dereq_('../lib');
  54517. var extendFlat = Lib.extendFlat;
  54518. var extendDeep = Lib.extendDeep;
  54519. // Put default plotTile layouts here
  54520. function cloneLayoutOverride(tileClass) {
  54521. var override;
  54522. switch(tileClass) {
  54523. case 'themes__thumb':
  54524. override = {
  54525. autosize: true,
  54526. width: 150,
  54527. height: 150,
  54528. title: '',
  54529. showlegend: false,
  54530. margin: {l: 5, r: 5, t: 5, b: 5, pad: 0},
  54531. annotations: []
  54532. };
  54533. break;
  54534. case 'thumbnail':
  54535. override = {
  54536. title: '',
  54537. hidesources: true,
  54538. showlegend: false,
  54539. borderwidth: 0,
  54540. bordercolor: '',
  54541. margin: {l: 1, r: 1, t: 1, b: 1, pad: 0},
  54542. annotations: []
  54543. };
  54544. break;
  54545. default:
  54546. override = {};
  54547. }
  54548. return override;
  54549. }
  54550. function keyIsAxis(keyName) {
  54551. var types = ['xaxis', 'yaxis', 'zaxis'];
  54552. return (types.indexOf(keyName.slice(0, 5)) > -1);
  54553. }
  54554. module.exports = function clonePlot(graphObj, options) {
  54555. // Polar plot compatibility
  54556. if(graphObj.framework && graphObj.framework.isPolar) {
  54557. graphObj = graphObj.framework.getConfig();
  54558. }
  54559. var i;
  54560. var oldData = graphObj.data;
  54561. var oldLayout = graphObj.layout;
  54562. var newData = extendDeep([], oldData);
  54563. var newLayout = extendDeep({}, oldLayout, cloneLayoutOverride(options.tileClass));
  54564. var context = graphObj._context || {};
  54565. if(options.width) newLayout.width = options.width;
  54566. if(options.height) newLayout.height = options.height;
  54567. if(options.tileClass === 'thumbnail' || options.tileClass === 'themes__thumb') {
  54568. // kill annotations
  54569. newLayout.annotations = [];
  54570. var keys = Object.keys(newLayout);
  54571. for(i = 0; i < keys.length; i++) {
  54572. if(keyIsAxis(keys[i])) {
  54573. newLayout[keys[i]].title = '';
  54574. }
  54575. }
  54576. // kill colorbar and pie labels
  54577. for(i = 0; i < newData.length; i++) {
  54578. var trace = newData[i];
  54579. trace.showscale = false;
  54580. if(trace.marker) trace.marker.showscale = false;
  54581. if(trace.type === 'pie') trace.textposition = 'none';
  54582. }
  54583. }
  54584. if(Array.isArray(options.annotations)) {
  54585. for(i = 0; i < options.annotations.length; i++) {
  54586. newLayout.annotations.push(options.annotations[i]);
  54587. }
  54588. }
  54589. // TODO: does this scene modification really belong here?
  54590. // If we still need it, can it move into the gl3d module?
  54591. var sceneIds = Object.keys(newLayout).filter(function(key) {
  54592. return key.match(/^scene\d*$/);
  54593. });
  54594. if(sceneIds.length) {
  54595. var axesImageOverride = {};
  54596. if(options.tileClass === 'thumbnail') {
  54597. axesImageOverride = {
  54598. title: '',
  54599. showaxeslabels: false,
  54600. showticklabels: false,
  54601. linetickenable: false
  54602. };
  54603. }
  54604. for(i = 0; i < sceneIds.length; i++) {
  54605. var scene = newLayout[sceneIds[i]];
  54606. if(!scene.xaxis) {
  54607. scene.xaxis = {};
  54608. }
  54609. if(!scene.yaxis) {
  54610. scene.yaxis = {};
  54611. }
  54612. if(!scene.zaxis) {
  54613. scene.zaxis = {};
  54614. }
  54615. extendFlat(scene.xaxis, axesImageOverride);
  54616. extendFlat(scene.yaxis, axesImageOverride);
  54617. extendFlat(scene.zaxis, axesImageOverride);
  54618. // TODO what does this do?
  54619. scene._scene = null;
  54620. }
  54621. }
  54622. var gd = document.createElement('div');
  54623. if(options.tileClass) gd.className = options.tileClass;
  54624. var plotTile = {
  54625. gd: gd,
  54626. td: gd, // for external (image server) compatibility
  54627. layout: newLayout,
  54628. data: newData,
  54629. config: {
  54630. staticPlot: (options.staticPlot === undefined) ?
  54631. true :
  54632. options.staticPlot,
  54633. plotGlPixelRatio: (options.plotGlPixelRatio === undefined) ?
  54634. 2 :
  54635. options.plotGlPixelRatio,
  54636. displaylogo: options.displaylogo || false,
  54637. showLink: options.showLink || false,
  54638. showTips: options.showTips || false,
  54639. mapboxAccessToken: context.mapboxAccessToken
  54640. }
  54641. };
  54642. if(options.setBackground !== 'transparent') {
  54643. plotTile.config.setBackground = options.setBackground || 'opaque';
  54644. }
  54645. // attaching the default Layout the gd, so you can grab it later
  54646. plotTile.gd.defaultLayout = cloneLayoutOverride(options.tileClass);
  54647. return plotTile;
  54648. };
  54649. },{"../lib":169}],261:[function(_dereq_,module,exports){
  54650. /**
  54651. * Copyright 2012-2018, Plotly, Inc.
  54652. * All rights reserved.
  54653. *
  54654. * This source code is licensed under the MIT license found in the
  54655. * LICENSE file in the root directory of this source tree.
  54656. */
  54657. 'use strict';
  54658. var toImage = _dereq_('../plot_api/to_image');
  54659. var Lib = _dereq_('../lib'); // for isIE
  54660. var fileSaver = _dereq_('./filesaver');
  54661. /** Plotly.downloadImage
  54662. *
  54663. * @param {object | string | HTML div} gd
  54664. * can either be a data/layout/config object
  54665. * or an existing graph <div>
  54666. * or an id to an existing graph <div>
  54667. * @param {object} opts (see ../plot_api/to_image)
  54668. * @return {promise}
  54669. */
  54670. function downloadImage(gd, opts) {
  54671. var _gd;
  54672. if(!Lib.isPlainObject(gd)) _gd = Lib.getGraphDiv(gd);
  54673. // check for undefined opts
  54674. opts = opts || {};
  54675. // default to png
  54676. opts.format = opts.format || 'png';
  54677. return new Promise(function(resolve, reject) {
  54678. if(_gd && _gd._snapshotInProgress) {
  54679. reject(new Error('Snapshotting already in progress.'));
  54680. }
  54681. // see comments within svgtoimg for additional
  54682. // discussion of problems with IE
  54683. // can now draw to canvas, but CORS tainted canvas
  54684. // does not allow toDataURL
  54685. // svg format will work though
  54686. if(Lib.isIE() && opts.format !== 'svg') {
  54687. reject(new Error('Sorry IE does not support downloading from canvas. Try {format:\'svg\'} instead.'));
  54688. }
  54689. if(_gd) _gd._snapshotInProgress = true;
  54690. var promise = toImage(gd, opts);
  54691. var filename = opts.filename || gd.fn || 'newplot';
  54692. filename += '.' + opts.format;
  54693. promise.then(function(result) {
  54694. if(_gd) _gd._snapshotInProgress = false;
  54695. return fileSaver(result, filename);
  54696. }).then(function(name) {
  54697. resolve(name);
  54698. }).catch(function(err) {
  54699. if(_gd) _gd._snapshotInProgress = false;
  54700. reject(err);
  54701. });
  54702. });
  54703. }
  54704. module.exports = downloadImage;
  54705. },{"../lib":169,"../plot_api/to_image":207,"./filesaver":262}],262:[function(_dereq_,module,exports){
  54706. /**
  54707. * Copyright 2012-2018, Plotly, Inc.
  54708. * All rights reserved.
  54709. *
  54710. * This source code is licensed under the MIT license found in the
  54711. * LICENSE file in the root directory of this source tree.
  54712. */
  54713. /*
  54714. * substantial portions of this code from FileSaver.js
  54715. * https://github.com/eligrey/FileSaver.js
  54716. * License: https://github.com/eligrey/FileSaver.js/blob/master/LICENSE.md
  54717. * FileSaver.js
  54718. * A saveAs() FileSaver implementation.
  54719. * 1.1.20160328
  54720. *
  54721. * By Eli Grey, http://eligrey.com
  54722. * License: MIT
  54723. * See https://github.com/eligrey/FileSaver.js/blob/master/LICENSE.md
  54724. */
  54725. 'use strict';
  54726. var fileSaver = function(url, name) {
  54727. var saveLink = document.createElement('a');
  54728. var canUseSaveLink = 'download' in saveLink;
  54729. var isSafari = /Version\/[\d\.]+.*Safari/.test(navigator.userAgent);
  54730. var promise = new Promise(function(resolve, reject) {
  54731. // IE <10 is explicitly unsupported
  54732. if(typeof navigator !== 'undefined' && /MSIE [1-9]\./.test(navigator.userAgent)) {
  54733. reject(new Error('IE < 10 unsupported'));
  54734. }
  54735. // First try a.download, then web filesystem, then object URLs
  54736. if(isSafari) {
  54737. // Safari doesn't allow downloading of blob urls
  54738. document.location.href = 'data:application/octet-stream' + url.slice(url.search(/[,;]/));
  54739. resolve(name);
  54740. }
  54741. if(!name) {
  54742. name = 'download';
  54743. }
  54744. if(canUseSaveLink) {
  54745. saveLink.href = url;
  54746. saveLink.download = name;
  54747. document.body.appendChild(saveLink);
  54748. saveLink.click();
  54749. document.body.removeChild(saveLink);
  54750. resolve(name);
  54751. }
  54752. // IE 10+ (native saveAs)
  54753. if(typeof navigator !== 'undefined' && navigator.msSaveBlob) {
  54754. // At this point we are only dealing with a SVG encoded as
  54755. // a data URL (since IE only supports SVG)
  54756. var encoded = url.split(/^data:image\/svg\+xml,/)[1];
  54757. var svg = decodeURIComponent(encoded);
  54758. navigator.msSaveBlob(new Blob([svg]), name);
  54759. resolve(name);
  54760. }
  54761. reject(new Error('download error'));
  54762. });
  54763. return promise;
  54764. };
  54765. module.exports = fileSaver;
  54766. },{}],263:[function(_dereq_,module,exports){
  54767. /**
  54768. * Copyright 2012-2018, Plotly, Inc.
  54769. * All rights reserved.
  54770. *
  54771. * This source code is licensed under the MIT license found in the
  54772. * LICENSE file in the root directory of this source tree.
  54773. */
  54774. 'use strict';
  54775. exports.getDelay = function(fullLayout) {
  54776. if(!fullLayout._has) return 0;
  54777. return (
  54778. fullLayout._has('gl3d') ||
  54779. fullLayout._has('gl2d') ||
  54780. fullLayout._has('mapbox')
  54781. ) ? 500 : 0;
  54782. };
  54783. exports.getRedrawFunc = function(gd) {
  54784. var fullLayout = gd._fullLayout || {};
  54785. var hasPolar = fullLayout._has && fullLayout._has('polar');
  54786. var hasLegacyPolar = !hasPolar && gd.data && gd.data[0] && gd.data[0].r;
  54787. // do not work for legacy polar
  54788. if(hasLegacyPolar) return;
  54789. return function() {
  54790. (gd.calcdata || []).forEach(function(d) {
  54791. if(d[0] && d[0].t && d[0].t.cb) d[0].t.cb();
  54792. });
  54793. };
  54794. };
  54795. },{}],264:[function(_dereq_,module,exports){
  54796. /**
  54797. * Copyright 2012-2018, Plotly, Inc.
  54798. * All rights reserved.
  54799. *
  54800. * This source code is licensed under the MIT license found in the
  54801. * LICENSE file in the root directory of this source tree.
  54802. */
  54803. 'use strict';
  54804. var helpers = _dereq_('./helpers');
  54805. var Snapshot = {
  54806. getDelay: helpers.getDelay,
  54807. getRedrawFunc: helpers.getRedrawFunc,
  54808. clone: _dereq_('./cloneplot'),
  54809. toSVG: _dereq_('./tosvg'),
  54810. svgToImg: _dereq_('./svgtoimg'),
  54811. toImage: _dereq_('./toimage'),
  54812. downloadImage: _dereq_('./download')
  54813. };
  54814. module.exports = Snapshot;
  54815. },{"./cloneplot":260,"./download":261,"./helpers":263,"./svgtoimg":265,"./toimage":266,"./tosvg":267}],265:[function(_dereq_,module,exports){
  54816. /**
  54817. * Copyright 2012-2018, Plotly, Inc.
  54818. * All rights reserved.
  54819. *
  54820. * This source code is licensed under the MIT license found in the
  54821. * LICENSE file in the root directory of this source tree.
  54822. */
  54823. 'use strict';
  54824. var Lib = _dereq_('../lib');
  54825. var EventEmitter = _dereq_('events').EventEmitter;
  54826. function svgToImg(opts) {
  54827. var ev = opts.emitter || new EventEmitter();
  54828. var promise = new Promise(function(resolve, reject) {
  54829. var Image = window.Image;
  54830. var svg = opts.svg;
  54831. var format = opts.format || 'png';
  54832. // IE only support svg
  54833. if(Lib.isIE() && format !== 'svg') {
  54834. var ieSvgError = new Error('Sorry IE does not support downloading from canvas. Try {format:\'svg\'} instead.');
  54835. reject(ieSvgError);
  54836. // eventually remove the ev
  54837. // in favor of promises
  54838. if(!opts.promise) {
  54839. return ev.emit('error', ieSvgError);
  54840. } else {
  54841. return promise;
  54842. }
  54843. }
  54844. var canvas = opts.canvas;
  54845. var scale = opts.scale || 1;
  54846. var w0 = opts.width || 300;
  54847. var h0 = opts.height || 150;
  54848. var w1 = scale * w0;
  54849. var h1 = scale * h0;
  54850. var ctx = canvas.getContext('2d');
  54851. var img = new Image();
  54852. // for Safari support, eliminate createObjectURL
  54853. // this decision could cause problems if content
  54854. // is not restricted to svg
  54855. var url = 'data:image/svg+xml,' + encodeURIComponent(svg);
  54856. canvas.width = w1;
  54857. canvas.height = h1;
  54858. img.onload = function() {
  54859. var imgData;
  54860. // don't need to draw to canvas if svg
  54861. // save some time and also avoid failure on IE
  54862. if(format !== 'svg') {
  54863. ctx.drawImage(img, 0, 0, w1, h1);
  54864. }
  54865. switch(format) {
  54866. case 'jpeg':
  54867. imgData = canvas.toDataURL('image/jpeg');
  54868. break;
  54869. case 'png':
  54870. imgData = canvas.toDataURL('image/png');
  54871. break;
  54872. case 'webp':
  54873. imgData = canvas.toDataURL('image/webp');
  54874. break;
  54875. case 'svg':
  54876. imgData = url;
  54877. break;
  54878. default:
  54879. var errorMsg = 'Image format is not jpeg, png, svg or webp.';
  54880. reject(new Error(errorMsg));
  54881. // eventually remove the ev
  54882. // in favor of promises
  54883. if(!opts.promise) {
  54884. return ev.emit('error', errorMsg);
  54885. }
  54886. }
  54887. resolve(imgData);
  54888. // eventually remove the ev
  54889. // in favor of promises
  54890. if(!opts.promise) {
  54891. ev.emit('success', imgData);
  54892. }
  54893. };
  54894. img.onerror = function(err) {
  54895. reject(err);
  54896. // eventually remove the ev
  54897. // in favor of promises
  54898. if(!opts.promise) {
  54899. return ev.emit('error', err);
  54900. }
  54901. };
  54902. img.src = url;
  54903. });
  54904. // temporary for backward compatibility
  54905. // move to only Promise in 2.0.0
  54906. // and eliminate the EventEmitter
  54907. if(opts.promise) {
  54908. return promise;
  54909. }
  54910. return ev;
  54911. }
  54912. module.exports = svgToImg;
  54913. },{"../lib":169,"events":15}],266:[function(_dereq_,module,exports){
  54914. /**
  54915. * Copyright 2012-2018, Plotly, Inc.
  54916. * All rights reserved.
  54917. *
  54918. * This source code is licensed under the MIT license found in the
  54919. * LICENSE file in the root directory of this source tree.
  54920. */
  54921. 'use strict';
  54922. var EventEmitter = _dereq_('events').EventEmitter;
  54923. var Registry = _dereq_('../registry');
  54924. var Lib = _dereq_('../lib');
  54925. var helpers = _dereq_('./helpers');
  54926. var clonePlot = _dereq_('./cloneplot');
  54927. var toSVG = _dereq_('./tosvg');
  54928. var svgToImg = _dereq_('./svgtoimg');
  54929. /**
  54930. * @param {object} gd figure Object
  54931. * @param {object} opts option object
  54932. * @param opts.format 'jpeg' | 'png' | 'webp' | 'svg'
  54933. */
  54934. function toImage(gd, opts) {
  54935. // first clone the GD so we can operate in a clean environment
  54936. var ev = new EventEmitter();
  54937. var clone = clonePlot(gd, {format: 'png'});
  54938. var clonedGd = clone.gd;
  54939. // put the cloned div somewhere off screen before attaching to DOM
  54940. clonedGd.style.position = 'absolute';
  54941. clonedGd.style.left = '-5000px';
  54942. document.body.appendChild(clonedGd);
  54943. function wait() {
  54944. var delay = helpers.getDelay(clonedGd._fullLayout);
  54945. setTimeout(function() {
  54946. var svg = toSVG(clonedGd);
  54947. var canvas = document.createElement('canvas');
  54948. canvas.id = Lib.randstr();
  54949. ev = svgToImg({
  54950. format: opts.format,
  54951. width: clonedGd._fullLayout.width,
  54952. height: clonedGd._fullLayout.height,
  54953. canvas: canvas,
  54954. emitter: ev,
  54955. svg: svg
  54956. });
  54957. ev.clean = function() {
  54958. if(clonedGd) document.body.removeChild(clonedGd);
  54959. };
  54960. }, delay);
  54961. }
  54962. var redrawFunc = helpers.getRedrawFunc(clonedGd);
  54963. Registry.call('plot', clonedGd, clone.data, clone.layout, clone.config)
  54964. .then(redrawFunc)
  54965. .then(wait)
  54966. .catch(function(err) {
  54967. ev.emit('error', err);
  54968. });
  54969. return ev;
  54970. }
  54971. module.exports = toImage;
  54972. },{"../lib":169,"../registry":259,"./cloneplot":260,"./helpers":263,"./svgtoimg":265,"./tosvg":267,"events":15}],267:[function(_dereq_,module,exports){
  54973. /**
  54974. * Copyright 2012-2018, Plotly, Inc.
  54975. * All rights reserved.
  54976. *
  54977. * This source code is licensed under the MIT license found in the
  54978. * LICENSE file in the root directory of this source tree.
  54979. */
  54980. 'use strict';
  54981. var d3 = _dereq_('d3');
  54982. var Lib = _dereq_('../lib');
  54983. var Drawing = _dereq_('../components/drawing');
  54984. var Color = _dereq_('../components/color');
  54985. var xmlnsNamespaces = _dereq_('../constants/xmlns_namespaces');
  54986. var DOUBLEQUOTE_REGEX = /"/g;
  54987. var DUMMY_SUB = 'TOBESTRIPPED';
  54988. var DUMMY_REGEX = new RegExp('("' + DUMMY_SUB + ')|(' + DUMMY_SUB + '")', 'g');
  54989. function htmlEntityDecode(s) {
  54990. var hiddenDiv = d3.select('body').append('div').style({display: 'none'}).html('');
  54991. var replaced = s.replace(/(&[^;]*;)/gi, function(d) {
  54992. if(d === '&lt;') { return '&#60;'; } // special handling for brackets
  54993. if(d === '&rt;') { return '&#62;'; }
  54994. if(d.indexOf('<') !== -1 || d.indexOf('>') !== -1) { return ''; }
  54995. return hiddenDiv.html(d).text(); // everything else, let the browser decode it to unicode
  54996. });
  54997. hiddenDiv.remove();
  54998. return replaced;
  54999. }
  55000. function xmlEntityEncode(str) {
  55001. return str.replace(/&(?!\w+;|\#[0-9]+;| \#x[0-9A-F]+;)/g, '&amp;');
  55002. }
  55003. module.exports = function toSVG(gd, format, scale) {
  55004. var fullLayout = gd._fullLayout;
  55005. var svg = fullLayout._paper;
  55006. var toppaper = fullLayout._toppaper;
  55007. var width = fullLayout.width;
  55008. var height = fullLayout.height;
  55009. var i;
  55010. // make background color a rect in the svg, then revert after scraping
  55011. // all other alterations have been dealt with by properly preparing the svg
  55012. // in the first place... like setting cursors with css classes so we don't
  55013. // have to remove them, and providing the right namespaces in the svg to
  55014. // begin with
  55015. svg.insert('rect', ':first-child')
  55016. .call(Drawing.setRect, 0, 0, width, height)
  55017. .call(Color.fill, fullLayout.paper_bgcolor);
  55018. // subplot-specific to-SVG methods
  55019. // which notably add the contents of the gl-container
  55020. // into the main svg node
  55021. var basePlotModules = fullLayout._basePlotModules || [];
  55022. for(i = 0; i < basePlotModules.length; i++) {
  55023. var _module = basePlotModules[i];
  55024. if(_module.toSVG) _module.toSVG(gd);
  55025. }
  55026. // add top items above them assumes everything in toppaper is either
  55027. // a group or a defs, and if it's empty (like hoverlayer) we can ignore it.
  55028. if(toppaper) {
  55029. var nodes = toppaper.node().childNodes;
  55030. // make copy of nodes as childNodes prop gets mutated in loop below
  55031. var topGroups = Array.prototype.slice.call(nodes);
  55032. for(i = 0; i < topGroups.length; i++) {
  55033. var topGroup = topGroups[i];
  55034. if(topGroup.childNodes.length) svg.node().appendChild(topGroup);
  55035. }
  55036. }
  55037. // remove draglayer for Adobe Illustrator compatibility
  55038. if(fullLayout._draggers) {
  55039. fullLayout._draggers.remove();
  55040. }
  55041. // in case the svg element had an explicit background color, remove this
  55042. // we want the rect to get the color so it's the right size; svg bg will
  55043. // fill whatever container it's displayed in regardless of plot size.
  55044. svg.node().style.background = '';
  55045. svg.selectAll('text')
  55046. .attr({'data-unformatted': null, 'data-math': null})
  55047. .each(function() {
  55048. var txt = d3.select(this);
  55049. // hidden text is pre-formatting mathjax, the browser ignores it
  55050. // but in a static plot it's useless and it can confuse batik
  55051. // we've tried to standardize on display:none but make sure we still
  55052. // catch visibility:hidden if it ever arises
  55053. if(this.style.visibility === 'hidden' || this.style.display === 'none') {
  55054. txt.remove();
  55055. return;
  55056. }
  55057. else {
  55058. // clear other visibility/display values to default
  55059. // to not potentially confuse non-browser SVG implementations
  55060. txt.style({visibility: null, display: null});
  55061. }
  55062. // Font family styles break things because of quotation marks,
  55063. // so we must remove them *after* the SVG DOM has been serialized
  55064. // to a string (browsers convert singles back)
  55065. var ff = this.style.fontFamily;
  55066. if(ff && ff.indexOf('"') !== -1) {
  55067. txt.style('font-family', ff.replace(DOUBLEQUOTE_REGEX, DUMMY_SUB));
  55068. }
  55069. });
  55070. svg.selectAll('.point, .scatterpts, .legendfill>path, .legendlines>path, .cbfill').each(function() {
  55071. var pt = d3.select(this);
  55072. // similar to font family styles above,
  55073. // we must remove " after the SVG DOM has been serialized
  55074. var fill = this.style.fill;
  55075. if(fill && fill.indexOf('url(') !== -1) {
  55076. pt.style('fill', fill.replace(DOUBLEQUOTE_REGEX, DUMMY_SUB));
  55077. }
  55078. var stroke = this.style.stroke;
  55079. if(stroke && stroke.indexOf('url(') !== -1) {
  55080. pt.style('stroke', stroke.replace(DOUBLEQUOTE_REGEX, DUMMY_SUB));
  55081. }
  55082. });
  55083. if(format === 'pdf' || format === 'eps') {
  55084. // these formats make the extra line MathJax adds around symbols look super thick in some cases
  55085. // it looks better if this is removed entirely.
  55086. svg.selectAll('#MathJax_SVG_glyphs path')
  55087. .attr('stroke-width', 0);
  55088. }
  55089. // fix for IE namespacing quirk?
  55090. // http://stackoverflow.com/questions/19610089/unwanted-namespaces-on-svg-markup-when-using-xmlserializer-in-javascript-with-ie
  55091. svg.node().setAttributeNS(xmlnsNamespaces.xmlns, 'xmlns', xmlnsNamespaces.svg);
  55092. svg.node().setAttributeNS(xmlnsNamespaces.xmlns, 'xmlns:xlink', xmlnsNamespaces.xlink);
  55093. if(format === 'svg' && scale) {
  55094. svg.attr('width', scale * width);
  55095. svg.attr('height', scale * height);
  55096. svg.attr('viewBox', '0 0 ' + width + ' ' + height);
  55097. }
  55098. var s = new window.XMLSerializer().serializeToString(svg.node());
  55099. s = htmlEntityDecode(s);
  55100. s = xmlEntityEncode(s);
  55101. // Fix quotations around font strings and gradient URLs
  55102. s = s.replace(DUMMY_REGEX, '\'');
  55103. // IE is very strict, so we will need to clean
  55104. // svg with the following regex
  55105. // yes this is messy, but do not know a better way
  55106. // Even with this IE will not work due to tainted canvas
  55107. // see https://github.com/kangax/fabric.js/issues/1957
  55108. // http://stackoverflow.com/questions/18112047/canvas-todataurl-working-in-all-browsers-except-ie10
  55109. // Leave here just in case the CORS/tainted IE issue gets resolved
  55110. if(Lib.isIE()) {
  55111. // replace double quote with single quote
  55112. s = s.replace(/"/gi, '\'');
  55113. // url in svg are single quoted
  55114. // since we changed double to single
  55115. // we'll need to change these to double-quoted
  55116. s = s.replace(/(\('#)([^']*)('\))/gi, '(\"#$2\")');
  55117. // font names with spaces will be escaped single-quoted
  55118. // we'll need to change these to double-quoted
  55119. s = s.replace(/(\\')/gi, '\"');
  55120. }
  55121. return s;
  55122. };
  55123. },{"../components/color":50,"../components/drawing":75,"../constants/xmlns_namespaces":152,"../lib":169,"d3":16}],268:[function(_dereq_,module,exports){
  55124. /**
  55125. * Copyright 2012-2018, Plotly, Inc.
  55126. * All rights reserved.
  55127. *
  55128. * This source code is licensed under the MIT license found in the
  55129. * LICENSE file in the root directory of this source tree.
  55130. */
  55131. 'use strict';
  55132. var mergeArray = _dereq_('../../lib').mergeArray;
  55133. // arrayOk attributes, merge them into calcdata array
  55134. module.exports = function arraysToCalcdata(cd, trace) {
  55135. for(var i = 0; i < cd.length; i++) cd[i].i = i;
  55136. mergeArray(trace.text, cd, 'tx');
  55137. mergeArray(trace.hovertext, cd, 'htx');
  55138. var marker = trace.marker;
  55139. if(marker) {
  55140. mergeArray(marker.opacity, cd, 'mo');
  55141. mergeArray(marker.color, cd, 'mc');
  55142. var markerLine = marker.line;
  55143. if(markerLine) {
  55144. mergeArray(markerLine.color, cd, 'mlc');
  55145. mergeArray(markerLine.width, cd, 'mlw');
  55146. }
  55147. }
  55148. };
  55149. },{"../../lib":169}],269:[function(_dereq_,module,exports){
  55150. /**
  55151. * Copyright 2012-2018, Plotly, Inc.
  55152. * All rights reserved.
  55153. *
  55154. * This source code is licensed under the MIT license found in the
  55155. * LICENSE file in the root directory of this source tree.
  55156. */
  55157. 'use strict';
  55158. var scatterAttrs = _dereq_('../scatter/attributes');
  55159. var colorAttributes = _dereq_('../../components/colorscale/attributes');
  55160. var colorbarAttrs = _dereq_('../../components/colorbar/attributes');
  55161. var fontAttrs = _dereq_('../../plots/font_attributes');
  55162. var extendFlat = _dereq_('../../lib/extend').extendFlat;
  55163. var textFontAttrs = fontAttrs({
  55164. editType: 'calc',
  55165. arrayOk: true,
  55166. });
  55167. var scatterMarkerAttrs = scatterAttrs.marker;
  55168. var scatterMarkerLineAttrs = scatterMarkerAttrs.line;
  55169. var markerLineWidth = extendFlat({},
  55170. scatterMarkerLineAttrs.width, { dflt: 0 });
  55171. var markerLine = extendFlat({
  55172. width: markerLineWidth,
  55173. editType: 'calc'
  55174. }, colorAttributes('marker.line'));
  55175. var marker = extendFlat({
  55176. line: markerLine,
  55177. editType: 'calc'
  55178. }, colorAttributes('marker'), {
  55179. colorbar: colorbarAttrs,
  55180. opacity: {
  55181. valType: 'number',
  55182. arrayOk: true,
  55183. dflt: 1,
  55184. min: 0,
  55185. max: 1,
  55186. editType: 'style',
  55187. }
  55188. });
  55189. module.exports = {
  55190. x: scatterAttrs.x,
  55191. x0: scatterAttrs.x0,
  55192. dx: scatterAttrs.dx,
  55193. y: scatterAttrs.y,
  55194. y0: scatterAttrs.y0,
  55195. dy: scatterAttrs.dy,
  55196. text: scatterAttrs.text,
  55197. hovertext: scatterAttrs.hovertext,
  55198. textposition: {
  55199. valType: 'enumerated',
  55200. values: ['inside', 'outside', 'auto', 'none'],
  55201. dflt: 'none',
  55202. arrayOk: true,
  55203. editType: 'calc',
  55204. },
  55205. textfont: extendFlat({}, textFontAttrs, {
  55206. }),
  55207. insidetextfont: extendFlat({}, textFontAttrs, {
  55208. }),
  55209. outsidetextfont: extendFlat({}, textFontAttrs, {
  55210. }),
  55211. constraintext: {
  55212. valType: 'enumerated',
  55213. values: ['inside', 'outside', 'both', 'none'],
  55214. dflt: 'both',
  55215. editType: 'calc',
  55216. },
  55217. cliponaxis: extendFlat({}, scatterAttrs.cliponaxis, {
  55218. }),
  55219. orientation: {
  55220. valType: 'enumerated',
  55221. values: ['v', 'h'],
  55222. editType: 'calc+clearAxisTypes',
  55223. },
  55224. base: {
  55225. valType: 'any',
  55226. dflt: null,
  55227. arrayOk: true,
  55228. editType: 'calc',
  55229. },
  55230. offset: {
  55231. valType: 'number',
  55232. dflt: null,
  55233. arrayOk: true,
  55234. editType: 'calc',
  55235. },
  55236. width: {
  55237. valType: 'number',
  55238. dflt: null,
  55239. min: 0,
  55240. arrayOk: true,
  55241. editType: 'calc',
  55242. },
  55243. marker: marker,
  55244. selected: {
  55245. marker: {
  55246. opacity: scatterAttrs.selected.marker.opacity,
  55247. color: scatterAttrs.selected.marker.color,
  55248. editType: 'style'
  55249. },
  55250. textfont: scatterAttrs.selected.textfont,
  55251. editType: 'style'
  55252. },
  55253. unselected: {
  55254. marker: {
  55255. opacity: scatterAttrs.unselected.marker.opacity,
  55256. color: scatterAttrs.unselected.marker.color,
  55257. editType: 'style'
  55258. },
  55259. textfont: scatterAttrs.unselected.textfont,
  55260. editType: 'style'
  55261. },
  55262. r: scatterAttrs.r,
  55263. t: scatterAttrs.t,
  55264. _deprecated: {
  55265. bardir: {
  55266. valType: 'enumerated',
  55267. editType: 'calc',
  55268. values: ['v', 'h'],
  55269. }
  55270. }
  55271. };
  55272. },{"../../components/colorbar/attributes":51,"../../components/colorscale/attributes":57,"../../lib/extend":163,"../../plots/font_attributes":240,"../scatter/attributes":366}],270:[function(_dereq_,module,exports){
  55273. /**
  55274. * Copyright 2012-2018, Plotly, Inc.
  55275. * All rights reserved.
  55276. *
  55277. * This source code is licensed under the MIT license found in the
  55278. * LICENSE file in the root directory of this source tree.
  55279. */
  55280. 'use strict';
  55281. var Axes = _dereq_('../../plots/cartesian/axes');
  55282. var hasColorscale = _dereq_('../../components/colorscale/has_colorscale');
  55283. var colorscaleCalc = _dereq_('../../components/colorscale/calc');
  55284. var arraysToCalcdata = _dereq_('./arrays_to_calcdata');
  55285. var calcSelection = _dereq_('../scatter/calc_selection');
  55286. module.exports = function calc(gd, trace) {
  55287. var xa = Axes.getFromId(gd, trace.xaxis || 'x');
  55288. var ya = Axes.getFromId(gd, trace.yaxis || 'y');
  55289. var size, pos;
  55290. if(trace.orientation === 'h') {
  55291. size = xa.makeCalcdata(trace, 'x');
  55292. pos = ya.makeCalcdata(trace, 'y');
  55293. } else {
  55294. size = ya.makeCalcdata(trace, 'y');
  55295. pos = xa.makeCalcdata(trace, 'x');
  55296. }
  55297. // create the "calculated data" to plot
  55298. var serieslen = Math.min(pos.length, size.length);
  55299. var cd = new Array(serieslen);
  55300. // set position and size
  55301. for(var i = 0; i < serieslen; i++) {
  55302. cd[i] = { p: pos[i], s: size[i] };
  55303. if(trace.ids) {
  55304. cd[i].id = String(trace.ids[i]);
  55305. }
  55306. }
  55307. // auto-z and autocolorscale if applicable
  55308. if(hasColorscale(trace, 'marker')) {
  55309. colorscaleCalc(trace, trace.marker.color, 'marker', 'c');
  55310. }
  55311. if(hasColorscale(trace, 'marker.line')) {
  55312. colorscaleCalc(trace, trace.marker.line.color, 'marker.line', 'c');
  55313. }
  55314. arraysToCalcdata(cd, trace);
  55315. calcSelection(cd, trace);
  55316. return cd;
  55317. };
  55318. },{"../../components/colorscale/calc":58,"../../components/colorscale/has_colorscale":64,"../../plots/cartesian/axes":214,"../scatter/calc_selection":368,"./arrays_to_calcdata":268}],271:[function(_dereq_,module,exports){
  55319. /**
  55320. * Copyright 2012-2018, Plotly, Inc.
  55321. * All rights reserved.
  55322. *
  55323. * This source code is licensed under the MIT license found in the
  55324. * LICENSE file in the root directory of this source tree.
  55325. */
  55326. 'use strict';
  55327. var isNumeric = _dereq_('fast-isnumeric');
  55328. var isArrayOrTypedArray = _dereq_('../../lib').isArrayOrTypedArray;
  55329. var BADNUM = _dereq_('../../constants/numerical').BADNUM;
  55330. var Registry = _dereq_('../../registry');
  55331. var Axes = _dereq_('../../plots/cartesian/axes');
  55332. var Sieve = _dereq_('./sieve.js');
  55333. /*
  55334. * Bar chart stacking/grouping positioning and autoscaling calculations
  55335. * for each direction separately calculate the ranges and positions
  55336. * note that this handles histograms too
  55337. * now doing this one subplot at a time
  55338. */
  55339. function crossTraceCalc(gd, plotinfo) {
  55340. var xa = plotinfo.xaxis,
  55341. ya = plotinfo.yaxis;
  55342. var fullTraces = gd._fullData,
  55343. calcTraces = gd.calcdata,
  55344. calcTracesHorizontal = [],
  55345. calcTracesVertical = [],
  55346. i;
  55347. for(i = 0; i < fullTraces.length; i++) {
  55348. var fullTrace = fullTraces[i];
  55349. if(
  55350. fullTrace.visible === true &&
  55351. Registry.traceIs(fullTrace, 'bar') &&
  55352. fullTrace.xaxis === xa._id &&
  55353. fullTrace.yaxis === ya._id
  55354. ) {
  55355. if(fullTrace.orientation === 'h') {
  55356. calcTracesHorizontal.push(calcTraces[i]);
  55357. }
  55358. else {
  55359. calcTracesVertical.push(calcTraces[i]);
  55360. }
  55361. }
  55362. }
  55363. setGroupPositions(gd, xa, ya, calcTracesVertical);
  55364. setGroupPositions(gd, ya, xa, calcTracesHorizontal);
  55365. }
  55366. function setGroupPositions(gd, pa, sa, calcTraces) {
  55367. if(!calcTraces.length) return;
  55368. var barmode = gd._fullLayout.barmode,
  55369. overlay = (barmode === 'overlay'),
  55370. group = (barmode === 'group'),
  55371. excluded,
  55372. included,
  55373. i, calcTrace, fullTrace;
  55374. initBase(gd, pa, sa, calcTraces);
  55375. if(overlay) {
  55376. setGroupPositionsInOverlayMode(gd, pa, sa, calcTraces);
  55377. }
  55378. else if(group) {
  55379. // exclude from the group those traces for which the user set an offset
  55380. excluded = [];
  55381. included = [];
  55382. for(i = 0; i < calcTraces.length; i++) {
  55383. calcTrace = calcTraces[i];
  55384. fullTrace = calcTrace[0].trace;
  55385. if(fullTrace.offset === undefined) included.push(calcTrace);
  55386. else excluded.push(calcTrace);
  55387. }
  55388. if(included.length) {
  55389. setGroupPositionsInGroupMode(gd, pa, sa, included);
  55390. }
  55391. if(excluded.length) {
  55392. setGroupPositionsInOverlayMode(gd, pa, sa, excluded);
  55393. }
  55394. }
  55395. else {
  55396. // exclude from the stack those traces for which the user set a base
  55397. excluded = [];
  55398. included = [];
  55399. for(i = 0; i < calcTraces.length; i++) {
  55400. calcTrace = calcTraces[i];
  55401. fullTrace = calcTrace[0].trace;
  55402. if(fullTrace.base === undefined) included.push(calcTrace);
  55403. else excluded.push(calcTrace);
  55404. }
  55405. if(included.length) {
  55406. setGroupPositionsInStackOrRelativeMode(gd, pa, sa, included);
  55407. }
  55408. if(excluded.length) {
  55409. setGroupPositionsInOverlayMode(gd, pa, sa, excluded);
  55410. }
  55411. }
  55412. collectExtents(calcTraces, pa);
  55413. }
  55414. function initBase(gd, pa, sa, calcTraces) {
  55415. var i, j;
  55416. for(i = 0; i < calcTraces.length; i++) {
  55417. var cd = calcTraces[i];
  55418. var trace = cd[0].trace;
  55419. var base = trace.base;
  55420. var b;
  55421. // not sure if it really makes sense to have dates for bar size data...
  55422. // ideally if we want to make gantt charts or something we'd treat
  55423. // the actual size (trace.x or y) as time delta but base as absolute
  55424. // time. But included here for completeness.
  55425. var scalendar = trace.orientation === 'h' ? trace.xcalendar : trace.ycalendar;
  55426. if(isArrayOrTypedArray(base)) {
  55427. for(j = 0; j < Math.min(base.length, cd.length); j++) {
  55428. b = sa.d2c(base[j], 0, scalendar);
  55429. if(isNumeric(b)) {
  55430. cd[j].b = +b;
  55431. cd[j].hasB = 1;
  55432. }
  55433. else cd[j].b = 0;
  55434. }
  55435. for(; j < cd.length; j++) {
  55436. cd[j].b = 0;
  55437. }
  55438. } else {
  55439. b = sa.d2c(base, 0, scalendar);
  55440. var hasBase = isNumeric(b);
  55441. b = hasBase ? b : 0;
  55442. for(j = 0; j < cd.length; j++) {
  55443. cd[j].b = b;
  55444. if(hasBase) cd[j].hasB = 1;
  55445. }
  55446. }
  55447. }
  55448. }
  55449. function setGroupPositionsInOverlayMode(gd, pa, sa, calcTraces) {
  55450. var barnorm = gd._fullLayout.barnorm,
  55451. separateNegativeValues = false,
  55452. dontMergeOverlappingData = !barnorm;
  55453. // update position axis and set bar offsets and widths
  55454. for(var i = 0; i < calcTraces.length; i++) {
  55455. var calcTrace = calcTraces[i];
  55456. var sieve = new Sieve(
  55457. [calcTrace], separateNegativeValues, dontMergeOverlappingData
  55458. );
  55459. // set bar offsets and widths, and update position axis
  55460. setOffsetAndWidth(gd, pa, sieve);
  55461. // set bar bases and sizes, and update size axis
  55462. //
  55463. // (note that `setGroupPositionsInOverlayMode` handles the case barnorm
  55464. // is defined, because this function is also invoked for traces that
  55465. // can't be grouped or stacked)
  55466. if(barnorm) {
  55467. sieveBars(gd, sa, sieve);
  55468. normalizeBars(gd, sa, sieve);
  55469. }
  55470. else {
  55471. setBaseAndTop(gd, sa, sieve);
  55472. }
  55473. }
  55474. }
  55475. function setGroupPositionsInGroupMode(gd, pa, sa, calcTraces) {
  55476. var fullLayout = gd._fullLayout,
  55477. barnorm = fullLayout.barnorm,
  55478. separateNegativeValues = false,
  55479. dontMergeOverlappingData = !barnorm,
  55480. sieve = new Sieve(
  55481. calcTraces, separateNegativeValues, dontMergeOverlappingData
  55482. );
  55483. // set bar offsets and widths, and update position axis
  55484. setOffsetAndWidthInGroupMode(gd, pa, sieve);
  55485. // set bar bases and sizes, and update size axis
  55486. if(barnorm) {
  55487. sieveBars(gd, sa, sieve);
  55488. normalizeBars(gd, sa, sieve);
  55489. }
  55490. else {
  55491. setBaseAndTop(gd, sa, sieve);
  55492. }
  55493. }
  55494. function setGroupPositionsInStackOrRelativeMode(gd, pa, sa, calcTraces) {
  55495. var fullLayout = gd._fullLayout,
  55496. barmode = fullLayout.barmode,
  55497. stack = (barmode === 'stack'),
  55498. relative = (barmode === 'relative'),
  55499. barnorm = gd._fullLayout.barnorm,
  55500. separateNegativeValues = relative,
  55501. dontMergeOverlappingData = !(barnorm || stack || relative),
  55502. sieve = new Sieve(
  55503. calcTraces, separateNegativeValues, dontMergeOverlappingData
  55504. );
  55505. // set bar offsets and widths, and update position axis
  55506. setOffsetAndWidth(gd, pa, sieve);
  55507. // set bar bases and sizes, and update size axis
  55508. stackBars(gd, sa, sieve);
  55509. // flag the outmost bar (for text display purposes)
  55510. for(var i = 0; i < calcTraces.length; i++) {
  55511. var calcTrace = calcTraces[i];
  55512. for(var j = 0; j < calcTrace.length; j++) {
  55513. var bar = calcTrace[j];
  55514. if(bar.s === BADNUM) continue;
  55515. var isOutmostBar = ((bar.b + bar.s) === sieve.get(bar.p, bar.s));
  55516. if(isOutmostBar) bar._outmost = true;
  55517. }
  55518. }
  55519. // Note that marking the outmost bars has to be done
  55520. // before `normalizeBars` changes `bar.b` and `bar.s`.
  55521. if(barnorm) normalizeBars(gd, sa, sieve);
  55522. }
  55523. function setOffsetAndWidth(gd, pa, sieve) {
  55524. var fullLayout = gd._fullLayout,
  55525. bargap = fullLayout.bargap,
  55526. bargroupgap = fullLayout.bargroupgap || 0,
  55527. minDiff = sieve.minDiff,
  55528. calcTraces = sieve.traces,
  55529. i, calcTrace, calcTrace0,
  55530. t;
  55531. // set bar offsets and widths
  55532. var barGroupWidth = minDiff * (1 - bargap),
  55533. barWidthPlusGap = barGroupWidth,
  55534. barWidth = barWidthPlusGap * (1 - bargroupgap);
  55535. // computer bar group center and bar offset
  55536. var offsetFromCenter = -barWidth / 2;
  55537. for(i = 0; i < calcTraces.length; i++) {
  55538. calcTrace = calcTraces[i];
  55539. calcTrace0 = calcTrace[0];
  55540. // store bar width and offset for this trace
  55541. t = calcTrace0.t;
  55542. t.barwidth = barWidth;
  55543. t.poffset = offsetFromCenter;
  55544. t.bargroupwidth = barGroupWidth;
  55545. t.bardelta = minDiff;
  55546. }
  55547. // stack bars that only differ by rounding
  55548. sieve.binWidth = calcTraces[0][0].t.barwidth / 100;
  55549. // if defined, apply trace offset and width
  55550. applyAttributes(sieve);
  55551. // store the bar center in each calcdata item
  55552. setBarCenterAndWidth(gd, pa, sieve);
  55553. // update position axes
  55554. updatePositionAxis(gd, pa, sieve);
  55555. }
  55556. function setOffsetAndWidthInGroupMode(gd, pa, sieve) {
  55557. var fullLayout = gd._fullLayout,
  55558. bargap = fullLayout.bargap,
  55559. bargroupgap = fullLayout.bargroupgap || 0,
  55560. positions = sieve.positions,
  55561. distinctPositions = sieve.distinctPositions,
  55562. minDiff = sieve.minDiff,
  55563. calcTraces = sieve.traces,
  55564. i, calcTrace, calcTrace0,
  55565. t;
  55566. // if there aren't any overlapping positions,
  55567. // let them have full width even if mode is group
  55568. var overlap = (positions.length !== distinctPositions.length);
  55569. var nTraces = calcTraces.length,
  55570. barGroupWidth = minDiff * (1 - bargap),
  55571. barWidthPlusGap = (overlap) ? barGroupWidth / nTraces : barGroupWidth,
  55572. barWidth = barWidthPlusGap * (1 - bargroupgap);
  55573. for(i = 0; i < nTraces; i++) {
  55574. calcTrace = calcTraces[i];
  55575. calcTrace0 = calcTrace[0];
  55576. // computer bar group center and bar offset
  55577. var offsetFromCenter = (overlap) ?
  55578. ((2 * i + 1 - nTraces) * barWidthPlusGap - barWidth) / 2 :
  55579. -barWidth / 2;
  55580. // store bar width and offset for this trace
  55581. t = calcTrace0.t;
  55582. t.barwidth = barWidth;
  55583. t.poffset = offsetFromCenter;
  55584. t.bargroupwidth = barGroupWidth;
  55585. t.bardelta = minDiff;
  55586. }
  55587. // stack bars that only differ by rounding
  55588. sieve.binWidth = calcTraces[0][0].t.barwidth / 100;
  55589. // if defined, apply trace width
  55590. applyAttributes(sieve);
  55591. // store the bar center in each calcdata item
  55592. setBarCenterAndWidth(gd, pa, sieve);
  55593. // update position axes
  55594. updatePositionAxis(gd, pa, sieve, overlap);
  55595. }
  55596. function applyAttributes(sieve) {
  55597. var calcTraces = sieve.traces,
  55598. i, calcTrace, calcTrace0, fullTrace,
  55599. j,
  55600. t;
  55601. for(i = 0; i < calcTraces.length; i++) {
  55602. calcTrace = calcTraces[i];
  55603. calcTrace0 = calcTrace[0];
  55604. fullTrace = calcTrace0.trace;
  55605. t = calcTrace0.t;
  55606. var offset = fullTrace._offset || fullTrace.offset,
  55607. initialPoffset = t.poffset,
  55608. newPoffset;
  55609. if(isArrayOrTypedArray(offset)) {
  55610. // if offset is an array, then clone it into t.poffset.
  55611. newPoffset = offset.slice(0, calcTrace.length);
  55612. // guard against non-numeric items
  55613. for(j = 0; j < newPoffset.length; j++) {
  55614. if(!isNumeric(newPoffset[j])) {
  55615. newPoffset[j] = initialPoffset;
  55616. }
  55617. }
  55618. // if the length of the array is too short,
  55619. // then extend it with the initial value of t.poffset
  55620. for(j = newPoffset.length; j < calcTrace.length; j++) {
  55621. newPoffset.push(initialPoffset);
  55622. }
  55623. t.poffset = newPoffset;
  55624. }
  55625. else if(offset !== undefined) {
  55626. t.poffset = offset;
  55627. }
  55628. var width = fullTrace._width || fullTrace.width,
  55629. initialBarwidth = t.barwidth;
  55630. if(isArrayOrTypedArray(width)) {
  55631. // if width is an array, then clone it into t.barwidth.
  55632. var newBarwidth = width.slice(0, calcTrace.length);
  55633. // guard against non-numeric items
  55634. for(j = 0; j < newBarwidth.length; j++) {
  55635. if(!isNumeric(newBarwidth[j])) newBarwidth[j] = initialBarwidth;
  55636. }
  55637. // if the length of the array is too short,
  55638. // then extend it with the initial value of t.barwidth
  55639. for(j = newBarwidth.length; j < calcTrace.length; j++) {
  55640. newBarwidth.push(initialBarwidth);
  55641. }
  55642. t.barwidth = newBarwidth;
  55643. // if user didn't set offset,
  55644. // then correct t.poffset to ensure bars remain centered
  55645. if(offset === undefined) {
  55646. newPoffset = [];
  55647. for(j = 0; j < calcTrace.length; j++) {
  55648. newPoffset.push(
  55649. initialPoffset + (initialBarwidth - newBarwidth[j]) / 2
  55650. );
  55651. }
  55652. t.poffset = newPoffset;
  55653. }
  55654. }
  55655. else if(width !== undefined) {
  55656. t.barwidth = width;
  55657. // if user didn't set offset,
  55658. // then correct t.poffset to ensure bars remain centered
  55659. if(offset === undefined) {
  55660. t.poffset = initialPoffset + (initialBarwidth - width) / 2;
  55661. }
  55662. }
  55663. }
  55664. }
  55665. function setBarCenterAndWidth(gd, pa, sieve) {
  55666. var calcTraces = sieve.traces,
  55667. pLetter = getAxisLetter(pa);
  55668. for(var i = 0; i < calcTraces.length; i++) {
  55669. var calcTrace = calcTraces[i],
  55670. t = calcTrace[0].t,
  55671. poffset = t.poffset,
  55672. poffsetIsArray = Array.isArray(poffset),
  55673. barwidth = t.barwidth,
  55674. barwidthIsArray = Array.isArray(barwidth);
  55675. for(var j = 0; j < calcTrace.length; j++) {
  55676. var calcBar = calcTrace[j];
  55677. // store the actual bar width and position, for use by hover
  55678. var width = calcBar.w = (barwidthIsArray) ? barwidth[j] : barwidth;
  55679. calcBar[pLetter] = calcBar.p +
  55680. ((poffsetIsArray) ? poffset[j] : poffset) +
  55681. width / 2;
  55682. }
  55683. }
  55684. }
  55685. function updatePositionAxis(gd, pa, sieve, allowMinDtick) {
  55686. var calcTraces = sieve.traces,
  55687. distinctPositions = sieve.distinctPositions,
  55688. distinctPositions0 = distinctPositions[0],
  55689. minDiff = sieve.minDiff,
  55690. vpad = minDiff / 2;
  55691. Axes.minDtick(pa, minDiff, distinctPositions0, allowMinDtick);
  55692. // If the user set the bar width or the offset,
  55693. // then bars can be shifted away from their positions
  55694. // and widths can be larger than minDiff.
  55695. //
  55696. // Here, we compute pMin and pMax to expand the position axis,
  55697. // so that all bars are fully within the axis range.
  55698. var pMin = Math.min.apply(Math, distinctPositions) - vpad,
  55699. pMax = Math.max.apply(Math, distinctPositions) + vpad;
  55700. for(var i = 0; i < calcTraces.length; i++) {
  55701. var calcTrace = calcTraces[i],
  55702. calcTrace0 = calcTrace[0],
  55703. fullTrace = calcTrace0.trace;
  55704. if(fullTrace.width === undefined && fullTrace.offset === undefined) {
  55705. continue;
  55706. }
  55707. var t = calcTrace0.t,
  55708. poffset = t.poffset,
  55709. barwidth = t.barwidth,
  55710. poffsetIsArray = Array.isArray(poffset),
  55711. barwidthIsArray = Array.isArray(barwidth);
  55712. for(var j = 0; j < calcTrace.length; j++) {
  55713. var calcBar = calcTrace[j],
  55714. calcBarOffset = (poffsetIsArray) ? poffset[j] : poffset,
  55715. calcBarWidth = (barwidthIsArray) ? barwidth[j] : barwidth,
  55716. p = calcBar.p,
  55717. l = p + calcBarOffset,
  55718. r = l + calcBarWidth;
  55719. pMin = Math.min(pMin, l);
  55720. pMax = Math.max(pMax, r);
  55721. }
  55722. }
  55723. var extremes = Axes.findExtremes(pa, [pMin, pMax], {padded: false});
  55724. putExtremes(calcTraces, pa, extremes);
  55725. }
  55726. function expandRange(range, newValue) {
  55727. if(isNumeric(range[0])) range[0] = Math.min(range[0], newValue);
  55728. else range[0] = newValue;
  55729. if(isNumeric(range[1])) range[1] = Math.max(range[1], newValue);
  55730. else range[1] = newValue;
  55731. }
  55732. function setBaseAndTop(gd, sa, sieve) {
  55733. // store these bar bases and tops in calcdata
  55734. // and make sure the size axis includes zero,
  55735. // along with the bases and tops of each bar.
  55736. var traces = sieve.traces,
  55737. sLetter = getAxisLetter(sa),
  55738. sRange = [null, null];
  55739. for(var i = 0; i < traces.length; i++) {
  55740. var trace = traces[i];
  55741. for(var j = 0; j < trace.length; j++) {
  55742. var bar = trace[j],
  55743. barBase = bar.b,
  55744. barTop = barBase + bar.s;
  55745. bar[sLetter] = barTop;
  55746. if(isNumeric(sa.c2l(barTop))) expandRange(sRange, barTop);
  55747. if(bar.hasB && isNumeric(sa.c2l(barBase))) expandRange(sRange, barBase);
  55748. }
  55749. }
  55750. var extremes = Axes.findExtremes(sa, sRange, {tozero: true, padded: true});
  55751. putExtremes(traces, sa, extremes);
  55752. }
  55753. function stackBars(gd, sa, sieve) {
  55754. var fullLayout = gd._fullLayout,
  55755. barnorm = fullLayout.barnorm,
  55756. sLetter = getAxisLetter(sa),
  55757. traces = sieve.traces,
  55758. i, trace,
  55759. j, bar;
  55760. var sRange = [null, null];
  55761. for(i = 0; i < traces.length; i++) {
  55762. trace = traces[i];
  55763. for(j = 0; j < trace.length; j++) {
  55764. bar = trace[j];
  55765. if(bar.s === BADNUM) continue;
  55766. // stack current bar and get previous sum
  55767. var barBase = sieve.put(bar.p, bar.b + bar.s),
  55768. barTop = barBase + bar.b + bar.s;
  55769. // store the bar base and top in each calcdata item
  55770. bar.b = barBase;
  55771. bar[sLetter] = barTop;
  55772. if(!barnorm) {
  55773. if(isNumeric(sa.c2l(barTop))) expandRange(sRange, barTop);
  55774. if(bar.hasB && isNumeric(sa.c2l(barBase))) expandRange(sRange, barBase);
  55775. }
  55776. }
  55777. }
  55778. // if barnorm is set, let normalizeBars update the axis range
  55779. if(!barnorm) {
  55780. var extremes = Axes.findExtremes(sa, sRange, {tozero: true, padded: true});
  55781. putExtremes(traces, sa, extremes);
  55782. }
  55783. }
  55784. function sieveBars(gd, sa, sieve) {
  55785. var traces = sieve.traces;
  55786. for(var i = 0; i < traces.length; i++) {
  55787. var trace = traces[i];
  55788. for(var j = 0; j < trace.length; j++) {
  55789. var bar = trace[j];
  55790. if(bar.s !== BADNUM) sieve.put(bar.p, bar.b + bar.s);
  55791. }
  55792. }
  55793. }
  55794. function normalizeBars(gd, sa, sieve) {
  55795. // Note:
  55796. //
  55797. // normalizeBars requires that either sieveBars or stackBars has been
  55798. // previously invoked.
  55799. var traces = sieve.traces,
  55800. sLetter = getAxisLetter(sa),
  55801. sTop = (gd._fullLayout.barnorm === 'fraction') ? 1 : 100,
  55802. sTiny = sTop / 1e9, // in case of rounding error in sum
  55803. sMin = sa.l2c(sa.c2l(0)),
  55804. sMax = (gd._fullLayout.barmode === 'stack') ? sTop : sMin,
  55805. sRange = [sMin, sMax],
  55806. padded = false;
  55807. function maybeExpand(newValue) {
  55808. if(isNumeric(sa.c2l(newValue)) &&
  55809. ((newValue < sMin - sTiny) || (newValue > sMax + sTiny) || !isNumeric(sMin))
  55810. ) {
  55811. padded = true;
  55812. expandRange(sRange, newValue);
  55813. }
  55814. }
  55815. for(var i = 0; i < traces.length; i++) {
  55816. var trace = traces[i];
  55817. for(var j = 0; j < trace.length; j++) {
  55818. var bar = trace[j];
  55819. if(bar.s === BADNUM) continue;
  55820. var scale = Math.abs(sTop / sieve.get(bar.p, bar.s));
  55821. bar.b *= scale;
  55822. bar.s *= scale;
  55823. var barBase = bar.b,
  55824. barTop = barBase + bar.s;
  55825. bar[sLetter] = barTop;
  55826. maybeExpand(barTop);
  55827. if(bar.hasB) maybeExpand(barBase);
  55828. }
  55829. }
  55830. // update range of size axis
  55831. var extremes = Axes.findExtremes(sa, sRange, {tozero: true, padded: padded});
  55832. putExtremes(traces, sa, extremes);
  55833. }
  55834. function getAxisLetter(ax) {
  55835. return ax._id.charAt(0);
  55836. }
  55837. function putExtremes(cd, ax, extremes) {
  55838. for(var i = 0; i < cd.length; i++) {
  55839. cd[i][0].trace._extremes[ax._id] = extremes;
  55840. }
  55841. }
  55842. // find the full position span of bars at each position
  55843. // for use by hover, to ensure labels move in if bars are
  55844. // narrower than the space they're in.
  55845. // run once per trace group (subplot & direction) and
  55846. // the same mapping is attached to all calcdata traces
  55847. function collectExtents(calcTraces, pa) {
  55848. var posLetter = pa._id.charAt(0);
  55849. var extents = {};
  55850. var pMin = Infinity;
  55851. var pMax = -Infinity;
  55852. var i, j, cd;
  55853. for(i = 0; i < calcTraces.length; i++) {
  55854. cd = calcTraces[i];
  55855. for(j = 0; j < cd.length; j++) {
  55856. var p = cd[j].p;
  55857. if(isNumeric(p)) {
  55858. pMin = Math.min(pMin, p);
  55859. pMax = Math.max(pMax, p);
  55860. }
  55861. }
  55862. }
  55863. // this is just for positioning of hover labels, and nobody will care if
  55864. // the label is 1px too far out; so round positions to 1/10K in case
  55865. // position values don't exactly match from trace to trace
  55866. var roundFactor = 10000 / (pMax - pMin);
  55867. var round = extents.round = function(p) {
  55868. return String(Math.round(roundFactor * (p - pMin)));
  55869. };
  55870. var poffset, poffsetIsArray;
  55871. for(i = 0; i < calcTraces.length; i++) {
  55872. cd = calcTraces[i];
  55873. cd[0].t.extents = extents;
  55874. poffset = cd[0].t.poffset;
  55875. poffsetIsArray = Array.isArray(poffset);
  55876. for(j = 0; j < cd.length; j++) {
  55877. var di = cd[j];
  55878. var p0 = di[posLetter] - di.w / 2;
  55879. if(isNumeric(p0)) {
  55880. var p1 = di[posLetter] + di.w / 2;
  55881. var pVal = round(di.p);
  55882. if(extents[pVal]) {
  55883. extents[pVal] = [Math.min(p0, extents[pVal][0]), Math.max(p1, extents[pVal][1])];
  55884. } else {
  55885. extents[pVal] = [p0, p1];
  55886. }
  55887. }
  55888. di.p0 = di.p + ((poffsetIsArray) ? poffset[j] : poffset);
  55889. di.p1 = di.p0 + di.w;
  55890. di.s0 = di.b;
  55891. di.s1 = di.s0 + di.s;
  55892. }
  55893. }
  55894. }
  55895. module.exports = {
  55896. crossTraceCalc: crossTraceCalc,
  55897. setGroupPositions: setGroupPositions
  55898. };
  55899. },{"../../constants/numerical":151,"../../lib":169,"../../plots/cartesian/axes":214,"../../registry":259,"./sieve.js":279,"fast-isnumeric":18}],272:[function(_dereq_,module,exports){
  55900. /**
  55901. * Copyright 2012-2018, Plotly, Inc.
  55902. * All rights reserved.
  55903. *
  55904. * This source code is licensed under the MIT license found in the
  55905. * LICENSE file in the root directory of this source tree.
  55906. */
  55907. 'use strict';
  55908. var Lib = _dereq_('../../lib');
  55909. var Color = _dereq_('../../components/color');
  55910. var Registry = _dereq_('../../registry');
  55911. var handleXYDefaults = _dereq_('../scatter/xy_defaults');
  55912. var handleStyleDefaults = _dereq_('../bar/style_defaults');
  55913. var attributes = _dereq_('./attributes');
  55914. module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout) {
  55915. function coerce(attr, dflt) {
  55916. return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);
  55917. }
  55918. var coerceFont = Lib.coerceFont;
  55919. var len = handleXYDefaults(traceIn, traceOut, layout, coerce);
  55920. if(!len) {
  55921. traceOut.visible = false;
  55922. return;
  55923. }
  55924. coerce('orientation', (traceOut.x && !traceOut.y) ? 'h' : 'v');
  55925. coerce('base');
  55926. coerce('offset');
  55927. coerce('width');
  55928. coerce('text');
  55929. coerce('hovertext');
  55930. var textPosition = coerce('textposition');
  55931. var hasBoth = Array.isArray(textPosition) || textPosition === 'auto',
  55932. hasInside = hasBoth || textPosition === 'inside',
  55933. hasOutside = hasBoth || textPosition === 'outside';
  55934. if(hasInside || hasOutside) {
  55935. var textFont = coerceFont(coerce, 'textfont', layout.font);
  55936. if(hasInside) coerceFont(coerce, 'insidetextfont', textFont);
  55937. if(hasOutside) coerceFont(coerce, 'outsidetextfont', textFont);
  55938. coerce('constraintext');
  55939. coerce('selected.textfont.color');
  55940. coerce('unselected.textfont.color');
  55941. coerce('cliponaxis');
  55942. }
  55943. handleStyleDefaults(traceIn, traceOut, coerce, defaultColor, layout);
  55944. // override defaultColor for error bars with defaultLine
  55945. var errorBarsSupplyDefaults = Registry.getComponentMethod('errorbars', 'supplyDefaults');
  55946. errorBarsSupplyDefaults(traceIn, traceOut, Color.defaultLine, {axis: 'y'});
  55947. errorBarsSupplyDefaults(traceIn, traceOut, Color.defaultLine, {axis: 'x', inherit: 'y'});
  55948. Lib.coerceSelectionMarkerOpacity(traceOut, coerce);
  55949. };
  55950. },{"../../components/color":50,"../../lib":169,"../../registry":259,"../bar/style_defaults":281,"../scatter/xy_defaults":392,"./attributes":269}],273:[function(_dereq_,module,exports){
  55951. /**
  55952. * Copyright 2012-2018, Plotly, Inc.
  55953. * All rights reserved.
  55954. *
  55955. * This source code is licensed under the MIT license found in the
  55956. * LICENSE file in the root directory of this source tree.
  55957. */
  55958. 'use strict';
  55959. var Fx = _dereq_('../../components/fx');
  55960. var Registry = _dereq_('../../registry');
  55961. var Color = _dereq_('../../components/color');
  55962. var fillHoverText = _dereq_('../scatter/fill_hover_text');
  55963. function hoverPoints(pointData, xval, yval, hovermode) {
  55964. var cd = pointData.cd;
  55965. var trace = cd[0].trace;
  55966. var t = cd[0].t;
  55967. var isClosest = (hovermode === 'closest');
  55968. var maxHoverDistance = pointData.maxHoverDistance;
  55969. var maxSpikeDistance = pointData.maxSpikeDistance;
  55970. var posVal, sizeVal, posLetter, sizeLetter, dx, dy, pRangeCalc;
  55971. function thisBarMinPos(di) { return di[posLetter] - di.w / 2; }
  55972. function thisBarMaxPos(di) { return di[posLetter] + di.w / 2; }
  55973. var minPos = isClosest ?
  55974. thisBarMinPos :
  55975. function(di) {
  55976. /*
  55977. * In compare mode, accept a bar if you're on it *or* its group.
  55978. * Nearly always it's the group that matters, but in case the bar
  55979. * was explicitly set wider than its group we'd better accept the
  55980. * whole bar.
  55981. *
  55982. * use `bardelta` instead of `bargroupwidth` so we accept hover
  55983. * in the gap. That way hover doesn't flash on and off as you
  55984. * mouse over the plot in compare modes.
  55985. * In 'closest' mode though the flashing seems inevitable,
  55986. * without far more complex logic
  55987. */
  55988. return Math.min(thisBarMinPos(di), di.p - t.bardelta / 2);
  55989. };
  55990. var maxPos = isClosest ?
  55991. thisBarMaxPos :
  55992. function(di) {
  55993. return Math.max(thisBarMaxPos(di), di.p + t.bardelta / 2);
  55994. };
  55995. function _positionFn(_minPos, _maxPos) {
  55996. // add a little to the pseudo-distance for wider bars, so that like scatter,
  55997. // if you are over two overlapping bars, the narrower one wins.
  55998. return Fx.inbox(_minPos - posVal, _maxPos - posVal,
  55999. maxHoverDistance + Math.min(1, Math.abs(_maxPos - _minPos) / pRangeCalc) - 1);
  56000. }
  56001. function positionFn(di) {
  56002. return _positionFn(minPos(di), maxPos(di));
  56003. }
  56004. function thisBarPositionFn(di) {
  56005. return _positionFn(thisBarMinPos(di), thisBarMaxPos(di));
  56006. }
  56007. function sizeFn(di) {
  56008. // add a gradient so hovering near the end of a
  56009. // bar makes it a little closer match
  56010. return Fx.inbox(di.b - sizeVal, di[sizeLetter] - sizeVal,
  56011. maxHoverDistance + (di[sizeLetter] - sizeVal) / (di[sizeLetter] - di.b) - 1);
  56012. }
  56013. if(trace.orientation === 'h') {
  56014. posVal = yval;
  56015. sizeVal = xval;
  56016. posLetter = 'y';
  56017. sizeLetter = 'x';
  56018. dx = sizeFn;
  56019. dy = positionFn;
  56020. }
  56021. else {
  56022. posVal = xval;
  56023. sizeVal = yval;
  56024. posLetter = 'x';
  56025. sizeLetter = 'y';
  56026. dy = sizeFn;
  56027. dx = positionFn;
  56028. }
  56029. var pa = pointData[posLetter + 'a'];
  56030. var sa = pointData[sizeLetter + 'a'];
  56031. pRangeCalc = Math.abs(pa.r2c(pa.range[1]) - pa.r2c(pa.range[0]));
  56032. function dxy(di) { return (dx(di) + dy(di)) / 2; }
  56033. var distfn = Fx.getDistanceFunction(hovermode, dx, dy, dxy);
  56034. Fx.getClosest(cd, distfn, pointData);
  56035. // skip the rest (for this trace) if we didn't find a close point
  56036. if(pointData.index === false) return;
  56037. // if we get here and we're not in 'closest' mode, push min/max pos back
  56038. // onto the group - even though that means occasionally the mouse will be
  56039. // over the hover label.
  56040. if(!isClosest) {
  56041. minPos = function(di) {
  56042. return Math.min(thisBarMinPos(di), di.p - t.bargroupwidth / 2);
  56043. };
  56044. maxPos = function(di) {
  56045. return Math.max(thisBarMaxPos(di), di.p + t.bargroupwidth / 2);
  56046. };
  56047. }
  56048. // the closest data point
  56049. var index = pointData.index;
  56050. var di = cd[index];
  56051. var size = (trace.base) ? di.b + di.s : di.s;
  56052. pointData[sizeLetter + '0'] = pointData[sizeLetter + '1'] = sa.c2p(di[sizeLetter], true);
  56053. pointData[sizeLetter + 'LabelVal'] = size;
  56054. var extent = t.extents[t.extents.round(di.p)];
  56055. pointData[posLetter + '0'] = pa.c2p(isClosest ? minPos(di) : extent[0], true);
  56056. pointData[posLetter + '1'] = pa.c2p(isClosest ? maxPos(di) : extent[1], true);
  56057. pointData[posLetter + 'LabelVal'] = di.p;
  56058. // spikelines always want "closest" distance regardless of hovermode
  56059. pointData.spikeDistance = (sizeFn(di) + thisBarPositionFn(di)) / 2 + maxSpikeDistance - maxHoverDistance;
  56060. // they also want to point to the data value, regardless of where the label goes
  56061. // in case of bars shifted within groups
  56062. pointData[posLetter + 'Spike'] = pa.c2p(di.p, true);
  56063. pointData.color = getTraceColor(trace, di);
  56064. fillHoverText(di, trace, pointData);
  56065. Registry.getComponentMethod('errorbars', 'hoverInfo')(di, trace, pointData);
  56066. return [pointData];
  56067. }
  56068. function getTraceColor(trace, di) {
  56069. var mc = di.mcc || trace.marker.color;
  56070. var mlc = di.mlcc || trace.marker.line.color;
  56071. var mlw = di.mlw || trace.marker.line.width;
  56072. if(Color.opacity(mc)) return mc;
  56073. else if(Color.opacity(mlc) && mlw) return mlc;
  56074. }
  56075. module.exports = {
  56076. hoverPoints: hoverPoints,
  56077. getTraceColor: getTraceColor
  56078. };
  56079. },{"../../components/color":50,"../../components/fx":92,"../../registry":259,"../scatter/fill_hover_text":374}],274:[function(_dereq_,module,exports){
  56080. /**
  56081. * Copyright 2012-2018, Plotly, Inc.
  56082. * All rights reserved.
  56083. *
  56084. * This source code is licensed under the MIT license found in the
  56085. * LICENSE file in the root directory of this source tree.
  56086. */
  56087. 'use strict';
  56088. var Bar = {};
  56089. Bar.attributes = _dereq_('./attributes');
  56090. Bar.layoutAttributes = _dereq_('./layout_attributes');
  56091. Bar.supplyDefaults = _dereq_('./defaults');
  56092. Bar.supplyLayoutDefaults = _dereq_('./layout_defaults');
  56093. Bar.calc = _dereq_('./calc');
  56094. Bar.crossTraceCalc = _dereq_('./cross_trace_calc').crossTraceCalc;
  56095. Bar.colorbar = _dereq_('../scatter/marker_colorbar');
  56096. Bar.arraysToCalcdata = _dereq_('./arrays_to_calcdata');
  56097. Bar.plot = _dereq_('./plot');
  56098. Bar.style = _dereq_('./style').style;
  56099. Bar.styleOnSelect = _dereq_('./style').styleOnSelect;
  56100. Bar.hoverPoints = _dereq_('./hover').hoverPoints;
  56101. Bar.selectPoints = _dereq_('./select');
  56102. Bar.moduleType = 'trace';
  56103. Bar.name = 'bar';
  56104. Bar.basePlotModule = _dereq_('../../plots/cartesian');
  56105. Bar.categories = ['cartesian', 'svg', 'bar', 'oriented', 'errorBarsOK', 'showLegend', 'zoomScale'];
  56106. Bar.meta = {
  56107. };
  56108. module.exports = Bar;
  56109. },{"../../plots/cartesian":225,"../scatter/marker_colorbar":384,"./arrays_to_calcdata":268,"./attributes":269,"./calc":270,"./cross_trace_calc":271,"./defaults":272,"./hover":273,"./layout_attributes":275,"./layout_defaults":276,"./plot":277,"./select":278,"./style":280}],275:[function(_dereq_,module,exports){
  56110. /**
  56111. * Copyright 2012-2018, Plotly, Inc.
  56112. * All rights reserved.
  56113. *
  56114. * This source code is licensed under the MIT license found in the
  56115. * LICENSE file in the root directory of this source tree.
  56116. */
  56117. 'use strict';
  56118. module.exports = {
  56119. barmode: {
  56120. valType: 'enumerated',
  56121. values: ['stack', 'group', 'overlay', 'relative'],
  56122. dflt: 'group',
  56123. editType: 'calc',
  56124. },
  56125. barnorm: {
  56126. valType: 'enumerated',
  56127. values: ['', 'fraction', 'percent'],
  56128. dflt: '',
  56129. editType: 'calc',
  56130. },
  56131. bargap: {
  56132. valType: 'number',
  56133. min: 0,
  56134. max: 1,
  56135. editType: 'calc',
  56136. },
  56137. bargroupgap: {
  56138. valType: 'number',
  56139. min: 0,
  56140. max: 1,
  56141. dflt: 0,
  56142. editType: 'calc',
  56143. }
  56144. };
  56145. },{}],276:[function(_dereq_,module,exports){
  56146. /**
  56147. * Copyright 2012-2018, Plotly, Inc.
  56148. * All rights reserved.
  56149. *
  56150. * This source code is licensed under the MIT license found in the
  56151. * LICENSE file in the root directory of this source tree.
  56152. */
  56153. 'use strict';
  56154. var Registry = _dereq_('../../registry');
  56155. var Axes = _dereq_('../../plots/cartesian/axes');
  56156. var Lib = _dereq_('../../lib');
  56157. var layoutAttributes = _dereq_('./layout_attributes');
  56158. module.exports = function(layoutIn, layoutOut, fullData) {
  56159. function coerce(attr, dflt) {
  56160. return Lib.coerce(layoutIn, layoutOut, layoutAttributes, attr, dflt);
  56161. }
  56162. var hasBars = false,
  56163. shouldBeGapless = false,
  56164. gappedAnyway = false,
  56165. usedSubplots = {};
  56166. for(var i = 0; i < fullData.length; i++) {
  56167. var trace = fullData[i];
  56168. if(Registry.traceIs(trace, 'bar')) hasBars = true;
  56169. else continue;
  56170. // if we have at least 2 grouped bar traces on the same subplot,
  56171. // we should default to a gap anyway, even if the data is histograms
  56172. if(layoutIn.barmode !== 'overlay' && layoutIn.barmode !== 'stack') {
  56173. var subploti = trace.xaxis + trace.yaxis;
  56174. if(usedSubplots[subploti]) gappedAnyway = true;
  56175. usedSubplots[subploti] = true;
  56176. }
  56177. if(trace.visible && trace.type === 'histogram') {
  56178. var pa = Axes.getFromId({_fullLayout: layoutOut},
  56179. trace[trace.orientation === 'v' ? 'xaxis' : 'yaxis']);
  56180. if(pa.type !== 'category') shouldBeGapless = true;
  56181. }
  56182. }
  56183. if(!hasBars) return;
  56184. var mode = coerce('barmode');
  56185. if(mode !== 'overlay') coerce('barnorm');
  56186. coerce('bargap', (shouldBeGapless && !gappedAnyway) ? 0 : 0.2);
  56187. coerce('bargroupgap');
  56188. };
  56189. },{"../../lib":169,"../../plots/cartesian/axes":214,"../../registry":259,"./layout_attributes":275}],277:[function(_dereq_,module,exports){
  56190. /**
  56191. * Copyright 2012-2018, Plotly, Inc.
  56192. * All rights reserved.
  56193. *
  56194. * This source code is licensed under the MIT license found in the
  56195. * LICENSE file in the root directory of this source tree.
  56196. */
  56197. 'use strict';
  56198. var d3 = _dereq_('d3');
  56199. var isNumeric = _dereq_('fast-isnumeric');
  56200. var tinycolor = _dereq_('tinycolor2');
  56201. var Lib = _dereq_('../../lib');
  56202. var svgTextUtils = _dereq_('../../lib/svg_text_utils');
  56203. var Color = _dereq_('../../components/color');
  56204. var Drawing = _dereq_('../../components/drawing');
  56205. var Registry = _dereq_('../../registry');
  56206. var attributes = _dereq_('./attributes'),
  56207. attributeText = attributes.text,
  56208. attributeTextPosition = attributes.textposition,
  56209. attributeTextFont = attributes.textfont,
  56210. attributeInsideTextFont = attributes.insidetextfont,
  56211. attributeOutsideTextFont = attributes.outsidetextfont;
  56212. // padding in pixels around text
  56213. var TEXTPAD = 3;
  56214. module.exports = function plot(gd, plotinfo, cdbar, barLayer) {
  56215. var xa = plotinfo.xaxis;
  56216. var ya = plotinfo.yaxis;
  56217. var fullLayout = gd._fullLayout;
  56218. var bartraces = Lib.makeTraceGroups(barLayer, cdbar, 'trace bars').each(function(cd) {
  56219. var plotGroup = d3.select(this);
  56220. var cd0 = cd[0];
  56221. var trace = cd0.trace;
  56222. if(!plotinfo.isRangePlot) cd0.node3 = plotGroup;
  56223. var pointGroup = Lib.ensureSingle(plotGroup, 'g', 'points');
  56224. var bars = pointGroup.selectAll('g.point').data(Lib.identity);
  56225. bars.enter().append('g')
  56226. .classed('point', true);
  56227. bars.exit().remove();
  56228. bars.each(function(di, i) {
  56229. var bar = d3.select(this);
  56230. // now display the bar
  56231. // clipped xf/yf (2nd arg true): non-positive
  56232. // log values go off-screen by plotwidth
  56233. // so you see them continue if you drag the plot
  56234. var x0, x1, y0, y1;
  56235. if(trace.orientation === 'h') {
  56236. y0 = ya.c2p(di.p0, true);
  56237. y1 = ya.c2p(di.p1, true);
  56238. x0 = xa.c2p(di.s0, true);
  56239. x1 = xa.c2p(di.s1, true);
  56240. // for selections
  56241. di.ct = [x1, (y0 + y1) / 2];
  56242. }
  56243. else {
  56244. x0 = xa.c2p(di.p0, true);
  56245. x1 = xa.c2p(di.p1, true);
  56246. y0 = ya.c2p(di.s0, true);
  56247. y1 = ya.c2p(di.s1, true);
  56248. // for selections
  56249. di.ct = [(x0 + x1) / 2, y1];
  56250. }
  56251. if(!isNumeric(x0) || !isNumeric(x1) ||
  56252. !isNumeric(y0) || !isNumeric(y1) ||
  56253. x0 === x1 || y0 === y1) {
  56254. bar.remove();
  56255. return;
  56256. }
  56257. var lw = (di.mlw + 1 || trace.marker.line.width + 1 ||
  56258. (di.trace ? di.trace.marker.line.width : 0) + 1) - 1,
  56259. offset = d3.round((lw / 2) % 1, 2);
  56260. function roundWithLine(v) {
  56261. // if there are explicit gaps, don't round,
  56262. // it can make the gaps look crappy
  56263. return (fullLayout.bargap === 0 && fullLayout.bargroupgap === 0) ?
  56264. d3.round(Math.round(v) - offset, 2) : v;
  56265. }
  56266. function expandToVisible(v, vc) {
  56267. // if it's not in danger of disappearing entirely,
  56268. // round more precisely
  56269. return Math.abs(v - vc) >= 2 ? roundWithLine(v) :
  56270. // but if it's very thin, expand it so it's
  56271. // necessarily visible, even if it might overlap
  56272. // its neighbor
  56273. (v > vc ? Math.ceil(v) : Math.floor(v));
  56274. }
  56275. if(!gd._context.staticPlot) {
  56276. // if bars are not fully opaque or they have a line
  56277. // around them, round to integer pixels, mainly for
  56278. // safari so we prevent overlaps from its expansive
  56279. // pixelation. if the bars ARE fully opaque and have
  56280. // no line, expand to a full pixel to make sure we
  56281. // can see them
  56282. var op = Color.opacity(di.mc || trace.marker.color),
  56283. fixpx = (op < 1 || lw > 0.01) ?
  56284. roundWithLine : expandToVisible;
  56285. x0 = fixpx(x0, x1);
  56286. x1 = fixpx(x1, x0);
  56287. y0 = fixpx(y0, y1);
  56288. y1 = fixpx(y1, y0);
  56289. }
  56290. Lib.ensureSingle(bar, 'path')
  56291. .style('vector-effect', 'non-scaling-stroke')
  56292. .attr('d',
  56293. 'M' + x0 + ',' + y0 + 'V' + y1 + 'H' + x1 + 'V' + y0 + 'Z')
  56294. .call(Drawing.setClipUrl, plotinfo.layerClipId);
  56295. appendBarText(gd, bar, cd, i, x0, x1, y0, y1);
  56296. if(plotinfo.layerClipId) {
  56297. Drawing.hideOutsideRangePoint(di, bar.select('text'), xa, ya, trace.xcalendar, trace.ycalendar);
  56298. }
  56299. });
  56300. // lastly, clip points groups of `cliponaxis !== false` traces
  56301. // on `plotinfo._hasClipOnAxisFalse === true` subplots
  56302. var hasClipOnAxisFalse = cd0.trace.cliponaxis === false;
  56303. Drawing.setClipUrl(plotGroup, hasClipOnAxisFalse ? null : plotinfo.layerClipId);
  56304. });
  56305. // error bars are on the top
  56306. Registry.getComponentMethod('errorbars', 'plot')(bartraces, plotinfo);
  56307. };
  56308. function appendBarText(gd, bar, calcTrace, i, x0, x1, y0, y1) {
  56309. var textPosition;
  56310. function appendTextNode(bar, text, textFont) {
  56311. var textSelection = Lib.ensureSingle(bar, 'text')
  56312. .text(text)
  56313. .attr({
  56314. 'class': 'bartext bartext-' + textPosition,
  56315. transform: '',
  56316. 'text-anchor': 'middle',
  56317. // prohibit tex interpretation until we can handle
  56318. // tex and regular text together
  56319. 'data-notex': 1
  56320. })
  56321. .call(Drawing.font, textFont)
  56322. .call(svgTextUtils.convertToTspans, gd);
  56323. return textSelection;
  56324. }
  56325. // get trace attributes
  56326. var trace = calcTrace[0].trace,
  56327. orientation = trace.orientation;
  56328. var text = getText(trace, i);
  56329. textPosition = getTextPosition(trace, i);
  56330. if(!text || textPosition === 'none') {
  56331. bar.select('text').remove();
  56332. return;
  56333. }
  56334. var textFont = getTextFont(trace, i, gd._fullLayout.font),
  56335. insideTextFont = getInsideTextFont(trace, i, textFont),
  56336. outsideTextFont = getOutsideTextFont(trace, i, textFont);
  56337. // compute text position
  56338. var barmode = gd._fullLayout.barmode,
  56339. inStackMode = (barmode === 'stack'),
  56340. inRelativeMode = (barmode === 'relative'),
  56341. inStackOrRelativeMode = inStackMode || inRelativeMode,
  56342. calcBar = calcTrace[i],
  56343. isOutmostBar = !inStackOrRelativeMode || calcBar._outmost,
  56344. barWidth = Math.abs(x1 - x0) - 2 * TEXTPAD, // padding excluded
  56345. barHeight = Math.abs(y1 - y0) - 2 * TEXTPAD, // padding excluded
  56346. textSelection,
  56347. textBB,
  56348. textWidth,
  56349. textHeight;
  56350. if(textPosition === 'outside') {
  56351. if(!isOutmostBar) textPosition = 'inside';
  56352. }
  56353. if(textPosition === 'auto') {
  56354. if(isOutmostBar) {
  56355. // draw text using insideTextFont and check if it fits inside bar
  56356. textPosition = 'inside';
  56357. textSelection = appendTextNode(bar, text, insideTextFont);
  56358. textBB = Drawing.bBox(textSelection.node()),
  56359. textWidth = textBB.width,
  56360. textHeight = textBB.height;
  56361. var textHasSize = (textWidth > 0 && textHeight > 0),
  56362. fitsInside =
  56363. (textWidth <= barWidth && textHeight <= barHeight),
  56364. fitsInsideIfRotated =
  56365. (textWidth <= barHeight && textHeight <= barWidth),
  56366. fitsInsideIfShrunk = (orientation === 'h') ?
  56367. (barWidth >= textWidth * (barHeight / textHeight)) :
  56368. (barHeight >= textHeight * (barWidth / textWidth));
  56369. if(textHasSize &&
  56370. (fitsInside || fitsInsideIfRotated || fitsInsideIfShrunk)) {
  56371. textPosition = 'inside';
  56372. }
  56373. else {
  56374. textPosition = 'outside';
  56375. textSelection.remove();
  56376. textSelection = null;
  56377. }
  56378. }
  56379. else textPosition = 'inside';
  56380. }
  56381. if(!textSelection) {
  56382. textSelection = appendTextNode(bar, text,
  56383. (textPosition === 'outside') ?
  56384. outsideTextFont : insideTextFont);
  56385. textBB = Drawing.bBox(textSelection.node()),
  56386. textWidth = textBB.width,
  56387. textHeight = textBB.height;
  56388. if(textWidth <= 0 || textHeight <= 0) {
  56389. textSelection.remove();
  56390. return;
  56391. }
  56392. }
  56393. // compute text transform
  56394. var transform, constrained;
  56395. if(textPosition === 'outside') {
  56396. constrained = trace.constraintext === 'both' || trace.constraintext === 'outside';
  56397. transform = getTransformToMoveOutsideBar(x0, x1, y0, y1, textBB,
  56398. orientation, constrained);
  56399. }
  56400. else {
  56401. constrained = trace.constraintext === 'both' || trace.constraintext === 'inside';
  56402. transform = getTransformToMoveInsideBar(x0, x1, y0, y1, textBB,
  56403. orientation, constrained);
  56404. }
  56405. textSelection.attr('transform', transform);
  56406. }
  56407. function getTransformToMoveInsideBar(x0, x1, y0, y1, textBB, orientation, constrained) {
  56408. // compute text and target positions
  56409. var textWidth = textBB.width,
  56410. textHeight = textBB.height,
  56411. textX = (textBB.left + textBB.right) / 2,
  56412. textY = (textBB.top + textBB.bottom) / 2,
  56413. barWidth = Math.abs(x1 - x0),
  56414. barHeight = Math.abs(y1 - y0),
  56415. targetWidth,
  56416. targetHeight,
  56417. targetX,
  56418. targetY;
  56419. // apply text padding
  56420. var textpad;
  56421. if(barWidth > (2 * TEXTPAD) && barHeight > (2 * TEXTPAD)) {
  56422. textpad = TEXTPAD;
  56423. barWidth -= 2 * textpad;
  56424. barHeight -= 2 * textpad;
  56425. }
  56426. else textpad = 0;
  56427. // compute rotation and scale
  56428. var rotate,
  56429. scale;
  56430. if(textWidth <= barWidth && textHeight <= barHeight) {
  56431. // no scale or rotation is required
  56432. rotate = false;
  56433. scale = 1;
  56434. }
  56435. else if(textWidth <= barHeight && textHeight <= barWidth) {
  56436. // only rotation is required
  56437. rotate = true;
  56438. scale = 1;
  56439. }
  56440. else if((textWidth < textHeight) === (barWidth < barHeight)) {
  56441. // only scale is required
  56442. rotate = false;
  56443. scale = constrained ? Math.min(barWidth / textWidth, barHeight / textHeight) : 1;
  56444. }
  56445. else {
  56446. // both scale and rotation are required
  56447. rotate = true;
  56448. scale = constrained ? Math.min(barHeight / textWidth, barWidth / textHeight) : 1;
  56449. }
  56450. if(rotate) rotate = 90; // rotate clockwise
  56451. // compute text and target positions
  56452. if(rotate) {
  56453. targetWidth = scale * textHeight;
  56454. targetHeight = scale * textWidth;
  56455. }
  56456. else {
  56457. targetWidth = scale * textWidth;
  56458. targetHeight = scale * textHeight;
  56459. }
  56460. if(orientation === 'h') {
  56461. if(x1 < x0) {
  56462. // bar end is on the left hand side
  56463. targetX = x1 + textpad + targetWidth / 2;
  56464. targetY = (y0 + y1) / 2;
  56465. }
  56466. else {
  56467. targetX = x1 - textpad - targetWidth / 2;
  56468. targetY = (y0 + y1) / 2;
  56469. }
  56470. }
  56471. else {
  56472. if(y1 > y0) {
  56473. // bar end is on the bottom
  56474. targetX = (x0 + x1) / 2;
  56475. targetY = y1 - textpad - targetHeight / 2;
  56476. }
  56477. else {
  56478. targetX = (x0 + x1) / 2;
  56479. targetY = y1 + textpad + targetHeight / 2;
  56480. }
  56481. }
  56482. return getTransform(textX, textY, targetX, targetY, scale, rotate);
  56483. }
  56484. function getTransformToMoveOutsideBar(x0, x1, y0, y1, textBB, orientation, constrained) {
  56485. var barWidth = (orientation === 'h') ?
  56486. Math.abs(y1 - y0) :
  56487. Math.abs(x1 - x0),
  56488. textpad;
  56489. // Keep the padding so the text doesn't sit right against
  56490. // the bars, but don't factor it into barWidth
  56491. if(barWidth > 2 * TEXTPAD) {
  56492. textpad = TEXTPAD;
  56493. }
  56494. // compute rotation and scale
  56495. var scale = 1;
  56496. if(constrained) {
  56497. scale = (orientation === 'h') ?
  56498. Math.min(1, barWidth / textBB.height) :
  56499. Math.min(1, barWidth / textBB.width);
  56500. }
  56501. // compute text and target positions
  56502. var textX = (textBB.left + textBB.right) / 2,
  56503. textY = (textBB.top + textBB.bottom) / 2,
  56504. targetWidth,
  56505. targetHeight,
  56506. targetX,
  56507. targetY;
  56508. targetWidth = scale * textBB.width;
  56509. targetHeight = scale * textBB.height;
  56510. if(orientation === 'h') {
  56511. if(x1 < x0) {
  56512. // bar end is on the left hand side
  56513. targetX = x1 - textpad - targetWidth / 2;
  56514. targetY = (y0 + y1) / 2;
  56515. }
  56516. else {
  56517. targetX = x1 + textpad + targetWidth / 2;
  56518. targetY = (y0 + y1) / 2;
  56519. }
  56520. }
  56521. else {
  56522. if(y1 > y0) {
  56523. // bar end is on the bottom
  56524. targetX = (x0 + x1) / 2;
  56525. targetY = y1 + textpad + targetHeight / 2;
  56526. }
  56527. else {
  56528. targetX = (x0 + x1) / 2;
  56529. targetY = y1 - textpad - targetHeight / 2;
  56530. }
  56531. }
  56532. return getTransform(textX, textY, targetX, targetY, scale, false);
  56533. }
  56534. function getTransform(textX, textY, targetX, targetY, scale, rotate) {
  56535. var transformScale,
  56536. transformRotate,
  56537. transformTranslate;
  56538. if(scale < 1) transformScale = 'scale(' + scale + ') ';
  56539. else {
  56540. scale = 1;
  56541. transformScale = '';
  56542. }
  56543. transformRotate = (rotate) ?
  56544. 'rotate(' + rotate + ' ' + textX + ' ' + textY + ') ' : '';
  56545. // Note that scaling also affects the center of the text box
  56546. var translateX = (targetX - scale * textX),
  56547. translateY = (targetY - scale * textY);
  56548. transformTranslate = 'translate(' + translateX + ' ' + translateY + ')';
  56549. return transformTranslate + transformScale + transformRotate;
  56550. }
  56551. function getText(trace, index) {
  56552. var value = getValue(trace.text, index);
  56553. return coerceString(attributeText, value);
  56554. }
  56555. function getTextPosition(trace, index) {
  56556. var value = getValue(trace.textposition, index);
  56557. return coerceEnumerated(attributeTextPosition, value);
  56558. }
  56559. function getTextFont(trace, index, defaultValue) {
  56560. return getFontValue(
  56561. attributeTextFont, trace.textfont, index, defaultValue);
  56562. }
  56563. function getInsideTextFont(trace, index, defaultValue) {
  56564. return getFontValue(
  56565. attributeInsideTextFont, trace.insidetextfont, index, defaultValue);
  56566. }
  56567. function getOutsideTextFont(trace, index, defaultValue) {
  56568. return getFontValue(
  56569. attributeOutsideTextFont, trace.outsidetextfont, index, defaultValue);
  56570. }
  56571. function getFontValue(attributeDefinition, attributeValue, index, defaultValue) {
  56572. attributeValue = attributeValue || {};
  56573. var familyValue = getValue(attributeValue.family, index),
  56574. sizeValue = getValue(attributeValue.size, index),
  56575. colorValue = getValue(attributeValue.color, index);
  56576. return {
  56577. family: coerceString(
  56578. attributeDefinition.family, familyValue, defaultValue.family),
  56579. size: coerceNumber(
  56580. attributeDefinition.size, sizeValue, defaultValue.size),
  56581. color: coerceColor(
  56582. attributeDefinition.color, colorValue, defaultValue.color)
  56583. };
  56584. }
  56585. function getValue(arrayOrScalar, index) {
  56586. var value;
  56587. if(!Array.isArray(arrayOrScalar)) value = arrayOrScalar;
  56588. else if(index < arrayOrScalar.length) value = arrayOrScalar[index];
  56589. return value;
  56590. }
  56591. function coerceString(attributeDefinition, value, defaultValue) {
  56592. if(typeof value === 'string') {
  56593. if(value || !attributeDefinition.noBlank) return value;
  56594. }
  56595. else if(typeof value === 'number') {
  56596. if(!attributeDefinition.strict) return String(value);
  56597. }
  56598. return (defaultValue !== undefined) ?
  56599. defaultValue :
  56600. attributeDefinition.dflt;
  56601. }
  56602. function coerceEnumerated(attributeDefinition, value, defaultValue) {
  56603. if(attributeDefinition.coerceNumber) value = +value;
  56604. if(attributeDefinition.values.indexOf(value) !== -1) return value;
  56605. return (defaultValue !== undefined) ?
  56606. defaultValue :
  56607. attributeDefinition.dflt;
  56608. }
  56609. function coerceNumber(attributeDefinition, value, defaultValue) {
  56610. if(isNumeric(value)) {
  56611. value = +value;
  56612. var min = attributeDefinition.min,
  56613. max = attributeDefinition.max,
  56614. isOutOfBounds = (min !== undefined && value < min) ||
  56615. (max !== undefined && value > max);
  56616. if(!isOutOfBounds) return value;
  56617. }
  56618. return (defaultValue !== undefined) ?
  56619. defaultValue :
  56620. attributeDefinition.dflt;
  56621. }
  56622. function coerceColor(attributeDefinition, value, defaultValue) {
  56623. if(tinycolor(value).isValid()) return value;
  56624. return (defaultValue !== undefined) ?
  56625. defaultValue :
  56626. attributeDefinition.dflt;
  56627. }
  56628. },{"../../components/color":50,"../../components/drawing":75,"../../lib":169,"../../lib/svg_text_utils":191,"../../registry":259,"./attributes":269,"d3":16,"fast-isnumeric":18,"tinycolor2":33}],278:[function(_dereq_,module,exports){
  56629. /**
  56630. * Copyright 2012-2018, Plotly, Inc.
  56631. * All rights reserved.
  56632. *
  56633. * This source code is licensed under the MIT license found in the
  56634. * LICENSE file in the root directory of this source tree.
  56635. */
  56636. 'use strict';
  56637. module.exports = function selectPoints(searchInfo, selectionTester) {
  56638. var cd = searchInfo.cd;
  56639. var xa = searchInfo.xaxis;
  56640. var ya = searchInfo.yaxis;
  56641. var selection = [];
  56642. var i;
  56643. if(selectionTester === false) {
  56644. // clear selection
  56645. for(i = 0; i < cd.length; i++) {
  56646. cd[i].selected = 0;
  56647. }
  56648. } else {
  56649. for(i = 0; i < cd.length; i++) {
  56650. var di = cd[i];
  56651. if(selectionTester.contains(di.ct, false, i, searchInfo)) {
  56652. selection.push({
  56653. pointNumber: i,
  56654. x: xa.c2d(di.x),
  56655. y: ya.c2d(di.y)
  56656. });
  56657. di.selected = 1;
  56658. } else {
  56659. di.selected = 0;
  56660. }
  56661. }
  56662. }
  56663. return selection;
  56664. };
  56665. },{}],279:[function(_dereq_,module,exports){
  56666. /**
  56667. * Copyright 2012-2018, Plotly, Inc.
  56668. * All rights reserved.
  56669. *
  56670. * This source code is licensed under the MIT license found in the
  56671. * LICENSE file in the root directory of this source tree.
  56672. */
  56673. 'use strict';
  56674. module.exports = Sieve;
  56675. var Lib = _dereq_('../../lib');
  56676. var BADNUM = _dereq_('../../constants/numerical').BADNUM;
  56677. /**
  56678. * Helper class to sieve data from traces into bins
  56679. *
  56680. * @class
  56681. * @param {Array} traces
  56682. * Array of calculated traces
  56683. * @param {boolean} [separateNegativeValues]
  56684. * If true, then split data at the same position into a bar
  56685. * for positive values and another for negative values
  56686. * @param {boolean} [dontMergeOverlappingData]
  56687. * If true, then don't merge overlapping bars into a single bar
  56688. */
  56689. function Sieve(traces, separateNegativeValues, dontMergeOverlappingData) {
  56690. this.traces = traces;
  56691. this.separateNegativeValues = separateNegativeValues;
  56692. this.dontMergeOverlappingData = dontMergeOverlappingData;
  56693. // for single-bin histograms - see histogram/calc
  56694. var width1 = Infinity;
  56695. var positions = [];
  56696. for(var i = 0; i < traces.length; i++) {
  56697. var trace = traces[i];
  56698. for(var j = 0; j < trace.length; j++) {
  56699. var bar = trace[j];
  56700. if(bar.p !== BADNUM) positions.push(bar.p);
  56701. }
  56702. if(trace[0] && trace[0].width1) {
  56703. width1 = Math.min(trace[0].width1, width1);
  56704. }
  56705. }
  56706. this.positions = positions;
  56707. var dv = Lib.distinctVals(positions);
  56708. this.distinctPositions = dv.vals;
  56709. if(dv.vals.length === 1 && width1 !== Infinity) this.minDiff = width1;
  56710. else this.minDiff = Math.min(dv.minDiff, width1);
  56711. this.binWidth = this.minDiff;
  56712. this.bins = {};
  56713. }
  56714. /**
  56715. * Sieve datum
  56716. *
  56717. * @method
  56718. * @param {number} position
  56719. * @param {number} value
  56720. * @returns {number} Previous bin value
  56721. */
  56722. Sieve.prototype.put = function put(position, value) {
  56723. var label = this.getLabel(position, value),
  56724. oldValue = this.bins[label] || 0;
  56725. this.bins[label] = oldValue + value;
  56726. return oldValue;
  56727. };
  56728. /**
  56729. * Get current bin value for a given datum
  56730. *
  56731. * @method
  56732. * @param {number} position Position of datum
  56733. * @param {number} [value] Value of datum
  56734. * (required if this.separateNegativeValues is true)
  56735. * @returns {number} Current bin value
  56736. */
  56737. Sieve.prototype.get = function put(position, value) {
  56738. var label = this.getLabel(position, value);
  56739. return this.bins[label] || 0;
  56740. };
  56741. /**
  56742. * Get bin label for a given datum
  56743. *
  56744. * @method
  56745. * @param {number} position Position of datum
  56746. * @param {number} [value] Value of datum
  56747. * (required if this.separateNegativeValues is true)
  56748. * @returns {string} Bin label
  56749. * (prefixed with a 'v' if value is negative and this.separateNegativeValues is
  56750. * true; otherwise prefixed with '^')
  56751. */
  56752. Sieve.prototype.getLabel = function getLabel(position, value) {
  56753. var prefix = (value < 0 && this.separateNegativeValues) ? 'v' : '^',
  56754. label = (this.dontMergeOverlappingData) ?
  56755. position :
  56756. Math.round(position / this.binWidth);
  56757. return prefix + label;
  56758. };
  56759. },{"../../constants/numerical":151,"../../lib":169}],280:[function(_dereq_,module,exports){
  56760. /**
  56761. * Copyright 2012-2018, Plotly, Inc.
  56762. * All rights reserved.
  56763. *
  56764. * This source code is licensed under the MIT license found in the
  56765. * LICENSE file in the root directory of this source tree.
  56766. */
  56767. 'use strict';
  56768. var d3 = _dereq_('d3');
  56769. var Drawing = _dereq_('../../components/drawing');
  56770. var Registry = _dereq_('../../registry');
  56771. function style(gd, cd) {
  56772. var s = cd ? cd[0].node3 : d3.select(gd).selectAll('g.trace.bars');
  56773. var barcount = s.size();
  56774. var fullLayout = gd._fullLayout;
  56775. // trace styling
  56776. s.style('opacity', function(d) { return d[0].trace.opacity; })
  56777. // for gapless (either stacked or neighboring grouped) bars use
  56778. // crispEdges to turn off antialiasing so an artificial gap
  56779. // isn't introduced.
  56780. .each(function(d) {
  56781. if((fullLayout.barmode === 'stack' && barcount > 1) ||
  56782. (fullLayout.bargap === 0 &&
  56783. fullLayout.bargroupgap === 0 &&
  56784. !d[0].trace.marker.line.width)) {
  56785. d3.select(this).attr('shape-rendering', 'crispEdges');
  56786. }
  56787. });
  56788. s.selectAll('g.points').each(function(d) {
  56789. var sel = d3.select(this);
  56790. var trace = d[0].trace;
  56791. stylePoints(sel, trace, gd);
  56792. });
  56793. Registry.getComponentMethod('errorbars', 'style')(s);
  56794. }
  56795. function stylePoints(sel, trace, gd) {
  56796. var pts = sel.selectAll('path');
  56797. var txs = sel.selectAll('text');
  56798. Drawing.pointStyle(pts, trace, gd);
  56799. txs.each(function(d) {
  56800. var tx = d3.select(this);
  56801. var textFont;
  56802. if(tx.classed('bartext-inside')) {
  56803. textFont = trace.insidetextfont;
  56804. } else if(tx.classed('bartext-outside')) {
  56805. textFont = trace.outsidetextfont;
  56806. }
  56807. if(!textFont) textFont = trace.textfont;
  56808. function cast(k) {
  56809. var cont = textFont[k];
  56810. return Array.isArray(cont) ? cont[d.i] : cont;
  56811. }
  56812. Drawing.font(tx, cast('family'), cast('size'), cast('color'));
  56813. });
  56814. }
  56815. function styleOnSelect(gd, cd) {
  56816. var s = cd[0].node3;
  56817. var trace = cd[0].trace;
  56818. if(trace.selectedpoints) {
  56819. Drawing.selectedPointStyle(s.selectAll('path'), trace);
  56820. Drawing.selectedTextStyle(s.selectAll('text'), trace);
  56821. } else {
  56822. stylePoints(s, trace, gd);
  56823. }
  56824. }
  56825. module.exports = {
  56826. style: style,
  56827. styleOnSelect: styleOnSelect
  56828. };
  56829. },{"../../components/drawing":75,"../../registry":259,"d3":16}],281:[function(_dereq_,module,exports){
  56830. /**
  56831. * Copyright 2012-2018, Plotly, Inc.
  56832. * All rights reserved.
  56833. *
  56834. * This source code is licensed under the MIT license found in the
  56835. * LICENSE file in the root directory of this source tree.
  56836. */
  56837. 'use strict';
  56838. var Color = _dereq_('../../components/color');
  56839. var hasColorscale = _dereq_('../../components/colorscale/has_colorscale');
  56840. var colorscaleDefaults = _dereq_('../../components/colorscale/defaults');
  56841. module.exports = function handleStyleDefaults(traceIn, traceOut, coerce, defaultColor, layout) {
  56842. coerce('marker.color', defaultColor);
  56843. if(hasColorscale(traceIn, 'marker')) {
  56844. colorscaleDefaults(
  56845. traceIn, traceOut, layout, coerce, {prefix: 'marker.', cLetter: 'c'}
  56846. );
  56847. }
  56848. coerce('marker.line.color', Color.defaultLine);
  56849. if(hasColorscale(traceIn, 'marker.line')) {
  56850. colorscaleDefaults(
  56851. traceIn, traceOut, layout, coerce, {prefix: 'marker.line.', cLetter: 'c'}
  56852. );
  56853. }
  56854. coerce('marker.line.width');
  56855. coerce('marker.opacity');
  56856. coerce('selected.marker.color');
  56857. coerce('unselected.marker.color');
  56858. };
  56859. },{"../../components/color":50,"../../components/colorscale/defaults":60,"../../components/colorscale/has_colorscale":64}],282:[function(_dereq_,module,exports){
  56860. /**
  56861. * Copyright 2012-2018, Plotly, Inc.
  56862. * All rights reserved.
  56863. *
  56864. * This source code is licensed under the MIT license found in the
  56865. * LICENSE file in the root directory of this source tree.
  56866. */
  56867. 'use strict';
  56868. var scatterAttrs = _dereq_('../scatter/attributes');
  56869. var colorAttrs = _dereq_('../../components/color/attributes');
  56870. var extendFlat = _dereq_('../../lib/extend').extendFlat;
  56871. var scatterMarkerAttrs = scatterAttrs.marker;
  56872. var scatterMarkerLineAttrs = scatterMarkerAttrs.line;
  56873. module.exports = {
  56874. y: {
  56875. valType: 'data_array',
  56876. editType: 'calc+clearAxisTypes',
  56877. },
  56878. x: {
  56879. valType: 'data_array',
  56880. editType: 'calc+clearAxisTypes',
  56881. },
  56882. x0: {
  56883. valType: 'any',
  56884. editType: 'calc+clearAxisTypes',
  56885. },
  56886. y0: {
  56887. valType: 'any',
  56888. editType: 'calc+clearAxisTypes',
  56889. },
  56890. name: {
  56891. valType: 'string',
  56892. editType: 'calc+clearAxisTypes',
  56893. },
  56894. text: extendFlat({}, scatterAttrs.text, {
  56895. }),
  56896. whiskerwidth: {
  56897. valType: 'number',
  56898. min: 0,
  56899. max: 1,
  56900. dflt: 0.5,
  56901. editType: 'calc',
  56902. },
  56903. notched: {
  56904. valType: 'boolean',
  56905. editType: 'calc',
  56906. },
  56907. notchwidth: {
  56908. valType: 'number',
  56909. min: 0,
  56910. max: 0.5,
  56911. dflt: 0.25,
  56912. editType: 'calc',
  56913. },
  56914. boxpoints: {
  56915. valType: 'enumerated',
  56916. values: ['all', 'outliers', 'suspectedoutliers', false],
  56917. dflt: 'outliers',
  56918. editType: 'calc',
  56919. },
  56920. boxmean: {
  56921. valType: 'enumerated',
  56922. values: [true, 'sd', false],
  56923. dflt: false,
  56924. editType: 'calc',
  56925. },
  56926. jitter: {
  56927. valType: 'number',
  56928. min: 0,
  56929. max: 1,
  56930. editType: 'calc',
  56931. },
  56932. pointpos: {
  56933. valType: 'number',
  56934. min: -2,
  56935. max: 2,
  56936. editType: 'calc',
  56937. },
  56938. orientation: {
  56939. valType: 'enumerated',
  56940. values: ['v', 'h'],
  56941. editType: 'calc+clearAxisTypes',
  56942. },
  56943. marker: {
  56944. outliercolor: {
  56945. valType: 'color',
  56946. dflt: 'rgba(0, 0, 0, 0)',
  56947. editType: 'style',
  56948. },
  56949. symbol: extendFlat({}, scatterMarkerAttrs.symbol,
  56950. {arrayOk: false, editType: 'plot'}),
  56951. opacity: extendFlat({}, scatterMarkerAttrs.opacity,
  56952. {arrayOk: false, dflt: 1, editType: 'style'}),
  56953. size: extendFlat({}, scatterMarkerAttrs.size,
  56954. {arrayOk: false, editType: 'calc'}),
  56955. color: extendFlat({}, scatterMarkerAttrs.color,
  56956. {arrayOk: false, editType: 'style'}),
  56957. line: {
  56958. color: extendFlat({}, scatterMarkerLineAttrs.color,
  56959. {arrayOk: false, dflt: colorAttrs.defaultLine, editType: 'style'}
  56960. ),
  56961. width: extendFlat({}, scatterMarkerLineAttrs.width,
  56962. {arrayOk: false, dflt: 0, editType: 'style'}
  56963. ),
  56964. outliercolor: {
  56965. valType: 'color',
  56966. editType: 'style',
  56967. },
  56968. outlierwidth: {
  56969. valType: 'number',
  56970. min: 0,
  56971. dflt: 1,
  56972. editType: 'style',
  56973. },
  56974. editType: 'style'
  56975. },
  56976. editType: 'plot'
  56977. },
  56978. line: {
  56979. color: {
  56980. valType: 'color',
  56981. editType: 'style',
  56982. },
  56983. width: {
  56984. valType: 'number',
  56985. min: 0,
  56986. dflt: 2,
  56987. editType: 'style',
  56988. },
  56989. editType: 'plot'
  56990. },
  56991. fillcolor: scatterAttrs.fillcolor,
  56992. selected: {
  56993. marker: scatterAttrs.selected.marker,
  56994. editType: 'style'
  56995. },
  56996. unselected: {
  56997. marker: scatterAttrs.unselected.marker,
  56998. editType: 'style'
  56999. },
  57000. hoveron: {
  57001. valType: 'flaglist',
  57002. flags: ['boxes', 'points'],
  57003. dflt: 'boxes+points',
  57004. editType: 'style',
  57005. }
  57006. };
  57007. },{"../../components/color/attributes":49,"../../lib/extend":163,"../scatter/attributes":366}],283:[function(_dereq_,module,exports){
  57008. /**
  57009. * Copyright 2012-2018, Plotly, Inc.
  57010. * All rights reserved.
  57011. *
  57012. * This source code is licensed under the MIT license found in the
  57013. * LICENSE file in the root directory of this source tree.
  57014. */
  57015. 'use strict';
  57016. var isNumeric = _dereq_('fast-isnumeric');
  57017. var Lib = _dereq_('../../lib');
  57018. var _ = Lib._;
  57019. var Axes = _dereq_('../../plots/cartesian/axes');
  57020. // outlier definition based on http://www.physics.csbsju.edu/stats/box2.html
  57021. module.exports = function calc(gd, trace) {
  57022. var fullLayout = gd._fullLayout;
  57023. var xa = Axes.getFromId(gd, trace.xaxis || 'x');
  57024. var ya = Axes.getFromId(gd, trace.yaxis || 'y');
  57025. var cd = [];
  57026. // N.B. violin reuses same Box.calc
  57027. var numKey = trace.type === 'violin' ? '_numViolins' : '_numBoxes';
  57028. var i;
  57029. var valAxis, valLetter;
  57030. var posAxis, posLetter;
  57031. if(trace.orientation === 'h') {
  57032. valAxis = xa;
  57033. valLetter = 'x';
  57034. posAxis = ya;
  57035. posLetter = 'y';
  57036. } else {
  57037. valAxis = ya;
  57038. valLetter = 'y';
  57039. posAxis = xa;
  57040. posLetter = 'x';
  57041. }
  57042. var val = valAxis.makeCalcdata(trace, valLetter);
  57043. var pos = getPos(trace, posLetter, posAxis, val, fullLayout[numKey]);
  57044. var dv = Lib.distinctVals(pos);
  57045. var posDistinct = dv.vals;
  57046. var dPos = dv.minDiff / 2;
  57047. var posBins = makeBins(posDistinct, dPos);
  57048. var pLen = posDistinct.length;
  57049. var ptsPerBin = initNestedArray(pLen);
  57050. // bin pts info per position bins
  57051. for(i = 0; i < trace._length; i++) {
  57052. var v = val[i];
  57053. if(!isNumeric(v)) continue;
  57054. var n = Lib.findBin(pos[i], posBins);
  57055. if(n >= 0 && n < pLen) {
  57056. var pt = {v: v, i: i};
  57057. arraysToCalcdata(pt, trace, i);
  57058. ptsPerBin[n].push(pt);
  57059. }
  57060. }
  57061. // build calcdata trace items, one item per distinct position
  57062. for(i = 0; i < pLen; i++) {
  57063. if(ptsPerBin[i].length > 0) {
  57064. var pts = ptsPerBin[i].sort(sortByVal);
  57065. var boxVals = pts.map(extractVal);
  57066. var bvLen = boxVals.length;
  57067. var cdi = {
  57068. pos: posDistinct[i],
  57069. pts: pts
  57070. };
  57071. cdi.min = boxVals[0];
  57072. cdi.max = boxVals[bvLen - 1];
  57073. cdi.mean = Lib.mean(boxVals, bvLen);
  57074. cdi.sd = Lib.stdev(boxVals, bvLen, cdi.mean);
  57075. // first quartile
  57076. cdi.q1 = Lib.interp(boxVals, 0.25);
  57077. // median
  57078. cdi.med = Lib.interp(boxVals, 0.5);
  57079. // third quartile
  57080. cdi.q3 = Lib.interp(boxVals, 0.75);
  57081. // lower and upper fences - last point inside
  57082. // 1.5 interquartile ranges from quartiles
  57083. cdi.lf = Math.min(
  57084. cdi.q1,
  57085. boxVals[Math.min(
  57086. Lib.findBin(2.5 * cdi.q1 - 1.5 * cdi.q3, boxVals, true) + 1,
  57087. bvLen - 1
  57088. )]
  57089. );
  57090. cdi.uf = Math.max(
  57091. cdi.q3,
  57092. boxVals[Math.max(
  57093. Lib.findBin(2.5 * cdi.q3 - 1.5 * cdi.q1, boxVals),
  57094. 0
  57095. )]
  57096. );
  57097. // lower and upper outliers - 3 IQR out (don't clip to max/min,
  57098. // this is only for discriminating suspected & far outliers)
  57099. cdi.lo = 4 * cdi.q1 - 3 * cdi.q3;
  57100. cdi.uo = 4 * cdi.q3 - 3 * cdi.q1;
  57101. // lower and upper notches ~95% Confidence Intervals for median
  57102. var iqr = cdi.q3 - cdi.q1;
  57103. var mci = 1.57 * iqr / Math.sqrt(bvLen);
  57104. cdi.ln = cdi.med - mci;
  57105. cdi.un = cdi.med + mci;
  57106. cd.push(cdi);
  57107. }
  57108. }
  57109. calcSelection(cd, trace);
  57110. var extremes = Axes.findExtremes(valAxis, val, {padded: true});
  57111. trace._extremes[valAxis._id] = extremes;
  57112. if(cd.length > 0) {
  57113. cd[0].t = {
  57114. num: fullLayout[numKey],
  57115. dPos: dPos,
  57116. posLetter: posLetter,
  57117. valLetter: valLetter,
  57118. labels: {
  57119. med: _(gd, 'median:'),
  57120. min: _(gd, 'min:'),
  57121. q1: _(gd, 'q1:'),
  57122. q3: _(gd, 'q3:'),
  57123. max: _(gd, 'max:'),
  57124. mean: trace.boxmean === 'sd' ? _(gd, 'mean ± σ:') : _(gd, 'mean:'),
  57125. lf: _(gd, 'lower fence:'),
  57126. uf: _(gd, 'upper fence:')
  57127. }
  57128. };
  57129. fullLayout[numKey]++;
  57130. return cd;
  57131. } else {
  57132. return [{t: {empty: true}}];
  57133. }
  57134. };
  57135. // In vertical (horizontal) box plots:
  57136. // if no x (y) data, use x0 (y0), or name
  57137. // so if you want one box
  57138. // per trace, set x0 (y0) to the x (y) value or category for this trace
  57139. // (or set x (y) to a constant array matching y (x))
  57140. function getPos(trace, posLetter, posAxis, val, num) {
  57141. if(posLetter in trace) {
  57142. return posAxis.makeCalcdata(trace, posLetter);
  57143. }
  57144. var pos0;
  57145. if(posLetter + '0' in trace) {
  57146. pos0 = trace[posLetter + '0'];
  57147. } else if('name' in trace && (
  57148. posAxis.type === 'category' || (
  57149. isNumeric(trace.name) &&
  57150. ['linear', 'log'].indexOf(posAxis.type) !== -1
  57151. ) || (
  57152. Lib.isDateTime(trace.name) &&
  57153. posAxis.type === 'date'
  57154. )
  57155. )) {
  57156. pos0 = trace.name;
  57157. } else {
  57158. pos0 = num;
  57159. }
  57160. var pos0c = posAxis.d2c(pos0, 0, trace[posLetter + 'calendar']);
  57161. return val.map(function() { return pos0c; });
  57162. }
  57163. function makeBins(x, dx) {
  57164. var len = x.length;
  57165. var bins = new Array(len + 1);
  57166. for(var i = 0; i < len; i++) {
  57167. bins[i] = x[i] - dx;
  57168. }
  57169. bins[len] = x[len - 1] + dx;
  57170. return bins;
  57171. }
  57172. function initNestedArray(len) {
  57173. var arr = new Array(len);
  57174. for(var i = 0; i < len; i++) {
  57175. arr[i] = [];
  57176. }
  57177. return arr;
  57178. }
  57179. function arraysToCalcdata(pt, trace, i) {
  57180. var trace2calc = {
  57181. text: 'tx'
  57182. };
  57183. for(var k in trace2calc) {
  57184. if(Array.isArray(trace[k])) {
  57185. pt[trace2calc[k]] = trace[k][i];
  57186. }
  57187. }
  57188. }
  57189. function calcSelection(cd, trace) {
  57190. if(Lib.isArrayOrTypedArray(trace.selectedpoints)) {
  57191. for(var i = 0; i < cd.length; i++) {
  57192. var pts = cd[i].pts || [];
  57193. var ptNumber2cdIndex = {};
  57194. for(var j = 0; j < pts.length; j++) {
  57195. ptNumber2cdIndex[pts[j].i] = j;
  57196. }
  57197. Lib.tagSelected(pts, trace, ptNumber2cdIndex);
  57198. }
  57199. }
  57200. }
  57201. function sortByVal(a, b) { return a.v - b.v; }
  57202. function extractVal(o) { return o.v; }
  57203. },{"../../lib":169,"../../plots/cartesian/axes":214,"fast-isnumeric":18}],284:[function(_dereq_,module,exports){
  57204. /**
  57205. * Copyright 2012-2018, Plotly, Inc.
  57206. * All rights reserved.
  57207. *
  57208. * This source code is licensed under the MIT license found in the
  57209. * LICENSE file in the root directory of this source tree.
  57210. */
  57211. 'use strict';
  57212. var Axes = _dereq_('../../plots/cartesian/axes');
  57213. var Lib = _dereq_('../../lib');
  57214. var orientations = ['v', 'h'];
  57215. function crossTraceCalc(gd, plotinfo) {
  57216. var calcdata = gd.calcdata;
  57217. var xa = plotinfo.xaxis;
  57218. var ya = plotinfo.yaxis;
  57219. for(var i = 0; i < orientations.length; i++) {
  57220. var orientation = orientations[i];
  57221. var posAxis = orientation === 'h' ? ya : xa;
  57222. var boxList = [];
  57223. var minPad = 0;
  57224. var maxPad = 0;
  57225. // make list of boxes / candlesticks
  57226. // For backward compatibility, candlesticks are treated as if they *are* box traces here
  57227. for(var j = 0; j < calcdata.length; j++) {
  57228. var cd = calcdata[j];
  57229. var t = cd[0].t;
  57230. var trace = cd[0].trace;
  57231. if(trace.visible === true &&
  57232. (trace.type === 'box' || trace.type === 'candlestick') &&
  57233. !t.empty &&
  57234. (trace.orientation || 'v') === orientation &&
  57235. trace.xaxis === xa._id &&
  57236. trace.yaxis === ya._id
  57237. ) {
  57238. boxList.push(j);
  57239. if(trace.boxpoints) {
  57240. minPad = Math.max(minPad, trace.jitter - trace.pointpos - 1);
  57241. maxPad = Math.max(maxPad, trace.jitter + trace.pointpos - 1);
  57242. }
  57243. }
  57244. }
  57245. setPositionOffset('box', gd, boxList, posAxis, [minPad, maxPad]);
  57246. }
  57247. }
  57248. function setPositionOffset(traceType, gd, boxList, posAxis, pad) {
  57249. var calcdata = gd.calcdata;
  57250. var fullLayout = gd._fullLayout;
  57251. var pointList = [];
  57252. // N.B. reused in violin
  57253. var numKey = traceType === 'violin' ? '_numViolins' : '_numBoxes';
  57254. var i, j, calcTrace;
  57255. // make list of box points
  57256. for(i = 0; i < boxList.length; i++) {
  57257. calcTrace = calcdata[boxList[i]];
  57258. for(j = 0; j < calcTrace.length; j++) {
  57259. pointList.push(calcTrace[j].pos);
  57260. }
  57261. }
  57262. if(!pointList.length) return;
  57263. // box plots - update dPos based on multiple traces
  57264. // and then use for posAxis autorange
  57265. var boxdv = Lib.distinctVals(pointList);
  57266. var dPos = boxdv.minDiff / 2;
  57267. // if there's no duplication of x points,
  57268. // disable 'group' mode by setting counter to 1
  57269. if(pointList.length === boxdv.vals.length) {
  57270. fullLayout[numKey] = 1;
  57271. }
  57272. // check for forced minimum dtick
  57273. Axes.minDtick(posAxis, boxdv.minDiff, boxdv.vals[0], true);
  57274. var gap = fullLayout[traceType + 'gap'];
  57275. var groupgap = fullLayout[traceType + 'groupgap'];
  57276. var padfactor = (1 - gap) * (1 - groupgap) * dPos / fullLayout[numKey];
  57277. // autoscale the x axis - including space for points if they're off the side
  57278. // TODO: this will overdo it if the outermost boxes don't have
  57279. // their points as far out as the other boxes
  57280. var extremes = Axes.findExtremes(posAxis, boxdv.vals, {
  57281. vpadminus: dPos + pad[0] * padfactor,
  57282. vpadplus: dPos + pad[1] * padfactor
  57283. });
  57284. for(i = 0; i < boxList.length; i++) {
  57285. calcTrace = calcdata[boxList[i]];
  57286. // set the width of all boxes
  57287. calcTrace[0].t.dPos = dPos;
  57288. // link extremes to all boxes
  57289. calcTrace[0].trace._extremes[posAxis._id] = extremes;
  57290. }
  57291. }
  57292. module.exports = {
  57293. crossTraceCalc: crossTraceCalc,
  57294. setPositionOffset: setPositionOffset
  57295. };
  57296. },{"../../lib":169,"../../plots/cartesian/axes":214}],285:[function(_dereq_,module,exports){
  57297. /**
  57298. * Copyright 2012-2018, Plotly, Inc.
  57299. * All rights reserved.
  57300. *
  57301. * This source code is licensed under the MIT license found in the
  57302. * LICENSE file in the root directory of this source tree.
  57303. */
  57304. 'use strict';
  57305. var Lib = _dereq_('../../lib');
  57306. var Registry = _dereq_('../../registry');
  57307. var Color = _dereq_('../../components/color');
  57308. var attributes = _dereq_('./attributes');
  57309. function supplyDefaults(traceIn, traceOut, defaultColor, layout) {
  57310. function coerce(attr, dflt) {
  57311. return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);
  57312. }
  57313. handleSampleDefaults(traceIn, traceOut, coerce, layout);
  57314. if(traceOut.visible === false) return;
  57315. coerce('line.color', (traceIn.marker || {}).color || defaultColor);
  57316. coerce('line.width');
  57317. coerce('fillcolor', Color.addOpacity(traceOut.line.color, 0.5));
  57318. coerce('whiskerwidth');
  57319. coerce('boxmean');
  57320. var notched = coerce('notched', traceIn.notchwidth !== undefined);
  57321. if(notched) coerce('notchwidth');
  57322. handlePointsDefaults(traceIn, traceOut, coerce, {prefix: 'box'});
  57323. }
  57324. function handleSampleDefaults(traceIn, traceOut, coerce, layout) {
  57325. var y = coerce('y');
  57326. var x = coerce('x');
  57327. var hasX = x && x.length;
  57328. var defaultOrientation, len;
  57329. if(y && y.length) {
  57330. defaultOrientation = 'v';
  57331. if(hasX) {
  57332. len = Math.min(x.length, y.length);
  57333. }
  57334. else {
  57335. coerce('x0');
  57336. len = y.length;
  57337. }
  57338. } else if(hasX) {
  57339. defaultOrientation = 'h';
  57340. coerce('y0');
  57341. len = x.length;
  57342. } else {
  57343. traceOut.visible = false;
  57344. return;
  57345. }
  57346. traceOut._length = len;
  57347. var handleCalendarDefaults = Registry.getComponentMethod('calendars', 'handleTraceDefaults');
  57348. handleCalendarDefaults(traceIn, traceOut, ['x', 'y'], layout);
  57349. coerce('orientation', defaultOrientation);
  57350. }
  57351. function handlePointsDefaults(traceIn, traceOut, coerce, opts) {
  57352. var prefix = opts.prefix;
  57353. var outlierColorDflt = Lib.coerce2(traceIn, traceOut, attributes, 'marker.outliercolor');
  57354. var lineoutliercolor = coerce('marker.line.outliercolor');
  57355. var points = coerce(
  57356. prefix + 'points',
  57357. (outlierColorDflt || lineoutliercolor) ? 'suspectedoutliers' : undefined
  57358. );
  57359. if(points) {
  57360. coerce('jitter', points === 'all' ? 0.3 : 0);
  57361. coerce('pointpos', points === 'all' ? -1.5 : 0);
  57362. coerce('marker.symbol');
  57363. coerce('marker.opacity');
  57364. coerce('marker.size');
  57365. coerce('marker.color', traceOut.line.color);
  57366. coerce('marker.line.color');
  57367. coerce('marker.line.width');
  57368. if(points === 'suspectedoutliers') {
  57369. coerce('marker.line.outliercolor', traceOut.marker.color);
  57370. coerce('marker.line.outlierwidth');
  57371. }
  57372. coerce('selected.marker.color');
  57373. coerce('unselected.marker.color');
  57374. coerce('selected.marker.size');
  57375. coerce('unselected.marker.size');
  57376. coerce('text');
  57377. } else {
  57378. delete traceOut.marker;
  57379. }
  57380. coerce('hoveron');
  57381. Lib.coerceSelectionMarkerOpacity(traceOut, coerce);
  57382. }
  57383. module.exports = {
  57384. supplyDefaults: supplyDefaults,
  57385. handleSampleDefaults: handleSampleDefaults,
  57386. handlePointsDefaults: handlePointsDefaults
  57387. };
  57388. },{"../../components/color":50,"../../lib":169,"../../registry":259,"./attributes":282}],286:[function(_dereq_,module,exports){
  57389. /**
  57390. * Copyright 2012-2018, Plotly, Inc.
  57391. * All rights reserved.
  57392. *
  57393. * This source code is licensed under the MIT license found in the
  57394. * LICENSE file in the root directory of this source tree.
  57395. */
  57396. 'use strict';
  57397. module.exports = function eventData(out, pt) {
  57398. // Note: hoverOnBox property is needed for click-to-select
  57399. // to ignore when a box was clicked. This is the reason box
  57400. // implements this custom eventData function.
  57401. if(pt.hoverOnBox) out.hoverOnBox = pt.hoverOnBox;
  57402. if('xVal' in pt) out.x = pt.xVal;
  57403. if('yVal' in pt) out.y = pt.yVal;
  57404. if(pt.xa) out.xaxis = pt.xa;
  57405. if(pt.ya) out.yaxis = pt.ya;
  57406. return out;
  57407. };
  57408. },{}],287:[function(_dereq_,module,exports){
  57409. /**
  57410. * Copyright 2012-2018, Plotly, Inc.
  57411. * All rights reserved.
  57412. *
  57413. * This source code is licensed under the MIT license found in the
  57414. * LICENSE file in the root directory of this source tree.
  57415. */
  57416. 'use strict';
  57417. var Axes = _dereq_('../../plots/cartesian/axes');
  57418. var Lib = _dereq_('../../lib');
  57419. var Fx = _dereq_('../../components/fx');
  57420. var Color = _dereq_('../../components/color');
  57421. var fillHoverText = _dereq_('../scatter/fill_hover_text');
  57422. function hoverPoints(pointData, xval, yval, hovermode) {
  57423. var cd = pointData.cd;
  57424. var trace = cd[0].trace;
  57425. var hoveron = trace.hoveron;
  57426. var closeBoxData = [];
  57427. var closePtData;
  57428. if(hoveron.indexOf('boxes') !== -1) {
  57429. closeBoxData = closeBoxData.concat(hoverOnBoxes(pointData, xval, yval, hovermode));
  57430. }
  57431. if(hoveron.indexOf('points') !== -1) {
  57432. closePtData = hoverOnPoints(pointData, xval, yval);
  57433. }
  57434. // If there's a point in range and hoveron has points, show the best single point only.
  57435. // If hoveron has boxes and there's no point in range (or hoveron doesn't have points), show the box stats.
  57436. if(hovermode === 'closest') {
  57437. if(closePtData) return [closePtData];
  57438. return closeBoxData;
  57439. }
  57440. // Otherwise in compare mode, allow a point AND the box stats to be labeled
  57441. // If there are multiple boxes in range (ie boxmode = 'overlay') we'll see stats for all of them.
  57442. if(closePtData) {
  57443. closeBoxData.push(closePtData);
  57444. return closeBoxData;
  57445. }
  57446. return closeBoxData;
  57447. }
  57448. function hoverOnBoxes(pointData, xval, yval, hovermode) {
  57449. var cd = pointData.cd;
  57450. var xa = pointData.xa;
  57451. var ya = pointData.ya;
  57452. var trace = cd[0].trace;
  57453. var t = cd[0].t;
  57454. var isViolin = trace.type === 'violin';
  57455. var closeBoxData = [];
  57456. var pLetter, vLetter, pAxis, vAxis, vVal, pVal, dx, dy, dPos,
  57457. hoverPseudoDistance, spikePseudoDistance;
  57458. var boxDelta = t.bdPos;
  57459. var posAcceptance = t.wHover;
  57460. var shiftPos = function(di) { return di.pos + t.bPos - pVal; };
  57461. if(isViolin && trace.side !== 'both') {
  57462. if(trace.side === 'positive') {
  57463. dPos = function(di) {
  57464. var pos = shiftPos(di);
  57465. return Fx.inbox(pos, pos + posAcceptance, hoverPseudoDistance);
  57466. };
  57467. }
  57468. if(trace.side === 'negative') {
  57469. dPos = function(di) {
  57470. var pos = shiftPos(di);
  57471. return Fx.inbox(pos - posAcceptance, pos, hoverPseudoDistance);
  57472. };
  57473. }
  57474. } else {
  57475. dPos = function(di) {
  57476. var pos = shiftPos(di);
  57477. return Fx.inbox(pos - posAcceptance, pos + posAcceptance, hoverPseudoDistance);
  57478. };
  57479. }
  57480. var dVal;
  57481. if(isViolin) {
  57482. dVal = function(di) {
  57483. return Fx.inbox(di.span[0] - vVal, di.span[1] - vVal, hoverPseudoDistance);
  57484. };
  57485. } else {
  57486. dVal = function(di) {
  57487. return Fx.inbox(di.min - vVal, di.max - vVal, hoverPseudoDistance);
  57488. };
  57489. }
  57490. if(trace.orientation === 'h') {
  57491. vVal = xval;
  57492. pVal = yval;
  57493. dx = dVal;
  57494. dy = dPos;
  57495. pLetter = 'y';
  57496. pAxis = ya;
  57497. vLetter = 'x';
  57498. vAxis = xa;
  57499. } else {
  57500. vVal = yval;
  57501. pVal = xval;
  57502. dx = dPos;
  57503. dy = dVal;
  57504. pLetter = 'x';
  57505. pAxis = xa;
  57506. vLetter = 'y';
  57507. vAxis = ya;
  57508. }
  57509. // if two boxes are overlaying, let the narrowest one win
  57510. var pseudoDistance = Math.min(1, boxDelta / Math.abs(pAxis.r2c(pAxis.range[1]) - pAxis.r2c(pAxis.range[0])));
  57511. hoverPseudoDistance = pointData.maxHoverDistance - pseudoDistance;
  57512. spikePseudoDistance = pointData.maxSpikeDistance - pseudoDistance;
  57513. function dxy(di) { return (dx(di) + dy(di)) / 2; }
  57514. var distfn = Fx.getDistanceFunction(hovermode, dx, dy, dxy);
  57515. Fx.getClosest(cd, distfn, pointData);
  57516. // skip the rest (for this trace) if we didn't find a close point
  57517. // and create the item(s) in closedata for this point
  57518. if(pointData.index === false) return [];
  57519. var di = cd[pointData.index];
  57520. var lc = trace.line.color;
  57521. var mc = (trace.marker || {}).color;
  57522. if(Color.opacity(lc) && trace.line.width) pointData.color = lc;
  57523. else if(Color.opacity(mc) && trace.boxpoints) pointData.color = mc;
  57524. else pointData.color = trace.fillcolor;
  57525. pointData[pLetter + '0'] = pAxis.c2p(di.pos + t.bPos - boxDelta, true);
  57526. pointData[pLetter + '1'] = pAxis.c2p(di.pos + t.bPos + boxDelta, true);
  57527. pointData[pLetter + 'LabelVal'] = di.pos;
  57528. var spikePosAttr = pLetter + 'Spike';
  57529. pointData.spikeDistance = dxy(di) * spikePseudoDistance / hoverPseudoDistance;
  57530. pointData[spikePosAttr] = pAxis.c2p(di.pos, true);
  57531. // box plots: each "point" gets many labels
  57532. var usedVals = {};
  57533. var attrs = ['med', 'min', 'q1', 'q3', 'max'];
  57534. if(trace.boxmean || (trace.meanline || {}).visible) {
  57535. attrs.push('mean');
  57536. }
  57537. if(trace.boxpoints || trace.points) {
  57538. attrs.push('lf', 'uf');
  57539. }
  57540. for(var i = 0; i < attrs.length; i++) {
  57541. var attr = attrs[i];
  57542. if(!(attr in di) || (di[attr] in usedVals)) continue;
  57543. usedVals[di[attr]] = true;
  57544. // copy out to a new object for each value to label
  57545. var val = di[attr];
  57546. var valPx = vAxis.c2p(val, true);
  57547. var pointData2 = Lib.extendFlat({}, pointData);
  57548. pointData2[vLetter + '0'] = pointData2[vLetter + '1'] = valPx;
  57549. pointData2[vLetter + 'LabelVal'] = val;
  57550. pointData2[vLetter + 'Label'] = (t.labels ? t.labels[attr] + ' ' : '') + Axes.hoverLabelText(vAxis, val);
  57551. // Note: introduced to be able to distinguish a
  57552. // clicked point from a box during click-to-select
  57553. pointData2.hoverOnBox = true;
  57554. if(attr === 'mean' && ('sd' in di) && trace.boxmean === 'sd') {
  57555. pointData2[vLetter + 'err'] = di.sd;
  57556. }
  57557. // only keep name and spikes on the first item (median)
  57558. pointData.name = '';
  57559. pointData.spikeDistance = undefined;
  57560. pointData[spikePosAttr] = undefined;
  57561. closeBoxData.push(pointData2);
  57562. }
  57563. return closeBoxData;
  57564. }
  57565. function hoverOnPoints(pointData, xval, yval) {
  57566. var cd = pointData.cd;
  57567. var xa = pointData.xa;
  57568. var ya = pointData.ya;
  57569. var trace = cd[0].trace;
  57570. var xPx = xa.c2p(xval);
  57571. var yPx = ya.c2p(yval);
  57572. var closePtData;
  57573. var dx = function(di) {
  57574. var rad = Math.max(3, di.mrc || 0);
  57575. return Math.max(Math.abs(xa.c2p(di.x) - xPx) - rad, 1 - 3 / rad);
  57576. };
  57577. var dy = function(di) {
  57578. var rad = Math.max(3, di.mrc || 0);
  57579. return Math.max(Math.abs(ya.c2p(di.y) - yPx) - rad, 1 - 3 / rad);
  57580. };
  57581. var distfn = Fx.quadrature(dx, dy);
  57582. // show one point per trace
  57583. var ijClosest = false;
  57584. var di, pt;
  57585. for(var i = 0; i < cd.length; i++) {
  57586. di = cd[i];
  57587. for(var j = 0; j < (di.pts || []).length; j++) {
  57588. pt = di.pts[j];
  57589. var newDistance = distfn(pt);
  57590. if(newDistance <= pointData.distance) {
  57591. pointData.distance = newDistance;
  57592. ijClosest = [i, j];
  57593. }
  57594. }
  57595. }
  57596. if(!ijClosest) return false;
  57597. di = cd[ijClosest[0]];
  57598. pt = di.pts[ijClosest[1]];
  57599. var xc = xa.c2p(pt.x, true);
  57600. var yc = ya.c2p(pt.y, true);
  57601. var rad = pt.mrc || 1;
  57602. closePtData = Lib.extendFlat({}, pointData, {
  57603. // corresponds to index in x/y input data array
  57604. index: pt.i,
  57605. color: (trace.marker || {}).color,
  57606. name: trace.name,
  57607. x0: xc - rad,
  57608. x1: xc + rad,
  57609. xLabelVal: pt.x,
  57610. y0: yc - rad,
  57611. y1: yc + rad,
  57612. yLabelVal: pt.y,
  57613. spikeDistance: pointData.distance
  57614. });
  57615. var pLetter = trace.orientation === 'h' ? 'y' : 'x';
  57616. var pa = trace.orientation === 'h' ? ya : xa;
  57617. closePtData[pLetter + 'Spike'] = pa.c2p(di.pos, true);
  57618. fillHoverText(pt, trace, closePtData);
  57619. return closePtData;
  57620. }
  57621. module.exports = {
  57622. hoverPoints: hoverPoints,
  57623. hoverOnBoxes: hoverOnBoxes,
  57624. hoverOnPoints: hoverOnPoints
  57625. };
  57626. },{"../../components/color":50,"../../components/fx":92,"../../lib":169,"../../plots/cartesian/axes":214,"../scatter/fill_hover_text":374}],288:[function(_dereq_,module,exports){
  57627. /**
  57628. * Copyright 2012-2018, Plotly, Inc.
  57629. * All rights reserved.
  57630. *
  57631. * This source code is licensed under the MIT license found in the
  57632. * LICENSE file in the root directory of this source tree.
  57633. */
  57634. 'use strict';
  57635. var Box = {};
  57636. Box.attributes = _dereq_('./attributes');
  57637. Box.layoutAttributes = _dereq_('./layout_attributes');
  57638. Box.supplyDefaults = _dereq_('./defaults').supplyDefaults;
  57639. Box.supplyLayoutDefaults = _dereq_('./layout_defaults').supplyLayoutDefaults;
  57640. Box.calc = _dereq_('./calc');
  57641. Box.crossTraceCalc = _dereq_('./cross_trace_calc').crossTraceCalc;
  57642. Box.plot = _dereq_('./plot').plot;
  57643. Box.style = _dereq_('./style').style;
  57644. Box.styleOnSelect = _dereq_('./style').styleOnSelect;
  57645. Box.hoverPoints = _dereq_('./hover').hoverPoints;
  57646. Box.eventData = _dereq_('./event_data');
  57647. Box.selectPoints = _dereq_('./select');
  57648. Box.moduleType = 'trace';
  57649. Box.name = 'box';
  57650. Box.basePlotModule = _dereq_('../../plots/cartesian');
  57651. Box.categories = ['cartesian', 'svg', 'symbols', 'oriented', 'box-violin', 'showLegend', 'boxLayout', 'zoomScale'];
  57652. Box.meta = {
  57653. };
  57654. module.exports = Box;
  57655. },{"../../plots/cartesian":225,"./attributes":282,"./calc":283,"./cross_trace_calc":284,"./defaults":285,"./event_data":286,"./hover":287,"./layout_attributes":289,"./layout_defaults":290,"./plot":291,"./select":292,"./style":293}],289:[function(_dereq_,module,exports){
  57656. /**
  57657. * Copyright 2012-2018, Plotly, Inc.
  57658. * All rights reserved.
  57659. *
  57660. * This source code is licensed under the MIT license found in the
  57661. * LICENSE file in the root directory of this source tree.
  57662. */
  57663. 'use strict';
  57664. module.exports = {
  57665. boxmode: {
  57666. valType: 'enumerated',
  57667. values: ['group', 'overlay'],
  57668. dflt: 'overlay',
  57669. editType: 'calc',
  57670. },
  57671. boxgap: {
  57672. valType: 'number',
  57673. min: 0,
  57674. max: 1,
  57675. dflt: 0.3,
  57676. editType: 'calc',
  57677. },
  57678. boxgroupgap: {
  57679. valType: 'number',
  57680. min: 0,
  57681. max: 1,
  57682. dflt: 0.3,
  57683. editType: 'calc',
  57684. }
  57685. };
  57686. },{}],290:[function(_dereq_,module,exports){
  57687. /**
  57688. * Copyright 2012-2018, Plotly, Inc.
  57689. * All rights reserved.
  57690. *
  57691. * This source code is licensed under the MIT license found in the
  57692. * LICENSE file in the root directory of this source tree.
  57693. */
  57694. 'use strict';
  57695. var Registry = _dereq_('../../registry');
  57696. var Lib = _dereq_('../../lib');
  57697. var layoutAttributes = _dereq_('./layout_attributes');
  57698. function _supply(layoutIn, layoutOut, fullData, coerce, traceType) {
  57699. var hasTraceType;
  57700. var category = traceType + 'Layout';
  57701. for(var i = 0; i < fullData.length; i++) {
  57702. if(Registry.traceIs(fullData[i], category)) {
  57703. hasTraceType = true;
  57704. break;
  57705. }
  57706. }
  57707. if(!hasTraceType) return;
  57708. coerce(traceType + 'mode');
  57709. coerce(traceType + 'gap');
  57710. coerce(traceType + 'groupgap');
  57711. }
  57712. function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {
  57713. function coerce(attr, dflt) {
  57714. return Lib.coerce(layoutIn, layoutOut, layoutAttributes, attr, dflt);
  57715. }
  57716. _supply(layoutIn, layoutOut, fullData, coerce, 'box');
  57717. }
  57718. module.exports = {
  57719. supplyLayoutDefaults: supplyLayoutDefaults,
  57720. _supply: _supply
  57721. };
  57722. },{"../../lib":169,"../../registry":259,"./layout_attributes":289}],291:[function(_dereq_,module,exports){
  57723. /**
  57724. * Copyright 2012-2018, Plotly, Inc.
  57725. * All rights reserved.
  57726. *
  57727. * This source code is licensed under the MIT license found in the
  57728. * LICENSE file in the root directory of this source tree.
  57729. */
  57730. 'use strict';
  57731. var d3 = _dereq_('d3');
  57732. var Lib = _dereq_('../../lib');
  57733. var Drawing = _dereq_('../../components/drawing');
  57734. // constants for dynamic jitter (ie less jitter for sparser points)
  57735. var JITTERCOUNT = 5; // points either side of this to include
  57736. var JITTERSPREAD = 0.01; // fraction of IQR to count as "dense"
  57737. function plot(gd, plotinfo, cdbox, boxLayer) {
  57738. var fullLayout = gd._fullLayout;
  57739. var xa = plotinfo.xaxis;
  57740. var ya = plotinfo.yaxis;
  57741. var numBoxes = fullLayout._numBoxes;
  57742. var groupFraction = (1 - fullLayout.boxgap);
  57743. var group = (fullLayout.boxmode === 'group' && numBoxes > 1);
  57744. Lib.makeTraceGroups(boxLayer, cdbox, 'trace boxes').each(function(cd) {
  57745. var plotGroup = d3.select(this);
  57746. var cd0 = cd[0];
  57747. var t = cd0.t;
  57748. var trace = cd0.trace;
  57749. if(!plotinfo.isRangePlot) cd0.node3 = plotGroup;
  57750. // box half width
  57751. var bdPos = t.dPos * groupFraction * (1 - fullLayout.boxgroupgap) / (group ? numBoxes : 1);
  57752. // box center offset
  57753. var bPos = group ? 2 * t.dPos * (-0.5 + (t.num + 0.5) / numBoxes) * groupFraction : 0;
  57754. // whisker width
  57755. var wdPos = bdPos * trace.whiskerwidth;
  57756. if(trace.visible !== true || t.empty) {
  57757. plotGroup.remove();
  57758. return;
  57759. }
  57760. var posAxis, valAxis;
  57761. if(trace.orientation === 'h') {
  57762. posAxis = ya;
  57763. valAxis = xa;
  57764. } else {
  57765. posAxis = xa;
  57766. valAxis = ya;
  57767. }
  57768. // save the box size and box position for use by hover
  57769. t.bPos = bPos;
  57770. t.bdPos = bdPos;
  57771. t.wdPos = wdPos;
  57772. // half-width within which to accept hover for this box
  57773. // always split the distance to the closest box
  57774. t.wHover = t.dPos * (group ? groupFraction / numBoxes : 1);
  57775. plotBoxAndWhiskers(plotGroup, {pos: posAxis, val: valAxis}, trace, t);
  57776. plotPoints(plotGroup, {x: xa, y: ya}, trace, t);
  57777. plotBoxMean(plotGroup, {pos: posAxis, val: valAxis}, trace, t);
  57778. });
  57779. }
  57780. function plotBoxAndWhiskers(sel, axes, trace, t) {
  57781. var posAxis = axes.pos;
  57782. var valAxis = axes.val;
  57783. var bPos = t.bPos;
  57784. var wdPos = t.wdPos || 0;
  57785. var bPosPxOffset = t.bPosPxOffset || 0;
  57786. var whiskerWidth = trace.whiskerwidth || 0;
  57787. var notched = trace.notched || false;
  57788. var nw = notched ? 1 - 2 * trace.notchwidth : 1;
  57789. // to support for one-sided box
  57790. var bdPos0;
  57791. var bdPos1;
  57792. if(Array.isArray(t.bdPos)) {
  57793. bdPos0 = t.bdPos[0];
  57794. bdPos1 = t.bdPos[1];
  57795. } else {
  57796. bdPos0 = t.bdPos;
  57797. bdPos1 = t.bdPos;
  57798. }
  57799. var paths = sel.selectAll('path.box').data((
  57800. trace.type !== 'violin' ||
  57801. trace.box.visible
  57802. ) ? Lib.identity : []);
  57803. paths.enter().append('path')
  57804. .style('vector-effect', 'non-scaling-stroke')
  57805. .attr('class', 'box');
  57806. paths.exit().remove();
  57807. paths.each(function(d) {
  57808. var pos = d.pos;
  57809. var posc = posAxis.c2p(pos + bPos, true) + bPosPxOffset;
  57810. var pos0 = posAxis.c2p(pos + bPos - bdPos0, true) + bPosPxOffset;
  57811. var pos1 = posAxis.c2p(pos + bPos + bdPos1, true) + bPosPxOffset;
  57812. var posw0 = posAxis.c2p(pos + bPos - wdPos, true) + bPosPxOffset;
  57813. var posw1 = posAxis.c2p(pos + bPos + wdPos, true) + bPosPxOffset;
  57814. var posm0 = posAxis.c2p(pos + bPos - bdPos0 * nw, true) + bPosPxOffset;
  57815. var posm1 = posAxis.c2p(pos + bPos + bdPos1 * nw, true) + bPosPxOffset;
  57816. var q1 = valAxis.c2p(d.q1, true);
  57817. var q3 = valAxis.c2p(d.q3, true);
  57818. // make sure median isn't identical to either of the
  57819. // quartiles, so we can see it
  57820. var m = Lib.constrain(
  57821. valAxis.c2p(d.med, true),
  57822. Math.min(q1, q3) + 1, Math.max(q1, q3) - 1
  57823. );
  57824. // for compatibility with box, violin, and candlestick
  57825. // perhaps we should put this into cd0.t instead so it's more explicit,
  57826. // but what we have now is:
  57827. // - box always has d.lf, but boxpoints can be anything
  57828. // - violin has d.lf and should always use it (boxpoints is undefined)
  57829. // - candlestick has only min/max
  57830. var useExtremes = (d.lf === undefined) || (trace.boxpoints === false);
  57831. var lf = valAxis.c2p(useExtremes ? d.min : d.lf, true);
  57832. var uf = valAxis.c2p(useExtremes ? d.max : d.uf, true);
  57833. var ln = valAxis.c2p(d.ln, true);
  57834. var un = valAxis.c2p(d.un, true);
  57835. if(trace.orientation === 'h') {
  57836. d3.select(this).attr('d',
  57837. 'M' + m + ',' + posm0 + 'V' + posm1 + // median line
  57838. 'M' + q1 + ',' + pos0 + 'V' + pos1 + // left edge
  57839. (notched ? 'H' + ln + 'L' + m + ',' + posm1 + 'L' + un + ',' + pos1 : '') + // top notched edge
  57840. 'H' + q3 + // end of the top edge
  57841. 'V' + pos0 + // right edge
  57842. (notched ? 'H' + un + 'L' + m + ',' + posm0 + 'L' + ln + ',' + pos0 : '') + // bottom notched edge
  57843. 'Z' + // end of the box
  57844. 'M' + q1 + ',' + posc + 'H' + lf + 'M' + q3 + ',' + posc + 'H' + uf + // whiskers
  57845. ((whiskerWidth === 0) ? '' : // whisker caps
  57846. 'M' + lf + ',' + posw0 + 'V' + posw1 + 'M' + uf + ',' + posw0 + 'V' + posw1));
  57847. } else {
  57848. d3.select(this).attr('d',
  57849. 'M' + posm0 + ',' + m + 'H' + posm1 + // median line
  57850. 'M' + pos0 + ',' + q1 + 'H' + pos1 + // top of the box
  57851. (notched ? 'V' + ln + 'L' + posm1 + ',' + m + 'L' + pos1 + ',' + un : '') + // notched right edge
  57852. 'V' + q3 + // end of the right edge
  57853. 'H' + pos0 + // bottom of the box
  57854. (notched ? 'V' + un + 'L' + posm0 + ',' + m + 'L' + pos0 + ',' + ln : '') + // notched left edge
  57855. 'Z' + // end of the box
  57856. 'M' + posc + ',' + q1 + 'V' + lf + 'M' + posc + ',' + q3 + 'V' + uf + // whiskers
  57857. ((whiskerWidth === 0) ? '' : // whisker caps
  57858. 'M' + posw0 + ',' + lf + 'H' + posw1 + 'M' + posw0 + ',' + uf + 'H' + posw1));
  57859. }
  57860. });
  57861. }
  57862. function plotPoints(sel, axes, trace, t) {
  57863. var xa = axes.x;
  57864. var ya = axes.y;
  57865. var bdPos = t.bdPos;
  57866. var bPos = t.bPos;
  57867. // to support violin points
  57868. var mode = trace.boxpoints || trace.points;
  57869. // repeatable pseudo-random number generator
  57870. Lib.seedPseudoRandom();
  57871. // since box plot points get an extra level of nesting, each
  57872. // box needs the trace styling info
  57873. var fn = function(d) {
  57874. d.forEach(function(v) {
  57875. v.t = t;
  57876. v.trace = trace;
  57877. });
  57878. return d;
  57879. };
  57880. var gPoints = sel.selectAll('g.points')
  57881. .data(mode ? fn : []);
  57882. gPoints.enter().append('g')
  57883. .attr('class', 'points');
  57884. gPoints.exit().remove();
  57885. var paths = gPoints.selectAll('path')
  57886. .data(function(d) {
  57887. var i;
  57888. var pts = mode === 'all' ?
  57889. d.pts :
  57890. d.pts.filter(function(pt) { return (pt.v < d.lf || pt.v > d.uf); });
  57891. // normally use IQR, but if this is 0 or too small, use max-min
  57892. var typicalSpread = Math.max((d.max - d.min) / 10, d.q3 - d.q1);
  57893. var minSpread = typicalSpread * 1e-9;
  57894. var spreadLimit = typicalSpread * JITTERSPREAD;
  57895. var jitterFactors = [];
  57896. var maxJitterFactor = 0;
  57897. var newJitter;
  57898. // dynamic jitter
  57899. if(trace.jitter) {
  57900. if(typicalSpread === 0) {
  57901. // edge case of no spread at all: fall back to max jitter
  57902. maxJitterFactor = 1;
  57903. jitterFactors = new Array(pts.length);
  57904. for(i = 0; i < pts.length; i++) {
  57905. jitterFactors[i] = 1;
  57906. }
  57907. } else {
  57908. for(i = 0; i < pts.length; i++) {
  57909. var i0 = Math.max(0, i - JITTERCOUNT);
  57910. var pmin = pts[i0].v;
  57911. var i1 = Math.min(pts.length - 1, i + JITTERCOUNT);
  57912. var pmax = pts[i1].v;
  57913. if(mode !== 'all') {
  57914. if(pts[i].v < d.lf) pmax = Math.min(pmax, d.lf);
  57915. else pmin = Math.max(pmin, d.uf);
  57916. }
  57917. var jitterFactor = Math.sqrt(spreadLimit * (i1 - i0) / (pmax - pmin + minSpread)) || 0;
  57918. jitterFactor = Lib.constrain(Math.abs(jitterFactor), 0, 1);
  57919. jitterFactors.push(jitterFactor);
  57920. maxJitterFactor = Math.max(jitterFactor, maxJitterFactor);
  57921. }
  57922. }
  57923. newJitter = trace.jitter * 2 / (maxJitterFactor || 1);
  57924. }
  57925. // fills in 'x' and 'y' in calcdata 'pts' item
  57926. for(i = 0; i < pts.length; i++) {
  57927. var pt = pts[i];
  57928. var v = pt.v;
  57929. var jitterOffset = trace.jitter ?
  57930. (newJitter * jitterFactors[i] * (Lib.pseudoRandom() - 0.5)) :
  57931. 0;
  57932. var posPx = d.pos + bPos + bdPos * (trace.pointpos + jitterOffset);
  57933. if(trace.orientation === 'h') {
  57934. pt.y = posPx;
  57935. pt.x = v;
  57936. } else {
  57937. pt.x = posPx;
  57938. pt.y = v;
  57939. }
  57940. // tag suspected outliers
  57941. if(mode === 'suspectedoutliers' && v < d.uo && v > d.lo) {
  57942. pt.so = true;
  57943. }
  57944. }
  57945. return pts;
  57946. });
  57947. paths.enter().append('path')
  57948. .classed('point', true);
  57949. paths.exit().remove();
  57950. paths.call(Drawing.translatePoints, xa, ya);
  57951. }
  57952. function plotBoxMean(sel, axes, trace, t) {
  57953. var posAxis = axes.pos;
  57954. var valAxis = axes.val;
  57955. var bPos = t.bPos;
  57956. var bPosPxOffset = t.bPosPxOffset || 0;
  57957. // to support violin mean lines
  57958. var mode = trace.boxmean || (trace.meanline || {}).visible;
  57959. // to support for one-sided box
  57960. var bdPos0;
  57961. var bdPos1;
  57962. if(Array.isArray(t.bdPos)) {
  57963. bdPos0 = t.bdPos[0];
  57964. bdPos1 = t.bdPos[1];
  57965. } else {
  57966. bdPos0 = t.bdPos;
  57967. bdPos1 = t.bdPos;
  57968. }
  57969. var paths = sel.selectAll('path.mean').data((
  57970. (trace.type === 'box' && trace.boxmean) ||
  57971. (trace.type === 'violin' && trace.box.visible && trace.meanline.visible)
  57972. ) ? Lib.identity : []);
  57973. paths.enter().append('path')
  57974. .attr('class', 'mean')
  57975. .style({
  57976. fill: 'none',
  57977. 'vector-effect': 'non-scaling-stroke'
  57978. });
  57979. paths.exit().remove();
  57980. paths.each(function(d) {
  57981. var posc = posAxis.c2p(d.pos + bPos, true) + bPosPxOffset;
  57982. var pos0 = posAxis.c2p(d.pos + bPos - bdPos0, true) + bPosPxOffset;
  57983. var pos1 = posAxis.c2p(d.pos + bPos + bdPos1, true) + bPosPxOffset;
  57984. var m = valAxis.c2p(d.mean, true);
  57985. var sl = valAxis.c2p(d.mean - d.sd, true);
  57986. var sh = valAxis.c2p(d.mean + d.sd, true);
  57987. if(trace.orientation === 'h') {
  57988. d3.select(this).attr('d',
  57989. 'M' + m + ',' + pos0 + 'V' + pos1 +
  57990. (mode === 'sd' ?
  57991. 'm0,0L' + sl + ',' + posc + 'L' + m + ',' + pos0 + 'L' + sh + ',' + posc + 'Z' :
  57992. '')
  57993. );
  57994. } else {
  57995. d3.select(this).attr('d',
  57996. 'M' + pos0 + ',' + m + 'H' + pos1 +
  57997. (mode === 'sd' ?
  57998. 'm0,0L' + posc + ',' + sl + 'L' + pos0 + ',' + m + 'L' + posc + ',' + sh + 'Z' :
  57999. '')
  58000. );
  58001. }
  58002. });
  58003. }
  58004. module.exports = {
  58005. plot: plot,
  58006. plotBoxAndWhiskers: plotBoxAndWhiskers,
  58007. plotPoints: plotPoints,
  58008. plotBoxMean: plotBoxMean
  58009. };
  58010. },{"../../components/drawing":75,"../../lib":169,"d3":16}],292:[function(_dereq_,module,exports){
  58011. /**
  58012. * Copyright 2012-2018, Plotly, Inc.
  58013. * All rights reserved.
  58014. *
  58015. * This source code is licensed under the MIT license found in the
  58016. * LICENSE file in the root directory of this source tree.
  58017. */
  58018. 'use strict';
  58019. module.exports = function selectPoints(searchInfo, selectionTester) {
  58020. var cd = searchInfo.cd;
  58021. var xa = searchInfo.xaxis;
  58022. var ya = searchInfo.yaxis;
  58023. var selection = [];
  58024. var i, j;
  58025. if(selectionTester === false) {
  58026. for(i = 0; i < cd.length; i++) {
  58027. for(j = 0; j < (cd[i].pts || []).length; j++) {
  58028. // clear selection
  58029. cd[i].pts[j].selected = 0;
  58030. }
  58031. }
  58032. } else {
  58033. for(i = 0; i < cd.length; i++) {
  58034. for(j = 0; j < (cd[i].pts || []).length; j++) {
  58035. var pt = cd[i].pts[j];
  58036. var x = xa.c2p(pt.x);
  58037. var y = ya.c2p(pt.y);
  58038. if(selectionTester.contains([x, y], null, pt.i, searchInfo)) {
  58039. selection.push({
  58040. pointNumber: pt.i,
  58041. x: xa.c2d(pt.x),
  58042. y: ya.c2d(pt.y)
  58043. });
  58044. pt.selected = 1;
  58045. } else {
  58046. pt.selected = 0;
  58047. }
  58048. }
  58049. }
  58050. }
  58051. return selection;
  58052. };
  58053. },{}],293:[function(_dereq_,module,exports){
  58054. /**
  58055. * Copyright 2012-2018, Plotly, Inc.
  58056. * All rights reserved.
  58057. *
  58058. * This source code is licensed under the MIT license found in the
  58059. * LICENSE file in the root directory of this source tree.
  58060. */
  58061. 'use strict';
  58062. var d3 = _dereq_('d3');
  58063. var Color = _dereq_('../../components/color');
  58064. var Drawing = _dereq_('../../components/drawing');
  58065. function style(gd, cd) {
  58066. var s = cd ? cd[0].node3 : d3.select(gd).selectAll('g.trace.boxes');
  58067. s.style('opacity', function(d) { return d[0].trace.opacity; });
  58068. s.each(function(d) {
  58069. var el = d3.select(this);
  58070. var trace = d[0].trace;
  58071. var lineWidth = trace.line.width;
  58072. function styleBox(boxSel, lineWidth, lineColor, fillColor) {
  58073. boxSel.style('stroke-width', lineWidth + 'px')
  58074. .call(Color.stroke, lineColor)
  58075. .call(Color.fill, fillColor);
  58076. }
  58077. var allBoxes = el.selectAll('path.box');
  58078. if(trace.type === 'candlestick') {
  58079. allBoxes.each(function(boxData) {
  58080. var thisBox = d3.select(this);
  58081. var container = trace[boxData.dir]; // dir = 'increasing' or 'decreasing'
  58082. styleBox(thisBox, container.line.width, container.line.color, container.fillcolor);
  58083. // TODO: custom selection style for candlesticks
  58084. thisBox.style('opacity', trace.selectedpoints && !boxData.selected ? 0.3 : 1);
  58085. });
  58086. }
  58087. else {
  58088. styleBox(allBoxes, lineWidth, trace.line.color, trace.fillcolor);
  58089. el.selectAll('path.mean')
  58090. .style({
  58091. 'stroke-width': lineWidth,
  58092. 'stroke-dasharray': (2 * lineWidth) + 'px,' + lineWidth + 'px'
  58093. })
  58094. .call(Color.stroke, trace.line.color);
  58095. var pts = el.selectAll('path.point');
  58096. Drawing.pointStyle(pts, trace, gd);
  58097. }
  58098. });
  58099. }
  58100. function styleOnSelect(gd, cd) {
  58101. var s = cd[0].node3;
  58102. var trace = cd[0].trace;
  58103. var pts = s.selectAll('path.point');
  58104. if(trace.selectedpoints) {
  58105. Drawing.selectedPointStyle(pts, trace);
  58106. } else {
  58107. Drawing.pointStyle(pts, trace, gd);
  58108. }
  58109. }
  58110. module.exports = {
  58111. style: style,
  58112. styleOnSelect: styleOnSelect
  58113. };
  58114. },{"../../components/color":50,"../../components/drawing":75,"d3":16}],294:[function(_dereq_,module,exports){
  58115. /**
  58116. * Copyright 2012-2018, Plotly, Inc.
  58117. * All rights reserved.
  58118. *
  58119. * This source code is licensed under the MIT license found in the
  58120. * LICENSE file in the root directory of this source tree.
  58121. */
  58122. 'use strict';
  58123. var heatmapAttrs = _dereq_('../heatmap/attributes');
  58124. var scatterAttrs = _dereq_('../scatter/attributes');
  58125. var colorscaleAttrs = _dereq_('../../components/colorscale/attributes');
  58126. var colorbarAttrs = _dereq_('../../components/colorbar/attributes');
  58127. var dash = _dereq_('../../components/drawing/attributes').dash;
  58128. var fontAttrs = _dereq_('../../plots/font_attributes');
  58129. var extendFlat = _dereq_('../../lib/extend').extendFlat;
  58130. var filterOps = _dereq_('../../constants/filter_ops');
  58131. var COMPARISON_OPS2 = filterOps.COMPARISON_OPS2;
  58132. var INTERVAL_OPS = filterOps.INTERVAL_OPS;
  58133. var scatterLineAttrs = scatterAttrs.line;
  58134. module.exports = extendFlat({
  58135. z: heatmapAttrs.z,
  58136. x: heatmapAttrs.x,
  58137. x0: heatmapAttrs.x0,
  58138. dx: heatmapAttrs.dx,
  58139. y: heatmapAttrs.y,
  58140. y0: heatmapAttrs.y0,
  58141. dy: heatmapAttrs.dy,
  58142. text: heatmapAttrs.text,
  58143. transpose: heatmapAttrs.transpose,
  58144. xtype: heatmapAttrs.xtype,
  58145. ytype: heatmapAttrs.ytype,
  58146. zhoverformat: heatmapAttrs.zhoverformat,
  58147. connectgaps: heatmapAttrs.connectgaps,
  58148. fillcolor: {
  58149. valType: 'color',
  58150. editType: 'calc',
  58151. },
  58152. autocontour: {
  58153. valType: 'boolean',
  58154. dflt: true,
  58155. editType: 'calc',
  58156. impliedEdits: {
  58157. 'contours.start': undefined,
  58158. 'contours.end': undefined,
  58159. 'contours.size': undefined
  58160. },
  58161. },
  58162. ncontours: {
  58163. valType: 'integer',
  58164. dflt: 15,
  58165. min: 1,
  58166. editType: 'calc',
  58167. },
  58168. contours: {
  58169. type: {
  58170. valType: 'enumerated',
  58171. values: ['levels', 'constraint'],
  58172. dflt: 'levels',
  58173. editType: 'calc',
  58174. },
  58175. start: {
  58176. valType: 'number',
  58177. dflt: null,
  58178. editType: 'plot',
  58179. impliedEdits: {'^autocontour': false},
  58180. },
  58181. end: {
  58182. valType: 'number',
  58183. dflt: null,
  58184. editType: 'plot',
  58185. impliedEdits: {'^autocontour': false},
  58186. },
  58187. size: {
  58188. valType: 'number',
  58189. dflt: null,
  58190. min: 0,
  58191. editType: 'plot',
  58192. impliedEdits: {'^autocontour': false},
  58193. },
  58194. coloring: {
  58195. valType: 'enumerated',
  58196. values: ['fill', 'heatmap', 'lines', 'none'],
  58197. dflt: 'fill',
  58198. editType: 'calc',
  58199. },
  58200. showlines: {
  58201. valType: 'boolean',
  58202. dflt: true,
  58203. editType: 'plot',
  58204. },
  58205. showlabels: {
  58206. valType: 'boolean',
  58207. dflt: false,
  58208. editType: 'plot',
  58209. },
  58210. labelfont: fontAttrs({
  58211. editType: 'plot',
  58212. colorEditType: 'style',
  58213. }),
  58214. labelformat: {
  58215. valType: 'string',
  58216. dflt: '',
  58217. editType: 'plot',
  58218. },
  58219. operation: {
  58220. valType: 'enumerated',
  58221. values: [].concat(COMPARISON_OPS2).concat(INTERVAL_OPS),
  58222. dflt: '=',
  58223. editType: 'calc',
  58224. },
  58225. value: {
  58226. valType: 'any',
  58227. dflt: 0,
  58228. editType: 'calc',
  58229. },
  58230. editType: 'calc',
  58231. impliedEdits: {'autocontour': false}
  58232. },
  58233. line: {
  58234. color: extendFlat({}, scatterLineAttrs.color, {
  58235. editType: 'style+colorbars',
  58236. }),
  58237. width: extendFlat({}, scatterLineAttrs.width, {
  58238. editType: 'style+colorbars'
  58239. }),
  58240. dash: dash,
  58241. smoothing: extendFlat({}, scatterLineAttrs.smoothing, {
  58242. }),
  58243. editType: 'plot'
  58244. }
  58245. },
  58246. colorscaleAttrs('', {
  58247. cLetter: 'z',
  58248. autoColorDflt: false,
  58249. editTypeOverride: 'calc'
  58250. }),
  58251. { colorbar: colorbarAttrs }
  58252. );
  58253. },{"../../components/colorbar/attributes":51,"../../components/colorscale/attributes":57,"../../components/drawing/attributes":74,"../../constants/filter_ops":149,"../../lib/extend":163,"../../plots/font_attributes":240,"../heatmap/attributes":316,"../scatter/attributes":366}],295:[function(_dereq_,module,exports){
  58254. /**
  58255. * Copyright 2012-2018, Plotly, Inc.
  58256. * All rights reserved.
  58257. *
  58258. * This source code is licensed under the MIT license found in the
  58259. * LICENSE file in the root directory of this source tree.
  58260. */
  58261. 'use strict';
  58262. var heatmapCalc = _dereq_('../heatmap/calc');
  58263. var setContours = _dereq_('./set_contours');
  58264. // most is the same as heatmap calc, then adjust it
  58265. // though a few things inside heatmap calc still look for
  58266. // contour maps, because the makeBoundArray calls are too entangled
  58267. module.exports = function calc(gd, trace) {
  58268. var cd = heatmapCalc(gd, trace);
  58269. setContours(trace);
  58270. return cd;
  58271. };
  58272. },{"../heatmap/calc":317,"./set_contours":313}],296:[function(_dereq_,module,exports){
  58273. /**
  58274. * Copyright 2012-2018, Plotly, Inc.
  58275. * All rights reserved.
  58276. *
  58277. * This source code is licensed under the MIT license found in the
  58278. * LICENSE file in the root directory of this source tree.
  58279. */
  58280. 'use strict';
  58281. module.exports = function(pathinfo, operation, perimeter, trace) {
  58282. // Abandon all hope, ye who enter here.
  58283. var i, v1, v2;
  58284. var pi0 = pathinfo[0];
  58285. var na = pi0.x.length;
  58286. var nb = pi0.y.length;
  58287. var z = pi0.z;
  58288. var contours = trace.contours;
  58289. var boundaryMax = -Infinity;
  58290. var boundaryMin = Infinity;
  58291. for(i = 0; i < nb; i++) {
  58292. boundaryMin = Math.min(boundaryMin, z[i][0]);
  58293. boundaryMin = Math.min(boundaryMin, z[i][na - 1]);
  58294. boundaryMax = Math.max(boundaryMax, z[i][0]);
  58295. boundaryMax = Math.max(boundaryMax, z[i][na - 1]);
  58296. }
  58297. for(i = 1; i < na - 1; i++) {
  58298. boundaryMin = Math.min(boundaryMin, z[0][i]);
  58299. boundaryMin = Math.min(boundaryMin, z[nb - 1][i]);
  58300. boundaryMax = Math.max(boundaryMax, z[0][i]);
  58301. boundaryMax = Math.max(boundaryMax, z[nb - 1][i]);
  58302. }
  58303. pi0.prefixBoundary = false;
  58304. switch(operation) {
  58305. case '>':
  58306. if(contours.value > boundaryMax) {
  58307. pi0.prefixBoundary = true;
  58308. }
  58309. break;
  58310. case '<':
  58311. if(contours.value < boundaryMin) {
  58312. pi0.prefixBoundary = true;
  58313. }
  58314. break;
  58315. case '[]':
  58316. v1 = Math.min.apply(null, contours.value);
  58317. v2 = Math.max.apply(null, contours.value);
  58318. if(v2 < boundaryMin || v1 > boundaryMax) {
  58319. pi0.prefixBoundary = true;
  58320. }
  58321. break;
  58322. case '][':
  58323. v1 = Math.min.apply(null, contours.value);
  58324. v2 = Math.max.apply(null, contours.value);
  58325. if(v1 < boundaryMin && v2 > boundaryMax) {
  58326. pi0.prefixBoundary = true;
  58327. }
  58328. break;
  58329. }
  58330. };
  58331. },{}],297:[function(_dereq_,module,exports){
  58332. /**
  58333. * Copyright 2012-2018, Plotly, Inc.
  58334. * All rights reserved.
  58335. *
  58336. * This source code is licensed under the MIT license found in the
  58337. * LICENSE file in the root directory of this source tree.
  58338. */
  58339. 'use strict';
  58340. var drawColorbar = _dereq_('../../components/colorbar/draw');
  58341. var makeColorMap = _dereq_('./make_color_map');
  58342. var endPlus = _dereq_('./end_plus');
  58343. module.exports = function colorbar(gd, cd) {
  58344. var trace = cd[0].trace;
  58345. var cbId = 'cb' + trace.uid;
  58346. gd._fullLayout._infolayer.selectAll('.' + cbId).remove();
  58347. if(!trace.showscale) return;
  58348. var cb = cd[0].t.cb = drawColorbar(gd, cbId);
  58349. var contours = trace.contours;
  58350. var line = trace.line;
  58351. var cs = contours.size || 1;
  58352. var coloring = contours.coloring;
  58353. var colorMap = makeColorMap(trace, {isColorbar: true});
  58354. cb.fillgradient(coloring === 'heatmap' ? trace.colorscale : '')
  58355. .zrange(coloring === 'heatmap' ? [trace.zmin, trace.zmax] : '')
  58356. .fillcolor((coloring === 'fill') ? colorMap : '')
  58357. .line({
  58358. color: coloring === 'lines' ? colorMap : line.color,
  58359. width: contours.showlines !== false ? line.width : 0,
  58360. dash: line.dash
  58361. })
  58362. .levels({
  58363. start: contours.start,
  58364. end: endPlus(contours),
  58365. size: cs
  58366. })
  58367. .options(trace.colorbar)();
  58368. };
  58369. },{"../../components/colorbar/draw":55,"./end_plus":305,"./make_color_map":310}],298:[function(_dereq_,module,exports){
  58370. /**
  58371. * Copyright 2012-2018, Plotly, Inc.
  58372. * All rights reserved.
  58373. *
  58374. * This source code is licensed under the MIT license found in the
  58375. * LICENSE file in the root directory of this source tree.
  58376. */
  58377. 'use strict';
  58378. module.exports = {
  58379. // some constants to help with marching squares algorithm
  58380. // where does the path start for each index?
  58381. BOTTOMSTART: [1, 9, 13, 104, 713],
  58382. TOPSTART: [4, 6, 7, 104, 713],
  58383. LEFTSTART: [8, 12, 14, 208, 1114],
  58384. RIGHTSTART: [2, 3, 11, 208, 1114],
  58385. // which way [dx,dy] do we leave a given index?
  58386. // saddles are already disambiguated
  58387. NEWDELTA: [
  58388. null, [-1, 0], [0, -1], [-1, 0],
  58389. [1, 0], null, [0, -1], [-1, 0],
  58390. [0, 1], [0, 1], null, [0, 1],
  58391. [1, 0], [1, 0], [0, -1]
  58392. ],
  58393. // for each saddle, the first index here is used
  58394. // for dx||dy<0, the second for dx||dy>0
  58395. CHOOSESADDLE: {
  58396. 104: [4, 1],
  58397. 208: [2, 8],
  58398. 713: [7, 13],
  58399. 1114: [11, 14]
  58400. },
  58401. // after one index has been used for a saddle, which do we
  58402. // substitute to be used up later?
  58403. SADDLEREMAINDER: {1: 4, 2: 8, 4: 1, 7: 13, 8: 2, 11: 14, 13: 7, 14: 11},
  58404. // length of a contour, as a multiple of the plot area diagonal, per label
  58405. LABELDISTANCE: 2,
  58406. // number of contour levels after which we start increasing the number of
  58407. // labels we draw. Many contours means they will generally be close
  58408. // together, so it will be harder to follow a long way to find a label
  58409. LABELINCREASE: 10,
  58410. // minimum length of a contour line, as a multiple of the label length,
  58411. // at which we draw *any* labels
  58412. LABELMIN: 3,
  58413. // max number of labels to draw on a single contour path, no matter how long
  58414. LABELMAX: 10,
  58415. // constants for the label position cost function
  58416. LABELOPTIMIZER: {
  58417. // weight given to edge proximity
  58418. EDGECOST: 1,
  58419. // weight given to the angle off horizontal
  58420. ANGLECOST: 1,
  58421. // weight given to distance from already-placed labels
  58422. NEIGHBORCOST: 5,
  58423. // cost multiplier for labels on the same level
  58424. SAMELEVELFACTOR: 10,
  58425. // minimum distance (as a multiple of the label length)
  58426. // for labels on the same level
  58427. SAMELEVELDISTANCE: 5,
  58428. // maximum cost before we won't even place the label
  58429. MAXCOST: 100,
  58430. // number of evenly spaced points to look at in the first
  58431. // iteration of the search
  58432. INITIALSEARCHPOINTS: 10,
  58433. // number of binary search iterations after the initial wide search
  58434. ITERATIONS: 5
  58435. }
  58436. };
  58437. },{}],299:[function(_dereq_,module,exports){
  58438. /**
  58439. * Copyright 2012-2018, Plotly, Inc.
  58440. * All rights reserved.
  58441. *
  58442. * This source code is licensed under the MIT license found in the
  58443. * LICENSE file in the root directory of this source tree.
  58444. */
  58445. 'use strict';
  58446. var isNumeric = _dereq_('fast-isnumeric');
  58447. var handleLabelDefaults = _dereq_('./label_defaults');
  58448. var Color = _dereq_('../../components/color');
  58449. var addOpacity = Color.addOpacity;
  58450. var opacity = Color.opacity;
  58451. var filterOps = _dereq_('../../constants/filter_ops');
  58452. var CONSTRAINT_REDUCTION = filterOps.CONSTRAINT_REDUCTION;
  58453. var COMPARISON_OPS2 = filterOps.COMPARISON_OPS2;
  58454. module.exports = function handleConstraintDefaults(traceIn, traceOut, coerce, layout, defaultColor, opts) {
  58455. var contours = traceOut.contours;
  58456. var showLines, lineColor, fillColor;
  58457. var operation = coerce('contours.operation');
  58458. contours._operation = CONSTRAINT_REDUCTION[operation];
  58459. handleConstraintValueDefaults(coerce, contours);
  58460. if(operation === '=') {
  58461. showLines = contours.showlines = true;
  58462. }
  58463. else {
  58464. showLines = coerce('contours.showlines');
  58465. fillColor = coerce('fillcolor', addOpacity(
  58466. (traceIn.line || {}).color || defaultColor, 0.5
  58467. ));
  58468. }
  58469. if(showLines) {
  58470. var lineDfltColor = fillColor && opacity(fillColor) ?
  58471. addOpacity(traceOut.fillcolor, 1) :
  58472. defaultColor;
  58473. lineColor = coerce('line.color', lineDfltColor);
  58474. coerce('line.width', 2);
  58475. coerce('line.dash');
  58476. }
  58477. coerce('line.smoothing');
  58478. handleLabelDefaults(coerce, layout, lineColor, opts);
  58479. };
  58480. function handleConstraintValueDefaults(coerce, contours) {
  58481. var zvalue;
  58482. if(COMPARISON_OPS2.indexOf(contours.operation) === -1) {
  58483. // Requires an array of two numbers:
  58484. coerce('contours.value', [0, 1]);
  58485. if(!Array.isArray(contours.value)) {
  58486. if(isNumeric(contours.value)) {
  58487. zvalue = parseFloat(contours.value);
  58488. contours.value = [zvalue, zvalue + 1];
  58489. }
  58490. } else if(contours.value.length > 2) {
  58491. contours.value = contours.value.slice(2);
  58492. } else if(contours.length === 0) {
  58493. contours.value = [0, 1];
  58494. } else if(contours.length < 2) {
  58495. zvalue = parseFloat(contours.value[0]);
  58496. contours.value = [zvalue, zvalue + 1];
  58497. } else {
  58498. contours.value = [
  58499. parseFloat(contours.value[0]),
  58500. parseFloat(contours.value[1])
  58501. ];
  58502. }
  58503. } else {
  58504. // Requires a single scalar:
  58505. coerce('contours.value', 0);
  58506. if(!isNumeric(contours.value)) {
  58507. if(Array.isArray(contours.value)) {
  58508. contours.value = parseFloat(contours.value[0]);
  58509. } else {
  58510. contours.value = 0;
  58511. }
  58512. }
  58513. }
  58514. }
  58515. },{"../../components/color":50,"../../constants/filter_ops":149,"./label_defaults":309,"fast-isnumeric":18}],300:[function(_dereq_,module,exports){
  58516. /**
  58517. * Copyright 2012-2018, Plotly, Inc.
  58518. * All rights reserved.
  58519. *
  58520. * This source code is licensed under the MIT license found in the
  58521. * LICENSE file in the root directory of this source tree.
  58522. */
  58523. 'use strict';
  58524. var filterOps = _dereq_('../../constants/filter_ops');
  58525. var isNumeric = _dereq_('fast-isnumeric');
  58526. // This syntax conforms to the existing filter transform syntax, but we don't care
  58527. // about open vs. closed intervals for simply drawing contours constraints:
  58528. module.exports = {
  58529. '[]': makeRangeSettings('[]'),
  58530. '][': makeRangeSettings(']['),
  58531. '>': makeInequalitySettings('>'),
  58532. '<': makeInequalitySettings('<'),
  58533. '=': makeInequalitySettings('=')
  58534. };
  58535. // This does not in any way shape or form support calendars. It's adapted from
  58536. // transforms/filter.js.
  58537. function coerceValue(operation, value) {
  58538. var hasArrayValue = Array.isArray(value);
  58539. var coercedValue;
  58540. function coerce(value) {
  58541. return isNumeric(value) ? (+value) : null;
  58542. }
  58543. if(filterOps.COMPARISON_OPS2.indexOf(operation) !== -1) {
  58544. coercedValue = hasArrayValue ? coerce(value[0]) : coerce(value);
  58545. } else if(filterOps.INTERVAL_OPS.indexOf(operation) !== -1) {
  58546. coercedValue = hasArrayValue ?
  58547. [coerce(value[0]), coerce(value[1])] :
  58548. [coerce(value), coerce(value)];
  58549. } else if(filterOps.SET_OPS.indexOf(operation) !== -1) {
  58550. coercedValue = hasArrayValue ? value.map(coerce) : [coerce(value)];
  58551. }
  58552. return coercedValue;
  58553. }
  58554. // Returns a parabola scaled so that the min/max is either +/- 1 and zero at the two values
  58555. // provided. The data is mapped by this function when constructing intervals so that it's
  58556. // very easy to construct contours as normal.
  58557. function makeRangeSettings(operation) {
  58558. return function(value) {
  58559. value = coerceValue(operation, value);
  58560. // Ensure proper ordering:
  58561. var min = Math.min(value[0], value[1]);
  58562. var max = Math.max(value[0], value[1]);
  58563. return {
  58564. start: min,
  58565. end: max,
  58566. size: max - min
  58567. };
  58568. };
  58569. }
  58570. function makeInequalitySettings(operation) {
  58571. return function(value) {
  58572. value = coerceValue(operation, value);
  58573. return {
  58574. start: value,
  58575. end: Infinity,
  58576. size: Infinity
  58577. };
  58578. };
  58579. }
  58580. },{"../../constants/filter_ops":149,"fast-isnumeric":18}],301:[function(_dereq_,module,exports){
  58581. /**
  58582. * Copyright 2012-2018, Plotly, Inc.
  58583. * All rights reserved.
  58584. *
  58585. * This source code is licensed under the MIT license found in the
  58586. * LICENSE file in the root directory of this source tree.
  58587. */
  58588. 'use strict';
  58589. module.exports = function handleContourDefaults(traceIn, traceOut, coerce, coerce2) {
  58590. var contourStart = coerce2('contours.start');
  58591. var contourEnd = coerce2('contours.end');
  58592. var missingEnd = (contourStart === false) || (contourEnd === false);
  58593. // normally we only need size if autocontour is off. But contour.calc
  58594. // pushes its calculated contour size back to the input trace, so for
  58595. // things like restyle that can call supplyDefaults without calc
  58596. // after the initial draw, we can just reuse the previous calculation
  58597. var contourSize = coerce('contours.size');
  58598. var autoContour;
  58599. if(missingEnd) autoContour = traceOut.autocontour = true;
  58600. else autoContour = coerce('autocontour', false);
  58601. if(autoContour || !contourSize) coerce('ncontours');
  58602. };
  58603. },{}],302:[function(_dereq_,module,exports){
  58604. /**
  58605. * Copyright 2012-2018, Plotly, Inc.
  58606. * All rights reserved.
  58607. *
  58608. * This source code is licensed under the MIT license found in the
  58609. * LICENSE file in the root directory of this source tree.
  58610. */
  58611. 'use strict';
  58612. var Lib = _dereq_('../../lib');
  58613. // The contour extraction is great, except it totally fails for constraints because we
  58614. // need weird range loops and flipped contours instead of the usual format. This function
  58615. // does some weird manipulation of the extracted pathinfo data such that it magically
  58616. // draws contours correctly *as* constraints.
  58617. module.exports = function(pathinfo, operation) {
  58618. var i, pi0, pi1;
  58619. var op0 = function(arr) { return arr.reverse(); };
  58620. var op1 = function(arr) { return arr; };
  58621. switch(operation) {
  58622. case '=':
  58623. case '<':
  58624. return pathinfo;
  58625. case '>':
  58626. if(pathinfo.length !== 1) {
  58627. Lib.warn('Contour data invalid for the specified inequality operation.');
  58628. }
  58629. // In this case there should be exactly two contour levels in pathinfo. We
  58630. // simply concatenate the info into one pathinfo and flip all of the data
  58631. // in one. This will draw the contour as closed.
  58632. pi0 = pathinfo[0];
  58633. for(i = 0; i < pi0.edgepaths.length; i++) {
  58634. pi0.edgepaths[i] = op0(pi0.edgepaths[i]);
  58635. }
  58636. for(i = 0; i < pi0.paths.length; i++) {
  58637. pi0.paths[i] = op0(pi0.paths[i]);
  58638. }
  58639. return pathinfo;
  58640. case '][':
  58641. var tmp = op0;
  58642. op0 = op1;
  58643. op1 = tmp;
  58644. // It's a nice rule, except this definitely *is* what's intended here.
  58645. /* eslint-disable: no-fallthrough */
  58646. case '[]':
  58647. /* eslint-enable: no-fallthrough */
  58648. if(pathinfo.length !== 2) {
  58649. Lib.warn('Contour data invalid for the specified inequality range operation.');
  58650. }
  58651. // In this case there should be exactly two contour levels in pathinfo. We
  58652. // simply concatenate the info into one pathinfo and flip all of the data
  58653. // in one. This will draw the contour as closed.
  58654. pi0 = copyPathinfo(pathinfo[0]);
  58655. pi1 = copyPathinfo(pathinfo[1]);
  58656. for(i = 0; i < pi0.edgepaths.length; i++) {
  58657. pi0.edgepaths[i] = op0(pi0.edgepaths[i]);
  58658. }
  58659. for(i = 0; i < pi0.paths.length; i++) {
  58660. pi0.paths[i] = op0(pi0.paths[i]);
  58661. }
  58662. while(pi1.edgepaths.length) {
  58663. pi0.edgepaths.push(op1(pi1.edgepaths.shift()));
  58664. }
  58665. while(pi1.paths.length) {
  58666. pi0.paths.push(op1(pi1.paths.shift()));
  58667. }
  58668. return [pi0];
  58669. }
  58670. };
  58671. function copyPathinfo(pi) {
  58672. return Lib.extendFlat({}, pi, {
  58673. edgepaths: Lib.extendDeep([], pi.edgepaths),
  58674. paths: Lib.extendDeep([], pi.paths)
  58675. });
  58676. }
  58677. },{"../../lib":169}],303:[function(_dereq_,module,exports){
  58678. /**
  58679. * Copyright 2012-2018, Plotly, Inc.
  58680. * All rights reserved.
  58681. *
  58682. * This source code is licensed under the MIT license found in the
  58683. * LICENSE file in the root directory of this source tree.
  58684. */
  58685. 'use strict';
  58686. var Lib = _dereq_('../../lib');
  58687. var handleXYZDefaults = _dereq_('../heatmap/xyz_defaults');
  58688. var handleConstraintDefaults = _dereq_('./constraint_defaults');
  58689. var handleContoursDefaults = _dereq_('./contours_defaults');
  58690. var handleStyleDefaults = _dereq_('./style_defaults');
  58691. var attributes = _dereq_('./attributes');
  58692. module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout) {
  58693. function coerce(attr, dflt) {
  58694. return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);
  58695. }
  58696. function coerce2(attr) {
  58697. return Lib.coerce2(traceIn, traceOut, attributes, attr);
  58698. }
  58699. var len = handleXYZDefaults(traceIn, traceOut, coerce, layout);
  58700. if(!len) {
  58701. traceOut.visible = false;
  58702. return;
  58703. }
  58704. coerce('text');
  58705. var isConstraint = (coerce('contours.type') === 'constraint');
  58706. coerce('connectgaps', Lib.isArray1D(traceOut.z));
  58707. if(isConstraint) {
  58708. handleConstraintDefaults(traceIn, traceOut, coerce, layout, defaultColor);
  58709. }
  58710. else {
  58711. handleContoursDefaults(traceIn, traceOut, coerce, coerce2);
  58712. handleStyleDefaults(traceIn, traceOut, coerce, layout);
  58713. }
  58714. };
  58715. },{"../../lib":169,"../heatmap/xyz_defaults":331,"./attributes":294,"./constraint_defaults":299,"./contours_defaults":301,"./style_defaults":315}],304:[function(_dereq_,module,exports){
  58716. /**
  58717. * Copyright 2012-2018, Plotly, Inc.
  58718. * All rights reserved.
  58719. *
  58720. * This source code is licensed under the MIT license found in the
  58721. * LICENSE file in the root directory of this source tree.
  58722. */
  58723. 'use strict';
  58724. var Lib = _dereq_('../../lib');
  58725. var constraintMapping = _dereq_('./constraint_mapping');
  58726. var endPlus = _dereq_('./end_plus');
  58727. module.exports = function emptyPathinfo(contours, plotinfo, cd0) {
  58728. var contoursFinal = (contours.type === 'constraint') ?
  58729. constraintMapping[contours._operation](contours.value) :
  58730. contours;
  58731. var cs = contoursFinal.size;
  58732. var pathinfo = [];
  58733. var end = endPlus(contoursFinal);
  58734. var carpet = cd0.trace._carpetTrace;
  58735. var basePathinfo = carpet ? {
  58736. // store axes so we can convert to px
  58737. xaxis: carpet.aaxis,
  58738. yaxis: carpet.baxis,
  58739. // full data arrays to use for interpolation
  58740. x: cd0.a,
  58741. y: cd0.b
  58742. } : {
  58743. xaxis: plotinfo.xaxis,
  58744. yaxis: plotinfo.yaxis,
  58745. x: cd0.x,
  58746. y: cd0.y
  58747. };
  58748. for(var ci = contoursFinal.start; ci < end; ci += cs) {
  58749. pathinfo.push(Lib.extendFlat({
  58750. level: ci,
  58751. // all the cells with nontrivial marching index
  58752. crossings: {},
  58753. // starting points on the edges of the lattice for each contour
  58754. starts: [],
  58755. // all unclosed paths (may have less items than starts,
  58756. // if a path is closed by rounding)
  58757. edgepaths: [],
  58758. // all closed paths
  58759. paths: [],
  58760. z: cd0.z,
  58761. smoothing: cd0.trace.line.smoothing
  58762. }, basePathinfo));
  58763. if(pathinfo.length > 1000) {
  58764. Lib.warn('Too many contours, clipping at 1000', contours);
  58765. break;
  58766. }
  58767. }
  58768. return pathinfo;
  58769. };
  58770. },{"../../lib":169,"./constraint_mapping":300,"./end_plus":305}],305:[function(_dereq_,module,exports){
  58771. /**
  58772. * Copyright 2012-2018, Plotly, Inc.
  58773. * All rights reserved.
  58774. *
  58775. * This source code is licensed under the MIT license found in the
  58776. * LICENSE file in the root directory of this source tree.
  58777. */
  58778. 'use strict';
  58779. /*
  58780. * tiny helper to move the end of the contours a little to prevent
  58781. * losing the last contour to rounding errors
  58782. */
  58783. module.exports = function endPlus(contours) {
  58784. return contours.end + contours.size / 1e6;
  58785. };
  58786. },{}],306:[function(_dereq_,module,exports){
  58787. /**
  58788. * Copyright 2012-2018, Plotly, Inc.
  58789. * All rights reserved.
  58790. *
  58791. * This source code is licensed under the MIT license found in the
  58792. * LICENSE file in the root directory of this source tree.
  58793. */
  58794. 'use strict';
  58795. var Lib = _dereq_('../../lib');
  58796. var constants = _dereq_('./constants');
  58797. module.exports = function findAllPaths(pathinfo, xtol, ytol) {
  58798. var cnt,
  58799. startLoc,
  58800. i,
  58801. pi,
  58802. j;
  58803. // Default just passes these values through as they were before:
  58804. xtol = xtol || 0.01;
  58805. ytol = ytol || 0.01;
  58806. for(i = 0; i < pathinfo.length; i++) {
  58807. pi = pathinfo[i];
  58808. for(j = 0; j < pi.starts.length; j++) {
  58809. startLoc = pi.starts[j];
  58810. makePath(pi, startLoc, 'edge', xtol, ytol);
  58811. }
  58812. cnt = 0;
  58813. while(Object.keys(pi.crossings).length && cnt < 10000) {
  58814. cnt++;
  58815. startLoc = Object.keys(pi.crossings)[0].split(',').map(Number);
  58816. makePath(pi, startLoc, undefined, xtol, ytol);
  58817. }
  58818. if(cnt === 10000) Lib.log('Infinite loop in contour?');
  58819. }
  58820. };
  58821. function equalPts(pt1, pt2, xtol, ytol) {
  58822. return Math.abs(pt1[0] - pt2[0]) < xtol &&
  58823. Math.abs(pt1[1] - pt2[1]) < ytol;
  58824. }
  58825. // distance in index units - uses the 3rd and 4th items in points
  58826. function ptDist(pt1, pt2) {
  58827. var dx = pt1[2] - pt2[2],
  58828. dy = pt1[3] - pt2[3];
  58829. return Math.sqrt(dx * dx + dy * dy);
  58830. }
  58831. function makePath(pi, loc, edgeflag, xtol, ytol) {
  58832. var startLocStr = loc.join(',');
  58833. var locStr = startLocStr;
  58834. var mi = pi.crossings[locStr];
  58835. var marchStep = startStep(mi, edgeflag, loc);
  58836. // start by going backward a half step and finding the crossing point
  58837. var pts = [getInterpPx(pi, loc, [-marchStep[0], -marchStep[1]])];
  58838. var startStepStr = marchStep.join(',');
  58839. var m = pi.z.length;
  58840. var n = pi.z[0].length;
  58841. var cnt;
  58842. // now follow the path
  58843. for(cnt = 0; cnt < 10000; cnt++) { // just to avoid infinite loops
  58844. if(mi > 20) {
  58845. mi = constants.CHOOSESADDLE[mi][(marchStep[0] || marchStep[1]) < 0 ? 0 : 1];
  58846. pi.crossings[locStr] = constants.SADDLEREMAINDER[mi];
  58847. }
  58848. else {
  58849. delete pi.crossings[locStr];
  58850. }
  58851. marchStep = constants.NEWDELTA[mi];
  58852. if(!marchStep) {
  58853. Lib.log('Found bad marching index:', mi, loc, pi.level);
  58854. break;
  58855. }
  58856. // find the crossing a half step forward, and then take the full step
  58857. pts.push(getInterpPx(pi, loc, marchStep));
  58858. loc[0] += marchStep[0];
  58859. loc[1] += marchStep[1];
  58860. // don't include the same point multiple times
  58861. if(equalPts(pts[pts.length - 1], pts[pts.length - 2], xtol, ytol)) pts.pop();
  58862. locStr = loc.join(',');
  58863. var atEdge = (marchStep[0] && (loc[0] < 0 || loc[0] > n - 2)) ||
  58864. (marchStep[1] && (loc[1] < 0 || loc[1] > m - 2)),
  58865. closedLoop = (locStr === startLocStr) && (marchStep.join(',') === startStepStr);
  58866. // have we completed a loop, or reached an edge?
  58867. if((closedLoop) || (edgeflag && atEdge)) break;
  58868. mi = pi.crossings[locStr];
  58869. }
  58870. if(cnt === 10000) {
  58871. Lib.log('Infinite loop in contour?');
  58872. }
  58873. var closedpath = equalPts(pts[0], pts[pts.length - 1], xtol, ytol);
  58874. var totaldist = 0;
  58875. var distThresholdFactor = 0.2 * pi.smoothing;
  58876. var alldists = [];
  58877. var cropstart = 0;
  58878. var distgroup, cnt2, cnt3, newpt, ptcnt, ptavg, thisdist,
  58879. i, j, edgepathi, edgepathj;
  58880. /*
  58881. * Check for points that are too close together (<1/5 the average dist
  58882. * *in grid index units* (important for log axes and nonuniform grids),
  58883. * less if less smoothed) and just take the center (or avg of center 2).
  58884. * This cuts down on funny behavior when a point is very close to a
  58885. * contour level.
  58886. */
  58887. for(cnt = 1; cnt < pts.length; cnt++) {
  58888. thisdist = ptDist(pts[cnt], pts[cnt - 1]);
  58889. totaldist += thisdist;
  58890. alldists.push(thisdist);
  58891. }
  58892. var distThreshold = totaldist / alldists.length * distThresholdFactor;
  58893. function getpt(i) { return pts[i % pts.length]; }
  58894. for(cnt = pts.length - 2; cnt >= cropstart; cnt--) {
  58895. distgroup = alldists[cnt];
  58896. if(distgroup < distThreshold) {
  58897. cnt3 = 0;
  58898. for(cnt2 = cnt - 1; cnt2 >= cropstart; cnt2--) {
  58899. if(distgroup + alldists[cnt2] < distThreshold) {
  58900. distgroup += alldists[cnt2];
  58901. }
  58902. else break;
  58903. }
  58904. // closed path with close points wrapping around the boundary?
  58905. if(closedpath && cnt === pts.length - 2) {
  58906. for(cnt3 = 0; cnt3 < cnt2; cnt3++) {
  58907. if(distgroup + alldists[cnt3] < distThreshold) {
  58908. distgroup += alldists[cnt3];
  58909. }
  58910. else break;
  58911. }
  58912. }
  58913. ptcnt = cnt - cnt2 + cnt3 + 1;
  58914. ptavg = Math.floor((cnt + cnt2 + cnt3 + 2) / 2);
  58915. // either endpoint included: keep the endpoint
  58916. if(!closedpath && cnt === pts.length - 2) newpt = pts[pts.length - 1];
  58917. else if(!closedpath && cnt2 === -1) newpt = pts[0];
  58918. // odd # of points - just take the central one
  58919. else if(ptcnt % 2) newpt = getpt(ptavg);
  58920. // even # of pts - average central two
  58921. else {
  58922. newpt = [(getpt(ptavg)[0] + getpt(ptavg + 1)[0]) / 2,
  58923. (getpt(ptavg)[1] + getpt(ptavg + 1)[1]) / 2];
  58924. }
  58925. pts.splice(cnt2 + 1, cnt - cnt2 + 1, newpt);
  58926. cnt = cnt2 + 1;
  58927. if(cnt3) cropstart = cnt3;
  58928. if(closedpath) {
  58929. if(cnt === pts.length - 2) pts[cnt3] = pts[pts.length - 1];
  58930. else if(cnt === 0) pts[pts.length - 1] = pts[0];
  58931. }
  58932. }
  58933. }
  58934. pts.splice(0, cropstart);
  58935. // done with the index parts - remove them so path generation works right
  58936. // because it depends on only having [xpx, ypx]
  58937. for(cnt = 0; cnt < pts.length; cnt++) pts[cnt].length = 2;
  58938. // don't return single-point paths (ie all points were the same
  58939. // so they got deleted?)
  58940. if(pts.length < 2) return;
  58941. else if(closedpath) {
  58942. pts.pop();
  58943. pi.paths.push(pts);
  58944. }
  58945. else {
  58946. if(!edgeflag) {
  58947. Lib.log('Unclosed interior contour?',
  58948. pi.level, startLocStr, pts.join('L'));
  58949. }
  58950. // edge path - does it start where an existing edge path ends, or vice versa?
  58951. var merged = false;
  58952. for(i = 0; i < pi.edgepaths.length; i++) {
  58953. edgepathi = pi.edgepaths[i];
  58954. if(!merged && equalPts(edgepathi[0], pts[pts.length - 1], xtol, ytol)) {
  58955. pts.pop();
  58956. merged = true;
  58957. // now does it ALSO meet the end of another (or the same) path?
  58958. var doublemerged = false;
  58959. for(j = 0; j < pi.edgepaths.length; j++) {
  58960. edgepathj = pi.edgepaths[j];
  58961. if(equalPts(edgepathj[edgepathj.length - 1], pts[0], xtol, ytol)) {
  58962. doublemerged = true;
  58963. pts.shift();
  58964. pi.edgepaths.splice(i, 1);
  58965. if(j === i) {
  58966. // the path is now closed
  58967. pi.paths.push(pts.concat(edgepathj));
  58968. }
  58969. else {
  58970. if(j > i) j--;
  58971. pi.edgepaths[j] = edgepathj.concat(pts, edgepathi);
  58972. }
  58973. break;
  58974. }
  58975. }
  58976. if(!doublemerged) {
  58977. pi.edgepaths[i] = pts.concat(edgepathi);
  58978. }
  58979. }
  58980. }
  58981. for(i = 0; i < pi.edgepaths.length; i++) {
  58982. if(merged) break;
  58983. edgepathi = pi.edgepaths[i];
  58984. if(equalPts(edgepathi[edgepathi.length - 1], pts[0], xtol, ytol)) {
  58985. pts.shift();
  58986. pi.edgepaths[i] = edgepathi.concat(pts);
  58987. merged = true;
  58988. }
  58989. }
  58990. if(!merged) pi.edgepaths.push(pts);
  58991. }
  58992. }
  58993. // special function to get the marching step of the
  58994. // first point in the path (leading to loc)
  58995. function startStep(mi, edgeflag, loc) {
  58996. var dx = 0,
  58997. dy = 0;
  58998. if(mi > 20 && edgeflag) {
  58999. // these saddles start at +/- x
  59000. if(mi === 208 || mi === 1114) {
  59001. // if we're starting at the left side, we must be going right
  59002. dx = loc[0] === 0 ? 1 : -1;
  59003. }
  59004. else {
  59005. // if we're starting at the bottom, we must be going up
  59006. dy = loc[1] === 0 ? 1 : -1;
  59007. }
  59008. }
  59009. else if(constants.BOTTOMSTART.indexOf(mi) !== -1) dy = 1;
  59010. else if(constants.LEFTSTART.indexOf(mi) !== -1) dx = 1;
  59011. else if(constants.TOPSTART.indexOf(mi) !== -1) dy = -1;
  59012. else dx = -1;
  59013. return [dx, dy];
  59014. }
  59015. /*
  59016. * Find the pixel coordinates of a particular crossing
  59017. *
  59018. * @param {object} pi: the pathinfo object at this level
  59019. * @param {array} loc: the grid index [x, y] of the crossing
  59020. * @param {array} step: the direction [dx, dy] we're moving on the grid
  59021. *
  59022. * @return {array} [xpx, ypx, xi, yi]: the first two are the pixel location,
  59023. * the next two are the interpolated grid indices, which we use for
  59024. * distance calculations to delete points that are too close together.
  59025. * This is important when the grid is nonuniform (and most dramatically when
  59026. * we're on log axes and include invalid (0 or negative) values.
  59027. * It's crucial to delete these extra two before turning an array of these
  59028. * points into a path, because those routines require length-2 points.
  59029. */
  59030. function getInterpPx(pi, loc, step) {
  59031. var locx = loc[0] + Math.max(step[0], 0),
  59032. locy = loc[1] + Math.max(step[1], 0),
  59033. zxy = pi.z[locy][locx],
  59034. xa = pi.xaxis,
  59035. ya = pi.yaxis;
  59036. if(step[1]) {
  59037. var dx = (pi.level - zxy) / (pi.z[locy][locx + 1] - zxy);
  59038. return [xa.c2p((1 - dx) * pi.x[locx] + dx * pi.x[locx + 1], true),
  59039. ya.c2p(pi.y[locy], true),
  59040. locx + dx, locy];
  59041. }
  59042. else {
  59043. var dy = (pi.level - zxy) / (pi.z[locy + 1][locx] - zxy);
  59044. return [xa.c2p(pi.x[locx], true),
  59045. ya.c2p((1 - dy) * pi.y[locy] + dy * pi.y[locy + 1], true),
  59046. locx, locy + dy];
  59047. }
  59048. }
  59049. },{"../../lib":169,"./constants":298}],307:[function(_dereq_,module,exports){
  59050. /**
  59051. * Copyright 2012-2018, Plotly, Inc.
  59052. * All rights reserved.
  59053. *
  59054. * This source code is licensed under the MIT license found in the
  59055. * LICENSE file in the root directory of this source tree.
  59056. */
  59057. 'use strict';
  59058. var Color = _dereq_('../../components/color');
  59059. var heatmapHoverPoints = _dereq_('../heatmap/hover');
  59060. module.exports = function hoverPoints(pointData, xval, yval, hovermode, hoverLayer) {
  59061. var hoverData = heatmapHoverPoints(pointData, xval, yval, hovermode, hoverLayer, true);
  59062. if(hoverData) {
  59063. hoverData.forEach(function(hoverPt) {
  59064. var trace = hoverPt.trace;
  59065. if(trace.contours.type === 'constraint') {
  59066. if(trace.fillcolor && Color.opacity(trace.fillcolor)) {
  59067. hoverPt.color = Color.addOpacity(trace.fillcolor, 1);
  59068. }
  59069. else if(trace.contours.showlines && Color.opacity(trace.line.color)) {
  59070. hoverPt.color = Color.addOpacity(trace.line.color, 1);
  59071. }
  59072. }
  59073. });
  59074. }
  59075. return hoverData;
  59076. };
  59077. },{"../../components/color":50,"../heatmap/hover":323}],308:[function(_dereq_,module,exports){
  59078. /**
  59079. * Copyright 2012-2018, Plotly, Inc.
  59080. * All rights reserved.
  59081. *
  59082. * This source code is licensed under the MIT license found in the
  59083. * LICENSE file in the root directory of this source tree.
  59084. */
  59085. 'use strict';
  59086. var Contour = {};
  59087. Contour.attributes = _dereq_('./attributes');
  59088. Contour.supplyDefaults = _dereq_('./defaults');
  59089. Contour.calc = _dereq_('./calc');
  59090. Contour.plot = _dereq_('./plot').plot;
  59091. Contour.style = _dereq_('./style');
  59092. Contour.colorbar = _dereq_('./colorbar');
  59093. Contour.hoverPoints = _dereq_('./hover');
  59094. Contour.moduleType = 'trace';
  59095. Contour.name = 'contour';
  59096. Contour.basePlotModule = _dereq_('../../plots/cartesian');
  59097. Contour.categories = ['cartesian', 'svg', '2dMap', 'contour', 'showLegend'];
  59098. Contour.meta = {
  59099. };
  59100. module.exports = Contour;
  59101. },{"../../plots/cartesian":225,"./attributes":294,"./calc":295,"./colorbar":297,"./defaults":303,"./hover":307,"./plot":312,"./style":314}],309:[function(_dereq_,module,exports){
  59102. /**
  59103. * Copyright 2012-2018, Plotly, Inc.
  59104. * All rights reserved.
  59105. *
  59106. * This source code is licensed under the MIT license found in the
  59107. * LICENSE file in the root directory of this source tree.
  59108. */
  59109. 'use strict';
  59110. var Lib = _dereq_('../../lib');
  59111. module.exports = function handleLabelDefaults(coerce, layout, lineColor, opts) {
  59112. if(!opts) opts = {};
  59113. var showLabels = coerce('contours.showlabels');
  59114. if(showLabels) {
  59115. var globalFont = layout.font;
  59116. Lib.coerceFont(coerce, 'contours.labelfont', {
  59117. family: globalFont.family,
  59118. size: globalFont.size,
  59119. color: lineColor
  59120. });
  59121. coerce('contours.labelformat');
  59122. }
  59123. if(opts.hasHover !== false) coerce('zhoverformat');
  59124. };
  59125. },{"../../lib":169}],310:[function(_dereq_,module,exports){
  59126. /**
  59127. * Copyright 2012-2018, Plotly, Inc.
  59128. * All rights reserved.
  59129. *
  59130. * This source code is licensed under the MIT license found in the
  59131. * LICENSE file in the root directory of this source tree.
  59132. */
  59133. 'use strict';
  59134. var d3 = _dereq_('d3');
  59135. var Colorscale = _dereq_('../../components/colorscale');
  59136. var endPlus = _dereq_('./end_plus');
  59137. module.exports = function makeColorMap(trace) {
  59138. var contours = trace.contours,
  59139. start = contours.start,
  59140. end = endPlus(contours),
  59141. cs = contours.size || 1,
  59142. nc = Math.floor((end - start) / cs) + 1,
  59143. extra = contours.coloring === 'lines' ? 0 : 1;
  59144. if(!isFinite(cs)) {
  59145. cs = 1;
  59146. nc = 1;
  59147. }
  59148. var scl = trace.colorscale,
  59149. len = scl.length;
  59150. var domain = new Array(len),
  59151. range = new Array(len);
  59152. var si, i;
  59153. if(contours.coloring === 'heatmap') {
  59154. if(trace.zauto && trace.autocontour === false) {
  59155. trace.zmin = start - cs / 2;
  59156. trace.zmax = trace.zmin + nc * cs;
  59157. }
  59158. for(i = 0; i < len; i++) {
  59159. si = scl[i];
  59160. domain[i] = si[0] * (trace.zmax - trace.zmin) + trace.zmin;
  59161. range[i] = si[1];
  59162. }
  59163. // do the contours extend beyond the colorscale?
  59164. // if so, extend the colorscale with constants
  59165. var zRange = d3.extent([trace.zmin, trace.zmax, contours.start,
  59166. contours.start + cs * (nc - 1)]),
  59167. zmin = zRange[trace.zmin < trace.zmax ? 0 : 1],
  59168. zmax = zRange[trace.zmin < trace.zmax ? 1 : 0];
  59169. if(zmin !== trace.zmin) {
  59170. domain.splice(0, 0, zmin);
  59171. range.splice(0, 0, Range[0]);
  59172. }
  59173. if(zmax !== trace.zmax) {
  59174. domain.push(zmax);
  59175. range.push(range[range.length - 1]);
  59176. }
  59177. }
  59178. else {
  59179. for(i = 0; i < len; i++) {
  59180. si = scl[i];
  59181. domain[i] = (si[0] * (nc + extra - 1) - (extra / 2)) * cs + start;
  59182. range[i] = si[1];
  59183. }
  59184. }
  59185. return Colorscale.makeColorScaleFunc({
  59186. domain: domain,
  59187. range: range,
  59188. }, {
  59189. noNumericCheck: true
  59190. });
  59191. };
  59192. },{"../../components/colorscale":65,"./end_plus":305,"d3":16}],311:[function(_dereq_,module,exports){
  59193. /**
  59194. * Copyright 2012-2018, Plotly, Inc.
  59195. * All rights reserved.
  59196. *
  59197. * This source code is licensed under the MIT license found in the
  59198. * LICENSE file in the root directory of this source tree.
  59199. */
  59200. 'use strict';
  59201. var constants = _dereq_('./constants');
  59202. // Calculate all the marching indices, for ALL levels at once.
  59203. // since we want to be exhaustive we'll check for contour crossings
  59204. // at every intersection, rather than just following a path
  59205. // TODO: shorten the inner loop to only the relevant levels
  59206. module.exports = function makeCrossings(pathinfo) {
  59207. var z = pathinfo[0].z,
  59208. m = z.length,
  59209. n = z[0].length, // we already made sure z isn't ragged in interp2d
  59210. twoWide = m === 2 || n === 2,
  59211. xi,
  59212. yi,
  59213. startIndices,
  59214. ystartIndices,
  59215. label,
  59216. corners,
  59217. mi,
  59218. pi,
  59219. i;
  59220. for(yi = 0; yi < m - 1; yi++) {
  59221. ystartIndices = [];
  59222. if(yi === 0) ystartIndices = ystartIndices.concat(constants.BOTTOMSTART);
  59223. if(yi === m - 2) ystartIndices = ystartIndices.concat(constants.TOPSTART);
  59224. for(xi = 0; xi < n - 1; xi++) {
  59225. startIndices = ystartIndices.slice();
  59226. if(xi === 0) startIndices = startIndices.concat(constants.LEFTSTART);
  59227. if(xi === n - 2) startIndices = startIndices.concat(constants.RIGHTSTART);
  59228. label = xi + ',' + yi;
  59229. corners = [[z[yi][xi], z[yi][xi + 1]],
  59230. [z[yi + 1][xi], z[yi + 1][xi + 1]]];
  59231. for(i = 0; i < pathinfo.length; i++) {
  59232. pi = pathinfo[i];
  59233. mi = getMarchingIndex(pi.level, corners);
  59234. if(!mi) continue;
  59235. pi.crossings[label] = mi;
  59236. if(startIndices.indexOf(mi) !== -1) {
  59237. pi.starts.push([xi, yi]);
  59238. if(twoWide && startIndices.indexOf(mi,
  59239. startIndices.indexOf(mi) + 1) !== -1) {
  59240. // the same square has starts from opposite sides
  59241. // it's not possible to have starts on opposite edges
  59242. // of a corner, only a start and an end...
  59243. // but if the array is only two points wide (either way)
  59244. // you can have starts on opposite sides.
  59245. pi.starts.push([xi, yi]);
  59246. }
  59247. }
  59248. }
  59249. }
  59250. }
  59251. };
  59252. // modified marching squares algorithm,
  59253. // so we disambiguate the saddle points from the start
  59254. // and we ignore the cases with no crossings
  59255. // the index I'm using is based on:
  59256. // http://en.wikipedia.org/wiki/Marching_squares
  59257. // except that the saddles bifurcate and I represent them
  59258. // as the decimal combination of the two appropriate
  59259. // non-saddle indices
  59260. function getMarchingIndex(val, corners) {
  59261. var mi = (corners[0][0] > val ? 0 : 1) +
  59262. (corners[0][1] > val ? 0 : 2) +
  59263. (corners[1][1] > val ? 0 : 4) +
  59264. (corners[1][0] > val ? 0 : 8);
  59265. if(mi === 5 || mi === 10) {
  59266. var avg = (corners[0][0] + corners[0][1] +
  59267. corners[1][0] + corners[1][1]) / 4;
  59268. // two peaks with a big valley
  59269. if(val > avg) return (mi === 5) ? 713 : 1114;
  59270. // two valleys with a big ridge
  59271. return (mi === 5) ? 104 : 208;
  59272. }
  59273. return (mi === 15) ? 0 : mi;
  59274. }
  59275. },{"./constants":298}],312:[function(_dereq_,module,exports){
  59276. /**
  59277. * Copyright 2012-2018, Plotly, Inc.
  59278. * All rights reserved.
  59279. *
  59280. * This source code is licensed under the MIT license found in the
  59281. * LICENSE file in the root directory of this source tree.
  59282. */
  59283. 'use strict';
  59284. var d3 = _dereq_('d3');
  59285. var Lib = _dereq_('../../lib');
  59286. var Drawing = _dereq_('../../components/drawing');
  59287. var svgTextUtils = _dereq_('../../lib/svg_text_utils');
  59288. var Axes = _dereq_('../../plots/cartesian/axes');
  59289. var setConvert = _dereq_('../../plots/cartesian/set_convert');
  59290. var heatmapPlot = _dereq_('../heatmap/plot');
  59291. var makeCrossings = _dereq_('./make_crossings');
  59292. var findAllPaths = _dereq_('./find_all_paths');
  59293. var emptyPathinfo = _dereq_('./empty_pathinfo');
  59294. var convertToConstraints = _dereq_('./convert_to_constraints');
  59295. var closeBoundaries = _dereq_('./close_boundaries');
  59296. var constants = _dereq_('./constants');
  59297. var costConstants = constants.LABELOPTIMIZER;
  59298. exports.plot = function plot(gd, plotinfo, cdcontours, contourLayer) {
  59299. var xa = plotinfo.xaxis;
  59300. var ya = plotinfo.yaxis;
  59301. var fullLayout = gd._fullLayout;
  59302. Lib.makeTraceGroups(contourLayer, cdcontours, 'contour').each(function(cd) {
  59303. var plotGroup = d3.select(this);
  59304. var cd0 = cd[0];
  59305. var trace = cd0.trace;
  59306. var x = cd0.x;
  59307. var y = cd0.y;
  59308. var contours = trace.contours;
  59309. var pathinfo = emptyPathinfo(contours, plotinfo, cd0);
  59310. // use a heatmap to fill - draw it behind the lines
  59311. var heatmapColoringLayer = Lib.ensureSingle(plotGroup, 'g', 'heatmapcoloring');
  59312. var cdheatmaps = [];
  59313. if(contours.coloring === 'heatmap') {
  59314. if(trace.zauto && (trace.autocontour === false)) {
  59315. trace._input.zmin = trace.zmin =
  59316. contours.start - contours.size / 2;
  59317. trace._input.zmax = trace.zmax =
  59318. trace.zmin + pathinfo.length * contours.size;
  59319. }
  59320. cdheatmaps = [cd];
  59321. }
  59322. heatmapPlot(gd, plotinfo, cdheatmaps, heatmapColoringLayer);
  59323. makeCrossings(pathinfo);
  59324. findAllPaths(pathinfo);
  59325. var leftedge = xa.c2p(x[0], true),
  59326. rightedge = xa.c2p(x[x.length - 1], true),
  59327. bottomedge = ya.c2p(y[0], true),
  59328. topedge = ya.c2p(y[y.length - 1], true),
  59329. perimeter = [
  59330. [leftedge, topedge],
  59331. [rightedge, topedge],
  59332. [rightedge, bottomedge],
  59333. [leftedge, bottomedge]
  59334. ];
  59335. var fillPathinfo = pathinfo;
  59336. if(contours.type === 'constraint') {
  59337. fillPathinfo = convertToConstraints(pathinfo, contours._operation);
  59338. closeBoundaries(fillPathinfo, contours._operation, perimeter, trace);
  59339. }
  59340. // draw everything
  59341. makeBackground(plotGroup, perimeter, contours);
  59342. makeFills(plotGroup, fillPathinfo, perimeter, contours);
  59343. makeLinesAndLabels(plotGroup, pathinfo, gd, cd0, contours, perimeter);
  59344. clipGaps(plotGroup, plotinfo, fullLayout._clips, cd0, perimeter);
  59345. });
  59346. };
  59347. function makeBackground(plotgroup, perimeter, contours) {
  59348. var bggroup = Lib.ensureSingle(plotgroup, 'g', 'contourbg');
  59349. var bgfill = bggroup.selectAll('path')
  59350. .data(contours.coloring === 'fill' ? [0] : []);
  59351. bgfill.enter().append('path');
  59352. bgfill.exit().remove();
  59353. bgfill
  59354. .attr('d', 'M' + perimeter.join('L') + 'Z')
  59355. .style('stroke', 'none');
  59356. }
  59357. function makeFills(plotgroup, pathinfo, perimeter, contours) {
  59358. var fillgroup = Lib.ensureSingle(plotgroup, 'g', 'contourfill');
  59359. var fillitems = fillgroup.selectAll('path')
  59360. .data(contours.coloring === 'fill' || (contours.type === 'constraint' && contours._operation !== '=') ? pathinfo : []);
  59361. fillitems.enter().append('path');
  59362. fillitems.exit().remove();
  59363. fillitems.each(function(pi) {
  59364. // join all paths for this level together into a single path
  59365. // first follow clockwise around the perimeter to close any open paths
  59366. // if the whole perimeter is above this level, start with a path
  59367. // enclosing the whole thing. With all that, the parity should mean
  59368. // that we always fill everything above the contour, nothing below
  59369. var fullpath = joinAllPaths(pi, perimeter);
  59370. if(!fullpath) d3.select(this).remove();
  59371. else d3.select(this).attr('d', fullpath).style('stroke', 'none');
  59372. });
  59373. }
  59374. function initFullPath(pi, perimeter) {
  59375. var prefixBoundary = pi.prefixBoundary;
  59376. if(prefixBoundary === undefined) {
  59377. var edgeVal2 = Math.min(pi.z[0][0], pi.z[0][1]);
  59378. prefixBoundary = (!pi.edgepaths.length && edgeVal2 > pi.level);
  59379. }
  59380. if(prefixBoundary) {
  59381. // TODO: why does ^^ not work for constraints?
  59382. // pi.prefixBoundary gets set by closeBoundaries
  59383. return 'M' + perimeter.join('L') + 'Z';
  59384. }
  59385. return '';
  59386. }
  59387. function joinAllPaths(pi, perimeter) {
  59388. var fullpath = initFullPath(pi, perimeter),
  59389. i = 0,
  59390. startsleft = pi.edgepaths.map(function(v, i) { return i; }),
  59391. newloop = true,
  59392. endpt,
  59393. newendpt,
  59394. cnt,
  59395. nexti,
  59396. possiblei,
  59397. addpath;
  59398. function istop(pt) { return Math.abs(pt[1] - perimeter[0][1]) < 0.01; }
  59399. function isbottom(pt) { return Math.abs(pt[1] - perimeter[2][1]) < 0.01; }
  59400. function isleft(pt) { return Math.abs(pt[0] - perimeter[0][0]) < 0.01; }
  59401. function isright(pt) { return Math.abs(pt[0] - perimeter[2][0]) < 0.01; }
  59402. while(startsleft.length) {
  59403. addpath = Drawing.smoothopen(pi.edgepaths[i], pi.smoothing);
  59404. fullpath += newloop ? addpath : addpath.replace(/^M/, 'L');
  59405. startsleft.splice(startsleft.indexOf(i), 1);
  59406. endpt = pi.edgepaths[i][pi.edgepaths[i].length - 1];
  59407. nexti = -1;
  59408. // now loop through sides, moving our endpoint until we find a new start
  59409. for(cnt = 0; cnt < 4; cnt++) { // just to prevent infinite loops
  59410. if(!endpt) {
  59411. Lib.log('Missing end?', i, pi);
  59412. break;
  59413. }
  59414. if(istop(endpt) && !isright(endpt)) newendpt = perimeter[1]; // right top
  59415. else if(isleft(endpt)) newendpt = perimeter[0]; // left top
  59416. else if(isbottom(endpt)) newendpt = perimeter[3]; // right bottom
  59417. else if(isright(endpt)) newendpt = perimeter[2]; // left bottom
  59418. for(possiblei = 0; possiblei < pi.edgepaths.length; possiblei++) {
  59419. var ptNew = pi.edgepaths[possiblei][0];
  59420. // is ptNew on the (horz. or vert.) segment from endpt to newendpt?
  59421. if(Math.abs(endpt[0] - newendpt[0]) < 0.01) {
  59422. if(Math.abs(endpt[0] - ptNew[0]) < 0.01 &&
  59423. (ptNew[1] - endpt[1]) * (newendpt[1] - ptNew[1]) >= 0) {
  59424. newendpt = ptNew;
  59425. nexti = possiblei;
  59426. }
  59427. }
  59428. else if(Math.abs(endpt[1] - newendpt[1]) < 0.01) {
  59429. if(Math.abs(endpt[1] - ptNew[1]) < 0.01 &&
  59430. (ptNew[0] - endpt[0]) * (newendpt[0] - ptNew[0]) >= 0) {
  59431. newendpt = ptNew;
  59432. nexti = possiblei;
  59433. }
  59434. }
  59435. else {
  59436. Lib.log('endpt to newendpt is not vert. or horz.',
  59437. endpt, newendpt, ptNew);
  59438. }
  59439. }
  59440. endpt = newendpt;
  59441. if(nexti >= 0) break;
  59442. fullpath += 'L' + newendpt;
  59443. }
  59444. if(nexti === pi.edgepaths.length) {
  59445. Lib.log('unclosed perimeter path');
  59446. break;
  59447. }
  59448. i = nexti;
  59449. // if we closed back on a loop we already included,
  59450. // close it and start a new loop
  59451. newloop = (startsleft.indexOf(i) === -1);
  59452. if(newloop) {
  59453. i = startsleft[0];
  59454. fullpath += 'Z';
  59455. }
  59456. }
  59457. // finally add the interior paths
  59458. for(i = 0; i < pi.paths.length; i++) {
  59459. fullpath += Drawing.smoothclosed(pi.paths[i], pi.smoothing);
  59460. }
  59461. return fullpath;
  59462. }
  59463. function makeLinesAndLabels(plotgroup, pathinfo, gd, cd0, contours, perimeter) {
  59464. var lineContainer = Lib.ensureSingle(plotgroup, 'g', 'contourlines');
  59465. var showLines = contours.showlines !== false;
  59466. var showLabels = contours.showlabels;
  59467. var clipLinesForLabels = showLines && showLabels;
  59468. // Even if we're not going to show lines, we need to create them
  59469. // if we're showing labels, because the fill paths include the perimeter
  59470. // so can't be used to position the labels correctly.
  59471. // In this case we'll remove the lines after making the labels.
  59472. var linegroup = exports.createLines(lineContainer, showLines || showLabels, pathinfo);
  59473. var lineClip = exports.createLineClip(lineContainer, clipLinesForLabels,
  59474. gd._fullLayout._clips, cd0.trace.uid);
  59475. var labelGroup = plotgroup.selectAll('g.contourlabels')
  59476. .data(showLabels ? [0] : []);
  59477. labelGroup.exit().remove();
  59478. labelGroup.enter().append('g')
  59479. .classed('contourlabels', true);
  59480. if(showLabels) {
  59481. var labelClipPathData = [perimeter];
  59482. var labelData = [];
  59483. // invalidate the getTextLocation cache in case paths changed
  59484. Lib.clearLocationCache();
  59485. var contourFormat = exports.labelFormatter(contours, cd0.t.cb, gd._fullLayout);
  59486. var dummyText = Drawing.tester.append('text')
  59487. .attr('data-notex', 1)
  59488. .call(Drawing.font, contours.labelfont);
  59489. var xLen = pathinfo[0].xaxis._length;
  59490. var yLen = pathinfo[0].yaxis._length;
  59491. // visible bounds of the contour trace (and the midpoints, to
  59492. // help with cost calculations)
  59493. var bounds = {
  59494. left: Math.max(perimeter[0][0], 0),
  59495. right: Math.min(perimeter[2][0], xLen),
  59496. top: Math.max(perimeter[0][1], 0),
  59497. bottom: Math.min(perimeter[2][1], yLen)
  59498. };
  59499. bounds.middle = (bounds.top + bounds.bottom) / 2;
  59500. bounds.center = (bounds.left + bounds.right) / 2;
  59501. var plotDiagonal = Math.sqrt(xLen * xLen + yLen * yLen);
  59502. // the path length to use to scale the number of labels to draw:
  59503. var normLength = constants.LABELDISTANCE * plotDiagonal /
  59504. Math.max(1, pathinfo.length / constants.LABELINCREASE);
  59505. linegroup.each(function(d) {
  59506. var textOpts = exports.calcTextOpts(d.level, contourFormat, dummyText, gd);
  59507. d3.select(this).selectAll('path').each(function() {
  59508. var path = this;
  59509. var pathBounds = Lib.getVisibleSegment(path, bounds, textOpts.height / 2);
  59510. if(!pathBounds) return;
  59511. if(pathBounds.len < (textOpts.width + textOpts.height) * constants.LABELMIN) return;
  59512. var maxLabels = Math.min(Math.ceil(pathBounds.len / normLength),
  59513. constants.LABELMAX);
  59514. for(var i = 0; i < maxLabels; i++) {
  59515. var loc = exports.findBestTextLocation(path, pathBounds, textOpts,
  59516. labelData, bounds);
  59517. if(!loc) break;
  59518. exports.addLabelData(loc, textOpts, labelData, labelClipPathData);
  59519. }
  59520. });
  59521. });
  59522. dummyText.remove();
  59523. exports.drawLabels(labelGroup, labelData, gd, lineClip,
  59524. clipLinesForLabels ? labelClipPathData : null);
  59525. }
  59526. if(showLabels && !showLines) linegroup.remove();
  59527. }
  59528. exports.createLines = function(lineContainer, makeLines, pathinfo) {
  59529. var smoothing = pathinfo[0].smoothing;
  59530. var linegroup = lineContainer.selectAll('g.contourlevel')
  59531. .data(makeLines ? pathinfo : []);
  59532. linegroup.exit().remove();
  59533. linegroup.enter().append('g')
  59534. .classed('contourlevel', true);
  59535. if(makeLines) {
  59536. // pedgepaths / ppaths are used by contourcarpet, for the paths transformed from a/b to x/y
  59537. // edgepaths / paths are used by contour since it's in x/y from the start
  59538. var opencontourlines = linegroup.selectAll('path.openline')
  59539. .data(function(d) { return d.pedgepaths || d.edgepaths; });
  59540. opencontourlines.exit().remove();
  59541. opencontourlines.enter().append('path')
  59542. .classed('openline', true);
  59543. opencontourlines
  59544. .attr('d', function(d) {
  59545. return Drawing.smoothopen(d, smoothing);
  59546. })
  59547. .style('stroke-miterlimit', 1)
  59548. .style('vector-effect', 'non-scaling-stroke');
  59549. var closedcontourlines = linegroup.selectAll('path.closedline')
  59550. .data(function(d) { return d.ppaths || d.paths; });
  59551. closedcontourlines.exit().remove();
  59552. closedcontourlines.enter().append('path')
  59553. .classed('closedline', true);
  59554. closedcontourlines
  59555. .attr('d', function(d) {
  59556. return Drawing.smoothclosed(d, smoothing);
  59557. })
  59558. .style('stroke-miterlimit', 1)
  59559. .style('vector-effect', 'non-scaling-stroke');
  59560. }
  59561. return linegroup;
  59562. };
  59563. exports.createLineClip = function(lineContainer, clipLinesForLabels, clips, uid) {
  59564. var clipId = clipLinesForLabels ? ('clipline' + uid) : null;
  59565. var lineClip = clips.selectAll('#' + clipId)
  59566. .data(clipLinesForLabels ? [0] : []);
  59567. lineClip.exit().remove();
  59568. lineClip.enter().append('clipPath')
  59569. .classed('contourlineclip', true)
  59570. .attr('id', clipId);
  59571. Drawing.setClipUrl(lineContainer, clipId);
  59572. return lineClip;
  59573. };
  59574. exports.labelFormatter = function(contours, colorbar, fullLayout) {
  59575. if(contours.labelformat) {
  59576. return fullLayout._d3locale.numberFormat(contours.labelformat);
  59577. }
  59578. else {
  59579. var formatAxis;
  59580. if(colorbar) {
  59581. formatAxis = colorbar.axis;
  59582. }
  59583. else {
  59584. formatAxis = {
  59585. type: 'linear',
  59586. _id: 'ycontour',
  59587. showexponent: 'all',
  59588. exponentformat: 'B'
  59589. };
  59590. if(contours.type === 'constraint') {
  59591. var value = contours.value;
  59592. if(Array.isArray(value)) {
  59593. formatAxis.range = [value[0], value[value.length - 1]];
  59594. }
  59595. else formatAxis.range = [value, value];
  59596. }
  59597. else {
  59598. formatAxis.range = [contours.start, contours.end];
  59599. formatAxis.nticks = (contours.end - contours.start) / contours.size;
  59600. }
  59601. if(formatAxis.range[0] === formatAxis.range[1]) {
  59602. formatAxis.range[1] += formatAxis.range[0] || 1;
  59603. }
  59604. if(!formatAxis.nticks) formatAxis.nticks = 1000;
  59605. setConvert(formatAxis, fullLayout);
  59606. Axes.prepTicks(formatAxis);
  59607. formatAxis._tmin = null;
  59608. formatAxis._tmax = null;
  59609. }
  59610. return function(v) {
  59611. return Axes.tickText(formatAxis, v).text;
  59612. };
  59613. }
  59614. };
  59615. exports.calcTextOpts = function(level, contourFormat, dummyText, gd) {
  59616. var text = contourFormat(level);
  59617. dummyText.text(text)
  59618. .call(svgTextUtils.convertToTspans, gd);
  59619. var bBox = Drawing.bBox(dummyText.node(), true);
  59620. return {
  59621. text: text,
  59622. width: bBox.width,
  59623. height: bBox.height,
  59624. level: level,
  59625. dy: (bBox.top + bBox.bottom) / 2
  59626. };
  59627. };
  59628. exports.findBestTextLocation = function(path, pathBounds, textOpts, labelData, plotBounds) {
  59629. var textWidth = textOpts.width;
  59630. var p0, dp, pMax, pMin, loc;
  59631. if(pathBounds.isClosed) {
  59632. dp = pathBounds.len / costConstants.INITIALSEARCHPOINTS;
  59633. p0 = pathBounds.min + dp / 2;
  59634. pMax = pathBounds.max;
  59635. }
  59636. else {
  59637. dp = (pathBounds.len - textWidth) / (costConstants.INITIALSEARCHPOINTS + 1);
  59638. p0 = pathBounds.min + dp + textWidth / 2;
  59639. pMax = pathBounds.max - (dp + textWidth) / 2;
  59640. }
  59641. var cost = Infinity;
  59642. for(var j = 0; j < costConstants.ITERATIONS; j++) {
  59643. for(var p = p0; p < pMax; p += dp) {
  59644. var newLocation = Lib.getTextLocation(path, pathBounds.total, p, textWidth);
  59645. var newCost = locationCost(newLocation, textOpts, labelData, plotBounds);
  59646. if(newCost < cost) {
  59647. cost = newCost;
  59648. loc = newLocation;
  59649. pMin = p;
  59650. }
  59651. }
  59652. if(cost > costConstants.MAXCOST * 2) break;
  59653. // subsequent iterations just look half steps away from the
  59654. // best we found in the previous iteration
  59655. if(j) dp /= 2;
  59656. p0 = pMin - dp / 2;
  59657. pMax = p0 + dp * 1.5;
  59658. }
  59659. if(cost <= costConstants.MAXCOST) return loc;
  59660. };
  59661. /*
  59662. * locationCost: a cost function for label locations
  59663. * composed of three kinds of penalty:
  59664. * - for open paths, being close to the end of the path
  59665. * - the angle away from horizontal
  59666. * - being too close to already placed neighbors
  59667. */
  59668. function locationCost(loc, textOpts, labelData, bounds) {
  59669. var halfWidth = textOpts.width / 2;
  59670. var halfHeight = textOpts.height / 2;
  59671. var x = loc.x;
  59672. var y = loc.y;
  59673. var theta = loc.theta;
  59674. var dx = Math.cos(theta) * halfWidth;
  59675. var dy = Math.sin(theta) * halfWidth;
  59676. // cost for being near an edge
  59677. var normX = ((x > bounds.center) ? (bounds.right - x) : (x - bounds.left)) /
  59678. (dx + Math.abs(Math.sin(theta) * halfHeight));
  59679. var normY = ((y > bounds.middle) ? (bounds.bottom - y) : (y - bounds.top)) /
  59680. (Math.abs(dy) + Math.cos(theta) * halfHeight);
  59681. if(normX < 1 || normY < 1) return Infinity;
  59682. var cost = costConstants.EDGECOST * (1 / (normX - 1) + 1 / (normY - 1));
  59683. // cost for not being horizontal
  59684. cost += costConstants.ANGLECOST * theta * theta;
  59685. // cost for being close to other labels
  59686. var x1 = x - dx;
  59687. var y1 = y - dy;
  59688. var x2 = x + dx;
  59689. var y2 = y + dy;
  59690. for(var i = 0; i < labelData.length; i++) {
  59691. var labeli = labelData[i];
  59692. var dxd = Math.cos(labeli.theta) * labeli.width / 2;
  59693. var dyd = Math.sin(labeli.theta) * labeli.width / 2;
  59694. var dist = Lib.segmentDistance(
  59695. x1, y1,
  59696. x2, y2,
  59697. labeli.x - dxd, labeli.y - dyd,
  59698. labeli.x + dxd, labeli.y + dyd
  59699. ) * 2 / (textOpts.height + labeli.height);
  59700. var sameLevel = labeli.level === textOpts.level;
  59701. var distOffset = sameLevel ? costConstants.SAMELEVELDISTANCE : 1;
  59702. if(dist <= distOffset) return Infinity;
  59703. var distFactor = costConstants.NEIGHBORCOST *
  59704. (sameLevel ? costConstants.SAMELEVELFACTOR : 1);
  59705. cost += distFactor / (dist - distOffset);
  59706. }
  59707. return cost;
  59708. }
  59709. exports.addLabelData = function(loc, textOpts, labelData, labelClipPathData) {
  59710. var halfWidth = textOpts.width / 2;
  59711. var halfHeight = textOpts.height / 2;
  59712. var x = loc.x;
  59713. var y = loc.y;
  59714. var theta = loc.theta;
  59715. var sin = Math.sin(theta);
  59716. var cos = Math.cos(theta);
  59717. var dxw = halfWidth * cos;
  59718. var dxh = halfHeight * sin;
  59719. var dyw = halfWidth * sin;
  59720. var dyh = -halfHeight * cos;
  59721. var bBoxPts = [
  59722. [x - dxw - dxh, y - dyw - dyh],
  59723. [x + dxw - dxh, y + dyw - dyh],
  59724. [x + dxw + dxh, y + dyw + dyh],
  59725. [x - dxw + dxh, y - dyw + dyh],
  59726. ];
  59727. labelData.push({
  59728. text: textOpts.text,
  59729. x: x,
  59730. y: y,
  59731. dy: textOpts.dy,
  59732. theta: theta,
  59733. level: textOpts.level,
  59734. width: textOpts.width,
  59735. height: textOpts.height
  59736. });
  59737. labelClipPathData.push(bBoxPts);
  59738. };
  59739. exports.drawLabels = function(labelGroup, labelData, gd, lineClip, labelClipPathData) {
  59740. var labels = labelGroup.selectAll('text')
  59741. .data(labelData, function(d) {
  59742. return d.text + ',' + d.x + ',' + d.y + ',' + d.theta;
  59743. });
  59744. labels.exit().remove();
  59745. labels.enter().append('text')
  59746. .attr({
  59747. 'data-notex': 1,
  59748. 'text-anchor': 'middle'
  59749. })
  59750. .each(function(d) {
  59751. var x = d.x + Math.sin(d.theta) * d.dy;
  59752. var y = d.y - Math.cos(d.theta) * d.dy;
  59753. d3.select(this)
  59754. .text(d.text)
  59755. .attr({
  59756. x: x,
  59757. y: y,
  59758. transform: 'rotate(' + (180 * d.theta / Math.PI) + ' ' + x + ' ' + y + ')'
  59759. })
  59760. .call(svgTextUtils.convertToTspans, gd);
  59761. });
  59762. if(labelClipPathData) {
  59763. var clipPath = '';
  59764. for(var i = 0; i < labelClipPathData.length; i++) {
  59765. clipPath += 'M' + labelClipPathData[i].join('L') + 'Z';
  59766. }
  59767. var lineClipPath = Lib.ensureSingle(lineClip, 'path', '');
  59768. lineClipPath.attr('d', clipPath);
  59769. }
  59770. };
  59771. function clipGaps(plotGroup, plotinfo, clips, cd0, perimeter) {
  59772. var clipId = 'clip' + cd0.trace.uid;
  59773. var clipPath = clips.selectAll('#' + clipId)
  59774. .data(cd0.trace.connectgaps ? [] : [0]);
  59775. clipPath.enter().append('clipPath')
  59776. .classed('contourclip', true)
  59777. .attr('id', clipId);
  59778. clipPath.exit().remove();
  59779. if(cd0.trace.connectgaps === false) {
  59780. var clipPathInfo = {
  59781. // fraction of the way from missing to present point
  59782. // to draw the boundary.
  59783. // if you make this 1 (or 1-epsilon) then a point in
  59784. // a sea of missing data will disappear entirely.
  59785. level: 0.9,
  59786. crossings: {},
  59787. starts: [],
  59788. edgepaths: [],
  59789. paths: [],
  59790. xaxis: plotinfo.xaxis,
  59791. yaxis: plotinfo.yaxis,
  59792. x: cd0.x,
  59793. y: cd0.y,
  59794. // 0 = no data, 1 = data
  59795. z: makeClipMask(cd0),
  59796. smoothing: 0
  59797. };
  59798. makeCrossings([clipPathInfo]);
  59799. findAllPaths([clipPathInfo]);
  59800. var fullpath = joinAllPaths(clipPathInfo, perimeter);
  59801. var path = Lib.ensureSingle(clipPath, 'path', '');
  59802. path.attr('d', fullpath);
  59803. }
  59804. else clipId = null;
  59805. plotGroup.call(Drawing.setClipUrl, clipId);
  59806. }
  59807. function makeClipMask(cd0) {
  59808. var empties = cd0.trace._emptypoints,
  59809. z = [],
  59810. m = cd0.z.length,
  59811. n = cd0.z[0].length,
  59812. i,
  59813. row = [],
  59814. emptyPoint;
  59815. for(i = 0; i < n; i++) row.push(1);
  59816. for(i = 0; i < m; i++) z.push(row.slice());
  59817. for(i = 0; i < empties.length; i++) {
  59818. emptyPoint = empties[i];
  59819. z[emptyPoint[0]][emptyPoint[1]] = 0;
  59820. }
  59821. // save this mask to determine whether to show this data in hover
  59822. cd0.zmask = z;
  59823. return z;
  59824. }
  59825. },{"../../components/drawing":75,"../../lib":169,"../../lib/svg_text_utils":191,"../../plots/cartesian/axes":214,"../../plots/cartesian/set_convert":232,"../heatmap/plot":328,"./close_boundaries":296,"./constants":298,"./convert_to_constraints":302,"./empty_pathinfo":304,"./find_all_paths":306,"./make_crossings":311,"d3":16}],313:[function(_dereq_,module,exports){
  59826. /**
  59827. * Copyright 2012-2018, Plotly, Inc.
  59828. * All rights reserved.
  59829. *
  59830. * This source code is licensed under the MIT license found in the
  59831. * LICENSE file in the root directory of this source tree.
  59832. */
  59833. 'use strict';
  59834. var Axes = _dereq_('../../plots/cartesian/axes');
  59835. var Lib = _dereq_('../../lib');
  59836. module.exports = function setContours(trace) {
  59837. var contours = trace.contours;
  59838. // check if we need to auto-choose contour levels
  59839. if(trace.autocontour) {
  59840. var zmin = trace.zmin;
  59841. var zmax = trace.zmax;
  59842. if(zmin === undefined || zmax === undefined) {
  59843. zmin = Lib.aggNums(Math.min, null, trace._z);
  59844. zmax = Lib.aggNums(Math.max, null, trace._z);
  59845. }
  59846. var dummyAx = autoContours(zmin, zmax, trace.ncontours);
  59847. contours.size = dummyAx.dtick;
  59848. contours.start = Axes.tickFirst(dummyAx);
  59849. dummyAx.range.reverse();
  59850. contours.end = Axes.tickFirst(dummyAx);
  59851. if(contours.start === zmin) contours.start += contours.size;
  59852. if(contours.end === zmax) contours.end -= contours.size;
  59853. // if you set a small ncontours, *and* the ends are exactly on zmin/zmax
  59854. // there's an edge case where start > end now. Make sure there's at least
  59855. // one meaningful contour, put it midway between the crossed values
  59856. if(contours.start > contours.end) {
  59857. contours.start = contours.end = (contours.start + contours.end) / 2;
  59858. }
  59859. // copy auto-contour info back to the source data.
  59860. // previously we copied the whole contours object back, but that had
  59861. // other info (coloring, showlines) that should be left to supplyDefaults
  59862. if(!trace._input.contours) trace._input.contours = {};
  59863. Lib.extendFlat(trace._input.contours, {
  59864. start: contours.start,
  59865. end: contours.end,
  59866. size: contours.size
  59867. });
  59868. trace._input.autocontour = true;
  59869. }
  59870. else if(contours.type !== 'constraint') {
  59871. // sanity checks on manually-supplied start/end/size
  59872. var start = contours.start,
  59873. end = contours.end,
  59874. inputContours = trace._input.contours;
  59875. if(start > end) {
  59876. contours.start = inputContours.start = end;
  59877. end = contours.end = inputContours.end = start;
  59878. start = contours.start;
  59879. }
  59880. if(!(contours.size > 0)) {
  59881. var sizeOut;
  59882. if(start === end) sizeOut = 1;
  59883. else sizeOut = autoContours(start, end, trace.ncontours).dtick;
  59884. inputContours.size = contours.size = sizeOut;
  59885. }
  59886. }
  59887. };
  59888. /*
  59889. * autoContours: make a dummy axis object with dtick we can use
  59890. * as contours.size, and if needed we can use Axes.tickFirst
  59891. * with this axis object to calculate the start and end too
  59892. *
  59893. * start: the value to start the contours at
  59894. * end: the value to end at (must be > start)
  59895. * ncontours: max number of contours to make, like roughDTick
  59896. *
  59897. * returns: an axis object
  59898. */
  59899. function autoContours(start, end, ncontours) {
  59900. var dummyAx = {
  59901. type: 'linear',
  59902. range: [start, end]
  59903. };
  59904. Axes.autoTicks(
  59905. dummyAx,
  59906. (end - start) / (ncontours || 15)
  59907. );
  59908. return dummyAx;
  59909. }
  59910. },{"../../lib":169,"../../plots/cartesian/axes":214}],314:[function(_dereq_,module,exports){
  59911. /**
  59912. * Copyright 2012-2018, Plotly, Inc.
  59913. * All rights reserved.
  59914. *
  59915. * This source code is licensed under the MIT license found in the
  59916. * LICENSE file in the root directory of this source tree.
  59917. */
  59918. 'use strict';
  59919. var d3 = _dereq_('d3');
  59920. var Drawing = _dereq_('../../components/drawing');
  59921. var heatmapStyle = _dereq_('../heatmap/style');
  59922. var makeColorMap = _dereq_('./make_color_map');
  59923. module.exports = function style(gd) {
  59924. var contours = d3.select(gd).selectAll('g.contour');
  59925. contours.style('opacity', function(d) {
  59926. return d[0].trace.opacity;
  59927. });
  59928. contours.each(function(d) {
  59929. var c = d3.select(this);
  59930. var trace = d[0].trace;
  59931. var contours = trace.contours;
  59932. var line = trace.line;
  59933. var cs = contours.size || 1;
  59934. var start = contours.start;
  59935. // for contourcarpet only - is this a constraint-type contour trace?
  59936. var isConstraintType = contours.type === 'constraint';
  59937. var colorLines = !isConstraintType && contours.coloring === 'lines';
  59938. var colorFills = !isConstraintType && contours.coloring === 'fill';
  59939. var colorMap = (colorLines || colorFills) ? makeColorMap(trace) : null;
  59940. c.selectAll('g.contourlevel').each(function(d) {
  59941. d3.select(this).selectAll('path')
  59942. .call(Drawing.lineGroupStyle,
  59943. line.width,
  59944. colorLines ? colorMap(d.level) : line.color,
  59945. line.dash);
  59946. });
  59947. var labelFont = contours.labelfont;
  59948. c.selectAll('g.contourlabels text').each(function(d) {
  59949. Drawing.font(d3.select(this), {
  59950. family: labelFont.family,
  59951. size: labelFont.size,
  59952. color: labelFont.color || (colorLines ? colorMap(d.level) : line.color)
  59953. });
  59954. });
  59955. if(isConstraintType) {
  59956. c.selectAll('g.contourfill path')
  59957. .style('fill', trace.fillcolor);
  59958. }
  59959. else if(colorFills) {
  59960. var firstFill;
  59961. c.selectAll('g.contourfill path')
  59962. .style('fill', function(d) {
  59963. if(firstFill === undefined) firstFill = d.level;
  59964. return colorMap(d.level + 0.5 * cs);
  59965. });
  59966. if(firstFill === undefined) firstFill = start;
  59967. c.selectAll('g.contourbg path')
  59968. .style('fill', colorMap(firstFill - 0.5 * cs));
  59969. }
  59970. });
  59971. heatmapStyle(gd);
  59972. };
  59973. },{"../../components/drawing":75,"../heatmap/style":329,"./make_color_map":310,"d3":16}],315:[function(_dereq_,module,exports){
  59974. /**
  59975. * Copyright 2012-2018, Plotly, Inc.
  59976. * All rights reserved.
  59977. *
  59978. * This source code is licensed under the MIT license found in the
  59979. * LICENSE file in the root directory of this source tree.
  59980. */
  59981. 'use strict';
  59982. var colorscaleDefaults = _dereq_('../../components/colorscale/defaults');
  59983. var handleLabelDefaults = _dereq_('./label_defaults');
  59984. module.exports = function handleStyleDefaults(traceIn, traceOut, coerce, layout, opts) {
  59985. var coloring = coerce('contours.coloring');
  59986. var showLines;
  59987. var lineColor = '';
  59988. if(coloring === 'fill') showLines = coerce('contours.showlines');
  59989. if(showLines !== false) {
  59990. if(coloring !== 'lines') lineColor = coerce('line.color', '#000');
  59991. coerce('line.width', 0.5);
  59992. coerce('line.dash');
  59993. }
  59994. if(coloring !== 'none') {
  59995. // plots/plots always coerces showlegend to true, but in this case
  59996. // we default to false and (by default) show a colorbar instead
  59997. if(traceIn.showlegend !== true) traceOut.showlegend = false;
  59998. traceOut._dfltShowLegend = false;
  59999. colorscaleDefaults(
  60000. traceIn, traceOut, layout, coerce, {prefix: '', cLetter: 'z'}
  60001. );
  60002. }
  60003. coerce('line.smoothing');
  60004. handleLabelDefaults(coerce, layout, lineColor, opts);
  60005. };
  60006. },{"../../components/colorscale/defaults":60,"./label_defaults":309}],316:[function(_dereq_,module,exports){
  60007. /**
  60008. * Copyright 2012-2018, Plotly, Inc.
  60009. * All rights reserved.
  60010. *
  60011. * This source code is licensed under the MIT license found in the
  60012. * LICENSE file in the root directory of this source tree.
  60013. */
  60014. 'use strict';
  60015. var scatterAttrs = _dereq_('../scatter/attributes');
  60016. var colorscaleAttrs = _dereq_('../../components/colorscale/attributes');
  60017. var colorbarAttrs = _dereq_('../../components/colorbar/attributes');
  60018. var extendFlat = _dereq_('../../lib/extend').extendFlat;
  60019. module.exports = extendFlat({
  60020. z: {
  60021. valType: 'data_array',
  60022. editType: 'calc',
  60023. },
  60024. x: extendFlat({}, scatterAttrs.x, {impliedEdits: {xtype: 'array'}}),
  60025. x0: extendFlat({}, scatterAttrs.x0, {impliedEdits: {xtype: 'scaled'}}),
  60026. dx: extendFlat({}, scatterAttrs.dx, {impliedEdits: {xtype: 'scaled'}}),
  60027. y: extendFlat({}, scatterAttrs.y, {impliedEdits: {ytype: 'array'}}),
  60028. y0: extendFlat({}, scatterAttrs.y0, {impliedEdits: {ytype: 'scaled'}}),
  60029. dy: extendFlat({}, scatterAttrs.dy, {impliedEdits: {ytype: 'scaled'}}),
  60030. text: {
  60031. valType: 'data_array',
  60032. editType: 'calc',
  60033. },
  60034. transpose: {
  60035. valType: 'boolean',
  60036. dflt: false,
  60037. editType: 'calc',
  60038. },
  60039. xtype: {
  60040. valType: 'enumerated',
  60041. values: ['array', 'scaled'],
  60042. editType: 'calc+clearAxisTypes',
  60043. },
  60044. ytype: {
  60045. valType: 'enumerated',
  60046. values: ['array', 'scaled'],
  60047. editType: 'calc+clearAxisTypes',
  60048. },
  60049. zsmooth: {
  60050. valType: 'enumerated',
  60051. values: ['fast', 'best', false],
  60052. dflt: false,
  60053. editType: 'calc',
  60054. },
  60055. connectgaps: {
  60056. valType: 'boolean',
  60057. dflt: false,
  60058. editType: 'calc',
  60059. },
  60060. xgap: {
  60061. valType: 'number',
  60062. dflt: 0,
  60063. min: 0,
  60064. editType: 'plot',
  60065. },
  60066. ygap: {
  60067. valType: 'number',
  60068. dflt: 0,
  60069. min: 0,
  60070. editType: 'plot',
  60071. },
  60072. zhoverformat: {
  60073. valType: 'string',
  60074. dflt: '',
  60075. editType: 'none',
  60076. },
  60077. },
  60078. colorscaleAttrs('', {
  60079. cLetter: 'z',
  60080. autoColorDflt: false
  60081. }),
  60082. { colorbar: colorbarAttrs }
  60083. );
  60084. },{"../../components/colorbar/attributes":51,"../../components/colorscale/attributes":57,"../../lib/extend":163,"../scatter/attributes":366}],317:[function(_dereq_,module,exports){
  60085. /**
  60086. * Copyright 2012-2018, Plotly, Inc.
  60087. * All rights reserved.
  60088. *
  60089. * This source code is licensed under the MIT license found in the
  60090. * LICENSE file in the root directory of this source tree.
  60091. */
  60092. 'use strict';
  60093. var Registry = _dereq_('../../registry');
  60094. var Lib = _dereq_('../../lib');
  60095. var Axes = _dereq_('../../plots/cartesian/axes');
  60096. var histogram2dCalc = _dereq_('../histogram2d/calc');
  60097. var colorscaleCalc = _dereq_('../../components/colorscale/calc');
  60098. var convertColumnData = _dereq_('./convert_column_xyz');
  60099. var maxRowLength = _dereq_('./max_row_length');
  60100. var clean2dArray = _dereq_('./clean_2d_array');
  60101. var interp2d = _dereq_('./interp2d');
  60102. var findEmpties = _dereq_('./find_empties');
  60103. var makeBoundArray = _dereq_('./make_bound_array');
  60104. module.exports = function calc(gd, trace) {
  60105. // prepare the raw data
  60106. // run makeCalcdata on x and y even for heatmaps, in case of category mappings
  60107. var xa = Axes.getFromId(gd, trace.xaxis || 'x'),
  60108. ya = Axes.getFromId(gd, trace.yaxis || 'y'),
  60109. isContour = Registry.traceIs(trace, 'contour'),
  60110. isHist = Registry.traceIs(trace, 'histogram'),
  60111. isGL2D = Registry.traceIs(trace, 'gl2d'),
  60112. zsmooth = isContour ? 'best' : trace.zsmooth,
  60113. x,
  60114. x0,
  60115. dx,
  60116. y,
  60117. y0,
  60118. dy,
  60119. z,
  60120. i,
  60121. binned;
  60122. // cancel minimum tick spacings (only applies to bars and boxes)
  60123. xa._minDtick = 0;
  60124. ya._minDtick = 0;
  60125. if(isHist) {
  60126. binned = histogram2dCalc(gd, trace);
  60127. x = binned.x;
  60128. x0 = binned.x0;
  60129. dx = binned.dx;
  60130. y = binned.y;
  60131. y0 = binned.y0;
  60132. dy = binned.dy;
  60133. z = binned.z;
  60134. }
  60135. else {
  60136. var zIn = trace.z;
  60137. if(Lib.isArray1D(zIn)) {
  60138. convertColumnData(trace, xa, ya, 'x', 'y', ['z']);
  60139. x = trace._x;
  60140. y = trace._y;
  60141. zIn = trace._z;
  60142. } else {
  60143. x = trace.x ? xa.makeCalcdata(trace, 'x') : [];
  60144. y = trace.y ? ya.makeCalcdata(trace, 'y') : [];
  60145. }
  60146. x0 = trace.x0 || 0;
  60147. dx = trace.dx || 1;
  60148. y0 = trace.y0 || 0;
  60149. dy = trace.dy || 1;
  60150. z = clean2dArray(zIn, trace.transpose);
  60151. if(isContour || trace.connectgaps) {
  60152. trace._emptypoints = findEmpties(z);
  60153. interp2d(z, trace._emptypoints);
  60154. }
  60155. }
  60156. function noZsmooth(msg) {
  60157. zsmooth = trace._input.zsmooth = trace.zsmooth = false;
  60158. Lib.warn('cannot use zsmooth: "fast": ' + msg);
  60159. }
  60160. // check whether we really can smooth (ie all boxes are about the same size)
  60161. if(zsmooth === 'fast') {
  60162. if(xa.type === 'log' || ya.type === 'log') {
  60163. noZsmooth('log axis found');
  60164. }
  60165. else if(!isHist) {
  60166. if(x.length) {
  60167. var avgdx = (x[x.length - 1] - x[0]) / (x.length - 1),
  60168. maxErrX = Math.abs(avgdx / 100);
  60169. for(i = 0; i < x.length - 1; i++) {
  60170. if(Math.abs(x[i + 1] - x[i] - avgdx) > maxErrX) {
  60171. noZsmooth('x scale is not linear');
  60172. break;
  60173. }
  60174. }
  60175. }
  60176. if(y.length && zsmooth === 'fast') {
  60177. var avgdy = (y[y.length - 1] - y[0]) / (y.length - 1),
  60178. maxErrY = Math.abs(avgdy / 100);
  60179. for(i = 0; i < y.length - 1; i++) {
  60180. if(Math.abs(y[i + 1] - y[i] - avgdy) > maxErrY) {
  60181. noZsmooth('y scale is not linear');
  60182. break;
  60183. }
  60184. }
  60185. }
  60186. }
  60187. }
  60188. // create arrays of brick boundaries, to be used by autorange and heatmap.plot
  60189. var xlen = maxRowLength(z);
  60190. var xIn = trace.xtype === 'scaled' ? '' : x;
  60191. var xArray = makeBoundArray(trace, xIn, x0, dx, xlen, xa);
  60192. var yIn = trace.ytype === 'scaled' ? '' : y;
  60193. var yArray = makeBoundArray(trace, yIn, y0, dy, z.length, ya);
  60194. // handled in gl2d convert step
  60195. if(!isGL2D) {
  60196. trace._extremes[xa._id] = Axes.findExtremes(xa, xArray);
  60197. trace._extremes[ya._id] = Axes.findExtremes(ya, yArray);
  60198. }
  60199. var cd0 = {
  60200. x: xArray,
  60201. y: yArray,
  60202. z: z,
  60203. text: trace._text || trace.text
  60204. };
  60205. if(xIn && xIn.length === xArray.length - 1) cd0.xCenter = xIn;
  60206. if(yIn && yIn.length === yArray.length - 1) cd0.yCenter = yIn;
  60207. if(isHist) {
  60208. cd0.xRanges = binned.xRanges;
  60209. cd0.yRanges = binned.yRanges;
  60210. cd0.pts = binned.pts;
  60211. }
  60212. // auto-z and autocolorscale if applicable
  60213. if(!isContour || trace.contours.type !== 'constraint') {
  60214. colorscaleCalc(trace, z, '', 'z');
  60215. }
  60216. if(isContour && trace.contours && trace.contours.coloring === 'heatmap') {
  60217. var dummyTrace = {
  60218. type: trace.type === 'contour' ? 'heatmap' : 'histogram2d',
  60219. xcalendar: trace.xcalendar,
  60220. ycalendar: trace.ycalendar
  60221. };
  60222. cd0.xfill = makeBoundArray(dummyTrace, xIn, x0, dx, xlen, xa);
  60223. cd0.yfill = makeBoundArray(dummyTrace, yIn, y0, dy, z.length, ya);
  60224. }
  60225. return [cd0];
  60226. };
  60227. },{"../../components/colorscale/calc":58,"../../lib":169,"../../plots/cartesian/axes":214,"../../registry":259,"../histogram2d/calc":345,"./clean_2d_array":318,"./convert_column_xyz":320,"./find_empties":322,"./interp2d":325,"./make_bound_array":326,"./max_row_length":327}],318:[function(_dereq_,module,exports){
  60228. /**
  60229. * Copyright 2012-2018, Plotly, Inc.
  60230. * All rights reserved.
  60231. *
  60232. * This source code is licensed under the MIT license found in the
  60233. * LICENSE file in the root directory of this source tree.
  60234. */
  60235. 'use strict';
  60236. var isNumeric = _dereq_('fast-isnumeric');
  60237. module.exports = function clean2dArray(zOld, transpose) {
  60238. var rowlen, collen, getCollen, old2new, i, j;
  60239. function cleanZvalue(v) {
  60240. if(!isNumeric(v)) return undefined;
  60241. return +v;
  60242. }
  60243. if(transpose) {
  60244. rowlen = 0;
  60245. for(i = 0; i < zOld.length; i++) rowlen = Math.max(rowlen, zOld[i].length);
  60246. if(rowlen === 0) return false;
  60247. getCollen = function(zOld) { return zOld.length; };
  60248. old2new = function(zOld, i, j) { return zOld[j][i]; };
  60249. }
  60250. else {
  60251. rowlen = zOld.length;
  60252. getCollen = function(zOld, i) { return zOld[i].length; };
  60253. old2new = function(zOld, i, j) { return zOld[i][j]; };
  60254. }
  60255. var zNew = new Array(rowlen);
  60256. for(i = 0; i < rowlen; i++) {
  60257. collen = getCollen(zOld, i);
  60258. zNew[i] = new Array(collen);
  60259. for(j = 0; j < collen; j++) zNew[i][j] = cleanZvalue(old2new(zOld, i, j));
  60260. }
  60261. return zNew;
  60262. };
  60263. },{"fast-isnumeric":18}],319:[function(_dereq_,module,exports){
  60264. /**
  60265. * Copyright 2012-2018, Plotly, Inc.
  60266. * All rights reserved.
  60267. *
  60268. * This source code is licensed under the MIT license found in the
  60269. * LICENSE file in the root directory of this source tree.
  60270. */
  60271. 'use strict';
  60272. module.exports = {
  60273. min: 'zmin',
  60274. max: 'zmax'
  60275. };
  60276. },{}],320:[function(_dereq_,module,exports){
  60277. /**
  60278. * Copyright 2012-2018, Plotly, Inc.
  60279. * All rights reserved.
  60280. *
  60281. * This source code is licensed under the MIT license found in the
  60282. * LICENSE file in the root directory of this source tree.
  60283. */
  60284. 'use strict';
  60285. var Lib = _dereq_('../../lib');
  60286. var BADNUM = _dereq_('../../constants/numerical').BADNUM;
  60287. module.exports = function convertColumnData(trace, ax1, ax2, var1Name, var2Name, arrayVarNames) {
  60288. var colLen = trace._length;
  60289. var col1 = trace[var1Name].slice(0, colLen);
  60290. var col2 = trace[var2Name].slice(0, colLen);
  60291. var textCol = trace.text;
  60292. var hasColumnText = (textCol !== undefined && Lib.isArray1D(textCol));
  60293. var col1Calendar = trace[var1Name + 'calendar'];
  60294. var col2Calendar = trace[var2Name + 'calendar'];
  60295. var i, j, arrayVar, newArray, arrayVarName;
  60296. for(i = 0; i < colLen; i++) {
  60297. col1[i] = ax1.d2c(col1[i], 0, col1Calendar);
  60298. col2[i] = ax2.d2c(col2[i], 0, col2Calendar);
  60299. }
  60300. var col1dv = Lib.distinctVals(col1),
  60301. col1vals = col1dv.vals,
  60302. col2dv = Lib.distinctVals(col2),
  60303. col2vals = col2dv.vals,
  60304. newArrays = [];
  60305. for(i = 0; i < arrayVarNames.length; i++) {
  60306. newArrays[i] = Lib.init2dArray(col2vals.length, col1vals.length);
  60307. }
  60308. var i1, i2, text;
  60309. if(hasColumnText) text = Lib.init2dArray(col2vals.length, col1vals.length);
  60310. for(i = 0; i < colLen; i++) {
  60311. if(col1[i] !== BADNUM && col2[i] !== BADNUM) {
  60312. i1 = Lib.findBin(col1[i] + col1dv.minDiff / 2, col1vals);
  60313. i2 = Lib.findBin(col2[i] + col2dv.minDiff / 2, col2vals);
  60314. for(j = 0; j < arrayVarNames.length; j++) {
  60315. arrayVarName = arrayVarNames[j];
  60316. arrayVar = trace[arrayVarName];
  60317. newArray = newArrays[j];
  60318. newArray[i2][i1] = arrayVar[i];
  60319. }
  60320. if(hasColumnText) text[i2][i1] = textCol[i];
  60321. }
  60322. }
  60323. trace['_' + var1Name] = col1vals;
  60324. trace['_' + var2Name] = col2vals;
  60325. for(j = 0; j < arrayVarNames.length; j++) {
  60326. trace['_' + arrayVarNames[j]] = newArrays[j];
  60327. }
  60328. if(hasColumnText) trace._text = text;
  60329. };
  60330. },{"../../constants/numerical":151,"../../lib":169}],321:[function(_dereq_,module,exports){
  60331. /**
  60332. * Copyright 2012-2018, Plotly, Inc.
  60333. * All rights reserved.
  60334. *
  60335. * This source code is licensed under the MIT license found in the
  60336. * LICENSE file in the root directory of this source tree.
  60337. */
  60338. 'use strict';
  60339. var Lib = _dereq_('../../lib');
  60340. var handleXYZDefaults = _dereq_('./xyz_defaults');
  60341. var handleStyleDefaults = _dereq_('./style_defaults');
  60342. var colorscaleDefaults = _dereq_('../../components/colorscale/defaults');
  60343. var attributes = _dereq_('./attributes');
  60344. module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout) {
  60345. function coerce(attr, dflt) {
  60346. return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);
  60347. }
  60348. var validData = handleXYZDefaults(traceIn, traceOut, coerce, layout);
  60349. if(!validData) {
  60350. traceOut.visible = false;
  60351. return;
  60352. }
  60353. coerce('text');
  60354. handleStyleDefaults(traceIn, traceOut, coerce, layout);
  60355. coerce('connectgaps', Lib.isArray1D(traceOut.z) && (traceOut.zsmooth !== false));
  60356. colorscaleDefaults(traceIn, traceOut, layout, coerce, {prefix: '', cLetter: 'z'});
  60357. };
  60358. },{"../../components/colorscale/defaults":60,"../../lib":169,"./attributes":316,"./style_defaults":330,"./xyz_defaults":331}],322:[function(_dereq_,module,exports){
  60359. /**
  60360. * Copyright 2012-2018, Plotly, Inc.
  60361. * All rights reserved.
  60362. *
  60363. * This source code is licensed under the MIT license found in the
  60364. * LICENSE file in the root directory of this source tree.
  60365. */
  60366. 'use strict';
  60367. var maxRowLength = _dereq_('./max_row_length');
  60368. /* Return a list of empty points in 2D array z
  60369. * each empty point z[i][j] gives an array [i, j, neighborCount]
  60370. * neighborCount is the count of 4 nearest neighbors that DO exist
  60371. * this is to give us an order of points to evaluate for interpolation.
  60372. * if no neighbors exist, we iteratively look for neighbors that HAVE
  60373. * neighbors, and add a fractional neighborCount
  60374. */
  60375. module.exports = function findEmpties(z) {
  60376. var empties = [],
  60377. neighborHash = {},
  60378. noNeighborList = [],
  60379. nextRow = z[0],
  60380. row = [],
  60381. blank = [0, 0, 0],
  60382. rowLength = maxRowLength(z),
  60383. prevRow,
  60384. i,
  60385. j,
  60386. thisPt,
  60387. p,
  60388. neighborCount,
  60389. newNeighborHash,
  60390. foundNewNeighbors;
  60391. for(i = 0; i < z.length; i++) {
  60392. prevRow = row;
  60393. row = nextRow;
  60394. nextRow = z[i + 1] || [];
  60395. for(j = 0; j < rowLength; j++) {
  60396. if(row[j] === undefined) {
  60397. neighborCount = (row[j - 1] !== undefined ? 1 : 0) +
  60398. (row[j + 1] !== undefined ? 1 : 0) +
  60399. (prevRow[j] !== undefined ? 1 : 0) +
  60400. (nextRow[j] !== undefined ? 1 : 0);
  60401. if(neighborCount) {
  60402. // for this purpose, don't count off-the-edge points
  60403. // as undefined neighbors
  60404. if(i === 0) neighborCount++;
  60405. if(j === 0) neighborCount++;
  60406. if(i === z.length - 1) neighborCount++;
  60407. if(j === row.length - 1) neighborCount++;
  60408. // if all neighbors that could exist do, we don't
  60409. // need this for finding farther neighbors
  60410. if(neighborCount < 4) {
  60411. neighborHash[[i, j]] = [i, j, neighborCount];
  60412. }
  60413. empties.push([i, j, neighborCount]);
  60414. }
  60415. else noNeighborList.push([i, j]);
  60416. }
  60417. }
  60418. }
  60419. while(noNeighborList.length) {
  60420. newNeighborHash = {};
  60421. foundNewNeighbors = false;
  60422. // look for cells that now have neighbors but didn't before
  60423. for(p = noNeighborList.length - 1; p >= 0; p--) {
  60424. thisPt = noNeighborList[p];
  60425. i = thisPt[0];
  60426. j = thisPt[1];
  60427. neighborCount = ((neighborHash[[i - 1, j]] || blank)[2] +
  60428. (neighborHash[[i + 1, j]] || blank)[2] +
  60429. (neighborHash[[i, j - 1]] || blank)[2] +
  60430. (neighborHash[[i, j + 1]] || blank)[2]) / 20;
  60431. if(neighborCount) {
  60432. newNeighborHash[thisPt] = [i, j, neighborCount];
  60433. noNeighborList.splice(p, 1);
  60434. foundNewNeighbors = true;
  60435. }
  60436. }
  60437. if(!foundNewNeighbors) {
  60438. throw 'findEmpties iterated with no new neighbors';
  60439. }
  60440. // put these new cells into the main neighbor list
  60441. for(thisPt in newNeighborHash) {
  60442. neighborHash[thisPt] = newNeighborHash[thisPt];
  60443. empties.push(newNeighborHash[thisPt]);
  60444. }
  60445. }
  60446. // sort the full list in descending order of neighbor count
  60447. return empties.sort(function(a, b) { return b[2] - a[2]; });
  60448. };
  60449. },{"./max_row_length":327}],323:[function(_dereq_,module,exports){
  60450. /**
  60451. * Copyright 2012-2018, Plotly, Inc.
  60452. * All rights reserved.
  60453. *
  60454. * This source code is licensed under the MIT license found in the
  60455. * LICENSE file in the root directory of this source tree.
  60456. */
  60457. 'use strict';
  60458. var Fx = _dereq_('../../components/fx');
  60459. var Lib = _dereq_('../../lib');
  60460. var Axes = _dereq_('../../plots/cartesian/axes');
  60461. module.exports = function hoverPoints(pointData, xval, yval, hovermode, hoverLayer, contour) {
  60462. var cd0 = pointData.cd[0];
  60463. var trace = cd0.trace;
  60464. var xa = pointData.xa;
  60465. var ya = pointData.ya;
  60466. var x = cd0.x;
  60467. var y = cd0.y;
  60468. var z = cd0.z;
  60469. var xc = cd0.xCenter;
  60470. var yc = cd0.yCenter;
  60471. var zmask = cd0.zmask;
  60472. var range = [trace.zmin, trace.zmax];
  60473. var zhoverformat = trace.zhoverformat;
  60474. var x2 = x;
  60475. var y2 = y;
  60476. var xl, yl, nx, ny;
  60477. if(pointData.index !== false) {
  60478. try {
  60479. nx = Math.round(pointData.index[1]);
  60480. ny = Math.round(pointData.index[0]);
  60481. }
  60482. catch(e) {
  60483. Lib.error('Error hovering on heatmap, ' +
  60484. 'pointNumber must be [row,col], found:', pointData.index);
  60485. return;
  60486. }
  60487. if(nx < 0 || nx >= z[0].length || ny < 0 || ny > z.length) {
  60488. return;
  60489. }
  60490. }
  60491. else if(Fx.inbox(xval - x[0], xval - x[x.length - 1], 0) > 0 ||
  60492. Fx.inbox(yval - y[0], yval - y[y.length - 1], 0) > 0) {
  60493. return;
  60494. }
  60495. else {
  60496. if(contour) {
  60497. var i2;
  60498. x2 = [2 * x[0] - x[1]];
  60499. for(i2 = 1; i2 < x.length; i2++) {
  60500. x2.push((x[i2] + x[i2 - 1]) / 2);
  60501. }
  60502. x2.push([2 * x[x.length - 1] - x[x.length - 2]]);
  60503. y2 = [2 * y[0] - y[1]];
  60504. for(i2 = 1; i2 < y.length; i2++) {
  60505. y2.push((y[i2] + y[i2 - 1]) / 2);
  60506. }
  60507. y2.push([2 * y[y.length - 1] - y[y.length - 2]]);
  60508. }
  60509. nx = Math.max(0, Math.min(x2.length - 2, Lib.findBin(xval, x2)));
  60510. ny = Math.max(0, Math.min(y2.length - 2, Lib.findBin(yval, y2)));
  60511. }
  60512. var x0 = xa.c2p(x[nx]),
  60513. x1 = xa.c2p(x[nx + 1]),
  60514. y0 = ya.c2p(y[ny]),
  60515. y1 = ya.c2p(y[ny + 1]);
  60516. if(contour) {
  60517. x1 = x0;
  60518. xl = x[nx];
  60519. y1 = y0;
  60520. yl = y[ny];
  60521. }
  60522. else {
  60523. xl = xc ? xc[nx] : ((x[nx] + x[nx + 1]) / 2);
  60524. yl = yc ? yc[ny] : ((y[ny] + y[ny + 1]) / 2);
  60525. if(trace.zsmooth) {
  60526. x0 = x1 = xa.c2p(xl);
  60527. y0 = y1 = ya.c2p(yl);
  60528. }
  60529. }
  60530. var zVal = z[ny][nx];
  60531. if(zmask && !zmask[ny][nx]) zVal = undefined;
  60532. var text;
  60533. if(Array.isArray(cd0.text) && Array.isArray(cd0.text[ny])) {
  60534. text = cd0.text[ny][nx];
  60535. }
  60536. var zLabel;
  60537. // dummy axis for formatting the z value
  60538. var dummyAx = {
  60539. type: 'linear',
  60540. range: range,
  60541. hoverformat: zhoverformat,
  60542. _separators: xa._separators,
  60543. _numFormat: xa._numFormat
  60544. };
  60545. var zLabelObj = Axes.tickText(dummyAx, zVal, 'hover');
  60546. zLabel = zLabelObj.text;
  60547. return [Lib.extendFlat(pointData, {
  60548. index: [ny, nx],
  60549. // never let a 2D override 1D type as closest point
  60550. distance: pointData.maxHoverDistance,
  60551. spikeDistance: pointData.maxSpikeDistance,
  60552. x0: x0,
  60553. x1: x1,
  60554. y0: y0,
  60555. y1: y1,
  60556. xLabelVal: xl,
  60557. yLabelVal: yl,
  60558. zLabelVal: zVal,
  60559. zLabel: zLabel,
  60560. text: text
  60561. })];
  60562. };
  60563. },{"../../components/fx":92,"../../lib":169,"../../plots/cartesian/axes":214}],324:[function(_dereq_,module,exports){
  60564. /**
  60565. * Copyright 2012-2018, Plotly, Inc.
  60566. * All rights reserved.
  60567. *
  60568. * This source code is licensed under the MIT license found in the
  60569. * LICENSE file in the root directory of this source tree.
  60570. */
  60571. 'use strict';
  60572. var Heatmap = {};
  60573. Heatmap.attributes = _dereq_('./attributes');
  60574. Heatmap.supplyDefaults = _dereq_('./defaults');
  60575. Heatmap.calc = _dereq_('./calc');
  60576. Heatmap.plot = _dereq_('./plot');
  60577. Heatmap.colorbar = _dereq_('./colorbar');
  60578. Heatmap.style = _dereq_('./style');
  60579. Heatmap.hoverPoints = _dereq_('./hover');
  60580. Heatmap.moduleType = 'trace';
  60581. Heatmap.name = 'heatmap';
  60582. Heatmap.basePlotModule = _dereq_('../../plots/cartesian');
  60583. Heatmap.categories = ['cartesian', 'svg', '2dMap'];
  60584. Heatmap.meta = {
  60585. };
  60586. module.exports = Heatmap;
  60587. },{"../../plots/cartesian":225,"./attributes":316,"./calc":317,"./colorbar":319,"./defaults":321,"./hover":323,"./plot":328,"./style":329}],325:[function(_dereq_,module,exports){
  60588. /**
  60589. * Copyright 2012-2018, Plotly, Inc.
  60590. * All rights reserved.
  60591. *
  60592. * This source code is licensed under the MIT license found in the
  60593. * LICENSE file in the root directory of this source tree.
  60594. */
  60595. 'use strict';
  60596. var Lib = _dereq_('../../lib');
  60597. var INTERPTHRESHOLD = 1e-2;
  60598. var NEIGHBORSHIFTS = [[-1, 0], [1, 0], [0, -1], [0, 1]];
  60599. function correctionOvershoot(maxFractionalChange) {
  60600. // start with less overshoot, until we know it's converging,
  60601. // then ramp up the overshoot for faster convergence
  60602. return 0.5 - 0.25 * Math.min(1, maxFractionalChange * 0.5);
  60603. }
  60604. /*
  60605. * interp2d: Fill in missing data from a 2D array using an iterative
  60606. * poisson equation solver with zero-derivative BC at edges.
  60607. * Amazingly, this just amounts to repeatedly averaging all the existing
  60608. * nearest neighbors, at least if we don't take x/y scaling into account,
  60609. * which is the right approach here where x and y may not even have the
  60610. * same units.
  60611. *
  60612. * @param {array of arrays} z
  60613. * The 2D array to fill in. Will be mutated here. Assumed to already be
  60614. * cleaned, so all entries are numbers except gaps, which are `undefined`.
  60615. * @param {array of arrays} emptyPoints
  60616. * Each entry [i, j, neighborCount] for empty points z[i][j] and the number
  60617. * of neighbors that are *not* missing. Assumed to be sorted from most to
  60618. * least neighbors, as produced by heatmap/find_empties.
  60619. */
  60620. module.exports = function interp2d(z, emptyPoints) {
  60621. var maxFractionalChange = 1;
  60622. var i;
  60623. // one pass to fill in a starting value for all the empties
  60624. iterateInterp2d(z, emptyPoints);
  60625. // we're don't need to iterate lone empties - remove them
  60626. for(i = 0; i < emptyPoints.length; i++) {
  60627. if(emptyPoints[i][2] < 4) break;
  60628. }
  60629. // but don't remove these points from the original array,
  60630. // we'll use them for masking, so make a copy.
  60631. emptyPoints = emptyPoints.slice(i);
  60632. for(i = 0; i < 100 && maxFractionalChange > INTERPTHRESHOLD; i++) {
  60633. maxFractionalChange = iterateInterp2d(z, emptyPoints,
  60634. correctionOvershoot(maxFractionalChange));
  60635. }
  60636. if(maxFractionalChange > INTERPTHRESHOLD) {
  60637. Lib.log('interp2d didn\'t converge quickly', maxFractionalChange);
  60638. }
  60639. return z;
  60640. };
  60641. function iterateInterp2d(z, emptyPoints, overshoot) {
  60642. var maxFractionalChange = 0,
  60643. thisPt,
  60644. i,
  60645. j,
  60646. p,
  60647. q,
  60648. neighborShift,
  60649. neighborRow,
  60650. neighborVal,
  60651. neighborCount,
  60652. neighborSum,
  60653. initialVal,
  60654. minNeighbor,
  60655. maxNeighbor;
  60656. for(p = 0; p < emptyPoints.length; p++) {
  60657. thisPt = emptyPoints[p];
  60658. i = thisPt[0];
  60659. j = thisPt[1];
  60660. initialVal = z[i][j];
  60661. neighborSum = 0;
  60662. neighborCount = 0;
  60663. for(q = 0; q < 4; q++) {
  60664. neighborShift = NEIGHBORSHIFTS[q];
  60665. neighborRow = z[i + neighborShift[0]];
  60666. if(!neighborRow) continue;
  60667. neighborVal = neighborRow[j + neighborShift[1]];
  60668. if(neighborVal !== undefined) {
  60669. if(neighborSum === 0) {
  60670. minNeighbor = maxNeighbor = neighborVal;
  60671. }
  60672. else {
  60673. minNeighbor = Math.min(minNeighbor, neighborVal);
  60674. maxNeighbor = Math.max(maxNeighbor, neighborVal);
  60675. }
  60676. neighborCount++;
  60677. neighborSum += neighborVal;
  60678. }
  60679. }
  60680. if(neighborCount === 0) {
  60681. throw 'iterateInterp2d order is wrong: no defined neighbors';
  60682. }
  60683. // this is the laplace equation interpolation:
  60684. // each point is just the average of its neighbors
  60685. // note that this ignores differential x/y scaling
  60686. // which I think is the right approach, since we
  60687. // don't know what that scaling means
  60688. z[i][j] = neighborSum / neighborCount;
  60689. if(initialVal === undefined) {
  60690. if(neighborCount < 4) maxFractionalChange = 1;
  60691. }
  60692. else {
  60693. // we can make large empty regions converge faster
  60694. // if we overshoot the change vs the previous value
  60695. z[i][j] = (1 + overshoot) * z[i][j] - overshoot * initialVal;
  60696. if(maxNeighbor > minNeighbor) {
  60697. maxFractionalChange = Math.max(maxFractionalChange,
  60698. Math.abs(z[i][j] - initialVal) / (maxNeighbor - minNeighbor));
  60699. }
  60700. }
  60701. }
  60702. return maxFractionalChange;
  60703. }
  60704. },{"../../lib":169}],326:[function(_dereq_,module,exports){
  60705. /**
  60706. * Copyright 2012-2018, Plotly, Inc.
  60707. * All rights reserved.
  60708. *
  60709. * This source code is licensed under the MIT license found in the
  60710. * LICENSE file in the root directory of this source tree.
  60711. */
  60712. 'use strict';
  60713. var Registry = _dereq_('../../registry');
  60714. var isArrayOrTypedArray = _dereq_('../../lib').isArrayOrTypedArray;
  60715. module.exports = function makeBoundArray(trace, arrayIn, v0In, dvIn, numbricks, ax) {
  60716. var arrayOut = [],
  60717. isContour = Registry.traceIs(trace, 'contour'),
  60718. isHist = Registry.traceIs(trace, 'histogram'),
  60719. isGL2D = Registry.traceIs(trace, 'gl2d'),
  60720. v0,
  60721. dv,
  60722. i;
  60723. var isArrayOfTwoItemsOrMore = isArrayOrTypedArray(arrayIn) && arrayIn.length > 1;
  60724. if(isArrayOfTwoItemsOrMore && !isHist && (ax.type !== 'category')) {
  60725. var len = arrayIn.length;
  60726. // given vals are brick centers
  60727. // hopefully length === numbricks, but use this method even if too few are supplied
  60728. // and extend it linearly based on the last two points
  60729. if(len <= numbricks) {
  60730. // contour plots only want the centers
  60731. if(isContour || isGL2D) arrayOut = arrayIn.slice(0, numbricks);
  60732. else if(numbricks === 1) {
  60733. arrayOut = [arrayIn[0] - 0.5, arrayIn[0] + 0.5];
  60734. }
  60735. else {
  60736. arrayOut = [1.5 * arrayIn[0] - 0.5 * arrayIn[1]];
  60737. for(i = 1; i < len; i++) {
  60738. arrayOut.push((arrayIn[i - 1] + arrayIn[i]) * 0.5);
  60739. }
  60740. arrayOut.push(1.5 * arrayIn[len - 1] - 0.5 * arrayIn[len - 2]);
  60741. }
  60742. if(len < numbricks) {
  60743. var lastPt = arrayOut[arrayOut.length - 1],
  60744. delta = lastPt - arrayOut[arrayOut.length - 2];
  60745. for(i = len; i < numbricks; i++) {
  60746. lastPt += delta;
  60747. arrayOut.push(lastPt);
  60748. }
  60749. }
  60750. }
  60751. else {
  60752. // hopefully length === numbricks+1, but do something regardless:
  60753. // given vals are brick boundaries
  60754. return isContour ?
  60755. arrayIn.slice(0, numbricks) : // we must be strict for contours
  60756. arrayIn.slice(0, numbricks + 1);
  60757. }
  60758. }
  60759. else {
  60760. dv = dvIn || 1;
  60761. var calendar = trace[ax._id.charAt(0) + 'calendar'];
  60762. if(isHist || ax.type === 'category') v0 = ax.r2c(v0In, 0, calendar) || 0;
  60763. else if(isArrayOrTypedArray(arrayIn) && arrayIn.length === 1) v0 = arrayIn[0];
  60764. else if(v0In === undefined) v0 = 0;
  60765. else v0 = ax.d2c(v0In, 0, calendar);
  60766. for(i = (isContour || isGL2D) ? 0 : -0.5; i < numbricks; i++) {
  60767. arrayOut.push(v0 + dv * i);
  60768. }
  60769. }
  60770. return arrayOut;
  60771. };
  60772. },{"../../lib":169,"../../registry":259}],327:[function(_dereq_,module,exports){
  60773. /**
  60774. * Copyright 2012-2018, Plotly, Inc.
  60775. * All rights reserved.
  60776. *
  60777. * This source code is licensed under the MIT license found in the
  60778. * LICENSE file in the root directory of this source tree.
  60779. */
  60780. 'use strict';
  60781. module.exports = function maxRowLength(z) {
  60782. var len = 0;
  60783. for(var i = 0; i < z.length; i++) {
  60784. len = Math.max(len, z[i].length);
  60785. }
  60786. return len;
  60787. };
  60788. },{}],328:[function(_dereq_,module,exports){
  60789. /**
  60790. * Copyright 2012-2018, Plotly, Inc.
  60791. * All rights reserved.
  60792. *
  60793. * This source code is licensed under the MIT license found in the
  60794. * LICENSE file in the root directory of this source tree.
  60795. */
  60796. 'use strict';
  60797. var d3 = _dereq_('d3');
  60798. var tinycolor = _dereq_('tinycolor2');
  60799. var Registry = _dereq_('../../registry');
  60800. var Lib = _dereq_('../../lib');
  60801. var Colorscale = _dereq_('../../components/colorscale');
  60802. var xmlnsNamespaces = _dereq_('../../constants/xmlns_namespaces');
  60803. var maxRowLength = _dereq_('./max_row_length');
  60804. module.exports = function(gd, plotinfo, cdheatmaps, heatmapLayer) {
  60805. var xa = plotinfo.xaxis;
  60806. var ya = plotinfo.yaxis;
  60807. Lib.makeTraceGroups(heatmapLayer, cdheatmaps, 'hm').each(function(cd) {
  60808. var plotGroup = d3.select(this);
  60809. var cd0 = cd[0];
  60810. var trace = cd0.trace;
  60811. var z = cd0.z;
  60812. var x = cd0.x;
  60813. var y = cd0.y;
  60814. var xc = cd0.xCenter;
  60815. var yc = cd0.yCenter;
  60816. var isContour = Registry.traceIs(trace, 'contour');
  60817. var zsmooth = isContour ? 'best' : trace.zsmooth;
  60818. // get z dims
  60819. var m = z.length;
  60820. var n = maxRowLength(z);
  60821. var xrev = false;
  60822. var yrev = false;
  60823. var left, right, temp, top, bottom, i;
  60824. // TODO: if there are multiple overlapping categorical heatmaps,
  60825. // or if we allow category sorting, then the categories may not be
  60826. // sequential... may need to reorder and/or expand z
  60827. // Get edges of png in pixels (xa.c2p() maps axes coordinates to pixel coordinates)
  60828. // figure out if either axis is reversed (y is usually reversed, in pixel coords)
  60829. // also clip the image to maximum 50% outside the visible plot area
  60830. // bigger image lets you pan more naturally, but slows performance.
  60831. // TODO: use low-resolution images outside the visible plot for panning
  60832. // these while loops find the first and last brick bounds that are defined
  60833. // (in case of log of a negative)
  60834. i = 0;
  60835. while(left === undefined && i < x.length - 1) {
  60836. left = xa.c2p(x[i]);
  60837. i++;
  60838. }
  60839. i = x.length - 1;
  60840. while(right === undefined && i > 0) {
  60841. right = xa.c2p(x[i]);
  60842. i--;
  60843. }
  60844. if(right < left) {
  60845. temp = right;
  60846. right = left;
  60847. left = temp;
  60848. xrev = true;
  60849. }
  60850. i = 0;
  60851. while(top === undefined && i < y.length - 1) {
  60852. top = ya.c2p(y[i]);
  60853. i++;
  60854. }
  60855. i = y.length - 1;
  60856. while(bottom === undefined && i > 0) {
  60857. bottom = ya.c2p(y[i]);
  60858. i--;
  60859. }
  60860. if(bottom < top) {
  60861. temp = top;
  60862. top = bottom;
  60863. bottom = temp;
  60864. yrev = true;
  60865. }
  60866. // for contours with heatmap fill, we generate the boundaries based on
  60867. // brick centers but then use the brick edges for drawing the bricks
  60868. if(isContour) {
  60869. xc = x;
  60870. yc = y;
  60871. x = cd0.xfill;
  60872. y = cd0.yfill;
  60873. }
  60874. // make an image that goes at most half a screen off either side, to keep
  60875. // time reasonable when you zoom in. if zsmooth is true/fast, don't worry
  60876. // about this, because zooming doesn't increase number of pixels
  60877. // if zsmooth is best, don't include anything off screen because it takes too long
  60878. if(zsmooth !== 'fast') {
  60879. var extra = zsmooth === 'best' ? 0 : 0.5;
  60880. left = Math.max(-extra * xa._length, left);
  60881. right = Math.min((1 + extra) * xa._length, right);
  60882. top = Math.max(-extra * ya._length, top);
  60883. bottom = Math.min((1 + extra) * ya._length, bottom);
  60884. }
  60885. var imageWidth = Math.round(right - left),
  60886. imageHeight = Math.round(bottom - top);
  60887. // setup image nodes
  60888. // if image is entirely off-screen, don't even draw it
  60889. var isOffScreen = (imageWidth <= 0 || imageHeight <= 0);
  60890. if(isOffScreen) {
  60891. var noImage = plotGroup.selectAll('image').data([]);
  60892. noImage.exit().remove();
  60893. return;
  60894. }
  60895. // generate image data
  60896. var canvasW, canvasH;
  60897. if(zsmooth === 'fast') {
  60898. canvasW = n;
  60899. canvasH = m;
  60900. } else {
  60901. canvasW = imageWidth;
  60902. canvasH = imageHeight;
  60903. }
  60904. var canvas = document.createElement('canvas');
  60905. canvas.width = canvasW;
  60906. canvas.height = canvasH;
  60907. var context = canvas.getContext('2d');
  60908. var sclFunc = Colorscale.makeColorScaleFunc(
  60909. Colorscale.extractScale(
  60910. trace.colorscale,
  60911. trace.zmin,
  60912. trace.zmax
  60913. ),
  60914. { noNumericCheck: true, returnArray: true }
  60915. );
  60916. // map brick boundaries to image pixels
  60917. var xpx,
  60918. ypx;
  60919. if(zsmooth === 'fast') {
  60920. xpx = xrev ?
  60921. function(index) { return n - 1 - index; } :
  60922. Lib.identity;
  60923. ypx = yrev ?
  60924. function(index) { return m - 1 - index; } :
  60925. Lib.identity;
  60926. }
  60927. else {
  60928. xpx = function(index) {
  60929. return Lib.constrain(Math.round(xa.c2p(x[index]) - left),
  60930. 0, imageWidth);
  60931. };
  60932. ypx = function(index) {
  60933. return Lib.constrain(Math.round(ya.c2p(y[index]) - top),
  60934. 0, imageHeight);
  60935. };
  60936. }
  60937. // build the pixel map brick-by-brick
  60938. // cruise through z-matrix row-by-row
  60939. // build a brick at each z-matrix value
  60940. var yi = ypx(0);
  60941. var yb = [yi, yi];
  60942. var xbi = xrev ? 0 : 1;
  60943. var ybi = yrev ? 0 : 1;
  60944. // for collecting an average luminosity of the heatmap
  60945. var pixcount = 0;
  60946. var rcount = 0;
  60947. var gcount = 0;
  60948. var bcount = 0;
  60949. var xb, j, xi, v, row, c;
  60950. function setColor(v, pixsize) {
  60951. if(v !== undefined) {
  60952. var c = sclFunc(v);
  60953. c[0] = Math.round(c[0]);
  60954. c[1] = Math.round(c[1]);
  60955. c[2] = Math.round(c[2]);
  60956. pixcount += pixsize;
  60957. rcount += c[0] * pixsize;
  60958. gcount += c[1] * pixsize;
  60959. bcount += c[2] * pixsize;
  60960. return c;
  60961. }
  60962. return [0, 0, 0, 0];
  60963. }
  60964. function interpColor(r0, r1, xinterp, yinterp) {
  60965. var z00 = r0[xinterp.bin0];
  60966. if(z00 === undefined) return setColor(undefined, 1);
  60967. var z01 = r0[xinterp.bin1],
  60968. z10 = r1[xinterp.bin0],
  60969. z11 = r1[xinterp.bin1],
  60970. dx = (z01 - z00) || 0,
  60971. dy = (z10 - z00) || 0,
  60972. dxy;
  60973. // the bilinear interpolation term needs different calculations
  60974. // for all the different permutations of missing data
  60975. // among the neighbors of the main point, to ensure
  60976. // continuity across brick boundaries.
  60977. if(z01 === undefined) {
  60978. if(z11 === undefined) dxy = 0;
  60979. else if(z10 === undefined) dxy = 2 * (z11 - z00);
  60980. else dxy = (2 * z11 - z10 - z00) * 2 / 3;
  60981. }
  60982. else if(z11 === undefined) {
  60983. if(z10 === undefined) dxy = 0;
  60984. else dxy = (2 * z00 - z01 - z10) * 2 / 3;
  60985. }
  60986. else if(z10 === undefined) dxy = (2 * z11 - z01 - z00) * 2 / 3;
  60987. else dxy = (z11 + z00 - z01 - z10);
  60988. return setColor(z00 + xinterp.frac * dx + yinterp.frac * (dy + xinterp.frac * dxy));
  60989. }
  60990. if(zsmooth) { // best or fast, works fastest with imageData
  60991. var pxIndex = 0,
  60992. pixels;
  60993. try {
  60994. pixels = new Uint8Array(imageWidth * imageHeight * 4);
  60995. }
  60996. catch(e) {
  60997. pixels = new Array(imageWidth * imageHeight * 4);
  60998. }
  60999. if(zsmooth === 'best') {
  61000. var xForPx = xc || x;
  61001. var yForPx = yc || y;
  61002. var xPixArray = new Array(xForPx.length);
  61003. var yPixArray = new Array(yForPx.length);
  61004. var xinterpArray = new Array(imageWidth);
  61005. var findInterpX = xc ? findInterpFromCenters : findInterp;
  61006. var findInterpY = yc ? findInterpFromCenters : findInterp;
  61007. var yinterp, r0, r1;
  61008. // first make arrays of x and y pixel locations of brick boundaries
  61009. for(i = 0; i < xForPx.length; i++) xPixArray[i] = Math.round(xa.c2p(xForPx[i]) - left);
  61010. for(i = 0; i < yForPx.length; i++) yPixArray[i] = Math.round(ya.c2p(yForPx[i]) - top);
  61011. // then make arrays of interpolations
  61012. // (bin0=closest, bin1=next, frac=fractional dist.)
  61013. for(i = 0; i < imageWidth; i++) xinterpArray[i] = findInterpX(i, xPixArray);
  61014. // now do the interpolations and fill the png
  61015. for(j = 0; j < imageHeight; j++) {
  61016. yinterp = findInterpY(j, yPixArray);
  61017. r0 = z[yinterp.bin0];
  61018. r1 = z[yinterp.bin1];
  61019. for(i = 0; i < imageWidth; i++, pxIndex += 4) {
  61020. c = interpColor(r0, r1, xinterpArray[i], yinterp);
  61021. putColor(pixels, pxIndex, c);
  61022. }
  61023. }
  61024. }
  61025. else { // zsmooth = fast
  61026. for(j = 0; j < m; j++) {
  61027. row = z[j];
  61028. yb = ypx(j);
  61029. for(i = 0; i < imageWidth; i++) {
  61030. c = setColor(row[i], 1);
  61031. pxIndex = (yb * imageWidth + xpx(i)) * 4;
  61032. putColor(pixels, pxIndex, c);
  61033. }
  61034. }
  61035. }
  61036. var imageData = context.createImageData(imageWidth, imageHeight);
  61037. try {
  61038. imageData.data.set(pixels);
  61039. }
  61040. catch(e) {
  61041. var pxArray = imageData.data,
  61042. dlen = pxArray.length;
  61043. for(j = 0; j < dlen; j ++) {
  61044. pxArray[j] = pixels[j];
  61045. }
  61046. }
  61047. context.putImageData(imageData, 0, 0);
  61048. } else { // zsmooth = false -> filling potentially large bricks works fastest with fillRect
  61049. // gaps do not need to be exact integers, but if they *are* we will get
  61050. // cleaner edges by rounding at least one edge
  61051. var xGap = trace.xgap;
  61052. var yGap = trace.ygap;
  61053. var xGapLeft = Math.floor(xGap / 2);
  61054. var yGapTop = Math.floor(yGap / 2);
  61055. for(j = 0; j < m; j++) {
  61056. row = z[j];
  61057. yb.reverse();
  61058. yb[ybi] = ypx(j + 1);
  61059. if(yb[0] === yb[1] || yb[0] === undefined || yb[1] === undefined) {
  61060. continue;
  61061. }
  61062. xi = xpx(0);
  61063. xb = [xi, xi];
  61064. for(i = 0; i < n; i++) {
  61065. // build one color brick!
  61066. xb.reverse();
  61067. xb[xbi] = xpx(i + 1);
  61068. if(xb[0] === xb[1] || xb[0] === undefined || xb[1] === undefined) {
  61069. continue;
  61070. }
  61071. v = row[i];
  61072. c = setColor(v, (xb[1] - xb[0]) * (yb[1] - yb[0]));
  61073. context.fillStyle = 'rgba(' + c.join(',') + ')';
  61074. context.fillRect(xb[0] + xGapLeft, yb[0] + yGapTop,
  61075. xb[1] - xb[0] - xGap, yb[1] - yb[0] - yGap);
  61076. }
  61077. }
  61078. }
  61079. rcount = Math.round(rcount / pixcount);
  61080. gcount = Math.round(gcount / pixcount);
  61081. bcount = Math.round(bcount / pixcount);
  61082. var avgColor = tinycolor('rgb(' + rcount + ',' + gcount + ',' + bcount + ')');
  61083. gd._hmpixcount = (gd._hmpixcount||0) + pixcount;
  61084. gd._hmlumcount = (gd._hmlumcount||0) + pixcount * avgColor.getLuminance();
  61085. var image3 = plotGroup.selectAll('image')
  61086. .data(cd);
  61087. image3.enter().append('svg:image').attr({
  61088. xmlns: xmlnsNamespaces.svg,
  61089. preserveAspectRatio: 'none'
  61090. });
  61091. image3.attr({
  61092. height: imageHeight,
  61093. width: imageWidth,
  61094. x: left,
  61095. y: top,
  61096. 'xlink:href': canvas.toDataURL('image/png')
  61097. });
  61098. });
  61099. };
  61100. // get interpolated bin value. Returns {bin0:closest bin, frac:fractional dist to next, bin1:next bin}
  61101. function findInterp(pixel, pixArray) {
  61102. var maxBin = pixArray.length - 2;
  61103. var bin = Lib.constrain(Lib.findBin(pixel, pixArray), 0, maxBin);
  61104. var pix0 = pixArray[bin];
  61105. var pix1 = pixArray[bin + 1];
  61106. var interp = Lib.constrain(bin + (pixel - pix0) / (pix1 - pix0) - 0.5, 0, maxBin);
  61107. var bin0 = Math.round(interp);
  61108. var frac = Math.abs(interp - bin0);
  61109. if(!interp || interp === maxBin || !frac) {
  61110. return {
  61111. bin0: bin0,
  61112. bin1: bin0,
  61113. frac: 0
  61114. };
  61115. }
  61116. return {
  61117. bin0: bin0,
  61118. frac: frac,
  61119. bin1: Math.round(bin0 + frac / (interp - bin0))
  61120. };
  61121. }
  61122. function findInterpFromCenters(pixel, centerPixArray) {
  61123. var maxBin = centerPixArray.length - 1;
  61124. var bin = Lib.constrain(Lib.findBin(pixel, centerPixArray), 0, maxBin);
  61125. var pix0 = centerPixArray[bin];
  61126. var pix1 = centerPixArray[bin + 1];
  61127. var frac = ((pixel - pix0) / (pix1 - pix0)) || 0;
  61128. if(frac <= 0) {
  61129. return {
  61130. bin0: bin,
  61131. bin1: bin,
  61132. frac: 0
  61133. };
  61134. }
  61135. if(frac < 0.5) {
  61136. return {
  61137. bin0: bin,
  61138. bin1: bin + 1,
  61139. frac: frac
  61140. };
  61141. }
  61142. return {
  61143. bin0: bin + 1,
  61144. bin1: bin,
  61145. frac: 1 - frac
  61146. };
  61147. }
  61148. function putColor(pixels, pxIndex, c) {
  61149. pixels[pxIndex] = c[0];
  61150. pixels[pxIndex + 1] = c[1];
  61151. pixels[pxIndex + 2] = c[2];
  61152. pixels[pxIndex + 3] = Math.round(c[3] * 255);
  61153. }
  61154. },{"../../components/colorscale":65,"../../constants/xmlns_namespaces":152,"../../lib":169,"../../registry":259,"./max_row_length":327,"d3":16,"tinycolor2":33}],329:[function(_dereq_,module,exports){
  61155. /**
  61156. * Copyright 2012-2018, Plotly, Inc.
  61157. * All rights reserved.
  61158. *
  61159. * This source code is licensed under the MIT license found in the
  61160. * LICENSE file in the root directory of this source tree.
  61161. */
  61162. 'use strict';
  61163. var d3 = _dereq_('d3');
  61164. module.exports = function style(gd) {
  61165. d3.select(gd).selectAll('.hm image')
  61166. .style('opacity', function(d) {
  61167. return d.trace.opacity;
  61168. });
  61169. };
  61170. },{"d3":16}],330:[function(_dereq_,module,exports){
  61171. /**
  61172. * Copyright 2012-2018, Plotly, Inc.
  61173. * All rights reserved.
  61174. *
  61175. * This source code is licensed under the MIT license found in the
  61176. * LICENSE file in the root directory of this source tree.
  61177. */
  61178. 'use strict';
  61179. module.exports = function handleStyleDefaults(traceIn, traceOut, coerce) {
  61180. var zsmooth = coerce('zsmooth');
  61181. if(zsmooth === false) {
  61182. // ensure that xgap and ygap are coerced only when zsmooth allows them to have an effect.
  61183. coerce('xgap');
  61184. coerce('ygap');
  61185. }
  61186. coerce('zhoverformat');
  61187. };
  61188. },{}],331:[function(_dereq_,module,exports){
  61189. /**
  61190. * Copyright 2012-2018, Plotly, Inc.
  61191. * All rights reserved.
  61192. *
  61193. * This source code is licensed under the MIT license found in the
  61194. * LICENSE file in the root directory of this source tree.
  61195. */
  61196. 'use strict';
  61197. var isNumeric = _dereq_('fast-isnumeric');
  61198. var Lib = _dereq_('../../lib');
  61199. var Registry = _dereq_('../../registry');
  61200. module.exports = function handleXYZDefaults(traceIn, traceOut, coerce, layout, xName, yName) {
  61201. var z = coerce('z');
  61202. xName = xName || 'x';
  61203. yName = yName || 'y';
  61204. var x, y;
  61205. if(z === undefined || !z.length) return 0;
  61206. if(Lib.isArray1D(traceIn.z)) {
  61207. x = coerce(xName);
  61208. y = coerce(yName);
  61209. // column z must be accompanied by xName and yName arrays
  61210. if(!(x && x.length && y && y.length)) return 0;
  61211. traceOut._length = Math.min(x.length, y.length, z.length);
  61212. }
  61213. else {
  61214. x = coordDefaults(xName, coerce);
  61215. y = coordDefaults(yName, coerce);
  61216. // TODO put z validation elsewhere
  61217. if(!isValidZ(z)) return 0;
  61218. coerce('transpose');
  61219. traceOut._length = null;
  61220. }
  61221. var handleCalendarDefaults = Registry.getComponentMethod('calendars', 'handleTraceDefaults');
  61222. handleCalendarDefaults(traceIn, traceOut, [xName, yName], layout);
  61223. return true;
  61224. };
  61225. function coordDefaults(coordStr, coerce) {
  61226. var coord = coerce(coordStr),
  61227. coordType = coord ?
  61228. coerce(coordStr + 'type', 'array') :
  61229. 'scaled';
  61230. if(coordType === 'scaled') {
  61231. coerce(coordStr + '0');
  61232. coerce('d' + coordStr);
  61233. }
  61234. return coord;
  61235. }
  61236. function isValidZ(z) {
  61237. var allRowsAreArrays = true,
  61238. oneRowIsFilled = false,
  61239. hasOneNumber = false,
  61240. zi;
  61241. /*
  61242. * Without this step:
  61243. *
  61244. * hasOneNumber = false breaks contour but not heatmap
  61245. * allRowsAreArrays = false breaks contour but not heatmap
  61246. * oneRowIsFilled = false breaks both
  61247. */
  61248. for(var i = 0; i < z.length; i++) {
  61249. zi = z[i];
  61250. if(!Lib.isArrayOrTypedArray(zi)) {
  61251. allRowsAreArrays = false;
  61252. break;
  61253. }
  61254. if(zi.length > 0) oneRowIsFilled = true;
  61255. for(var j = 0; j < zi.length; j++) {
  61256. if(isNumeric(zi[j])) {
  61257. hasOneNumber = true;
  61258. break;
  61259. }
  61260. }
  61261. }
  61262. return (allRowsAreArrays && oneRowIsFilled && hasOneNumber);
  61263. }
  61264. },{"../../lib":169,"../../registry":259,"fast-isnumeric":18}],332:[function(_dereq_,module,exports){
  61265. /**
  61266. * Copyright 2012-2018, Plotly, Inc.
  61267. * All rights reserved.
  61268. *
  61269. * This source code is licensed under the MIT license found in the
  61270. * LICENSE file in the root directory of this source tree.
  61271. */
  61272. 'use strict';
  61273. var barAttrs = _dereq_('../bar/attributes');
  61274. module.exports = {
  61275. x: {
  61276. valType: 'data_array',
  61277. editType: 'calc+clearAxisTypes',
  61278. },
  61279. y: {
  61280. valType: 'data_array',
  61281. editType: 'calc+clearAxisTypes',
  61282. },
  61283. text: barAttrs.text,
  61284. orientation: barAttrs.orientation,
  61285. histfunc: {
  61286. valType: 'enumerated',
  61287. values: ['count', 'sum', 'avg', 'min', 'max'],
  61288. dflt: 'count',
  61289. editType: 'calc',
  61290. },
  61291. histnorm: {
  61292. valType: 'enumerated',
  61293. values: ['', 'percent', 'probability', 'density', 'probability density'],
  61294. dflt: '',
  61295. editType: 'calc',
  61296. },
  61297. cumulative: {
  61298. enabled: {
  61299. valType: 'boolean',
  61300. dflt: false,
  61301. editType: 'calc',
  61302. },
  61303. direction: {
  61304. valType: 'enumerated',
  61305. values: ['increasing', 'decreasing'],
  61306. dflt: 'increasing',
  61307. editType: 'calc',
  61308. },
  61309. currentbin: {
  61310. valType: 'enumerated',
  61311. values: ['include', 'exclude', 'half'],
  61312. dflt: 'include',
  61313. editType: 'calc',
  61314. },
  61315. editType: 'calc'
  61316. },
  61317. autobinx: {
  61318. valType: 'boolean',
  61319. dflt: null,
  61320. editType: 'calc',
  61321. impliedEdits: {
  61322. 'xbins.start': undefined,
  61323. 'xbins.end': undefined,
  61324. 'xbins.size': undefined
  61325. },
  61326. },
  61327. nbinsx: {
  61328. valType: 'integer',
  61329. min: 0,
  61330. dflt: 0,
  61331. editType: 'calc',
  61332. },
  61333. xbins: makeBinsAttr('x'),
  61334. autobiny: {
  61335. valType: 'boolean',
  61336. dflt: null,
  61337. editType: 'calc',
  61338. impliedEdits: {
  61339. 'ybins.start': undefined,
  61340. 'ybins.end': undefined,
  61341. 'ybins.size': undefined
  61342. },
  61343. },
  61344. nbinsy: {
  61345. valType: 'integer',
  61346. min: 0,
  61347. dflt: 0,
  61348. editType: 'calc',
  61349. },
  61350. ybins: makeBinsAttr('y'),
  61351. marker: barAttrs.marker,
  61352. selected: barAttrs.selected,
  61353. unselected: barAttrs.unselected,
  61354. _deprecated: {
  61355. bardir: barAttrs._deprecated.bardir
  61356. }
  61357. };
  61358. function makeBinsAttr(axLetter) {
  61359. var impliedEdits = {};
  61360. impliedEdits['autobin' + axLetter] = false;
  61361. var impliedEditsInner = {};
  61362. impliedEditsInner['^autobin' + axLetter] = false;
  61363. return {
  61364. start: {
  61365. valType: 'any', // for date axes
  61366. dflt: null,
  61367. editType: 'calc',
  61368. impliedEdits: impliedEditsInner,
  61369. },
  61370. end: {
  61371. valType: 'any', // for date axes
  61372. dflt: null,
  61373. editType: 'calc',
  61374. impliedEdits: impliedEditsInner,
  61375. },
  61376. size: {
  61377. valType: 'any', // for date axes
  61378. dflt: null,
  61379. editType: 'calc',
  61380. impliedEdits: impliedEditsInner,
  61381. },
  61382. editType: 'calc',
  61383. impliedEdits: impliedEdits
  61384. };
  61385. }
  61386. },{"../bar/attributes":269}],333:[function(_dereq_,module,exports){
  61387. /**
  61388. * Copyright 2012-2018, Plotly, Inc.
  61389. * All rights reserved.
  61390. *
  61391. * This source code is licensed under the MIT license found in the
  61392. * LICENSE file in the root directory of this source tree.
  61393. */
  61394. 'use strict';
  61395. module.exports = function doAvg(size, counts) {
  61396. var nMax = size.length,
  61397. total = 0;
  61398. for(var i = 0; i < nMax; i++) {
  61399. if(counts[i]) {
  61400. size[i] /= counts[i];
  61401. total += size[i];
  61402. }
  61403. else size[i] = null;
  61404. }
  61405. return total;
  61406. };
  61407. },{}],334:[function(_dereq_,module,exports){
  61408. /**
  61409. * Copyright 2012-2018, Plotly, Inc.
  61410. * All rights reserved.
  61411. *
  61412. * This source code is licensed under the MIT license found in the
  61413. * LICENSE file in the root directory of this source tree.
  61414. */
  61415. 'use strict';
  61416. module.exports = function handleBinDefaults(traceIn, traceOut, coerce, binDirections) {
  61417. coerce('histnorm');
  61418. binDirections.forEach(function(binDirection) {
  61419. /*
  61420. * Because date axes have string values for start and end,
  61421. * and string options for size, we cannot validate these attributes
  61422. * now. We will do this during calc (immediately prior to binning)
  61423. * in ./clean_bins, and push the cleaned values back to _fullData.
  61424. */
  61425. coerce(binDirection + 'bins.start');
  61426. coerce(binDirection + 'bins.end');
  61427. coerce(binDirection + 'bins.size');
  61428. var autobin = coerce('autobin' + binDirection);
  61429. if(autobin !== false) coerce('nbins' + binDirection);
  61430. });
  61431. return traceOut;
  61432. };
  61433. },{}],335:[function(_dereq_,module,exports){
  61434. /**
  61435. * Copyright 2012-2018, Plotly, Inc.
  61436. * All rights reserved.
  61437. *
  61438. * This source code is licensed under the MIT license found in the
  61439. * LICENSE file in the root directory of this source tree.
  61440. */
  61441. 'use strict';
  61442. var isNumeric = _dereq_('fast-isnumeric');
  61443. module.exports = {
  61444. count: function(n, i, size) {
  61445. size[n]++;
  61446. return 1;
  61447. },
  61448. sum: function(n, i, size, counterData) {
  61449. var v = counterData[i];
  61450. if(isNumeric(v)) {
  61451. v = Number(v);
  61452. size[n] += v;
  61453. return v;
  61454. }
  61455. return 0;
  61456. },
  61457. avg: function(n, i, size, counterData, counts) {
  61458. var v = counterData[i];
  61459. if(isNumeric(v)) {
  61460. v = Number(v);
  61461. size[n] += v;
  61462. counts[n]++;
  61463. }
  61464. return 0;
  61465. },
  61466. min: function(n, i, size, counterData) {
  61467. var v = counterData[i];
  61468. if(isNumeric(v)) {
  61469. v = Number(v);
  61470. if(!isNumeric(size[n])) {
  61471. size[n] = v;
  61472. return v;
  61473. }
  61474. else if(size[n] > v) {
  61475. var delta = v - size[n];
  61476. size[n] = v;
  61477. return delta;
  61478. }
  61479. }
  61480. return 0;
  61481. },
  61482. max: function(n, i, size, counterData) {
  61483. var v = counterData[i];
  61484. if(isNumeric(v)) {
  61485. v = Number(v);
  61486. if(!isNumeric(size[n])) {
  61487. size[n] = v;
  61488. return v;
  61489. }
  61490. else if(size[n] < v) {
  61491. var delta = v - size[n];
  61492. size[n] = v;
  61493. return delta;
  61494. }
  61495. }
  61496. return 0;
  61497. }
  61498. };
  61499. },{"fast-isnumeric":18}],336:[function(_dereq_,module,exports){
  61500. /**
  61501. * Copyright 2012-2018, Plotly, Inc.
  61502. * All rights reserved.
  61503. *
  61504. * This source code is licensed under the MIT license found in the
  61505. * LICENSE file in the root directory of this source tree.
  61506. */
  61507. 'use strict';
  61508. var numConstants = _dereq_('../../constants/numerical');
  61509. var oneYear = numConstants.ONEAVGYEAR;
  61510. var oneMonth = numConstants.ONEAVGMONTH;
  61511. var oneDay = numConstants.ONEDAY;
  61512. var oneHour = numConstants.ONEHOUR;
  61513. var oneMin = numConstants.ONEMIN;
  61514. var oneSec = numConstants.ONESEC;
  61515. var tickIncrement = _dereq_('../../plots/cartesian/axes').tickIncrement;
  61516. /*
  61517. * make a function that will find rounded bin edges
  61518. * @param {number} leftGap: how far from the left edge of any bin is the closest data value?
  61519. * @param {number} rightGap: how far from the right edge of any bin is the closest data value?
  61520. * @param {Array[number]} binEdges: the actual edge values used in binning
  61521. * @param {object} pa: the position axis
  61522. * @param {string} calendar: the data calendar
  61523. *
  61524. * @return {function(v, isRightEdge)}:
  61525. * find the start (isRightEdge is falsy) or end (truthy) label value for a bin edge `v`
  61526. */
  61527. module.exports = function getBinSpanLabelRound(leftGap, rightGap, binEdges, pa, calendar) {
  61528. // the rounding digit is the largest digit that changes in *all* of 4 regions:
  61529. // - inside the rightGap before binEdges[0] (shifted 10% to the left)
  61530. // - inside the leftGap after binEdges[0] (expanded by 10% of rightGap on each end)
  61531. // - same for binEdges[1]
  61532. var dv0 = -1.1 * rightGap;
  61533. var dv1 = -0.1 * rightGap;
  61534. var dv2 = leftGap - dv1;
  61535. var edge0 = binEdges[0];
  61536. var edge1 = binEdges[1];
  61537. var leftDigit = Math.min(
  61538. biggestDigitChanged(edge0 + dv1, edge0 + dv2, pa, calendar),
  61539. biggestDigitChanged(edge1 + dv1, edge1 + dv2, pa, calendar)
  61540. );
  61541. var rightDigit = Math.min(
  61542. biggestDigitChanged(edge0 + dv0, edge0 + dv1, pa, calendar),
  61543. biggestDigitChanged(edge1 + dv0, edge1 + dv1, pa, calendar)
  61544. );
  61545. // normally we try to make the label for the right edge different from
  61546. // the left edge label, so it's unambiguous which bin gets data on the edge.
  61547. // but if this results in more than 3 extra digits (or for dates, more than
  61548. // 2 fields ie hr&min or min&sec, which is 3600x), it'll be more clutter than
  61549. // useful so keep the label cleaner instead
  61550. var digit, disambiguateEdges;
  61551. if(leftDigit > rightDigit && rightDigit < Math.abs(edge1 - edge0) / 4000) {
  61552. digit = leftDigit;
  61553. disambiguateEdges = false;
  61554. }
  61555. else {
  61556. digit = Math.min(leftDigit, rightDigit);
  61557. disambiguateEdges = true;
  61558. }
  61559. if(pa.type === 'date' && digit > oneDay) {
  61560. var dashExclude = (digit === oneYear) ? 1 : 6;
  61561. var increment = (digit === oneYear) ? 'M12' : 'M1';
  61562. return function(v, isRightEdge) {
  61563. var dateStr = pa.c2d(v, oneYear, calendar);
  61564. var dashPos = dateStr.indexOf('-', dashExclude);
  61565. if(dashPos > 0) dateStr = dateStr.substr(0, dashPos);
  61566. var roundedV = pa.d2c(dateStr, 0, calendar);
  61567. if(roundedV < v) {
  61568. var nextV = tickIncrement(roundedV, increment, false, calendar);
  61569. if((roundedV + nextV) / 2 < v + leftGap) roundedV = nextV;
  61570. }
  61571. if(isRightEdge && disambiguateEdges) {
  61572. return tickIncrement(roundedV, increment, true, calendar);
  61573. }
  61574. return roundedV;
  61575. };
  61576. }
  61577. return function(v, isRightEdge) {
  61578. var roundedV = digit * Math.round(v / digit);
  61579. // if we rounded down and we could round up and still be < leftGap
  61580. // (or what leftGap values round to), do that
  61581. if(roundedV + (digit / 10) < v && roundedV + (digit * 0.9) < v + leftGap) {
  61582. roundedV += digit;
  61583. }
  61584. // finally for the right edge back off one digit - but only if we can do that
  61585. // and not clip off any data that's potentially in the bin
  61586. if(isRightEdge && disambiguateEdges) {
  61587. roundedV -= digit;
  61588. }
  61589. return roundedV;
  61590. };
  61591. };
  61592. /*
  61593. * Find the largest digit that changes within a (calcdata) region [v1, v2]
  61594. * if dates, "digit" means date/time part when it's bigger than a second
  61595. * returns the unit value to round to this digit, eg 0.01 to round to hundredths, or
  61596. * 100 to round to hundreds. returns oneMonth or oneYear for month or year rounding,
  61597. * so that Math.min will work, rather than 'M1' and 'M12'
  61598. */
  61599. function biggestDigitChanged(v1, v2, pa, calendar) {
  61600. // are we crossing zero? can't say anything.
  61601. // in principle this doesn't apply to dates but turns out this doesn't matter.
  61602. if(v1 * v2 <= 0) return Infinity;
  61603. var dv = Math.abs(v2 - v1);
  61604. var isDate = pa.type === 'date';
  61605. var digit = biggestGuaranteedDigitChanged(dv, isDate);
  61606. // see if a larger digit also changed
  61607. for(var i = 0; i < 10; i++) {
  61608. // numbers: next digit needs to be >10x but <100x then gets rounded down.
  61609. // dates: next digit can be as much as 60x (then rounded down)
  61610. var nextDigit = biggestGuaranteedDigitChanged(digit * 80, isDate);
  61611. // if we get to years, the chain stops
  61612. if(digit === nextDigit) break;
  61613. if(didDigitChange(nextDigit, v1, v2, isDate, pa, calendar)) digit = nextDigit;
  61614. else break;
  61615. }
  61616. return digit;
  61617. }
  61618. /*
  61619. * Find the largest digit that *definitely* changes in a region [v, v + dv] for any v
  61620. * for nonuniform date regions (months/years) pick the largest
  61621. */
  61622. function biggestGuaranteedDigitChanged(dv, isDate) {
  61623. if(isDate && dv > oneSec) {
  61624. // this is supposed to be the biggest *guaranteed* change
  61625. // so compare to the longest month and year across any calendar,
  61626. // and we'll iterate back up later
  61627. // note: does not support rounding larger than one year. We could add
  61628. // that if anyone wants it, but seems unusual and not strictly necessary.
  61629. if(dv > oneDay) {
  61630. if(dv > oneYear * 1.1) return oneYear;
  61631. if(dv > oneMonth * 1.1) return oneMonth;
  61632. return oneDay;
  61633. }
  61634. if(dv > oneHour) return oneHour;
  61635. if(dv > oneMin) return oneMin;
  61636. return oneSec;
  61637. }
  61638. return Math.pow(10, Math.floor(Math.log(dv) / Math.LN10));
  61639. }
  61640. function didDigitChange(digit, v1, v2, isDate, pa, calendar) {
  61641. if(isDate && digit > oneDay) {
  61642. var dateParts1 = dateParts(v1, pa, calendar);
  61643. var dateParts2 = dateParts(v2, pa, calendar);
  61644. var parti = (digit === oneYear) ? 0 : 1;
  61645. return dateParts1[parti] !== dateParts2[parti];
  61646. }
  61647. return Math.floor(v2 / digit) - Math.floor(v1 / digit) > 0.1;
  61648. }
  61649. function dateParts(v, pa, calendar) {
  61650. var parts = pa.c2d(v, oneYear, calendar).split('-');
  61651. if(parts[0] === '') {
  61652. parts.unshift();
  61653. parts[0] = '-' + parts[0];
  61654. }
  61655. return parts;
  61656. }
  61657. },{"../../constants/numerical":151,"../../plots/cartesian/axes":214}],337:[function(_dereq_,module,exports){
  61658. /**
  61659. * Copyright 2012-2018, Plotly, Inc.
  61660. * All rights reserved.
  61661. *
  61662. * This source code is licensed under the MIT license found in the
  61663. * LICENSE file in the root directory of this source tree.
  61664. */
  61665. 'use strict';
  61666. var isNumeric = _dereq_('fast-isnumeric');
  61667. var Lib = _dereq_('../../lib');
  61668. var Axes = _dereq_('../../plots/cartesian/axes');
  61669. var arraysToCalcdata = _dereq_('../bar/arrays_to_calcdata');
  61670. var binFunctions = _dereq_('./bin_functions');
  61671. var normFunctions = _dereq_('./norm_functions');
  61672. var doAvg = _dereq_('./average');
  61673. var cleanBins = _dereq_('./clean_bins');
  61674. var oneMonth = _dereq_('../../constants/numerical').ONEAVGMONTH;
  61675. var getBinSpanLabelRound = _dereq_('./bin_label_vals');
  61676. module.exports = function calc(gd, trace) {
  61677. // ignore as much processing as possible (and including in autorange) if not visible
  61678. if(trace.visible !== true) return;
  61679. // depending on orientation, set position and size axes and data ranges
  61680. // note: this logic for choosing orientation is duplicated in graph_obj->setstyles
  61681. var pos = [];
  61682. var size = [];
  61683. var pa = Axes.getFromId(gd, trace.orientation === 'h' ?
  61684. (trace.yaxis || 'y') : (trace.xaxis || 'x'));
  61685. var mainData = trace.orientation === 'h' ? 'y' : 'x';
  61686. var counterData = {x: 'y', y: 'x'}[mainData];
  61687. var calendar = trace[mainData + 'calendar'];
  61688. var cumulativeSpec = trace.cumulative;
  61689. var i;
  61690. cleanBins(trace, pa, mainData);
  61691. var binsAndPos = calcAllAutoBins(gd, trace, pa, mainData);
  61692. var binSpec = binsAndPos[0];
  61693. var pos0 = binsAndPos[1];
  61694. var nonuniformBins = typeof binSpec.size === 'string';
  61695. var binEdges = [];
  61696. var bins = nonuniformBins ? binEdges : binSpec;
  61697. // make the empty bin array
  61698. var inc = [];
  61699. var counts = [];
  61700. var inputPoints = [];
  61701. var total = 0;
  61702. var norm = trace.histnorm;
  61703. var func = trace.histfunc;
  61704. var densityNorm = norm.indexOf('density') !== -1;
  61705. var i2, binEnd, n;
  61706. if(cumulativeSpec.enabled && densityNorm) {
  61707. // we treat "cumulative" like it means "integral" if you use a density norm,
  61708. // which in the end means it's the same as without "density"
  61709. norm = norm.replace(/ ?density$/, '');
  61710. densityNorm = false;
  61711. }
  61712. var extremeFunc = func === 'max' || func === 'min';
  61713. var sizeInit = extremeFunc ? null : 0;
  61714. var binFunc = binFunctions.count;
  61715. var normFunc = normFunctions[norm];
  61716. var isAvg = false;
  61717. var pr2c = function(v) { return pa.r2c(v, 0, calendar); };
  61718. var rawCounterData;
  61719. if(Lib.isArrayOrTypedArray(trace[counterData]) && func !== 'count') {
  61720. rawCounterData = trace[counterData];
  61721. isAvg = func === 'avg';
  61722. binFunc = binFunctions[func];
  61723. }
  61724. // create the bins (and any extra arrays needed)
  61725. // assume more than 1e6 bins is an error, so we don't crash the browser
  61726. i = pr2c(binSpec.start);
  61727. // decrease end a little in case of rounding errors
  61728. binEnd = pr2c(binSpec.end) + (i - Axes.tickIncrement(i, binSpec.size, false, calendar)) / 1e6;
  61729. while(i < binEnd && pos.length < 1e6) {
  61730. i2 = Axes.tickIncrement(i, binSpec.size, false, calendar);
  61731. pos.push((i + i2) / 2);
  61732. size.push(sizeInit);
  61733. inputPoints.push([]);
  61734. // nonuniform bins (like months) we need to search,
  61735. // rather than straight calculate the bin we're in
  61736. binEdges.push(i);
  61737. // nonuniform bins also need nonuniform normalization factors
  61738. if(densityNorm) inc.push(1 / (i2 - i));
  61739. if(isAvg) counts.push(0);
  61740. // break to avoid infinite loops
  61741. if(i2 <= i) break;
  61742. i = i2;
  61743. }
  61744. binEdges.push(i);
  61745. // for date axes we need bin bounds to be calcdata. For nonuniform bins
  61746. // we already have this, but uniform with start/end/size they're still strings.
  61747. if(!nonuniformBins && pa.type === 'date') {
  61748. bins = {
  61749. start: pr2c(bins.start),
  61750. end: pr2c(bins.end),
  61751. size: bins.size
  61752. };
  61753. }
  61754. // bin the data
  61755. // and make histogram-specific pt-number-to-cd-index map object
  61756. var nMax = size.length;
  61757. var uniqueValsPerBin = true;
  61758. var leftGap = Infinity;
  61759. var rightGap = Infinity;
  61760. var ptNumber2cdIndex = {};
  61761. for(i = 0; i < pos0.length; i++) {
  61762. var posi = pos0[i];
  61763. n = Lib.findBin(posi, bins);
  61764. if(n >= 0 && n < nMax) {
  61765. total += binFunc(n, i, size, rawCounterData, counts);
  61766. if(uniqueValsPerBin && inputPoints[n].length && posi !== pos0[inputPoints[n][0]]) {
  61767. uniqueValsPerBin = false;
  61768. }
  61769. inputPoints[n].push(i);
  61770. ptNumber2cdIndex[i] = n;
  61771. leftGap = Math.min(leftGap, posi - binEdges[n]);
  61772. rightGap = Math.min(rightGap, binEdges[n + 1] - posi);
  61773. }
  61774. }
  61775. var roundFn;
  61776. if(!uniqueValsPerBin) {
  61777. roundFn = getBinSpanLabelRound(leftGap, rightGap, binEdges, pa, calendar);
  61778. }
  61779. // average and/or normalize the data, if needed
  61780. if(isAvg) total = doAvg(size, counts);
  61781. if(normFunc) normFunc(size, total, inc);
  61782. // after all normalization etc, now we can accumulate if desired
  61783. if(cumulativeSpec.enabled) cdf(size, cumulativeSpec.direction, cumulativeSpec.currentbin);
  61784. var seriesLen = Math.min(pos.length, size.length);
  61785. var cd = [];
  61786. var firstNonzero = 0;
  61787. var lastNonzero = seriesLen - 1;
  61788. // look for empty bins at the ends to remove, so autoscale omits them
  61789. for(i = 0; i < seriesLen; i++) {
  61790. if(size[i]) {
  61791. firstNonzero = i;
  61792. break;
  61793. }
  61794. }
  61795. for(i = seriesLen - 1; i >= firstNonzero; i--) {
  61796. if(size[i]) {
  61797. lastNonzero = i;
  61798. break;
  61799. }
  61800. }
  61801. // create the "calculated data" to plot
  61802. for(i = firstNonzero; i <= lastNonzero; i++) {
  61803. if((isNumeric(pos[i]) && isNumeric(size[i]))) {
  61804. var cdi = {
  61805. p: pos[i],
  61806. s: size[i],
  61807. b: 0
  61808. };
  61809. // setup hover and event data fields,
  61810. // N.B. pts and "hover" positions ph0/ph1 don't seem to make much sense
  61811. // for cumulative distributions
  61812. if(!cumulativeSpec.enabled) {
  61813. cdi.pts = inputPoints[i];
  61814. if(uniqueValsPerBin) {
  61815. cdi.ph0 = cdi.ph1 = (inputPoints[i].length) ? pos0[inputPoints[i][0]] : pos[i];
  61816. }
  61817. else {
  61818. cdi.ph0 = roundFn(binEdges[i]);
  61819. cdi.ph1 = roundFn(binEdges[i + 1], true);
  61820. }
  61821. }
  61822. cd.push(cdi);
  61823. }
  61824. }
  61825. if(cd.length === 1) {
  61826. // when we collapse to a single bin, calcdata no longer describes bin size
  61827. // so we need to explicitly specify it
  61828. cd[0].width1 = Axes.tickIncrement(cd[0].p, binSpec.size, false, calendar) - cd[0].p;
  61829. }
  61830. arraysToCalcdata(cd, trace);
  61831. if(Lib.isArrayOrTypedArray(trace.selectedpoints)) {
  61832. Lib.tagSelected(cd, trace, ptNumber2cdIndex);
  61833. }
  61834. return cd;
  61835. };
  61836. /*
  61837. * calcAllAutoBins: we want all histograms on the same axes to share bin specs
  61838. * if they're grouped or stacked. If the user has explicitly specified differing
  61839. * bin specs, there's nothing we can do, but if possible we will try to use the
  61840. * smallest bins of any of the auto values for all histograms grouped/stacked
  61841. * together.
  61842. */
  61843. function calcAllAutoBins(gd, trace, pa, mainData, _overlayEdgeCase) {
  61844. var binAttr = mainData + 'bins';
  61845. var isOverlay = gd._fullLayout.barmode === 'overlay';
  61846. var i, tracei, calendar, firstManual, pos0;
  61847. // all but the first trace in this group has already been marked finished
  61848. // clear this flag, so next time we run calc we will run autobin again
  61849. if(trace._autoBinFinished) {
  61850. delete trace._autoBinFinished;
  61851. }
  61852. else {
  61853. // must be the first trace in the group - do the autobinning on them all
  61854. // find all grouped traces - in overlay mode each trace is independent
  61855. var traceGroup = isOverlay ? [trace] : getConnectedHistograms(gd, trace);
  61856. var autoBinnedTraces = [];
  61857. var minSize = Infinity;
  61858. var minStart = Infinity;
  61859. var maxEnd = -Infinity;
  61860. var autoBinAttr = 'autobin' + mainData;
  61861. for(i = 0; i < traceGroup.length; i++) {
  61862. tracei = traceGroup[i];
  61863. // stash pos0 on the trace so we don't need to duplicate this
  61864. // in the main body of calc
  61865. pos0 = tracei._pos0 = pa.makeCalcdata(tracei, mainData);
  61866. var binSpec = tracei[binAttr];
  61867. if((tracei[autoBinAttr]) || !binSpec ||
  61868. binSpec.start === null || binSpec.end === null) {
  61869. calendar = tracei[mainData + 'calendar'];
  61870. var cumulativeSpec = tracei.cumulative;
  61871. binSpec = Axes.autoBin(pos0, pa, tracei['nbins' + mainData], false, calendar);
  61872. // Edge case: single-valued histogram overlaying others
  61873. // Use them all together to calculate the bin size for the single-valued one
  61874. if(isOverlay && binSpec._dataSpan === 0 && pa.type !== 'category') {
  61875. // Several single-valued histograms! Stop infinite recursion,
  61876. // just return an extra flag that tells handleSingleValueOverlays
  61877. // to sort out this trace too
  61878. if(_overlayEdgeCase) return [binSpec, pos0, true];
  61879. binSpec = handleSingleValueOverlays(gd, trace, pa, mainData, binAttr);
  61880. }
  61881. // adjust for CDF edge cases
  61882. if(cumulativeSpec.enabled && (cumulativeSpec.currentbin !== 'include')) {
  61883. if(cumulativeSpec.direction === 'decreasing') {
  61884. minStart = Math.min(minStart, pa.r2c(binSpec.start, 0, calendar) - binSpec.size);
  61885. }
  61886. else {
  61887. maxEnd = Math.max(maxEnd, pa.r2c(binSpec.end, 0, calendar) + binSpec.size);
  61888. }
  61889. }
  61890. // note that it's possible to get here with an explicit autobin: false
  61891. // if the bins were not specified. mark this trace for followup
  61892. autoBinnedTraces.push(tracei);
  61893. }
  61894. else if(!firstManual) {
  61895. // Remember the first manually set binSpec. We'll try to be extra
  61896. // accommodating of this one, so other bins line up with these.
  61897. // But if there's more than one manual bin set and they're mutually
  61898. // inconsistent, then there's not much we can do...
  61899. firstManual = {
  61900. size: binSpec.size,
  61901. start: pa.r2c(binSpec.start, 0, calendar),
  61902. end: pa.r2c(binSpec.end, 0, calendar)
  61903. };
  61904. }
  61905. // Even non-autobinned traces get included here, so we get the greatest extent
  61906. // and minimum bin size of them all.
  61907. // But manually binned traces won't be adjusted, even if the auto values
  61908. // are inconsistent with the manual ones (or the manual ones are inconsistent
  61909. // with each other).
  61910. minSize = getMinSize(minSize, binSpec.size);
  61911. minStart = Math.min(minStart, pa.r2c(binSpec.start, 0, calendar));
  61912. maxEnd = Math.max(maxEnd, pa.r2c(binSpec.end, 0, calendar));
  61913. // add the flag that lets us abort autobin on later traces
  61914. if(i) tracei._autoBinFinished = 1;
  61915. }
  61916. // do what we can to match the auto bins to the first manual bins
  61917. // but only if sizes are all numeric
  61918. if(firstManual && isNumeric(firstManual.size) && isNumeric(minSize)) {
  61919. // first need to ensure the bin size is the same as or an integer fraction
  61920. // of the first manual bin
  61921. // allow the bin size to increase just under the autobin step size to match,
  61922. // (which is a factor of 2 or 2.5) otherwise shrink it
  61923. if(minSize > firstManual.size / 1.9) minSize = firstManual.size;
  61924. else minSize = firstManual.size / Math.ceil(firstManual.size / minSize);
  61925. // now decrease minStart if needed to make the bin centers line up
  61926. var adjustedFirstStart = firstManual.start + (firstManual.size - minSize) / 2;
  61927. minStart = adjustedFirstStart - minSize * Math.ceil((adjustedFirstStart - minStart) / minSize);
  61928. }
  61929. // now go back to the autobinned traces and update their bin specs with the final values
  61930. for(i = 0; i < autoBinnedTraces.length; i++) {
  61931. tracei = autoBinnedTraces[i];
  61932. calendar = tracei[mainData + 'calendar'];
  61933. tracei._input[binAttr] = tracei[binAttr] = {
  61934. start: pa.c2r(minStart, 0, calendar),
  61935. end: pa.c2r(maxEnd, 0, calendar),
  61936. size: minSize
  61937. };
  61938. // note that it's possible to get here with an explicit autobin: false
  61939. // if the bins were not specified.
  61940. // in that case this will remain in the trace, so that future updates
  61941. // which would change the autobinning will not do so.
  61942. tracei._input[autoBinAttr] = tracei[autoBinAttr];
  61943. }
  61944. }
  61945. pos0 = trace._pos0;
  61946. delete trace._pos0;
  61947. return [trace[binAttr], pos0];
  61948. }
  61949. /*
  61950. * Adjust single-value histograms in overlay mode to make as good a
  61951. * guess as we can at autobin values the user would like.
  61952. *
  61953. * Returns the binSpec for the trace that sparked all this
  61954. */
  61955. function handleSingleValueOverlays(gd, trace, pa, mainData, binAttr) {
  61956. var overlaidTraceGroup = getConnectedHistograms(gd, trace);
  61957. var pastThisTrace = false;
  61958. var minSize = Infinity;
  61959. var singleValuedTraces = [trace];
  61960. var i, tracei;
  61961. // first collect all the:
  61962. // - min bin size from all multi-valued traces
  61963. // - single-valued traces
  61964. for(i = 0; i < overlaidTraceGroup.length; i++) {
  61965. tracei = overlaidTraceGroup[i];
  61966. if(tracei === trace) pastThisTrace = true;
  61967. else if(!pastThisTrace) {
  61968. // This trace has already had its autobins calculated
  61969. // (so must not have been single-valued).
  61970. minSize = Math.min(minSize, tracei[binAttr].size);
  61971. }
  61972. else {
  61973. var resulti = calcAllAutoBins(gd, tracei, pa, mainData, true);
  61974. var binSpeci = resulti[0];
  61975. var isSingleValued = resulti[2];
  61976. // so we can use this result when we get to tracei in the normal
  61977. // course of events, mark it as done and put _pos0 back
  61978. tracei._autoBinFinished = 1;
  61979. tracei._pos0 = resulti[1];
  61980. if(isSingleValued) {
  61981. singleValuedTraces.push(tracei);
  61982. }
  61983. else {
  61984. minSize = Math.min(minSize, binSpeci.size);
  61985. }
  61986. }
  61987. }
  61988. // find the real data values for each single-valued trace
  61989. // hunt through pos0 for the first valid value
  61990. var dataVals = new Array(singleValuedTraces.length);
  61991. for(i = 0; i < singleValuedTraces.length; i++) {
  61992. var pos0 = singleValuedTraces[i]._pos0;
  61993. for(var j = 0; j < pos0.length; j++) {
  61994. if(pos0[j] !== undefined) {
  61995. dataVals[i] = pos0[j];
  61996. break;
  61997. }
  61998. }
  61999. }
  62000. // are ALL traces are single-valued? use the min difference between
  62001. // all of their values (which defaults to 1 if there's still only one)
  62002. if(!isFinite(minSize)) {
  62003. minSize = Lib.distinctVals(dataVals).minDiff;
  62004. }
  62005. // now apply the min size we found to all single-valued traces
  62006. for(i = 0; i < singleValuedTraces.length; i++) {
  62007. tracei = singleValuedTraces[i];
  62008. var calendar = tracei[mainData + 'calendar'];
  62009. tracei._input[binAttr] = tracei[binAttr] = {
  62010. start: pa.c2r(dataVals[i] - minSize / 2, 0, calendar),
  62011. end: pa.c2r(dataVals[i] + minSize / 2, 0, calendar),
  62012. size: minSize
  62013. };
  62014. }
  62015. return trace[binAttr];
  62016. }
  62017. /*
  62018. * Return an array of histograms that share axes and orientation.
  62019. *
  62020. * Only considers histograms. In principle we could include bars in a
  62021. * similar way to how we do manually binned histograms, though this
  62022. * would have tons of edge cases and value judgments to make.
  62023. */
  62024. function getConnectedHistograms(gd, trace) {
  62025. var xid = trace.xaxis;
  62026. var yid = trace.yaxis;
  62027. var orientation = trace.orientation;
  62028. var out = [];
  62029. var fullData = gd._fullData;
  62030. for(var i = 0; i < fullData.length; i++) {
  62031. var tracei = fullData[i];
  62032. if(tracei.type === 'histogram' &&
  62033. tracei.visible === true &&
  62034. tracei.orientation === orientation &&
  62035. tracei.xaxis === xid && tracei.yaxis === yid
  62036. ) {
  62037. out.push(tracei);
  62038. }
  62039. }
  62040. return out;
  62041. }
  62042. /*
  62043. * getMinSize: find the smallest given that size can be a string code
  62044. * ie 'M6' for 6 months. ('L' wouldn't make sense to compare with numeric sizes)
  62045. */
  62046. function getMinSize(size1, size2) {
  62047. if(size1 === Infinity) return size2;
  62048. var sizeNumeric1 = numericSize(size1);
  62049. var sizeNumeric2 = numericSize(size2);
  62050. return sizeNumeric2 < sizeNumeric1 ? size2 : size1;
  62051. }
  62052. function numericSize(size) {
  62053. if(isNumeric(size)) return size;
  62054. if(typeof size === 'string' && size.charAt(0) === 'M') {
  62055. return oneMonth * +(size.substr(1));
  62056. }
  62057. return Infinity;
  62058. }
  62059. function cdf(size, direction, currentBin) {
  62060. var i, vi, prevSum;
  62061. function firstHalfPoint(i) {
  62062. prevSum = size[i];
  62063. size[i] /= 2;
  62064. }
  62065. function nextHalfPoint(i) {
  62066. vi = size[i];
  62067. size[i] = prevSum + vi / 2;
  62068. prevSum += vi;
  62069. }
  62070. if(currentBin === 'half') {
  62071. if(direction === 'increasing') {
  62072. firstHalfPoint(0);
  62073. for(i = 1; i < size.length; i++) {
  62074. nextHalfPoint(i);
  62075. }
  62076. }
  62077. else {
  62078. firstHalfPoint(size.length - 1);
  62079. for(i = size.length - 2; i >= 0; i--) {
  62080. nextHalfPoint(i);
  62081. }
  62082. }
  62083. }
  62084. else if(direction === 'increasing') {
  62085. for(i = 1; i < size.length; i++) {
  62086. size[i] += size[i - 1];
  62087. }
  62088. // 'exclude' is identical to 'include' just shifted one bin over
  62089. if(currentBin === 'exclude') {
  62090. size.unshift(0);
  62091. size.pop();
  62092. }
  62093. }
  62094. else {
  62095. for(i = size.length - 2; i >= 0; i--) {
  62096. size[i] += size[i + 1];
  62097. }
  62098. if(currentBin === 'exclude') {
  62099. size.push(0);
  62100. size.shift();
  62101. }
  62102. }
  62103. }
  62104. },{"../../constants/numerical":151,"../../lib":169,"../../plots/cartesian/axes":214,"../bar/arrays_to_calcdata":268,"./average":333,"./bin_functions":335,"./bin_label_vals":336,"./clean_bins":338,"./norm_functions":343,"fast-isnumeric":18}],338:[function(_dereq_,module,exports){
  62105. /**
  62106. * Copyright 2012-2018, Plotly, Inc.
  62107. * All rights reserved.
  62108. *
  62109. * This source code is licensed under the MIT license found in the
  62110. * LICENSE file in the root directory of this source tree.
  62111. */
  62112. 'use strict';
  62113. var isNumeric = _dereq_('fast-isnumeric');
  62114. var cleanDate = _dereq_('../../lib').cleanDate;
  62115. var constants = _dereq_('../../constants/numerical');
  62116. var ONEDAY = constants.ONEDAY;
  62117. var BADNUM = constants.BADNUM;
  62118. /*
  62119. * cleanBins: validate attributes autobin[xy] and [xy]bins.(start, end, size)
  62120. * Mutates trace so all these attributes are valid.
  62121. *
  62122. * Normally this kind of thing would happen during supplyDefaults, but
  62123. * in this case we need to know the axis type, and axis type isn't set until
  62124. * after trace supplyDefaults are completed. So this gets called during the
  62125. * calc step, when data are inserted into bins.
  62126. */
  62127. module.exports = function cleanBins(trace, ax, binDirection) {
  62128. var axType = ax.type,
  62129. binAttr = binDirection + 'bins',
  62130. bins = trace[binAttr];
  62131. if(!bins) bins = trace[binAttr] = {};
  62132. var cleanBound = (axType === 'date') ?
  62133. function(v) { return (v || v === 0) ? cleanDate(v, BADNUM, bins.calendar) : null; } :
  62134. function(v) { return isNumeric(v) ? Number(v) : null; };
  62135. bins.start = cleanBound(bins.start);
  62136. bins.end = cleanBound(bins.end);
  62137. // logic for bin size is very similar to dtick (cartesian/tick_value_defaults)
  62138. // but without the extra string options for log axes
  62139. // ie the only strings we accept are M<n> for months
  62140. var sizeDflt = (axType === 'date') ? ONEDAY : 1,
  62141. binSize = bins.size;
  62142. if(isNumeric(binSize)) {
  62143. bins.size = (binSize > 0) ? Number(binSize) : sizeDflt;
  62144. }
  62145. else if(typeof binSize !== 'string') {
  62146. bins.size = sizeDflt;
  62147. }
  62148. else {
  62149. // date special case: "M<n>" gives bins every (integer) n months
  62150. var prefix = binSize.charAt(0),
  62151. sizeNum = binSize.substr(1);
  62152. sizeNum = isNumeric(sizeNum) ? Number(sizeNum) : 0;
  62153. if((sizeNum <= 0) || !(
  62154. axType === 'date' && prefix === 'M' && sizeNum === Math.round(sizeNum)
  62155. )) {
  62156. bins.size = sizeDflt;
  62157. }
  62158. }
  62159. var autoBinAttr = 'autobin' + binDirection;
  62160. if(typeof trace[autoBinAttr] !== 'boolean') {
  62161. trace[autoBinAttr] = trace._fullInput[autoBinAttr] = trace._input[autoBinAttr] = !(
  62162. (bins.start || bins.start === 0) &&
  62163. (bins.end || bins.end === 0)
  62164. );
  62165. }
  62166. if(!trace[autoBinAttr]) {
  62167. delete trace['nbins' + binDirection];
  62168. delete trace._fullInput['nbins' + binDirection];
  62169. }
  62170. };
  62171. },{"../../constants/numerical":151,"../../lib":169,"fast-isnumeric":18}],339:[function(_dereq_,module,exports){
  62172. /**
  62173. * Copyright 2012-2018, Plotly, Inc.
  62174. * All rights reserved.
  62175. *
  62176. * This source code is licensed under the MIT license found in the
  62177. * LICENSE file in the root directory of this source tree.
  62178. */
  62179. 'use strict';
  62180. var Registry = _dereq_('../../registry');
  62181. var Lib = _dereq_('../../lib');
  62182. var Color = _dereq_('../../components/color');
  62183. var handleBinDefaults = _dereq_('./bin_defaults');
  62184. var handleStyleDefaults = _dereq_('../bar/style_defaults');
  62185. var attributes = _dereq_('./attributes');
  62186. module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout) {
  62187. function coerce(attr, dflt) {
  62188. return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);
  62189. }
  62190. var x = coerce('x');
  62191. var y = coerce('y');
  62192. var cumulative = coerce('cumulative.enabled');
  62193. if(cumulative) {
  62194. coerce('cumulative.direction');
  62195. coerce('cumulative.currentbin');
  62196. }
  62197. coerce('text');
  62198. var orientation = coerce('orientation', (y && !x) ? 'h' : 'v');
  62199. var sampleLetter = orientation === 'v' ? 'x' : 'y';
  62200. var aggLetter = orientation === 'v' ? 'y' : 'x';
  62201. var len = (x && y) ? Math.min(x.length && y.length) : (traceOut[sampleLetter] || []).length;
  62202. if(!len) {
  62203. traceOut.visible = false;
  62204. return;
  62205. }
  62206. traceOut._length = len;
  62207. var handleCalendarDefaults = Registry.getComponentMethod('calendars', 'handleTraceDefaults');
  62208. handleCalendarDefaults(traceIn, traceOut, ['x', 'y'], layout);
  62209. var hasAggregationData = traceOut[aggLetter];
  62210. if(hasAggregationData) coerce('histfunc');
  62211. handleBinDefaults(traceIn, traceOut, coerce, [sampleLetter]);
  62212. handleStyleDefaults(traceIn, traceOut, coerce, defaultColor, layout);
  62213. // override defaultColor for error bars with defaultLine
  62214. var errorBarsSupplyDefaults = Registry.getComponentMethod('errorbars', 'supplyDefaults');
  62215. errorBarsSupplyDefaults(traceIn, traceOut, Color.defaultLine, {axis: 'y'});
  62216. errorBarsSupplyDefaults(traceIn, traceOut, Color.defaultLine, {axis: 'x', inherit: 'y'});
  62217. Lib.coerceSelectionMarkerOpacity(traceOut, coerce);
  62218. };
  62219. },{"../../components/color":50,"../../lib":169,"../../registry":259,"../bar/style_defaults":281,"./attributes":332,"./bin_defaults":334}],340:[function(_dereq_,module,exports){
  62220. /**
  62221. * Copyright 2012-2018, Plotly, Inc.
  62222. * All rights reserved.
  62223. *
  62224. * This source code is licensed under the MIT license found in the
  62225. * LICENSE file in the root directory of this source tree.
  62226. */
  62227. 'use strict';
  62228. module.exports = function eventData(out, pt, trace, cd, pointNumber) {
  62229. // standard cartesian event data
  62230. out.x = 'xVal' in pt ? pt.xVal : pt.x;
  62231. out.y = 'yVal' in pt ? pt.yVal : pt.y;
  62232. if(pt.xa) out.xaxis = pt.xa;
  62233. if(pt.ya) out.yaxis = pt.ya;
  62234. // specific to histogram - CDFs do not have pts (yet?)
  62235. if(!(trace.cumulative || {}).enabled) {
  62236. var pts = Array.isArray(pointNumber) ?
  62237. cd[0].pts[pointNumber[0]][pointNumber[1]] :
  62238. cd[pointNumber].pts;
  62239. out.pointNumbers = pts;
  62240. out.binNumber = out.pointNumber;
  62241. delete out.pointNumber;
  62242. delete out.pointIndex;
  62243. var pointIndices;
  62244. if(trace._indexToPoints) {
  62245. pointIndices = [];
  62246. for(var i = 0; i < pts.length; i++) {
  62247. pointIndices = pointIndices.concat(trace._indexToPoints[pts[i]]);
  62248. }
  62249. } else {
  62250. pointIndices = pts;
  62251. }
  62252. out.pointIndices = pointIndices;
  62253. }
  62254. return out;
  62255. };
  62256. },{}],341:[function(_dereq_,module,exports){
  62257. /**
  62258. * Copyright 2012-2018, Plotly, Inc.
  62259. * All rights reserved.
  62260. *
  62261. * This source code is licensed under the MIT license found in the
  62262. * LICENSE file in the root directory of this source tree.
  62263. */
  62264. 'use strict';
  62265. var barHover = _dereq_('../bar/hover').hoverPoints;
  62266. var hoverLabelText = _dereq_('../../plots/cartesian/axes').hoverLabelText;
  62267. module.exports = function hoverPoints(pointData, xval, yval, hovermode) {
  62268. var pts = barHover(pointData, xval, yval, hovermode);
  62269. if(!pts) return;
  62270. pointData = pts[0];
  62271. var di = pointData.cd[pointData.index];
  62272. var trace = pointData.cd[0].trace;
  62273. if(!trace.cumulative.enabled) {
  62274. var posLetter = trace.orientation === 'h' ? 'y' : 'x';
  62275. pointData[posLetter + 'Label'] = hoverLabelText(pointData[posLetter + 'a'], di.ph0, di.ph1);
  62276. }
  62277. return pts;
  62278. };
  62279. },{"../../plots/cartesian/axes":214,"../bar/hover":273}],342:[function(_dereq_,module,exports){
  62280. /**
  62281. * Copyright 2012-2018, Plotly, Inc.
  62282. * All rights reserved.
  62283. *
  62284. * This source code is licensed under the MIT license found in the
  62285. * LICENSE file in the root directory of this source tree.
  62286. */
  62287. 'use strict';
  62288. /**
  62289. * Histogram has its own attribute, defaults and calc steps,
  62290. * but uses bar's plot to display
  62291. * and bar's crossTraceCalc (formerly known as setPositions) for stacking and grouping
  62292. */
  62293. /**
  62294. * histogram errorBarsOK is debatable, but it's put in for backward compat.
  62295. * there are use cases for it - sqrt for a simple histogram works right now,
  62296. * constant and % work but they're not so meaningful. I guess it could be cool
  62297. * to allow quadrature combination of errors in summed histograms...
  62298. */
  62299. var Histogram = {};
  62300. Histogram.attributes = _dereq_('./attributes');
  62301. Histogram.layoutAttributes = _dereq_('../bar/layout_attributes');
  62302. Histogram.supplyDefaults = _dereq_('./defaults');
  62303. Histogram.supplyLayoutDefaults = _dereq_('../bar/layout_defaults');
  62304. Histogram.calc = _dereq_('./calc');
  62305. Histogram.crossTraceCalc = _dereq_('../bar/cross_trace_calc').crossTraceCalc;
  62306. Histogram.plot = _dereq_('../bar/plot');
  62307. Histogram.layerName = 'barlayer';
  62308. Histogram.style = _dereq_('../bar/style').style;
  62309. Histogram.styleOnSelect = _dereq_('../bar/style').styleOnSelect;
  62310. Histogram.colorbar = _dereq_('../scatter/marker_colorbar');
  62311. Histogram.hoverPoints = _dereq_('./hover');
  62312. Histogram.selectPoints = _dereq_('../bar/select');
  62313. Histogram.eventData = _dereq_('./event_data');
  62314. Histogram.moduleType = 'trace';
  62315. Histogram.name = 'histogram';
  62316. Histogram.basePlotModule = _dereq_('../../plots/cartesian');
  62317. Histogram.categories = ['cartesian', 'svg', 'bar', 'histogram', 'oriented', 'errorBarsOK', 'showLegend'];
  62318. Histogram.meta = {
  62319. };
  62320. module.exports = Histogram;
  62321. },{"../../plots/cartesian":225,"../bar/cross_trace_calc":271,"../bar/layout_attributes":275,"../bar/layout_defaults":276,"../bar/plot":277,"../bar/select":278,"../bar/style":280,"../scatter/marker_colorbar":384,"./attributes":332,"./calc":337,"./defaults":339,"./event_data":340,"./hover":341}],343:[function(_dereq_,module,exports){
  62322. /**
  62323. * Copyright 2012-2018, Plotly, Inc.
  62324. * All rights reserved.
  62325. *
  62326. * This source code is licensed under the MIT license found in the
  62327. * LICENSE file in the root directory of this source tree.
  62328. */
  62329. 'use strict';
  62330. module.exports = {
  62331. percent: function(size, total) {
  62332. var nMax = size.length,
  62333. norm = 100 / total;
  62334. for(var n = 0; n < nMax; n++) size[n] *= norm;
  62335. },
  62336. probability: function(size, total) {
  62337. var nMax = size.length;
  62338. for(var n = 0; n < nMax; n++) size[n] /= total;
  62339. },
  62340. density: function(size, total, inc, yinc) {
  62341. var nMax = size.length;
  62342. yinc = yinc || 1;
  62343. for(var n = 0; n < nMax; n++) size[n] *= inc[n] * yinc;
  62344. },
  62345. 'probability density': function(size, total, inc, yinc) {
  62346. var nMax = size.length;
  62347. if(yinc) total /= yinc;
  62348. for(var n = 0; n < nMax; n++) size[n] *= inc[n] / total;
  62349. }
  62350. };
  62351. },{}],344:[function(_dereq_,module,exports){
  62352. /**
  62353. * Copyright 2012-2018, Plotly, Inc.
  62354. * All rights reserved.
  62355. *
  62356. * This source code is licensed under the MIT license found in the
  62357. * LICENSE file in the root directory of this source tree.
  62358. */
  62359. 'use strict';
  62360. var histogramAttrs = _dereq_('../histogram/attributes');
  62361. var heatmapAttrs = _dereq_('../heatmap/attributes');
  62362. var colorscaleAttrs = _dereq_('../../components/colorscale/attributes');
  62363. var colorbarAttrs = _dereq_('../../components/colorbar/attributes');
  62364. var extendFlat = _dereq_('../../lib/extend').extendFlat;
  62365. module.exports = extendFlat(
  62366. {
  62367. x: histogramAttrs.x,
  62368. y: histogramAttrs.y,
  62369. z: {
  62370. valType: 'data_array',
  62371. editType: 'calc',
  62372. },
  62373. marker: {
  62374. color: {
  62375. valType: 'data_array',
  62376. editType: 'calc',
  62377. },
  62378. editType: 'calc'
  62379. },
  62380. histnorm: histogramAttrs.histnorm,
  62381. histfunc: histogramAttrs.histfunc,
  62382. autobinx: histogramAttrs.autobinx,
  62383. nbinsx: histogramAttrs.nbinsx,
  62384. xbins: histogramAttrs.xbins,
  62385. autobiny: histogramAttrs.autobiny,
  62386. nbinsy: histogramAttrs.nbinsy,
  62387. ybins: histogramAttrs.ybins,
  62388. xgap: heatmapAttrs.xgap,
  62389. ygap: heatmapAttrs.ygap,
  62390. zsmooth: heatmapAttrs.zsmooth,
  62391. zhoverformat: heatmapAttrs.zhoverformat
  62392. },
  62393. colorscaleAttrs('', {
  62394. cLetter: 'z',
  62395. autoColorDflt: false
  62396. }),
  62397. { colorbar: colorbarAttrs }
  62398. );
  62399. },{"../../components/colorbar/attributes":51,"../../components/colorscale/attributes":57,"../../lib/extend":163,"../heatmap/attributes":316,"../histogram/attributes":332}],345:[function(_dereq_,module,exports){
  62400. /**
  62401. * Copyright 2012-2018, Plotly, Inc.
  62402. * All rights reserved.
  62403. *
  62404. * This source code is licensed under the MIT license found in the
  62405. * LICENSE file in the root directory of this source tree.
  62406. */
  62407. 'use strict';
  62408. var Lib = _dereq_('../../lib');
  62409. var Axes = _dereq_('../../plots/cartesian/axes');
  62410. var binFunctions = _dereq_('../histogram/bin_functions');
  62411. var normFunctions = _dereq_('../histogram/norm_functions');
  62412. var doAvg = _dereq_('../histogram/average');
  62413. var cleanBins = _dereq_('../histogram/clean_bins');
  62414. var getBinSpanLabelRound = _dereq_('../histogram/bin_label_vals');
  62415. module.exports = function calc(gd, trace) {
  62416. var xa = Axes.getFromId(gd, trace.xaxis || 'x');
  62417. var x = trace.x ? xa.makeCalcdata(trace, 'x') : [];
  62418. var ya = Axes.getFromId(gd, trace.yaxis || 'y');
  62419. var y = trace.y ? ya.makeCalcdata(trace, 'y') : [];
  62420. var xcalendar = trace.xcalendar;
  62421. var ycalendar = trace.ycalendar;
  62422. var xr2c = function(v) { return xa.r2c(v, 0, xcalendar); };
  62423. var yr2c = function(v) { return ya.r2c(v, 0, ycalendar); };
  62424. var xc2r = function(v) { return xa.c2r(v, 0, xcalendar); };
  62425. var yc2r = function(v) { return ya.c2r(v, 0, ycalendar); };
  62426. var i, j, n, m;
  62427. var serieslen = trace._length;
  62428. if(x.length > serieslen) x.splice(serieslen, x.length - serieslen);
  62429. if(y.length > serieslen) y.splice(serieslen, y.length - serieslen);
  62430. // calculate the bins
  62431. cleanAndAutobin(trace, 'x', x, xa, xr2c, xc2r, xcalendar);
  62432. cleanAndAutobin(trace, 'y', y, ya, yr2c, yc2r, ycalendar);
  62433. // make the empty bin array & scale the map
  62434. var z = [];
  62435. var onecol = [];
  62436. var zerocol = [];
  62437. var nonuniformBinsX = (typeof(trace.xbins.size) === 'string');
  62438. var nonuniformBinsY = (typeof(trace.ybins.size) === 'string');
  62439. var xEdges = [];
  62440. var yEdges = [];
  62441. var xbins = nonuniformBinsX ? xEdges : trace.xbins;
  62442. var ybins = nonuniformBinsY ? yEdges : trace.ybins;
  62443. var total = 0;
  62444. var counts = [];
  62445. var inputPoints = [];
  62446. var norm = trace.histnorm;
  62447. var func = trace.histfunc;
  62448. var densitynorm = (norm.indexOf('density') !== -1);
  62449. var extremefunc = (func === 'max' || func === 'min');
  62450. var sizeinit = (extremefunc ? null : 0);
  62451. var binfunc = binFunctions.count;
  62452. var normfunc = normFunctions[norm];
  62453. var doavg = false;
  62454. var xinc = [];
  62455. var yinc = [];
  62456. // set a binning function other than count?
  62457. // for binning functions: check first for 'z',
  62458. // then 'mc' in case we had a colored scatter plot
  62459. // and want to transfer these colors to the 2D histo
  62460. // TODO: axe this, make it the responsibility of the app changing type? or an impliedEdit?
  62461. var rawCounterData = ('z' in trace) ?
  62462. trace.z :
  62463. (('marker' in trace && Array.isArray(trace.marker.color)) ?
  62464. trace.marker.color : '');
  62465. if(rawCounterData && func !== 'count') {
  62466. doavg = func === 'avg';
  62467. binfunc = binFunctions[func];
  62468. }
  62469. // decrease end a little in case of rounding errors
  62470. var binSpec = trace.xbins,
  62471. binStart = xr2c(binSpec.start),
  62472. binEnd = xr2c(binSpec.end) +
  62473. (binStart - Axes.tickIncrement(binStart, binSpec.size, false, xcalendar)) / 1e6;
  62474. for(i = binStart; i < binEnd; i = Axes.tickIncrement(i, binSpec.size, false, xcalendar)) {
  62475. onecol.push(sizeinit);
  62476. xEdges.push(i);
  62477. if(doavg) zerocol.push(0);
  62478. }
  62479. xEdges.push(i);
  62480. var nx = onecol.length;
  62481. var x0c = xr2c(trace.xbins.start);
  62482. var dx = (i - x0c) / nx;
  62483. var x0 = xc2r(x0c + dx / 2);
  62484. binSpec = trace.ybins;
  62485. binStart = yr2c(binSpec.start);
  62486. binEnd = yr2c(binSpec.end) +
  62487. (binStart - Axes.tickIncrement(binStart, binSpec.size, false, ycalendar)) / 1e6;
  62488. for(i = binStart; i < binEnd; i = Axes.tickIncrement(i, binSpec.size, false, ycalendar)) {
  62489. z.push(onecol.slice());
  62490. yEdges.push(i);
  62491. var ipCol = new Array(nx);
  62492. for(j = 0; j < nx; j++) ipCol[j] = [];
  62493. inputPoints.push(ipCol);
  62494. if(doavg) counts.push(zerocol.slice());
  62495. }
  62496. yEdges.push(i);
  62497. var ny = z.length;
  62498. var y0c = yr2c(trace.ybins.start);
  62499. var dy = (i - y0c) / ny;
  62500. var y0 = yc2r(y0c + dy / 2);
  62501. if(densitynorm) {
  62502. xinc = makeIncrements(onecol.length, xbins, dx, nonuniformBinsX);
  62503. yinc = makeIncrements(z.length, ybins, dy, nonuniformBinsY);
  62504. }
  62505. // for date axes we need bin bounds to be calcdata. For nonuniform bins
  62506. // we already have this, but uniform with start/end/size they're still strings.
  62507. if(!nonuniformBinsX && xa.type === 'date') xbins = binsToCalc(xr2c, xbins);
  62508. if(!nonuniformBinsY && ya.type === 'date') ybins = binsToCalc(yr2c, ybins);
  62509. // put data into bins
  62510. var uniqueValsPerX = true;
  62511. var uniqueValsPerY = true;
  62512. var xVals = new Array(nx);
  62513. var yVals = new Array(ny);
  62514. var xGapLow = Infinity;
  62515. var xGapHigh = Infinity;
  62516. var yGapLow = Infinity;
  62517. var yGapHigh = Infinity;
  62518. for(i = 0; i < serieslen; i++) {
  62519. var xi = x[i];
  62520. var yi = y[i];
  62521. n = Lib.findBin(xi, xbins);
  62522. m = Lib.findBin(yi, ybins);
  62523. if(n >= 0 && n < nx && m >= 0 && m < ny) {
  62524. total += binfunc(n, i, z[m], rawCounterData, counts[m]);
  62525. inputPoints[m][n].push(i);
  62526. if(uniqueValsPerX) {
  62527. if(xVals[n] === undefined) xVals[n] = xi;
  62528. else if(xVals[n] !== xi) uniqueValsPerX = false;
  62529. }
  62530. if(uniqueValsPerY) {
  62531. if(yVals[n] === undefined) yVals[n] = yi;
  62532. else if(yVals[n] !== yi) uniqueValsPerY = false;
  62533. }
  62534. xGapLow = Math.min(xGapLow, xi - xEdges[n]);
  62535. xGapHigh = Math.min(xGapHigh, xEdges[n + 1] - xi);
  62536. yGapLow = Math.min(yGapLow, yi - yEdges[m]);
  62537. yGapHigh = Math.min(yGapHigh, yEdges[m + 1] - yi);
  62538. }
  62539. }
  62540. // normalize, if needed
  62541. if(doavg) {
  62542. for(m = 0; m < ny; m++) total += doAvg(z[m], counts[m]);
  62543. }
  62544. if(normfunc) {
  62545. for(m = 0; m < ny; m++) normfunc(z[m], total, xinc, yinc[m]);
  62546. }
  62547. return {
  62548. x: x,
  62549. xRanges: getRanges(xEdges, uniqueValsPerX && xVals, xGapLow, xGapHigh, xa, xcalendar),
  62550. x0: x0,
  62551. dx: dx,
  62552. y: y,
  62553. yRanges: getRanges(yEdges, uniqueValsPerY && yVals, yGapLow, yGapHigh, ya, ycalendar),
  62554. y0: y0,
  62555. dy: dy,
  62556. z: z,
  62557. pts: inputPoints
  62558. };
  62559. };
  62560. function cleanAndAutobin(trace, axLetter, data, ax, r2c, c2r, calendar) {
  62561. var binSpecAttr = axLetter + 'bins';
  62562. var autoBinAttr = 'autobin' + axLetter;
  62563. var binSpec = trace[binSpecAttr];
  62564. cleanBins(trace, ax, axLetter);
  62565. if(trace[autoBinAttr] || !binSpec || binSpec.start === null || binSpec.end === null) {
  62566. binSpec = Axes.autoBin(data, ax, trace['nbins' + axLetter], '2d', calendar);
  62567. if(trace.type === 'histogram2dcontour') {
  62568. // the "true" last argument reverses the tick direction (which we can't
  62569. // just do with a minus sign because of month bins)
  62570. binSpec.start = c2r(Axes.tickIncrement(
  62571. r2c(binSpec.start), binSpec.size, true, calendar));
  62572. binSpec.end = c2r(Axes.tickIncrement(
  62573. r2c(binSpec.end), binSpec.size, false, calendar));
  62574. }
  62575. // copy bin info back to the source data.
  62576. trace._input[binSpecAttr] = trace[binSpecAttr] = binSpec;
  62577. // note that it's possible to get here with an explicit autobin: false
  62578. // if the bins were not specified.
  62579. // in that case this will remain in the trace, so that future updates
  62580. // which would change the autobinning will not do so.
  62581. trace._input[autoBinAttr] = trace[autoBinAttr];
  62582. }
  62583. }
  62584. function makeIncrements(len, bins, dv, nonuniform) {
  62585. var out = new Array(len);
  62586. var i;
  62587. if(nonuniform) {
  62588. for(i = 0; i < len; i++) out[i] = 1 / (bins[i + 1] - bins[i]);
  62589. }
  62590. else {
  62591. var inc = 1 / dv;
  62592. for(i = 0; i < len; i++) out[i] = inc;
  62593. }
  62594. return out;
  62595. }
  62596. function binsToCalc(r2c, bins) {
  62597. return {
  62598. start: r2c(bins.start),
  62599. end: r2c(bins.end),
  62600. size: bins.size
  62601. };
  62602. }
  62603. function getRanges(edges, uniqueVals, gapLow, gapHigh, ax, calendar) {
  62604. var i;
  62605. var len = edges.length - 1;
  62606. var out = new Array(len);
  62607. if(uniqueVals) {
  62608. for(i = 0; i < len; i++) out[i] = [uniqueVals[i], uniqueVals[i]];
  62609. }
  62610. else {
  62611. var roundFn = getBinSpanLabelRound(gapLow, gapHigh, edges, ax, calendar);
  62612. for(i = 0; i < len; i++) out[i] = [roundFn(edges[i]), roundFn(edges[i + 1], true)];
  62613. }
  62614. return out;
  62615. }
  62616. },{"../../lib":169,"../../plots/cartesian/axes":214,"../histogram/average":333,"../histogram/bin_functions":335,"../histogram/bin_label_vals":336,"../histogram/clean_bins":338,"../histogram/norm_functions":343}],346:[function(_dereq_,module,exports){
  62617. /**
  62618. * Copyright 2012-2018, Plotly, Inc.
  62619. * All rights reserved.
  62620. *
  62621. * This source code is licensed under the MIT license found in the
  62622. * LICENSE file in the root directory of this source tree.
  62623. */
  62624. 'use strict';
  62625. var Lib = _dereq_('../../lib');
  62626. var handleSampleDefaults = _dereq_('./sample_defaults');
  62627. var handleStyleDefaults = _dereq_('../heatmap/style_defaults');
  62628. var colorscaleDefaults = _dereq_('../../components/colorscale/defaults');
  62629. var attributes = _dereq_('./attributes');
  62630. module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout) {
  62631. function coerce(attr, dflt) {
  62632. return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);
  62633. }
  62634. handleSampleDefaults(traceIn, traceOut, coerce, layout);
  62635. if(traceOut.visible === false) return;
  62636. handleStyleDefaults(traceIn, traceOut, coerce, layout);
  62637. colorscaleDefaults(
  62638. traceIn, traceOut, layout, coerce, {prefix: '', cLetter: 'z'}
  62639. );
  62640. };
  62641. },{"../../components/colorscale/defaults":60,"../../lib":169,"../heatmap/style_defaults":330,"./attributes":344,"./sample_defaults":349}],347:[function(_dereq_,module,exports){
  62642. /**
  62643. * Copyright 2012-2018, Plotly, Inc.
  62644. * All rights reserved.
  62645. *
  62646. * This source code is licensed under the MIT license found in the
  62647. * LICENSE file in the root directory of this source tree.
  62648. */
  62649. 'use strict';
  62650. var heatmapHover = _dereq_('../heatmap/hover');
  62651. var hoverLabelText = _dereq_('../../plots/cartesian/axes').hoverLabelText;
  62652. module.exports = function hoverPoints(pointData, xval, yval, hovermode, hoverLayer, contour) {
  62653. var pts = heatmapHover(pointData, xval, yval, hovermode, hoverLayer, contour);
  62654. if(!pts) return;
  62655. pointData = pts[0];
  62656. var indices = pointData.index;
  62657. var ny = indices[0];
  62658. var nx = indices[1];
  62659. var cd0 = pointData.cd[0];
  62660. var xRange = cd0.xRanges[nx];
  62661. var yRange = cd0.yRanges[ny];
  62662. pointData.xLabel = hoverLabelText(pointData.xa, xRange[0], xRange[1]);
  62663. pointData.yLabel = hoverLabelText(pointData.ya, yRange[0], yRange[1]);
  62664. return pts;
  62665. };
  62666. },{"../../plots/cartesian/axes":214,"../heatmap/hover":323}],348:[function(_dereq_,module,exports){
  62667. /**
  62668. * Copyright 2012-2018, Plotly, Inc.
  62669. * All rights reserved.
  62670. *
  62671. * This source code is licensed under the MIT license found in the
  62672. * LICENSE file in the root directory of this source tree.
  62673. */
  62674. 'use strict';
  62675. var Histogram2D = {};
  62676. Histogram2D.attributes = _dereq_('./attributes');
  62677. Histogram2D.supplyDefaults = _dereq_('./defaults');
  62678. Histogram2D.calc = _dereq_('../heatmap/calc');
  62679. Histogram2D.plot = _dereq_('../heatmap/plot');
  62680. Histogram2D.layerName = 'heatmaplayer';
  62681. Histogram2D.colorbar = _dereq_('../heatmap/colorbar');
  62682. Histogram2D.style = _dereq_('../heatmap/style');
  62683. Histogram2D.hoverPoints = _dereq_('./hover');
  62684. Histogram2D.eventData = _dereq_('../histogram/event_data');
  62685. Histogram2D.moduleType = 'trace';
  62686. Histogram2D.name = 'histogram2d';
  62687. Histogram2D.basePlotModule = _dereq_('../../plots/cartesian');
  62688. Histogram2D.categories = ['cartesian', 'svg', '2dMap', 'histogram'];
  62689. Histogram2D.meta = {
  62690. };
  62691. module.exports = Histogram2D;
  62692. },{"../../plots/cartesian":225,"../heatmap/calc":317,"../heatmap/colorbar":319,"../heatmap/plot":328,"../heatmap/style":329,"../histogram/event_data":340,"./attributes":344,"./defaults":346,"./hover":347}],349:[function(_dereq_,module,exports){
  62693. /**
  62694. * Copyright 2012-2018, Plotly, Inc.
  62695. * All rights reserved.
  62696. *
  62697. * This source code is licensed under the MIT license found in the
  62698. * LICENSE file in the root directory of this source tree.
  62699. */
  62700. 'use strict';
  62701. var Registry = _dereq_('../../registry');
  62702. var handleBinDefaults = _dereq_('../histogram/bin_defaults');
  62703. module.exports = function handleSampleDefaults(traceIn, traceOut, coerce, layout) {
  62704. var x = coerce('x');
  62705. var y = coerce('y');
  62706. // we could try to accept x0 and dx, etc...
  62707. // but that's a pretty weird use case.
  62708. // for now require both x and y explicitly specified.
  62709. if(!(x && x.length && y && y.length)) {
  62710. traceOut.visible = false;
  62711. return;
  62712. }
  62713. traceOut._length = Math.min(x.length, y.length);
  62714. var handleCalendarDefaults = Registry.getComponentMethod('calendars', 'handleTraceDefaults');
  62715. handleCalendarDefaults(traceIn, traceOut, ['x', 'y'], layout);
  62716. // if marker.color is an array, we can use it in aggregation instead of z
  62717. var hasAggregationData = coerce('z') || coerce('marker.color');
  62718. if(hasAggregationData) coerce('histfunc');
  62719. var binDirections = ['x', 'y'];
  62720. handleBinDefaults(traceIn, traceOut, coerce, binDirections);
  62721. };
  62722. },{"../../registry":259,"../histogram/bin_defaults":334}],350:[function(_dereq_,module,exports){
  62723. /**
  62724. * Copyright 2012-2018, Plotly, Inc.
  62725. * All rights reserved.
  62726. *
  62727. * This source code is licensed under the MIT license found in the
  62728. * LICENSE file in the root directory of this source tree.
  62729. */
  62730. 'use strict';
  62731. var histogram2dAttrs = _dereq_('../histogram2d/attributes');
  62732. var contourAttrs = _dereq_('../contour/attributes');
  62733. var colorscaleAttrs = _dereq_('../../components/colorscale/attributes');
  62734. var colorbarAttrs = _dereq_('../../components/colorbar/attributes');
  62735. var extendFlat = _dereq_('../../lib/extend').extendFlat;
  62736. module.exports = extendFlat({
  62737. x: histogram2dAttrs.x,
  62738. y: histogram2dAttrs.y,
  62739. z: histogram2dAttrs.z,
  62740. marker: histogram2dAttrs.marker,
  62741. histnorm: histogram2dAttrs.histnorm,
  62742. histfunc: histogram2dAttrs.histfunc,
  62743. autobinx: histogram2dAttrs.autobinx,
  62744. nbinsx: histogram2dAttrs.nbinsx,
  62745. xbins: histogram2dAttrs.xbins,
  62746. autobiny: histogram2dAttrs.autobiny,
  62747. nbinsy: histogram2dAttrs.nbinsy,
  62748. ybins: histogram2dAttrs.ybins,
  62749. autocontour: contourAttrs.autocontour,
  62750. ncontours: contourAttrs.ncontours,
  62751. contours: contourAttrs.contours,
  62752. line: contourAttrs.line,
  62753. zhoverformat: histogram2dAttrs.zhoverformat
  62754. },
  62755. colorscaleAttrs('', {
  62756. cLetter: 'z',
  62757. editTypeOverride: 'calc'
  62758. }),
  62759. { colorbar: colorbarAttrs }
  62760. );
  62761. },{"../../components/colorbar/attributes":51,"../../components/colorscale/attributes":57,"../../lib/extend":163,"../contour/attributes":294,"../histogram2d/attributes":344}],351:[function(_dereq_,module,exports){
  62762. /**
  62763. * Copyright 2012-2018, Plotly, Inc.
  62764. * All rights reserved.
  62765. *
  62766. * This source code is licensed under the MIT license found in the
  62767. * LICENSE file in the root directory of this source tree.
  62768. */
  62769. 'use strict';
  62770. var Lib = _dereq_('../../lib');
  62771. var handleSampleDefaults = _dereq_('../histogram2d/sample_defaults');
  62772. var handleContoursDefaults = _dereq_('../contour/contours_defaults');
  62773. var handleStyleDefaults = _dereq_('../contour/style_defaults');
  62774. var attributes = _dereq_('./attributes');
  62775. module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout) {
  62776. function coerce(attr, dflt) {
  62777. return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);
  62778. }
  62779. function coerce2(attr) {
  62780. return Lib.coerce2(traceIn, traceOut, attributes, attr);
  62781. }
  62782. handleSampleDefaults(traceIn, traceOut, coerce, layout);
  62783. if(traceOut.visible === false) return;
  62784. handleContoursDefaults(traceIn, traceOut, coerce, coerce2);
  62785. handleStyleDefaults(traceIn, traceOut, coerce, layout);
  62786. };
  62787. },{"../../lib":169,"../contour/contours_defaults":301,"../contour/style_defaults":315,"../histogram2d/sample_defaults":349,"./attributes":350}],352:[function(_dereq_,module,exports){
  62788. /**
  62789. * Copyright 2012-2018, Plotly, Inc.
  62790. * All rights reserved.
  62791. *
  62792. * This source code is licensed under the MIT license found in the
  62793. * LICENSE file in the root directory of this source tree.
  62794. */
  62795. 'use strict';
  62796. var Histogram2dContour = {};
  62797. Histogram2dContour.attributes = _dereq_('./attributes');
  62798. Histogram2dContour.supplyDefaults = _dereq_('./defaults');
  62799. Histogram2dContour.calc = _dereq_('../contour/calc');
  62800. Histogram2dContour.plot = _dereq_('../contour/plot').plot;
  62801. Histogram2dContour.layerName = 'contourlayer';
  62802. Histogram2dContour.style = _dereq_('../contour/style');
  62803. Histogram2dContour.colorbar = _dereq_('../contour/colorbar');
  62804. Histogram2dContour.hoverPoints = _dereq_('../contour/hover');
  62805. Histogram2dContour.moduleType = 'trace';
  62806. Histogram2dContour.name = 'histogram2dcontour';
  62807. Histogram2dContour.basePlotModule = _dereq_('../../plots/cartesian');
  62808. Histogram2dContour.categories = ['cartesian', 'svg', '2dMap', 'contour', 'histogram', 'showLegend'];
  62809. Histogram2dContour.meta = {
  62810. };
  62811. module.exports = Histogram2dContour;
  62812. },{"../../plots/cartesian":225,"../contour/calc":295,"../contour/colorbar":297,"../contour/hover":307,"../contour/plot":312,"../contour/style":314,"./attributes":350,"./defaults":351}],353:[function(_dereq_,module,exports){
  62813. /**
  62814. * Copyright 2012-2018, Plotly, Inc.
  62815. * All rights reserved.
  62816. *
  62817. * This source code is licensed under the MIT license found in the
  62818. * LICENSE file in the root directory of this source tree.
  62819. */
  62820. 'use strict';
  62821. var colorAttrs = _dereq_('../../components/color/attributes');
  62822. var fontAttrs = _dereq_('../../plots/font_attributes');
  62823. var plotAttrs = _dereq_('../../plots/attributes');
  62824. var domainAttrs = _dereq_('../../plots/domain').attributes;
  62825. var extendFlat = _dereq_('../../lib/extend').extendFlat;
  62826. var textFontAttrs = fontAttrs({
  62827. editType: 'calc',
  62828. colorEditType: 'style',
  62829. });
  62830. module.exports = {
  62831. labels: {
  62832. valType: 'data_array',
  62833. editType: 'calc',
  62834. },
  62835. // equivalent of x0 and dx, if label is missing
  62836. label0: {
  62837. valType: 'number',
  62838. dflt: 0,
  62839. editType: 'calc',
  62840. },
  62841. dlabel: {
  62842. valType: 'number',
  62843. dflt: 1,
  62844. editType: 'calc',
  62845. },
  62846. values: {
  62847. valType: 'data_array',
  62848. editType: 'calc',
  62849. },
  62850. marker: {
  62851. colors: {
  62852. valType: 'data_array', // TODO 'color_array' ?
  62853. editType: 'calc',
  62854. },
  62855. line: {
  62856. color: {
  62857. valType: 'color',
  62858. dflt: colorAttrs.defaultLine,
  62859. arrayOk: true,
  62860. editType: 'style',
  62861. },
  62862. width: {
  62863. valType: 'number',
  62864. min: 0,
  62865. dflt: 0,
  62866. arrayOk: true,
  62867. editType: 'style',
  62868. },
  62869. editType: 'calc'
  62870. },
  62871. editType: 'calc'
  62872. },
  62873. text: {
  62874. valType: 'data_array',
  62875. editType: 'calc',
  62876. },
  62877. hovertext: {
  62878. valType: 'string',
  62879. dflt: '',
  62880. arrayOk: true,
  62881. editType: 'style',
  62882. },
  62883. // 'see eg:'
  62884. // 'https://www.e-education.psu.edu/natureofgeoinfo/sites/www.e-education.psu.edu.natureofgeoinfo/files/image/hisp_pies.gif',
  62885. // '(this example involves a map too - may someday be a whole trace type',
  62886. // 'of its own. but the point is the size of the whole pie is important.)'
  62887. scalegroup: {
  62888. valType: 'string',
  62889. dflt: '',
  62890. editType: 'calc',
  62891. },
  62892. // labels (legend is handled by plots.attributes.showlegend and layout.hiddenlabels)
  62893. textinfo: {
  62894. valType: 'flaglist',
  62895. flags: ['label', 'text', 'value', 'percent'],
  62896. extras: ['none'],
  62897. editType: 'calc',
  62898. },
  62899. hoverinfo: extendFlat({}, plotAttrs.hoverinfo, {
  62900. flags: ['label', 'text', 'value', 'percent', 'name']
  62901. }),
  62902. textposition: {
  62903. valType: 'enumerated',
  62904. values: ['inside', 'outside', 'auto', 'none'],
  62905. dflt: 'auto',
  62906. arrayOk: true,
  62907. editType: 'calc',
  62908. },
  62909. // TODO make those arrayOk?
  62910. textfont: extendFlat({}, textFontAttrs, {
  62911. }),
  62912. insidetextfont: extendFlat({}, textFontAttrs, {
  62913. }),
  62914. outsidetextfont: extendFlat({}, textFontAttrs, {
  62915. }),
  62916. // position and shape
  62917. domain: domainAttrs({name: 'pie', trace: true, editType: 'calc'}),
  62918. hole: {
  62919. valType: 'number',
  62920. min: 0,
  62921. max: 1,
  62922. dflt: 0,
  62923. editType: 'calc',
  62924. },
  62925. // ordering and direction
  62926. sort: {
  62927. valType: 'boolean',
  62928. dflt: true,
  62929. editType: 'calc',
  62930. },
  62931. direction: {
  62932. /**
  62933. * there are two common conventions, both of which place the first
  62934. * (largest, if sorted) slice with its left edge at 12 o'clock but
  62935. * succeeding slices follow either cw or ccw from there.
  62936. *
  62937. * see http://visage.co/data-visualization-101-pie-charts/
  62938. */
  62939. valType: 'enumerated',
  62940. values: ['clockwise', 'counterclockwise'],
  62941. dflt: 'counterclockwise',
  62942. editType: 'calc',
  62943. },
  62944. rotation: {
  62945. valType: 'number',
  62946. min: -360,
  62947. max: 360,
  62948. dflt: 0,
  62949. editType: 'calc',
  62950. },
  62951. pull: {
  62952. valType: 'number',
  62953. min: 0,
  62954. max: 1,
  62955. dflt: 0,
  62956. arrayOk: true,
  62957. editType: 'calc',
  62958. }
  62959. };
  62960. },{"../../components/color/attributes":49,"../../lib/extend":163,"../../plots/attributes":211,"../../plots/domain":239,"../../plots/font_attributes":240}],354:[function(_dereq_,module,exports){
  62961. /**
  62962. * Copyright 2012-2018, Plotly, Inc.
  62963. * All rights reserved.
  62964. *
  62965. * This source code is licensed under the MIT license found in the
  62966. * LICENSE file in the root directory of this source tree.
  62967. */
  62968. 'use strict';
  62969. var Registry = _dereq_('../../registry');
  62970. var getModuleCalcData = _dereq_('../../plots/get_data').getModuleCalcData;
  62971. exports.name = 'pie';
  62972. exports.plot = function(gd) {
  62973. var Pie = Registry.getModule('pie');
  62974. var cdPie = getModuleCalcData(gd.calcdata, Pie)[0];
  62975. if(cdPie.length) Pie.plot(gd, cdPie);
  62976. };
  62977. exports.clean = function(newFullData, newFullLayout, oldFullData, oldFullLayout) {
  62978. var hadPie = (oldFullLayout._has && oldFullLayout._has('pie'));
  62979. var hasPie = (newFullLayout._has && newFullLayout._has('pie'));
  62980. if(hadPie && !hasPie) {
  62981. oldFullLayout._pielayer.selectAll('g.trace').remove();
  62982. }
  62983. };
  62984. },{"../../plots/get_data":242,"../../registry":259}],355:[function(_dereq_,module,exports){
  62985. /**
  62986. * Copyright 2012-2018, Plotly, Inc.
  62987. * All rights reserved.
  62988. *
  62989. * This source code is licensed under the MIT license found in the
  62990. * LICENSE file in the root directory of this source tree.
  62991. */
  62992. 'use strict';
  62993. var isNumeric = _dereq_('fast-isnumeric');
  62994. var isArrayOrTypedArray = _dereq_('../../lib').isArrayOrTypedArray;
  62995. var tinycolor = _dereq_('tinycolor2');
  62996. var Color = _dereq_('../../components/color');
  62997. var helpers = _dereq_('./helpers');
  62998. exports.calc = function calc(gd, trace) {
  62999. var vals = trace.values;
  63000. var hasVals = isArrayOrTypedArray(vals) && vals.length;
  63001. var labels = trace.labels;
  63002. var colors = trace.marker.colors || [];
  63003. var cd = [];
  63004. var fullLayout = gd._fullLayout;
  63005. var colorMap = fullLayout._piecolormap;
  63006. var allThisTraceLabels = {};
  63007. var vTotal = 0;
  63008. var hiddenLabels = fullLayout.hiddenlabels || [];
  63009. var i, v, label, hidden, pt;
  63010. if(trace.dlabel) {
  63011. labels = new Array(vals.length);
  63012. for(i = 0; i < vals.length; i++) {
  63013. labels[i] = String(trace.label0 + i * trace.dlabel);
  63014. }
  63015. }
  63016. function pullColor(color, label) {
  63017. if(!color) return false;
  63018. color = tinycolor(color);
  63019. if(!color.isValid()) return false;
  63020. color = Color.addOpacity(color, color.getAlpha());
  63021. if(!colorMap[label]) colorMap[label] = color;
  63022. return color;
  63023. }
  63024. var seriesLen = (hasVals ? vals : labels).length;
  63025. for(i = 0; i < seriesLen; i++) {
  63026. if(hasVals) {
  63027. v = vals[i];
  63028. if(!isNumeric(v)) continue;
  63029. v = +v;
  63030. if(v < 0) continue;
  63031. }
  63032. else v = 1;
  63033. label = labels[i];
  63034. if(label === undefined || label === '') label = i;
  63035. label = String(label);
  63036. var thisLabelIndex = allThisTraceLabels[label];
  63037. if(thisLabelIndex === undefined) {
  63038. allThisTraceLabels[label] = cd.length;
  63039. hidden = hiddenLabels.indexOf(label) !== -1;
  63040. if(!hidden) vTotal += v;
  63041. cd.push({
  63042. v: v,
  63043. label: label,
  63044. color: pullColor(colors[i], label),
  63045. i: i,
  63046. pts: [i],
  63047. hidden: hidden
  63048. });
  63049. }
  63050. else {
  63051. pt = cd[thisLabelIndex];
  63052. pt.v += v;
  63053. pt.pts.push(i);
  63054. if(!pt.hidden) vTotal += v;
  63055. if(pt.color === false && colors[i]) {
  63056. pt.color = pullColor(colors[i], label);
  63057. }
  63058. }
  63059. }
  63060. if(trace.sort) cd.sort(function(a, b) { return b.v - a.v; });
  63061. // include the sum of all values in the first point
  63062. if(cd[0]) cd[0].vTotal = vTotal;
  63063. // now insert text
  63064. if(trace.textinfo && trace.textinfo !== 'none') {
  63065. var hasLabel = trace.textinfo.indexOf('label') !== -1;
  63066. var hasText = trace.textinfo.indexOf('text') !== -1;
  63067. var hasValue = trace.textinfo.indexOf('value') !== -1;
  63068. var hasPercent = trace.textinfo.indexOf('percent') !== -1;
  63069. var separators = fullLayout.separators;
  63070. var thisText;
  63071. for(i = 0; i < cd.length; i++) {
  63072. pt = cd[i];
  63073. thisText = hasLabel ? [pt.label] : [];
  63074. if(hasText) {
  63075. var texti = helpers.getFirstFilled(trace.text, pt.pts);
  63076. if(texti) thisText.push(texti);
  63077. }
  63078. if(hasValue) thisText.push(helpers.formatPieValue(pt.v, separators));
  63079. if(hasPercent) thisText.push(helpers.formatPiePercent(pt.v / vTotal, separators));
  63080. pt.text = thisText.join('<br>');
  63081. }
  63082. }
  63083. return cd;
  63084. };
  63085. /*
  63086. * `calc` filled in (and collated) explicit colors.
  63087. * Now we need to propagate these explicit colors to other traces,
  63088. * and fill in default colors.
  63089. * This is done after sorting, so we pick defaults
  63090. * in the order slices will be displayed
  63091. */
  63092. exports.crossTraceCalc = function(gd) {
  63093. var fullLayout = gd._fullLayout;
  63094. var calcdata = gd.calcdata;
  63095. var pieColorWay = fullLayout.piecolorway;
  63096. var colorMap = fullLayout._piecolormap;
  63097. if(fullLayout.extendpiecolors) {
  63098. pieColorWay = generateExtendedColors(pieColorWay);
  63099. }
  63100. var dfltColorCount = 0;
  63101. var i, j, cd, pt;
  63102. for(i = 0; i < calcdata.length; i++) {
  63103. cd = calcdata[i];
  63104. if(cd[0].trace.type !== 'pie') continue;
  63105. for(j = 0; j < cd.length; j++) {
  63106. pt = cd[j];
  63107. if(pt.color === false) {
  63108. // have we seen this label and assigned a color to it in a previous trace?
  63109. if(colorMap[pt.label]) {
  63110. pt.color = colorMap[pt.label];
  63111. }
  63112. else {
  63113. colorMap[pt.label] = pt.color = pieColorWay[dfltColorCount % pieColorWay.length];
  63114. dfltColorCount++;
  63115. }
  63116. }
  63117. }
  63118. }
  63119. };
  63120. /**
  63121. * pick a default color from the main default set, augmented by
  63122. * itself lighter then darker before repeating
  63123. */
  63124. var extendedColorWays = {};
  63125. function generateExtendedColors(colorList) {
  63126. var i;
  63127. var colorString = JSON.stringify(colorList);
  63128. var pieColors = extendedColorWays[colorString];
  63129. if(!pieColors) {
  63130. pieColors = colorList.slice();
  63131. for(i = 0; i < colorList.length; i++) {
  63132. pieColors.push(tinycolor(colorList[i]).lighten(20).toHexString());
  63133. }
  63134. for(i = 0; i < colorList.length; i++) {
  63135. pieColors.push(tinycolor(colorList[i]).darken(20).toHexString());
  63136. }
  63137. extendedColorWays[colorString] = pieColors;
  63138. }
  63139. return pieColors;
  63140. }
  63141. },{"../../components/color":50,"../../lib":169,"./helpers":358,"fast-isnumeric":18,"tinycolor2":33}],356:[function(_dereq_,module,exports){
  63142. /**
  63143. * Copyright 2012-2018, Plotly, Inc.
  63144. * All rights reserved.
  63145. *
  63146. * This source code is licensed under the MIT license found in the
  63147. * LICENSE file in the root directory of this source tree.
  63148. */
  63149. 'use strict';
  63150. var Lib = _dereq_('../../lib');
  63151. var attributes = _dereq_('./attributes');
  63152. var handleDomainDefaults = _dereq_('../../plots/domain').defaults;
  63153. module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout) {
  63154. function coerce(attr, dflt) {
  63155. return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);
  63156. }
  63157. var coerceFont = Lib.coerceFont;
  63158. var len;
  63159. var vals = coerce('values');
  63160. var hasVals = Lib.isArrayOrTypedArray(vals);
  63161. var labels = coerce('labels');
  63162. if(Array.isArray(labels)) {
  63163. len = labels.length;
  63164. if(hasVals) len = Math.min(len, vals.length);
  63165. }
  63166. else if(hasVals) {
  63167. len = vals.length;
  63168. coerce('label0');
  63169. coerce('dlabel');
  63170. }
  63171. if(!len) {
  63172. traceOut.visible = false;
  63173. return;
  63174. }
  63175. traceOut._length = len;
  63176. var lineWidth = coerce('marker.line.width');
  63177. if(lineWidth) coerce('marker.line.color');
  63178. coerce('marker.colors');
  63179. coerce('scalegroup');
  63180. // TODO: hole needs to be coerced to the same value within a scaleegroup
  63181. var textData = coerce('text');
  63182. var textInfo = coerce('textinfo', Array.isArray(textData) ? 'text+percent' : 'percent');
  63183. coerce('hovertext');
  63184. if(textInfo && textInfo !== 'none') {
  63185. var textPosition = coerce('textposition'),
  63186. hasBoth = Array.isArray(textPosition) || textPosition === 'auto',
  63187. hasInside = hasBoth || textPosition === 'inside',
  63188. hasOutside = hasBoth || textPosition === 'outside';
  63189. if(hasInside || hasOutside) {
  63190. var dfltFont = coerceFont(coerce, 'textfont', layout.font);
  63191. if(hasInside) coerceFont(coerce, 'insidetextfont', dfltFont);
  63192. if(hasOutside) coerceFont(coerce, 'outsidetextfont', dfltFont);
  63193. }
  63194. }
  63195. handleDomainDefaults(traceOut, layout, coerce);
  63196. coerce('hole');
  63197. coerce('sort');
  63198. coerce('direction');
  63199. coerce('rotation');
  63200. coerce('pull');
  63201. };
  63202. },{"../../lib":169,"../../plots/domain":239,"./attributes":353}],357:[function(_dereq_,module,exports){
  63203. /**
  63204. * Copyright 2012-2018, Plotly, Inc.
  63205. * All rights reserved.
  63206. *
  63207. * This source code is licensed under the MIT license found in the
  63208. * LICENSE file in the root directory of this source tree.
  63209. */
  63210. 'use strict';
  63211. var appendArrayMultiPointValues = _dereq_('../../components/fx/helpers').appendArrayMultiPointValues;
  63212. // Note: like other eventData routines, this creates the data for hover/unhover/click events
  63213. // but it has a different API and goes through a totally different pathway.
  63214. // So to ensure it doesn't get misused, it's not attached to the Pie module.
  63215. module.exports = function eventData(pt, trace) {
  63216. var out = {
  63217. curveNumber: trace.index,
  63218. pointNumbers: pt.pts,
  63219. data: trace._input,
  63220. fullData: trace,
  63221. label: pt.label,
  63222. color: pt.color,
  63223. value: pt.v,
  63224. // pt.v (and pt.i below) for backward compatibility
  63225. v: pt.v
  63226. };
  63227. // Only include pointNumber if it's unambiguous
  63228. if(pt.pts.length === 1) out.pointNumber = out.i = pt.pts[0];
  63229. // Add extra data arrays to the output
  63230. // notice that this is the multi-point version ('s' on the end!)
  63231. // so added data will be arrays matching the pointNumbers array.
  63232. appendArrayMultiPointValues(out, trace, pt.pts);
  63233. return out;
  63234. };
  63235. },{"../../components/fx/helpers":89}],358:[function(_dereq_,module,exports){
  63236. /**
  63237. * Copyright 2012-2018, Plotly, Inc.
  63238. * All rights reserved.
  63239. *
  63240. * This source code is licensed under the MIT license found in the
  63241. * LICENSE file in the root directory of this source tree.
  63242. */
  63243. 'use strict';
  63244. var Lib = _dereq_('../../lib');
  63245. exports.formatPiePercent = function formatPiePercent(v, separators) {
  63246. var vRounded = (v * 100).toPrecision(3);
  63247. if(vRounded.lastIndexOf('.') !== -1) {
  63248. vRounded = vRounded.replace(/[.]?0+$/, '');
  63249. }
  63250. return Lib.numSeparate(vRounded, separators) + '%';
  63251. };
  63252. exports.formatPieValue = function formatPieValue(v, separators) {
  63253. var vRounded = v.toPrecision(10);
  63254. if(vRounded.lastIndexOf('.') !== -1) {
  63255. vRounded = vRounded.replace(/[.]?0+$/, '');
  63256. }
  63257. return Lib.numSeparate(vRounded, separators);
  63258. };
  63259. exports.getFirstFilled = function getFirstFilled(array, indices) {
  63260. if(!Array.isArray(array)) return;
  63261. for(var i = 0; i < indices.length; i++) {
  63262. var v = array[indices[i]];
  63263. if(v || v === 0) return v;
  63264. }
  63265. };
  63266. exports.castOption = function castOption(item, indices) {
  63267. if(Array.isArray(item)) return exports.getFirstFilled(item, indices);
  63268. else if(item) return item;
  63269. };
  63270. },{"../../lib":169}],359:[function(_dereq_,module,exports){
  63271. /**
  63272. * Copyright 2012-2018, Plotly, Inc.
  63273. * All rights reserved.
  63274. *
  63275. * This source code is licensed under the MIT license found in the
  63276. * LICENSE file in the root directory of this source tree.
  63277. */
  63278. 'use strict';
  63279. var Pie = {};
  63280. Pie.attributes = _dereq_('./attributes');
  63281. Pie.supplyDefaults = _dereq_('./defaults');
  63282. Pie.supplyLayoutDefaults = _dereq_('./layout_defaults');
  63283. Pie.layoutAttributes = _dereq_('./layout_attributes');
  63284. var calcModule = _dereq_('./calc');
  63285. Pie.calc = calcModule.calc;
  63286. Pie.crossTraceCalc = calcModule.crossTraceCalc;
  63287. Pie.plot = _dereq_('./plot');
  63288. Pie.style = _dereq_('./style');
  63289. Pie.styleOne = _dereq_('./style_one');
  63290. Pie.moduleType = 'trace';
  63291. Pie.name = 'pie';
  63292. Pie.basePlotModule = _dereq_('./base_plot');
  63293. Pie.categories = ['pie', 'showLegend'];
  63294. Pie.meta = {
  63295. };
  63296. module.exports = Pie;
  63297. },{"./attributes":353,"./base_plot":354,"./calc":355,"./defaults":356,"./layout_attributes":360,"./layout_defaults":361,"./plot":362,"./style":363,"./style_one":364}],360:[function(_dereq_,module,exports){
  63298. /**
  63299. * Copyright 2012-2018, Plotly, Inc.
  63300. * All rights reserved.
  63301. *
  63302. * This source code is licensed under the MIT license found in the
  63303. * LICENSE file in the root directory of this source tree.
  63304. */
  63305. 'use strict';
  63306. module.exports = {
  63307. /**
  63308. * hiddenlabels is the pie chart analog of visible:'legendonly'
  63309. * but it can contain many labels, and can hide slices
  63310. * from several pies simultaneously
  63311. */
  63312. hiddenlabels: {
  63313. valType: 'data_array',
  63314. editType: 'calc'
  63315. },
  63316. piecolorway: {
  63317. valType: 'colorlist',
  63318. editType: 'calc',
  63319. },
  63320. extendpiecolors: {
  63321. valType: 'boolean',
  63322. dflt: true,
  63323. editType: 'calc',
  63324. }
  63325. };
  63326. },{}],361:[function(_dereq_,module,exports){
  63327. /**
  63328. * Copyright 2012-2018, Plotly, Inc.
  63329. * All rights reserved.
  63330. *
  63331. * This source code is licensed under the MIT license found in the
  63332. * LICENSE file in the root directory of this source tree.
  63333. */
  63334. 'use strict';
  63335. var Lib = _dereq_('../../lib');
  63336. var layoutAttributes = _dereq_('./layout_attributes');
  63337. module.exports = function supplyLayoutDefaults(layoutIn, layoutOut) {
  63338. function coerce(attr, dflt) {
  63339. return Lib.coerce(layoutIn, layoutOut, layoutAttributes, attr, dflt);
  63340. }
  63341. coerce('hiddenlabels');
  63342. coerce('piecolorway', layoutOut.colorway);
  63343. coerce('extendpiecolors');
  63344. };
  63345. },{"../../lib":169,"./layout_attributes":360}],362:[function(_dereq_,module,exports){
  63346. /**
  63347. * Copyright 2012-2018, Plotly, Inc.
  63348. * All rights reserved.
  63349. *
  63350. * This source code is licensed under the MIT license found in the
  63351. * LICENSE file in the root directory of this source tree.
  63352. */
  63353. 'use strict';
  63354. var d3 = _dereq_('d3');
  63355. var Fx = _dereq_('../../components/fx');
  63356. var Color = _dereq_('../../components/color');
  63357. var Drawing = _dereq_('../../components/drawing');
  63358. var Lib = _dereq_('../../lib');
  63359. var svgTextUtils = _dereq_('../../lib/svg_text_utils');
  63360. var helpers = _dereq_('./helpers');
  63361. var eventData = _dereq_('./event_data');
  63362. module.exports = function plot(gd, cdpie) {
  63363. var fullLayout = gd._fullLayout;
  63364. scalePies(cdpie, fullLayout._size);
  63365. var pieGroups = Lib.makeTraceGroups(fullLayout._pielayer, cdpie, 'trace').each(function(cd) {
  63366. var pieGroup = d3.select(this);
  63367. var cd0 = cd[0];
  63368. var trace = cd0.trace;
  63369. setCoords(cd);
  63370. // TODO: miter might look better but can sometimes cause problems
  63371. // maybe miter with a small-ish stroke-miterlimit?
  63372. pieGroup.attr('stroke-linejoin', 'round');
  63373. pieGroup.each(function() {
  63374. var slices = d3.select(this).selectAll('g.slice').data(cd);
  63375. slices.enter().append('g')
  63376. .classed('slice', true);
  63377. slices.exit().remove();
  63378. var quadrants = [
  63379. [[], []], // y<0: x<0, x>=0
  63380. [[], []] // y>=0: x<0, x>=0
  63381. ];
  63382. var hasOutsideText = false;
  63383. slices.each(function(pt) {
  63384. if(pt.hidden) {
  63385. d3.select(this).selectAll('path,g').remove();
  63386. return;
  63387. }
  63388. // to have consistent event data compared to other traces
  63389. pt.pointNumber = pt.i;
  63390. pt.curveNumber = trace.index;
  63391. quadrants[pt.pxmid[1] < 0 ? 0 : 1][pt.pxmid[0] < 0 ? 0 : 1].push(pt);
  63392. var cx = cd0.cx;
  63393. var cy = cd0.cy;
  63394. var sliceTop = d3.select(this);
  63395. var slicePath = sliceTop.selectAll('path.surface').data([pt]);
  63396. // hover state vars
  63397. // have we drawn a hover label, so it should be cleared later
  63398. var hasHoverLabel = false;
  63399. // have we emitted a hover event, so later an unhover event should be emitted
  63400. // note that click events do not depend on this - you can still get them
  63401. // with hovermode: false or if you were earlier dragging, then clicked
  63402. // in the same slice that you moused up in
  63403. var hasHoverEvent = false;
  63404. function handleMouseOver() {
  63405. // in case fullLayout or fullData has changed without a replot
  63406. var fullLayout2 = gd._fullLayout;
  63407. var trace2 = gd._fullData[trace.index];
  63408. if(gd._dragging || fullLayout2.hovermode === false) return;
  63409. var hoverinfo = trace2.hoverinfo;
  63410. if(Array.isArray(hoverinfo)) {
  63411. // super hacky: we need to pull out the *first* hoverinfo from
  63412. // pt.pts, then put it back into an array in a dummy trace
  63413. // and call castHoverinfo on that.
  63414. // TODO: do we want to have Fx.castHoverinfo somehow handle this?
  63415. // it already takes an array for index, for 2D, so this seems tricky.
  63416. hoverinfo = Fx.castHoverinfo({
  63417. hoverinfo: [helpers.castOption(hoverinfo, pt.pts)],
  63418. _module: trace._module
  63419. }, fullLayout2, 0);
  63420. }
  63421. if(hoverinfo === 'all') hoverinfo = 'label+text+value+percent+name';
  63422. // in case we dragged over the pie from another subplot,
  63423. // or if hover is turned off
  63424. if(hoverinfo !== 'none' && hoverinfo !== 'skip' && hoverinfo) {
  63425. var rInscribed = getInscribedRadiusFraction(pt, cd0);
  63426. var hoverCenterX = cx + pt.pxmid[0] * (1 - rInscribed);
  63427. var hoverCenterY = cy + pt.pxmid[1] * (1 - rInscribed);
  63428. var separators = fullLayout.separators;
  63429. var thisText = [];
  63430. if(hoverinfo.indexOf('label') !== -1) thisText.push(pt.label);
  63431. if(hoverinfo.indexOf('text') !== -1) {
  63432. var texti = helpers.castOption(trace2.hovertext || trace2.text, pt.pts);
  63433. if(texti) thisText.push(texti);
  63434. }
  63435. if(hoverinfo.indexOf('value') !== -1) thisText.push(helpers.formatPieValue(pt.v, separators));
  63436. if(hoverinfo.indexOf('percent') !== -1) thisText.push(helpers.formatPiePercent(pt.v / cd0.vTotal, separators));
  63437. var hoverLabel = trace.hoverlabel;
  63438. var hoverFont = hoverLabel.font;
  63439. Fx.loneHover({
  63440. x0: hoverCenterX - rInscribed * cd0.r,
  63441. x1: hoverCenterX + rInscribed * cd0.r,
  63442. y: hoverCenterY,
  63443. text: thisText.join('<br>'),
  63444. name: hoverinfo.indexOf('name') !== -1 ? trace2.name : undefined,
  63445. idealAlign: pt.pxmid[0] < 0 ? 'left' : 'right',
  63446. color: helpers.castOption(hoverLabel.bgcolor, pt.pts) || pt.color,
  63447. borderColor: helpers.castOption(hoverLabel.bordercolor, pt.pts),
  63448. fontFamily: helpers.castOption(hoverFont.family, pt.pts),
  63449. fontSize: helpers.castOption(hoverFont.size, pt.pts),
  63450. fontColor: helpers.castOption(hoverFont.color, pt.pts)
  63451. }, {
  63452. container: fullLayout2._hoverlayer.node(),
  63453. outerContainer: fullLayout2._paper.node(),
  63454. gd: gd
  63455. });
  63456. hasHoverLabel = true;
  63457. }
  63458. gd.emit('plotly_hover', {
  63459. points: [eventData(pt, trace2)],
  63460. event: d3.event
  63461. });
  63462. hasHoverEvent = true;
  63463. }
  63464. function handleMouseOut(evt) {
  63465. var fullLayout2 = gd._fullLayout;
  63466. var trace2 = gd._fullData[trace.index];
  63467. if(hasHoverEvent) {
  63468. evt.originalEvent = d3.event;
  63469. gd.emit('plotly_unhover', {
  63470. points: [eventData(pt, trace2)],
  63471. event: d3.event
  63472. });
  63473. hasHoverEvent = false;
  63474. }
  63475. if(hasHoverLabel) {
  63476. Fx.loneUnhover(fullLayout2._hoverlayer.node());
  63477. hasHoverLabel = false;
  63478. }
  63479. }
  63480. function handleClick() {
  63481. // TODO: this does not support right-click. If we want to support it, we
  63482. // would likely need to change pie to use dragElement instead of straight
  63483. // mapbox event binding. Or perhaps better, make a simple wrapper with the
  63484. // right mousedown, mousemove, and mouseup handlers just for a left/right click
  63485. // mapbox would use this too.
  63486. var fullLayout2 = gd._fullLayout;
  63487. var trace2 = gd._fullData[trace.index];
  63488. if(gd._dragging || fullLayout2.hovermode === false) return;
  63489. gd._hoverdata = [eventData(pt, trace2)];
  63490. Fx.click(gd, d3.event);
  63491. }
  63492. slicePath.enter().append('path')
  63493. .classed('surface', true)
  63494. .style({'pointer-events': 'all'});
  63495. sliceTop.select('path.textline').remove();
  63496. sliceTop
  63497. .on('mouseover', handleMouseOver)
  63498. .on('mouseout', handleMouseOut)
  63499. .on('click', handleClick);
  63500. if(trace.pull) {
  63501. var pull = +helpers.castOption(trace.pull, pt.pts) || 0;
  63502. if(pull > 0) {
  63503. cx += pull * pt.pxmid[0];
  63504. cy += pull * pt.pxmid[1];
  63505. }
  63506. }
  63507. pt.cxFinal = cx;
  63508. pt.cyFinal = cy;
  63509. function arc(start, finish, cw, scale) {
  63510. return 'a' + (scale * cd0.r) + ',' + (scale * cd0.r) + ' 0 ' +
  63511. pt.largeArc + (cw ? ' 1 ' : ' 0 ') +
  63512. (scale * (finish[0] - start[0])) + ',' + (scale * (finish[1] - start[1]));
  63513. }
  63514. var hole = trace.hole;
  63515. if(pt.v === cd0.vTotal) { // 100% fails bcs arc start and end are identical
  63516. var outerCircle = 'M' + (cx + pt.px0[0]) + ',' + (cy + pt.px0[1]) +
  63517. arc(pt.px0, pt.pxmid, true, 1) +
  63518. arc(pt.pxmid, pt.px0, true, 1) + 'Z';
  63519. if(hole) {
  63520. slicePath.attr('d',
  63521. 'M' + (cx + hole * pt.px0[0]) + ',' + (cy + hole * pt.px0[1]) +
  63522. arc(pt.px0, pt.pxmid, false, hole) +
  63523. arc(pt.pxmid, pt.px0, false, hole) +
  63524. 'Z' + outerCircle);
  63525. }
  63526. else slicePath.attr('d', outerCircle);
  63527. } else {
  63528. var outerArc = arc(pt.px0, pt.px1, true, 1);
  63529. if(hole) {
  63530. var rim = 1 - hole;
  63531. slicePath.attr('d',
  63532. 'M' + (cx + hole * pt.px1[0]) + ',' + (cy + hole * pt.px1[1]) +
  63533. arc(pt.px1, pt.px0, false, hole) +
  63534. 'l' + (rim * pt.px0[0]) + ',' + (rim * pt.px0[1]) +
  63535. outerArc +
  63536. 'Z');
  63537. } else {
  63538. slicePath.attr('d',
  63539. 'M' + cx + ',' + cy +
  63540. 'l' + pt.px0[0] + ',' + pt.px0[1] +
  63541. outerArc +
  63542. 'Z');
  63543. }
  63544. }
  63545. // add text
  63546. var textPosition = helpers.castOption(trace.textposition, pt.pts);
  63547. var sliceTextGroup = sliceTop.selectAll('g.slicetext')
  63548. .data(pt.text && (textPosition !== 'none') ? [0] : []);
  63549. sliceTextGroup.enter().append('g')
  63550. .classed('slicetext', true);
  63551. sliceTextGroup.exit().remove();
  63552. sliceTextGroup.each(function() {
  63553. var sliceText = Lib.ensureSingle(d3.select(this), 'text', '', function(s) {
  63554. // prohibit tex interpretation until we can handle
  63555. // tex and regular text together
  63556. s.attr('data-notex', 1);
  63557. });
  63558. sliceText.text(pt.text)
  63559. .attr({
  63560. 'class': 'slicetext',
  63561. transform: '',
  63562. 'text-anchor': 'middle'
  63563. })
  63564. .call(Drawing.font, textPosition === 'outside' ?
  63565. trace.outsidetextfont : trace.insidetextfont)
  63566. .call(svgTextUtils.convertToTspans, gd);
  63567. // position the text relative to the slice
  63568. var textBB = Drawing.bBox(sliceText.node());
  63569. var transform;
  63570. if(textPosition === 'outside') {
  63571. transform = transformOutsideText(textBB, pt);
  63572. } else {
  63573. transform = transformInsideText(textBB, pt, cd0);
  63574. if(textPosition === 'auto' && transform.scale < 1) {
  63575. sliceText.call(Drawing.font, trace.outsidetextfont);
  63576. if(trace.outsidetextfont.family !== trace.insidetextfont.family ||
  63577. trace.outsidetextfont.size !== trace.insidetextfont.size) {
  63578. textBB = Drawing.bBox(sliceText.node());
  63579. }
  63580. transform = transformOutsideText(textBB, pt);
  63581. }
  63582. }
  63583. var translateX = cx + pt.pxmid[0] * transform.rCenter + (transform.x || 0);
  63584. var translateY = cy + pt.pxmid[1] * transform.rCenter + (transform.y || 0);
  63585. // save some stuff to use later ensure no labels overlap
  63586. if(transform.outside) {
  63587. pt.yLabelMin = translateY - textBB.height / 2;
  63588. pt.yLabelMid = translateY;
  63589. pt.yLabelMax = translateY + textBB.height / 2;
  63590. pt.labelExtraX = 0;
  63591. pt.labelExtraY = 0;
  63592. hasOutsideText = true;
  63593. }
  63594. sliceText.attr('transform',
  63595. 'translate(' + translateX + ',' + translateY + ')' +
  63596. (transform.scale < 1 ? ('scale(' + transform.scale + ')') : '') +
  63597. (transform.rotate ? ('rotate(' + transform.rotate + ')') : '') +
  63598. 'translate(' +
  63599. (-(textBB.left + textBB.right) / 2) + ',' +
  63600. (-(textBB.top + textBB.bottom) / 2) +
  63601. ')');
  63602. });
  63603. });
  63604. // now make sure no labels overlap (at least within one pie)
  63605. if(hasOutsideText) scootLabels(quadrants, trace);
  63606. slices.each(function(pt) {
  63607. if(pt.labelExtraX || pt.labelExtraY) {
  63608. // first move the text to its new location
  63609. var sliceTop = d3.select(this);
  63610. var sliceText = sliceTop.select('g.slicetext text');
  63611. sliceText.attr('transform', 'translate(' + pt.labelExtraX + ',' + pt.labelExtraY + ')' +
  63612. sliceText.attr('transform'));
  63613. // then add a line to the new location
  63614. var lineStartX = pt.cxFinal + pt.pxmid[0];
  63615. var lineStartY = pt.cyFinal + pt.pxmid[1];
  63616. var textLinePath = 'M' + lineStartX + ',' + lineStartY;
  63617. var finalX = (pt.yLabelMax - pt.yLabelMin) * (pt.pxmid[0] < 0 ? -1 : 1) / 4;
  63618. if(pt.labelExtraX) {
  63619. var yFromX = pt.labelExtraX * pt.pxmid[1] / pt.pxmid[0];
  63620. var yNet = pt.yLabelMid + pt.labelExtraY - (pt.cyFinal + pt.pxmid[1]);
  63621. if(Math.abs(yFromX) > Math.abs(yNet)) {
  63622. textLinePath +=
  63623. 'l' + (yNet * pt.pxmid[0] / pt.pxmid[1]) + ',' + yNet +
  63624. 'H' + (lineStartX + pt.labelExtraX + finalX);
  63625. } else {
  63626. textLinePath += 'l' + pt.labelExtraX + ',' + yFromX +
  63627. 'v' + (yNet - yFromX) +
  63628. 'h' + finalX;
  63629. }
  63630. } else {
  63631. textLinePath +=
  63632. 'V' + (pt.yLabelMid + pt.labelExtraY) +
  63633. 'h' + finalX;
  63634. }
  63635. sliceTop.append('path')
  63636. .classed('textline', true)
  63637. .call(Color.stroke, trace.outsidetextfont.color)
  63638. .attr({
  63639. 'stroke-width': Math.min(2, trace.outsidetextfont.size / 8),
  63640. d: textLinePath,
  63641. fill: 'none'
  63642. });
  63643. }
  63644. });
  63645. });
  63646. });
  63647. // This is for a bug in Chrome (as of 2015-07-22, and does not affect FF)
  63648. // if insidetextfont and outsidetextfont are different sizes, sometimes the size
  63649. // of an "em" gets taken from the wrong element at first so lines are
  63650. // spaced wrong. You just have to tell it to try again later and it gets fixed.
  63651. // I have no idea why we haven't seen this in other contexts. Also, sometimes
  63652. // it gets the initial draw correct but on redraw it gets confused.
  63653. setTimeout(function() {
  63654. pieGroups.selectAll('tspan').each(function() {
  63655. var s = d3.select(this);
  63656. if(s.attr('dy')) s.attr('dy', s.attr('dy'));
  63657. });
  63658. }, 0);
  63659. };
  63660. function transformInsideText(textBB, pt, cd0) {
  63661. var textDiameter = Math.sqrt(textBB.width * textBB.width + textBB.height * textBB.height);
  63662. var textAspect = textBB.width / textBB.height;
  63663. var halfAngle = Math.PI * Math.min(pt.v / cd0.vTotal, 0.5);
  63664. var ring = 1 - cd0.trace.hole;
  63665. var rInscribed = getInscribedRadiusFraction(pt, cd0),
  63666. // max size text can be inserted inside without rotating it
  63667. // this inscribes the text rectangle in a circle, which is then inscribed
  63668. // in the slice, so it will be an underestimate, which some day we may want
  63669. // to improve so this case can get more use
  63670. transform = {
  63671. scale: rInscribed * cd0.r * 2 / textDiameter,
  63672. // and the center position and rotation in this case
  63673. rCenter: 1 - rInscribed,
  63674. rotate: 0
  63675. };
  63676. if(transform.scale >= 1) return transform;
  63677. // max size if text is rotated radially
  63678. var Qr = textAspect + 1 / (2 * Math.tan(halfAngle));
  63679. var maxHalfHeightRotRadial = cd0.r * Math.min(
  63680. 1 / (Math.sqrt(Qr * Qr + 0.5) + Qr),
  63681. ring / (Math.sqrt(textAspect * textAspect + ring / 2) + textAspect)
  63682. );
  63683. var radialTransform = {
  63684. scale: maxHalfHeightRotRadial * 2 / textBB.height,
  63685. rCenter: Math.cos(maxHalfHeightRotRadial / cd0.r) -
  63686. maxHalfHeightRotRadial * textAspect / cd0.r,
  63687. rotate: (180 / Math.PI * pt.midangle + 720) % 180 - 90
  63688. };
  63689. // max size if text is rotated tangentially
  63690. var aspectInv = 1 / textAspect;
  63691. var Qt = aspectInv + 1 / (2 * Math.tan(halfAngle));
  63692. var maxHalfWidthTangential = cd0.r * Math.min(
  63693. 1 / (Math.sqrt(Qt * Qt + 0.5) + Qt),
  63694. ring / (Math.sqrt(aspectInv * aspectInv + ring / 2) + aspectInv)
  63695. );
  63696. var tangentialTransform = {
  63697. scale: maxHalfWidthTangential * 2 / textBB.width,
  63698. rCenter: Math.cos(maxHalfWidthTangential / cd0.r) -
  63699. maxHalfWidthTangential / textAspect / cd0.r,
  63700. rotate: (180 / Math.PI * pt.midangle + 810) % 180 - 90
  63701. };
  63702. // if we need a rotated transform, pick the biggest one
  63703. // even if both are bigger than 1
  63704. var rotatedTransform = tangentialTransform.scale > radialTransform.scale ?
  63705. tangentialTransform : radialTransform;
  63706. if(transform.scale < 1 && rotatedTransform.scale > transform.scale) return rotatedTransform;
  63707. return transform;
  63708. }
  63709. function getInscribedRadiusFraction(pt, cd0) {
  63710. if(pt.v === cd0.vTotal && !cd0.trace.hole) return 1;// special case of 100% with no hole
  63711. var halfAngle = Math.PI * Math.min(pt.v / cd0.vTotal, 0.5);
  63712. return Math.min(1 / (1 + 1 / Math.sin(halfAngle)), (1 - cd0.trace.hole) / 2);
  63713. }
  63714. function transformOutsideText(textBB, pt) {
  63715. var x = pt.pxmid[0];
  63716. var y = pt.pxmid[1];
  63717. var dx = textBB.width / 2;
  63718. var dy = textBB.height / 2;
  63719. if(x < 0) dx *= -1;
  63720. if(y < 0) dy *= -1;
  63721. return {
  63722. scale: 1,
  63723. rCenter: 1,
  63724. rotate: 0,
  63725. x: dx + Math.abs(dy) * (dx > 0 ? 1 : -1) / 2,
  63726. y: dy / (1 + x * x / (y * y)),
  63727. outside: true
  63728. };
  63729. }
  63730. function scootLabels(quadrants, trace) {
  63731. var xHalf, yHalf, equatorFirst, farthestX, farthestY,
  63732. xDiffSign, yDiffSign, thisQuad, oppositeQuad,
  63733. wholeSide, i, thisQuadOutside, firstOppositeOutsidePt;
  63734. function topFirst(a, b) { return a.pxmid[1] - b.pxmid[1]; }
  63735. function bottomFirst(a, b) { return b.pxmid[1] - a.pxmid[1]; }
  63736. function scootOneLabel(thisPt, prevPt) {
  63737. if(!prevPt) prevPt = {};
  63738. var prevOuterY = prevPt.labelExtraY + (yHalf ? prevPt.yLabelMax : prevPt.yLabelMin);
  63739. var thisInnerY = yHalf ? thisPt.yLabelMin : thisPt.yLabelMax;
  63740. var thisOuterY = yHalf ? thisPt.yLabelMax : thisPt.yLabelMin;
  63741. var thisSliceOuterY = thisPt.cyFinal + farthestY(thisPt.px0[1], thisPt.px1[1]);
  63742. var newExtraY = prevOuterY - thisInnerY;
  63743. var xBuffer, i, otherPt, otherOuterY, otherOuterX, newExtraX;
  63744. // make sure this label doesn't overlap other labels
  63745. // this *only* has us move these labels vertically
  63746. if(newExtraY * yDiffSign > 0) thisPt.labelExtraY = newExtraY;
  63747. // make sure this label doesn't overlap any slices
  63748. if(!Array.isArray(trace.pull)) return; // this can only happen with array pulls
  63749. for(i = 0; i < wholeSide.length; i++) {
  63750. otherPt = wholeSide[i];
  63751. // overlap can only happen if the other point is pulled more than this one
  63752. if(otherPt === thisPt || (
  63753. (helpers.castOption(trace.pull, thisPt.pts) || 0) >=
  63754. (helpers.castOption(trace.pull, otherPt.pts) || 0))
  63755. ) {
  63756. continue;
  63757. }
  63758. if((thisPt.pxmid[1] - otherPt.pxmid[1]) * yDiffSign > 0) {
  63759. // closer to the equator - by construction all of these happen first
  63760. // move the text vertically to get away from these slices
  63761. otherOuterY = otherPt.cyFinal + farthestY(otherPt.px0[1], otherPt.px1[1]);
  63762. newExtraY = otherOuterY - thisInnerY - thisPt.labelExtraY;
  63763. if(newExtraY * yDiffSign > 0) thisPt.labelExtraY += newExtraY;
  63764. } else if((thisOuterY + thisPt.labelExtraY - thisSliceOuterY) * yDiffSign > 0) {
  63765. // farther from the equator - happens after we've done all the
  63766. // vertical moving we're going to do
  63767. // move horizontally to get away from these more polar slices
  63768. // if we're moving horz. based on a slice that's several slices away from this one
  63769. // then we need some extra space for the lines to labels between them
  63770. xBuffer = 3 * xDiffSign * Math.abs(i - wholeSide.indexOf(thisPt));
  63771. otherOuterX = otherPt.cxFinal + farthestX(otherPt.px0[0], otherPt.px1[0]);
  63772. newExtraX = otherOuterX + xBuffer - (thisPt.cxFinal + thisPt.pxmid[0]) - thisPt.labelExtraX;
  63773. if(newExtraX * xDiffSign > 0) thisPt.labelExtraX += newExtraX;
  63774. }
  63775. }
  63776. }
  63777. for(yHalf = 0; yHalf < 2; yHalf++) {
  63778. equatorFirst = yHalf ? topFirst : bottomFirst;
  63779. farthestY = yHalf ? Math.max : Math.min;
  63780. yDiffSign = yHalf ? 1 : -1;
  63781. for(xHalf = 0; xHalf < 2; xHalf++) {
  63782. farthestX = xHalf ? Math.max : Math.min;
  63783. xDiffSign = xHalf ? 1 : -1;
  63784. // first sort the array
  63785. // note this is a copy of cd, so cd itself doesn't get sorted
  63786. // but we can still modify points in place.
  63787. thisQuad = quadrants[yHalf][xHalf];
  63788. thisQuad.sort(equatorFirst);
  63789. oppositeQuad = quadrants[1 - yHalf][xHalf];
  63790. wholeSide = oppositeQuad.concat(thisQuad);
  63791. thisQuadOutside = [];
  63792. for(i = 0; i < thisQuad.length; i++) {
  63793. if(thisQuad[i].yLabelMid !== undefined) thisQuadOutside.push(thisQuad[i]);
  63794. }
  63795. firstOppositeOutsidePt = false;
  63796. for(i = 0; yHalf && i < oppositeQuad.length; i++) {
  63797. if(oppositeQuad[i].yLabelMid !== undefined) {
  63798. firstOppositeOutsidePt = oppositeQuad[i];
  63799. break;
  63800. }
  63801. }
  63802. // each needs to avoid the previous
  63803. for(i = 0; i < thisQuadOutside.length; i++) {
  63804. var prevPt = i && thisQuadOutside[i - 1];
  63805. // bottom half needs to avoid the first label of the top half
  63806. // top half we still need to call scootOneLabel on the first slice
  63807. // so we can avoid other slices, but we don't pass a prevPt
  63808. if(firstOppositeOutsidePt && !i) prevPt = firstOppositeOutsidePt;
  63809. scootOneLabel(thisQuadOutside[i], prevPt);
  63810. }
  63811. }
  63812. }
  63813. }
  63814. function scalePies(cdpie, plotSize) {
  63815. var scaleGroups = [];
  63816. var pieBoxWidth, pieBoxHeight, i, j, cd0, trace,
  63817. maxPull, scaleGroup, minPxPerValUnit;
  63818. // first figure out the center and maximum radius for each pie
  63819. for(i = 0; i < cdpie.length; i++) {
  63820. cd0 = cdpie[i][0];
  63821. trace = cd0.trace;
  63822. pieBoxWidth = plotSize.w * (trace.domain.x[1] - trace.domain.x[0]);
  63823. pieBoxHeight = plotSize.h * (trace.domain.y[1] - trace.domain.y[0]);
  63824. maxPull = trace.pull;
  63825. if(Array.isArray(maxPull)) {
  63826. maxPull = 0;
  63827. for(j = 0; j < trace.pull.length; j++) {
  63828. if(trace.pull[j] > maxPull) maxPull = trace.pull[j];
  63829. }
  63830. }
  63831. cd0.r = Math.min(pieBoxWidth, pieBoxHeight) / (2 + 2 * maxPull);
  63832. cd0.cx = plotSize.l + plotSize.w * (trace.domain.x[1] + trace.domain.x[0]) / 2;
  63833. cd0.cy = plotSize.t + plotSize.h * (2 - trace.domain.y[1] - trace.domain.y[0]) / 2;
  63834. if(trace.scalegroup && scaleGroups.indexOf(trace.scalegroup) === -1) {
  63835. scaleGroups.push(trace.scalegroup);
  63836. }
  63837. }
  63838. // Then scale any pies that are grouped
  63839. for(j = 0; j < scaleGroups.length; j++) {
  63840. minPxPerValUnit = Infinity;
  63841. scaleGroup = scaleGroups[j];
  63842. for(i = 0; i < cdpie.length; i++) {
  63843. cd0 = cdpie[i][0];
  63844. if(cd0.trace.scalegroup === scaleGroup) {
  63845. minPxPerValUnit = Math.min(minPxPerValUnit,
  63846. cd0.r * cd0.r / cd0.vTotal);
  63847. }
  63848. }
  63849. for(i = 0; i < cdpie.length; i++) {
  63850. cd0 = cdpie[i][0];
  63851. if(cd0.trace.scalegroup === scaleGroup) {
  63852. cd0.r = Math.sqrt(minPxPerValUnit * cd0.vTotal);
  63853. }
  63854. }
  63855. }
  63856. }
  63857. function setCoords(cd) {
  63858. var cd0 = cd[0];
  63859. var trace = cd0.trace;
  63860. var currentAngle = trace.rotation * Math.PI / 180;
  63861. var angleFactor = 2 * Math.PI / cd0.vTotal;
  63862. var firstPt = 'px0';
  63863. var lastPt = 'px1';
  63864. var i, cdi, currentCoords;
  63865. if(trace.direction === 'counterclockwise') {
  63866. for(i = 0; i < cd.length; i++) {
  63867. if(!cd[i].hidden) break; // find the first non-hidden slice
  63868. }
  63869. if(i === cd.length) return; // all slices hidden
  63870. currentAngle += angleFactor * cd[i].v;
  63871. angleFactor *= -1;
  63872. firstPt = 'px1';
  63873. lastPt = 'px0';
  63874. }
  63875. function getCoords(angle) {
  63876. return [cd0.r * Math.sin(angle), -cd0.r * Math.cos(angle)];
  63877. }
  63878. currentCoords = getCoords(currentAngle);
  63879. for(i = 0; i < cd.length; i++) {
  63880. cdi = cd[i];
  63881. if(cdi.hidden) continue;
  63882. cdi[firstPt] = currentCoords;
  63883. currentAngle += angleFactor * cdi.v / 2;
  63884. cdi.pxmid = getCoords(currentAngle);
  63885. cdi.midangle = currentAngle;
  63886. currentAngle += angleFactor * cdi.v / 2;
  63887. currentCoords = getCoords(currentAngle);
  63888. cdi[lastPt] = currentCoords;
  63889. cdi.largeArc = (cdi.v > cd0.vTotal / 2) ? 1 : 0;
  63890. }
  63891. }
  63892. },{"../../components/color":50,"../../components/drawing":75,"../../components/fx":92,"../../lib":169,"../../lib/svg_text_utils":191,"./event_data":357,"./helpers":358,"d3":16}],363:[function(_dereq_,module,exports){
  63893. /**
  63894. * Copyright 2012-2018, Plotly, Inc.
  63895. * All rights reserved.
  63896. *
  63897. * This source code is licensed under the MIT license found in the
  63898. * LICENSE file in the root directory of this source tree.
  63899. */
  63900. 'use strict';
  63901. var d3 = _dereq_('d3');
  63902. var styleOne = _dereq_('./style_one');
  63903. module.exports = function style(gd) {
  63904. gd._fullLayout._pielayer.selectAll('.trace').each(function(cd) {
  63905. var cd0 = cd[0];
  63906. var trace = cd0.trace;
  63907. var traceSelection = d3.select(this);
  63908. traceSelection.style({opacity: trace.opacity});
  63909. traceSelection.selectAll('path.surface').each(function(pt) {
  63910. d3.select(this).call(styleOne, pt, trace);
  63911. });
  63912. });
  63913. };
  63914. },{"./style_one":364,"d3":16}],364:[function(_dereq_,module,exports){
  63915. /**
  63916. * Copyright 2012-2018, Plotly, Inc.
  63917. * All rights reserved.
  63918. *
  63919. * This source code is licensed under the MIT license found in the
  63920. * LICENSE file in the root directory of this source tree.
  63921. */
  63922. 'use strict';
  63923. var Color = _dereq_('../../components/color');
  63924. var castOption = _dereq_('./helpers').castOption;
  63925. module.exports = function styleOne(s, pt, trace) {
  63926. var line = trace.marker.line;
  63927. var lineColor = castOption(line.color, pt.pts) || Color.defaultLine;
  63928. var lineWidth = castOption(line.width, pt.pts) || 0;
  63929. s.style({'stroke-width': lineWidth})
  63930. .call(Color.fill, pt.color)
  63931. .call(Color.stroke, lineColor);
  63932. };
  63933. },{"../../components/color":50,"./helpers":358}],365:[function(_dereq_,module,exports){
  63934. /**
  63935. * Copyright 2012-2018, Plotly, Inc.
  63936. * All rights reserved.
  63937. *
  63938. * This source code is licensed under the MIT license found in the
  63939. * LICENSE file in the root directory of this source tree.
  63940. */
  63941. 'use strict';
  63942. var Lib = _dereq_('../../lib');
  63943. // arrayOk attributes, merge them into calcdata array
  63944. module.exports = function arraysToCalcdata(cd, trace) {
  63945. // so each point knows which index it originally came from
  63946. for(var i = 0; i < cd.length; i++) cd[i].i = i;
  63947. Lib.mergeArray(trace.text, cd, 'tx');
  63948. Lib.mergeArray(trace.hovertext, cd, 'htx');
  63949. Lib.mergeArray(trace.customdata, cd, 'data');
  63950. Lib.mergeArray(trace.textposition, cd, 'tp');
  63951. if(trace.textfont) {
  63952. Lib.mergeArray(trace.textfont.size, cd, 'ts');
  63953. Lib.mergeArray(trace.textfont.color, cd, 'tc');
  63954. Lib.mergeArray(trace.textfont.family, cd, 'tf');
  63955. }
  63956. var marker = trace.marker;
  63957. if(marker) {
  63958. Lib.mergeArray(marker.size, cd, 'ms');
  63959. Lib.mergeArray(marker.opacity, cd, 'mo');
  63960. Lib.mergeArray(marker.symbol, cd, 'mx');
  63961. Lib.mergeArray(marker.color, cd, 'mc');
  63962. var markerLine = marker.line;
  63963. if(marker.line) {
  63964. Lib.mergeArray(markerLine.color, cd, 'mlc');
  63965. Lib.mergeArray(markerLine.width, cd, 'mlw');
  63966. }
  63967. var markerGradient = marker.gradient;
  63968. if(markerGradient && markerGradient.type !== 'none') {
  63969. Lib.mergeArray(markerGradient.type, cd, 'mgt');
  63970. Lib.mergeArray(markerGradient.color, cd, 'mgc');
  63971. }
  63972. }
  63973. };
  63974. },{"../../lib":169}],366:[function(_dereq_,module,exports){
  63975. /**
  63976. * Copyright 2012-2018, Plotly, Inc.
  63977. * All rights reserved.
  63978. *
  63979. * This source code is licensed under the MIT license found in the
  63980. * LICENSE file in the root directory of this source tree.
  63981. */
  63982. 'use strict';
  63983. var colorAttributes = _dereq_('../../components/colorscale/attributes');
  63984. var colorbarAttrs = _dereq_('../../components/colorbar/attributes');
  63985. var fontAttrs = _dereq_('../../plots/font_attributes');
  63986. var dash = _dereq_('../../components/drawing/attributes').dash;
  63987. var Drawing = _dereq_('../../components/drawing');
  63988. var constants = _dereq_('./constants');
  63989. var extendFlat = _dereq_('../../lib/extend').extendFlat;
  63990. module.exports = {
  63991. x: {
  63992. valType: 'data_array',
  63993. editType: 'calc+clearAxisTypes',
  63994. },
  63995. x0: {
  63996. valType: 'any',
  63997. dflt: 0,
  63998. editType: 'calc+clearAxisTypes',
  63999. },
  64000. dx: {
  64001. valType: 'number',
  64002. dflt: 1,
  64003. editType: 'calc',
  64004. },
  64005. y: {
  64006. valType: 'data_array',
  64007. editType: 'calc+clearAxisTypes',
  64008. },
  64009. y0: {
  64010. valType: 'any',
  64011. dflt: 0,
  64012. editType: 'calc+clearAxisTypes',
  64013. },
  64014. dy: {
  64015. valType: 'number',
  64016. dflt: 1,
  64017. editType: 'calc',
  64018. },
  64019. stackgroup: {
  64020. valType: 'string',
  64021. dflt: '',
  64022. editType: 'calc',
  64023. },
  64024. orientation: {
  64025. valType: 'enumerated',
  64026. values: ['v', 'h'],
  64027. editType: 'calc',
  64028. },
  64029. groupnorm: {
  64030. valType: 'enumerated',
  64031. values: ['', 'fraction', 'percent'],
  64032. dflt: '',
  64033. editType: 'calc',
  64034. },
  64035. stackgaps: {
  64036. valType: 'enumerated',
  64037. values: ['infer zero', 'interpolate'],
  64038. dflt: 'infer zero',
  64039. editType: 'calc',
  64040. },
  64041. text: {
  64042. valType: 'string',
  64043. dflt: '',
  64044. arrayOk: true,
  64045. editType: 'calc',
  64046. },
  64047. hovertext: {
  64048. valType: 'string',
  64049. dflt: '',
  64050. arrayOk: true,
  64051. editType: 'style',
  64052. },
  64053. mode: {
  64054. valType: 'flaglist',
  64055. flags: ['lines', 'markers', 'text'],
  64056. extras: ['none'],
  64057. editType: 'calc',
  64058. },
  64059. hoveron: {
  64060. valType: 'flaglist',
  64061. flags: ['points', 'fills'],
  64062. editType: 'style',
  64063. },
  64064. line: {
  64065. color: {
  64066. valType: 'color',
  64067. editType: 'style',
  64068. },
  64069. width: {
  64070. valType: 'number',
  64071. min: 0,
  64072. dflt: 2,
  64073. editType: 'style',
  64074. },
  64075. shape: {
  64076. valType: 'enumerated',
  64077. values: ['linear', 'spline', 'hv', 'vh', 'hvh', 'vhv'],
  64078. dflt: 'linear',
  64079. editType: 'plot',
  64080. },
  64081. smoothing: {
  64082. valType: 'number',
  64083. min: 0,
  64084. max: 1.3,
  64085. dflt: 1,
  64086. editType: 'plot',
  64087. },
  64088. dash: extendFlat({}, dash, {editType: 'style'}),
  64089. simplify: {
  64090. valType: 'boolean',
  64091. dflt: true,
  64092. editType: 'plot',
  64093. },
  64094. editType: 'plot'
  64095. },
  64096. connectgaps: {
  64097. valType: 'boolean',
  64098. dflt: false,
  64099. editType: 'calc',
  64100. },
  64101. cliponaxis: {
  64102. valType: 'boolean',
  64103. dflt: true,
  64104. editType: 'plot',
  64105. },
  64106. fill: {
  64107. valType: 'enumerated',
  64108. values: ['none', 'tozeroy', 'tozerox', 'tonexty', 'tonextx', 'toself', 'tonext'],
  64109. editType: 'calc',
  64110. },
  64111. fillcolor: {
  64112. valType: 'color',
  64113. editType: 'style',
  64114. },
  64115. marker: extendFlat({
  64116. symbol: {
  64117. valType: 'enumerated',
  64118. values: Drawing.symbolList,
  64119. dflt: 'circle',
  64120. arrayOk: true,
  64121. editType: 'style',
  64122. },
  64123. opacity: {
  64124. valType: 'number',
  64125. min: 0,
  64126. max: 1,
  64127. arrayOk: true,
  64128. editType: 'style',
  64129. },
  64130. size: {
  64131. valType: 'number',
  64132. min: 0,
  64133. dflt: 6,
  64134. arrayOk: true,
  64135. editType: 'calc',
  64136. },
  64137. maxdisplayed: {
  64138. valType: 'number',
  64139. min: 0,
  64140. dflt: 0,
  64141. editType: 'plot',
  64142. },
  64143. sizeref: {
  64144. valType: 'number',
  64145. dflt: 1,
  64146. editType: 'calc',
  64147. },
  64148. sizemin: {
  64149. valType: 'number',
  64150. min: 0,
  64151. dflt: 0,
  64152. editType: 'calc',
  64153. },
  64154. sizemode: {
  64155. valType: 'enumerated',
  64156. values: ['diameter', 'area'],
  64157. dflt: 'diameter',
  64158. editType: 'calc',
  64159. },
  64160. colorbar: colorbarAttrs,
  64161. line: extendFlat({
  64162. width: {
  64163. valType: 'number',
  64164. min: 0,
  64165. arrayOk: true,
  64166. editType: 'style',
  64167. },
  64168. editType: 'calc'
  64169. },
  64170. colorAttributes('marker.line')
  64171. ),
  64172. gradient: {
  64173. type: {
  64174. valType: 'enumerated',
  64175. values: ['radial', 'horizontal', 'vertical', 'none'],
  64176. arrayOk: true,
  64177. dflt: 'none',
  64178. editType: 'calc',
  64179. },
  64180. color: {
  64181. valType: 'color',
  64182. arrayOk: true,
  64183. editType: 'calc',
  64184. },
  64185. editType: 'calc'
  64186. },
  64187. editType: 'calc'
  64188. },
  64189. colorAttributes('marker')
  64190. ),
  64191. selected: {
  64192. marker: {
  64193. opacity: {
  64194. valType: 'number',
  64195. min: 0,
  64196. max: 1,
  64197. editType: 'style',
  64198. },
  64199. color: {
  64200. valType: 'color',
  64201. editType: 'style',
  64202. },
  64203. size: {
  64204. valType: 'number',
  64205. min: 0,
  64206. editType: 'style',
  64207. },
  64208. editType: 'style'
  64209. },
  64210. textfont: {
  64211. color: {
  64212. valType: 'color',
  64213. editType: 'style',
  64214. },
  64215. editType: 'style'
  64216. },
  64217. editType: 'style'
  64218. },
  64219. unselected: {
  64220. marker: {
  64221. opacity: {
  64222. valType: 'number',
  64223. min: 0,
  64224. max: 1,
  64225. editType: 'style',
  64226. },
  64227. color: {
  64228. valType: 'color',
  64229. editType: 'style',
  64230. },
  64231. size: {
  64232. valType: 'number',
  64233. min: 0,
  64234. editType: 'style',
  64235. },
  64236. editType: 'style'
  64237. },
  64238. textfont: {
  64239. color: {
  64240. valType: 'color',
  64241. editType: 'style',
  64242. },
  64243. editType: 'style'
  64244. },
  64245. editType: 'style'
  64246. },
  64247. textposition: {
  64248. valType: 'enumerated',
  64249. values: [
  64250. 'top left', 'top center', 'top right',
  64251. 'middle left', 'middle center', 'middle right',
  64252. 'bottom left', 'bottom center', 'bottom right'
  64253. ],
  64254. dflt: 'middle center',
  64255. arrayOk: true,
  64256. editType: 'calc',
  64257. },
  64258. textfont: fontAttrs({
  64259. editType: 'calc',
  64260. colorEditType: 'style',
  64261. arrayOk: true,
  64262. }),
  64263. r: {
  64264. valType: 'data_array',
  64265. editType: 'calc',
  64266. },
  64267. t: {
  64268. valType: 'data_array',
  64269. editType: 'calc',
  64270. }
  64271. };
  64272. },{"../../components/colorbar/attributes":51,"../../components/colorscale/attributes":57,"../../components/drawing":75,"../../components/drawing/attributes":74,"../../lib/extend":163,"../../plots/font_attributes":240,"./constants":371}],367:[function(_dereq_,module,exports){
  64273. /**
  64274. * Copyright 2012-2018, Plotly, Inc.
  64275. * All rights reserved.
  64276. *
  64277. * This source code is licensed under the MIT license found in the
  64278. * LICENSE file in the root directory of this source tree.
  64279. */
  64280. 'use strict';
  64281. var isNumeric = _dereq_('fast-isnumeric');
  64282. var Lib = _dereq_('../../lib');
  64283. var Axes = _dereq_('../../plots/cartesian/axes');
  64284. var BADNUM = _dereq_('../../constants/numerical').BADNUM;
  64285. var subTypes = _dereq_('./subtypes');
  64286. var calcColorscale = _dereq_('./colorscale_calc');
  64287. var arraysToCalcdata = _dereq_('./arrays_to_calcdata');
  64288. var calcSelection = _dereq_('./calc_selection');
  64289. function calc(gd, trace) {
  64290. var fullLayout = gd._fullLayout;
  64291. var xa = Axes.getFromId(gd, trace.xaxis || 'x');
  64292. var ya = Axes.getFromId(gd, trace.yaxis || 'y');
  64293. var x = xa.makeCalcdata(trace, 'x');
  64294. var y = ya.makeCalcdata(trace, 'y');
  64295. var serieslen = trace._length;
  64296. var cd = new Array(serieslen);
  64297. var ids = trace.ids;
  64298. var stackGroupOpts = getStackOpts(trace, fullLayout, xa, ya);
  64299. var interpolateGaps = false;
  64300. var isV, i, j, k, interpolate, vali;
  64301. setFirstScatter(fullLayout, trace);
  64302. var xAttr = 'x';
  64303. var yAttr = 'y';
  64304. var posAttr;
  64305. if(stackGroupOpts) {
  64306. stackGroupOpts.traceIndices.push(trace.index);
  64307. isV = stackGroupOpts.orientation === 'v';
  64308. // size, like we use for bar
  64309. if(isV) {
  64310. yAttr = 's';
  64311. posAttr = 'x';
  64312. }
  64313. else {
  64314. xAttr = 's';
  64315. posAttr = 'y';
  64316. }
  64317. interpolate = stackGroupOpts.stackgaps === 'interpolate';
  64318. }
  64319. else {
  64320. var ppad = calcMarkerSize(trace, serieslen);
  64321. calcAxisExpansion(gd, trace, xa, ya, x, y, ppad);
  64322. }
  64323. for(i = 0; i < serieslen; i++) {
  64324. var cdi = cd[i] = {};
  64325. var xValid = isNumeric(x[i]);
  64326. var yValid = isNumeric(y[i]);
  64327. if(xValid && yValid) {
  64328. cdi[xAttr] = x[i];
  64329. cdi[yAttr] = y[i];
  64330. }
  64331. // if we're stacking we need to hold on to all valid positions
  64332. // even with invalid sizes
  64333. else if(stackGroupOpts && (isV ? xValid : yValid)) {
  64334. cdi[posAttr] = isV ? x[i] : y[i];
  64335. cdi.gap = true;
  64336. if(interpolate) {
  64337. cdi.s = BADNUM;
  64338. interpolateGaps = true;
  64339. }
  64340. else {
  64341. cdi.s = 0;
  64342. }
  64343. }
  64344. else {
  64345. cdi[xAttr] = cdi[yAttr] = BADNUM;
  64346. }
  64347. if(ids) {
  64348. cdi.id = String(ids[i]);
  64349. }
  64350. }
  64351. arraysToCalcdata(cd, trace);
  64352. calcColorscale(trace);
  64353. calcSelection(cd, trace);
  64354. if(stackGroupOpts) {
  64355. // remove bad positions and sort
  64356. // note that original indices get added to cd in arraysToCalcdata
  64357. i = 0;
  64358. while(i < cd.length) {
  64359. if(cd[i][posAttr] === BADNUM) {
  64360. cd.splice(i, 1);
  64361. }
  64362. else i++;
  64363. }
  64364. Lib.sort(cd, function(a, b) {
  64365. return (a[posAttr] - b[posAttr]) || (a.i - b.i);
  64366. });
  64367. if(interpolateGaps) {
  64368. // first fill the beginning with constant from the first point
  64369. i = 0;
  64370. while(i < cd.length - 1 && cd[i].gap) {
  64371. i++;
  64372. }
  64373. vali = cd[i].s;
  64374. if(!vali) vali = cd[i].s = 0; // in case of no data AT ALL in this trace - use 0
  64375. for(j = 0; j < i; j++) {
  64376. cd[j].s = vali;
  64377. }
  64378. // then fill the end with constant from the last point
  64379. k = cd.length - 1;
  64380. while(k > i && cd[k].gap) {
  64381. k--;
  64382. }
  64383. vali = cd[k].s;
  64384. for(j = cd.length - 1; j > k; j--) {
  64385. cd[j].s = vali;
  64386. }
  64387. // now interpolate internal gaps linearly
  64388. while(i < k) {
  64389. i++;
  64390. if(cd[i].gap) {
  64391. j = i + 1;
  64392. while(cd[j].gap) {
  64393. j++;
  64394. }
  64395. var pos0 = cd[i - 1][posAttr];
  64396. var size0 = cd[i - 1].s;
  64397. var m = (cd[j].s - size0) / (cd[j][posAttr] - pos0);
  64398. while(i < j) {
  64399. cd[i].s = size0 + (cd[i][posAttr] - pos0) * m;
  64400. i++;
  64401. }
  64402. }
  64403. }
  64404. }
  64405. }
  64406. return cd;
  64407. }
  64408. function calcAxisExpansion(gd, trace, xa, ya, x, y, ppad) {
  64409. var serieslen = trace._length;
  64410. var fullLayout = gd._fullLayout;
  64411. var xId = xa._id;
  64412. var yId = ya._id;
  64413. var firstScatter = fullLayout._firstScatter[firstScatterGroup(trace)] === trace.uid;
  64414. var stackOrientation = (getStackOpts(trace, fullLayout, xa, ya) || {}).orientation;
  64415. var fill = trace.fill;
  64416. // cancel minimum tick spacings (only applies to bars and boxes)
  64417. xa._minDtick = 0;
  64418. ya._minDtick = 0;
  64419. // check whether bounds should be tight, padded, extended to zero...
  64420. // most cases both should be padded on both ends, so start with that.
  64421. var xOptions = {padded: true};
  64422. var yOptions = {padded: true};
  64423. if(ppad) {
  64424. xOptions.ppad = yOptions.ppad = ppad;
  64425. }
  64426. // TODO: text size
  64427. var openEnded = serieslen < 2 || (x[0] !== x[serieslen - 1]) || (y[0] !== y[serieslen - 1]);
  64428. // include zero (tight) and extremes (padded) if fill to zero
  64429. // (unless the shape is closed, then it's just filling the shape regardless)
  64430. if(openEnded && (
  64431. (fill === 'tozerox') ||
  64432. ((fill === 'tonextx') && (firstScatter || stackOrientation === 'h'))
  64433. )) {
  64434. xOptions.tozero = true;
  64435. }
  64436. // if no error bars, markers or text, or fill to y=0 remove x padding
  64437. else if(!(trace.error_y || {}).visible && (
  64438. (fill === 'tonexty' || fill === 'tozeroy') ||
  64439. (!subTypes.hasMarkers(trace) && !subTypes.hasText(trace))
  64440. )) {
  64441. xOptions.padded = false;
  64442. xOptions.ppad = 0;
  64443. }
  64444. // now check for y - rather different logic, though still mostly padded both ends
  64445. // include zero (tight) and extremes (padded) if fill to zero
  64446. // (unless the shape is closed, then it's just filling the shape regardless)
  64447. if(openEnded && (
  64448. (fill === 'tozeroy') ||
  64449. ((fill === 'tonexty') && (firstScatter || stackOrientation === 'v'))
  64450. )) {
  64451. yOptions.tozero = true;
  64452. }
  64453. // tight y: any x fill
  64454. else if(fill === 'tonextx' || fill === 'tozerox') {
  64455. yOptions.padded = false;
  64456. }
  64457. // N.B. asymmetric splom traces call this with blank {} xa or ya
  64458. if(xId) trace._extremes[xId] = Axes.findExtremes(xa, x, xOptions);
  64459. if(yId) trace._extremes[yId] = Axes.findExtremes(ya, y, yOptions);
  64460. }
  64461. function calcMarkerSize(trace, serieslen) {
  64462. if(!subTypes.hasMarkers(trace)) return;
  64463. // Treat size like x or y arrays --- Run d2c
  64464. // this needs to go before ppad computation
  64465. var marker = trace.marker;
  64466. var sizeref = 1.6 * (trace.marker.sizeref || 1);
  64467. var markerTrans;
  64468. if(trace.marker.sizemode === 'area') {
  64469. markerTrans = function(v) {
  64470. return Math.max(Math.sqrt((v || 0) / sizeref), 3);
  64471. };
  64472. } else {
  64473. markerTrans = function(v) {
  64474. return Math.max((v || 0) / sizeref, 3);
  64475. };
  64476. }
  64477. if(Lib.isArrayOrTypedArray(marker.size)) {
  64478. // I tried auto-type but category and dates dont make much sense.
  64479. var ax = {type: 'linear'};
  64480. Axes.setConvert(ax);
  64481. var s = ax.makeCalcdata(trace.marker, 'size');
  64482. var sizeOut = new Array(serieslen);
  64483. for(var i = 0; i < serieslen; i++) {
  64484. sizeOut[i] = markerTrans(s[i]);
  64485. }
  64486. return sizeOut;
  64487. } else {
  64488. return markerTrans(marker.size);
  64489. }
  64490. }
  64491. /**
  64492. * mark the first scatter trace for each subplot
  64493. * note that scatter and scattergl each get their own first trace
  64494. * note also that I'm doing this during calc rather than supplyDefaults
  64495. * so I don't need to worry about transforms, but if we ever do
  64496. * per-trace calc this will get confused.
  64497. */
  64498. function setFirstScatter(fullLayout, trace) {
  64499. var group = firstScatterGroup(trace);
  64500. var firstScatter = fullLayout._firstScatter;
  64501. if(!firstScatter[group]) firstScatter[group] = trace.uid;
  64502. }
  64503. function firstScatterGroup(trace) {
  64504. var stackGroup = trace.stackgroup;
  64505. return trace.xaxis + trace.yaxis + trace.type +
  64506. (stackGroup ? '-' + stackGroup : '');
  64507. }
  64508. function getStackOpts(trace, fullLayout, xa, ya) {
  64509. var stackGroup = trace.stackgroup;
  64510. if(!stackGroup) return;
  64511. var stackOpts = fullLayout._scatterStackOpts[xa._id + ya._id][stackGroup];
  64512. var stackAx = stackOpts.orientation === 'v' ? ya : xa;
  64513. // Allow stacking only on numeric axes
  64514. // calc is a little late to be figuring this out, but during supplyDefaults
  64515. // we don't know the axis type yet
  64516. if(stackAx.type === 'linear' || stackAx.type === 'log') return stackOpts;
  64517. }
  64518. module.exports = {
  64519. calc: calc,
  64520. calcMarkerSize: calcMarkerSize,
  64521. calcAxisExpansion: calcAxisExpansion,
  64522. setFirstScatter: setFirstScatter,
  64523. getStackOpts: getStackOpts
  64524. };
  64525. },{"../../constants/numerical":151,"../../lib":169,"../../plots/cartesian/axes":214,"./arrays_to_calcdata":365,"./calc_selection":368,"./colorscale_calc":370,"./subtypes":390,"fast-isnumeric":18}],368:[function(_dereq_,module,exports){
  64526. /**
  64527. * Copyright 2012-2018, Plotly, Inc.
  64528. * All rights reserved.
  64529. *
  64530. * This source code is licensed under the MIT license found in the
  64531. * LICENSE file in the root directory of this source tree.
  64532. */
  64533. 'use strict';
  64534. var Lib = _dereq_('../../lib');
  64535. module.exports = function calcSelection(cd, trace) {
  64536. if(Lib.isArrayOrTypedArray(trace.selectedpoints)) {
  64537. Lib.tagSelected(cd, trace);
  64538. }
  64539. };
  64540. },{"../../lib":169}],369:[function(_dereq_,module,exports){
  64541. /**
  64542. * Copyright 2012-2018, Plotly, Inc.
  64543. * All rights reserved.
  64544. *
  64545. * This source code is licensed under the MIT license found in the
  64546. * LICENSE file in the root directory of this source tree.
  64547. */
  64548. 'use strict';
  64549. // remove opacity for any trace that has a fill or is filled to
  64550. module.exports = function cleanData(fullData) {
  64551. for(var i = 0; i < fullData.length; i++) {
  64552. var tracei = fullData[i];
  64553. if(tracei.type !== 'scatter') continue;
  64554. var filli = tracei.fill;
  64555. if(filli === 'none' || filli === 'toself') continue;
  64556. tracei.opacity = undefined;
  64557. if(filli === 'tonexty' || filli === 'tonextx') {
  64558. for(var j = i - 1; j >= 0; j--) {
  64559. var tracej = fullData[j];
  64560. if((tracej.type === 'scatter') &&
  64561. (tracej.xaxis === tracei.xaxis) &&
  64562. (tracej.yaxis === tracei.yaxis)) {
  64563. tracej.opacity = undefined;
  64564. break;
  64565. }
  64566. }
  64567. }
  64568. }
  64569. };
  64570. },{}],370:[function(_dereq_,module,exports){
  64571. /**
  64572. * Copyright 2012-2018, Plotly, Inc.
  64573. * All rights reserved.
  64574. *
  64575. * This source code is licensed under the MIT license found in the
  64576. * LICENSE file in the root directory of this source tree.
  64577. */
  64578. 'use strict';
  64579. var hasColorscale = _dereq_('../../components/colorscale/has_colorscale');
  64580. var calcColorscale = _dereq_('../../components/colorscale/calc');
  64581. var subTypes = _dereq_('./subtypes');
  64582. module.exports = function calcMarkerColorscale(trace) {
  64583. if(subTypes.hasLines(trace) && hasColorscale(trace, 'line')) {
  64584. calcColorscale(trace, trace.line.color, 'line', 'c');
  64585. }
  64586. if(subTypes.hasMarkers(trace)) {
  64587. if(hasColorscale(trace, 'marker')) {
  64588. calcColorscale(trace, trace.marker.color, 'marker', 'c');
  64589. }
  64590. if(hasColorscale(trace, 'marker.line')) {
  64591. calcColorscale(trace, trace.marker.line.color, 'marker.line', 'c');
  64592. }
  64593. }
  64594. };
  64595. },{"../../components/colorscale/calc":58,"../../components/colorscale/has_colorscale":64,"./subtypes":390}],371:[function(_dereq_,module,exports){
  64596. /**
  64597. * Copyright 2012-2018, Plotly, Inc.
  64598. * All rights reserved.
  64599. *
  64600. * This source code is licensed under the MIT license found in the
  64601. * LICENSE file in the root directory of this source tree.
  64602. */
  64603. 'use strict';
  64604. module.exports = {
  64605. PTS_LINESONLY: 20,
  64606. // fixed parameters of clustering and clipping algorithms
  64607. // fraction of clustering tolerance "so close we don't even consider it a new point"
  64608. minTolerance: 0.2,
  64609. // how fast does clustering tolerance increase as you get away from the visible region
  64610. toleranceGrowth: 10,
  64611. // number of viewport sizes away from the visible region
  64612. // at which we clip all lines to the perimeter
  64613. maxScreensAway: 20
  64614. };
  64615. },{}],372:[function(_dereq_,module,exports){
  64616. /**
  64617. * Copyright 2012-2018, Plotly, Inc.
  64618. * All rights reserved.
  64619. *
  64620. * This source code is licensed under the MIT license found in the
  64621. * LICENSE file in the root directory of this source tree.
  64622. */
  64623. 'use strict';
  64624. var calc = _dereq_('./calc');
  64625. /*
  64626. * Scatter stacking & normalization calculations
  64627. * runs per subplot, and can handle multiple stacking groups
  64628. */
  64629. module.exports = function crossTraceCalc(gd, plotinfo) {
  64630. var xa = plotinfo.xaxis;
  64631. var ya = plotinfo.yaxis;
  64632. var subplot = xa._id + ya._id;
  64633. var subplotStackOpts = gd._fullLayout._scatterStackOpts[subplot];
  64634. if(!subplotStackOpts) return;
  64635. var calcTraces = gd.calcdata;
  64636. var i, j, k, i2, cd, cd0, posj, sumj, norm;
  64637. var groupOpts, interpolate, groupnorm, posAttr, valAttr;
  64638. var hasAnyBlanks;
  64639. for(var stackGroup in subplotStackOpts) {
  64640. groupOpts = subplotStackOpts[stackGroup];
  64641. var indices = groupOpts.traceIndices;
  64642. // can get here with no indices if the stack axis is non-numeric
  64643. if(!indices.length) continue;
  64644. interpolate = groupOpts.stackgaps === 'interpolate';
  64645. groupnorm = groupOpts.groupnorm;
  64646. if(groupOpts.orientation === 'v') {
  64647. posAttr = 'x';
  64648. valAttr = 'y';
  64649. }
  64650. else {
  64651. posAttr = 'y';
  64652. valAttr = 'x';
  64653. }
  64654. hasAnyBlanks = new Array(indices.length);
  64655. for(i = 0; i < hasAnyBlanks.length; i++) {
  64656. hasAnyBlanks[i] = false;
  64657. }
  64658. // Collect the complete set of all positions across ALL traces.
  64659. // Start with the first trace, then interleave items from later traces
  64660. // as needed.
  64661. // Fill in mising items as we go.
  64662. cd0 = calcTraces[indices[0]];
  64663. var allPositions = new Array(cd0.length);
  64664. for(i = 0; i < cd0.length; i++) {
  64665. allPositions[i] = cd0[i][posAttr];
  64666. }
  64667. for(i = 1; i < indices.length; i++) {
  64668. cd = calcTraces[indices[i]];
  64669. for(j = k = 0; j < cd.length; j++) {
  64670. posj = cd[j][posAttr];
  64671. for(; posj > allPositions[k] && k < allPositions.length; k++) {
  64672. // the current trace is missing a position from some previous trace(s)
  64673. insertBlank(cd, j, allPositions[k], i, hasAnyBlanks, interpolate, posAttr);
  64674. j++;
  64675. }
  64676. if(posj !== allPositions[k]) {
  64677. // previous trace(s) are missing a position from the current trace
  64678. for(i2 = 0; i2 < i; i2++) {
  64679. insertBlank(calcTraces[indices[i2]], k, posj, i2, hasAnyBlanks, interpolate, posAttr);
  64680. }
  64681. allPositions.splice(k, 0, posj);
  64682. }
  64683. k++;
  64684. }
  64685. for(; k < allPositions.length; k++) {
  64686. insertBlank(cd, j, allPositions[k], i, hasAnyBlanks, interpolate, posAttr);
  64687. j++;
  64688. }
  64689. }
  64690. var serieslen = allPositions.length;
  64691. // stack (and normalize)!
  64692. for(j = 0; j < cd0.length; j++) {
  64693. sumj = cd0[j][valAttr] = cd0[j].s;
  64694. for(i = 1; i < indices.length; i++) {
  64695. cd = calcTraces[indices[i]];
  64696. cd[0].trace._rawLength = cd[0].trace._length;
  64697. cd[0].trace._length = serieslen;
  64698. sumj += cd[j].s;
  64699. cd[j][valAttr] = sumj;
  64700. }
  64701. if(groupnorm) {
  64702. norm = ((groupnorm === 'fraction') ? sumj : (sumj / 100)) || 1;
  64703. for(i = 0; i < indices.length; i++) {
  64704. var cdj = calcTraces[indices[i]][j];
  64705. cdj[valAttr] /= norm;
  64706. cdj.sNorm = cdj.s / norm;
  64707. }
  64708. }
  64709. }
  64710. // autorange
  64711. for(i = 0; i < indices.length; i++) {
  64712. cd = calcTraces[indices[i]];
  64713. var trace = cd[0].trace;
  64714. var ppad = calc.calcMarkerSize(trace, trace._rawLength);
  64715. var arrayPad = Array.isArray(ppad);
  64716. if((ppad && hasAnyBlanks[i]) || arrayPad) {
  64717. var ppadRaw = ppad;
  64718. ppad = new Array(serieslen);
  64719. for(j = 0; j < serieslen; j++) {
  64720. ppad[j] = cd[j].gap ? 0 : (arrayPad ? ppadRaw[cd[j].i] : ppadRaw);
  64721. }
  64722. }
  64723. var x = new Array(serieslen);
  64724. var y = new Array(serieslen);
  64725. for(j = 0; j < serieslen; j++) {
  64726. x[j] = cd[j].x;
  64727. y[j] = cd[j].y;
  64728. }
  64729. calc.calcAxisExpansion(gd, trace, xa, ya, x, y, ppad);
  64730. // while we're here (in a loop over all traces in the stack)
  64731. // record the orientation, so hover can find it easily
  64732. cd[0].t.orientation = groupOpts.orientation;
  64733. }
  64734. }
  64735. };
  64736. function insertBlank(calcTrace, index, position, traceIndex, hasAnyBlanks, interpolate, posAttr) {
  64737. hasAnyBlanks[traceIndex] = true;
  64738. var newEntry = {
  64739. i: null,
  64740. gap: true,
  64741. s: 0
  64742. };
  64743. newEntry[posAttr] = position;
  64744. calcTrace.splice(index, 0, newEntry);
  64745. // Even if we're not interpolating, if one trace has multiple
  64746. // values at the same position and this trace only has one value there,
  64747. // we just duplicate that one value rather than insert a zero.
  64748. // We also make it look like a real point - because it's ambiguous which
  64749. // one really is the real one!
  64750. if(index && position === calcTrace[index - 1][posAttr]) {
  64751. var prevEntry = calcTrace[index - 1];
  64752. newEntry.s = prevEntry.s;
  64753. // TODO is it going to cause any problems to have multiple
  64754. // calcdata points with the same index?
  64755. newEntry.i = prevEntry.i;
  64756. newEntry.gap = prevEntry.gap;
  64757. }
  64758. else if(interpolate) {
  64759. newEntry.s = getInterp(calcTrace, index, position, posAttr);
  64760. }
  64761. if(!index) {
  64762. // t and trace need to stay on the first cd entry
  64763. calcTrace[0].t = calcTrace[1].t;
  64764. calcTrace[0].trace = calcTrace[1].trace;
  64765. delete calcTrace[1].t;
  64766. delete calcTrace[1].trace;
  64767. }
  64768. }
  64769. function getInterp(calcTrace, index, position, posAttr) {
  64770. var pt0 = calcTrace[index - 1];
  64771. var pt1 = calcTrace[index + 1];
  64772. if(!pt1) return pt0.s;
  64773. if(!pt0) return pt1.s;
  64774. return pt0.s + (pt1.s - pt0.s) * (position - pt0[posAttr]) / (pt1[posAttr] - pt0[posAttr]);
  64775. }
  64776. },{"./calc":367}],373:[function(_dereq_,module,exports){
  64777. /**
  64778. * Copyright 2012-2018, Plotly, Inc.
  64779. * All rights reserved.
  64780. *
  64781. * This source code is licensed under the MIT license found in the
  64782. * LICENSE file in the root directory of this source tree.
  64783. */
  64784. 'use strict';
  64785. var Lib = _dereq_('../../lib');
  64786. var Registry = _dereq_('../../registry');
  64787. var attributes = _dereq_('./attributes');
  64788. var constants = _dereq_('./constants');
  64789. var subTypes = _dereq_('./subtypes');
  64790. var handleXYDefaults = _dereq_('./xy_defaults');
  64791. var handleStackDefaults = _dereq_('./stack_defaults');
  64792. var handleMarkerDefaults = _dereq_('./marker_defaults');
  64793. var handleLineDefaults = _dereq_('./line_defaults');
  64794. var handleLineShapeDefaults = _dereq_('./line_shape_defaults');
  64795. var handleTextDefaults = _dereq_('./text_defaults');
  64796. var handleFillColorDefaults = _dereq_('./fillcolor_defaults');
  64797. module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout) {
  64798. function coerce(attr, dflt) {
  64799. return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);
  64800. }
  64801. var len = handleXYDefaults(traceIn, traceOut, layout, coerce);
  64802. if(!len) traceOut.visible = false;
  64803. if(!traceOut.visible) return;
  64804. var stackGroupOpts = handleStackDefaults(traceIn, traceOut, layout, coerce);
  64805. var defaultMode = !stackGroupOpts && (len < constants.PTS_LINESONLY) ?
  64806. 'lines+markers' : 'lines';
  64807. coerce('text');
  64808. coerce('hovertext');
  64809. coerce('mode', defaultMode);
  64810. if(subTypes.hasLines(traceOut)) {
  64811. handleLineDefaults(traceIn, traceOut, defaultColor, layout, coerce);
  64812. handleLineShapeDefaults(traceIn, traceOut, coerce);
  64813. coerce('connectgaps');
  64814. coerce('line.simplify');
  64815. }
  64816. if(subTypes.hasMarkers(traceOut)) {
  64817. handleMarkerDefaults(traceIn, traceOut, defaultColor, layout, coerce, {gradient: true});
  64818. }
  64819. if(subTypes.hasText(traceOut)) {
  64820. handleTextDefaults(traceIn, traceOut, layout, coerce);
  64821. }
  64822. var dfltHoverOn = [];
  64823. if(subTypes.hasMarkers(traceOut) || subTypes.hasText(traceOut)) {
  64824. coerce('cliponaxis');
  64825. coerce('marker.maxdisplayed');
  64826. dfltHoverOn.push('points');
  64827. }
  64828. // It's possible for this default to be changed by a later trace.
  64829. // We handle that case in some hacky code inside handleStackDefaults.
  64830. coerce('fill', stackGroupOpts ? stackGroupOpts.fillDflt : 'none');
  64831. if(traceOut.fill !== 'none') {
  64832. handleFillColorDefaults(traceIn, traceOut, defaultColor, coerce);
  64833. if(!subTypes.hasLines(traceOut)) handleLineShapeDefaults(traceIn, traceOut, coerce);
  64834. }
  64835. if(traceOut.fill === 'tonext' || traceOut.fill === 'toself') {
  64836. dfltHoverOn.push('fills');
  64837. }
  64838. coerce('hoveron', dfltHoverOn.join('+') || 'points');
  64839. var errorBarsSupplyDefaults = Registry.getComponentMethod('errorbars', 'supplyDefaults');
  64840. errorBarsSupplyDefaults(traceIn, traceOut, defaultColor, {axis: 'y'});
  64841. errorBarsSupplyDefaults(traceIn, traceOut, defaultColor, {axis: 'x', inherit: 'y'});
  64842. Lib.coerceSelectionMarkerOpacity(traceOut, coerce);
  64843. };
  64844. },{"../../lib":169,"../../registry":259,"./attributes":366,"./constants":371,"./fillcolor_defaults":375,"./line_defaults":379,"./line_shape_defaults":381,"./marker_defaults":385,"./stack_defaults":388,"./subtypes":390,"./text_defaults":391,"./xy_defaults":392}],374:[function(_dereq_,module,exports){
  64845. /**
  64846. * Copyright 2012-2018, Plotly, Inc.
  64847. * All rights reserved.
  64848. *
  64849. * This source code is licensed under the MIT license found in the
  64850. * LICENSE file in the root directory of this source tree.
  64851. */
  64852. 'use strict';
  64853. var Lib = _dereq_('../../lib');
  64854. /** Fill hover 'pointData' container with 'correct' hover text value
  64855. *
  64856. * - If trace hoverinfo contains a 'text' flag and hovertext is not set,
  64857. * the text elements will be seen in the hover labels.
  64858. *
  64859. * - If trace hoverinfo contains a 'text' flag and hovertext is set,
  64860. * hovertext takes precedence over text
  64861. * i.e. the hoverinfo elements will be seen in the hover labels
  64862. *
  64863. * @param {object} calcPt
  64864. * @param {object} trace
  64865. * @param {object || array} contOut (mutated here)
  64866. */
  64867. module.exports = function fillHoverText(calcPt, trace, contOut) {
  64868. var fill = Array.isArray(contOut) ?
  64869. function(v) { contOut.push(v); } :
  64870. function(v) { contOut.text = v; };
  64871. var htx = Lib.extractOption(calcPt, trace, 'htx', 'hovertext');
  64872. if(isValid(htx)) return fill(htx);
  64873. var tx = Lib.extractOption(calcPt, trace, 'tx', 'text');
  64874. if(isValid(tx)) return fill(tx);
  64875. };
  64876. // accept all truthy values and 0 (which gets cast to '0' in the hover labels)
  64877. function isValid(v) {
  64878. return v || v === 0;
  64879. }
  64880. },{"../../lib":169}],375:[function(_dereq_,module,exports){
  64881. /**
  64882. * Copyright 2012-2018, Plotly, Inc.
  64883. * All rights reserved.
  64884. *
  64885. * This source code is licensed under the MIT license found in the
  64886. * LICENSE file in the root directory of this source tree.
  64887. */
  64888. 'use strict';
  64889. var Color = _dereq_('../../components/color');
  64890. var isArrayOrTypedArray = _dereq_('../../lib').isArrayOrTypedArray;
  64891. module.exports = function fillColorDefaults(traceIn, traceOut, defaultColor, coerce) {
  64892. var inheritColorFromMarker = false;
  64893. if(traceOut.marker) {
  64894. // don't try to inherit a color array
  64895. var markerColor = traceOut.marker.color,
  64896. markerLineColor = (traceOut.marker.line || {}).color;
  64897. if(markerColor && !isArrayOrTypedArray(markerColor)) {
  64898. inheritColorFromMarker = markerColor;
  64899. }
  64900. else if(markerLineColor && !isArrayOrTypedArray(markerLineColor)) {
  64901. inheritColorFromMarker = markerLineColor;
  64902. }
  64903. }
  64904. coerce('fillcolor', Color.addOpacity(
  64905. (traceOut.line || {}).color ||
  64906. inheritColorFromMarker ||
  64907. defaultColor, 0.5
  64908. ));
  64909. };
  64910. },{"../../components/color":50,"../../lib":169}],376:[function(_dereq_,module,exports){
  64911. /**
  64912. * Copyright 2012-2018, Plotly, Inc.
  64913. * All rights reserved.
  64914. *
  64915. * This source code is licensed under the MIT license found in the
  64916. * LICENSE file in the root directory of this source tree.
  64917. */
  64918. 'use strict';
  64919. var Color = _dereq_('../../components/color');
  64920. var subtypes = _dereq_('./subtypes');
  64921. module.exports = function getTraceColor(trace, di) {
  64922. var lc, tc;
  64923. // TODO: text modes
  64924. if(trace.mode === 'lines') {
  64925. lc = trace.line.color;
  64926. return (lc && Color.opacity(lc)) ?
  64927. lc : trace.fillcolor;
  64928. }
  64929. else if(trace.mode === 'none') {
  64930. return trace.fill ? trace.fillcolor : '';
  64931. }
  64932. else {
  64933. var mc = di.mcc || (trace.marker || {}).color,
  64934. mlc = di.mlcc || ((trace.marker || {}).line || {}).color;
  64935. tc = (mc && Color.opacity(mc)) ? mc :
  64936. (mlc && Color.opacity(mlc) &&
  64937. (di.mlw || ((trace.marker || {}).line || {}).width)) ? mlc : '';
  64938. if(tc) {
  64939. // make sure the points aren't TOO transparent
  64940. if(Color.opacity(tc) < 0.3) {
  64941. return Color.addOpacity(tc, 0.3);
  64942. }
  64943. else return tc;
  64944. }
  64945. else {
  64946. lc = (trace.line || {}).color;
  64947. return (lc && Color.opacity(lc) &&
  64948. subtypes.hasLines(trace) && trace.line.width) ?
  64949. lc : trace.fillcolor;
  64950. }
  64951. }
  64952. };
  64953. },{"../../components/color":50,"./subtypes":390}],377:[function(_dereq_,module,exports){
  64954. /**
  64955. * Copyright 2012-2018, Plotly, Inc.
  64956. * All rights reserved.
  64957. *
  64958. * This source code is licensed under the MIT license found in the
  64959. * LICENSE file in the root directory of this source tree.
  64960. */
  64961. 'use strict';
  64962. var Lib = _dereq_('../../lib');
  64963. var Fx = _dereq_('../../components/fx');
  64964. var Registry = _dereq_('../../registry');
  64965. var getTraceColor = _dereq_('./get_trace_color');
  64966. var Color = _dereq_('../../components/color');
  64967. var fillHoverText = _dereq_('./fill_hover_text');
  64968. module.exports = function hoverPoints(pointData, xval, yval, hovermode) {
  64969. var cd = pointData.cd;
  64970. var trace = cd[0].trace;
  64971. var xa = pointData.xa;
  64972. var ya = pointData.ya;
  64973. var xpx = xa.c2p(xval);
  64974. var ypx = ya.c2p(yval);
  64975. var pt = [xpx, ypx];
  64976. var hoveron = trace.hoveron || '';
  64977. var minRad = (trace.mode.indexOf('markers') !== -1) ? 3 : 0.5;
  64978. // look for points to hover on first, then take fills only if we
  64979. // didn't find a point
  64980. if(hoveron.indexOf('points') !== -1) {
  64981. var dx = function(di) {
  64982. // dx and dy are used in compare modes - here we want to always
  64983. // prioritize the closest data point, at least as long as markers are
  64984. // the same size or nonexistent, but still try to prioritize small markers too.
  64985. var rad = Math.max(3, di.mrc || 0);
  64986. var kink = 1 - 1 / rad;
  64987. var dxRaw = Math.abs(xa.c2p(di.x) - xpx);
  64988. var d = (dxRaw < rad) ? (kink * dxRaw / rad) : (dxRaw - rad + kink);
  64989. return d;
  64990. };
  64991. var dy = function(di) {
  64992. var rad = Math.max(3, di.mrc || 0);
  64993. var kink = 1 - 1 / rad;
  64994. var dyRaw = Math.abs(ya.c2p(di.y) - ypx);
  64995. return (dyRaw < rad) ? (kink * dyRaw / rad) : (dyRaw - rad + kink);
  64996. };
  64997. var dxy = function(di) {
  64998. // scatter points: d.mrc is the calculated marker radius
  64999. // adjust the distance so if you're inside the marker it
  65000. // always will show up regardless of point size, but
  65001. // prioritize smaller points
  65002. var rad = Math.max(minRad, di.mrc || 0);
  65003. var dx = xa.c2p(di.x) - xpx;
  65004. var dy = ya.c2p(di.y) - ypx;
  65005. return Math.max(Math.sqrt(dx * dx + dy * dy) - rad, 1 - minRad / rad);
  65006. };
  65007. var distfn = Fx.getDistanceFunction(hovermode, dx, dy, dxy);
  65008. Fx.getClosest(cd, distfn, pointData);
  65009. // skip the rest (for this trace) if we didn't find a close point
  65010. if(pointData.index !== false) {
  65011. // the closest data point
  65012. var di = cd[pointData.index];
  65013. var xc = xa.c2p(di.x, true);
  65014. var yc = ya.c2p(di.y, true);
  65015. var rad = di.mrc || 1;
  65016. // now we're done using the whole `calcdata` array, replace the
  65017. // index with the original index (in case of inserted point from
  65018. // stacked area)
  65019. pointData.index = di.i;
  65020. var orientation = cd[0].t.orientation;
  65021. // TODO: for scatter and bar, option to show (sub)totals and
  65022. // raw data? Currently stacked and/or normalized bars just show
  65023. // the normalized individual sizes, so that's what I'm doing here
  65024. // for now.
  65025. var sizeVal = orientation && (di.sNorm || di.s);
  65026. var xLabelVal = (orientation === 'h') ? sizeVal : di.x;
  65027. var yLabelVal = (orientation === 'v') ? sizeVal : di.y;
  65028. Lib.extendFlat(pointData, {
  65029. color: getTraceColor(trace, di),
  65030. x0: xc - rad,
  65031. x1: xc + rad,
  65032. xLabelVal: xLabelVal,
  65033. y0: yc - rad,
  65034. y1: yc + rad,
  65035. yLabelVal: yLabelVal,
  65036. spikeDistance: dxy(di)
  65037. });
  65038. fillHoverText(di, trace, pointData);
  65039. Registry.getComponentMethod('errorbars', 'hoverInfo')(di, trace, pointData);
  65040. return [pointData];
  65041. }
  65042. }
  65043. // even if hoveron is 'fills', only use it if we have polygons too
  65044. if(hoveron.indexOf('fills') !== -1 && trace._polygons) {
  65045. var polygons = trace._polygons;
  65046. var polygonsIn = [];
  65047. var inside = false;
  65048. var xmin = Infinity;
  65049. var xmax = -Infinity;
  65050. var ymin = Infinity;
  65051. var ymax = -Infinity;
  65052. var i, j, polygon, pts, xCross, x0, x1, y0, y1;
  65053. for(i = 0; i < polygons.length; i++) {
  65054. polygon = polygons[i];
  65055. // TODO: this is not going to work right for curved edges, it will
  65056. // act as though they're straight. That's probably going to need
  65057. // the elements themselves to capture the events. Worth it?
  65058. if(polygon.contains(pt)) {
  65059. inside = !inside;
  65060. // TODO: need better than just the overall bounding box
  65061. polygonsIn.push(polygon);
  65062. ymin = Math.min(ymin, polygon.ymin);
  65063. ymax = Math.max(ymax, polygon.ymax);
  65064. }
  65065. }
  65066. if(inside) {
  65067. // constrain ymin/max to the visible plot, so the label goes
  65068. // at the middle of the piece you can see
  65069. ymin = Math.max(ymin, 0);
  65070. ymax = Math.min(ymax, ya._length);
  65071. // find the overall left-most and right-most points of the
  65072. // polygon(s) we're inside at their combined vertical midpoint.
  65073. // This is where we will draw the hover label.
  65074. // Note that this might not be the vertical midpoint of the
  65075. // whole trace, if it's disjoint.
  65076. var yAvg = (ymin + ymax) / 2;
  65077. for(i = 0; i < polygonsIn.length; i++) {
  65078. pts = polygonsIn[i].pts;
  65079. for(j = 1; j < pts.length; j++) {
  65080. y0 = pts[j - 1][1];
  65081. y1 = pts[j][1];
  65082. if((y0 > yAvg) !== (y1 >= yAvg)) {
  65083. x0 = pts[j - 1][0];
  65084. x1 = pts[j][0];
  65085. if(y1 - y0) {
  65086. xCross = x0 + (x1 - x0) * (yAvg - y0) / (y1 - y0);
  65087. xmin = Math.min(xmin, xCross);
  65088. xmax = Math.max(xmax, xCross);
  65089. }
  65090. }
  65091. }
  65092. }
  65093. // constrain xmin/max to the visible plot now too
  65094. xmin = Math.max(xmin, 0);
  65095. xmax = Math.min(xmax, xa._length);
  65096. // get only fill or line color for the hover color
  65097. var color = Color.defaultLine;
  65098. if(Color.opacity(trace.fillcolor)) color = trace.fillcolor;
  65099. else if(Color.opacity((trace.line || {}).color)) {
  65100. color = trace.line.color;
  65101. }
  65102. Lib.extendFlat(pointData, {
  65103. // never let a 2D override 1D type as closest point
  65104. // also: no spikeDistance, it's not allowed for fills
  65105. distance: pointData.maxHoverDistance,
  65106. x0: xmin,
  65107. x1: xmax,
  65108. y0: yAvg,
  65109. y1: yAvg,
  65110. color: color
  65111. });
  65112. delete pointData.index;
  65113. if(trace.text && !Array.isArray(trace.text)) {
  65114. pointData.text = String(trace.text);
  65115. }
  65116. else pointData.text = trace.name;
  65117. return [pointData];
  65118. }
  65119. }
  65120. };
  65121. },{"../../components/color":50,"../../components/fx":92,"../../lib":169,"../../registry":259,"./fill_hover_text":374,"./get_trace_color":376}],378:[function(_dereq_,module,exports){
  65122. /**
  65123. * Copyright 2012-2018, Plotly, Inc.
  65124. * All rights reserved.
  65125. *
  65126. * This source code is licensed under the MIT license found in the
  65127. * LICENSE file in the root directory of this source tree.
  65128. */
  65129. 'use strict';
  65130. var Scatter = {};
  65131. var subtypes = _dereq_('./subtypes');
  65132. Scatter.hasLines = subtypes.hasLines;
  65133. Scatter.hasMarkers = subtypes.hasMarkers;
  65134. Scatter.hasText = subtypes.hasText;
  65135. Scatter.isBubble = subtypes.isBubble;
  65136. Scatter.attributes = _dereq_('./attributes');
  65137. Scatter.supplyDefaults = _dereq_('./defaults');
  65138. Scatter.cleanData = _dereq_('./clean_data');
  65139. Scatter.calc = _dereq_('./calc').calc;
  65140. Scatter.crossTraceCalc = _dereq_('./cross_trace_calc');
  65141. Scatter.arraysToCalcdata = _dereq_('./arrays_to_calcdata');
  65142. Scatter.plot = _dereq_('./plot');
  65143. Scatter.colorbar = _dereq_('./marker_colorbar');
  65144. Scatter.style = _dereq_('./style').style;
  65145. Scatter.styleOnSelect = _dereq_('./style').styleOnSelect;
  65146. Scatter.hoverPoints = _dereq_('./hover');
  65147. Scatter.selectPoints = _dereq_('./select');
  65148. Scatter.animatable = true;
  65149. Scatter.moduleType = 'trace';
  65150. Scatter.name = 'scatter';
  65151. Scatter.basePlotModule = _dereq_('../../plots/cartesian');
  65152. Scatter.categories = [
  65153. 'cartesian', 'svg', 'symbols', 'errorBarsOK', 'showLegend', 'scatter-like',
  65154. 'zoomScale'
  65155. ];
  65156. Scatter.meta = {
  65157. };
  65158. module.exports = Scatter;
  65159. },{"../../plots/cartesian":225,"./arrays_to_calcdata":365,"./attributes":366,"./calc":367,"./clean_data":369,"./cross_trace_calc":372,"./defaults":373,"./hover":377,"./marker_colorbar":384,"./plot":386,"./select":387,"./style":389,"./subtypes":390}],379:[function(_dereq_,module,exports){
  65160. /**
  65161. * Copyright 2012-2018, Plotly, Inc.
  65162. * All rights reserved.
  65163. *
  65164. * This source code is licensed under the MIT license found in the
  65165. * LICENSE file in the root directory of this source tree.
  65166. */
  65167. 'use strict';
  65168. var isArrayOrTypedArray = _dereq_('../../lib').isArrayOrTypedArray;
  65169. var hasColorscale = _dereq_('../../components/colorscale/has_colorscale');
  65170. var colorscaleDefaults = _dereq_('../../components/colorscale/defaults');
  65171. module.exports = function lineDefaults(traceIn, traceOut, defaultColor, layout, coerce, opts) {
  65172. var markerColor = (traceIn.marker || {}).color;
  65173. coerce('line.color', defaultColor);
  65174. if(hasColorscale(traceIn, 'line')) {
  65175. colorscaleDefaults(traceIn, traceOut, layout, coerce, {prefix: 'line.', cLetter: 'c', noScale: true});
  65176. } else {
  65177. var lineColorDflt = (isArrayOrTypedArray(markerColor) ? false : markerColor) || defaultColor;
  65178. coerce('line.color', lineColorDflt);
  65179. }
  65180. coerce('line.width');
  65181. if(!(opts || {}).noDash) coerce('line.dash');
  65182. };
  65183. },{"../../components/colorscale/defaults":60,"../../components/colorscale/has_colorscale":64,"../../lib":169}],380:[function(_dereq_,module,exports){
  65184. /**
  65185. * Copyright 2012-2018, Plotly, Inc.
  65186. * All rights reserved.
  65187. *
  65188. * This source code is licensed under the MIT license found in the
  65189. * LICENSE file in the root directory of this source tree.
  65190. */
  65191. 'use strict';
  65192. var numConstants = _dereq_('../../constants/numerical');
  65193. var BADNUM = numConstants.BADNUM;
  65194. var LOG_CLIP = numConstants.LOG_CLIP;
  65195. var LOG_CLIP_PLUS = LOG_CLIP + 0.5;
  65196. var LOG_CLIP_MINUS = LOG_CLIP - 0.5;
  65197. var Lib = _dereq_('../../lib');
  65198. var segmentsIntersect = Lib.segmentsIntersect;
  65199. var constrain = Lib.constrain;
  65200. var constants = _dereq_('./constants');
  65201. module.exports = function linePoints(d, opts) {
  65202. var xa = opts.xaxis;
  65203. var ya = opts.yaxis;
  65204. var xLog = xa.type === 'log';
  65205. var yLog = ya.type === 'log';
  65206. var xLen = xa._length;
  65207. var yLen = ya._length;
  65208. var connectGaps = opts.connectGaps;
  65209. var baseTolerance = opts.baseTolerance;
  65210. var shape = opts.shape;
  65211. var linear = shape === 'linear';
  65212. var segments = [];
  65213. var minTolerance = constants.minTolerance;
  65214. var pts = new Array(d.length);
  65215. var pti = 0;
  65216. var i;
  65217. // pt variables are pixel coordinates [x,y] of one point
  65218. // these four are the outputs of clustering on a line
  65219. var clusterStartPt, clusterEndPt, clusterHighPt, clusterLowPt;
  65220. // "this" is the next point we're considering adding to the cluster
  65221. var thisPt;
  65222. // did we encounter the high point first, then a low point, or vice versa?
  65223. var clusterHighFirst;
  65224. // the first two points in the cluster determine its unit vector
  65225. // so the second is always in the "High" direction
  65226. var clusterUnitVector;
  65227. // the pixel delta from clusterStartPt
  65228. var thisVector;
  65229. // val variables are (signed) pixel distances along the cluster vector
  65230. var clusterRefDist, clusterHighVal, clusterLowVal, thisVal;
  65231. // deviation variables are (signed) pixel distances normal to the cluster vector
  65232. var clusterMinDeviation, clusterMaxDeviation, thisDeviation;
  65233. // turn one calcdata point into pixel coordinates
  65234. function getPt(index) {
  65235. var di = d[index];
  65236. if(!di) return false;
  65237. var x = xa.c2p(di.x);
  65238. var y = ya.c2p(di.y);
  65239. // if non-positive log values, set them VERY far off-screen
  65240. // so the line looks essentially straight from the previous point.
  65241. if(x === BADNUM) {
  65242. if(xLog) x = xa.c2p(di.x, true);
  65243. if(x === BADNUM) return false;
  65244. // If BOTH were bad log values, make the line follow a constant
  65245. // exponent rather than a constant slope
  65246. if(yLog && y === BADNUM) {
  65247. x *= Math.abs(xa._m * yLen * (xa._m > 0 ? LOG_CLIP_PLUS : LOG_CLIP_MINUS) /
  65248. (ya._m * xLen * (ya._m > 0 ? LOG_CLIP_PLUS : LOG_CLIP_MINUS)));
  65249. }
  65250. x *= 1000;
  65251. }
  65252. if(y === BADNUM) {
  65253. if(yLog) y = ya.c2p(di.y, true);
  65254. if(y === BADNUM) return false;
  65255. y *= 1000;
  65256. }
  65257. return [x, y];
  65258. }
  65259. function crossesViewport(xFrac0, yFrac0, xFrac1, yFrac1) {
  65260. var dx = xFrac1 - xFrac0;
  65261. var dy = yFrac1 - yFrac0;
  65262. var dx0 = 0.5 - xFrac0;
  65263. var dy0 = 0.5 - yFrac0;
  65264. var norm2 = dx * dx + dy * dy;
  65265. var dot = dx * dx0 + dy * dy0;
  65266. if(dot > 0 && dot < norm2) {
  65267. var cross = dx0 * dy - dy0 * dx;
  65268. if(cross * cross < norm2) return true;
  65269. }
  65270. }
  65271. var latestXFrac, latestYFrac;
  65272. // if we're off-screen, increase tolerance over baseTolerance
  65273. function getTolerance(pt, nextPt) {
  65274. var xFrac = pt[0] / xLen;
  65275. var yFrac = pt[1] / yLen;
  65276. var offScreenFraction = Math.max(0, -xFrac, xFrac - 1, -yFrac, yFrac - 1);
  65277. if(offScreenFraction && (latestXFrac !== undefined) &&
  65278. crossesViewport(xFrac, yFrac, latestXFrac, latestYFrac)
  65279. ) {
  65280. offScreenFraction = 0;
  65281. }
  65282. if(offScreenFraction && nextPt &&
  65283. crossesViewport(xFrac, yFrac, nextPt[0] / xLen, nextPt[1] / yLen)
  65284. ) {
  65285. offScreenFraction = 0;
  65286. }
  65287. return (1 + constants.toleranceGrowth * offScreenFraction) * baseTolerance;
  65288. }
  65289. function ptDist(pt1, pt2) {
  65290. var dx = pt1[0] - pt2[0];
  65291. var dy = pt1[1] - pt2[1];
  65292. return Math.sqrt(dx * dx + dy * dy);
  65293. }
  65294. // last bit of filtering: clip paths that are VERY far off-screen
  65295. // so we don't get near the browser's hard limit (+/- 2^29 px in Chrome and FF)
  65296. var maxScreensAway = constants.maxScreensAway;
  65297. // find the intersections between the segment from pt1 to pt2
  65298. // and the large rectangle maxScreensAway around the viewport
  65299. // if one of pt1 and pt2 is inside and the other outside, there
  65300. // will be only one intersection.
  65301. // if both are outside there will be 0 or 2 intersections
  65302. // (or 1 if it's right at a corner - we'll treat that like 0)
  65303. // returns an array of intersection pts
  65304. var xEdge0 = -xLen * maxScreensAway;
  65305. var xEdge1 = xLen * (1 + maxScreensAway);
  65306. var yEdge0 = -yLen * maxScreensAway;
  65307. var yEdge1 = yLen * (1 + maxScreensAway);
  65308. var edges = [
  65309. [xEdge0, yEdge0, xEdge1, yEdge0],
  65310. [xEdge1, yEdge0, xEdge1, yEdge1],
  65311. [xEdge1, yEdge1, xEdge0, yEdge1],
  65312. [xEdge0, yEdge1, xEdge0, yEdge0]
  65313. ];
  65314. var xEdge, yEdge, lastXEdge, lastYEdge, lastFarPt, edgePt;
  65315. // for linear line shape, edge intersections should be linearly interpolated
  65316. // spline uses this too, which isn't precisely correct but is actually pretty
  65317. // good, because Catmull-Rom weights far-away points less in creating the curvature
  65318. function getLinearEdgeIntersections(pt1, pt2) {
  65319. var out = [];
  65320. var ptCount = 0;
  65321. for(var i = 0; i < 4; i++) {
  65322. var edge = edges[i];
  65323. var ptInt = segmentsIntersect(pt1[0], pt1[1], pt2[0], pt2[1],
  65324. edge[0], edge[1], edge[2], edge[3]);
  65325. if(ptInt && (!ptCount ||
  65326. Math.abs(ptInt.x - out[0][0]) > 1 ||
  65327. Math.abs(ptInt.y - out[0][1]) > 1
  65328. )) {
  65329. ptInt = [ptInt.x, ptInt.y];
  65330. // if we have 2 intersections, make sure the closest one to pt1 comes first
  65331. if(ptCount && ptDist(ptInt, pt1) < ptDist(out[0], pt1)) out.unshift(ptInt);
  65332. else out.push(ptInt);
  65333. ptCount++;
  65334. }
  65335. }
  65336. return out;
  65337. }
  65338. function onlyConstrainedPoint(pt) {
  65339. if(pt[0] < xEdge0 || pt[0] > xEdge1 || pt[1] < yEdge0 || pt[1] > yEdge1) {
  65340. return [constrain(pt[0], xEdge0, xEdge1), constrain(pt[1], yEdge0, yEdge1)];
  65341. }
  65342. }
  65343. function sameEdge(pt1, pt2) {
  65344. if(pt1[0] === pt2[0] && (pt1[0] === xEdge0 || pt1[0] === xEdge1)) return true;
  65345. if(pt1[1] === pt2[1] && (pt1[1] === yEdge0 || pt1[1] === yEdge1)) return true;
  65346. }
  65347. // for line shapes hv and vh, movement in the two dimensions is decoupled,
  65348. // so all we need to do is constrain each dimension independently
  65349. function getHVEdgeIntersections(pt1, pt2) {
  65350. var out = [];
  65351. var ptInt1 = onlyConstrainedPoint(pt1);
  65352. var ptInt2 = onlyConstrainedPoint(pt2);
  65353. if(ptInt1 && ptInt2 && sameEdge(ptInt1, ptInt2)) return out;
  65354. if(ptInt1) out.push(ptInt1);
  65355. if(ptInt2) out.push(ptInt2);
  65356. return out;
  65357. }
  65358. // hvh and vhv we sometimes have to move one of the intersection points
  65359. // out BEYOND the clipping rect, by a maximum of a factor of 2, so that
  65360. // the midpoint line is drawn in the right place
  65361. function getABAEdgeIntersections(dim, limit0, limit1) {
  65362. return function(pt1, pt2) {
  65363. var ptInt1 = onlyConstrainedPoint(pt1);
  65364. var ptInt2 = onlyConstrainedPoint(pt2);
  65365. var out = [];
  65366. if(ptInt1 && ptInt2 && sameEdge(ptInt1, ptInt2)) return out;
  65367. if(ptInt1) out.push(ptInt1);
  65368. if(ptInt2) out.push(ptInt2);
  65369. var midShift = 2 * Lib.constrain((pt1[dim] + pt2[dim]) / 2, limit0, limit1) -
  65370. ((ptInt1 || pt1)[dim] + (ptInt2 || pt2)[dim]);
  65371. if(midShift) {
  65372. var ptToAlter;
  65373. if(ptInt1 && ptInt2) {
  65374. ptToAlter = (midShift > 0 === ptInt1[dim] > ptInt2[dim]) ? ptInt1 : ptInt2;
  65375. }
  65376. else ptToAlter = ptInt1 || ptInt2;
  65377. ptToAlter[dim] += midShift;
  65378. }
  65379. return out;
  65380. };
  65381. }
  65382. var getEdgeIntersections;
  65383. if(shape === 'linear' || shape === 'spline') {
  65384. getEdgeIntersections = getLinearEdgeIntersections;
  65385. }
  65386. else if(shape === 'hv' || shape === 'vh') {
  65387. getEdgeIntersections = getHVEdgeIntersections;
  65388. }
  65389. else if(shape === 'hvh') getEdgeIntersections = getABAEdgeIntersections(0, xEdge0, xEdge1);
  65390. else if(shape === 'vhv') getEdgeIntersections = getABAEdgeIntersections(1, yEdge0, yEdge1);
  65391. // a segment pt1->pt2 entirely outside the nearby region:
  65392. // find the corner it gets closest to touching
  65393. function getClosestCorner(pt1, pt2) {
  65394. var dx = pt2[0] - pt1[0];
  65395. var m = (pt2[1] - pt1[1]) / dx;
  65396. var b = (pt1[1] * pt2[0] - pt2[1] * pt1[0]) / dx;
  65397. if(b > 0) return [m > 0 ? xEdge0 : xEdge1, yEdge1];
  65398. else return [m > 0 ? xEdge1 : xEdge0, yEdge0];
  65399. }
  65400. function updateEdge(pt) {
  65401. var x = pt[0];
  65402. var y = pt[1];
  65403. var xSame = x === pts[pti - 1][0];
  65404. var ySame = y === pts[pti - 1][1];
  65405. // duplicate point?
  65406. if(xSame && ySame) return;
  65407. if(pti > 1) {
  65408. // backtracking along an edge?
  65409. var xSame2 = x === pts[pti - 2][0];
  65410. var ySame2 = y === pts[pti - 2][1];
  65411. if(xSame && (x === xEdge0 || x === xEdge1) && xSame2) {
  65412. if(ySame2) pti--; // backtracking exactly - drop prev pt and don't add
  65413. else pts[pti - 1] = pt; // not exact: replace the prev pt
  65414. }
  65415. else if(ySame && (y === yEdge0 || y === yEdge1) && ySame2) {
  65416. if(xSame2) pti--;
  65417. else pts[pti - 1] = pt;
  65418. }
  65419. else pts[pti++] = pt;
  65420. }
  65421. else pts[pti++] = pt;
  65422. }
  65423. function updateEdgesForReentry(pt) {
  65424. // if we're outside the nearby region and going back in,
  65425. // we may need to loop around a corner point
  65426. if(pts[pti - 1][0] !== pt[0] && pts[pti - 1][1] !== pt[1]) {
  65427. updateEdge([lastXEdge, lastYEdge]);
  65428. }
  65429. updateEdge(pt);
  65430. lastFarPt = null;
  65431. lastXEdge = lastYEdge = 0;
  65432. }
  65433. function addPt(pt) {
  65434. latestXFrac = pt[0] / xLen;
  65435. latestYFrac = pt[1] / yLen;
  65436. // Are we more than maxScreensAway off-screen any direction?
  65437. // if so, clip to this box, but in such a way that on-screen
  65438. // drawing is unchanged
  65439. xEdge = (pt[0] < xEdge0) ? xEdge0 : (pt[0] > xEdge1) ? xEdge1 : 0;
  65440. yEdge = (pt[1] < yEdge0) ? yEdge0 : (pt[1] > yEdge1) ? yEdge1 : 0;
  65441. if(xEdge || yEdge) {
  65442. // to get fills right - if first point is far, push it toward the
  65443. // screen in whichever direction(s) are far
  65444. if(!pti) {
  65445. pts[pti++] = [xEdge || pt[0], yEdge || pt[1]];
  65446. }
  65447. else if(lastFarPt) {
  65448. // both this point and the last are outside the nearby region
  65449. // check if we're crossing the nearby region
  65450. var intersections = getEdgeIntersections(lastFarPt, pt);
  65451. if(intersections.length > 1) {
  65452. updateEdgesForReentry(intersections[0]);
  65453. pts[pti++] = intersections[1];
  65454. }
  65455. }
  65456. // we're leaving the nearby region - add the point where we left it
  65457. else {
  65458. edgePt = getEdgeIntersections(pts[pti - 1], pt)[0];
  65459. pts[pti++] = edgePt;
  65460. }
  65461. var lastPt = pts[pti - 1];
  65462. if(xEdge && yEdge && (lastPt[0] !== xEdge || lastPt[1] !== yEdge)) {
  65463. // we've gone out beyond a new corner: add the corner too
  65464. // so that the next point will take the right winding
  65465. if(lastFarPt) {
  65466. if(lastXEdge !== xEdge && lastYEdge !== yEdge) {
  65467. if(lastXEdge && lastYEdge) {
  65468. // we've gone around to an opposite corner - we
  65469. // need to add the correct extra corner
  65470. // in order to get the right winding
  65471. updateEdge(getClosestCorner(lastFarPt, pt));
  65472. }
  65473. else {
  65474. // we're coming from a far edge - the extra corner
  65475. // we need is determined uniquely by the sectors
  65476. updateEdge([lastXEdge || xEdge, lastYEdge || yEdge]);
  65477. }
  65478. }
  65479. else if(lastXEdge && lastYEdge) {
  65480. updateEdge([lastXEdge, lastYEdge]);
  65481. }
  65482. }
  65483. updateEdge([xEdge, yEdge]);
  65484. }
  65485. else if((lastXEdge - xEdge) && (lastYEdge - yEdge)) {
  65486. // we're coming from an edge or far corner to an edge - again the
  65487. // extra corner we need is uniquely determined by the sectors
  65488. updateEdge([xEdge || lastXEdge, yEdge || lastYEdge]);
  65489. }
  65490. lastFarPt = pt;
  65491. lastXEdge = xEdge;
  65492. lastYEdge = yEdge;
  65493. }
  65494. else {
  65495. if(lastFarPt) {
  65496. // this point is in range but the previous wasn't: add its entry pt first
  65497. updateEdgesForReentry(getEdgeIntersections(lastFarPt, pt)[0]);
  65498. }
  65499. pts[pti++] = pt;
  65500. }
  65501. }
  65502. // loop over ALL points in this trace
  65503. for(i = 0; i < d.length; i++) {
  65504. clusterStartPt = getPt(i);
  65505. if(!clusterStartPt) continue;
  65506. pti = 0;
  65507. lastFarPt = null;
  65508. addPt(clusterStartPt);
  65509. // loop over one segment of the trace
  65510. for(i++; i < d.length; i++) {
  65511. clusterHighPt = getPt(i);
  65512. if(!clusterHighPt) {
  65513. if(connectGaps) continue;
  65514. else break;
  65515. }
  65516. // can't decimate if nonlinear line shape
  65517. // TODO: we *could* decimate [hv]{2,3} shapes if we restricted clusters to horz or vert again
  65518. // but spline would be verrry awkward to decimate
  65519. if(!linear || !opts.simplify) {
  65520. addPt(clusterHighPt);
  65521. continue;
  65522. }
  65523. var nextPt = getPt(i + 1);
  65524. clusterRefDist = ptDist(clusterHighPt, clusterStartPt);
  65525. if(clusterRefDist < getTolerance(clusterHighPt, nextPt) * minTolerance) continue;
  65526. clusterUnitVector = [
  65527. (clusterHighPt[0] - clusterStartPt[0]) / clusterRefDist,
  65528. (clusterHighPt[1] - clusterStartPt[1]) / clusterRefDist
  65529. ];
  65530. clusterLowPt = clusterStartPt;
  65531. clusterHighVal = clusterRefDist;
  65532. clusterLowVal = clusterMinDeviation = clusterMaxDeviation = 0;
  65533. clusterHighFirst = false;
  65534. clusterEndPt = clusterHighPt;
  65535. // loop over one cluster of points that collapse onto one line
  65536. for(i++; i < d.length; i++) {
  65537. thisPt = nextPt;
  65538. nextPt = getPt(i + 1);
  65539. if(!thisPt) {
  65540. if(connectGaps) continue;
  65541. else break;
  65542. }
  65543. thisVector = [
  65544. thisPt[0] - clusterStartPt[0],
  65545. thisPt[1] - clusterStartPt[1]
  65546. ];
  65547. // cross product (or dot with normal to the cluster vector)
  65548. thisDeviation = thisVector[0] * clusterUnitVector[1] - thisVector[1] * clusterUnitVector[0];
  65549. clusterMinDeviation = Math.min(clusterMinDeviation, thisDeviation);
  65550. clusterMaxDeviation = Math.max(clusterMaxDeviation, thisDeviation);
  65551. if(clusterMaxDeviation - clusterMinDeviation > getTolerance(thisPt, nextPt)) break;
  65552. clusterEndPt = thisPt;
  65553. thisVal = thisVector[0] * clusterUnitVector[0] + thisVector[1] * clusterUnitVector[1];
  65554. if(thisVal > clusterHighVal) {
  65555. clusterHighVal = thisVal;
  65556. clusterHighPt = thisPt;
  65557. clusterHighFirst = false;
  65558. } else if(thisVal < clusterLowVal) {
  65559. clusterLowVal = thisVal;
  65560. clusterLowPt = thisPt;
  65561. clusterHighFirst = true;
  65562. }
  65563. }
  65564. // insert this cluster into pts
  65565. // we've already inserted the start pt, now check if we have high and low pts
  65566. if(clusterHighFirst) {
  65567. addPt(clusterHighPt);
  65568. if(clusterEndPt !== clusterLowPt) addPt(clusterLowPt);
  65569. } else {
  65570. if(clusterLowPt !== clusterStartPt) addPt(clusterLowPt);
  65571. if(clusterEndPt !== clusterHighPt) addPt(clusterHighPt);
  65572. }
  65573. // and finally insert the end pt
  65574. addPt(clusterEndPt);
  65575. // have we reached the end of this segment?
  65576. if(i >= d.length || !thisPt) break;
  65577. // otherwise we have an out-of-cluster point to insert as next clusterStartPt
  65578. addPt(thisPt);
  65579. clusterStartPt = thisPt;
  65580. }
  65581. // to get fills right - repeat what we did at the start
  65582. if(lastFarPt) updateEdge([lastXEdge || lastFarPt[0], lastYEdge || lastFarPt[1]]);
  65583. segments.push(pts.slice(0, pti));
  65584. }
  65585. return segments;
  65586. };
  65587. },{"../../constants/numerical":151,"../../lib":169,"./constants":371}],381:[function(_dereq_,module,exports){
  65588. /**
  65589. * Copyright 2012-2018, Plotly, Inc.
  65590. * All rights reserved.
  65591. *
  65592. * This source code is licensed under the MIT license found in the
  65593. * LICENSE file in the root directory of this source tree.
  65594. */
  65595. 'use strict';
  65596. // common to 'scatter' and 'scatterternary'
  65597. module.exports = function handleLineShapeDefaults(traceIn, traceOut, coerce) {
  65598. var shape = coerce('line.shape');
  65599. if(shape === 'spline') coerce('line.smoothing');
  65600. };
  65601. },{}],382:[function(_dereq_,module,exports){
  65602. /**
  65603. * Copyright 2012-2018, Plotly, Inc.
  65604. * All rights reserved.
  65605. *
  65606. * This source code is licensed under the MIT license found in the
  65607. * LICENSE file in the root directory of this source tree.
  65608. */
  65609. 'use strict';
  65610. var LINKEDFILLS = {tonextx: 1, tonexty: 1, tonext: 1};
  65611. module.exports = function linkTraces(gd, plotinfo, cdscatter) {
  65612. var trace, i, group, prevtrace, groupIndex;
  65613. // first sort traces to keep stacks & filled-together groups together
  65614. var groupIndices = {};
  65615. var needsSort = false;
  65616. var prevGroupIndex = -1;
  65617. var nextGroupIndex = 0;
  65618. var prevUnstackedGroupIndex = -1;
  65619. for(i = 0; i < cdscatter.length; i++) {
  65620. trace = cdscatter[i][0].trace;
  65621. group = trace.stackgroup || '';
  65622. if(group) {
  65623. if(group in groupIndices) {
  65624. groupIndex = groupIndices[group];
  65625. }
  65626. else {
  65627. groupIndex = groupIndices[group] = nextGroupIndex;
  65628. nextGroupIndex++;
  65629. }
  65630. }
  65631. else if(trace.fill in LINKEDFILLS && prevUnstackedGroupIndex >= 0) {
  65632. groupIndex = prevUnstackedGroupIndex;
  65633. }
  65634. else {
  65635. groupIndex = prevUnstackedGroupIndex = nextGroupIndex;
  65636. nextGroupIndex++;
  65637. }
  65638. if(groupIndex < prevGroupIndex) needsSort = true;
  65639. trace._groupIndex = prevGroupIndex = groupIndex;
  65640. }
  65641. var cdscatterSorted = cdscatter.slice();
  65642. if(needsSort) {
  65643. cdscatterSorted.sort(function(a, b) {
  65644. var traceA = a[0].trace;
  65645. var traceB = b[0].trace;
  65646. return (traceA._groupIndex - traceB._groupIndex) ||
  65647. (traceA.index - traceB.index);
  65648. });
  65649. }
  65650. // now link traces to each other
  65651. var prevtraces = {};
  65652. for(i = 0; i < cdscatterSorted.length; i++) {
  65653. trace = cdscatterSorted[i][0].trace;
  65654. group = trace.stackgroup || '';
  65655. // Note: The check which ensures all cdscatter here are for the same axis and
  65656. // are either cartesian or scatterternary has been removed. This code assumes
  65657. // the passed scattertraces have been filtered to the proper plot types and
  65658. // the proper subplots.
  65659. if(trace.visible === true) {
  65660. trace._nexttrace = null;
  65661. if(trace.fill in LINKEDFILLS) {
  65662. prevtrace = prevtraces[group];
  65663. trace._prevtrace = prevtrace || null;
  65664. if(prevtrace) {
  65665. prevtrace._nexttrace = trace;
  65666. }
  65667. }
  65668. prevtraces[group] = trace;
  65669. } else {
  65670. trace._prevtrace = trace._nexttrace = null;
  65671. }
  65672. }
  65673. return cdscatterSorted;
  65674. };
  65675. },{}],383:[function(_dereq_,module,exports){
  65676. /**
  65677. * Copyright 2012-2018, Plotly, Inc.
  65678. * All rights reserved.
  65679. *
  65680. * This source code is licensed under the MIT license found in the
  65681. * LICENSE file in the root directory of this source tree.
  65682. */
  65683. 'use strict';
  65684. var isNumeric = _dereq_('fast-isnumeric');
  65685. // used in the drawing step for 'scatter' and 'scattegeo' and
  65686. // in the convert step for 'scatter3d'
  65687. module.exports = function makeBubbleSizeFn(trace) {
  65688. var marker = trace.marker,
  65689. sizeRef = marker.sizeref || 1,
  65690. sizeMin = marker.sizemin || 0;
  65691. // for bubble charts, allow scaling the provided value linearly
  65692. // and by area or diameter.
  65693. // Note this only applies to the array-value sizes
  65694. var baseFn = (marker.sizemode === 'area') ?
  65695. function(v) { return Math.sqrt(v / sizeRef); } :
  65696. function(v) { return v / sizeRef; };
  65697. // TODO add support for position/negative bubbles?
  65698. // TODO add 'sizeoffset' attribute?
  65699. return function(v) {
  65700. var baseSize = baseFn(v / 2);
  65701. // don't show non-numeric and negative sizes
  65702. return (isNumeric(baseSize) && (baseSize > 0)) ?
  65703. Math.max(baseSize, sizeMin) :
  65704. 0;
  65705. };
  65706. };
  65707. },{"fast-isnumeric":18}],384:[function(_dereq_,module,exports){
  65708. /**
  65709. * Copyright 2012-2018, Plotly, Inc.
  65710. * All rights reserved.
  65711. *
  65712. * This source code is licensed under the MIT license found in the
  65713. * LICENSE file in the root directory of this source tree.
  65714. */
  65715. 'use strict';
  65716. module.exports = {
  65717. container: 'marker',
  65718. min: 'cmin',
  65719. max: 'cmax'
  65720. };
  65721. },{}],385:[function(_dereq_,module,exports){
  65722. /**
  65723. * Copyright 2012-2018, Plotly, Inc.
  65724. * All rights reserved.
  65725. *
  65726. * This source code is licensed under the MIT license found in the
  65727. * LICENSE file in the root directory of this source tree.
  65728. */
  65729. 'use strict';
  65730. var Color = _dereq_('../../components/color');
  65731. var hasColorscale = _dereq_('../../components/colorscale/has_colorscale');
  65732. var colorscaleDefaults = _dereq_('../../components/colorscale/defaults');
  65733. var subTypes = _dereq_('./subtypes');
  65734. /*
  65735. * opts: object of flags to control features not all marker users support
  65736. * noLine: caller does not support marker lines
  65737. * gradient: caller supports gradients
  65738. * noSelect: caller does not support selected/unselected attribute containers
  65739. */
  65740. module.exports = function markerDefaults(traceIn, traceOut, defaultColor, layout, coerce, opts) {
  65741. var isBubble = subTypes.isBubble(traceIn),
  65742. lineColor = (traceIn.line || {}).color,
  65743. defaultMLC;
  65744. opts = opts || {};
  65745. // marker.color inherit from line.color (even if line.color is an array)
  65746. if(lineColor) defaultColor = lineColor;
  65747. coerce('marker.symbol');
  65748. coerce('marker.opacity', isBubble ? 0.7 : 1);
  65749. coerce('marker.size');
  65750. coerce('marker.color', defaultColor);
  65751. if(hasColorscale(traceIn, 'marker')) {
  65752. colorscaleDefaults(traceIn, traceOut, layout, coerce, {prefix: 'marker.', cLetter: 'c'});
  65753. }
  65754. if(!opts.noSelect) {
  65755. coerce('selected.marker.color');
  65756. coerce('unselected.marker.color');
  65757. coerce('selected.marker.size');
  65758. coerce('unselected.marker.size');
  65759. }
  65760. if(!opts.noLine) {
  65761. // if there's a line with a different color than the marker, use
  65762. // that line color as the default marker line color
  65763. // (except when it's an array)
  65764. // mostly this is for transparent markers to behave nicely
  65765. if(lineColor && !Array.isArray(lineColor) && (traceOut.marker.color !== lineColor)) {
  65766. defaultMLC = lineColor;
  65767. }
  65768. else if(isBubble) defaultMLC = Color.background;
  65769. else defaultMLC = Color.defaultLine;
  65770. coerce('marker.line.color', defaultMLC);
  65771. if(hasColorscale(traceIn, 'marker.line')) {
  65772. colorscaleDefaults(traceIn, traceOut, layout, coerce, {prefix: 'marker.line.', cLetter: 'c'});
  65773. }
  65774. coerce('marker.line.width', isBubble ? 1 : 0);
  65775. }
  65776. if(isBubble) {
  65777. coerce('marker.sizeref');
  65778. coerce('marker.sizemin');
  65779. coerce('marker.sizemode');
  65780. }
  65781. if(opts.gradient) {
  65782. var gradientType = coerce('marker.gradient.type');
  65783. if(gradientType !== 'none') {
  65784. coerce('marker.gradient.color');
  65785. }
  65786. }
  65787. };
  65788. },{"../../components/color":50,"../../components/colorscale/defaults":60,"../../components/colorscale/has_colorscale":64,"./subtypes":390}],386:[function(_dereq_,module,exports){
  65789. /**
  65790. * Copyright 2012-2018, Plotly, Inc.
  65791. * All rights reserved.
  65792. *
  65793. * This source code is licensed under the MIT license found in the
  65794. * LICENSE file in the root directory of this source tree.
  65795. */
  65796. 'use strict';
  65797. var d3 = _dereq_('d3');
  65798. var Registry = _dereq_('../../registry');
  65799. var Lib = _dereq_('../../lib');
  65800. var ensureSingle = Lib.ensureSingle;
  65801. var identity = Lib.identity;
  65802. var Drawing = _dereq_('../../components/drawing');
  65803. var subTypes = _dereq_('./subtypes');
  65804. var linePoints = _dereq_('./line_points');
  65805. var linkTraces = _dereq_('./link_traces');
  65806. var polygonTester = _dereq_('../../lib/polygon').tester;
  65807. module.exports = function plot(gd, plotinfo, cdscatter, scatterLayer, transitionOpts, makeOnCompleteCallback) {
  65808. var join, onComplete;
  65809. // If transition config is provided, then it is only a partial replot and traces not
  65810. // updated are removed.
  65811. var isFullReplot = !transitionOpts;
  65812. var hasTransition = !!transitionOpts && transitionOpts.duration > 0;
  65813. // Link traces so the z-order of fill layers is correct
  65814. var cdscatterSorted = linkTraces(gd, plotinfo, cdscatter);
  65815. join = scatterLayer.selectAll('g.trace')
  65816. .data(cdscatterSorted, function(d) { return d[0].trace.uid; });
  65817. // Append new traces:
  65818. join.enter().append('g')
  65819. .attr('class', function(d) {
  65820. return 'trace scatter trace' + d[0].trace.uid;
  65821. })
  65822. .style('stroke-miterlimit', 2);
  65823. join.order();
  65824. createFills(gd, join, plotinfo);
  65825. if(hasTransition) {
  65826. if(makeOnCompleteCallback) {
  65827. // If it was passed a callback to register completion, make a callback. If
  65828. // this is created, then it must be executed on completion, otherwise the
  65829. // pos-transition redraw will not execute:
  65830. onComplete = makeOnCompleteCallback();
  65831. }
  65832. var transition = d3.transition()
  65833. .duration(transitionOpts.duration)
  65834. .ease(transitionOpts.easing)
  65835. .each('end', function() {
  65836. onComplete && onComplete();
  65837. })
  65838. .each('interrupt', function() {
  65839. onComplete && onComplete();
  65840. });
  65841. transition.each(function() {
  65842. // Must run the selection again since otherwise enters/updates get grouped together
  65843. // and these get executed out of order. Except we need them in order!
  65844. scatterLayer.selectAll('g.trace').each(function(d, i) {
  65845. plotOne(gd, i, plotinfo, d, cdscatterSorted, this, transitionOpts);
  65846. });
  65847. });
  65848. } else {
  65849. join.each(function(d, i) {
  65850. plotOne(gd, i, plotinfo, d, cdscatterSorted, this, transitionOpts);
  65851. });
  65852. }
  65853. if(isFullReplot) {
  65854. join.exit().remove();
  65855. }
  65856. // remove paths that didn't get used
  65857. scatterLayer.selectAll('path:not([d])').remove();
  65858. };
  65859. function createFills(gd, traceJoin, plotinfo) {
  65860. traceJoin.each(function(d) {
  65861. var fills = ensureSingle(d3.select(this), 'g', 'fills');
  65862. Drawing.setClipUrl(fills, plotinfo.layerClipId);
  65863. var trace = d[0].trace;
  65864. var fillData = [];
  65865. if(trace.fill && (trace.fill.substr(0, 6) === 'tozero' || trace.fill === 'toself' ||
  65866. (trace.fill.substr(0, 2) === 'to' && !trace._prevtrace))
  65867. ) {
  65868. fillData = ['_ownFill'];
  65869. }
  65870. if(trace._nexttrace) {
  65871. // make the fill-to-next path now for the NEXT trace, so it shows
  65872. // behind both lines.
  65873. fillData.push('_nextFill');
  65874. }
  65875. var fillJoin = fills.selectAll('g')
  65876. .data(fillData, identity);
  65877. fillJoin.enter().append('g');
  65878. fillJoin.exit()
  65879. .each(function(d) { trace[d] = null; })
  65880. .remove();
  65881. fillJoin.order().each(function(d) {
  65882. // make a path element inside the fill group, just so
  65883. // we can give it its own data later on and the group can
  65884. // keep its simple '_*Fill' data
  65885. trace[d] = ensureSingle(d3.select(this), 'path', 'js-fill');
  65886. });
  65887. });
  65888. }
  65889. function plotOne(gd, idx, plotinfo, cdscatter, cdscatterAll, element, transitionOpts) {
  65890. var i;
  65891. // Since this has been reorganized and we're executing this on individual traces,
  65892. // we need to pass it the full list of cdscatter as well as this trace's index (idx)
  65893. // since it does an internal n^2 loop over comparisons with other traces:
  65894. selectMarkers(gd, idx, plotinfo, cdscatter, cdscatterAll);
  65895. var hasTransition = !!transitionOpts && transitionOpts.duration > 0;
  65896. function transition(selection) {
  65897. return hasTransition ? selection.transition() : selection;
  65898. }
  65899. var xa = plotinfo.xaxis,
  65900. ya = plotinfo.yaxis;
  65901. var trace = cdscatter[0].trace;
  65902. var line = trace.line;
  65903. var tr = d3.select(element);
  65904. var errorBarGroup = ensureSingle(tr, 'g', 'errorbars');
  65905. var lines = ensureSingle(tr, 'g', 'lines');
  65906. var points = ensureSingle(tr, 'g', 'points');
  65907. var text = ensureSingle(tr, 'g', 'text');
  65908. // error bars are at the bottom
  65909. Registry.getComponentMethod('errorbars', 'plot')(errorBarGroup, plotinfo, transitionOpts);
  65910. if(trace.visible !== true) return;
  65911. transition(tr).style('opacity', trace.opacity);
  65912. // BUILD LINES AND FILLS
  65913. var ownFillEl3, tonext;
  65914. var ownFillDir = trace.fill.charAt(trace.fill.length - 1);
  65915. if(ownFillDir !== 'x' && ownFillDir !== 'y') ownFillDir = '';
  65916. // store node for tweaking by selectPoints
  65917. if(!plotinfo.isRangePlot) cdscatter[0].node3 = tr;
  65918. var prevRevpath = '';
  65919. var prevPolygons = [];
  65920. var prevtrace = trace._prevtrace;
  65921. if(prevtrace) {
  65922. prevRevpath = prevtrace._prevRevpath || '';
  65923. tonext = prevtrace._nextFill;
  65924. prevPolygons = prevtrace._polygons;
  65925. }
  65926. var thispath,
  65927. thisrevpath,
  65928. // fullpath is all paths for this curve, joined together straight
  65929. // across gaps, for filling
  65930. fullpath = '',
  65931. // revpath is fullpath reversed, for fill-to-next
  65932. revpath = '',
  65933. // functions for converting a point array to a path
  65934. pathfn, revpathbase, revpathfn,
  65935. // variables used before and after the data join
  65936. pt0, lastSegment, pt1, thisPolygons;
  65937. // initialize line join data / method
  65938. var segments = [],
  65939. makeUpdate = Lib.noop;
  65940. ownFillEl3 = trace._ownFill;
  65941. if(subTypes.hasLines(trace) || trace.fill !== 'none') {
  65942. if(tonext) {
  65943. // This tells .style which trace to use for fill information:
  65944. tonext.datum(cdscatter);
  65945. }
  65946. if(['hv', 'vh', 'hvh', 'vhv'].indexOf(line.shape) !== -1) {
  65947. pathfn = Drawing.steps(line.shape);
  65948. revpathbase = Drawing.steps(
  65949. line.shape.split('').reverse().join('')
  65950. );
  65951. }
  65952. else if(line.shape === 'spline') {
  65953. pathfn = revpathbase = function(pts) {
  65954. var pLast = pts[pts.length - 1];
  65955. if(pts.length > 1 && pts[0][0] === pLast[0] && pts[0][1] === pLast[1]) {
  65956. // identical start and end points: treat it as a
  65957. // closed curve so we don't get a kink
  65958. return Drawing.smoothclosed(pts.slice(1), line.smoothing);
  65959. }
  65960. else {
  65961. return Drawing.smoothopen(pts, line.smoothing);
  65962. }
  65963. };
  65964. }
  65965. else {
  65966. pathfn = revpathbase = function(pts) {
  65967. return 'M' + pts.join('L');
  65968. };
  65969. }
  65970. revpathfn = function(pts) {
  65971. // note: this is destructive (reverses pts in place) so can't use pts after this
  65972. return revpathbase(pts.reverse());
  65973. };
  65974. segments = linePoints(cdscatter, {
  65975. xaxis: xa,
  65976. yaxis: ya,
  65977. connectGaps: trace.connectgaps,
  65978. baseTolerance: Math.max(line.width || 1, 3) / 4,
  65979. shape: line.shape,
  65980. simplify: line.simplify
  65981. });
  65982. // since we already have the pixel segments here, use them to make
  65983. // polygons for hover on fill
  65984. // TODO: can we skip this if hoveron!=fills? That would mean we
  65985. // need to redraw when you change hoveron...
  65986. thisPolygons = trace._polygons = new Array(segments.length);
  65987. for(i = 0; i < segments.length; i++) {
  65988. trace._polygons[i] = polygonTester(segments[i]);
  65989. }
  65990. if(segments.length) {
  65991. pt0 = segments[0][0];
  65992. lastSegment = segments[segments.length - 1];
  65993. pt1 = lastSegment[lastSegment.length - 1];
  65994. }
  65995. makeUpdate = function(isEnter) {
  65996. return function(pts) {
  65997. thispath = pathfn(pts);
  65998. thisrevpath = revpathfn(pts);
  65999. if(!fullpath) {
  66000. fullpath = thispath;
  66001. revpath = thisrevpath;
  66002. }
  66003. else if(ownFillDir) {
  66004. fullpath += 'L' + thispath.substr(1);
  66005. revpath = thisrevpath + ('L' + revpath.substr(1));
  66006. }
  66007. else {
  66008. fullpath += 'Z' + thispath;
  66009. revpath = thisrevpath + 'Z' + revpath;
  66010. }
  66011. if(subTypes.hasLines(trace) && pts.length > 1) {
  66012. var el = d3.select(this);
  66013. // This makes the coloring work correctly:
  66014. el.datum(cdscatter);
  66015. if(isEnter) {
  66016. transition(el.style('opacity', 0)
  66017. .attr('d', thispath)
  66018. .call(Drawing.lineGroupStyle))
  66019. .style('opacity', 1);
  66020. } else {
  66021. var sel = transition(el);
  66022. sel.attr('d', thispath);
  66023. Drawing.singleLineStyle(cdscatter, sel);
  66024. }
  66025. }
  66026. };
  66027. };
  66028. }
  66029. var lineJoin = lines.selectAll('.js-line').data(segments);
  66030. transition(lineJoin.exit())
  66031. .style('opacity', 0)
  66032. .remove();
  66033. lineJoin.each(makeUpdate(false));
  66034. lineJoin.enter().append('path')
  66035. .classed('js-line', true)
  66036. .style('vector-effect', 'non-scaling-stroke')
  66037. .call(Drawing.lineGroupStyle)
  66038. .each(makeUpdate(true));
  66039. Drawing.setClipUrl(lineJoin, plotinfo.layerClipId);
  66040. function clearFill(selection) {
  66041. transition(selection).attr('d', 'M0,0Z');
  66042. }
  66043. if(segments.length) {
  66044. if(ownFillEl3) {
  66045. ownFillEl3.datum(cdscatter);
  66046. if(pt0 && pt1) {
  66047. if(ownFillDir) {
  66048. if(ownFillDir === 'y') {
  66049. pt0[1] = pt1[1] = ya.c2p(0, true);
  66050. }
  66051. else if(ownFillDir === 'x') {
  66052. pt0[0] = pt1[0] = xa.c2p(0, true);
  66053. }
  66054. // fill to zero: full trace path, plus extension of
  66055. // the endpoints to the appropriate axis
  66056. // For the sake of animations, wrap the points around so that
  66057. // the points on the axes are the first two points. Otherwise
  66058. // animations get a little crazy if the number of points changes.
  66059. transition(ownFillEl3).attr('d', 'M' + pt1 + 'L' + pt0 + 'L' + fullpath.substr(1))
  66060. .call(Drawing.singleFillStyle);
  66061. } else {
  66062. // fill to self: just join the path to itself
  66063. transition(ownFillEl3).attr('d', fullpath + 'Z')
  66064. .call(Drawing.singleFillStyle);
  66065. }
  66066. }
  66067. }
  66068. else if(tonext) {
  66069. if(trace.fill.substr(0, 6) === 'tonext' && fullpath && prevRevpath) {
  66070. // fill to next: full trace path, plus the previous path reversed
  66071. if(trace.fill === 'tonext') {
  66072. // tonext: for use by concentric shapes, like manually constructed
  66073. // contours, we just add the two paths closed on themselves.
  66074. // This makes strange results if one path is *not* entirely
  66075. // inside the other, but then that is a strange usage.
  66076. transition(tonext).attr('d', fullpath + 'Z' + prevRevpath + 'Z')
  66077. .call(Drawing.singleFillStyle);
  66078. }
  66079. else {
  66080. // tonextx/y: for now just connect endpoints with lines. This is
  66081. // the correct behavior if the endpoints are at the same value of
  66082. // y/x, but if they *aren't*, we should ideally do more complicated
  66083. // things depending on whether the new endpoint projects onto the
  66084. // existing curve or off the end of it
  66085. transition(tonext).attr('d', fullpath + 'L' + prevRevpath.substr(1) + 'Z')
  66086. .call(Drawing.singleFillStyle);
  66087. }
  66088. trace._polygons = trace._polygons.concat(prevPolygons);
  66089. }
  66090. else {
  66091. clearFill(tonext);
  66092. trace._polygons = null;
  66093. }
  66094. }
  66095. trace._prevRevpath = revpath;
  66096. trace._prevPolygons = thisPolygons;
  66097. }
  66098. else {
  66099. if(ownFillEl3) clearFill(ownFillEl3);
  66100. else if(tonext) clearFill(tonext);
  66101. trace._polygons = trace._prevRevpath = trace._prevPolygons = null;
  66102. }
  66103. function visFilter(d) {
  66104. return d.filter(function(v) { return !v.gap && v.vis; });
  66105. }
  66106. function visFilterWithGaps(d) {
  66107. return d.filter(function(v) { return v.vis; });
  66108. }
  66109. function gapFilter(d) {
  66110. return d.filter(function(v) { return !v.gap; });
  66111. }
  66112. function keyFunc(d) {
  66113. return d.id;
  66114. }
  66115. // Returns a function if the trace is keyed, otherwise returns undefined
  66116. function getKeyFunc(trace) {
  66117. if(trace.ids) {
  66118. return keyFunc;
  66119. }
  66120. }
  66121. function hideFilter() {
  66122. return false;
  66123. }
  66124. function makePoints(points, text, cdscatter) {
  66125. var join, selection, hasNode;
  66126. var trace = cdscatter[0].trace;
  66127. var showMarkers = subTypes.hasMarkers(trace);
  66128. var showText = subTypes.hasText(trace);
  66129. var keyFunc = getKeyFunc(trace);
  66130. var markerFilter = hideFilter;
  66131. var textFilter = hideFilter;
  66132. if(showMarkers || showText) {
  66133. var showFilter = identity;
  66134. // if we're stacking, "infer zero" gap mode gets markers in the
  66135. // gap points - because we've inferred a zero there - but other
  66136. // modes (currently "interpolate", later "interrupt" hopefully)
  66137. // we don't draw generated markers
  66138. var stackGroup = trace.stackgroup;
  66139. var isInferZero = stackGroup && (
  66140. gd._fullLayout._scatterStackOpts[xa._id + ya._id][stackGroup].stackgaps === 'infer zero');
  66141. if(trace.marker.maxdisplayed || trace._needsCull) {
  66142. showFilter = isInferZero ? visFilterWithGaps : visFilter;
  66143. }
  66144. else if(stackGroup && !isInferZero) {
  66145. showFilter = gapFilter;
  66146. }
  66147. if(showMarkers) markerFilter = showFilter;
  66148. if(showText) textFilter = showFilter;
  66149. }
  66150. // marker points
  66151. selection = points.selectAll('path.point');
  66152. join = selection.data(markerFilter, keyFunc);
  66153. var enter = join.enter().append('path')
  66154. .classed('point', true);
  66155. if(hasTransition) {
  66156. enter
  66157. .call(Drawing.pointStyle, trace, gd)
  66158. .call(Drawing.translatePoints, xa, ya)
  66159. .style('opacity', 0)
  66160. .transition()
  66161. .style('opacity', 1);
  66162. }
  66163. join.order();
  66164. var styleFns;
  66165. if(showMarkers) {
  66166. styleFns = Drawing.makePointStyleFns(trace);
  66167. }
  66168. join.each(function(d) {
  66169. var el = d3.select(this);
  66170. var sel = transition(el);
  66171. hasNode = Drawing.translatePoint(d, sel, xa, ya);
  66172. if(hasNode) {
  66173. Drawing.singlePointStyle(d, sel, trace, styleFns, gd);
  66174. if(plotinfo.layerClipId) {
  66175. Drawing.hideOutsideRangePoint(d, sel, xa, ya, trace.xcalendar, trace.ycalendar);
  66176. }
  66177. if(trace.customdata) {
  66178. el.classed('plotly-customdata', d.data !== null && d.data !== undefined);
  66179. }
  66180. } else {
  66181. sel.remove();
  66182. }
  66183. });
  66184. if(hasTransition) {
  66185. join.exit().transition()
  66186. .style('opacity', 0)
  66187. .remove();
  66188. } else {
  66189. join.exit().remove();
  66190. }
  66191. // text points
  66192. selection = text.selectAll('g');
  66193. join = selection.data(textFilter, keyFunc);
  66194. // each text needs to go in its own 'g' in case
  66195. // it gets converted to mathjax
  66196. join.enter().append('g').classed('textpoint', true).append('text');
  66197. join.order();
  66198. join.each(function(d) {
  66199. var g = d3.select(this);
  66200. var sel = transition(g.select('text'));
  66201. hasNode = Drawing.translatePoint(d, sel, xa, ya);
  66202. if(hasNode) {
  66203. if(plotinfo.layerClipId) {
  66204. Drawing.hideOutsideRangePoint(d, g, xa, ya, trace.xcalendar, trace.ycalendar);
  66205. }
  66206. } else {
  66207. g.remove();
  66208. }
  66209. });
  66210. join.selectAll('text')
  66211. .call(Drawing.textPointStyle, trace, gd)
  66212. .each(function(d) {
  66213. // This just *has* to be totally custom becuase of SVG text positioning :(
  66214. // It's obviously copied from translatePoint; we just can't use that
  66215. var x = xa.c2p(d.x);
  66216. var y = ya.c2p(d.y);
  66217. d3.select(this).selectAll('tspan.line').each(function() {
  66218. transition(d3.select(this)).attr({x: x, y: y});
  66219. });
  66220. });
  66221. join.exit().remove();
  66222. }
  66223. points.datum(cdscatter);
  66224. text.datum(cdscatter);
  66225. makePoints(points, text, cdscatter);
  66226. // lastly, clip points groups of `cliponaxis !== false` traces
  66227. // on `plotinfo._hasClipOnAxisFalse === true` subplots
  66228. var hasClipOnAxisFalse = trace.cliponaxis === false;
  66229. var clipUrl = hasClipOnAxisFalse ? null : plotinfo.layerClipId;
  66230. Drawing.setClipUrl(points, clipUrl);
  66231. Drawing.setClipUrl(text, clipUrl);
  66232. }
  66233. function selectMarkers(gd, idx, plotinfo, cdscatter, cdscatterAll) {
  66234. var xa = plotinfo.xaxis,
  66235. ya = plotinfo.yaxis,
  66236. xr = d3.extent(Lib.simpleMap(xa.range, xa.r2c)),
  66237. yr = d3.extent(Lib.simpleMap(ya.range, ya.r2c));
  66238. var trace = cdscatter[0].trace;
  66239. if(!subTypes.hasMarkers(trace)) return;
  66240. // if marker.maxdisplayed is used, select a maximum of
  66241. // mnum markers to show, from the set that are in the viewport
  66242. var mnum = trace.marker.maxdisplayed;
  66243. // TODO: remove some as we get away from the viewport?
  66244. if(mnum === 0) return;
  66245. var cd = cdscatter.filter(function(v) {
  66246. return v.x >= xr[0] && v.x <= xr[1] && v.y >= yr[0] && v.y <= yr[1];
  66247. }),
  66248. inc = Math.ceil(cd.length / mnum),
  66249. tnum = 0;
  66250. cdscatterAll.forEach(function(cdj, j) {
  66251. var tracei = cdj[0].trace;
  66252. if(subTypes.hasMarkers(tracei) &&
  66253. tracei.marker.maxdisplayed > 0 && j < idx) {
  66254. tnum++;
  66255. }
  66256. });
  66257. // if multiple traces use maxdisplayed, stagger which markers we
  66258. // display this formula offsets successive traces by 1/3 of the
  66259. // increment, adding an extra small amount after each triplet so
  66260. // it's not quite periodic
  66261. var i0 = Math.round(tnum * inc / 3 + Math.floor(tnum / 3) * inc / 7.1);
  66262. // for error bars: save in cd which markers to show
  66263. // so we don't have to repeat this
  66264. cdscatter.forEach(function(v) { delete v.vis; });
  66265. cd.forEach(function(v, i) {
  66266. if(Math.round((i + i0) % inc) === 0) v.vis = true;
  66267. });
  66268. }
  66269. },{"../../components/drawing":75,"../../lib":169,"../../lib/polygon":182,"../../registry":259,"./line_points":380,"./link_traces":382,"./subtypes":390,"d3":16}],387:[function(_dereq_,module,exports){
  66270. /**
  66271. * Copyright 2012-2018, Plotly, Inc.
  66272. * All rights reserved.
  66273. *
  66274. * This source code is licensed under the MIT license found in the
  66275. * LICENSE file in the root directory of this source tree.
  66276. */
  66277. 'use strict';
  66278. var subtypes = _dereq_('./subtypes');
  66279. module.exports = function selectPoints(searchInfo, selectionTester) {
  66280. var cd = searchInfo.cd,
  66281. xa = searchInfo.xaxis,
  66282. ya = searchInfo.yaxis,
  66283. selection = [],
  66284. trace = cd[0].trace,
  66285. i,
  66286. di,
  66287. x,
  66288. y;
  66289. var hasOnlyLines = (!subtypes.hasMarkers(trace) && !subtypes.hasText(trace));
  66290. if(hasOnlyLines) return [];
  66291. if(selectionTester === false) { // clear selection
  66292. for(i = 0; i < cd.length; i++) {
  66293. cd[i].selected = 0;
  66294. }
  66295. }
  66296. else {
  66297. for(i = 0; i < cd.length; i++) {
  66298. di = cd[i];
  66299. x = xa.c2p(di.x);
  66300. y = ya.c2p(di.y);
  66301. if((di.i !== null) && selectionTester.contains([x, y], false, i, searchInfo)) {
  66302. selection.push({
  66303. pointNumber: di.i,
  66304. x: xa.c2d(di.x),
  66305. y: ya.c2d(di.y)
  66306. });
  66307. di.selected = 1;
  66308. } else {
  66309. di.selected = 0;
  66310. }
  66311. }
  66312. }
  66313. return selection;
  66314. };
  66315. },{"./subtypes":390}],388:[function(_dereq_,module,exports){
  66316. /**
  66317. * Copyright 2012-2018, Plotly, Inc.
  66318. * All rights reserved.
  66319. *
  66320. * This source code is licensed under the MIT license found in the
  66321. * LICENSE file in the root directory of this source tree.
  66322. */
  66323. 'use strict';
  66324. var perStackAttrs = ['orientation', 'groupnorm', 'stackgaps'];
  66325. module.exports = function handleStackDefaults(traceIn, traceOut, layout, coerce) {
  66326. var stackOpts = layout._scatterStackOpts;
  66327. var stackGroup = coerce('stackgroup');
  66328. if(stackGroup) {
  66329. // use independent stacking options per subplot
  66330. var subplot = traceOut.xaxis + traceOut.yaxis;
  66331. var subplotStackOpts = stackOpts[subplot];
  66332. if(!subplotStackOpts) subplotStackOpts = stackOpts[subplot] = {};
  66333. var groupOpts = subplotStackOpts[stackGroup];
  66334. var firstTrace = false;
  66335. if(groupOpts) {
  66336. groupOpts.traces.push(traceOut);
  66337. }
  66338. else {
  66339. groupOpts = subplotStackOpts[stackGroup] = {
  66340. // keep track of trace indices for use during stacking calculations
  66341. // this will be filled in during `calc` and used during `crossTraceCalc`
  66342. // so it's OK if we don't recreate it during a non-calc edit
  66343. traceIndices: [],
  66344. // Hold on to the whole set of prior traces
  66345. // First one is most important, so we can clear defaults
  66346. // there if we find explicit values only in later traces.
  66347. // We're only going to *use* the values stored in groupOpts,
  66348. // but for the editor and validate we want things self-consistent
  66349. // The full set of traces is used only to fix `fill` default if
  66350. // we find `orientation: 'h'` beyond the first trace
  66351. traces: [traceOut]
  66352. };
  66353. firstTrace = true;
  66354. }
  66355. // TODO: how is this going to work with groupby transforms?
  66356. // in principle it should be OK I guess, as long as explicit group styles
  66357. // don't override explicit base-trace styles?
  66358. var dflts = {
  66359. orientation: (traceOut.x && !traceOut.y) ? 'h' : 'v'
  66360. };
  66361. for(var i = 0; i < perStackAttrs.length; i++) {
  66362. var attr = perStackAttrs[i];
  66363. var attrFound = attr + 'Found';
  66364. if(!groupOpts[attrFound]) {
  66365. var traceHasAttr = traceIn[attr] !== undefined;
  66366. var isOrientation = attr === 'orientation';
  66367. if(traceHasAttr || firstTrace) {
  66368. groupOpts[attr] = coerce(attr, dflts[attr]);
  66369. if(isOrientation) {
  66370. groupOpts.fillDflt = groupOpts[attr] === 'h' ?
  66371. 'tonextx' : 'tonexty';
  66372. }
  66373. if(traceHasAttr) {
  66374. // Note: this will show a value here even if it's invalid
  66375. // in which case it will revert to default.
  66376. groupOpts[attrFound] = true;
  66377. // Note: only one trace in the stack will get a _fullData
  66378. // entry for a given stack-wide attribute. If no traces
  66379. // (or the first trace) specify that attribute, the
  66380. // first trace will get it. If the first trace does NOT
  66381. // specify it but some later trace does, then it gets
  66382. // removed from the first trace and only included in the
  66383. // one that specified it. This is mostly important for
  66384. // editors (that want to see the full values to know
  66385. // what settings are available) and Plotly.react diffing.
  66386. // Editors may want to use fullLayout._scatterStackOpts
  66387. // directly and make these settings available from all
  66388. // traces in the stack... then set the new value into
  66389. // the first trace, and clear all later traces.
  66390. if(!firstTrace) {
  66391. delete groupOpts.traces[0][attr];
  66392. // orientation can affect default fill of previous traces
  66393. if(isOrientation) {
  66394. for(var j = 0; j < groupOpts.traces.length - 1; j++) {
  66395. var trace2 = groupOpts.traces[j];
  66396. if(trace2._input.fill !== trace2.fill) {
  66397. trace2.fill = groupOpts.fillDflt;
  66398. }
  66399. }
  66400. }
  66401. }
  66402. }
  66403. }
  66404. }
  66405. }
  66406. return groupOpts;
  66407. }
  66408. };
  66409. },{}],389:[function(_dereq_,module,exports){
  66410. /**
  66411. * Copyright 2012-2018, Plotly, Inc.
  66412. * All rights reserved.
  66413. *
  66414. * This source code is licensed under the MIT license found in the
  66415. * LICENSE file in the root directory of this source tree.
  66416. */
  66417. 'use strict';
  66418. var d3 = _dereq_('d3');
  66419. var Drawing = _dereq_('../../components/drawing');
  66420. var Registry = _dereq_('../../registry');
  66421. function style(gd, cd) {
  66422. var s = cd ? cd[0].node3 : d3.select(gd).selectAll('g.trace.scatter');
  66423. s.style('opacity', function(d) {
  66424. return d[0].trace.opacity;
  66425. });
  66426. s.selectAll('g.points').each(function(d) {
  66427. var sel = d3.select(this);
  66428. var trace = d.trace || d[0].trace;
  66429. stylePoints(sel, trace, gd);
  66430. });
  66431. s.selectAll('g.text').each(function(d) {
  66432. var sel = d3.select(this);
  66433. var trace = d.trace || d[0].trace;
  66434. styleText(sel, trace, gd);
  66435. });
  66436. s.selectAll('g.trace path.js-line')
  66437. .call(Drawing.lineGroupStyle);
  66438. s.selectAll('g.trace path.js-fill')
  66439. .call(Drawing.fillGroupStyle);
  66440. Registry.getComponentMethod('errorbars', 'style')(s);
  66441. }
  66442. function stylePoints(sel, trace, gd) {
  66443. Drawing.pointStyle(sel.selectAll('path.point'), trace, gd);
  66444. }
  66445. function styleText(sel, trace, gd) {
  66446. Drawing.textPointStyle(sel.selectAll('text'), trace, gd);
  66447. }
  66448. function styleOnSelect(gd, cd) {
  66449. var s = cd[0].node3;
  66450. var trace = cd[0].trace;
  66451. if(trace.selectedpoints) {
  66452. Drawing.selectedPointStyle(s.selectAll('path.point'), trace);
  66453. Drawing.selectedTextStyle(s.selectAll('text'), trace);
  66454. } else {
  66455. stylePoints(s, trace, gd);
  66456. styleText(s, trace, gd);
  66457. }
  66458. }
  66459. module.exports = {
  66460. style: style,
  66461. stylePoints: stylePoints,
  66462. styleText: styleText,
  66463. styleOnSelect: styleOnSelect
  66464. };
  66465. },{"../../components/drawing":75,"../../registry":259,"d3":16}],390:[function(_dereq_,module,exports){
  66466. /**
  66467. * Copyright 2012-2018, Plotly, Inc.
  66468. * All rights reserved.
  66469. *
  66470. * This source code is licensed under the MIT license found in the
  66471. * LICENSE file in the root directory of this source tree.
  66472. */
  66473. 'use strict';
  66474. var Lib = _dereq_('../../lib');
  66475. module.exports = {
  66476. hasLines: function(trace) {
  66477. return trace.visible && trace.mode &&
  66478. trace.mode.indexOf('lines') !== -1;
  66479. },
  66480. hasMarkers: function(trace) {
  66481. return trace.visible && (
  66482. (trace.mode && trace.mode.indexOf('markers') !== -1) ||
  66483. // until splom implements 'mode'
  66484. trace.type === 'splom'
  66485. );
  66486. },
  66487. hasText: function(trace) {
  66488. return trace.visible && trace.mode &&
  66489. trace.mode.indexOf('text') !== -1;
  66490. },
  66491. isBubble: function(trace) {
  66492. return Lib.isPlainObject(trace.marker) &&
  66493. Lib.isArrayOrTypedArray(trace.marker.size);
  66494. }
  66495. };
  66496. },{"../../lib":169}],391:[function(_dereq_,module,exports){
  66497. /**
  66498. * Copyright 2012-2018, Plotly, Inc.
  66499. * All rights reserved.
  66500. *
  66501. * This source code is licensed under the MIT license found in the
  66502. * LICENSE file in the root directory of this source tree.
  66503. */
  66504. 'use strict';
  66505. var Lib = _dereq_('../../lib');
  66506. /*
  66507. * opts: object of flags to control features not all text users support
  66508. * noSelect: caller does not support selected/unselected attribute containers
  66509. */
  66510. module.exports = function(traceIn, traceOut, layout, coerce, opts) {
  66511. opts = opts || {};
  66512. coerce('textposition');
  66513. Lib.coerceFont(coerce, 'textfont', layout.font);
  66514. if(!opts.noSelect) {
  66515. coerce('selected.textfont.color');
  66516. coerce('unselected.textfont.color');
  66517. }
  66518. };
  66519. },{"../../lib":169}],392:[function(_dereq_,module,exports){
  66520. /**
  66521. * Copyright 2012-2018, Plotly, Inc.
  66522. * All rights reserved.
  66523. *
  66524. * This source code is licensed under the MIT license found in the
  66525. * LICENSE file in the root directory of this source tree.
  66526. */
  66527. 'use strict';
  66528. var Registry = _dereq_('../../registry');
  66529. module.exports = function handleXYDefaults(traceIn, traceOut, layout, coerce) {
  66530. var len,
  66531. x = coerce('x'),
  66532. y = coerce('y');
  66533. var handleCalendarDefaults = Registry.getComponentMethod('calendars', 'handleTraceDefaults');
  66534. handleCalendarDefaults(traceIn, traceOut, ['x', 'y'], layout);
  66535. if(x) {
  66536. if(y) {
  66537. len = Math.min(x.length, y.length);
  66538. }
  66539. else {
  66540. len = x.length;
  66541. coerce('y0');
  66542. coerce('dy');
  66543. }
  66544. }
  66545. else {
  66546. if(!y) return 0;
  66547. len = traceOut.y.length;
  66548. coerce('x0');
  66549. coerce('dx');
  66550. }
  66551. traceOut._length = len;
  66552. return len;
  66553. };
  66554. },{"../../registry":259}],393:[function(_dereq_,module,exports){
  66555. /**
  66556. * Copyright 2012-2018, Plotly, Inc.
  66557. * All rights reserved.
  66558. *
  66559. * This source code is licensed under the MIT license found in the
  66560. * LICENSE file in the root directory of this source tree.
  66561. */
  66562. 'use strict';
  66563. var scatterAttrs = _dereq_('../scatter/attributes');
  66564. var plotAttrs = _dereq_('../../plots/attributes');
  66565. var colorAttributes = _dereq_('../../components/colorscale/attributes');
  66566. var colorbarAttrs = _dereq_('../../components/colorbar/attributes');
  66567. var dash = _dereq_('../../components/drawing/attributes').dash;
  66568. var extendFlat = _dereq_('../../lib/extend').extendFlat;
  66569. var scatterMarkerAttrs = scatterAttrs.marker,
  66570. scatterLineAttrs = scatterAttrs.line,
  66571. scatterMarkerLineAttrs = scatterMarkerAttrs.line;
  66572. module.exports = {
  66573. a: {
  66574. valType: 'data_array',
  66575. editType: 'calc',
  66576. },
  66577. b: {
  66578. valType: 'data_array',
  66579. editType: 'calc',
  66580. },
  66581. c: {
  66582. valType: 'data_array',
  66583. editType: 'calc',
  66584. },
  66585. sum: {
  66586. valType: 'number',
  66587. dflt: 0,
  66588. min: 0,
  66589. editType: 'calc',
  66590. },
  66591. mode: extendFlat({}, scatterAttrs.mode, {dflt: 'markers'}),
  66592. text: extendFlat({}, scatterAttrs.text, {
  66593. }),
  66594. hovertext: extendFlat({}, scatterAttrs.hovertext, {
  66595. }),
  66596. line: {
  66597. color: scatterLineAttrs.color,
  66598. width: scatterLineAttrs.width,
  66599. dash: dash,
  66600. shape: extendFlat({}, scatterLineAttrs.shape,
  66601. {values: ['linear', 'spline']}),
  66602. smoothing: scatterLineAttrs.smoothing,
  66603. editType: 'calc'
  66604. },
  66605. connectgaps: scatterAttrs.connectgaps,
  66606. cliponaxis: scatterAttrs.cliponaxis,
  66607. fill: extendFlat({}, scatterAttrs.fill, {
  66608. values: ['none', 'toself', 'tonext'],
  66609. dflt: 'none',
  66610. }),
  66611. fillcolor: scatterAttrs.fillcolor,
  66612. marker: extendFlat({
  66613. symbol: scatterMarkerAttrs.symbol,
  66614. opacity: scatterMarkerAttrs.opacity,
  66615. maxdisplayed: scatterMarkerAttrs.maxdisplayed,
  66616. size: scatterMarkerAttrs.size,
  66617. sizeref: scatterMarkerAttrs.sizeref,
  66618. sizemin: scatterMarkerAttrs.sizemin,
  66619. sizemode: scatterMarkerAttrs.sizemode,
  66620. line: extendFlat({
  66621. width: scatterMarkerLineAttrs.width,
  66622. editType: 'calc'
  66623. },
  66624. colorAttributes('marker.line')
  66625. ),
  66626. gradient: scatterMarkerAttrs.gradient,
  66627. editType: 'calc'
  66628. }, colorAttributes('marker'), {
  66629. colorbar: colorbarAttrs
  66630. }),
  66631. textfont: scatterAttrs.textfont,
  66632. textposition: scatterAttrs.textposition,
  66633. selected: scatterAttrs.selected,
  66634. unselected: scatterAttrs.unselected,
  66635. hoverinfo: extendFlat({}, plotAttrs.hoverinfo, {
  66636. flags: ['a', 'b', 'c', 'text', 'name']
  66637. }),
  66638. hoveron: scatterAttrs.hoveron,
  66639. };
  66640. },{"../../components/colorbar/attributes":51,"../../components/colorscale/attributes":57,"../../components/drawing/attributes":74,"../../lib/extend":163,"../../plots/attributes":211,"../scatter/attributes":366}],394:[function(_dereq_,module,exports){
  66641. /**
  66642. * Copyright 2012-2018, Plotly, Inc.
  66643. * All rights reserved.
  66644. *
  66645. * This source code is licensed under the MIT license found in the
  66646. * LICENSE file in the root directory of this source tree.
  66647. */
  66648. 'use strict';
  66649. var isNumeric = _dereq_('fast-isnumeric');
  66650. var calcColorscale = _dereq_('../scatter/colorscale_calc');
  66651. var arraysToCalcdata = _dereq_('../scatter/arrays_to_calcdata');
  66652. var calcSelection = _dereq_('../scatter/calc_selection');
  66653. var calcMarkerSize = _dereq_('../scatter/calc').calcMarkerSize;
  66654. var dataArrays = ['a', 'b', 'c'];
  66655. var arraysToFill = {a: ['b', 'c'], b: ['a', 'c'], c: ['a', 'b']};
  66656. module.exports = function calc(gd, trace) {
  66657. var ternary = gd._fullLayout[trace.subplot];
  66658. var displaySum = ternary.sum;
  66659. var normSum = trace.sum || displaySum;
  66660. var arrays = {a: trace.a, b: trace.b, c: trace.c};
  66661. var i, j, dataArray, newArray, fillArray1, fillArray2;
  66662. // fill in one missing component
  66663. for(i = 0; i < dataArrays.length; i++) {
  66664. dataArray = dataArrays[i];
  66665. if(arrays[dataArray]) continue;
  66666. fillArray1 = arrays[arraysToFill[dataArray][0]];
  66667. fillArray2 = arrays[arraysToFill[dataArray][1]];
  66668. newArray = new Array(fillArray1.length);
  66669. for(j = 0; j < fillArray1.length; j++) {
  66670. newArray[j] = normSum - fillArray1[j] - fillArray2[j];
  66671. }
  66672. arrays[dataArray] = newArray;
  66673. }
  66674. // make the calcdata array
  66675. var serieslen = trace._length;
  66676. var cd = new Array(serieslen);
  66677. var a, b, c, norm, x, y;
  66678. for(i = 0; i < serieslen; i++) {
  66679. a = arrays.a[i];
  66680. b = arrays.b[i];
  66681. c = arrays.c[i];
  66682. if(isNumeric(a) && isNumeric(b) && isNumeric(c)) {
  66683. a = +a;
  66684. b = +b;
  66685. c = +c;
  66686. norm = displaySum / (a + b + c);
  66687. if(norm !== 1) {
  66688. a *= norm;
  66689. b *= norm;
  66690. c *= norm;
  66691. }
  66692. // map a, b, c onto x and y where the full scale of y
  66693. // is [0, sum], and x is [-sum, sum]
  66694. // TODO: this makes `a` always the top, `b` the bottom left,
  66695. // and `c` the bottom right. Do we want options to rearrange
  66696. // these?
  66697. y = a;
  66698. x = c - b;
  66699. cd[i] = {x: x, y: y, a: a, b: b, c: c};
  66700. }
  66701. else cd[i] = {x: false, y: false};
  66702. }
  66703. calcMarkerSize(trace, serieslen);
  66704. calcColorscale(trace);
  66705. arraysToCalcdata(cd, trace);
  66706. calcSelection(cd, trace);
  66707. return cd;
  66708. };
  66709. },{"../scatter/arrays_to_calcdata":365,"../scatter/calc":367,"../scatter/calc_selection":368,"../scatter/colorscale_calc":370,"fast-isnumeric":18}],395:[function(_dereq_,module,exports){
  66710. /**
  66711. * Copyright 2012-2018, Plotly, Inc.
  66712. * All rights reserved.
  66713. *
  66714. * This source code is licensed under the MIT license found in the
  66715. * LICENSE file in the root directory of this source tree.
  66716. */
  66717. 'use strict';
  66718. var Lib = _dereq_('../../lib');
  66719. var constants = _dereq_('../scatter/constants');
  66720. var subTypes = _dereq_('../scatter/subtypes');
  66721. var handleMarkerDefaults = _dereq_('../scatter/marker_defaults');
  66722. var handleLineDefaults = _dereq_('../scatter/line_defaults');
  66723. var handleLineShapeDefaults = _dereq_('../scatter/line_shape_defaults');
  66724. var handleTextDefaults = _dereq_('../scatter/text_defaults');
  66725. var handleFillColorDefaults = _dereq_('../scatter/fillcolor_defaults');
  66726. var attributes = _dereq_('./attributes');
  66727. module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout) {
  66728. function coerce(attr, dflt) {
  66729. return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);
  66730. }
  66731. var a = coerce('a'),
  66732. b = coerce('b'),
  66733. c = coerce('c'),
  66734. len;
  66735. // allow any one array to be missing, len is the minimum length of those
  66736. // present. Note that after coerce data_array's are either Arrays (which
  66737. // are truthy even if empty) or undefined. As in scatter, an empty array
  66738. // is different from undefined, because it can signify that this data is
  66739. // not known yet but expected in the future
  66740. if(a) {
  66741. len = a.length;
  66742. if(b) {
  66743. len = Math.min(len, b.length);
  66744. if(c) len = Math.min(len, c.length);
  66745. }
  66746. else if(c) len = Math.min(len, c.length);
  66747. else len = 0;
  66748. }
  66749. else if(b && c) {
  66750. len = Math.min(b.length, c.length);
  66751. }
  66752. if(!len) {
  66753. traceOut.visible = false;
  66754. return;
  66755. }
  66756. traceOut._length = len;
  66757. coerce('sum');
  66758. coerce('text');
  66759. coerce('hovertext');
  66760. var defaultMode = len < constants.PTS_LINESONLY ? 'lines+markers' : 'lines';
  66761. coerce('mode', defaultMode);
  66762. if(subTypes.hasLines(traceOut)) {
  66763. handleLineDefaults(traceIn, traceOut, defaultColor, layout, coerce);
  66764. handleLineShapeDefaults(traceIn, traceOut, coerce);
  66765. coerce('connectgaps');
  66766. }
  66767. if(subTypes.hasMarkers(traceOut)) {
  66768. handleMarkerDefaults(traceIn, traceOut, defaultColor, layout, coerce, {gradient: true});
  66769. }
  66770. if(subTypes.hasText(traceOut)) {
  66771. handleTextDefaults(traceIn, traceOut, layout, coerce);
  66772. }
  66773. var dfltHoverOn = [];
  66774. if(subTypes.hasMarkers(traceOut) || subTypes.hasText(traceOut)) {
  66775. coerce('cliponaxis');
  66776. coerce('marker.maxdisplayed');
  66777. dfltHoverOn.push('points');
  66778. }
  66779. coerce('fill');
  66780. if(traceOut.fill !== 'none') {
  66781. handleFillColorDefaults(traceIn, traceOut, defaultColor, coerce);
  66782. if(!subTypes.hasLines(traceOut)) handleLineShapeDefaults(traceIn, traceOut, coerce);
  66783. }
  66784. if(traceOut.fill === 'tonext' || traceOut.fill === 'toself') {
  66785. dfltHoverOn.push('fills');
  66786. }
  66787. coerce('hoveron', dfltHoverOn.join('+') || 'points');
  66788. Lib.coerceSelectionMarkerOpacity(traceOut, coerce);
  66789. };
  66790. },{"../../lib":169,"../scatter/constants":371,"../scatter/fillcolor_defaults":375,"../scatter/line_defaults":379,"../scatter/line_shape_defaults":381,"../scatter/marker_defaults":385,"../scatter/subtypes":390,"../scatter/text_defaults":391,"./attributes":393}],396:[function(_dereq_,module,exports){
  66791. /**
  66792. * Copyright 2012-2018, Plotly, Inc.
  66793. * All rights reserved.
  66794. *
  66795. * This source code is licensed under the MIT license found in the
  66796. * LICENSE file in the root directory of this source tree.
  66797. */
  66798. 'use strict';
  66799. module.exports = function eventData(out, pt, trace, cd, pointNumber) {
  66800. if(pt.xa) out.xaxis = pt.xa;
  66801. if(pt.ya) out.yaxis = pt.ya;
  66802. if(cd[pointNumber]) {
  66803. var cdi = cd[pointNumber];
  66804. // N.B. These are the normalized coordinates.
  66805. out.a = cdi.a;
  66806. out.b = cdi.b;
  66807. out.c = cdi.c;
  66808. } else {
  66809. // for fill-hover only
  66810. out.a = pt.a;
  66811. out.b = pt.b;
  66812. out.c = pt.c;
  66813. }
  66814. return out;
  66815. };
  66816. },{}],397:[function(_dereq_,module,exports){
  66817. /**
  66818. * Copyright 2012-2018, Plotly, Inc.
  66819. * All rights reserved.
  66820. *
  66821. * This source code is licensed under the MIT license found in the
  66822. * LICENSE file in the root directory of this source tree.
  66823. */
  66824. 'use strict';
  66825. var scatterHover = _dereq_('../scatter/hover');
  66826. var Axes = _dereq_('../../plots/cartesian/axes');
  66827. module.exports = function hoverPoints(pointData, xval, yval, hovermode) {
  66828. var scatterPointData = scatterHover(pointData, xval, yval, hovermode);
  66829. if(!scatterPointData || scatterPointData[0].index === false) return;
  66830. var newPointData = scatterPointData[0];
  66831. // if hovering on a fill, we don't show any point data so the label is
  66832. // unchanged from what scatter gives us - except that it needs to
  66833. // be constrained to the trianglular plot area, not just the rectangular
  66834. // area defined by the synthetic x and y axes
  66835. // TODO: in some cases the vertical middle of the shape is not within
  66836. // the triangular viewport at all, so the label can become disconnected
  66837. // from the shape entirely. But calculating what portion of the shape
  66838. // is actually visible, as constrained by the diagonal axis lines, is not
  66839. // so easy and anyway we lost the information we would have needed to do
  66840. // this inside scatterHover.
  66841. if(newPointData.index === undefined) {
  66842. var yFracUp = 1 - (newPointData.y0 / pointData.ya._length),
  66843. xLen = pointData.xa._length,
  66844. xMin = xLen * yFracUp / 2,
  66845. xMax = xLen - xMin;
  66846. newPointData.x0 = Math.max(Math.min(newPointData.x0, xMax), xMin);
  66847. newPointData.x1 = Math.max(Math.min(newPointData.x1, xMax), xMin);
  66848. return scatterPointData;
  66849. }
  66850. var cdi = newPointData.cd[newPointData.index];
  66851. newPointData.a = cdi.a;
  66852. newPointData.b = cdi.b;
  66853. newPointData.c = cdi.c;
  66854. newPointData.xLabelVal = undefined;
  66855. newPointData.yLabelVal = undefined;
  66856. // TODO: nice formatting, and label by axis title, for a, b, and c?
  66857. var trace = newPointData.trace;
  66858. var ternary = newPointData.subplot;
  66859. var hoverinfo = cdi.hi || trace.hoverinfo;
  66860. var parts = hoverinfo.split('+');
  66861. var text = [];
  66862. function textPart(ax, val) {
  66863. text.push(ax._hovertitle + ': ' + Axes.tickText(ax, val, 'hover').text);
  66864. }
  66865. if(parts.indexOf('all') !== -1) parts = ['a', 'b', 'c'];
  66866. if(parts.indexOf('a') !== -1) textPart(ternary.aaxis, cdi.a);
  66867. if(parts.indexOf('b') !== -1) textPart(ternary.baxis, cdi.b);
  66868. if(parts.indexOf('c') !== -1) textPart(ternary.caxis, cdi.c);
  66869. newPointData.extraText = text.join('<br>');
  66870. return scatterPointData;
  66871. };
  66872. },{"../../plots/cartesian/axes":214,"../scatter/hover":377}],398:[function(_dereq_,module,exports){
  66873. /**
  66874. * Copyright 2012-2018, Plotly, Inc.
  66875. * All rights reserved.
  66876. *
  66877. * This source code is licensed under the MIT license found in the
  66878. * LICENSE file in the root directory of this source tree.
  66879. */
  66880. 'use strict';
  66881. var ScatterTernary = {};
  66882. ScatterTernary.attributes = _dereq_('./attributes');
  66883. ScatterTernary.supplyDefaults = _dereq_('./defaults');
  66884. ScatterTernary.colorbar = _dereq_('../scatter/marker_colorbar');
  66885. ScatterTernary.calc = _dereq_('./calc');
  66886. ScatterTernary.plot = _dereq_('./plot');
  66887. ScatterTernary.style = _dereq_('../scatter/style').style;
  66888. ScatterTernary.styleOnSelect = _dereq_('../scatter/style').styleOnSelect;
  66889. ScatterTernary.hoverPoints = _dereq_('./hover');
  66890. ScatterTernary.selectPoints = _dereq_('../scatter/select');
  66891. ScatterTernary.eventData = _dereq_('./event_data');
  66892. ScatterTernary.moduleType = 'trace';
  66893. ScatterTernary.name = 'scatterternary';
  66894. ScatterTernary.basePlotModule = _dereq_('../../plots/ternary');
  66895. ScatterTernary.categories = ['ternary', 'symbols', 'showLegend', 'scatter-like'];
  66896. ScatterTernary.meta = {
  66897. };
  66898. module.exports = ScatterTernary;
  66899. },{"../../plots/ternary":255,"../scatter/marker_colorbar":384,"../scatter/select":387,"../scatter/style":389,"./attributes":393,"./calc":394,"./defaults":395,"./event_data":396,"./hover":397,"./plot":399}],399:[function(_dereq_,module,exports){
  66900. /**
  66901. * Copyright 2012-2018, Plotly, Inc.
  66902. * All rights reserved.
  66903. *
  66904. * This source code is licensed under the MIT license found in the
  66905. * LICENSE file in the root directory of this source tree.
  66906. */
  66907. 'use strict';
  66908. var scatterPlot = _dereq_('../scatter/plot');
  66909. module.exports = function plot(gd, ternary, moduleCalcData) {
  66910. var plotContainer = ternary.plotContainer;
  66911. // remove all nodes inside the scatter layer
  66912. plotContainer.select('.scatterlayer').selectAll('*').remove();
  66913. // mimic cartesian plotinfo
  66914. var plotinfo = {
  66915. xaxis: ternary.xaxis,
  66916. yaxis: ternary.yaxis,
  66917. plot: plotContainer,
  66918. layerClipId: ternary._hasClipOnAxisFalse ? ternary.clipIdRelative : null
  66919. };
  66920. var scatterLayer = ternary.layers.frontplot.select('g.scatterlayer');
  66921. scatterPlot(gd, plotinfo, moduleCalcData, scatterLayer);
  66922. };
  66923. },{"../scatter/plot":386}],400:[function(_dereq_,module,exports){
  66924. /**
  66925. * Copyright 2012-2018, Plotly, Inc.
  66926. * All rights reserved.
  66927. *
  66928. * This source code is licensed under the MIT license found in the
  66929. * LICENSE file in the root directory of this source tree.
  66930. */
  66931. 'use strict';
  66932. var boxAttrs = _dereq_('../box/attributes');
  66933. var extendFlat = _dereq_('../../lib/extend').extendFlat;
  66934. module.exports = {
  66935. y: boxAttrs.y,
  66936. x: boxAttrs.x,
  66937. x0: boxAttrs.x0,
  66938. y0: boxAttrs.y0,
  66939. name: boxAttrs.name,
  66940. orientation: extendFlat({}, boxAttrs.orientation, {
  66941. }),
  66942. bandwidth: {
  66943. valType: 'number',
  66944. min: 0,
  66945. editType: 'calc',
  66946. },
  66947. scalegroup: {
  66948. valType: 'string',
  66949. dflt: '',
  66950. editType: 'calc',
  66951. },
  66952. scalemode: {
  66953. valType: 'enumerated',
  66954. values: ['width', 'count'],
  66955. dflt: 'width',
  66956. editType: 'calc',
  66957. },
  66958. spanmode: {
  66959. valType: 'enumerated',
  66960. values: ['soft', 'hard', 'manual'],
  66961. dflt: 'soft',
  66962. editType: 'calc',
  66963. },
  66964. span: {
  66965. valType: 'info_array',
  66966. items: [
  66967. {valType: 'any', editType: 'calc'},
  66968. {valType: 'any', editType: 'calc'}
  66969. ],
  66970. editType: 'calc',
  66971. },
  66972. line: {
  66973. color: {
  66974. valType: 'color',
  66975. editType: 'style',
  66976. },
  66977. width: {
  66978. valType: 'number',
  66979. min: 0,
  66980. dflt: 2,
  66981. editType: 'style',
  66982. },
  66983. editType: 'plot'
  66984. },
  66985. fillcolor: boxAttrs.fillcolor,
  66986. points: extendFlat({}, boxAttrs.boxpoints, {
  66987. }),
  66988. jitter: extendFlat({}, boxAttrs.jitter, {
  66989. }),
  66990. pointpos: extendFlat({}, boxAttrs.pointpos, {
  66991. }),
  66992. marker: boxAttrs.marker,
  66993. text: boxAttrs.text,
  66994. box: {
  66995. visible: {
  66996. valType: 'boolean',
  66997. dflt: false,
  66998. editType: 'plot',
  66999. },
  67000. width: {
  67001. valType: 'number',
  67002. min: 0,
  67003. max: 1,
  67004. dflt: 0.25,
  67005. editType: 'plot',
  67006. },
  67007. fillcolor: {
  67008. valType: 'color',
  67009. editType: 'style',
  67010. },
  67011. line: {
  67012. color: {
  67013. valType: 'color',
  67014. editType: 'style',
  67015. },
  67016. width: {
  67017. valType: 'number',
  67018. min: 0,
  67019. editType: 'style',
  67020. },
  67021. editType: 'style'
  67022. },
  67023. editType: 'plot'
  67024. },
  67025. meanline: {
  67026. visible: {
  67027. valType: 'boolean',
  67028. dflt: false,
  67029. editType: 'plot',
  67030. },
  67031. color: {
  67032. valType: 'color',
  67033. editType: 'style',
  67034. },
  67035. width: {
  67036. valType: 'number',
  67037. min: 0,
  67038. editType: 'style',
  67039. },
  67040. editType: 'plot'
  67041. },
  67042. side: {
  67043. valType: 'enumerated',
  67044. values: ['both', 'positive', 'negative'],
  67045. dflt: 'both',
  67046. editType: 'plot',
  67047. },
  67048. selected: boxAttrs.selected,
  67049. unselected: boxAttrs.unselected,
  67050. hoveron: {
  67051. valType: 'flaglist',
  67052. flags: ['violins', 'points', 'kde'],
  67053. dflt: 'violins+points+kde',
  67054. extras: ['all'],
  67055. editType: 'style',
  67056. }
  67057. };
  67058. },{"../../lib/extend":163,"../box/attributes":282}],401:[function(_dereq_,module,exports){
  67059. /**
  67060. * Copyright 2012-2018, Plotly, Inc.
  67061. * All rights reserved.
  67062. *
  67063. * This source code is licensed under the MIT license found in the
  67064. * LICENSE file in the root directory of this source tree.
  67065. */
  67066. 'use strict';
  67067. var Lib = _dereq_('../../lib');
  67068. var Axes = _dereq_('../../plots/cartesian/axes');
  67069. var boxCalc = _dereq_('../box/calc');
  67070. var helpers = _dereq_('./helpers');
  67071. var BADNUM = _dereq_('../../constants/numerical').BADNUM;
  67072. module.exports = function calc(gd, trace) {
  67073. var cd = boxCalc(gd, trace);
  67074. if(cd[0].t.empty) return cd;
  67075. var fullLayout = gd._fullLayout;
  67076. var valAxis = Axes.getFromId(
  67077. gd,
  67078. trace[trace.orientation === 'h' ? 'xaxis' : 'yaxis']
  67079. );
  67080. var violinScaleGroupStats = fullLayout._violinScaleGroupStats;
  67081. var scaleGroup = trace.scalegroup;
  67082. var groupStats = violinScaleGroupStats[scaleGroup];
  67083. if(!groupStats) {
  67084. groupStats = violinScaleGroupStats[scaleGroup] = {
  67085. maxWidth: 0,
  67086. maxCount: 0
  67087. };
  67088. }
  67089. var spanMin = Infinity;
  67090. var spanMax = -Infinity;
  67091. for(var i = 0; i < cd.length; i++) {
  67092. var cdi = cd[i];
  67093. var vals = cdi.pts.map(helpers.extractVal);
  67094. var bandwidth = cdi.bandwidth = calcBandwidth(trace, cdi, vals);
  67095. var span = cdi.span = calcSpan(trace, cdi, valAxis, bandwidth);
  67096. // step that well covers the bandwidth and is multiple of span distance
  67097. var dist = span[1] - span[0];
  67098. var n = Math.ceil(dist / (bandwidth / 3));
  67099. var step = dist / n;
  67100. if(!isFinite(step) || !isFinite(n)) {
  67101. Lib.error('Something went wrong with computing the violin span');
  67102. cd[0].t.empty = true;
  67103. return cd;
  67104. }
  67105. var kde = helpers.makeKDE(cdi, trace, vals);
  67106. cdi.density = new Array(n);
  67107. for(var k = 0, t = span[0]; t < (span[1] + step / 2); k++, t += step) {
  67108. var v = kde(t);
  67109. groupStats.maxWidth = Math.max(groupStats.maxWidth, v);
  67110. cdi.density[k] = {v: v, t: t};
  67111. }
  67112. groupStats.maxCount = Math.max(groupStats.maxCount, vals.length);
  67113. spanMin = Math.min(spanMin, span[0]);
  67114. spanMax = Math.max(spanMax, span[1]);
  67115. }
  67116. var extremes = Axes.findExtremes(valAxis, [spanMin, spanMax], {padded: true});
  67117. trace._extremes[valAxis._id] = extremes;
  67118. cd[0].t.labels.kde = Lib._(gd, 'kde:');
  67119. return cd;
  67120. };
  67121. // Default to Silveman's rule of thumb
  67122. // - https://stats.stackexchange.com/a/6671
  67123. // - https://en.wikipedia.org/wiki/Kernel_density_estimation#A_rule-of-thumb_bandwidth_estimator
  67124. // - https://github.com/statsmodels/statsmodels/blob/master/statsmodels/nonparametric/bandwidths.py
  67125. function silvermanRule(len, ssd, iqr) {
  67126. var a = Math.min(ssd, iqr / 1.349);
  67127. return 1.059 * a * Math.pow(len, -0.2);
  67128. }
  67129. function calcBandwidth(trace, cdi, vals) {
  67130. var span = cdi.max - cdi.min;
  67131. // plot single-value violin with bandwidth of 1
  67132. if(!span) return 1;
  67133. // Limit how small the bandwidth can be.
  67134. //
  67135. // Silverman's rule of thumb can be "very" small
  67136. // when IQR does a poor job at describing the spread
  67137. // of the distribution.
  67138. // We also want to limit custom bandwidths
  67139. // to not blow up kde computations.
  67140. if(trace.bandwidth) {
  67141. return Math.max(trace.bandwidth, span / 1e4);
  67142. } else {
  67143. var len = vals.length;
  67144. var ssd = Lib.stdev(vals, len - 1, cdi.mean);
  67145. return Math.max(
  67146. silvermanRule(len, ssd, cdi.q3 - cdi.q1),
  67147. span / 100
  67148. );
  67149. }
  67150. }
  67151. function calcSpan(trace, cdi, valAxis, bandwidth) {
  67152. var spanmode = trace.spanmode;
  67153. var spanIn = trace.span || [];
  67154. var spanTight = [cdi.min, cdi.max];
  67155. var spanLoose = [cdi.min - 2 * bandwidth, cdi.max + 2 * bandwidth];
  67156. var spanOut;
  67157. function calcSpanItem(index) {
  67158. var s = spanIn[index];
  67159. var sc = valAxis.d2c(s, 0, trace[cdi.valLetter + 'calendar']);
  67160. return sc === BADNUM ? spanLoose[index] : sc;
  67161. }
  67162. if(spanmode === 'soft') {
  67163. spanOut = spanLoose;
  67164. } else if(spanmode === 'hard') {
  67165. spanOut = spanTight;
  67166. } else {
  67167. spanOut = [calcSpanItem(0), calcSpanItem(1)];
  67168. }
  67169. // to reuse the equal-range-item block
  67170. var dummyAx = {
  67171. type: 'linear',
  67172. range: spanOut
  67173. };
  67174. Axes.setConvert(dummyAx);
  67175. dummyAx.cleanRange();
  67176. return spanOut;
  67177. }
  67178. },{"../../constants/numerical":151,"../../lib":169,"../../plots/cartesian/axes":214,"../box/calc":283,"./helpers":404}],402:[function(_dereq_,module,exports){
  67179. /**
  67180. * Copyright 2012-2018, Plotly, Inc.
  67181. * All rights reserved.
  67182. *
  67183. * This source code is licensed under the MIT license found in the
  67184. * LICENSE file in the root directory of this source tree.
  67185. */
  67186. 'use strict';
  67187. var setPositionOffset = _dereq_('../box/cross_trace_calc').setPositionOffset;
  67188. var orientations = ['v', 'h'];
  67189. module.exports = function crossTraceCalc(gd, plotinfo) {
  67190. var calcdata = gd.calcdata;
  67191. var xa = plotinfo.xaxis;
  67192. var ya = plotinfo.yaxis;
  67193. for(var i = 0; i < orientations.length; i++) {
  67194. var orientation = orientations[i];
  67195. var posAxis = orientation === 'h' ? ya : xa;
  67196. var violinList = [];
  67197. var minPad = 0;
  67198. var maxPad = 0;
  67199. for(var j = 0; j < calcdata.length; j++) {
  67200. var cd = calcdata[j];
  67201. var t = cd[0].t;
  67202. var trace = cd[0].trace;
  67203. if(trace.visible === true && trace.type === 'violin' &&
  67204. !t.empty &&
  67205. trace.orientation === orientation &&
  67206. trace.xaxis === xa._id &&
  67207. trace.yaxis === ya._id
  67208. ) {
  67209. violinList.push(j);
  67210. if(trace.points !== false) {
  67211. minPad = Math.max(minPad, trace.jitter - trace.pointpos - 1);
  67212. maxPad = Math.max(maxPad, trace.jitter + trace.pointpos - 1);
  67213. }
  67214. }
  67215. }
  67216. setPositionOffset('violin', gd, violinList, posAxis, [minPad, maxPad]);
  67217. }
  67218. };
  67219. },{"../box/cross_trace_calc":284}],403:[function(_dereq_,module,exports){
  67220. /**
  67221. * Copyright 2012-2018, Plotly, Inc.
  67222. * All rights reserved.
  67223. *
  67224. * This source code is licensed under the MIT license found in the
  67225. * LICENSE file in the root directory of this source tree.
  67226. */
  67227. 'use strict';
  67228. var Lib = _dereq_('../../lib');
  67229. var Color = _dereq_('../../components/color');
  67230. var boxDefaults = _dereq_('../box/defaults');
  67231. var attributes = _dereq_('./attributes');
  67232. module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout) {
  67233. function coerce(attr, dflt) {
  67234. return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);
  67235. }
  67236. function coerce2(attr, dflt) {
  67237. return Lib.coerce2(traceIn, traceOut, attributes, attr, dflt);
  67238. }
  67239. boxDefaults.handleSampleDefaults(traceIn, traceOut, coerce, layout);
  67240. if(traceOut.visible === false) return;
  67241. coerce('bandwidth');
  67242. coerce('scalegroup', traceOut.name);
  67243. coerce('scalemode');
  67244. coerce('side');
  67245. var span = coerce('span');
  67246. var spanmodeDflt;
  67247. if(Array.isArray(span)) spanmodeDflt = 'manual';
  67248. coerce('spanmode', spanmodeDflt);
  67249. var lineColor = coerce('line.color', (traceIn.marker || {}).color || defaultColor);
  67250. var lineWidth = coerce('line.width');
  67251. var fillColor = coerce('fillcolor', Color.addOpacity(traceOut.line.color, 0.5));
  67252. boxDefaults.handlePointsDefaults(traceIn, traceOut, coerce, {prefix: ''});
  67253. var boxWidth = coerce2('box.width');
  67254. var boxFillColor = coerce2('box.fillcolor', fillColor);
  67255. var boxLineColor = coerce2('box.line.color', lineColor);
  67256. var boxLineWidth = coerce2('box.line.width', lineWidth);
  67257. var boxVisible = coerce('box.visible', Boolean(boxWidth || boxFillColor || boxLineColor || boxLineWidth));
  67258. if(!boxVisible) traceOut.box = {visible: false};
  67259. var meanLineColor = coerce2('meanline.color', lineColor);
  67260. var meanLineWidth = coerce2('meanline.width', lineWidth);
  67261. var meanLineVisible = coerce('meanline.visible', Boolean(meanLineColor || meanLineWidth));
  67262. if(!meanLineVisible) traceOut.meanline = {visible: false};
  67263. };
  67264. },{"../../components/color":50,"../../lib":169,"../box/defaults":285,"./attributes":400}],404:[function(_dereq_,module,exports){
  67265. /**
  67266. * Copyright 2012-2018, Plotly, Inc.
  67267. * All rights reserved.
  67268. *
  67269. * This source code is licensed under the MIT license found in the
  67270. * LICENSE file in the root directory of this source tree.
  67271. */
  67272. 'use strict';
  67273. var Lib = _dereq_('../../lib');
  67274. // Maybe add kernels more down the road,
  67275. // but note that the default `spanmode: 'soft'` bounds might have
  67276. // to become kernel-dependent
  67277. var kernels = {
  67278. gaussian: function(v) {
  67279. return (1 / Math.sqrt(2 * Math.PI)) * Math.exp(-0.5 * v * v);
  67280. }
  67281. };
  67282. exports.makeKDE = function(calcItem, trace, vals) {
  67283. var len = vals.length;
  67284. var kernel = kernels.gaussian;
  67285. var bandwidth = calcItem.bandwidth;
  67286. var factor = 1 / (len * bandwidth);
  67287. // don't use Lib.aggNums to skip isNumeric checks
  67288. return function(x) {
  67289. var sum = 0;
  67290. for(var i = 0; i < len; i++) {
  67291. sum += kernel((x - vals[i]) / bandwidth);
  67292. }
  67293. return factor * sum;
  67294. };
  67295. };
  67296. exports.getPositionOnKdePath = function(calcItem, trace, valuePx) {
  67297. var posLetter, valLetter;
  67298. if(trace.orientation === 'h') {
  67299. posLetter = 'y';
  67300. valLetter = 'x';
  67301. } else {
  67302. posLetter = 'x';
  67303. valLetter = 'y';
  67304. }
  67305. var pointOnPath = Lib.findPointOnPath(
  67306. calcItem.path,
  67307. valuePx,
  67308. valLetter,
  67309. {pathLength: calcItem.pathLength}
  67310. );
  67311. var posCenterPx = calcItem.posCenterPx;
  67312. var posOnPath0 = pointOnPath[posLetter];
  67313. var posOnPath1 = trace.side === 'both' ?
  67314. 2 * posCenterPx - posOnPath0 :
  67315. posCenterPx;
  67316. return [posOnPath0, posOnPath1];
  67317. };
  67318. exports.getKdeValue = function(calcItem, trace, valueDist) {
  67319. var vals = calcItem.pts.map(exports.extractVal);
  67320. var kde = exports.makeKDE(calcItem, trace, vals);
  67321. return kde(valueDist) / calcItem.posDensityScale;
  67322. };
  67323. exports.extractVal = function(o) { return o.v; };
  67324. },{"../../lib":169}],405:[function(_dereq_,module,exports){
  67325. /**
  67326. * Copyright 2012-2018, Plotly, Inc.
  67327. * All rights reserved.
  67328. *
  67329. * This source code is licensed under the MIT license found in the
  67330. * LICENSE file in the root directory of this source tree.
  67331. */
  67332. 'use strict';
  67333. var Lib = _dereq_('../../lib');
  67334. var Axes = _dereq_('../../plots/cartesian/axes');
  67335. var boxHoverPoints = _dereq_('../box/hover');
  67336. var helpers = _dereq_('./helpers');
  67337. module.exports = function hoverPoints(pointData, xval, yval, hovermode, hoverLayer) {
  67338. var cd = pointData.cd;
  67339. var trace = cd[0].trace;
  67340. var hoveron = trace.hoveron;
  67341. var hasHoveronViolins = hoveron.indexOf('violins') !== -1;
  67342. var hasHoveronKDE = hoveron.indexOf('kde') !== -1;
  67343. var closeData = [];
  67344. var closePtData;
  67345. var violinLineAttrs;
  67346. if(hasHoveronViolins || hasHoveronKDE) {
  67347. var closeBoxData = boxHoverPoints.hoverOnBoxes(pointData, xval, yval, hovermode);
  67348. if(hasHoveronViolins) {
  67349. closeData = closeData.concat(closeBoxData);
  67350. }
  67351. if(hasHoveronKDE && closeBoxData.length > 0) {
  67352. var xa = pointData.xa;
  67353. var ya = pointData.ya;
  67354. var pLetter, vLetter, pAxis, vAxis, vVal;
  67355. if(trace.orientation === 'h') {
  67356. vVal = xval;
  67357. pLetter = 'y';
  67358. pAxis = ya;
  67359. vLetter = 'x';
  67360. vAxis = xa;
  67361. } else {
  67362. vVal = yval;
  67363. pLetter = 'x';
  67364. pAxis = xa;
  67365. vLetter = 'y';
  67366. vAxis = ya;
  67367. }
  67368. var di = cd[pointData.index];
  67369. if(vVal >= di.span[0] && vVal <= di.span[1]) {
  67370. var kdePointData = Lib.extendFlat({}, pointData);
  67371. var vValPx = vAxis.c2p(vVal, true);
  67372. var kdeVal = helpers.getKdeValue(di, trace, vVal);
  67373. var pOnPath = helpers.getPositionOnKdePath(di, trace, vValPx);
  67374. var paOffset = pAxis._offset;
  67375. var paLength = pAxis._length;
  67376. kdePointData[pLetter + '0'] = pOnPath[0];
  67377. kdePointData[pLetter + '1'] = pOnPath[1];
  67378. kdePointData[vLetter + '0'] = kdePointData[vLetter + '1'] = vValPx;
  67379. kdePointData[vLetter + 'Label'] = vLetter + ': ' + Axes.hoverLabelText(vAxis, vVal) + ', ' + cd[0].t.labels.kde + ' ' + kdeVal.toFixed(3);
  67380. // move the spike to the KDE point
  67381. kdePointData.spikeDistance = closeBoxData[0].spikeDistance;
  67382. var spikePosAttr = pLetter + 'Spike';
  67383. kdePointData[spikePosAttr] = closeBoxData[0][spikePosAttr];
  67384. closeBoxData[0].spikeDistance = undefined;
  67385. closeBoxData[0][spikePosAttr] = undefined;
  67386. closeData.push(kdePointData);
  67387. violinLineAttrs = {stroke: pointData.color};
  67388. violinLineAttrs[pLetter + '1'] = Lib.constrain(paOffset + pOnPath[0], paOffset, paOffset + paLength);
  67389. violinLineAttrs[pLetter + '2'] = Lib.constrain(paOffset + pOnPath[1], paOffset, paOffset + paLength);
  67390. violinLineAttrs[vLetter + '1'] = violinLineAttrs[vLetter + '2'] = vAxis._offset + vValPx;
  67391. }
  67392. }
  67393. }
  67394. if(hoveron.indexOf('points') !== -1) {
  67395. closePtData = boxHoverPoints.hoverOnPoints(pointData, xval, yval);
  67396. }
  67397. // update violin line (if any)
  67398. var violinLine = hoverLayer.selectAll('.violinline-' + trace.uid)
  67399. .data(violinLineAttrs ? [0] : []);
  67400. violinLine.enter().append('line')
  67401. .classed('violinline-' + trace.uid, true)
  67402. .attr('stroke-width', 1.5);
  67403. violinLine.exit().remove();
  67404. violinLine.attr(violinLineAttrs);
  67405. // same combine logic as box hoverPoints
  67406. if(hovermode === 'closest') {
  67407. if(closePtData) return [closePtData];
  67408. return closeData;
  67409. }
  67410. if(closePtData) {
  67411. closeData.push(closePtData);
  67412. return closeData;
  67413. }
  67414. return closeData;
  67415. };
  67416. },{"../../lib":169,"../../plots/cartesian/axes":214,"../box/hover":287,"./helpers":404}],406:[function(_dereq_,module,exports){
  67417. /**
  67418. * Copyright 2012-2018, Plotly, Inc.
  67419. * All rights reserved.
  67420. *
  67421. * This source code is licensed under the MIT license found in the
  67422. * LICENSE file in the root directory of this source tree.
  67423. */
  67424. 'use strict';
  67425. module.exports = {
  67426. attributes: _dereq_('./attributes'),
  67427. layoutAttributes: _dereq_('./layout_attributes'),
  67428. supplyDefaults: _dereq_('./defaults'),
  67429. supplyLayoutDefaults: _dereq_('./layout_defaults'),
  67430. calc: _dereq_('./calc'),
  67431. crossTraceCalc: _dereq_('./cross_trace_calc'),
  67432. plot: _dereq_('./plot'),
  67433. style: _dereq_('./style'),
  67434. styleOnSelect: _dereq_('../scatter/style').styleOnSelect,
  67435. hoverPoints: _dereq_('./hover'),
  67436. selectPoints: _dereq_('../box/select'),
  67437. moduleType: 'trace',
  67438. name: 'violin',
  67439. basePlotModule: _dereq_('../../plots/cartesian'),
  67440. categories: ['cartesian', 'svg', 'symbols', 'oriented', 'box-violin', 'showLegend', 'violinLayout', 'zoomScale'],
  67441. meta: {
  67442. }
  67443. };
  67444. },{"../../plots/cartesian":225,"../box/select":292,"../scatter/style":389,"./attributes":400,"./calc":401,"./cross_trace_calc":402,"./defaults":403,"./hover":405,"./layout_attributes":407,"./layout_defaults":408,"./plot":409,"./style":410}],407:[function(_dereq_,module,exports){
  67445. /**
  67446. * Copyright 2012-2018, Plotly, Inc.
  67447. * All rights reserved.
  67448. *
  67449. * This source code is licensed under the MIT license found in the
  67450. * LICENSE file in the root directory of this source tree.
  67451. */
  67452. 'use strict';
  67453. var boxLayoutAttrs = _dereq_('../box/layout_attributes');
  67454. var extendFlat = _dereq_('../../lib').extendFlat;
  67455. module.exports = {
  67456. violinmode: extendFlat({}, boxLayoutAttrs.boxmode, {
  67457. }),
  67458. violingap: extendFlat({}, boxLayoutAttrs.boxgap, {
  67459. }),
  67460. violingroupgap: extendFlat({}, boxLayoutAttrs.boxgroupgap, {
  67461. })
  67462. };
  67463. },{"../../lib":169,"../box/layout_attributes":289}],408:[function(_dereq_,module,exports){
  67464. /**
  67465. * Copyright 2012-2018, Plotly, Inc.
  67466. * All rights reserved.
  67467. *
  67468. * This source code is licensed under the MIT license found in the
  67469. * LICENSE file in the root directory of this source tree.
  67470. */
  67471. 'use strict';
  67472. var Lib = _dereq_('../../lib');
  67473. var layoutAttributes = _dereq_('./layout_attributes');
  67474. var boxLayoutDefaults = _dereq_('../box/layout_defaults');
  67475. module.exports = function supplyLayoutDefaults(layoutIn, layoutOut, fullData) {
  67476. function coerce(attr, dflt) {
  67477. return Lib.coerce(layoutIn, layoutOut, layoutAttributes, attr, dflt);
  67478. }
  67479. boxLayoutDefaults._supply(layoutIn, layoutOut, fullData, coerce, 'violin');
  67480. };
  67481. },{"../../lib":169,"../box/layout_defaults":290,"./layout_attributes":407}],409:[function(_dereq_,module,exports){
  67482. /**
  67483. * Copyright 2012-2018, Plotly, Inc.
  67484. * All rights reserved.
  67485. *
  67486. * This source code is licensed under the MIT license found in the
  67487. * LICENSE file in the root directory of this source tree.
  67488. */
  67489. 'use strict';
  67490. var d3 = _dereq_('d3');
  67491. var Lib = _dereq_('../../lib');
  67492. var Drawing = _dereq_('../../components/drawing');
  67493. var boxPlot = _dereq_('../box/plot');
  67494. var linePoints = _dereq_('../scatter/line_points');
  67495. var helpers = _dereq_('./helpers');
  67496. module.exports = function plot(gd, plotinfo, cdViolins, violinLayer) {
  67497. var fullLayout = gd._fullLayout;
  67498. var xa = plotinfo.xaxis;
  67499. var ya = plotinfo.yaxis;
  67500. function makePath(pts) {
  67501. var segments = linePoints(pts, {
  67502. xaxis: xa,
  67503. yaxis: ya,
  67504. connectGaps: true,
  67505. baseTolerance: 0.75,
  67506. shape: 'spline',
  67507. simplify: true
  67508. });
  67509. return Drawing.smoothopen(segments[0], 1);
  67510. }
  67511. Lib.makeTraceGroups(violinLayer, cdViolins, 'trace violins').each(function(cd) {
  67512. var plotGroup = d3.select(this);
  67513. var cd0 = cd[0];
  67514. var t = cd0.t;
  67515. var trace = cd0.trace;
  67516. if(!plotinfo.isRangePlot) cd0.node3 = plotGroup;
  67517. var numViolins = fullLayout._numViolins;
  67518. var group = (fullLayout.violinmode === 'group' && numViolins > 1);
  67519. var groupFraction = 1 - fullLayout.violingap;
  67520. // violin max half width
  67521. var bdPos = t.bdPos = t.dPos * groupFraction * (1 - fullLayout.violingroupgap) / (group ? numViolins : 1);
  67522. // violin center offset
  67523. var bPos = t.bPos = group ? 2 * t.dPos * (-0.5 + (t.num + 0.5) / numViolins) * groupFraction : 0;
  67524. // half-width within which to accept hover for this violin
  67525. // always split the distance to the closest violin
  67526. t.wHover = t.dPos * (group ? groupFraction / numViolins : 1);
  67527. if(trace.visible !== true || t.empty) {
  67528. plotGroup.remove();
  67529. return;
  67530. }
  67531. var valAxis = plotinfo[t.valLetter + 'axis'];
  67532. var posAxis = plotinfo[t.posLetter + 'axis'];
  67533. var hasBothSides = trace.side === 'both';
  67534. var hasPositiveSide = hasBothSides || trace.side === 'positive';
  67535. var hasNegativeSide = hasBothSides || trace.side === 'negative';
  67536. var groupStats = fullLayout._violinScaleGroupStats[trace.scalegroup];
  67537. var violins = plotGroup.selectAll('path.violin').data(Lib.identity);
  67538. violins.enter().append('path')
  67539. .style('vector-effect', 'non-scaling-stroke')
  67540. .attr('class', 'violin');
  67541. violins.exit().remove();
  67542. violins.each(function(d) {
  67543. var pathSel = d3.select(this);
  67544. var density = d.density;
  67545. var len = density.length;
  67546. var posCenter = d.pos + bPos;
  67547. var posCenterPx = posAxis.c2p(posCenter);
  67548. var scale;
  67549. switch(trace.scalemode) {
  67550. case 'width':
  67551. scale = groupStats.maxWidth / bdPos;
  67552. break;
  67553. case 'count':
  67554. scale = (groupStats.maxWidth / bdPos) * (groupStats.maxCount / d.pts.length);
  67555. break;
  67556. }
  67557. var pathPos, pathNeg, path;
  67558. var i, k, pts, pt;
  67559. if(hasPositiveSide) {
  67560. pts = new Array(len);
  67561. for(i = 0; i < len; i++) {
  67562. pt = pts[i] = {};
  67563. pt[t.posLetter] = posCenter + (density[i].v / scale);
  67564. pt[t.valLetter] = density[i].t;
  67565. }
  67566. pathPos = makePath(pts);
  67567. }
  67568. if(hasNegativeSide) {
  67569. pts = new Array(len);
  67570. for(k = 0, i = len - 1; k < len; k++, i--) {
  67571. pt = pts[k] = {};
  67572. pt[t.posLetter] = posCenter - (density[i].v / scale);
  67573. pt[t.valLetter] = density[i].t;
  67574. }
  67575. pathNeg = makePath(pts);
  67576. }
  67577. if(hasBothSides) {
  67578. path = pathPos + 'L' + pathNeg.substr(1) + 'Z';
  67579. }
  67580. else {
  67581. var startPt = [posCenterPx, valAxis.c2p(density[0].t)];
  67582. var endPt = [posCenterPx, valAxis.c2p(density[len - 1].t)];
  67583. if(trace.orientation === 'h') {
  67584. startPt.reverse();
  67585. endPt.reverse();
  67586. }
  67587. if(hasPositiveSide) {
  67588. path = 'M' + startPt + 'L' + pathPos.substr(1) + 'L' + endPt;
  67589. } else {
  67590. path = 'M' + endPt + 'L' + pathNeg.substr(1) + 'L' + startPt;
  67591. }
  67592. }
  67593. pathSel.attr('d', path);
  67594. // save a few things used in getPositionOnKdePath, getKdeValue
  67595. // on hover and for meanline draw block below
  67596. d.posCenterPx = posCenterPx;
  67597. d.posDensityScale = scale * bdPos;
  67598. d.path = pathSel.node();
  67599. d.pathLength = d.path.getTotalLength() / (hasBothSides ? 2 : 1);
  67600. });
  67601. var boxAttrs = trace.box;
  67602. var boxWidth = boxAttrs.width;
  67603. var boxLineWidth = (boxAttrs.line || {}).width;
  67604. var bdPosScaled;
  67605. var bPosPxOffset;
  67606. if(hasBothSides) {
  67607. bdPosScaled = bdPos * boxWidth;
  67608. bPosPxOffset = 0;
  67609. } else if(hasPositiveSide) {
  67610. bdPosScaled = [0, bdPos * boxWidth / 2];
  67611. bPosPxOffset = -boxLineWidth;
  67612. } else {
  67613. bdPosScaled = [bdPos * boxWidth / 2, 0];
  67614. bPosPxOffset = boxLineWidth;
  67615. }
  67616. // inner box
  67617. boxPlot.plotBoxAndWhiskers(plotGroup, {pos: posAxis, val: valAxis}, trace, {
  67618. bPos: bPos,
  67619. bdPos: bdPosScaled,
  67620. bPosPxOffset: bPosPxOffset
  67621. });
  67622. // meanline insider box
  67623. boxPlot.plotBoxMean(plotGroup, {pos: posAxis, val: valAxis}, trace, {
  67624. bPos: bPos,
  67625. bdPos: bdPosScaled,
  67626. bPosPxOffset: bPosPxOffset
  67627. });
  67628. var fn;
  67629. if(!trace.box.visible && trace.meanline.visible) {
  67630. fn = Lib.identity;
  67631. }
  67632. // N.B. use different class name than boxPlot.plotBoxMean,
  67633. // to avoid selectAll conflict
  67634. var meanPaths = plotGroup.selectAll('path.meanline').data(fn || []);
  67635. meanPaths.enter().append('path')
  67636. .attr('class', 'meanline')
  67637. .style('fill', 'none')
  67638. .style('vector-effect', 'non-scaling-stroke');
  67639. meanPaths.exit().remove();
  67640. meanPaths.each(function(d) {
  67641. var v = valAxis.c2p(d.mean, true);
  67642. var p = helpers.getPositionOnKdePath(d, trace, v);
  67643. d3.select(this).attr('d',
  67644. trace.orientation === 'h' ?
  67645. 'M' + v + ',' + p[0] + 'V' + p[1] :
  67646. 'M' + p[0] + ',' + v + 'H' + p[1]
  67647. );
  67648. });
  67649. boxPlot.plotPoints(plotGroup, {x: xa, y: ya}, trace, t);
  67650. });
  67651. };
  67652. },{"../../components/drawing":75,"../../lib":169,"../box/plot":291,"../scatter/line_points":380,"./helpers":404,"d3":16}],410:[function(_dereq_,module,exports){
  67653. /**
  67654. * Copyright 2012-2018, Plotly, Inc.
  67655. * All rights reserved.
  67656. *
  67657. * This source code is licensed under the MIT license found in the
  67658. * LICENSE file in the root directory of this source tree.
  67659. */
  67660. 'use strict';
  67661. var d3 = _dereq_('d3');
  67662. var Color = _dereq_('../../components/color');
  67663. var stylePoints = _dereq_('../scatter/style').stylePoints;
  67664. module.exports = function style(gd, cd) {
  67665. var s = cd ? cd[0].node3 : d3.select(gd).selectAll('g.trace.violins');
  67666. s.style('opacity', function(d) { return d[0].trace.opacity; });
  67667. s.each(function(d) {
  67668. var trace = d[0].trace;
  67669. var sel = d3.select(this);
  67670. var box = trace.box || {};
  67671. var boxLine = box.line || {};
  67672. var meanline = trace.meanline || {};
  67673. var meanLineWidth = meanline.width;
  67674. sel.selectAll('path.violin')
  67675. .style('stroke-width', trace.line.width + 'px')
  67676. .call(Color.stroke, trace.line.color)
  67677. .call(Color.fill, trace.fillcolor);
  67678. sel.selectAll('path.box')
  67679. .style('stroke-width', boxLine.width + 'px')
  67680. .call(Color.stroke, boxLine.color)
  67681. .call(Color.fill, box.fillcolor);
  67682. var meanLineStyle = {
  67683. 'stroke-width': meanLineWidth + 'px',
  67684. 'stroke-dasharray': (2 * meanLineWidth) + 'px,' + meanLineWidth + 'px'
  67685. };
  67686. sel.selectAll('path.mean')
  67687. .style(meanLineStyle)
  67688. .call(Color.stroke, meanline.color);
  67689. sel.selectAll('path.meanline')
  67690. .style(meanLineStyle)
  67691. .call(Color.stroke, meanline.color);
  67692. stylePoints(sel, trace, gd);
  67693. });
  67694. };
  67695. },{"../../components/color":50,"../scatter/style":389,"d3":16}]},{},[11])(11)
  67696. });