index.js 603 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640
  1. (function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
  3. typeof define === 'function' && define.amd ? define(['exports'], factory) :
  4. (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.F2 = {}));
  5. }(this, (function (exports) { 'use strict';
  6. function getDefaultExportFromCjs (x) {
  7. return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
  8. }
  9. function createCommonjsModule(fn, basedir, module) {
  10. return module = {
  11. path: basedir,
  12. exports: {},
  13. require: function (path, base) {
  14. return commonjsRequire(path, (base === undefined || base === null) ? module.path : base);
  15. }
  16. }, fn(module, module.exports), module.exports;
  17. }
  18. function commonjsRequire () {
  19. throw new Error('Dynamic requires are not currently supported by @rollup/plugin-commonjs');
  20. }
  21. var _typeof_1 = createCommonjsModule(function (module) {
  22. function _typeof(obj) {
  23. "@babel/helpers - typeof";
  24. return (module.exports = _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
  25. return typeof obj;
  26. } : function (obj) {
  27. return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  28. }, module.exports.__esModule = true, module.exports["default"] = module.exports), _typeof(obj);
  29. }
  30. module.exports = _typeof, module.exports.__esModule = true, module.exports["default"] = module.exports;
  31. });
  32. var _typeof = /*@__PURE__*/getDefaultExportFromCjs(_typeof_1);
  33. var toPrimitive = createCommonjsModule(function (module) {
  34. var _typeof = _typeof_1["default"];
  35. function _toPrimitive(input, hint) {
  36. if (_typeof(input) !== "object" || input === null) return input;
  37. var prim = input[Symbol.toPrimitive];
  38. if (prim !== undefined) {
  39. var res = prim.call(input, hint || "default");
  40. if (_typeof(res) !== "object") return res;
  41. throw new TypeError("@@toPrimitive must return a primitive value.");
  42. }
  43. return (hint === "string" ? String : Number)(input);
  44. }
  45. module.exports = _toPrimitive, module.exports.__esModule = true, module.exports["default"] = module.exports;
  46. });
  47. var toPropertyKey = createCommonjsModule(function (module) {
  48. var _typeof = _typeof_1["default"];
  49. function _toPropertyKey(arg) {
  50. var key = toPrimitive(arg, "string");
  51. return _typeof(key) === "symbol" ? key : String(key);
  52. }
  53. module.exports = _toPropertyKey, module.exports.__esModule = true, module.exports["default"] = module.exports;
  54. });
  55. var defineProperty = createCommonjsModule(function (module) {
  56. function _defineProperty(obj, key, value) {
  57. key = toPropertyKey(key);
  58. if (key in obj) {
  59. Object.defineProperty(obj, key, {
  60. value: value,
  61. enumerable: true,
  62. configurable: true,
  63. writable: true
  64. });
  65. } else {
  66. obj[key] = value;
  67. }
  68. return obj;
  69. }
  70. module.exports = _defineProperty, module.exports.__esModule = true, module.exports["default"] = module.exports;
  71. });
  72. var _defineProperty = /*@__PURE__*/getDefaultExportFromCjs(defineProperty);
  73. var objectSpread2 = createCommonjsModule(function (module) {
  74. function ownKeys(object, enumerableOnly) {
  75. var keys = Object.keys(object);
  76. if (Object.getOwnPropertySymbols) {
  77. var symbols = Object.getOwnPropertySymbols(object);
  78. enumerableOnly && (symbols = symbols.filter(function (sym) {
  79. return Object.getOwnPropertyDescriptor(object, sym).enumerable;
  80. })), keys.push.apply(keys, symbols);
  81. }
  82. return keys;
  83. }
  84. function _objectSpread2(target) {
  85. for (var i = 1; i < arguments.length; i++) {
  86. var source = null != arguments[i] ? arguments[i] : {};
  87. i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
  88. defineProperty(target, key, source[key]);
  89. }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
  90. Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
  91. });
  92. }
  93. return target;
  94. }
  95. module.exports = _objectSpread2, module.exports.__esModule = true, module.exports["default"] = module.exports;
  96. });
  97. var _objectSpread = /*@__PURE__*/getDefaultExportFromCjs(objectSpread2);
  98. var isArrayLike = function (value) {
  99. /**
  100. * isArrayLike([1, 2, 3]) => true
  101. * isArrayLike(document.body.children) => true
  102. * isArrayLike('abc') => true
  103. * isArrayLike(Function) => false
  104. */
  105. return value !== null && typeof value !== 'function' && isFinite(value.length);
  106. };
  107. var filter = function (arr, func) {
  108. if (!isArrayLike(arr)) {
  109. return arr;
  110. }
  111. var result = [];
  112. for (var index = 0; index < arr.length; index++) {
  113. var value = arr[index];
  114. if (func(value, index)) {
  115. result.push(value);
  116. }
  117. }
  118. return result;
  119. };
  120. var toString = {}.toString;
  121. var isType = function (value, type) { return toString.call(value) === '[object ' + type + ']'; };
  122. /**
  123. * 是否为函数
  124. * @param {*} fn 对象
  125. * @return {Boolean} 是否函数
  126. */
  127. var isFunction = (function (value) {
  128. return isType(value, 'Function');
  129. });
  130. // isFinite,
  131. var isNil = function (value) {
  132. /**
  133. * isNil(null) => true
  134. * isNil() => true
  135. */
  136. return value === null || value === undefined;
  137. };
  138. var isArray = (function (value) {
  139. return Array.isArray ?
  140. Array.isArray(value) :
  141. isType(value, 'Array');
  142. });
  143. var isObject = (function (value) {
  144. /**
  145. * isObject({}) => true
  146. * isObject([1, 2, 3]) => true
  147. * isObject(Function) => true
  148. * isObject(null) => false
  149. */
  150. var type = typeof value;
  151. return value !== null && type === 'object' || type === 'function';
  152. });
  153. function each(elements, func) {
  154. if (!elements) {
  155. return;
  156. }
  157. var rst;
  158. if (isArray(elements)) {
  159. for (var i = 0, len = elements.length; i < len; i++) {
  160. rst = func(elements[i], i);
  161. if (rst === false) {
  162. break;
  163. }
  164. }
  165. }
  166. else if (isObject(elements)) {
  167. for (var k in elements) {
  168. if (elements.hasOwnProperty(k)) {
  169. rst = func(elements[k], k);
  170. if (rst === false) {
  171. break;
  172. }
  173. }
  174. }
  175. }
  176. }
  177. var keys = Object.keys ? function (obj) { return Object.keys(obj); } : function (obj) {
  178. var result = [];
  179. each(obj, function (value, key) {
  180. if (!(isFunction(obj) && key === 'prototype')) {
  181. result.push(key);
  182. }
  183. });
  184. return result;
  185. };
  186. function isMatch(obj, attrs) {
  187. var _keys = keys(attrs);
  188. var length = _keys.length;
  189. if (isNil(obj))
  190. return !length;
  191. for (var i = 0; i < length; i += 1) {
  192. var key = _keys[i];
  193. if (attrs[key] !== obj[key] || !(key in obj)) {
  194. return false;
  195. }
  196. }
  197. return true;
  198. }
  199. var isObjectLike = function (value) {
  200. /**
  201. * isObjectLike({}) => true
  202. * isObjectLike([1, 2, 3]) => true
  203. * isObjectLike(Function) => false
  204. * isObjectLike(null) => false
  205. */
  206. return typeof value === 'object' && value !== null;
  207. };
  208. var isPlainObject = function (value) {
  209. /**
  210. * isObjectLike(new Foo) => false
  211. * isObjectLike([1, 2, 3]) => false
  212. * isObjectLike({ x: 0, y: 0 }) => true
  213. * isObjectLike(Object.create(null)) => true
  214. */
  215. if (!isObjectLike(value) || !isType(value, 'Object')) {
  216. return false;
  217. }
  218. if (Object.getPrototypeOf(value) === null) {
  219. return true;
  220. }
  221. var proto = value;
  222. while (Object.getPrototypeOf(proto) !== null) {
  223. proto = Object.getPrototypeOf(proto);
  224. }
  225. return Object.getPrototypeOf(value) === proto;
  226. };
  227. function find(arr, predicate) {
  228. if (!isArray(arr))
  229. return null;
  230. var _predicate;
  231. if (isFunction(predicate)) {
  232. _predicate = predicate;
  233. }
  234. if (isPlainObject(predicate)) {
  235. _predicate = function (a) { return isMatch(a, predicate); };
  236. }
  237. if (_predicate) {
  238. for (var i = 0; i < arr.length; i += 1) {
  239. if (_predicate(arr[i])) {
  240. return arr[i];
  241. }
  242. }
  243. }
  244. return null;
  245. }
  246. function findIndex(arr, predicate, fromIndex) {
  247. if (fromIndex === void 0) { fromIndex = 0; }
  248. for (var i = fromIndex; i < arr.length; i++) {
  249. if (predicate(arr[i], i)) {
  250. // 找到终止循环
  251. return i;
  252. }
  253. }
  254. return -1;
  255. }
  256. /**
  257. * Flattens `array` a single level deep.
  258. *
  259. * @param {Array} arr The array to flatten.
  260. * @return {Array} Returns the new flattened array.
  261. * @example
  262. *
  263. * flatten([1, [2, [3, [4]], 5]]); // => [1, 2, [3, [4]], 5]
  264. */
  265. var flatten = function (arr) {
  266. if (!isArray(arr)) {
  267. return [];
  268. }
  269. var rst = [];
  270. for (var i = 0; i < arr.length; i++) {
  271. rst = rst.concat(arr[i]);
  272. }
  273. return rst;
  274. };
  275. /**
  276. * @param {Array} arr The array to iterate over.
  277. * @return {*} Returns the maximum value.
  278. * @example
  279. *
  280. * max([1, 2]);
  281. * // => 2
  282. *
  283. * max([]);
  284. * // => undefined
  285. *
  286. * const data = new Array(1250010).fill(1).map((d,idx) => idx);
  287. *
  288. * max(data);
  289. * // => 1250010
  290. * // Math.max(...data) will encounter "Maximum call stack size exceeded" error
  291. */
  292. var getMax = (function (arr) {
  293. if (!isArray(arr)) {
  294. return undefined;
  295. }
  296. return arr.reduce(function (prev, curr) {
  297. return Math.max(prev, curr);
  298. }, arr[0]);
  299. });
  300. /**
  301. * @param {Array} arr The array to iterate over.
  302. * @return {*} Returns the minimum value.
  303. * @example
  304. *
  305. * min([1, 2]);
  306. * // => 1
  307. *
  308. * min([]);
  309. * // => undefined
  310. *
  311. * const data = new Array(1250010).fill(1).map((d,idx) => idx);
  312. *
  313. * min(data);
  314. * // => 1250010
  315. * // Math.min(...data) will encounter "Maximum call stack size exceeded" error
  316. */
  317. var getMin = (function (arr) {
  318. if (!isArray(arr)) {
  319. return undefined;
  320. }
  321. return arr.reduce(function (prev, curr) {
  322. return Math.min(prev, curr);
  323. }, arr[0]);
  324. });
  325. var getRange = function (values) {
  326. // 存在 NaN 时,min,max 判定会出问题
  327. var filterValues = values.filter(function (v) { return !isNaN(v); });
  328. if (!filterValues.length) {
  329. // 如果没有数值则直接返回0
  330. return {
  331. min: 0,
  332. max: 0,
  333. };
  334. }
  335. if (isArray(values[0])) {
  336. var tmp = [];
  337. for (var i = 0; i < values.length; i++) {
  338. tmp = tmp.concat(values[i]);
  339. }
  340. filterValues = tmp;
  341. }
  342. var max = getMax(filterValues);
  343. var min = getMin(filterValues);
  344. return {
  345. min: min,
  346. max: max,
  347. };
  348. };
  349. var reduce = function (arr, fn, init) {
  350. if (!isArray(arr) && !isPlainObject(arr)) {
  351. return arr;
  352. }
  353. var result = init;
  354. each(arr, function (data, i) {
  355. result = fn(result, data, i);
  356. });
  357. return result;
  358. };
  359. var isString = (function (str) {
  360. return isType(str, 'String');
  361. });
  362. var valuesOfKey = (function (data, name) {
  363. var rst = [];
  364. var tmpMap = {};
  365. for (var i = 0; i < data.length; i++) {
  366. var obj = data[i];
  367. var value = obj[name];
  368. if (!isNil(value)) {
  369. // flatten
  370. if (!isArray(value)) {
  371. value = [value];
  372. }
  373. for (var j = 0; j < value.length; j++) {
  374. var val = value[j];
  375. // unique
  376. if (!tmpMap[val]) {
  377. rst.push(val);
  378. tmpMap[val] = true;
  379. }
  380. }
  381. }
  382. }
  383. return rst;
  384. });
  385. function head(o) {
  386. if (isArrayLike(o)) {
  387. return o[0];
  388. }
  389. return undefined;
  390. }
  391. function last(o) {
  392. if (isArrayLike(o)) {
  393. var arr = o;
  394. return arr[arr.length - 1];
  395. }
  396. return undefined;
  397. }
  398. var hasOwnProperty = Object.prototype.hasOwnProperty;
  399. function groupBy(data, condition) {
  400. if (!condition || !isArray(data)) {
  401. return {};
  402. }
  403. var result = {};
  404. // 兼容方法和 字符串的写法
  405. var predicate = isFunction(condition) ? condition : function (item) { return item[condition]; };
  406. var key;
  407. for (var i = 0; i < data.length; i++) {
  408. var item = data[i];
  409. key = predicate(item);
  410. if (hasOwnProperty.call(result, key)) {
  411. result[key].push(item);
  412. }
  413. else {
  414. result[key] = [item];
  415. }
  416. }
  417. return result;
  418. }
  419. /**
  420. * 将数据分组成 map
  421. * @param data
  422. * @param condition
  423. */
  424. function groupToMap(data, condition) {
  425. if (!condition) {
  426. return {
  427. 0: data,
  428. };
  429. }
  430. if (!isFunction(condition)) {
  431. // 如果是字符串,则按照 a*b 风格成数组
  432. var paramscondition_1 = isArray(condition) ? condition : condition.replace(/\s+/g, '').split('*');
  433. condition = function (row) {
  434. var unique = '_'; // 避免出现数字作为Key的情况,会进行按照数字的排序
  435. // 根据字段列表的值,拼接成 key
  436. for (var i = 0, l = paramscondition_1.length; i < l; i++) {
  437. unique += row[paramscondition_1[i]] && row[paramscondition_1[i]].toString();
  438. }
  439. return unique;
  440. };
  441. }
  442. return groupBy(data, condition);
  443. }
  444. var group = (function (data, condition) {
  445. if (!condition) {
  446. // 没有条件,则自身改成数组
  447. return [data];
  448. }
  449. var groups = groupToMap(data, condition);
  450. var array = [];
  451. for (var i in groups) {
  452. array.push(groups[i]);
  453. }
  454. return array;
  455. });
  456. var fixedBase = function (v, base) {
  457. var str = base.toString();
  458. var index = str.indexOf('.');
  459. if (index === -1) {
  460. return Math.round(v);
  461. }
  462. var length = str.substr(index + 1).length;
  463. if (length > 20) {
  464. length = 20;
  465. }
  466. return parseFloat(v.toFixed(length));
  467. };
  468. /**
  469. * 判断是否数字
  470. * @return {Boolean} 是否数字
  471. */
  472. var isNumber = function (value) {
  473. return isType(value, 'Number');
  474. };
  475. var PRECISION = 0.00001; // numbers less than this is considered as 0
  476. function isNumberEqual(a, b, precision) {
  477. if (precision === void 0) { precision = PRECISION; }
  478. return Math.abs((a - b)) < precision;
  479. }
  480. // @ts-ignore
  481. var values = Object.values ? function (obj) { return Object.values(obj); } : function (obj) {
  482. var result = [];
  483. each(obj, function (value, key) {
  484. if (!(isFunction(obj) && key === 'prototype')) {
  485. result.push(value);
  486. }
  487. });
  488. return result;
  489. };
  490. var toString$1 = (function (value) {
  491. if (isNil(value))
  492. return '';
  493. return value.toString();
  494. });
  495. function substitute(str, o) {
  496. if (!str || !o) {
  497. return str;
  498. }
  499. return str.replace(/\\?\{([^{}]+)\}/g, function (match, name) {
  500. if (match.charAt(0) === '\\') {
  501. return match.slice(1);
  502. }
  503. return (o[name] === undefined) ? '' : o[name];
  504. });
  505. }
  506. var upperFirst = function (value) {
  507. var str = toString$1(value);
  508. return str.charAt(0).toUpperCase() + str.substring(1);
  509. };
  510. var toString$2 = {}.toString;
  511. var getType = function (value) {
  512. return toString$2.call(value).replace(/^\[object /, '').replace(/]$/, '');
  513. };
  514. /**
  515. * 是否是布尔类型
  516. *
  517. * @param {Object} value 测试的值
  518. * @return {Boolean}
  519. */
  520. var isBoolean = function (value) {
  521. return isType(value, 'Boolean');
  522. };
  523. var isDate = function (value) {
  524. return isType(value, 'Date');
  525. };
  526. var objectProto = Object.prototype;
  527. var isPrototype = function (value) {
  528. var Ctor = value && value.constructor;
  529. var proto = (typeof Ctor === 'function' && Ctor.prototype) || objectProto;
  530. return value === proto;
  531. };
  532. var isUndefined = function (value) {
  533. return value === undefined;
  534. };
  535. // FIXME: Mutable param should be forbidden in static lang.
  536. function _mix(dist, obj) {
  537. for (var key in obj) {
  538. if (obj.hasOwnProperty(key) && key !== 'constructor' && obj[key] !== undefined) {
  539. dist[key] = obj[key];
  540. }
  541. }
  542. }
  543. function mix(dist, src1, src2, src3) {
  544. if (src1)
  545. _mix(dist, src1);
  546. if (src2)
  547. _mix(dist, src2);
  548. if (src3)
  549. _mix(dist, src3);
  550. return dist;
  551. }
  552. var clone = function (obj) {
  553. if (typeof obj !== 'object' || obj === null) {
  554. return obj;
  555. }
  556. var rst;
  557. if (isArray(obj)) {
  558. rst = [];
  559. for (var i = 0, l = obj.length; i < l; i++) {
  560. if (typeof obj[i] === 'object' && obj[i] != null) {
  561. rst[i] = clone(obj[i]);
  562. }
  563. else {
  564. rst[i] = obj[i];
  565. }
  566. }
  567. }
  568. else {
  569. rst = {};
  570. for (var k in obj) {
  571. if (typeof obj[k] === 'object' && obj[k] != null) {
  572. rst[k] = clone(obj[k]);
  573. }
  574. else {
  575. rst[k] = obj[k];
  576. }
  577. }
  578. }
  579. return rst;
  580. };
  581. /**
  582. * _.memoize(calColor);
  583. * _.memoize(calColor, (...args) => args[0]);
  584. * @param f
  585. * @param resolver
  586. */
  587. var memoize = (function (f, resolver) {
  588. if (!isFunction(f)) {
  589. throw new TypeError('Expected a function');
  590. }
  591. var memoized = function () {
  592. var args = [];
  593. for (var _i = 0; _i < arguments.length; _i++) {
  594. args[_i] = arguments[_i];
  595. }
  596. // 使用方法构造 key,如果不存在 resolver,则直接取第一个参数作为 key
  597. var key = resolver ? resolver.apply(this, args) : args[0];
  598. var cache = memoized.cache;
  599. if (cache.has(key)) {
  600. return cache.get(key);
  601. }
  602. var result = f.apply(this, args);
  603. // 缓存起来
  604. cache.set(key, result);
  605. return result;
  606. };
  607. memoized.cache = new Map();
  608. return memoized;
  609. });
  610. var MAX_MIX_LEVEL = 5;
  611. function _deepMix(dist, src, level, maxLevel) {
  612. level = level || 0;
  613. maxLevel = maxLevel || MAX_MIX_LEVEL;
  614. for (var key in src) {
  615. if (src.hasOwnProperty(key)) {
  616. var value = src[key];
  617. if (value !== null && isPlainObject(value)) {
  618. if (!isPlainObject(dist[key])) {
  619. dist[key] = {};
  620. }
  621. if (level < maxLevel) {
  622. _deepMix(dist[key], value, level + 1, maxLevel);
  623. }
  624. else {
  625. dist[key] = src[key];
  626. }
  627. }
  628. else if (isArray(value)) {
  629. dist[key] = [];
  630. dist[key] = dist[key].concat(value);
  631. }
  632. else if (value !== undefined) {
  633. dist[key] = value;
  634. }
  635. }
  636. }
  637. }
  638. // todo 重写
  639. var deepMix = function (rst) {
  640. var args = [];
  641. for (var _i = 1; _i < arguments.length; _i++) {
  642. args[_i - 1] = arguments[_i];
  643. }
  644. for (var i = 0; i < args.length; i += 1) {
  645. _deepMix(rst, args[i]);
  646. }
  647. return rst;
  648. };
  649. var indexOf = function (arr, obj) {
  650. if (!isArrayLike(arr)) {
  651. return -1;
  652. }
  653. var m = Array.prototype.indexOf;
  654. if (m) {
  655. return m.call(arr, obj);
  656. }
  657. var index = -1;
  658. for (var i = 0; i < arr.length; i++) {
  659. if (arr[i] === obj) {
  660. index = i;
  661. break;
  662. }
  663. }
  664. return index;
  665. };
  666. var hasOwnProperty$1 = Object.prototype.hasOwnProperty;
  667. function isEmpty(value) {
  668. /**
  669. * isEmpty(null) => true
  670. * isEmpty() => true
  671. * isEmpty(true) => true
  672. * isEmpty(1) => true
  673. * isEmpty([1, 2, 3]) => false
  674. * isEmpty('abc') => false
  675. * isEmpty({ a: 1 }) => false
  676. */
  677. if (isNil(value)) {
  678. return true;
  679. }
  680. if (isArrayLike(value)) {
  681. return !value.length;
  682. }
  683. var type = getType(value);
  684. if (type === 'Map' || type === 'Set') {
  685. return !value.size;
  686. }
  687. if (isPrototype(value)) {
  688. return !Object.keys(value).length;
  689. }
  690. for (var key in value) {
  691. if (hasOwnProperty$1.call(value, key)) {
  692. return false;
  693. }
  694. }
  695. return true;
  696. }
  697. var map = function (arr, func) {
  698. if (!isArrayLike(arr)) {
  699. // @ts-ignore
  700. return arr;
  701. }
  702. var result = [];
  703. for (var index = 0; index < arr.length; index++) {
  704. var value = arr[index];
  705. result.push(func(value, index));
  706. }
  707. return result;
  708. };
  709. var identity = function (v) { return v; };
  710. var mapValues = (function (object, func) {
  711. if (func === void 0) { func = identity; }
  712. var r = {};
  713. if (isObject(object) && !isNil(object)) {
  714. Object.keys(object).forEach(function (key) {
  715. // @ts-ignore
  716. r[key] = func(object[key], key);
  717. });
  718. }
  719. return r;
  720. });
  721. /**
  722. * https://github.com/developit/dlv/blob/master/index.js
  723. * @param obj
  724. * @param key
  725. * @param defaultValue
  726. */
  727. var get = (function (obj, key, defaultValue) {
  728. var p = 0;
  729. var keyArr = isString(key) ? key.split('.') : key;
  730. while (obj && p < keyArr.length) {
  731. obj = obj[keyArr[p++]];
  732. }
  733. return (obj === undefined || p < keyArr.length) ? defaultValue : obj;
  734. });
  735. var hasOwnProperty$2 = Object.prototype.hasOwnProperty;
  736. var pick = (function (object, keys) {
  737. if (object === null || !isPlainObject(object)) {
  738. return {};
  739. }
  740. var result = {};
  741. each(keys, function (key) {
  742. if (hasOwnProperty$2.call(object, key)) {
  743. result[key] = object[key];
  744. }
  745. });
  746. return result;
  747. });
  748. var omit = (function (obj, keys) {
  749. return reduce(obj, function (r, curr, key) {
  750. if (!keys.includes(key)) {
  751. r[key] = curr;
  752. }
  753. return r;
  754. }, {});
  755. });
  756. function size(o) {
  757. if (isNil(o)) {
  758. return 0;
  759. }
  760. if (isArrayLike(o)) {
  761. return o.length;
  762. }
  763. return Object.keys(o).length;
  764. }
  765. /******************************************************************************
  766. Copyright (c) Microsoft Corporation.
  767. Permission to use, copy, modify, and/or distribute this software for any
  768. purpose with or without fee is hereby granted.
  769. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
  770. REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  771. AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
  772. INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  773. LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  774. OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  775. PERFORMANCE OF THIS SOFTWARE.
  776. ***************************************************************************** */
  777. /* global Reflect, Promise */
  778. var extendStatics = function(d, b) {
  779. extendStatics = Object.setPrototypeOf ||
  780. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  781. function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
  782. return extendStatics(d, b);
  783. };
  784. function __extends(d, b) {
  785. if (typeof b !== "function" && b !== null)
  786. throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
  787. extendStatics(d, b);
  788. function __() { this.constructor = d; }
  789. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  790. }
  791. var __assign = function() {
  792. __assign = Object.assign || function __assign(t) {
  793. for (var s, i = 1, n = arguments.length; i < n; i++) {
  794. s = arguments[i];
  795. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
  796. }
  797. return t;
  798. };
  799. return __assign.apply(this, arguments);
  800. };
  801. /** @deprecated */
  802. function __spreadArrays() {
  803. for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
  804. for (var r = Array(s), k = 0, i = 0; i < il; i++)
  805. for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
  806. r[k] = a[j];
  807. return r;
  808. }
  809. var ctx;
  810. /**
  811. * 计算文本的宽度
  812. */
  813. memoize(function (text, font) {
  814. if (font === void 0) { font = {}; }
  815. var fontSize = font.fontSize, fontFamily = font.fontFamily, fontWeight = font.fontWeight, fontStyle = font.fontStyle, fontVariant = font.fontVariant;
  816. if (!ctx) {
  817. ctx = document.createElement('canvas').getContext('2d');
  818. }
  819. ctx.font = [fontStyle, fontVariant, fontWeight, fontSize + "px", fontFamily].join(' ');
  820. return ctx.measureText(isString(text) ? text : '').width;
  821. }, function (text, font) {
  822. if (font === void 0) { font = {}; }
  823. return __spreadArrays([text], values(font)).join('');
  824. });
  825. /**
  826. * k-v 存储
  827. */
  828. var default_1 = /** @class */ (function () {
  829. function default_1() {
  830. this.map = {};
  831. }
  832. default_1.prototype.has = function (key) {
  833. return this.map[key] !== undefined;
  834. };
  835. default_1.prototype.get = function (key, def) {
  836. var v = this.map[key];
  837. return v === undefined ? def : v;
  838. };
  839. default_1.prototype.set = function (key, value) {
  840. this.map[key] = value;
  841. };
  842. default_1.prototype.clear = function () {
  843. this.map = {};
  844. };
  845. default_1.prototype.delete = function (key) {
  846. delete this.map[key];
  847. };
  848. default_1.prototype.size = function () {
  849. return Object.keys(this.map).length;
  850. };
  851. return default_1;
  852. }());
  853. function cloneElement(element, props) {
  854. if (!element) return element;
  855. return _objectSpread(_objectSpread({}, element), {}, {
  856. props: _objectSpread(_objectSpread({}, element.props), props)
  857. });
  858. }
  859. function map$1(children, fn) {
  860. if (!children) {
  861. return fn(children);
  862. }
  863. if (isArray(children)) {
  864. return children.map(function (child) {
  865. return map$1(child, fn);
  866. });
  867. }
  868. return fn(children);
  869. }
  870. function compareArray(nextElements, lastElements, callback) {
  871. var keyed = {};
  872. var nextLength = nextElements.length;
  873. var lastLength = lastElements.length;
  874. for (var i = 0, len = lastLength; i < len; i++) {
  875. var element = lastElements[i];
  876. if (element && !isNil(element.key)) {
  877. var key = element.key;
  878. keyed[key] = element;
  879. }
  880. }
  881. // 比较元素
  882. for (var _i = 0, _len = Math.max(nextLength, lastLength); _i < _len; _i++) {
  883. var _element = nextElements[_i];
  884. if (!_element) {
  885. compare(_element, lastElements[_i], callback);
  886. continue;
  887. }
  888. var _key = _element.key;
  889. // 有key值定义
  890. if (!isNil(_element.key)) {
  891. var lastElement = keyed[_key];
  892. if (lastElement) delete keyed[_key];
  893. compare(_element, lastElement, callback);
  894. continue;
  895. }
  896. compare(_element, lastElements[_i], callback);
  897. }
  898. // 说明是删除的元素
  899. Object.keys(keyed).forEach(function (key) {
  900. compare(null, keyed[key], callback);
  901. });
  902. }
  903. // 比较2棵树
  904. function compare(nextElement, lastElement, callback) {
  905. // 有一个为空
  906. if (!nextElement || !lastElement) {
  907. callback(nextElement, lastElement);
  908. return;
  909. }
  910. if (isArray(nextElement) || isArray(lastElement)) {
  911. var nextElementArray = isArray(nextElement) ? nextElement : [nextElement];
  912. var lastElementArray = isArray(lastElement) ? lastElement : [lastElement];
  913. compareArray(nextElementArray, lastElementArray, callback);
  914. return;
  915. }
  916. callback(nextElement, lastElement);
  917. }
  918. function toArray(element) {
  919. if (!element) {
  920. return element;
  921. }
  922. if (!isArray(element)) {
  923. return [element];
  924. }
  925. var newArray = [];
  926. for (var i = 0, len = element.length; i < len; i++) {
  927. var item = element[i];
  928. if (isArray(item)) {
  929. // @ts-ignore
  930. newArray = newArray.concat(toArray(item));
  931. } else {
  932. newArray.push(item);
  933. }
  934. }
  935. return newArray;
  936. }
  937. var Children = {
  938. cloneElement: cloneElement,
  939. map: map$1,
  940. toArray: toArray,
  941. compare: compare
  942. };
  943. var classCallCheck = createCommonjsModule(function (module) {
  944. function _classCallCheck(instance, Constructor) {
  945. if (!(instance instanceof Constructor)) {
  946. throw new TypeError("Cannot call a class as a function");
  947. }
  948. }
  949. module.exports = _classCallCheck, module.exports.__esModule = true, module.exports["default"] = module.exports;
  950. });
  951. var _classCallCheck = /*@__PURE__*/getDefaultExportFromCjs(classCallCheck);
  952. var createClass = createCommonjsModule(function (module) {
  953. function _defineProperties(target, props) {
  954. for (var i = 0; i < props.length; i++) {
  955. var descriptor = props[i];
  956. descriptor.enumerable = descriptor.enumerable || false;
  957. descriptor.configurable = true;
  958. if ("value" in descriptor) descriptor.writable = true;
  959. Object.defineProperty(target, toPropertyKey(descriptor.key), descriptor);
  960. }
  961. }
  962. function _createClass(Constructor, protoProps, staticProps) {
  963. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  964. if (staticProps) _defineProperties(Constructor, staticProps);
  965. Object.defineProperty(Constructor, "prototype", {
  966. writable: false
  967. });
  968. return Constructor;
  969. }
  970. module.exports = _createClass, module.exports.__esModule = true, module.exports["default"] = module.exports;
  971. });
  972. var _createClass = /*@__PURE__*/getDefaultExportFromCjs(createClass);
  973. var Component = /*#__PURE__*/function () {
  974. function Component(props, context, updater) {
  975. _classCallCheck(this, Component);
  976. this.destroyed = false;
  977. this.props = props;
  978. this.state = {};
  979. this.context = context;
  980. this.updater = updater;
  981. }
  982. _createClass(Component, [{
  983. key: "willMount",
  984. value: function willMount() {}
  985. }, {
  986. key: "didMount",
  987. value: function didMount() {}
  988. }, {
  989. key: "willReceiveProps",
  990. value: function willReceiveProps(_props, context) {}
  991. }, {
  992. key: "willUpdate",
  993. value: function willUpdate() {}
  994. }, {
  995. key: "didUpdate",
  996. value: function didUpdate() {}
  997. }, {
  998. key: "render",
  999. value: function render() {
  1000. return null;
  1001. }
  1002. }, {
  1003. key: "didUnmount",
  1004. value: function didUnmount() {}
  1005. }, {
  1006. key: "setState",
  1007. value: function setState(partialState, callback) {
  1008. this.updater.enqueueSetState(this, partialState, callback);
  1009. }
  1010. }, {
  1011. key: "forceUpdate",
  1012. value: function forceUpdate(callback) {
  1013. this.updater.enqueueForceUpdate(this, {}, callback);
  1014. }
  1015. }, {
  1016. key: "setAnimate",
  1017. value: function setAnimate(animate) {
  1018. this.animate = animate;
  1019. }
  1020. }, {
  1021. key: "destroy",
  1022. value: function destroy() {
  1023. this.destroyed = true;
  1024. }
  1025. }]);
  1026. return Component;
  1027. }(); // 标识是否是组件
  1028. // @ts-ignore
  1029. Component.prototype.isF2Component = true;
  1030. var assertThisInitialized = createCommonjsModule(function (module) {
  1031. function _assertThisInitialized(self) {
  1032. if (self === void 0) {
  1033. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  1034. }
  1035. return self;
  1036. }
  1037. module.exports = _assertThisInitialized, module.exports.__esModule = true, module.exports["default"] = module.exports;
  1038. });
  1039. var _assertThisInitialized = /*@__PURE__*/getDefaultExportFromCjs(assertThisInitialized);
  1040. var setPrototypeOf = createCommonjsModule(function (module) {
  1041. function _setPrototypeOf(o, p) {
  1042. module.exports = _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
  1043. o.__proto__ = p;
  1044. return o;
  1045. }, module.exports.__esModule = true, module.exports["default"] = module.exports;
  1046. return _setPrototypeOf(o, p);
  1047. }
  1048. module.exports = _setPrototypeOf, module.exports.__esModule = true, module.exports["default"] = module.exports;
  1049. });
  1050. var inherits = createCommonjsModule(function (module) {
  1051. function _inherits(subClass, superClass) {
  1052. if (typeof superClass !== "function" && superClass !== null) {
  1053. throw new TypeError("Super expression must either be null or a function");
  1054. }
  1055. subClass.prototype = Object.create(superClass && superClass.prototype, {
  1056. constructor: {
  1057. value: subClass,
  1058. writable: true,
  1059. configurable: true
  1060. }
  1061. });
  1062. Object.defineProperty(subClass, "prototype", {
  1063. writable: false
  1064. });
  1065. if (superClass) setPrototypeOf(subClass, superClass);
  1066. }
  1067. module.exports = _inherits, module.exports.__esModule = true, module.exports["default"] = module.exports;
  1068. });
  1069. var _inherits = /*@__PURE__*/getDefaultExportFromCjs(inherits);
  1070. var getPrototypeOf = createCommonjsModule(function (module) {
  1071. function _getPrototypeOf(o) {
  1072. module.exports = _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) {
  1073. return o.__proto__ || Object.getPrototypeOf(o);
  1074. }, module.exports.__esModule = true, module.exports["default"] = module.exports;
  1075. return _getPrototypeOf(o);
  1076. }
  1077. module.exports = _getPrototypeOf, module.exports.__esModule = true, module.exports["default"] = module.exports;
  1078. });
  1079. var _getPrototypeOf = /*@__PURE__*/getDefaultExportFromCjs(getPrototypeOf);
  1080. var isNativeReflectConstruct = createCommonjsModule(function (module) {
  1081. function _isNativeReflectConstruct() {
  1082. if (typeof Reflect === "undefined" || !Reflect.construct) return false;
  1083. if (Reflect.construct.sham) return false;
  1084. if (typeof Proxy === "function") return true;
  1085. try {
  1086. Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
  1087. return true;
  1088. } catch (e) {
  1089. return false;
  1090. }
  1091. }
  1092. module.exports = _isNativeReflectConstruct, module.exports.__esModule = true, module.exports["default"] = module.exports;
  1093. });
  1094. var possibleConstructorReturn = createCommonjsModule(function (module) {
  1095. var _typeof = _typeof_1["default"];
  1096. function _possibleConstructorReturn(self, call) {
  1097. if (call && (_typeof(call) === "object" || typeof call === "function")) {
  1098. return call;
  1099. } else if (call !== void 0) {
  1100. throw new TypeError("Derived constructors may only return object or undefined");
  1101. }
  1102. return assertThisInitialized(self);
  1103. }
  1104. module.exports = _possibleConstructorReturn, module.exports.__esModule = true, module.exports["default"] = module.exports;
  1105. });
  1106. var _possibleConstructorReturn = /*@__PURE__*/getDefaultExportFromCjs(possibleConstructorReturn);
  1107. var createSuper = createCommonjsModule(function (module) {
  1108. function _createSuper(Derived) {
  1109. var hasNativeReflectConstruct = isNativeReflectConstruct();
  1110. return function _createSuperInternal() {
  1111. var Super = getPrototypeOf(Derived),
  1112. result;
  1113. if (hasNativeReflectConstruct) {
  1114. var NewTarget = getPrototypeOf(this).constructor;
  1115. result = Reflect.construct(Super, arguments, NewTarget);
  1116. } else {
  1117. result = Super.apply(this, arguments);
  1118. }
  1119. return possibleConstructorReturn(this, result);
  1120. };
  1121. }
  1122. module.exports = _createSuper, module.exports.__esModule = true, module.exports["default"] = module.exports;
  1123. });
  1124. var _createSuper = /*@__PURE__*/getDefaultExportFromCjs(createSuper);
  1125. var Timeline = /*#__PURE__*/function (_Component) {
  1126. _inherits(Timeline, _Component);
  1127. var _super = _createSuper(Timeline);
  1128. function Timeline(props) {
  1129. var _this;
  1130. _classCallCheck(this, Timeline);
  1131. _this = _super.call(this, props);
  1132. _this.next = function () {
  1133. var _assertThisInitialize = _assertThisInitialized(_this),
  1134. state = _assertThisInitialize.state,
  1135. props = _assertThisInitialize.props;
  1136. var index = state.index,
  1137. count = state.count,
  1138. delay = state.delay;
  1139. var loop = props.loop;
  1140. var next = loop ? (index + 1) % count : index + 1;
  1141. if (next < count) {
  1142. setTimeout(function () {
  1143. _this.setState({
  1144. index: next
  1145. });
  1146. }, delay || 0);
  1147. }
  1148. };
  1149. var delay = props.delay,
  1150. _props$start = props.start,
  1151. start = _props$start === void 0 ? 0 : _props$start,
  1152. children = props.children;
  1153. var count = Children.toArray(children).length;
  1154. _this.state = {
  1155. delay: delay,
  1156. count: count,
  1157. index: start
  1158. };
  1159. return _this;
  1160. }
  1161. _createClass(Timeline, [{
  1162. key: "didMount",
  1163. value: function didMount() {
  1164. var context = this.context;
  1165. var root = context.root;
  1166. root.on('animationEnd', this.next);
  1167. }
  1168. }, {
  1169. key: "didUnmount",
  1170. value: function didUnmount() {
  1171. var context = this.context;
  1172. var root = context.root;
  1173. root.off('animationEnd', this.next);
  1174. }
  1175. }, {
  1176. key: "render",
  1177. value: function render() {
  1178. var state = this.state,
  1179. props = this.props;
  1180. var children = props.children;
  1181. var index = state.index;
  1182. var childrenArray = Children.toArray(children);
  1183. return childrenArray[index];
  1184. }
  1185. }]);
  1186. return Timeline;
  1187. }(Component);
  1188. var WILDCARD = '*';
  1189. /* event-emitter */
  1190. var EventEmitter = /** @class */ (function () {
  1191. function EventEmitter() {
  1192. this._events = {};
  1193. }
  1194. /**
  1195. * 监听一个事件
  1196. * @param evt
  1197. * @param callback
  1198. * @param once
  1199. */
  1200. EventEmitter.prototype.on = function (evt, callback, once) {
  1201. if (!this._events[evt]) {
  1202. this._events[evt] = [];
  1203. }
  1204. this._events[evt].push({
  1205. callback: callback,
  1206. once: !!once,
  1207. });
  1208. return this;
  1209. };
  1210. /**
  1211. * 监听一个事件一次
  1212. * @param evt
  1213. * @param callback
  1214. */
  1215. EventEmitter.prototype.once = function (evt, callback) {
  1216. return this.on(evt, callback, true);
  1217. };
  1218. /**
  1219. * 触发一个事件
  1220. * @param evt
  1221. * @param args
  1222. */
  1223. EventEmitter.prototype.emit = function (evt) {
  1224. var _this = this;
  1225. var args = [];
  1226. for (var _i = 1; _i < arguments.length; _i++) {
  1227. args[_i - 1] = arguments[_i];
  1228. }
  1229. var events = this._events[evt] || [];
  1230. var wildcardEvents = this._events[WILDCARD] || [];
  1231. // 实际的处理 emit 方法
  1232. var doEmit = function (es) {
  1233. var length = es.length;
  1234. for (var i = 0; i < length; i++) {
  1235. if (!es[i]) {
  1236. continue;
  1237. }
  1238. var _a = es[i], callback = _a.callback, once = _a.once;
  1239. if (once) {
  1240. es.splice(i, 1);
  1241. if (es.length === 0) {
  1242. delete _this._events[evt];
  1243. }
  1244. length--;
  1245. i--;
  1246. }
  1247. callback.apply(_this, args);
  1248. }
  1249. };
  1250. doEmit(events);
  1251. doEmit(wildcardEvents);
  1252. };
  1253. /**
  1254. * 取消监听一个事件,或者一个channel
  1255. * @param evt
  1256. * @param callback
  1257. */
  1258. EventEmitter.prototype.off = function (evt, callback) {
  1259. if (!evt) {
  1260. // evt 为空全部清除
  1261. this._events = {};
  1262. }
  1263. else {
  1264. if (!callback) {
  1265. // evt 存在,callback 为空,清除事件所有方法
  1266. delete this._events[evt];
  1267. }
  1268. else {
  1269. // evt 存在,callback 存在,清除匹配的
  1270. var events = this._events[evt] || [];
  1271. var length_1 = events.length;
  1272. for (var i = 0; i < length_1; i++) {
  1273. if (events[i].callback === callback) {
  1274. events.splice(i, 1);
  1275. length_1--;
  1276. i--;
  1277. }
  1278. }
  1279. if (events.length === 0) {
  1280. delete this._events[evt];
  1281. }
  1282. }
  1283. }
  1284. return this;
  1285. };
  1286. /* 当前所有的事件 */
  1287. EventEmitter.prototype.getEvents = function () {
  1288. return this._events;
  1289. };
  1290. return EventEmitter;
  1291. }());
  1292. var Matrix = {
  1293. generateDefault: function generateDefault() {
  1294. return [1, 0, 0, 1, 0, 0];
  1295. },
  1296. isChanged: function isChanged(m) {
  1297. return m[0] !== 1 || m[1] !== 0 || m[2] !== 0 || m[3] !== 1 || m[4] !== 0 || m[5] !== 0;
  1298. },
  1299. multiply: function multiply(m1, m2) {
  1300. var m11 = m1[0] * m2[0] + m1[2] * m2[1];
  1301. var m12 = m1[1] * m2[0] + m1[3] * m2[1];
  1302. var m21 = m1[0] * m2[2] + m1[2] * m2[3];
  1303. var m22 = m1[1] * m2[2] + m1[3] * m2[3];
  1304. var dx = m1[0] * m2[4] + m1[2] * m2[5] + m1[4];
  1305. var dy = m1[1] * m2[4] + m1[3] * m2[5] + m1[5];
  1306. return [m11, m12, m21, m22, dx, dy];
  1307. },
  1308. scale: function scale(out, m, v) {
  1309. out[0] = m[0] * v[0];
  1310. out[1] = m[1] * v[0];
  1311. out[2] = m[2] * v[1];
  1312. out[3] = m[3] * v[1];
  1313. out[4] = m[4];
  1314. out[5] = m[5];
  1315. return out;
  1316. },
  1317. rotate: function rotate(out, m, radian) {
  1318. var c = Math.cos(radian);
  1319. var s = Math.sin(radian);
  1320. var m11 = m[0] * c + m[2] * s;
  1321. var m12 = m[1] * c + m[3] * s;
  1322. var m21 = m[0] * -s + m[2] * c;
  1323. var m22 = m[1] * -s + m[3] * c;
  1324. out[0] = m11;
  1325. out[1] = m12;
  1326. out[2] = m21;
  1327. out[3] = m22;
  1328. out[4] = m[4];
  1329. out[5] = m[5];
  1330. return out;
  1331. },
  1332. translate: function translate(out, m, v) {
  1333. out[0] = m[0];
  1334. out[1] = m[1];
  1335. out[2] = m[2];
  1336. out[3] = m[3];
  1337. out[4] = m[4] + m[0] * v[0] + m[2] * v[1];
  1338. out[5] = m[5] + m[1] * v[0] + m[3] * v[1];
  1339. return out;
  1340. },
  1341. transform: function transform(m, actions) {
  1342. var out = [].concat(m);
  1343. for (var i = 0, len = actions.length; i < len; i++) {
  1344. var action = actions[i];
  1345. switch (action[0]) {
  1346. case 't':
  1347. Matrix.translate(out, out, [action[1], action[2]]);
  1348. break;
  1349. case 's':
  1350. Matrix.scale(out, out, [action[1], action[2]]);
  1351. break;
  1352. case 'r':
  1353. Matrix.rotate(out, out, action[1]);
  1354. break;
  1355. }
  1356. }
  1357. return out;
  1358. }
  1359. };
  1360. /**
  1361. * 2 Dimensional Vector
  1362. * @module vector2
  1363. */
  1364. var Vector2 = {
  1365. /**
  1366. * Creates a new, empty vector2
  1367. *
  1368. * @return {vector2} a new 2D vector
  1369. */
  1370. create: function create() {
  1371. return [0, 0];
  1372. },
  1373. /**
  1374. * Calculates the length of a vector2
  1375. *
  1376. * @param {vector2} v vector to calculate length of
  1377. * @return {Number} length of v
  1378. */
  1379. length: function length(v) {
  1380. var x = v[0];
  1381. var y = v[1];
  1382. return Math.sqrt(x * x + y * y);
  1383. },
  1384. /**
  1385. * Normalize a vector2
  1386. *
  1387. * @param {vector2} out the receiving vector
  1388. * @param {vector2} v vector to normalize
  1389. * @return {vector2} out
  1390. */
  1391. normalize: function normalize(out, v) {
  1392. var len = this.length(v);
  1393. if (len === 0) {
  1394. out[0] = 0;
  1395. out[1] = 0;
  1396. } else {
  1397. out[0] = v[0] / len;
  1398. out[1] = v[1] / len;
  1399. }
  1400. return out;
  1401. },
  1402. /**
  1403. * Adds two vector2's
  1404. *
  1405. * @param {vector2} out the receiving vector
  1406. * @param {vector2} v1 the first operand
  1407. * @param {vector2} v2 the second operand
  1408. * @return {vector2} out
  1409. */
  1410. add: function add(out, v1, v2) {
  1411. out[0] = v1[0] + v2[0];
  1412. out[1] = v1[1] + v2[1];
  1413. return out;
  1414. },
  1415. /**
  1416. * Subtracts vector v2 from vector v1
  1417. *
  1418. * @param {vector2} out the receiving vector
  1419. * @param {vector2} v1 the first operand
  1420. * @param {vector2} v2 the second operand
  1421. * @return {vector2} out
  1422. */
  1423. sub: function sub(out, v1, v2) {
  1424. out[0] = v1[0] - v2[0];
  1425. out[1] = v1[1] - v2[1];
  1426. return out;
  1427. },
  1428. /**
  1429. * Scales a vector2 by a scalar number
  1430. *
  1431. * @param {vector2} out the receiving vector
  1432. * @param {vector2} v the vector to scale
  1433. * @param {Number} s amount to scale the vector by
  1434. * @return {vector2} out
  1435. */
  1436. scale: function scale(out, v, s) {
  1437. out[0] = v[0] * s;
  1438. out[1] = v[1] * s;
  1439. return out;
  1440. },
  1441. /**
  1442. * Calculates the dot product of two vector2's
  1443. *
  1444. * @param {vector2} v1 the first operand
  1445. * @param {vector2} v2 the second operand
  1446. * @return {Number} dot product of v1 and v2
  1447. */
  1448. dot: function dot(v1, v2) {
  1449. return v1[0] * v2[0] + v1[1] * v2[1];
  1450. },
  1451. /**
  1452. * Calculates the direction of two vector2's
  1453. *
  1454. * @param {vector2} v1 the first operand
  1455. * @param {vector2} v2 the second operand
  1456. * @return {Boolean} the direction of v1 and v2
  1457. */
  1458. direction: function direction(v1, v2) {
  1459. return v1[0] * v2[1] - v2[0] * v1[1];
  1460. },
  1461. /**
  1462. * Calculates the angle of two vector2's
  1463. *
  1464. * @param {vector2} v1 the first operand
  1465. * @param {vector2} v2 the second operand
  1466. * @return {Number} angle of v1 and v2
  1467. */
  1468. angle: function angle(v1, v2) {
  1469. var theta = this.dot(v1, v2) / (this.length(v1) * this.length(v2));
  1470. return Math.acos(theta);
  1471. },
  1472. /**
  1473. * Calculates the angle of two vector2's with direction
  1474. *
  1475. * @param {vector2} v1 the first operand
  1476. * @param {vector2} v2 the second operand
  1477. * @param {Boolean} direction the direction of two vector2's
  1478. * @return {Number} angle of v1 and v2
  1479. */
  1480. angleTo: function angleTo(v1, v2, direction) {
  1481. var angle = this.angle(v1, v2);
  1482. var angleLargeThanPI = this.direction(v1, v2) >= 0;
  1483. if (direction) {
  1484. if (angleLargeThanPI) {
  1485. return Math.PI * 2 - angle;
  1486. }
  1487. return angle;
  1488. }
  1489. if (angleLargeThanPI) {
  1490. return angle;
  1491. }
  1492. return Math.PI * 2 - angle;
  1493. },
  1494. /**
  1495. * whether a vector2 is zero vector
  1496. *
  1497. * @param {vector2} v vector to calculate
  1498. * @return {Boolean} is or not a zero vector
  1499. */
  1500. zero: function zero(v) {
  1501. return v[0] === 0 && v[1] === 0;
  1502. },
  1503. /**
  1504. * Calculates the euclidian distance between two vector2's
  1505. *
  1506. * @param {vector2} v1 the first operand
  1507. * @param {vector2} v2 the second operand
  1508. * @return {Number} distance between a and b
  1509. */
  1510. distance: function distance(v1, v2) {
  1511. var x = v2[0] - v1[0];
  1512. var y = v2[1] - v1[1];
  1513. return Math.sqrt(x * x + y * y);
  1514. },
  1515. /**
  1516. * Creates a new vector2 initialized with values from an existing vector
  1517. *
  1518. * @param {vector2} v vector to clone
  1519. * @return {Array} a new 2D vector
  1520. */
  1521. clone: function clone(v) {
  1522. return [v[0], v[1]];
  1523. },
  1524. /**
  1525. * Return the minimum of two vector2's
  1526. *
  1527. * @param {vector2} out the receiving vector
  1528. * @param {vector2} v1 the first operand
  1529. * @param {vector2} v2 the second operand
  1530. * @return {vector2} out
  1531. */
  1532. min: function min(out, v1, v2) {
  1533. out[0] = Math.min(v1[0], v2[0]);
  1534. out[1] = Math.min(v1[1], v2[1]);
  1535. return out;
  1536. },
  1537. /**
  1538. * Return the maximum of two vector2's
  1539. *
  1540. * @param {vector2} out the receiving vector
  1541. * @param {vector2} v1 the first operand
  1542. * @param {vector2} v2 the second operand
  1543. * @return {vector2} out
  1544. */
  1545. max: function max(out, v1, v2) {
  1546. out[0] = Math.max(v1[0], v2[0]);
  1547. out[1] = Math.max(v1[1], v2[1]);
  1548. return out;
  1549. },
  1550. /**
  1551. * Transforms the vector2 with a mat2d
  1552. *
  1553. * @param {vector2} out the receiving vector
  1554. * @param {vector2} v the vector to transform
  1555. * @param {mat2d} m matrix to transform with
  1556. * @return {vector2} out
  1557. */
  1558. transformMat2d: function transformMat2d(out, v, m) {
  1559. var x = v[0];
  1560. var y = v[1];
  1561. out[0] = m[0] * x + m[2] * y + m[4];
  1562. out[1] = m[1] * x + m[3] * y + m[5];
  1563. return out;
  1564. }
  1565. };
  1566. /**
  1567. * @fileOverview convert the line to curve
  1568. * @author dxq613@gmail.com
  1569. */
  1570. function getPoint(v) {
  1571. return [v.x, v.y];
  1572. }
  1573. function smoothBezier(points, smooth, isLoop, constraint) {
  1574. var cps = [];
  1575. var prevPoint;
  1576. var nextPoint;
  1577. var hasConstraint = !!constraint;
  1578. var min;
  1579. var max;
  1580. var point;
  1581. var len;
  1582. var l;
  1583. var i;
  1584. if (hasConstraint) {
  1585. min = [Infinity, Infinity];
  1586. max = [-Infinity, -Infinity];
  1587. for (i = 0, l = points.length; i < l; i++) {
  1588. point = getPoint(points[i]);
  1589. Vector2.min(min, min, point);
  1590. Vector2.max(max, max, point);
  1591. }
  1592. Vector2.min(min, min, constraint[0]);
  1593. Vector2.max(max, max, constraint[1]);
  1594. }
  1595. for (i = 0, len = points.length; i < len; i++) {
  1596. point = getPoint(points[i]);
  1597. if (isLoop) {
  1598. prevPoint = getPoint(points[i ? i - 1 : len - 1]);
  1599. nextPoint = getPoint(points[(i + 1) % len]);
  1600. } else {
  1601. if (i === 0 || i === len - 1) {
  1602. cps.push([point[0], point[1]]);
  1603. continue;
  1604. } else {
  1605. prevPoint = getPoint(points[i - 1]);
  1606. nextPoint = getPoint(points[i + 1]);
  1607. }
  1608. }
  1609. var v = Vector2.sub([], nextPoint, prevPoint);
  1610. Vector2.scale(v, v, smooth);
  1611. var d0 = Vector2.distance(point, prevPoint);
  1612. var d1 = Vector2.distance(point, nextPoint);
  1613. var sum = d0 + d1;
  1614. if (sum !== 0) {
  1615. d0 /= sum;
  1616. d1 /= sum;
  1617. }
  1618. var v1 = Vector2.scale([], v, -d0);
  1619. var v2 = Vector2.scale([], v, d1);
  1620. var cp0 = Vector2.add([], point, v1);
  1621. var cp1 = Vector2.add([], point, v2);
  1622. if (hasConstraint) {
  1623. Vector2.max(cp0, cp0, min);
  1624. Vector2.min(cp0, cp0, max);
  1625. Vector2.max(cp1, cp1, min);
  1626. Vector2.min(cp1, cp1, max);
  1627. }
  1628. cps.push([cp0[0], cp0[1]]);
  1629. cps.push([cp1[0], cp1[1]]);
  1630. }
  1631. if (isLoop) {
  1632. cps.push(cps.shift());
  1633. }
  1634. return cps;
  1635. }
  1636. function catmullRom2bezier(pointList, z, constraint) {
  1637. var isLoop = !!z;
  1638. var controlPointList = smoothBezier(pointList, 0.4, isLoop, constraint);
  1639. var len = pointList.length;
  1640. var d1 = [];
  1641. var cp1;
  1642. var cp2;
  1643. var p;
  1644. for (var i = 0; i < len - 1; i++) {
  1645. cp1 = controlPointList[i * 2];
  1646. cp2 = controlPointList[i * 2 + 1];
  1647. p = pointList[i + 1];
  1648. d1.push(['C', cp1[0], cp1[1], cp2[0], cp2[1], p.x, p.y]);
  1649. }
  1650. if (isLoop) {
  1651. cp1 = controlPointList[len];
  1652. cp2 = controlPointList[len + 1];
  1653. p = pointList[0];
  1654. d1.push(['C', cp1[0], cp1[1], cp2[0], cp2[1], p.x, p.y]);
  1655. }
  1656. return d1;
  1657. }
  1658. var start = Vector2.create();
  1659. var end = Vector2.create();
  1660. var extremity = Vector2.create();
  1661. function getCubicBezierXYatT(startPt, controlPt1, controlPt2, endPt, T) {
  1662. var x = CubicN(T, startPt.x, controlPt1.x, controlPt2.x, endPt.x);
  1663. var y = CubicN(T, startPt.y, controlPt1.y, controlPt2.y, endPt.y);
  1664. return {
  1665. x: x,
  1666. y: y
  1667. };
  1668. }
  1669. // cubic helper formula at T distance
  1670. function CubicN(T, a, b, c, d) {
  1671. var t2 = T * T;
  1672. var t3 = t2 * T;
  1673. return a + (-a * 3 + T * (3 * a - a * T)) * T + (3 * b + T * (-6 * b + b * 3 * T)) * T + (c * 3 - c * 3 * T) * t2 + d * t3;
  1674. }
  1675. function cubicBezierBounds(c) {
  1676. var minX = Infinity;
  1677. var maxX = -Infinity;
  1678. var minY = Infinity;
  1679. var maxY = -Infinity;
  1680. var s = {
  1681. x: c[0],
  1682. y: c[1]
  1683. };
  1684. var c1 = {
  1685. x: c[2],
  1686. y: c[3]
  1687. };
  1688. var c2 = {
  1689. x: c[4],
  1690. y: c[5]
  1691. };
  1692. var e = {
  1693. x: c[6],
  1694. y: c[7]
  1695. };
  1696. for (var t = 0; t < 100; t++) {
  1697. var pt = getCubicBezierXYatT(s, c1, c2, e, t / 100);
  1698. if (pt.x < minX) {
  1699. minX = pt.x;
  1700. }
  1701. if (pt.x > maxX) {
  1702. maxX = pt.x;
  1703. }
  1704. if (pt.y < minY) {
  1705. minY = pt.y;
  1706. }
  1707. if (pt.y > maxY) {
  1708. maxY = pt.y;
  1709. }
  1710. }
  1711. return {
  1712. minX: minX,
  1713. minY: minY,
  1714. maxX: maxX,
  1715. maxY: maxY
  1716. };
  1717. }
  1718. function getBBoxFromPoints(points, lineWidth) {
  1719. if (points.length === 0) {
  1720. return;
  1721. }
  1722. var p = points[0];
  1723. var left = p.x;
  1724. var right = p.x;
  1725. var top = p.y;
  1726. var bottom = p.y;
  1727. var len = points.length;
  1728. for (var i = 1; i < len; i++) {
  1729. p = points[i];
  1730. left = Math.min(left, p.x);
  1731. right = Math.max(right, p.x);
  1732. top = Math.min(top, p.y);
  1733. bottom = Math.max(bottom, p.y);
  1734. }
  1735. lineWidth = lineWidth / 2 || 0;
  1736. return {
  1737. minX: left - lineWidth,
  1738. minY: top - lineWidth,
  1739. maxX: right + lineWidth,
  1740. maxY: bottom + lineWidth
  1741. };
  1742. }
  1743. function getBBoxFromLine(x0, y0, x1, y1, lineWidth) {
  1744. lineWidth = lineWidth / 2 || 0;
  1745. return {
  1746. minX: Math.min(x0, x1) - lineWidth,
  1747. minY: Math.min(y0, y1) - lineWidth,
  1748. maxX: Math.max(x0, x1) + lineWidth,
  1749. maxY: Math.max(y0, y1) + lineWidth
  1750. };
  1751. }
  1752. function getBBoxFromArc(x, y, r, startAngle, endAngle, anticlockwise) {
  1753. var diff = Math.abs(startAngle - endAngle);
  1754. if (diff % (Math.PI * 2) < 1e-4 && diff > 1e-4) {
  1755. // Is a circle
  1756. return {
  1757. minX: x - r,
  1758. minY: y - r,
  1759. maxX: x + r,
  1760. maxY: y + r
  1761. };
  1762. }
  1763. start[0] = Math.cos(startAngle) * r + x;
  1764. start[1] = Math.sin(startAngle) * r + y;
  1765. end[0] = Math.cos(endAngle) * r + x;
  1766. end[1] = Math.sin(endAngle) * r + y;
  1767. var min = [0, 0];
  1768. var max = [0, 0];
  1769. Vector2.min(min, start, end);
  1770. Vector2.max(max, start, end);
  1771. // Thresh to [0, Math.PI * 2]
  1772. startAngle = startAngle % (Math.PI * 2);
  1773. if (startAngle < 0) {
  1774. startAngle = startAngle + Math.PI * 2;
  1775. }
  1776. endAngle = endAngle % (Math.PI * 2);
  1777. if (endAngle < 0) {
  1778. endAngle = endAngle + Math.PI * 2;
  1779. }
  1780. if (startAngle > endAngle && !anticlockwise) {
  1781. endAngle += Math.PI * 2;
  1782. } else if (startAngle < endAngle && anticlockwise) {
  1783. startAngle += Math.PI * 2;
  1784. }
  1785. if (anticlockwise) {
  1786. var tmp = endAngle;
  1787. endAngle = startAngle;
  1788. startAngle = tmp;
  1789. }
  1790. for (var angle = 0; angle < endAngle; angle += Math.PI / 2) {
  1791. if (angle > startAngle) {
  1792. extremity[0] = Math.cos(angle) * r + x;
  1793. extremity[1] = Math.sin(angle) * r + y;
  1794. Vector2.min(min, extremity, min);
  1795. Vector2.max(max, extremity, max);
  1796. }
  1797. }
  1798. return {
  1799. minX: min[0],
  1800. minY: min[1],
  1801. maxX: max[0],
  1802. maxY: max[1]
  1803. };
  1804. }
  1805. function getBBoxFromBezierGroup(points, lineWidth) {
  1806. var minX = Infinity;
  1807. var maxX = -Infinity;
  1808. var minY = Infinity;
  1809. var maxY = -Infinity;
  1810. for (var i = 0, len = points.length; i < len; i++) {
  1811. var bbox = cubicBezierBounds(points[i]);
  1812. if (bbox.minX < minX) {
  1813. minX = bbox.minX;
  1814. }
  1815. if (bbox.maxX > maxX) {
  1816. maxX = bbox.maxX;
  1817. }
  1818. if (bbox.minY < minY) {
  1819. minY = bbox.minY;
  1820. }
  1821. if (bbox.maxY > maxY) {
  1822. maxY = bbox.maxY;
  1823. }
  1824. }
  1825. lineWidth = lineWidth / 2 || 0;
  1826. return {
  1827. minX: minX - lineWidth,
  1828. minY: minY - lineWidth,
  1829. maxX: maxX + lineWidth,
  1830. maxY: maxY + lineWidth
  1831. };
  1832. }
  1833. function _classCallCheck$1(instance, Constructor) {
  1834. if (!(instance instanceof Constructor)) {
  1835. throw new TypeError("Cannot call a class as a function");
  1836. }
  1837. }
  1838. function _typeof$1(obj) {
  1839. "@babel/helpers - typeof";
  1840. return _typeof$1 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
  1841. return typeof obj;
  1842. } : function (obj) {
  1843. return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  1844. }, _typeof$1(obj);
  1845. }
  1846. function _toPrimitive(input, hint) {
  1847. if (_typeof$1(input) !== "object" || input === null) return input;
  1848. var prim = input[Symbol.toPrimitive];
  1849. if (prim !== undefined) {
  1850. var res = prim.call(input, hint || "default");
  1851. if (_typeof$1(res) !== "object") return res;
  1852. throw new TypeError("@@toPrimitive must return a primitive value.");
  1853. }
  1854. return (hint === "string" ? String : Number)(input);
  1855. }
  1856. function _toPropertyKey(arg) {
  1857. var key = _toPrimitive(arg, "string");
  1858. return _typeof$1(key) === "symbol" ? key : String(key);
  1859. }
  1860. function _defineProperties(target, props) {
  1861. for (var i = 0; i < props.length; i++) {
  1862. var descriptor = props[i];
  1863. descriptor.enumerable = descriptor.enumerable || false;
  1864. descriptor.configurable = true;
  1865. if ("value" in descriptor) descriptor.writable = true;
  1866. Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
  1867. }
  1868. }
  1869. function _createClass$1(Constructor, protoProps, staticProps) {
  1870. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  1871. if (staticProps) _defineProperties(Constructor, staticProps);
  1872. Object.defineProperty(Constructor, "prototype", {
  1873. writable: false
  1874. });
  1875. return Constructor;
  1876. }
  1877. function _setPrototypeOf(o, p) {
  1878. _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
  1879. o.__proto__ = p;
  1880. return o;
  1881. };
  1882. return _setPrototypeOf(o, p);
  1883. }
  1884. function _inherits$1(subClass, superClass) {
  1885. if (typeof superClass !== "function" && superClass !== null) {
  1886. throw new TypeError("Super expression must either be null or a function");
  1887. }
  1888. subClass.prototype = Object.create(superClass && superClass.prototype, {
  1889. constructor: {
  1890. value: subClass,
  1891. writable: true,
  1892. configurable: true
  1893. }
  1894. });
  1895. Object.defineProperty(subClass, "prototype", {
  1896. writable: false
  1897. });
  1898. if (superClass) _setPrototypeOf(subClass, superClass);
  1899. }
  1900. function _getPrototypeOf$1(o) {
  1901. _getPrototypeOf$1 = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) {
  1902. return o.__proto__ || Object.getPrototypeOf(o);
  1903. };
  1904. return _getPrototypeOf$1(o);
  1905. }
  1906. function _isNativeReflectConstruct() {
  1907. if (typeof Reflect === "undefined" || !Reflect.construct) return false;
  1908. if (Reflect.construct.sham) return false;
  1909. if (typeof Proxy === "function") return true;
  1910. try {
  1911. Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
  1912. return true;
  1913. } catch (e) {
  1914. return false;
  1915. }
  1916. }
  1917. function _assertThisInitialized$1(self) {
  1918. if (self === void 0) {
  1919. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  1920. }
  1921. return self;
  1922. }
  1923. function _possibleConstructorReturn$1(self, call) {
  1924. if (call && (_typeof$1(call) === "object" || typeof call === "function")) {
  1925. return call;
  1926. } else if (call !== void 0) {
  1927. throw new TypeError("Derived constructors may only return object or undefined");
  1928. }
  1929. return _assertThisInitialized$1(self);
  1930. }
  1931. function _createSuper$1(Derived) {
  1932. var hasNativeReflectConstruct = _isNativeReflectConstruct();
  1933. return function _createSuperInternal() {
  1934. var Super = _getPrototypeOf$1(Derived),
  1935. result;
  1936. if (hasNativeReflectConstruct) {
  1937. var NewTarget = _getPrototypeOf$1(this).constructor;
  1938. result = Reflect.construct(Super, arguments, NewTarget);
  1939. } else {
  1940. result = Super.apply(this, arguments);
  1941. }
  1942. return _possibleConstructorReturn$1(this, result);
  1943. };
  1944. }
  1945. // 多个事件分隔符
  1946. var TYPE_SEP = ' ';
  1947. var EventEmit = /*#__PURE__*/function () {
  1948. function EventEmit() {
  1949. _classCallCheck$1(this, EventEmit);
  1950. this.__events = {};
  1951. }
  1952. _createClass$1(EventEmit, [{
  1953. key: "on",
  1954. value: function on(type, listener) {
  1955. var _this = this;
  1956. if (!type || !listener) {
  1957. return;
  1958. }
  1959. type.split(TYPE_SEP).forEach(function (item) {
  1960. var events = _this.__events[item] || [];
  1961. events.push(listener);
  1962. _this.__events[item] = events;
  1963. });
  1964. }
  1965. }, {
  1966. key: "emit",
  1967. value: function emit(type, e) {
  1968. var _this2 = this;
  1969. if (isObject(type)) {
  1970. e = type;
  1971. type = e && e.type;
  1972. }
  1973. if (!type) {
  1974. return;
  1975. }
  1976. var events = this.__events[type];
  1977. if (!events || !events.length) {
  1978. return;
  1979. }
  1980. events.forEach(function (listener) {
  1981. listener.call(_this2, e);
  1982. });
  1983. }
  1984. }, {
  1985. key: "off",
  1986. value: function off(type, listener) {
  1987. var __events = this.__events;
  1988. type.split(TYPE_SEP).forEach(function (item) {
  1989. var events = __events[item];
  1990. if (!events || !events.length) {
  1991. return;
  1992. }
  1993. // 如果没有指定方法,则删除所有项
  1994. if (!listener) {
  1995. delete __events[item];
  1996. return;
  1997. }
  1998. // 删除指定的 listener
  1999. for (var i = 0, len = events.length; i < len; i++) {
  2000. if (events[i] === listener) {
  2001. events.splice(i, 1);
  2002. i--;
  2003. }
  2004. }
  2005. });
  2006. }
  2007. }]);
  2008. return EventEmit;
  2009. }();
  2010. /**
  2011. * Detects support for options object argument in addEventListener.
  2012. * https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#Safely_detecting_option_support
  2013. * @private
  2014. */
  2015. var supportsEventListenerOptions = function () {
  2016. var supports = false;
  2017. try {
  2018. var options = Object.defineProperty({}, 'passive', {
  2019. get: function get() {
  2020. supports = true;
  2021. }
  2022. });
  2023. window.addEventListener('e', null, options);
  2024. } catch (e) {
  2025. // continue regardless of error
  2026. }
  2027. return supports;
  2028. }();
  2029. /* global wx, my */
  2030. // weixin miniprogram
  2031. // @ts-ignore
  2032. var isWx = (typeof wx === "undefined" ? "undefined" : _typeof$1(wx)) === 'object' && typeof wx.getSystemInfoSync === 'function';
  2033. // ant miniprogram
  2034. // @ts-ignore
  2035. var isMy = (typeof my === "undefined" ? "undefined" : _typeof$1(my)) === 'object' && typeof my.getSystemInfoSync === 'function';
  2036. // in node
  2037. // @ts-ignore
  2038. var isNode = (typeof global === "undefined" ? "undefined" : _typeof$1(global)) && !(typeof window === "undefined" ? "undefined" : _typeof$1(window));
  2039. function isCanvasElement(el) {
  2040. if (!el || _typeof$1(el) !== 'object') return false;
  2041. if (el.nodeType === 1 && el.nodeName) {
  2042. // HTMLCanvasElement
  2043. return true;
  2044. }
  2045. // CanvasElement
  2046. return !!el.isCanvasElement;
  2047. }
  2048. function getPixelRatio() {
  2049. return window && window.devicePixelRatio || 1;
  2050. }
  2051. function getStyle(el, property) {
  2052. return el.currentStyle ? el.currentStyle[property] : document.defaultView.getComputedStyle(el, null).getPropertyValue(property);
  2053. }
  2054. function getWidth(el) {
  2055. var width = getStyle(el, 'width');
  2056. if (width === 'auto') {
  2057. width = el.offsetWidth;
  2058. }
  2059. return parseFloat(width);
  2060. }
  2061. function getHeight(el) {
  2062. var height = getStyle(el, 'height');
  2063. if (height === 'auto') {
  2064. height = el.offsetHeight;
  2065. }
  2066. return parseFloat(height);
  2067. }
  2068. function getDomById(id) {
  2069. if (!id) {
  2070. return null;
  2071. }
  2072. return document.getElementById(id);
  2073. }
  2074. function getRelativePosition(point, canvas) {
  2075. var canvasDom = canvas.get('el');
  2076. if (!canvasDom) return point;
  2077. var _canvasDom$getBoundin = canvasDom.getBoundingClientRect(),
  2078. top = _canvasDom$getBoundin.top,
  2079. left = _canvasDom$getBoundin.left;
  2080. var paddingLeft = parseFloat(getStyle(canvasDom, 'padding-left'));
  2081. var paddingTop = parseFloat(getStyle(canvasDom, 'padding-top'));
  2082. var mouseX = point.x - left - paddingLeft;
  2083. var mouseY = point.y - top - paddingTop;
  2084. return {
  2085. x: mouseX,
  2086. y: mouseY
  2087. };
  2088. }
  2089. function landscapePoint(point, canvas) {
  2090. var landscape = canvas.get('landscape');
  2091. if (!landscape) {
  2092. return point;
  2093. }
  2094. if (isFunction(landscape)) {
  2095. return landscape(point, canvas);
  2096. }
  2097. // 默认顺时针旋转90度
  2098. var height = canvas.get('height');
  2099. var x = point.y;
  2100. var y = height - point.x;
  2101. return {
  2102. x: x,
  2103. y: y
  2104. };
  2105. }
  2106. function convertPoints(ev, canvas) {
  2107. var touches = ev.touches;
  2108. // 认为是mouse事件
  2109. if (!touches) {
  2110. var point = getRelativePosition({
  2111. x: ev.clientX,
  2112. y: ev.clientY
  2113. }, canvas);
  2114. return [landscapePoint(point, canvas)];
  2115. }
  2116. // 单指 touchend 后,touchs 会变空,最后的触点要从changedTouches里拿
  2117. if (!touches.length) {
  2118. // 为了防止万一,加个空逻辑
  2119. touches = ev.changedTouches || [];
  2120. }
  2121. var points = [];
  2122. for (var i = 0, len = touches.length; i < len; i++) {
  2123. var touch = touches[i];
  2124. // x, y: 相对canvas原点的位置,clientX, clientY 相对于可视窗口的位置
  2125. var x = touch.x,
  2126. y = touch.y,
  2127. clientX = touch.clientX,
  2128. clientY = touch.clientY;
  2129. var _point = void 0;
  2130. // 小程序环境会有x,y
  2131. if (isNumber(x) || isNumber(y)) {
  2132. _point = {
  2133. x: x,
  2134. y: y
  2135. };
  2136. } else {
  2137. // 浏览器环境再计算下canvas的相对位置
  2138. _point = getRelativePosition({
  2139. x: clientX,
  2140. y: clientY
  2141. }, canvas);
  2142. }
  2143. points.push(landscapePoint(_point, canvas));
  2144. }
  2145. return points;
  2146. }
  2147. function measureText(text, font, ctx) {
  2148. if (!ctx) {
  2149. ctx = document.createElement('canvas').getContext('2d');
  2150. }
  2151. ctx.font = font || '12px sans-serif';
  2152. return ctx.measureText(text);
  2153. }
  2154. var convertPoints$1 = convertPoints;
  2155. // 计算滑动的方向
  2156. var calcDirection = function calcDirection(start, end) {
  2157. var xDistance = end.x - start.x;
  2158. var yDistance = end.y - start.y;
  2159. // x 的距离大于y 说明是横向,否则就是纵向
  2160. if (Math.abs(xDistance) > Math.abs(yDistance)) {
  2161. return xDistance > 0 ? 'right' : 'left';
  2162. }
  2163. return yDistance > 0 ? 'down' : 'up';
  2164. };
  2165. // 计算2点之间的距离
  2166. var calcDistance = function calcDistance(point1, point2) {
  2167. var xDistance = Math.abs(point2.x - point1.x);
  2168. var yDistance = Math.abs(point2.y - point1.y);
  2169. return Math.sqrt(xDistance * xDistance + yDistance * yDistance);
  2170. };
  2171. var getCenter = function getCenter(point1, point2) {
  2172. var x = point1.x + (point2.x - point1.x) / 2;
  2173. var y = point1.y + (point2.y - point1.y) / 2;
  2174. return {
  2175. x: x,
  2176. y: y
  2177. };
  2178. };
  2179. var PRESS_DELAY = 250;
  2180. var EventController = /*#__PURE__*/function () {
  2181. function EventController(_ref) {
  2182. var _this = this;
  2183. var canvas = _ref.canvas,
  2184. el = _ref.el;
  2185. _classCallCheck$1(this, EventController);
  2186. this._click = function (ev) {
  2187. var points = convertPoints$1(ev, _this.canvas);
  2188. ev.points = points;
  2189. _this.emitEvent('click', ev);
  2190. };
  2191. this._start = function (ev) {
  2192. var points = convertPoints$1(ev, _this.canvas);
  2193. if (!points) {
  2194. return;
  2195. }
  2196. ev.points = points;
  2197. _this.emitEvent('touchstart', ev);
  2198. // 防止上次的内容没有清理掉,重新reset下
  2199. _this.reset();
  2200. // 记录touch start 的时间
  2201. _this.startTime = Date.now();
  2202. // 记录touch start 的点
  2203. _this.startPoints = points;
  2204. if (points.length > 1) {
  2205. _this.startDistance = calcDistance(points[0], points[1]);
  2206. _this.center = getCenter(points[0], points[1]);
  2207. } else {
  2208. // 如果touchstart后停顿250ms, 则也触发press事件
  2209. _this.pressTimeout = setTimeout(function () {
  2210. // 这里固定触发press事件
  2211. var eventType = 'press';
  2212. var direction = 'none';
  2213. ev.direction = direction;
  2214. _this.emitStart(eventType, ev);
  2215. _this.emitEvent(eventType, ev);
  2216. _this.eventType = eventType;
  2217. _this.direction = direction;
  2218. }, PRESS_DELAY);
  2219. }
  2220. };
  2221. this._move = function (ev) {
  2222. var points = convertPoints$1(ev, _this.canvas);
  2223. if (!points) return;
  2224. _this.clearPressTimeout();
  2225. ev.points = points;
  2226. _this.emitEvent('touchmove', ev);
  2227. var startPoints = _this.startPoints;
  2228. if (!startPoints) return;
  2229. // 多指触控
  2230. if (points.length > 1) {
  2231. // touchstart的距离
  2232. var startDistance = _this.startDistance;
  2233. var currentDistance = calcDistance(points[0], points[1]);
  2234. ev.zoom = currentDistance / startDistance;
  2235. ev.center = _this.center;
  2236. // 触发缩放事件
  2237. _this.emitStart('pinch', ev);
  2238. _this.emitEvent('pinch', ev);
  2239. } else {
  2240. var deltaX = points[0].x - startPoints[0].x;
  2241. var deltaY = points[0].y - startPoints[0].y;
  2242. var direction = _this.direction || calcDirection(startPoints[0], points[0]);
  2243. _this.direction = direction;
  2244. // 获取press或者pan的事件类型
  2245. // press 按住滑动, pan表示平移
  2246. // 如果start后立刻move,则触发pan, 如果有停顿,则触发press
  2247. var eventType = _this.getEventType(points);
  2248. ev.direction = direction;
  2249. ev.deltaX = deltaX;
  2250. ev.deltaY = deltaY;
  2251. _this.emitStart(eventType, ev);
  2252. _this.emitEvent(eventType, ev);
  2253. // 记录最后2次move的时间和坐标,为了给swipe事件用
  2254. var prevMoveTime = _this.lastMoveTime;
  2255. var now = Date.now();
  2256. // 最后2次的时间间隔一定要大于0,否则swipe没发计算
  2257. if (now - prevMoveTime > 0) {
  2258. _this.prevMoveTime = prevMoveTime;
  2259. _this.prevMovePoints = _this.lastMovePoints;
  2260. _this.lastMoveTime = now;
  2261. _this.lastMovePoints = points;
  2262. }
  2263. }
  2264. };
  2265. this._end = function (ev) {
  2266. var points = convertPoints$1(ev, _this.canvas);
  2267. ev.points = points;
  2268. _this.emitEnd(ev);
  2269. _this.emitEvent('touchend', ev);
  2270. // swipe事件处理, 在touchend之后触发
  2271. var lastMoveTime = _this.lastMoveTime;
  2272. var now = Date.now();
  2273. // 做这个判断是为了最后一次touchmove后到end前,还有一个停顿的过程
  2274. // 100 是拍的一个值,理论这个值会很短,一般不卡顿的话在10ms以内
  2275. if (now - lastMoveTime < 100) {
  2276. var prevMoveTime = _this.prevMoveTime || _this.startTime;
  2277. var intervalTime = lastMoveTime - prevMoveTime;
  2278. // 时间间隔一定要大于0, 否则计算没意义
  2279. if (intervalTime > 0) {
  2280. var prevMovePoints = _this.prevMovePoints || _this.startPoints;
  2281. var lastMovePoints = _this.lastMovePoints;
  2282. // move速率
  2283. var velocity = calcDistance(prevMovePoints[0], lastMovePoints[0]) / intervalTime;
  2284. // 0.3 是参考hammerjs的设置
  2285. if (velocity > 0.3) {
  2286. ev.velocity = velocity;
  2287. ev.direction = calcDirection(prevMovePoints[0], lastMovePoints[0]);
  2288. ev.velocityX = (lastMovePoints[0].x - prevMovePoints[0].x) / intervalTime;
  2289. ev.velocityY = (lastMovePoints[0].y - prevMovePoints[0].y) / intervalTime;
  2290. _this.emitEvent('swipe', ev);
  2291. }
  2292. }
  2293. }
  2294. _this.reset();
  2295. var touches = ev.touches;
  2296. // 当多指只释放了1指时也会触发end, 这时重新触发一次start
  2297. if (touches && touches.length > 0) {
  2298. _this._start(ev);
  2299. }
  2300. };
  2301. this._cancel = function (ev) {
  2302. _this.emitEvent('touchcancel', ev);
  2303. _this.reset();
  2304. };
  2305. // canvasEl
  2306. this.canvas = canvas;
  2307. this.delegateEvent(el);
  2308. // 用来记录当前触发的事件
  2309. this.processEvent = {};
  2310. }
  2311. _createClass$1(EventController, [{
  2312. key: "delegateEvent",
  2313. value: function delegateEvent(canvasEl) {
  2314. // 代理这几个事件
  2315. canvasEl.addEventListener('click', this._click);
  2316. canvasEl.addEventListener('touchstart', this._start);
  2317. canvasEl.addEventListener('touchmove', this._move);
  2318. canvasEl.addEventListener('touchend', this._end);
  2319. canvasEl.addEventListener('touchcancel', this._cancel);
  2320. }
  2321. }, {
  2322. key: "emitEvent",
  2323. value: function emitEvent(type, ev) {
  2324. var canvas = this.canvas;
  2325. canvas.emit(type, ev);
  2326. }
  2327. }, {
  2328. key: "getEventType",
  2329. value: function getEventType(points) {
  2330. var eventType = this.eventType,
  2331. canvas = this.canvas,
  2332. startTime = this.startTime,
  2333. startPoints = this.startPoints;
  2334. if (eventType) {
  2335. return eventType;
  2336. }
  2337. var type;
  2338. var panEventListeners = canvas.__events.pan;
  2339. // 如果没有pan事件的监听,默认都是press
  2340. if (!panEventListeners || !panEventListeners.length) {
  2341. type = 'press';
  2342. } else {
  2343. // 如果有pan事件的处理,press则需要停顿250ms, 且移动距离小于10
  2344. var now = Date.now();
  2345. if (now - startTime > PRESS_DELAY && calcDistance(startPoints[0], points[0]) < 10) {
  2346. type = 'press';
  2347. } else {
  2348. type = 'pan';
  2349. }
  2350. }
  2351. this.eventType = type;
  2352. return type;
  2353. }
  2354. }, {
  2355. key: "enable",
  2356. value: function enable(eventType) {
  2357. this.processEvent[eventType] = true;
  2358. }
  2359. // 是否进行中的事件
  2360. }, {
  2361. key: "isProcess",
  2362. value: function isProcess(eventType) {
  2363. return this.processEvent[eventType];
  2364. }
  2365. // 触发start事件
  2366. }, {
  2367. key: "emitStart",
  2368. value: function emitStart(type, ev) {
  2369. if (this.isProcess(type)) {
  2370. return;
  2371. }
  2372. this.enable(type);
  2373. this.emitEvent("".concat(type, "start"), ev);
  2374. }
  2375. // 触发end事件
  2376. }, {
  2377. key: "emitEnd",
  2378. value: function emitEnd(ev) {
  2379. var _this2 = this;
  2380. var processEvent = this.processEvent;
  2381. Object.keys(processEvent).forEach(function (type) {
  2382. _this2.emitEvent("".concat(type, "end"), ev);
  2383. delete processEvent[type];
  2384. });
  2385. }
  2386. }, {
  2387. key: "clearPressTimeout",
  2388. value: function clearPressTimeout() {
  2389. if (this.pressTimeout) {
  2390. clearTimeout(this.pressTimeout);
  2391. this.pressTimeout = null;
  2392. }
  2393. }
  2394. }, {
  2395. key: "reset",
  2396. value: function reset() {
  2397. this.clearPressTimeout();
  2398. this.startTime = 0;
  2399. this.startPoints = null;
  2400. this.startDistance = 0;
  2401. this.direction = null;
  2402. this.eventType = null;
  2403. this.pinch = false;
  2404. this.prevMoveTime = 0;
  2405. this.prevMovePoints = null;
  2406. this.lastMoveTime = 0;
  2407. this.lastMovePoints = null;
  2408. }
  2409. }]);
  2410. return EventController;
  2411. }();
  2412. var CanvasElement = /*#__PURE__*/function (_EventEmit) {
  2413. _inherits$1(CanvasElement, _EventEmit);
  2414. var _super = _createSuper$1(CanvasElement);
  2415. /* eslint-enable */
  2416. function CanvasElement(ctx) {
  2417. var _this;
  2418. _classCallCheck$1(this, CanvasElement);
  2419. _this = _super.call(this);
  2420. _this.context = ctx;
  2421. // canvas实际的宽高 (width/height) * pixelRatio
  2422. // 有可能是 node canvas 创建的 context 对象
  2423. var canvas = ctx.canvas || {};
  2424. _this.width = canvas.width || 0;
  2425. _this.height = canvas.height || 0;
  2426. _this.style = {};
  2427. _this.currentStyle = {};
  2428. _this.attrs = {};
  2429. // 用来标识是CanvasElement实例
  2430. _this.isCanvasElement = true;
  2431. return _this;
  2432. }
  2433. _createClass$1(CanvasElement, [{
  2434. key: "getContext",
  2435. value: function getContext( /* type */
  2436. ) {
  2437. return this.context;
  2438. }
  2439. }, {
  2440. key: "getBoundingClientRect",
  2441. value: function getBoundingClientRect() {
  2442. var width = this.width;
  2443. var height = this.height;
  2444. // 默认都处理成可视窗口的顶部位置
  2445. return {
  2446. top: 0,
  2447. right: width,
  2448. bottom: height,
  2449. left: 0
  2450. };
  2451. }
  2452. }, {
  2453. key: "setAttribute",
  2454. value: function setAttribute(key, value) {
  2455. this.attrs[key] = value;
  2456. }
  2457. }, {
  2458. key: "addEventListener",
  2459. value: function addEventListener(type, listener) {
  2460. this.on(type, listener);
  2461. }
  2462. }, {
  2463. key: "removeEventListener",
  2464. value: function removeEventListener(type, listener) {
  2465. this.off(type, listener);
  2466. }
  2467. }, {
  2468. key: "dispatchEvent",
  2469. value: function dispatchEvent(type, e) {
  2470. this.emit(type, e);
  2471. }
  2472. }]);
  2473. return CanvasElement;
  2474. }(EventEmit);
  2475. function supportEventListener(canvas) {
  2476. if (!canvas) {
  2477. return false;
  2478. }
  2479. // 非 HTMLCanvasElement
  2480. if (canvas.nodeType !== 1 || !canvas.nodeName || canvas.nodeName.toLowerCase() !== 'canvas') {
  2481. return false;
  2482. }
  2483. // 微信小程序canvas.getContext('2d')时也是CanvasRenderingContext2D
  2484. // 也会有ctx.canvas, 而且nodeType也是1,所以还要在看下是否支持addEventListener
  2485. var support = false;
  2486. try {
  2487. canvas.addEventListener('eventTest', function () {
  2488. support = true;
  2489. });
  2490. canvas.dispatchEvent(new Event('eventTest'));
  2491. } catch (error) {
  2492. support = false;
  2493. }
  2494. return support;
  2495. }
  2496. var CanvasElement$1 = {
  2497. create: function create(ctx) {
  2498. if (!ctx) {
  2499. return null;
  2500. }
  2501. if (supportEventListener(ctx.canvas)) {
  2502. return ctx.canvas;
  2503. }
  2504. return new CanvasElement(ctx);
  2505. }
  2506. };
  2507. function remove(arr, obj) {
  2508. if (!arr) {
  2509. return;
  2510. }
  2511. var index = arr.indexOf(obj);
  2512. if (index !== -1) {
  2513. arr.splice(index, 1);
  2514. }
  2515. }
  2516. function _defineProperty$1(obj, key, value) {
  2517. key = _toPropertyKey(key);
  2518. if (key in obj) {
  2519. Object.defineProperty(obj, key, {
  2520. value: value,
  2521. enumerable: true,
  2522. configurable: true,
  2523. writable: true
  2524. });
  2525. } else {
  2526. obj[key] = value;
  2527. }
  2528. return obj;
  2529. }
  2530. function ownKeys(object, enumerableOnly) {
  2531. var keys = Object.keys(object);
  2532. if (Object.getOwnPropertySymbols) {
  2533. var symbols = Object.getOwnPropertySymbols(object);
  2534. enumerableOnly && (symbols = symbols.filter(function (sym) {
  2535. return Object.getOwnPropertyDescriptor(object, sym).enumerable;
  2536. })), keys.push.apply(keys, symbols);
  2537. }
  2538. return keys;
  2539. }
  2540. function _objectSpread2(target) {
  2541. for (var i = 1; i < arguments.length; i++) {
  2542. var source = null != arguments[i] ? arguments[i] : {};
  2543. i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
  2544. _defineProperty$1(target, key, source[key]);
  2545. }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
  2546. Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
  2547. });
  2548. }
  2549. return target;
  2550. }
  2551. function _mod(n, m) {
  2552. return (n % m + m) % m;
  2553. }
  2554. function _addStop(steps, gradient) {
  2555. each(steps, function (item) {
  2556. item = item.split(':');
  2557. gradient.addColorStop(Number(item[0]), item[1]);
  2558. });
  2559. }
  2560. // the string format: 'l(0) 0:#ffffff 0.5:#7ec2f3 1:#1890ff'
  2561. function _parseLineGradient(color, shape, context) {
  2562. var arr = color.split(' ');
  2563. var angle = arr[0].slice(2, arr[0].length - 1);
  2564. angle = _mod(parseFloat(angle) * Math.PI / 180, Math.PI * 2);
  2565. var steps = arr.slice(1);
  2566. var _shape$getBBox = shape.getBBox(),
  2567. minX = _shape$getBBox.minX,
  2568. minY = _shape$getBBox.minY,
  2569. maxX = _shape$getBBox.maxX,
  2570. maxY = _shape$getBBox.maxY;
  2571. var start;
  2572. var end;
  2573. if (angle >= 0 && angle < 0.5 * Math.PI) {
  2574. start = {
  2575. x: minX,
  2576. y: minY
  2577. };
  2578. end = {
  2579. x: maxX,
  2580. y: maxY
  2581. };
  2582. } else if (0.5 * Math.PI <= angle && angle < Math.PI) {
  2583. start = {
  2584. x: maxX,
  2585. y: minY
  2586. };
  2587. end = {
  2588. x: minX,
  2589. y: maxY
  2590. };
  2591. } else if (Math.PI <= angle && angle < 1.5 * Math.PI) {
  2592. start = {
  2593. x: maxX,
  2594. y: maxY
  2595. };
  2596. end = {
  2597. x: minX,
  2598. y: minY
  2599. };
  2600. } else {
  2601. start = {
  2602. x: minX,
  2603. y: maxY
  2604. };
  2605. end = {
  2606. x: maxX,
  2607. y: minY
  2608. };
  2609. }
  2610. var tanTheta = Math.tan(angle);
  2611. var tanTheta2 = tanTheta * tanTheta;
  2612. var x = (end.x - start.x + tanTheta * (end.y - start.y)) / (tanTheta2 + 1) + start.x;
  2613. var y = tanTheta * (end.x - start.x + tanTheta * (end.y - start.y)) / (tanTheta2 + 1) + start.y;
  2614. var gradient = context.createLinearGradient(start.x, start.y, x, y);
  2615. _addStop(steps, gradient);
  2616. return gradient;
  2617. }
  2618. // the string format: 'r(0.5, 0.5, 0.1) 0:#ffffff 1:#1890ff'
  2619. function _parseRadialGradient(color, shape, context) {
  2620. var arr = color.split(' ');
  2621. var circleCfg = arr[0].slice(2, arr[0].length - 1);
  2622. circleCfg = circleCfg.split(',');
  2623. var fx = parseFloat(circleCfg[0]);
  2624. var fy = parseFloat(circleCfg[1]);
  2625. var fr = parseFloat(circleCfg[2]);
  2626. var steps = arr.slice(1);
  2627. // if radius is 0, no gradient, stroke with the last color
  2628. if (fr === 0) {
  2629. var _color = steps[steps.length - 1];
  2630. return _color.split(':')[1];
  2631. }
  2632. var _shape$getBBox2 = shape.getBBox(),
  2633. width = _shape$getBBox2.width,
  2634. height = _shape$getBBox2.height,
  2635. minX = _shape$getBBox2.minX,
  2636. minY = _shape$getBBox2.minY;
  2637. var r = Math.sqrt(width * width + height * height) / 2;
  2638. var gradient = context.createRadialGradient(minX + width * fx, minY + height * fy, fr * r, minX + width / 2, minY + height / 2, r);
  2639. _addStop(steps, gradient);
  2640. return gradient;
  2641. }
  2642. function parseStyle(color, shape, context) {
  2643. if (color[1] === '(') {
  2644. try {
  2645. var firstCode = color[0];
  2646. if (firstCode === 'l') {
  2647. return _parseLineGradient(color, shape, context);
  2648. } else if (firstCode === 'r') {
  2649. return _parseRadialGradient(color, shape, context);
  2650. }
  2651. } catch (ev) {
  2652. console.error('error in parsing gradient string, please check if there are any extra whitespaces.');
  2653. console.error(ev);
  2654. }
  2655. }
  2656. return color;
  2657. }
  2658. var ALIAS_ATTRS_MAP = {
  2659. stroke: 'strokeStyle',
  2660. fill: 'fillStyle',
  2661. opacity: 'globalAlpha'
  2662. };
  2663. var SHAPE_ATTRS = ['fillStyle', 'font', 'globalAlpha', 'lineCap', 'lineWidth', 'lineJoin', 'miterLimit', 'shadowBlur', 'shadowColor', 'shadowOffsetX', 'shadowOffsetY', 'strokeStyle', 'textAlign', 'textBaseline', 'lineDash', 'shadow' // 兼容支付宝小程序
  2664. ];
  2665. var CLIP_SHAPES = ['circle', 'sector', 'polygon', 'rect', 'polyline', 'custom'];
  2666. var Element = /*#__PURE__*/function () {
  2667. function Element(cfg) {
  2668. _classCallCheck$1(this, Element);
  2669. this._initProperties();
  2670. mix(this._attrs, cfg);
  2671. var attrs = this._attrs.attrs;
  2672. if (attrs) {
  2673. this.initAttrs(attrs);
  2674. }
  2675. this.initTransform();
  2676. }
  2677. _createClass$1(Element, [{
  2678. key: "_initProperties",
  2679. value: function _initProperties() {
  2680. this._attrs = _objectSpread2(_objectSpread2({}, this._attrs), {}, {
  2681. zIndex: 0,
  2682. visible: true,
  2683. destroyed: false
  2684. });
  2685. }
  2686. }, {
  2687. key: "get",
  2688. value: function get(name) {
  2689. return this._attrs[name];
  2690. }
  2691. }, {
  2692. key: "set",
  2693. value: function set(name, value) {
  2694. this._attrs[name] = value;
  2695. }
  2696. }, {
  2697. key: "isGroup",
  2698. value: function isGroup() {
  2699. return this.get('isGroup');
  2700. }
  2701. }, {
  2702. key: "isShape",
  2703. value: function isShape() {
  2704. return this.get('isShape');
  2705. }
  2706. }, {
  2707. key: "initAttrs",
  2708. value: function initAttrs(attrs) {
  2709. this.attr(mix(this.getDefaultAttrs(), attrs));
  2710. }
  2711. }, {
  2712. key: "getDefaultAttrs",
  2713. value: function getDefaultAttrs() {
  2714. return {};
  2715. }
  2716. }, {
  2717. key: "_setAttr",
  2718. value: function _setAttr(name, value) {
  2719. var attrs = this._attrs.attrs;
  2720. if (name === 'clip') {
  2721. value = this._setAttrClip(value);
  2722. } else {
  2723. var alias = ALIAS_ATTRS_MAP[name];
  2724. if (alias) {
  2725. attrs[alias] = value;
  2726. }
  2727. }
  2728. attrs[name] = value;
  2729. }
  2730. }, {
  2731. key: "_getAttr",
  2732. value: function _getAttr(name) {
  2733. var _this$_attrs, _this$_attrs$attrs;
  2734. return (_this$_attrs = this._attrs) === null || _this$_attrs === void 0 ? void 0 : (_this$_attrs$attrs = _this$_attrs.attrs) === null || _this$_attrs$attrs === void 0 ? void 0 : _this$_attrs$attrs[name];
  2735. }
  2736. }, {
  2737. key: "_afterAttrsSet",
  2738. value: function _afterAttrsSet() {}
  2739. }, {
  2740. key: "_setAttrClip",
  2741. value: function _setAttrClip(clip) {
  2742. if (clip && CLIP_SHAPES.indexOf(clip._attrs.type) > -1) {
  2743. if (clip.get('canvas') === null) {
  2744. clip = _objectSpread2({}, clip);
  2745. }
  2746. clip.set('parent', this.get('parent'));
  2747. clip.set('context', this.get('context'));
  2748. return clip;
  2749. }
  2750. return null;
  2751. }
  2752. }, {
  2753. key: "attr",
  2754. value: function attr(name, value) {
  2755. if (this.get('destroyed')) return null;
  2756. var argumentsLen = arguments.length;
  2757. if (argumentsLen === 0) {
  2758. return this._attrs.attrs;
  2759. }
  2760. if (isObject(name)) {
  2761. this._attrs.bbox = null;
  2762. for (var k in name) {
  2763. this._setAttr(k, name[k]);
  2764. }
  2765. if (this._afterAttrsSet) {
  2766. this._afterAttrsSet();
  2767. }
  2768. return this;
  2769. }
  2770. if (argumentsLen === 2) {
  2771. this._attrs.bbox = null;
  2772. this._setAttr(name, value);
  2773. if (this._afterAttrsSet) {
  2774. this._afterAttrsSet();
  2775. }
  2776. return this;
  2777. }
  2778. return this._getAttr(name);
  2779. }
  2780. }, {
  2781. key: "getParent",
  2782. value: function getParent() {
  2783. return this.get('parent');
  2784. }
  2785. }, {
  2786. key: "draw",
  2787. value: function draw(context) {
  2788. if (this.get('destroyed')) {
  2789. return;
  2790. }
  2791. if (this.get('visible')) {
  2792. this.setContext(context);
  2793. this.drawInner(context);
  2794. this.restoreContext(context);
  2795. }
  2796. }
  2797. }, {
  2798. key: "setContext",
  2799. value: function setContext(context) {
  2800. var clip = this._attrs.attrs.clip;
  2801. context.save();
  2802. if (clip && !clip._attrs.destroyed) {
  2803. clip.resetTransform(context);
  2804. clip.createPath(context);
  2805. context.clip();
  2806. }
  2807. this.resetContext(context);
  2808. this.resetTransform(context);
  2809. }
  2810. }, {
  2811. key: "restoreContext",
  2812. value: function restoreContext(context) {
  2813. context.restore();
  2814. }
  2815. }, {
  2816. key: "resetContext",
  2817. value: function resetContext(context) {
  2818. var elAttrs = this._attrs.attrs;
  2819. for (var k in elAttrs) {
  2820. if (SHAPE_ATTRS.indexOf(k) > -1) {
  2821. var v = elAttrs[k];
  2822. if ((k === 'fillStyle' || k === 'strokeStyle') && v) {
  2823. v = parseStyle(v, this, context);
  2824. }
  2825. if (k === 'lineDash' && context.setLineDash && isArray(v)) {
  2826. context.setLineDash(v);
  2827. } else {
  2828. context[k] = v;
  2829. }
  2830. }
  2831. }
  2832. }
  2833. }, {
  2834. key: "hasFill",
  2835. value: function hasFill() {
  2836. return this.get('canFill') && this._attrs.attrs.fillStyle;
  2837. }
  2838. }, {
  2839. key: "hasStroke",
  2840. value: function hasStroke() {
  2841. return this.get('canStroke') && this._attrs.attrs.strokeStyle;
  2842. }
  2843. }, {
  2844. key: "drawInner",
  2845. value: function drawInner(_context) {}
  2846. }, {
  2847. key: "show",
  2848. value: function show() {
  2849. this.set('visible', true);
  2850. return this;
  2851. }
  2852. }, {
  2853. key: "hide",
  2854. value: function hide() {
  2855. this.set('visible', false);
  2856. return this;
  2857. }
  2858. }, {
  2859. key: "isVisible",
  2860. value: function isVisible() {
  2861. return this.get('visible');
  2862. }
  2863. }, {
  2864. key: "getAriaLabel",
  2865. value: function getAriaLabel() {
  2866. var _this$_attrs2 = this._attrs,
  2867. destroyed = _this$_attrs2.destroyed,
  2868. visible = _this$_attrs2.visible,
  2869. isShape = _this$_attrs2.isShape,
  2870. aria = _this$_attrs2.aria;
  2871. if (destroyed || !visible || isShape && !aria) {
  2872. return;
  2873. }
  2874. return this._getAriaLabel();
  2875. }
  2876. }, {
  2877. key: "_getAriaLabel",
  2878. value: function _getAriaLabel() {
  2879. return this._attrs.ariaLabel;
  2880. }
  2881. }, {
  2882. key: "_removeFromParent",
  2883. value: function _removeFromParent() {
  2884. var parent = this.get('parent');
  2885. if (parent) {
  2886. var children = parent.get('children');
  2887. remove(children, this);
  2888. }
  2889. return this;
  2890. }
  2891. }, {
  2892. key: "remove",
  2893. value: function remove(destroy) {
  2894. if (destroy) {
  2895. this.destroy();
  2896. } else {
  2897. this._removeFromParent();
  2898. }
  2899. }
  2900. }, {
  2901. key: "destroy",
  2902. value: function destroy() {
  2903. var destroyed = this.get('destroyed');
  2904. if (destroyed) {
  2905. return null;
  2906. }
  2907. this._removeFromParent();
  2908. // 保留 attrs
  2909. var attrs = this._attrs.attrs;
  2910. this._attrs = {
  2911. attrs: attrs
  2912. };
  2913. this.set('destroyed', true);
  2914. }
  2915. }, {
  2916. key: "getBBox",
  2917. value: function getBBox() {
  2918. return {
  2919. minX: 0,
  2920. maxX: 0,
  2921. minY: 0,
  2922. maxY: 0,
  2923. width: 0,
  2924. height: 0
  2925. };
  2926. }
  2927. }, {
  2928. key: "initTransform",
  2929. value: function initTransform() {
  2930. var attrs = this._attrs.attrs;
  2931. if (!attrs) {
  2932. attrs = {};
  2933. }
  2934. if (!attrs.matrix) {
  2935. attrs.matrix = [1, 0, 0, 1, 0, 0];
  2936. }
  2937. this._attrs.attrs = attrs;
  2938. }
  2939. }, {
  2940. key: "getMatrix",
  2941. value: function getMatrix() {
  2942. return this._attrs.attrs.matrix;
  2943. }
  2944. }, {
  2945. key: "setMatrix",
  2946. value: function setMatrix(m) {
  2947. this._attrs.attrs.matrix = [m[0], m[1], m[2], m[3], m[4], m[5]];
  2948. }
  2949. }, {
  2950. key: "transform",
  2951. value: function transform(actions) {
  2952. var matrix = this._attrs.attrs.matrix;
  2953. this._attrs.attrs.matrix = Matrix.transform(matrix, actions);
  2954. return this;
  2955. }
  2956. }, {
  2957. key: "setTransform",
  2958. value: function setTransform(actions) {
  2959. this._attrs.attrs.matrix = [1, 0, 0, 1, 0, 0];
  2960. return this.transform(actions);
  2961. }
  2962. }, {
  2963. key: "translate",
  2964. value: function translate(x, y) {
  2965. var matrix = this._attrs.attrs.matrix;
  2966. Matrix.translate(matrix, matrix, [x, y]);
  2967. }
  2968. }, {
  2969. key: "rotate",
  2970. value: function rotate(rad) {
  2971. var matrix = this._attrs.attrs.matrix;
  2972. Matrix.rotate(matrix, matrix, rad);
  2973. }
  2974. }, {
  2975. key: "scale",
  2976. value: function scale(sx, sy) {
  2977. var matrix = this._attrs.attrs.matrix;
  2978. Matrix.scale(matrix, matrix, [sx, sy]);
  2979. }
  2980. }, {
  2981. key: "moveTo",
  2982. value: function moveTo(x, y) {
  2983. var cx = this._attrs.x || 0;
  2984. var cy = this._attrs.y || 0;
  2985. this.translate(x - cx, y - cy);
  2986. this.set('x', x);
  2987. this.set('y', y);
  2988. }
  2989. }, {
  2990. key: "apply",
  2991. value: function apply(v) {
  2992. var m = this._attrs.attrs.matrix;
  2993. Vector2.transformMat2d(v, v, m);
  2994. return this;
  2995. }
  2996. }, {
  2997. key: "resetTransform",
  2998. value: function resetTransform(context) {
  2999. var mo = this._attrs.attrs.matrix;
  3000. if (Matrix.isChanged(mo)) {
  3001. context.transform(mo[0], mo[1], mo[2], mo[3], mo[4], mo[5]);
  3002. }
  3003. }
  3004. }, {
  3005. key: "isDestroyed",
  3006. value: function isDestroyed() {
  3007. return this.get('destroyed');
  3008. }
  3009. }]);
  3010. return Element;
  3011. }();
  3012. var Shape = /*#__PURE__*/function (_Element) {
  3013. _inherits$1(Shape, _Element);
  3014. var _super = _createSuper$1(Shape);
  3015. function Shape() {
  3016. _classCallCheck$1(this, Shape);
  3017. return _super.apply(this, arguments);
  3018. }
  3019. _createClass$1(Shape, [{
  3020. key: "_initProperties",
  3021. value: /* eslint-enable */
  3022. function _initProperties() {
  3023. this._attrs = _objectSpread2(_objectSpread2({}, this._attrs), {}, {
  3024. zIndex: 0,
  3025. visible: true,
  3026. destroyed: false,
  3027. isShape: true,
  3028. attrs: {}
  3029. });
  3030. }
  3031. }, {
  3032. key: "getType",
  3033. value: function getType() {
  3034. return this._attrs.type;
  3035. }
  3036. }, {
  3037. key: "drawInner",
  3038. value: function drawInner(context) {
  3039. var attrs = this.get('attrs');
  3040. this.createPath(context);
  3041. var originOpacity = context.globalAlpha;
  3042. if (this.hasFill()) {
  3043. var fillOpacity = attrs.fillOpacity;
  3044. if (!isNil(fillOpacity) && fillOpacity !== 1) {
  3045. context.globalAlpha = fillOpacity;
  3046. context.fill();
  3047. context.globalAlpha = originOpacity;
  3048. } else {
  3049. context.fill();
  3050. }
  3051. }
  3052. if (this.hasStroke()) {
  3053. var lineWidth = attrs.lineWidth;
  3054. if (lineWidth > 0) {
  3055. var strokeOpacity = attrs.strokeOpacity;
  3056. if (!isNil(strokeOpacity) && strokeOpacity !== 1) {
  3057. context.globalAlpha = strokeOpacity;
  3058. }
  3059. context.stroke();
  3060. }
  3061. }
  3062. }
  3063. }, {
  3064. key: "getBBox",
  3065. value: function getBBox() {
  3066. var bbox = this._attrs.bbox;
  3067. if (!bbox) {
  3068. bbox = this.calculateBox();
  3069. if (bbox) {
  3070. bbox.x = bbox.minX;
  3071. bbox.y = bbox.minY;
  3072. bbox.width = bbox.maxX - bbox.minX;
  3073. bbox.height = bbox.maxY - bbox.minY;
  3074. }
  3075. this._attrs.bbox = bbox;
  3076. }
  3077. return bbox;
  3078. }
  3079. }, {
  3080. key: "calculateBox",
  3081. value: function calculateBox() {
  3082. return null;
  3083. }
  3084. }, {
  3085. key: "createPath",
  3086. value: function createPath(_context) {}
  3087. }]);
  3088. return Shape;
  3089. }(Element);
  3090. function _superPropBase(object, property) {
  3091. while (!Object.prototype.hasOwnProperty.call(object, property)) {
  3092. object = _getPrototypeOf$1(object);
  3093. if (object === null) break;
  3094. }
  3095. return object;
  3096. }
  3097. function _get() {
  3098. if (typeof Reflect !== "undefined" && Reflect.get) {
  3099. _get = Reflect.get.bind();
  3100. } else {
  3101. _get = function _get(target, property, receiver) {
  3102. var base = _superPropBase(target, property);
  3103. if (!base) return;
  3104. var desc = Object.getOwnPropertyDescriptor(base, property);
  3105. if (desc.get) {
  3106. return desc.get.call(arguments.length < 3 ? target : receiver);
  3107. }
  3108. return desc.value;
  3109. };
  3110. }
  3111. return _get.apply(this, arguments);
  3112. }
  3113. function parsePadding(padding) {
  3114. var top = 0;
  3115. var right = 0;
  3116. var bottom = 0;
  3117. var left = 0;
  3118. if (isNumber(padding)) {
  3119. top = bottom = left = right = padding;
  3120. } else if (isArray(padding)) {
  3121. top = padding[0];
  3122. right = !isNil(padding[1]) ? padding[1] : padding[0];
  3123. bottom = !isNil(padding[2]) ? padding[2] : padding[0];
  3124. left = !isNil(padding[3]) ? padding[3] : right;
  3125. }
  3126. return [top, right, bottom, left];
  3127. }
  3128. // 为了处理radius 大于 width 或 height 的场景
  3129. function parseRadius(radius, width, height) {
  3130. radius = parsePadding(radius);
  3131. // 都为0
  3132. if (!radius[0] && !radius[1] && !radius[2] && !radius[3]) {
  3133. return radius;
  3134. }
  3135. var minWidth = Math.max(radius[0] + radius[1], radius[2] + radius[3]);
  3136. var minHeight = Math.max(radius[0] + radius[3], radius[1] + radius[2]);
  3137. var scale = Math.min(width / minWidth, height / minHeight);
  3138. if (scale < 1) {
  3139. return radius.map(function (r) {
  3140. return r * scale;
  3141. });
  3142. }
  3143. return radius;
  3144. }
  3145. var Rect = /*#__PURE__*/function (_Shape) {
  3146. _inherits$1(Rect, _Shape);
  3147. var _super = _createSuper$1(Rect);
  3148. function Rect() {
  3149. _classCallCheck$1(this, Rect);
  3150. return _super.apply(this, arguments);
  3151. }
  3152. _createClass$1(Rect, [{
  3153. key: "_initProperties",
  3154. value: function _initProperties() {
  3155. _get(_getPrototypeOf$1(Rect.prototype), "_initProperties", this).call(this);
  3156. this._attrs.canFill = true;
  3157. this._attrs.canStroke = true;
  3158. this._attrs.type = 'rect';
  3159. }
  3160. }, {
  3161. key: "getDefaultAttrs",
  3162. value: function getDefaultAttrs() {
  3163. return {
  3164. x: 0,
  3165. y: 0,
  3166. width: 0,
  3167. height: 0,
  3168. radius: 0,
  3169. lineWidth: 0
  3170. };
  3171. }
  3172. }, {
  3173. key: "createRadiusPath",
  3174. value: function createRadiusPath(context, x, y, width, height, radius) {
  3175. radius = parseRadius(radius, width, height);
  3176. context.moveTo(x + radius[0], y);
  3177. context.lineTo(x + width - radius[1], y);
  3178. context.arc(x + width - radius[1], y + radius[1], radius[1], -Math.PI / 2, 0, false);
  3179. context.lineTo(x + width, y + height - radius[2]);
  3180. context.arc(x + width - radius[2], y + height - radius[2], radius[2], 0, Math.PI / 2, false);
  3181. context.lineTo(x + radius[3], y + height);
  3182. context.arc(x + radius[3], y + height - radius[3], radius[3], Math.PI / 2, Math.PI, false);
  3183. context.lineTo(x, y + radius[0]);
  3184. context.arc(x + radius[0], y + radius[0], radius[0], Math.PI, Math.PI * 3 / 2, false);
  3185. context.closePath();
  3186. }
  3187. }, {
  3188. key: "createPath",
  3189. value: function createPath(context) {
  3190. var attrs = this.get('attrs');
  3191. var x = attrs.x,
  3192. y = attrs.y,
  3193. width = attrs.width,
  3194. height = attrs.height,
  3195. radius = attrs.radius;
  3196. context.beginPath();
  3197. if (!radius || !(width * height)) {
  3198. context.rect(x, y, width, height);
  3199. } else {
  3200. this.createRadiusPath(context, x, y, width, height, radius);
  3201. }
  3202. }
  3203. }, {
  3204. key: "calculateBox",
  3205. value: function calculateBox() {
  3206. var attrs = this.get('attrs');
  3207. var x = attrs.x,
  3208. y = attrs.y,
  3209. width = attrs.width,
  3210. height = attrs.height;
  3211. return {
  3212. minX: x,
  3213. minY: y,
  3214. maxX: x + width,
  3215. maxY: y + height
  3216. };
  3217. }
  3218. }]);
  3219. return Rect;
  3220. }(Shape);
  3221. var imageCaches = {};
  3222. var ImageShape = /*#__PURE__*/function (_Rect) {
  3223. _inherits$1(ImageShape, _Rect);
  3224. var _super = _createSuper$1(ImageShape);
  3225. function ImageShape() {
  3226. _classCallCheck$1(this, ImageShape);
  3227. return _super.apply(this, arguments);
  3228. }
  3229. _createClass$1(ImageShape, [{
  3230. key: "_initProperties",
  3231. value: function _initProperties() {
  3232. _get(_getPrototypeOf$1(ImageShape.prototype), "_initProperties", this).call(this);
  3233. this._attrs.canFill = false;
  3234. this._attrs.canStroke = false;
  3235. this._attrs.loading = false;
  3236. this._attrs.image = null;
  3237. this._attrs.type = 'image';
  3238. }
  3239. }, {
  3240. key: "draw",
  3241. value: function draw(context) {
  3242. var _this = this;
  3243. // 如果图片还在loading中直接返回,等下次绘制
  3244. if (this.get('loading')) {
  3245. return;
  3246. }
  3247. // 如果已经有image对象,直接绘制,会调用createPath绘制
  3248. var image = this.get('image');
  3249. if (image) {
  3250. _get(_getPrototypeOf$1(ImageShape.prototype), "draw", this).call(this, context);
  3251. return;
  3252. }
  3253. var attrs = this.get('attrs');
  3254. var src = attrs.src;
  3255. if (src) {
  3256. var cacheImage = this.get('cacheImage');
  3257. // 如果有缓存,则直接从缓存中拿
  3258. if (cacheImage && imageCaches[src]) {
  3259. this.set('image', imageCaches[src]);
  3260. this.draw(context);
  3261. return;
  3262. }
  3263. var _image = null;
  3264. var canvas = this.get('canvas');
  3265. if (canvas && canvas.get('createImage')) {
  3266. var createImage = canvas.get('createImage');
  3267. _image = createImage();
  3268. } else if (window.Image) {
  3269. _image = new Image();
  3270. }
  3271. if (_image) {
  3272. this.set('loading', true);
  3273. // 设置跨域, 等同于 image.crossOrigin = 'anonymous'
  3274. _image.crossOrigin = '';
  3275. _image.onload = function () {
  3276. _this.set('loading', false);
  3277. _this.set('image', _image);
  3278. // this.draw(context);
  3279. // 这里需要调用 canvas.draw 进行重新绘制,否则 image 会一直在最上层
  3280. canvas.draw();
  3281. };
  3282. // src 一定要在 crossOrigin 之后,否则 toDataURL 就会报 SecurityError
  3283. _image.src = src;
  3284. // 设置全局缓存
  3285. if (cacheImage) {
  3286. imageCaches[src] = _image;
  3287. }
  3288. }
  3289. }
  3290. }
  3291. }, {
  3292. key: "createPath",
  3293. value: function createPath(context) {
  3294. var image = this.get('image');
  3295. this.drawImage(context, image);
  3296. }
  3297. }, {
  3298. key: "drawImage",
  3299. value: function drawImage(context, image) {
  3300. var _this$_attrs = this._attrs,
  3301. attrs = _this$_attrs.attrs,
  3302. destroyed = _this$_attrs.destroyed;
  3303. if (destroyed) {
  3304. return;
  3305. }
  3306. var x = attrs.x,
  3307. y = attrs.y,
  3308. width = attrs.width,
  3309. height = attrs.height,
  3310. sx = attrs.sx,
  3311. sy = attrs.sy,
  3312. swidth = attrs.swidth,
  3313. sheight = attrs.sheight,
  3314. radius = attrs.radius,
  3315. fillOpacity = attrs.fillOpacity;
  3316. if (radius) {
  3317. context.save();
  3318. this.createRadiusPath(context, x, y, width, height, radius);
  3319. context.clip();
  3320. }
  3321. // 设置透明度
  3322. var originOpacity = context.globalAlpha;
  3323. if (!isNil(fillOpacity)) {
  3324. context.globalAlpha = fillOpacity;
  3325. }
  3326. if (!isNil(sx) && !isNil(sy) && !isNil(swidth) && !isNil(sheight)) {
  3327. context.drawImage(image, sx, sy, swidth, sheight, x, y, width, height);
  3328. } else {
  3329. context.drawImage(image, x, y, width, height);
  3330. }
  3331. context.globalAlpha = originOpacity;
  3332. if (radius) {
  3333. // 因为 save 和 restore 会一定程度上影响绘图性能,所以只在必要是调用
  3334. context.restore();
  3335. }
  3336. }
  3337. }]);
  3338. return ImageShape;
  3339. }(Rect);
  3340. var Circle = /*#__PURE__*/function (_Shape) {
  3341. _inherits$1(Circle, _Shape);
  3342. var _super = _createSuper$1(Circle);
  3343. function Circle() {
  3344. _classCallCheck$1(this, Circle);
  3345. return _super.apply(this, arguments);
  3346. }
  3347. _createClass$1(Circle, [{
  3348. key: "_initProperties",
  3349. value: function _initProperties() {
  3350. _get(_getPrototypeOf$1(Circle.prototype), "_initProperties", this).call(this);
  3351. this._attrs.canFill = true;
  3352. this._attrs.canStroke = true;
  3353. this._attrs.type = 'circle';
  3354. }
  3355. }, {
  3356. key: "getDefaultAttrs",
  3357. value: function getDefaultAttrs() {
  3358. return {
  3359. x: 0,
  3360. y: 0,
  3361. r: 0,
  3362. lineWidth: 0
  3363. };
  3364. }
  3365. }, {
  3366. key: "createPath",
  3367. value: function createPath(context) {
  3368. var attrs = this.get('attrs');
  3369. var x = attrs.x,
  3370. y = attrs.y,
  3371. r = attrs.r;
  3372. context.beginPath();
  3373. context.arc(x, y, r, 0, Math.PI * 2, false);
  3374. context.closePath();
  3375. }
  3376. }, {
  3377. key: "calculateBox",
  3378. value: function calculateBox() {
  3379. var attrs = this.get('attrs');
  3380. var x = attrs.x,
  3381. y = attrs.y,
  3382. r = attrs.r;
  3383. return {
  3384. minX: x - r,
  3385. maxX: x + r,
  3386. minY: y - r,
  3387. maxY: y + r
  3388. };
  3389. }
  3390. }]);
  3391. return Circle;
  3392. }(Shape);
  3393. var Line = /*#__PURE__*/function (_Shape) {
  3394. _inherits$1(Line, _Shape);
  3395. var _super = _createSuper$1(Line);
  3396. function Line() {
  3397. _classCallCheck$1(this, Line);
  3398. return _super.apply(this, arguments);
  3399. }
  3400. _createClass$1(Line, [{
  3401. key: "_initProperties",
  3402. value: function _initProperties() {
  3403. _get(_getPrototypeOf$1(Line.prototype), "_initProperties", this).call(this);
  3404. this._attrs.canStroke = true;
  3405. this._attrs.type = 'line';
  3406. }
  3407. }, {
  3408. key: "getDefaultAttrs",
  3409. value: function getDefaultAttrs() {
  3410. return {
  3411. x1: 0,
  3412. y1: 0,
  3413. x2: 0,
  3414. y2: 0,
  3415. lineWidth: 1
  3416. };
  3417. }
  3418. }, {
  3419. key: "createPath",
  3420. value: function createPath(context) {
  3421. var attrs = this.get('attrs');
  3422. var x1 = attrs.x1,
  3423. y1 = attrs.y1,
  3424. x2 = attrs.x2,
  3425. y2 = attrs.y2;
  3426. context.beginPath();
  3427. context.moveTo(x1, y1);
  3428. context.lineTo(x2, y2);
  3429. }
  3430. }, {
  3431. key: "calculateBox",
  3432. value: function calculateBox() {
  3433. var attrs = this.get('attrs');
  3434. var x1 = attrs.x1,
  3435. y1 = attrs.y1,
  3436. x2 = attrs.x2,
  3437. y2 = attrs.y2,
  3438. lineWidth = attrs.lineWidth;
  3439. return getBBoxFromLine(x1, y1, x2, y2, lineWidth);
  3440. }
  3441. }]);
  3442. return Line;
  3443. }(Shape);
  3444. var Polygon = /*#__PURE__*/function (_Shape) {
  3445. _inherits$1(Polygon, _Shape);
  3446. var _super = _createSuper$1(Polygon);
  3447. function Polygon() {
  3448. _classCallCheck$1(this, Polygon);
  3449. return _super.apply(this, arguments);
  3450. }
  3451. _createClass$1(Polygon, [{
  3452. key: "_initProperties",
  3453. value: function _initProperties() {
  3454. _get(_getPrototypeOf$1(Polygon.prototype), "_initProperties", this).call(this);
  3455. this._attrs.canFill = true;
  3456. this._attrs.canStroke = true;
  3457. this._attrs.type = 'polygon';
  3458. }
  3459. }, {
  3460. key: "getDefaultAttrs",
  3461. value: function getDefaultAttrs() {
  3462. return {
  3463. points: null,
  3464. lineWidth: 0
  3465. };
  3466. }
  3467. }, {
  3468. key: "createPath",
  3469. value: function createPath(context) {
  3470. var attrs = this.get('attrs');
  3471. var points = attrs.points;
  3472. context.beginPath();
  3473. for (var i = 0, len = points.length; i < len; i++) {
  3474. var point = points[i];
  3475. if (i === 0) {
  3476. context.moveTo(point.x, point.y);
  3477. } else {
  3478. context.lineTo(point.x, point.y);
  3479. }
  3480. }
  3481. context.closePath();
  3482. }
  3483. }, {
  3484. key: "calculateBox",
  3485. value: function calculateBox() {
  3486. var attrs = this.get('attrs');
  3487. var points = attrs.points;
  3488. return getBBoxFromPoints(points);
  3489. }
  3490. }]);
  3491. return Polygon;
  3492. }(Shape);
  3493. // filter the point which x or y is NaN
  3494. function _filterPoints(points) {
  3495. var filteredPoints = [];
  3496. for (var i = 0, len = points.length; i < len; i++) {
  3497. var point = points[i];
  3498. if (!isNaN(point.x) && !isNaN(point.y)) {
  3499. filteredPoints.push(point);
  3500. }
  3501. }
  3502. return filteredPoints;
  3503. }
  3504. var Polyline = /*#__PURE__*/function (_Shape) {
  3505. _inherits$1(Polyline, _Shape);
  3506. var _super = _createSuper$1(Polyline);
  3507. function Polyline() {
  3508. _classCallCheck$1(this, Polyline);
  3509. return _super.apply(this, arguments);
  3510. }
  3511. _createClass$1(Polyline, [{
  3512. key: "_initProperties",
  3513. value: function _initProperties() {
  3514. _get(_getPrototypeOf$1(Polyline.prototype), "_initProperties", this).call(this);
  3515. this._attrs.canFill = true;
  3516. this._attrs.canStroke = true;
  3517. this._attrs.type = 'polyline';
  3518. }
  3519. }, {
  3520. key: "getDefaultAttrs",
  3521. value: function getDefaultAttrs() {
  3522. return {
  3523. points: null,
  3524. lineWidth: 1,
  3525. smooth: false
  3526. };
  3527. }
  3528. }, {
  3529. key: "createPath",
  3530. value: function createPath(context) {
  3531. var attrs = this.get('attrs');
  3532. var points = attrs.points,
  3533. smooth = attrs.smooth;
  3534. var filteredPoints = _filterPoints(points);
  3535. context.beginPath();
  3536. if (filteredPoints.length) {
  3537. context.moveTo(filteredPoints[0].x, filteredPoints[0].y);
  3538. if (smooth) {
  3539. var constaint = [[0, 0], [1, 1]];
  3540. var sps = catmullRom2bezier(filteredPoints, false, constaint);
  3541. for (var i = 0, n = sps.length; i < n; i++) {
  3542. var sp = sps[i];
  3543. context.bezierCurveTo(sp[1], sp[2], sp[3], sp[4], sp[5], sp[6]);
  3544. }
  3545. } else {
  3546. var _i;
  3547. var l;
  3548. for (_i = 1, l = filteredPoints.length - 1; _i < l; _i++) {
  3549. context.lineTo(filteredPoints[_i].x, filteredPoints[_i].y);
  3550. }
  3551. context.lineTo(filteredPoints[l].x, filteredPoints[l].y);
  3552. }
  3553. }
  3554. }
  3555. }, {
  3556. key: "calculateBox",
  3557. value: function calculateBox() {
  3558. var attrs = this.get('attrs');
  3559. var points = attrs.points,
  3560. smooth = attrs.smooth,
  3561. lineWidth = attrs.lineWidth;
  3562. var filteredPoints = _filterPoints(points);
  3563. if (smooth) {
  3564. var newPoints = [];
  3565. var constaint = [[0, 0], [1, 1]];
  3566. var sps = catmullRom2bezier(filteredPoints, false, constaint);
  3567. for (var i = 0, n = sps.length; i < n; i++) {
  3568. var sp = sps[i];
  3569. if (i === 0) {
  3570. newPoints.push([filteredPoints[0].x, filteredPoints[0].y, sp[1], sp[2], sp[3], sp[4], sp[5], sp[6]]);
  3571. } else {
  3572. var lastPoint = sps[i - 1];
  3573. newPoints.push([lastPoint[5], lastPoint[6], sp[1], sp[2], sp[3], sp[4], sp[5], sp[6]]);
  3574. }
  3575. }
  3576. return getBBoxFromBezierGroup(newPoints, lineWidth);
  3577. }
  3578. return getBBoxFromPoints(filteredPoints, lineWidth);
  3579. }
  3580. }]);
  3581. return Polyline;
  3582. }(Shape);
  3583. var Arc = /*#__PURE__*/function (_Shape) {
  3584. _inherits$1(Arc, _Shape);
  3585. var _super = _createSuper$1(Arc);
  3586. function Arc() {
  3587. _classCallCheck$1(this, Arc);
  3588. return _super.apply(this, arguments);
  3589. }
  3590. _createClass$1(Arc, [{
  3591. key: "_initProperties",
  3592. value: function _initProperties() {
  3593. _get(_getPrototypeOf$1(Arc.prototype), "_initProperties", this).call(this);
  3594. this._attrs.canStroke = true;
  3595. this._attrs.canFill = true;
  3596. this._attrs.type = 'arc';
  3597. }
  3598. }, {
  3599. key: "getDefaultAttrs",
  3600. value: function getDefaultAttrs() {
  3601. return {
  3602. x: 0,
  3603. y: 0,
  3604. r: 0,
  3605. startAngle: 0,
  3606. endAngle: Math.PI * 2,
  3607. anticlockwise: false,
  3608. lineWidth: 1
  3609. };
  3610. }
  3611. }, {
  3612. key: "createPath",
  3613. value: function createPath(context) {
  3614. var attrs = this.get('attrs');
  3615. var x = attrs.x,
  3616. y = attrs.y,
  3617. r = attrs.r,
  3618. startAngle = attrs.startAngle,
  3619. endAngle = attrs.endAngle,
  3620. anticlockwise = attrs.anticlockwise;
  3621. context.beginPath();
  3622. if (startAngle !== endAngle) {
  3623. context.arc(x, y, r, startAngle, endAngle, anticlockwise);
  3624. }
  3625. }
  3626. }, {
  3627. key: "calculateBox",
  3628. value: function calculateBox() {
  3629. var attrs = this.get('attrs');
  3630. var x = attrs.x,
  3631. y = attrs.y,
  3632. r = attrs.r,
  3633. startAngle = attrs.startAngle,
  3634. endAngle = attrs.endAngle,
  3635. anticlockwise = attrs.anticlockwise;
  3636. return getBBoxFromArc(x, y, r, startAngle, endAngle, anticlockwise);
  3637. }
  3638. }]);
  3639. return Arc;
  3640. }(Shape);
  3641. var Sector = /*#__PURE__*/function (_Shape) {
  3642. _inherits$1(Sector, _Shape);
  3643. var _super = _createSuper$1(Sector);
  3644. function Sector() {
  3645. _classCallCheck$1(this, Sector);
  3646. return _super.apply(this, arguments);
  3647. }
  3648. _createClass$1(Sector, [{
  3649. key: "_initProperties",
  3650. value: function _initProperties() {
  3651. _get(_getPrototypeOf$1(Sector.prototype), "_initProperties", this).call(this);
  3652. this._attrs.canFill = true;
  3653. this._attrs.canStroke = true;
  3654. this._attrs.type = 'sector';
  3655. }
  3656. }, {
  3657. key: "getDefaultAttrs",
  3658. value: function getDefaultAttrs() {
  3659. return {
  3660. x: 0,
  3661. y: 0,
  3662. lineWidth: 0,
  3663. r: 0,
  3664. r0: 0,
  3665. startAngle: 0,
  3666. endAngle: Math.PI * 2,
  3667. anticlockwise: false
  3668. };
  3669. }
  3670. }, {
  3671. key: "createPath",
  3672. value: function createPath(context) {
  3673. var attrs = this.get('attrs');
  3674. var x = attrs.x,
  3675. y = attrs.y,
  3676. startAngle = attrs.startAngle,
  3677. r = attrs.r,
  3678. r0 = attrs.r0,
  3679. anticlockwise = attrs.anticlockwise;
  3680. // 最大为整个圆
  3681. var endAngle = Math.min(attrs.endAngle, startAngle + Math.PI * 2);
  3682. context.beginPath();
  3683. var unitX = Math.cos(startAngle);
  3684. var unitY = Math.sin(startAngle);
  3685. context.moveTo(unitX * r0 + x, unitY * r0 + y);
  3686. context.lineTo(unitX * r + x, unitY * r + y);
  3687. // 当扇形的角度非常小的时候,就不进行弧线的绘制;或者整个只有1个扇形时,会出现end<0的情况不绘制
  3688. if (Math.abs(endAngle - startAngle) > 0.0001 || startAngle === 0 && endAngle < 0) {
  3689. context.arc(x, y, r, startAngle, endAngle, anticlockwise);
  3690. context.lineTo(Math.cos(endAngle) * r0 + x, Math.sin(endAngle) * r0 + y);
  3691. if (r0 !== 0) {
  3692. context.arc(x, y, r0, endAngle, startAngle, !anticlockwise);
  3693. }
  3694. }
  3695. context.closePath();
  3696. }
  3697. }, {
  3698. key: "calculateBox",
  3699. value: function calculateBox() {
  3700. var attrs = this.get('attrs');
  3701. var x = attrs.x,
  3702. y = attrs.y,
  3703. r = attrs.r,
  3704. r0 = attrs.r0,
  3705. startAngle = attrs.startAngle,
  3706. endAngle = attrs.endAngle,
  3707. anticlockwise = attrs.anticlockwise;
  3708. var outerBBox = getBBoxFromArc(x, y, r, startAngle, endAngle, anticlockwise);
  3709. var innerBBox = getBBoxFromArc(x, y, r0, startAngle, endAngle, anticlockwise);
  3710. return {
  3711. minX: Math.min(outerBBox.minX, innerBBox.minX),
  3712. minY: Math.min(outerBBox.minY, innerBBox.minY),
  3713. maxX: Math.max(outerBBox.maxX, innerBBox.maxX),
  3714. maxY: Math.max(outerBBox.maxY, innerBBox.maxY)
  3715. };
  3716. }
  3717. }]);
  3718. return Sector;
  3719. }(Shape);
  3720. var Rect$1 = {
  3721. calcRotatedBox: function calcRotatedBox(_ref) {
  3722. var width = _ref.width,
  3723. height = _ref.height,
  3724. rotate = _ref.rotate;
  3725. var absRotate = Math.abs(rotate);
  3726. return {
  3727. width: Math.abs(width * Math.cos(absRotate) + height * Math.sin(absRotate)),
  3728. height: Math.abs(height * Math.cos(absRotate) + width * Math.sin(absRotate))
  3729. };
  3730. }
  3731. };
  3732. var measureText$1 = measureText;
  3733. var textWidthCacheCounter = 0;
  3734. var textWidthCache = {};
  3735. var TEXT_CACHE_MAX = 5000;
  3736. var Text = /*#__PURE__*/function (_Shape) {
  3737. _inherits$1(Text, _Shape);
  3738. var _super = _createSuper$1(Text);
  3739. function Text() {
  3740. _classCallCheck$1(this, Text);
  3741. return _super.apply(this, arguments);
  3742. }
  3743. _createClass$1(Text, [{
  3744. key: "_initProperties",
  3745. value: function _initProperties() {
  3746. _get(_getPrototypeOf$1(Text.prototype), "_initProperties", this).call(this);
  3747. this._attrs.canFill = true;
  3748. this._attrs.canStroke = true;
  3749. this._attrs.type = 'text';
  3750. }
  3751. }, {
  3752. key: "getDefaultAttrs",
  3753. value: function getDefaultAttrs() {
  3754. return {
  3755. lineWidth: 0,
  3756. lineCount: 1,
  3757. fontSize: 12,
  3758. fontFamily: '',
  3759. fontStyle: 'normal',
  3760. fontWeight: 'normal',
  3761. fontVariant: 'normal',
  3762. textAlign: 'start',
  3763. textBaseline: 'bottom',
  3764. lineHeight: null,
  3765. textArr: null
  3766. };
  3767. }
  3768. }, {
  3769. key: "_getFontStyle",
  3770. value: function _getFontStyle() {
  3771. var attrs = this._attrs.attrs;
  3772. var fontSize = attrs.fontSize,
  3773. fontFamily = attrs.fontFamily,
  3774. fontWeight = attrs.fontWeight,
  3775. fontStyle = attrs.fontStyle,
  3776. fontVariant = attrs.fontVariant;
  3777. return "".concat(fontStyle, " ").concat(fontVariant, " ").concat(fontWeight, " ").concat(fontSize, "px ").concat(fontFamily);
  3778. }
  3779. }, {
  3780. key: "_afterAttrsSet",
  3781. value: function _afterAttrsSet() {
  3782. var attrs = this._attrs.attrs;
  3783. attrs.font = this._getFontStyle();
  3784. if (attrs.text) {
  3785. var text = attrs.text;
  3786. var textArr = null;
  3787. var lineCount = 1;
  3788. if (isString(text) && text.indexOf('\n') !== -1) {
  3789. textArr = text.split('\n');
  3790. lineCount = textArr.length;
  3791. }
  3792. attrs.lineCount = lineCount;
  3793. attrs.textArr = textArr;
  3794. }
  3795. this.set('attrs', attrs);
  3796. }
  3797. }, {
  3798. key: "_getTextHeight",
  3799. value: function _getTextHeight() {
  3800. var attrs = this._attrs.attrs;
  3801. if (attrs.height) {
  3802. return attrs.height;
  3803. }
  3804. var lineCount = attrs.lineCount;
  3805. var fontSize = attrs.fontSize * 1;
  3806. if (lineCount > 1) {
  3807. var spaceingY = this._getSpaceingY();
  3808. return fontSize * lineCount + spaceingY * (lineCount - 1);
  3809. }
  3810. return fontSize;
  3811. }
  3812. }, {
  3813. key: "_getSpaceingY",
  3814. value: function _getSpaceingY() {
  3815. var attrs = this._attrs.attrs;
  3816. var lineHeight = attrs.lineHeight;
  3817. var fontSize = attrs.fontSize * 1;
  3818. return lineHeight ? lineHeight - fontSize : fontSize * 0.14;
  3819. }
  3820. }, {
  3821. key: "drawInner",
  3822. value: function drawInner(context) {
  3823. var attrs = this._attrs.attrs;
  3824. var text = attrs.text;
  3825. var x = attrs.x;
  3826. var y = attrs.y;
  3827. if (isNil(text) || isNaN(x) || isNaN(y)) {
  3828. // text will be 0
  3829. return;
  3830. }
  3831. var textArr = attrs.textArr;
  3832. var fontSize = attrs.fontSize * 1;
  3833. var spaceingY = this._getSpaceingY();
  3834. if (attrs.rotate) {
  3835. // do rotation
  3836. context.translate(x, y);
  3837. context.rotate(attrs.rotate);
  3838. x = 0;
  3839. y = 0;
  3840. }
  3841. var textBaseline = attrs.textBaseline;
  3842. var height;
  3843. if (textArr) {
  3844. height = this._getTextHeight();
  3845. }
  3846. var subY;
  3847. // context.beginPath();
  3848. if (this.hasFill()) {
  3849. var fillOpacity = attrs.fillOpacity;
  3850. if (!isNil(fillOpacity) && fillOpacity !== 1) {
  3851. context.globalAlpha = fillOpacity;
  3852. }
  3853. if (textArr) {
  3854. for (var i = 0, len = textArr.length; i < len; i++) {
  3855. var subText = textArr[i];
  3856. subY = y + i * (spaceingY + fontSize) - height + fontSize; // bottom;
  3857. if (textBaseline === 'middle') {
  3858. subY += height - fontSize - (height - fontSize) / 2;
  3859. }
  3860. if (textBaseline === 'top') {
  3861. subY += height - fontSize;
  3862. }
  3863. context.fillText(subText, x, subY);
  3864. }
  3865. } else {
  3866. context.fillText(text, x, y);
  3867. }
  3868. }
  3869. if (this.hasStroke()) {
  3870. if (textArr) {
  3871. for (var _i = 0, _len = textArr.length; _i < _len; _i++) {
  3872. var _subText = textArr[_i];
  3873. subY = y + _i * (spaceingY + fontSize) - height + fontSize; // bottom;
  3874. if (textBaseline === 'middle') {
  3875. subY += height - fontSize - (height - fontSize) / 2;
  3876. }
  3877. if (textBaseline === 'top') {
  3878. subY += height - fontSize;
  3879. }
  3880. context.strokeText(_subText, x, subY);
  3881. }
  3882. } else {
  3883. context.strokeText(text, x, y);
  3884. }
  3885. }
  3886. }
  3887. }, {
  3888. key: "_getAriaLabel",
  3889. value: function _getAriaLabel() {
  3890. return this._attrs.attrs.text;
  3891. }
  3892. }, {
  3893. key: "calculateBox",
  3894. value: function calculateBox() {
  3895. var attrs = this._attrs.attrs;
  3896. var x = attrs.x,
  3897. y = attrs.y,
  3898. textAlign = attrs.textAlign,
  3899. textBaseline = attrs.textBaseline;
  3900. var width = this._getTextWidth(); // attrs.width
  3901. if (!width) {
  3902. return {
  3903. minX: x,
  3904. minY: y,
  3905. maxX: x,
  3906. maxY: y
  3907. };
  3908. }
  3909. var height = this._getTextHeight(); // attrs.height
  3910. if (attrs.rotate) {
  3911. var rotatedBox = Rect$1.calcRotatedBox({
  3912. width: width,
  3913. height: height,
  3914. rotate: attrs.rotate
  3915. });
  3916. width = rotatedBox.width;
  3917. height = rotatedBox.height;
  3918. }
  3919. var point = {
  3920. x: x,
  3921. y: y - height
  3922. }; // default textAlign: start, textBaseline: bottom
  3923. if (textAlign) {
  3924. if (textAlign === 'end' || textAlign === 'right') {
  3925. point.x -= width;
  3926. } else if (textAlign === 'center') {
  3927. point.x -= width / 2;
  3928. }
  3929. }
  3930. if (textBaseline) {
  3931. if (textBaseline === 'top') {
  3932. point.y += height;
  3933. } else if (textBaseline === 'middle') {
  3934. point.y += height / 2;
  3935. }
  3936. }
  3937. return {
  3938. minX: point.x,
  3939. minY: point.y,
  3940. maxX: point.x + width,
  3941. maxY: point.y + height
  3942. };
  3943. }
  3944. }, {
  3945. key: "_getTextWidth",
  3946. value: function _getTextWidth() {
  3947. var attrs = this._attrs.attrs;
  3948. if (attrs.width) {
  3949. return attrs.width;
  3950. }
  3951. var text = attrs.text;
  3952. var context = this.get('context');
  3953. if (isNil(text)) return undefined;
  3954. var font = attrs.font;
  3955. var textArr = attrs.textArr;
  3956. var key = text + '' + font;
  3957. if (textWidthCache[key]) {
  3958. return textWidthCache[key];
  3959. }
  3960. var width = 0;
  3961. if (textArr) {
  3962. for (var i = 0, length = textArr.length; i < length; i++) {
  3963. var subText = textArr[i];
  3964. width = Math.max(width, measureText$1(subText, font, context).width);
  3965. }
  3966. } else {
  3967. width = measureText$1(text, font, context).width;
  3968. }
  3969. if (textWidthCacheCounter > TEXT_CACHE_MAX) {
  3970. textWidthCacheCounter = 0;
  3971. textWidthCache = {};
  3972. }
  3973. textWidthCacheCounter++;
  3974. textWidthCache[key] = width;
  3975. return width;
  3976. }
  3977. }]);
  3978. return Text;
  3979. }(Shape);
  3980. var Custom = /*#__PURE__*/function (_Shape) {
  3981. _inherits$1(Custom, _Shape);
  3982. var _super = _createSuper$1(Custom);
  3983. function Custom() {
  3984. _classCallCheck$1(this, Custom);
  3985. return _super.apply(this, arguments);
  3986. }
  3987. _createClass$1(Custom, [{
  3988. key: "_initProperties",
  3989. value: function _initProperties() {
  3990. _get(_getPrototypeOf$1(Custom.prototype), "_initProperties", this).call(this);
  3991. this._attrs.canFill = true;
  3992. this._attrs.canStroke = true;
  3993. this._attrs.createPath = null;
  3994. this._attrs.type = 'custom';
  3995. }
  3996. }, {
  3997. key: "createPath",
  3998. value: function createPath(context) {
  3999. var createPath = this.get('createPath');
  4000. createPath && createPath.call(this, context);
  4001. }
  4002. }, {
  4003. key: "calculateBox",
  4004. value: function calculateBox() {
  4005. var calculateBox = this.get('calculateBox');
  4006. return calculateBox && calculateBox.call(this);
  4007. }
  4008. }]);
  4009. return Custom;
  4010. }(Shape);
  4011. var SYMBOLS = {
  4012. circle: function circle(x, y, r, ctx) {
  4013. ctx.arc(x, y, r, 0, Math.PI * 2, false);
  4014. },
  4015. square: function square(x, y, r, ctx) {
  4016. ctx.moveTo(x - r, y - r);
  4017. ctx.lineTo(x + r, y - r);
  4018. ctx.lineTo(x + r, y + r);
  4019. ctx.lineTo(x - r, y + r);
  4020. ctx.closePath();
  4021. }
  4022. };
  4023. var Marker = /*#__PURE__*/function (_Shape) {
  4024. _inherits$1(Marker, _Shape);
  4025. var _super = _createSuper$1(Marker);
  4026. function Marker() {
  4027. _classCallCheck$1(this, Marker);
  4028. return _super.apply(this, arguments);
  4029. }
  4030. _createClass$1(Marker, [{
  4031. key: "_initProperties",
  4032. value: function _initProperties() {
  4033. _get(_getPrototypeOf$1(Marker.prototype), "_initProperties", this).call(this);
  4034. this._attrs.canFill = true;
  4035. this._attrs.canStroke = true;
  4036. this._attrs.type = 'marker';
  4037. }
  4038. }, {
  4039. key: "getDefaultAttrs",
  4040. value: function getDefaultAttrs() {
  4041. return {
  4042. x: 0,
  4043. y: 0,
  4044. lineWidth: 0
  4045. };
  4046. }
  4047. }, {
  4048. key: "createPath",
  4049. value: function createPath(context) {
  4050. var attrs = this.get('attrs');
  4051. var x = attrs.x,
  4052. y = attrs.y,
  4053. radius = attrs.radius;
  4054. var symbol = attrs.symbol || 'circle';
  4055. var method;
  4056. if (isFunction(symbol)) {
  4057. method = symbol;
  4058. } else {
  4059. method = SYMBOLS[symbol];
  4060. }
  4061. context.beginPath();
  4062. method(x, y, radius, context, this);
  4063. }
  4064. }, {
  4065. key: "calculateBox",
  4066. value: function calculateBox() {
  4067. var attrs = this.get('attrs');
  4068. var x = attrs.x,
  4069. y = attrs.y,
  4070. radius = attrs.radius;
  4071. return {
  4072. minX: x - radius,
  4073. minY: y - radius,
  4074. maxX: x + radius,
  4075. maxY: y + radius
  4076. };
  4077. }
  4078. }]);
  4079. return Marker;
  4080. }(Shape);
  4081. Shape.Rect = Rect;
  4082. Shape.Image = ImageShape;
  4083. Shape.Circle = Circle;
  4084. Shape.Line = Line;
  4085. Shape.Polygon = Polygon;
  4086. Shape.Polyline = Polyline;
  4087. Shape.Arc = Arc;
  4088. Shape.Sector = Sector;
  4089. Shape.Text = Text;
  4090. Shape.Custom = Custom;
  4091. Shape.Marker = Marker;
  4092. var SHAPE_MAP = {};
  4093. var INDEX = '_INDEX';
  4094. function getComparer(compare) {
  4095. return function (left, right) {
  4096. var result = compare(left, right);
  4097. return result === 0 ? left[INDEX] - right[INDEX] : result;
  4098. };
  4099. }
  4100. var Container = {
  4101. getGroupClass: function getGroupClass() {},
  4102. getChildren: function getChildren() {
  4103. return this.get('children');
  4104. },
  4105. addShape: function addShape(type) {
  4106. var cfg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  4107. var shapeType = SHAPE_MAP[type];
  4108. if (!shapeType) {
  4109. shapeType = upperFirst(type);
  4110. SHAPE_MAP[type] = shapeType;
  4111. }
  4112. var shape = new Shape[shapeType](cfg);
  4113. this.add(shape);
  4114. return shape;
  4115. },
  4116. addGroup: function addGroup(cfg) {
  4117. var groupClass = this.getGroupClass();
  4118. var rst = new groupClass(cfg);
  4119. this.add(rst);
  4120. return rst;
  4121. },
  4122. contain: function contain(item) {
  4123. var children = this.get('children');
  4124. return children.indexOf(item) > -1;
  4125. },
  4126. sort: function sort() {
  4127. var children = this.get('children');
  4128. for (var i = 0, len = children.length; i < len; i++) {
  4129. var child = children[i];
  4130. child[INDEX] = i;
  4131. }
  4132. children.sort(getComparer(function (obj1, obj2) {
  4133. return obj1.get('zIndex') - obj2.get('zIndex');
  4134. }));
  4135. return this;
  4136. },
  4137. drawChildren: function drawChildren(context) {
  4138. this.sort();
  4139. var children = this.get('children');
  4140. for (var i = 0, len = children.length; i < len; i++) {
  4141. var child = children[i];
  4142. child.draw(context);
  4143. }
  4144. return this;
  4145. },
  4146. clear: function clear() {
  4147. var children = this.get('children') || [];
  4148. while (children.length !== 0) {
  4149. children[children.length - 1].remove(true);
  4150. }
  4151. return this;
  4152. },
  4153. add: function add(items) {
  4154. var children = this.get('children');
  4155. if (!children) {
  4156. children = [];
  4157. this.set('children', children);
  4158. }
  4159. if (!isArray(items)) {
  4160. items = [items];
  4161. }
  4162. for (var i = 0, len = items.length; i < len; i++) {
  4163. var item = items[i];
  4164. var parent = item.get('parent');
  4165. if (parent) {
  4166. var descendants = parent.get('children');
  4167. remove(descendants, item);
  4168. }
  4169. this._setEvn(item);
  4170. children.push(item);
  4171. }
  4172. return this;
  4173. },
  4174. _setEvn: function _setEvn(item) {
  4175. var _item$_attrs$attrs, _item$_attrs$attrs2;
  4176. var _this$_attrs = this._attrs,
  4177. context = _this$_attrs.context,
  4178. canvas = _this$_attrs.canvas,
  4179. aria = _this$_attrs.aria;
  4180. var _item$_attrs = item._attrs,
  4181. isGroup = _item$_attrs.isGroup,
  4182. type = _item$_attrs.type;
  4183. item._attrs.parent = this;
  4184. item._attrs.context = context;
  4185. item._attrs.canvas = canvas;
  4186. // 是否需要无障碍处理
  4187. if (aria && item._attrs.aria !== false) {
  4188. item._attrs.aria = aria;
  4189. }
  4190. if (type === 'text' && canvas && canvas.get('fontFamily') && !((_item$_attrs$attrs = item._attrs.attrs) === null || _item$_attrs$attrs === void 0 ? void 0 : _item$_attrs$attrs.fontFamily)) {
  4191. item.attr('fontFamily', canvas.get('fontFamily'));
  4192. }
  4193. var clip = (_item$_attrs$attrs2 = item._attrs.attrs) === null || _item$_attrs$attrs2 === void 0 ? void 0 : _item$_attrs$attrs2.clip;
  4194. if (clip) {
  4195. clip._attrs.parent = this;
  4196. clip._attrs.context = context;
  4197. clip._attrs.canvas = canvas;
  4198. }
  4199. if (isGroup) {
  4200. var children = item._attrs.children;
  4201. for (var i = 0, len = children.length; i < len; i++) {
  4202. item._setEvn(children[i]);
  4203. }
  4204. }
  4205. },
  4206. _getAriaLabel: function _getAriaLabel() {
  4207. var _this$_attrs2 = this._attrs,
  4208. aria = _this$_attrs2.aria,
  4209. ariaLabel = _this$_attrs2.ariaLabel,
  4210. children = _this$_attrs2.children;
  4211. // 主动关闭
  4212. if (!aria) return;
  4213. var childAriaLabels = [];
  4214. if (children && children.length) {
  4215. for (var i = 0, len = children.length; i < len; i++) {
  4216. var _childAriaLabel = children[i].getAriaLabel();
  4217. if (_childAriaLabel) {
  4218. childAriaLabels.push(_childAriaLabel);
  4219. }
  4220. }
  4221. }
  4222. var childAriaLabel = childAriaLabels.join(' ');
  4223. // 2个都有时拼接成完整句子
  4224. if (ariaLabel && childAriaLabel) {
  4225. return "".concat(ariaLabel, " ").concat(childAriaLabel, " ");
  4226. }
  4227. // 只有1个,或者都没有
  4228. return ariaLabel || childAriaLabel;
  4229. }
  4230. };
  4231. var Group = /*#__PURE__*/function (_Rect) {
  4232. _inherits$1(Group, _Rect);
  4233. var _super = _createSuper$1(Group);
  4234. function Group() {
  4235. _classCallCheck$1(this, Group);
  4236. return _super.apply(this, arguments);
  4237. }
  4238. _createClass$1(Group, [{
  4239. key: "_initProperties",
  4240. value: /* eslint-enable */
  4241. function _initProperties() {
  4242. this._attrs = {
  4243. type: 'group',
  4244. zIndex: 0,
  4245. visible: true,
  4246. destroyed: false,
  4247. isGroup: true,
  4248. canFill: true,
  4249. canStroke: true,
  4250. children: [],
  4251. attrs: {
  4252. x: 0,
  4253. y: 0,
  4254. width: 0,
  4255. height: 0,
  4256. radius: 0,
  4257. lineWidth: 0
  4258. }
  4259. };
  4260. }
  4261. }, {
  4262. key: "getBBox",
  4263. value: function getBBox() {
  4264. var minX = Infinity;
  4265. var maxX = -Infinity;
  4266. var minY = Infinity;
  4267. var maxY = -Infinity;
  4268. var children = this.get('children');
  4269. for (var i = 0, length = children.length; i < length; i++) {
  4270. var child = children[i];
  4271. if (child.get('visible')) {
  4272. var box = child.getBBox();
  4273. if (!box) {
  4274. continue;
  4275. }
  4276. var leftTop = [box.minX, box.minY];
  4277. var leftBottom = [box.minX, box.maxY];
  4278. var rightTop = [box.maxX, box.minY];
  4279. var rightBottom = [box.maxX, box.maxY];
  4280. var matrix = child.attr('matrix');
  4281. Vector2.transformMat2d(leftTop, leftTop, matrix);
  4282. Vector2.transformMat2d(leftBottom, leftBottom, matrix);
  4283. Vector2.transformMat2d(rightTop, rightTop, matrix);
  4284. Vector2.transformMat2d(rightBottom, rightBottom, matrix);
  4285. minX = Math.min(leftTop[0], leftBottom[0], rightTop[0], rightBottom[0], minX);
  4286. maxX = Math.max(leftTop[0], leftBottom[0], rightTop[0], rightBottom[0], maxX);
  4287. minY = Math.min(leftTop[1], leftBottom[1], rightTop[1], rightBottom[1], minY);
  4288. maxY = Math.max(leftTop[1], leftBottom[1], rightTop[1], rightBottom[1], maxY);
  4289. }
  4290. }
  4291. return {
  4292. minX: minX,
  4293. minY: minY,
  4294. maxX: maxX,
  4295. maxY: maxY,
  4296. x: minX,
  4297. y: minY,
  4298. width: maxX - minX,
  4299. height: maxY - minY
  4300. };
  4301. }
  4302. }, {
  4303. key: "createPath",
  4304. value: function createPath(context) {
  4305. var attrs = this.get('attrs');
  4306. // 只有在有fillStyle或strokeStyle 时才需要绘制
  4307. if (!attrs.fillStyle && !attrs.strokeStyle) {
  4308. return;
  4309. }
  4310. _get(_getPrototypeOf$1(Group.prototype), "createPath", this).call(this, context);
  4311. }
  4312. }, {
  4313. key: "drawInner",
  4314. value: function drawInner(context) {
  4315. _get(_getPrototypeOf$1(Group.prototype), "drawInner", this).call(this, context);
  4316. this.drawChildren(context);
  4317. }
  4318. }, {
  4319. key: "destroy",
  4320. value: function destroy() {
  4321. if (this.get('destroyed')) {
  4322. return;
  4323. }
  4324. this.clear();
  4325. _get(_getPrototypeOf$1(Group.prototype), "destroy", this).call(this);
  4326. }
  4327. }]);
  4328. return Group;
  4329. }(Rect); // @ts-ignore
  4330. mix(Group.prototype, Container, {
  4331. getGroupClass: function getGroupClass() {
  4332. return Group;
  4333. }
  4334. });
  4335. var requestAnimationFrame$1 = (typeof window === "undefined" ? "undefined" : _typeof$1(window)) === 'object' && window.requestAnimationFrame ? window.requestAnimationFrame : function (fn) {
  4336. return setTimeout(fn, 16);
  4337. };
  4338. var lang = {
  4339. general: {
  4340. title: '这是一个图表,',
  4341. withTitle: '这是一个关于“{title}”的图表。'
  4342. },
  4343. coord: {
  4344. cartesian: 'X轴是{xLabel}Y轴是{yLabel}'
  4345. // polar: '弧度是{xLabel}半径是{yLabel}'
  4346. },
  4347. scale: {
  4348. linear: '数值型,数据最小值为{min},最大值为{max};',
  4349. cat: '分类型, 分类类型有:{values};',
  4350. timeCat: '时间型,时间范围从{start}到{end};'
  4351. },
  4352. geometry: {
  4353. prefix: '共有{count}种分类组成,',
  4354. oneData: '第{index}类是{name},数据是{values};',
  4355. partData: '第{index}类是{name},共有{count}项数据,前{part}项是{values};',
  4356. allData: '第{index}类是{name},有{count}项数据,分别是{values};'
  4357. },
  4358. legend: {
  4359. prefix: '图例分类有:'
  4360. }
  4361. };
  4362. var getPixelRatio$1 = getPixelRatio,
  4363. getDomById$1 = getDomById,
  4364. getWidth$1 = getWidth,
  4365. getHeight$1 = getHeight,
  4366. isCanvasElement$1 = isCanvasElement;
  4367. var Canvas = /*#__PURE__*/function (_EventEmit) {
  4368. _inherits$1(Canvas, _EventEmit);
  4369. var _super = _createSuper$1(Canvas);
  4370. function Canvas(cfg) {
  4371. var _this;
  4372. _classCallCheck$1(this, Canvas);
  4373. _this = _super.call(this);
  4374. var title = cfg.title;
  4375. var ariaLabel = title ? substitute(lang.general.withTitle, {
  4376. title: title
  4377. }) : lang.general.title;
  4378. _this._attrs = mix({
  4379. type: 'canvas',
  4380. children: [],
  4381. ariaLabel: ariaLabel
  4382. }, cfg);
  4383. _this._initPixelRatio();
  4384. _this._initCanvas();
  4385. return _this;
  4386. }
  4387. _createClass$1(Canvas, [{
  4388. key: "get",
  4389. value: /* eslint-enable */
  4390. function get(name) {
  4391. return this._attrs[name];
  4392. }
  4393. }, {
  4394. key: "set",
  4395. value: function set(name, value) {
  4396. this._attrs[name] = value;
  4397. }
  4398. }, {
  4399. key: "_initPixelRatio",
  4400. value: function _initPixelRatio() {
  4401. var pixelRatio = this.get('pixelRatio');
  4402. if (!pixelRatio) {
  4403. this.set('pixelRatio', getPixelRatio$1());
  4404. }
  4405. }
  4406. }, {
  4407. key: "beforeDraw",
  4408. value: function beforeDraw() {
  4409. var context = this._attrs.context;
  4410. var el = this._attrs.el;
  4411. context && context.clearRect && context.clearRect(0, 0, el.width, el.height);
  4412. }
  4413. }, {
  4414. key: "_initCanvas",
  4415. value: function _initCanvas() {
  4416. var el = this.get('el');
  4417. var context = this.get('context');
  4418. if (!el && !context) {
  4419. throw new Error('Please specify the id, el or context of the chart!');
  4420. }
  4421. var canvas;
  4422. if (el) {
  4423. // DOMElement or String
  4424. canvas = isString(el) ? getDomById$1(el) : el;
  4425. } else {
  4426. // 说明没有指定el
  4427. canvas = CanvasElement$1.create(context);
  4428. }
  4429. if (context && canvas && !canvas.getContext) {
  4430. canvas.getContext = function () {
  4431. return context;
  4432. };
  4433. }
  4434. var width = this.get('width') || getWidth$1(canvas) || canvas.width;
  4435. var height = this.get('height') || getHeight$1(canvas) || canvas.height;
  4436. this.set('canvas', this);
  4437. this.set('el', canvas);
  4438. this.set('context', context || canvas.getContext('2d'));
  4439. this.changeSize(width, height);
  4440. // 初始化事件控制器
  4441. var eventController = new EventController({
  4442. canvas: this,
  4443. el: canvas
  4444. });
  4445. this.set('eventController', eventController);
  4446. }
  4447. }, {
  4448. key: "changeSize",
  4449. value: function changeSize(width, height) {
  4450. var pixelRatio = this.get('pixelRatio');
  4451. var canvasDOM = this.get('el'); // HTMLCanvasElement or canvasElement
  4452. // 浏览器环境设置style样式
  4453. if (canvasDOM.style) {
  4454. canvasDOM.style.width = width + 'px';
  4455. canvasDOM.style.height = height + 'px';
  4456. }
  4457. if (isCanvasElement$1(canvasDOM)) {
  4458. canvasDOM.width = width * pixelRatio;
  4459. canvasDOM.height = height * pixelRatio;
  4460. if (pixelRatio !== 1) {
  4461. var ctx = this.get('context');
  4462. ctx.scale(pixelRatio, pixelRatio);
  4463. }
  4464. }
  4465. this.set('width', width);
  4466. this.set('height', height);
  4467. }
  4468. }, {
  4469. key: "getWidth",
  4470. value: function getWidth() {
  4471. var pixelRatio = this.get('pixelRatio');
  4472. var width = this.get('width');
  4473. return width * pixelRatio;
  4474. }
  4475. }, {
  4476. key: "getHeight",
  4477. value: function getHeight() {
  4478. var pixelRatio = this.get('pixelRatio');
  4479. var height = this.get('height');
  4480. return height * pixelRatio;
  4481. }
  4482. }, {
  4483. key: "getPointByClient",
  4484. value: function getPointByClient(clientX, clientY) {
  4485. var el = this.get('el');
  4486. var bbox = el.getBoundingClientRect();
  4487. var width = bbox.right - bbox.left;
  4488. var height = bbox.bottom - bbox.top;
  4489. return {
  4490. x: (clientX - bbox.left) * (el.width / width),
  4491. y: (clientY - bbox.top) * (el.height / height)
  4492. };
  4493. }
  4494. }, {
  4495. key: "_beginDraw",
  4496. value: function _beginDraw() {
  4497. this._attrs.toDraw = true;
  4498. }
  4499. }, {
  4500. key: "_endDraw",
  4501. value: function _endDraw() {
  4502. this._attrs.toDraw = false;
  4503. }
  4504. }, {
  4505. key: "draw",
  4506. value: function draw() {
  4507. var _this2 = this;
  4508. var drawInner = function drawInner() {
  4509. _this2.set('animateHandler', requestAnimationFrame$1(function () {
  4510. _this2.set('animateHandler', undefined);
  4511. if (_this2.get('toDraw')) {
  4512. drawInner();
  4513. }
  4514. }));
  4515. _this2.beforeDraw();
  4516. try {
  4517. var context = _this2._attrs.context;
  4518. _this2.drawChildren(context);
  4519. // 支付宝,微信小程序,需要调context.draw才能完成绘制, 所以这里直接判断是否有.draw方法
  4520. if (context.draw) {
  4521. context.draw();
  4522. }
  4523. // 设置无障碍文本
  4524. _this2.setAriaLabel();
  4525. } catch (ev) {
  4526. console.warn('error in draw canvas, detail as:');
  4527. console.warn(ev);
  4528. _this2._endDraw();
  4529. }
  4530. _this2._endDraw();
  4531. };
  4532. if (this.get('destroyed')) {
  4533. return;
  4534. }
  4535. if (this.get('animateHandler')) {
  4536. this._beginDraw();
  4537. } else {
  4538. drawInner();
  4539. }
  4540. }
  4541. // 设置无障碍文本
  4542. }, {
  4543. key: "setAriaLabel",
  4544. value: function setAriaLabel() {
  4545. var el = this._attrs.el;
  4546. var ariaLabel = this._getAriaLabel();
  4547. if (ariaLabel && el.setAttribute) {
  4548. el.setAttribute('aria-label', ariaLabel);
  4549. }
  4550. }
  4551. }, {
  4552. key: "destroy",
  4553. value: function destroy() {
  4554. if (this.get('destroyed')) {
  4555. return;
  4556. }
  4557. // 需要清理 canvas 画布内容,否则会导致 spa 应用 ios 下 canvas 白屏
  4558. // https://stackoverflow.com/questions/52532614/total-canvas-memory-use-exceeds-the-maximum-limit-safari-12
  4559. // https://github.com/antvis/F2/issues/630
  4560. var el = this.get('el');
  4561. el.width = 0;
  4562. el.height = 0;
  4563. this.clear();
  4564. this._attrs = {};
  4565. this.set('destroyed', true);
  4566. }
  4567. }, {
  4568. key: "isDestroyed",
  4569. value: function isDestroyed() {
  4570. return this.get('destroyed');
  4571. }
  4572. }]);
  4573. return Canvas;
  4574. }(EventEmit); // @ts-ignore
  4575. mix(Canvas.prototype, Container, {
  4576. getGroupClass: function getGroupClass() {
  4577. return Group;
  4578. }
  4579. });
  4580. var engines = {};
  4581. function getEngine(name) {
  4582. var G = engines[name];
  4583. if (G) {
  4584. return G;
  4585. }
  4586. return {
  4587. Canvas: Canvas,
  4588. Group: Group,
  4589. Shape: Shape
  4590. };
  4591. }
  4592. function createCanvas(cfg) {
  4593. var renderer = cfg.renderer;
  4594. var G = getEngine(renderer);
  4595. return new G.Canvas(cfg);
  4596. }
  4597. var objectWithoutPropertiesLoose = createCommonjsModule(function (module) {
  4598. function _objectWithoutPropertiesLoose(source, excluded) {
  4599. if (source == null) return {};
  4600. var target = {};
  4601. var sourceKeys = Object.keys(source);
  4602. var key, i;
  4603. for (i = 0; i < sourceKeys.length; i++) {
  4604. key = sourceKeys[i];
  4605. if (excluded.indexOf(key) >= 0) continue;
  4606. target[key] = source[key];
  4607. }
  4608. return target;
  4609. }
  4610. module.exports = _objectWithoutPropertiesLoose, module.exports.__esModule = true, module.exports["default"] = module.exports;
  4611. });
  4612. var objectWithoutProperties = createCommonjsModule(function (module) {
  4613. function _objectWithoutProperties(source, excluded) {
  4614. if (source == null) return {};
  4615. var target = objectWithoutPropertiesLoose(source, excluded);
  4616. var key, i;
  4617. if (Object.getOwnPropertySymbols) {
  4618. var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
  4619. for (i = 0; i < sourceSymbolKeys.length; i++) {
  4620. key = sourceSymbolKeys[i];
  4621. if (excluded.indexOf(key) >= 0) continue;
  4622. if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
  4623. target[key] = source[key];
  4624. }
  4625. }
  4626. return target;
  4627. }
  4628. module.exports = _objectWithoutProperties, module.exports.__esModule = true, module.exports["default"] = module.exports;
  4629. });
  4630. var _objectWithoutProperties = /*@__PURE__*/getDefaultExportFromCjs(objectWithoutProperties);
  4631. var _excluded = ["key", "ref"];
  4632. // 实现jsx-classic 入口
  4633. function jsx(type, config) {
  4634. var _ref = config || {},
  4635. key = _ref.key,
  4636. ref = _ref.ref,
  4637. props = _objectWithoutProperties(_ref, _excluded);
  4638. // 保持和automatic模式一致
  4639. for (var _len = arguments.length, children = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
  4640. children[_key - 2] = arguments[_key];
  4641. }
  4642. if (children.length) {
  4643. props.children = children.length === 1 ? children[0] : children;
  4644. }
  4645. return {
  4646. key: key,
  4647. ref: ref,
  4648. type: type,
  4649. props: props,
  4650. // 存储一些过程中的cache值
  4651. _cache: {}
  4652. };
  4653. }
  4654. var fragment = (function (props) {
  4655. return props.children;
  4656. });
  4657. // 默认设置50
  4658. var ONE_REM;
  4659. try {
  4660. // xgraph下这段会抛错
  4661. ONE_REM = parseInt(document.documentElement.style.fontSize, 10) || 50;
  4662. } catch (e) {
  4663. ONE_REM = 50;
  4664. }
  4665. var SCALE = ONE_REM / 100;
  4666. /**
  4667. * 像素转换
  4668. * @param {Number} px - 750视觉稿像素
  4669. * @return {Number} 屏幕上实际像素
  4670. */
  4671. function defaultPx2hd(px) {
  4672. if (!px) {
  4673. return 0;
  4674. }
  4675. return Number((px * SCALE).toFixed(1));
  4676. }
  4677. function parsePadding$1(padding) {
  4678. if (isNumber(padding)) {
  4679. return [padding, padding, padding, padding];
  4680. }
  4681. var top = padding[0];
  4682. var right = isNumber(padding[1]) ? padding[1] : padding[0];
  4683. var bottom = isNumber(padding[2]) ? padding[2] : top;
  4684. var left = isNumber(padding[3]) ? padding[3] : right;
  4685. return [top, right, bottom, left];
  4686. }
  4687. function batch2hd(px2hd) {
  4688. var batchPx2hd = function batchPx2hd(value) {
  4689. // 处理带px的数据
  4690. if (isString(value) && /^-?\d+px$/.test(value)) {
  4691. var num = value.substr(0, value.length - 2);
  4692. return px2hd(Number(num));
  4693. }
  4694. if (isArray(value)) {
  4695. return value.map(function (v) {
  4696. return batchPx2hd(v);
  4697. });
  4698. }
  4699. if (isPlainObject(value)) {
  4700. var result = {};
  4701. for (var key in value) {
  4702. if (value.hasOwnProperty(key)) {
  4703. var rst = batchPx2hd(value[key]);
  4704. if (!rst) {
  4705. result[key] = rst;
  4706. continue;
  4707. }
  4708. if (key === 'padding' || key === 'margin') {
  4709. var paddingArray = parsePadding$1(rst);
  4710. result[key] = paddingArray;
  4711. result["".concat(key, "Top")] = paddingArray[0];
  4712. result["".concat(key, "Right")] = paddingArray[1];
  4713. result["".concat(key, "Bottom")] = paddingArray[2];
  4714. result["".concat(key, "Left")] = paddingArray[3];
  4715. continue;
  4716. }
  4717. result[key] = rst;
  4718. }
  4719. }
  4720. return result;
  4721. }
  4722. // 默认直接返回
  4723. return value;
  4724. };
  4725. return batchPx2hd;
  4726. }
  4727. // 展开数组
  4728. function extendMap(arr, fn) {
  4729. if (!arr) {
  4730. return arr;
  4731. }
  4732. if (!isArray(arr)) {
  4733. return [fn(arr)];
  4734. }
  4735. var newArray = [];
  4736. for (var i = 0; i < arr.length; i++) {
  4737. var element = arr[i];
  4738. if (isArray(element)) {
  4739. newArray = newArray.concat(extendMap(element, fn));
  4740. } else if (element) {
  4741. newArray.push(fn(element));
  4742. }
  4743. }
  4744. return newArray;
  4745. }
  4746. function toTimeStamp(value) {
  4747. if (isString(value)) {
  4748. if (value.indexOf('T') > 0) {
  4749. value = new Date(value).getTime();
  4750. } else {
  4751. // new Date('2010/01/10') 和 new Date('2010-01-10') 的差别在于:
  4752. // 如果仅有年月日时,前者是带有时区的: Fri Jan 10 2020 02:40:13 GMT+0800 (中国标准时间)
  4753. // 后者会格式化成 Sun Jan 10 2010 08:00:00 GMT+0800 (中国标准时间)
  4754. value = new Date(value.replace(/-/gi, '/')).getTime();
  4755. }
  4756. }
  4757. if (isDate(value)) {
  4758. value = value.getTime();
  4759. }
  4760. return value;
  4761. }
  4762. function isInBBox(bbox, point) {
  4763. var minX = bbox.minX,
  4764. maxX = bbox.maxX,
  4765. minY = bbox.minY,
  4766. maxY = bbox.maxY;
  4767. var x = point.x,
  4768. y = point.y;
  4769. return minX <= x && maxX >= x && minY <= y && maxY >= y;
  4770. }
  4771. function getElementsByClassName(className, element) {
  4772. if (!element || !className) return [];
  4773. var rst = [];
  4774. if (element.get('className') === className) {
  4775. rst.push(element);
  4776. }
  4777. var children = element.get('children');
  4778. if (children && children.length) {
  4779. for (var i = 0; i < children.length; i++) {
  4780. var child = children[i];
  4781. rst = rst.concat(getElementsByClassName(className, child));
  4782. }
  4783. }
  4784. return rst;
  4785. }
  4786. var px2hd = batch2hd(defaultPx2hd);
  4787. /* eslint-disable */
  4788. // @ts-nocheck
  4789. // from css-layout
  4790. var CSS_UNDEFINED;
  4791. var CSS_DIRECTION_INHERIT = 'inherit';
  4792. var CSS_DIRECTION_LTR = 'ltr';
  4793. var CSS_DIRECTION_RTL = 'rtl';
  4794. var CSS_FLEX_DIRECTION_ROW = 'row';
  4795. var CSS_FLEX_DIRECTION_ROW_REVERSE = 'row-reverse';
  4796. var CSS_FLEX_DIRECTION_COLUMN = 'column';
  4797. var CSS_FLEX_DIRECTION_COLUMN_REVERSE = 'column-reverse';
  4798. var CSS_JUSTIFY_FLEX_START = 'flex-start';
  4799. var CSS_JUSTIFY_CENTER = 'center';
  4800. var CSS_JUSTIFY_FLEX_END = 'flex-end';
  4801. var CSS_JUSTIFY_SPACE_BETWEEN = 'space-between';
  4802. var CSS_JUSTIFY_SPACE_AROUND = 'space-around';
  4803. var CSS_ALIGN_FLEX_START = 'flex-start';
  4804. var CSS_ALIGN_CENTER = 'center';
  4805. var CSS_ALIGN_FLEX_END = 'flex-end';
  4806. var CSS_ALIGN_STRETCH = 'stretch';
  4807. var CSS_POSITION_RELATIVE = 'relative';
  4808. var CSS_POSITION_ABSOLUTE = 'absolute';
  4809. var leading = {
  4810. row: 'left',
  4811. 'row-reverse': 'right',
  4812. column: 'top',
  4813. 'column-reverse': 'bottom'
  4814. };
  4815. var trailing = {
  4816. row: 'right',
  4817. 'row-reverse': 'left',
  4818. column: 'bottom',
  4819. 'column-reverse': 'top'
  4820. };
  4821. var pos = {
  4822. row: 'left',
  4823. 'row-reverse': 'right',
  4824. column: 'top',
  4825. 'column-reverse': 'bottom'
  4826. };
  4827. var dim = {
  4828. row: 'width',
  4829. 'row-reverse': 'width',
  4830. column: 'height',
  4831. 'column-reverse': 'height'
  4832. };
  4833. // When transpiled to Java / C the node type has layout, children and style
  4834. // properties. For the JavaScript version this function adds these properties
  4835. // if they don't already exist.
  4836. function fillNodes(node) {
  4837. if (!node.layout || node.isDirty) {
  4838. node.layout = {
  4839. width: undefined,
  4840. height: undefined,
  4841. top: 0,
  4842. left: 0,
  4843. right: 0,
  4844. bottom: 0
  4845. };
  4846. }
  4847. if (!node.style) {
  4848. node.style = {};
  4849. }
  4850. if (!node.children) {
  4851. node.children = [];
  4852. }
  4853. node.children.forEach(fillNodes);
  4854. return node;
  4855. }
  4856. function isUndefined$1(value) {
  4857. return value === undefined;
  4858. }
  4859. function isRowDirection(flexDirection) {
  4860. return flexDirection === CSS_FLEX_DIRECTION_ROW || flexDirection === CSS_FLEX_DIRECTION_ROW_REVERSE;
  4861. }
  4862. function isColumnDirection(flexDirection) {
  4863. return flexDirection === CSS_FLEX_DIRECTION_COLUMN || flexDirection === CSS_FLEX_DIRECTION_COLUMN_REVERSE;
  4864. }
  4865. function getLeadingMargin(node, axis) {
  4866. if (node.style.marginStart !== undefined && isRowDirection(axis)) {
  4867. return node.style.marginStart;
  4868. }
  4869. var value = null;
  4870. switch (axis) {
  4871. case 'row':
  4872. value = node.style.marginLeft;
  4873. break;
  4874. case 'row-reverse':
  4875. value = node.style.marginRight;
  4876. break;
  4877. case 'column':
  4878. value = node.style.marginTop;
  4879. break;
  4880. case 'column-reverse':
  4881. value = node.style.marginBottom;
  4882. break;
  4883. }
  4884. if (value !== undefined) {
  4885. return value;
  4886. }
  4887. if (node.style.margin !== undefined) {
  4888. return node.style.margin;
  4889. }
  4890. return 0;
  4891. }
  4892. function getTrailingMargin(node, axis) {
  4893. if (node.style.marginEnd !== undefined && isRowDirection(axis)) {
  4894. return node.style.marginEnd;
  4895. }
  4896. var value = null;
  4897. switch (axis) {
  4898. case 'row':
  4899. value = node.style.marginRight;
  4900. break;
  4901. case 'row-reverse':
  4902. value = node.style.marginLeft;
  4903. break;
  4904. case 'column':
  4905. value = node.style.marginBottom;
  4906. break;
  4907. case 'column-reverse':
  4908. value = node.style.marginTop;
  4909. break;
  4910. }
  4911. if (value != null) {
  4912. return value;
  4913. }
  4914. if (node.style.margin !== undefined) {
  4915. return node.style.margin;
  4916. }
  4917. return 0;
  4918. }
  4919. function getLeadingPadding(node, axis) {
  4920. if (node.style.paddingStart !== undefined && node.style.paddingStart >= 0 && isRowDirection(axis)) {
  4921. return node.style.paddingStart;
  4922. }
  4923. var value = null;
  4924. switch (axis) {
  4925. case 'row':
  4926. value = node.style.paddingLeft;
  4927. break;
  4928. case 'row-reverse':
  4929. value = node.style.paddingRight;
  4930. break;
  4931. case 'column':
  4932. value = node.style.paddingTop;
  4933. break;
  4934. case 'column-reverse':
  4935. value = node.style.paddingBottom;
  4936. break;
  4937. }
  4938. if (value != null && value >= 0) {
  4939. return value;
  4940. }
  4941. if (node.style.padding !== undefined && node.style.padding >= 0) {
  4942. return node.style.padding;
  4943. }
  4944. return 0;
  4945. }
  4946. function getTrailingPadding(node, axis) {
  4947. if (node.style.paddingEnd !== undefined && node.style.paddingEnd >= 0 && isRowDirection(axis)) {
  4948. return node.style.paddingEnd;
  4949. }
  4950. var value = null;
  4951. switch (axis) {
  4952. case 'row':
  4953. value = node.style.paddingRight;
  4954. break;
  4955. case 'row-reverse':
  4956. value = node.style.paddingLeft;
  4957. break;
  4958. case 'column':
  4959. value = node.style.paddingBottom;
  4960. break;
  4961. case 'column-reverse':
  4962. value = node.style.paddingTop;
  4963. break;
  4964. }
  4965. if (value != null && value >= 0) {
  4966. return value;
  4967. }
  4968. if (node.style.padding !== undefined && node.style.padding >= 0) {
  4969. return node.style.padding;
  4970. }
  4971. return 0;
  4972. }
  4973. function getLeadingBorder(node, axis) {
  4974. if (node.style.borderStartWidth !== undefined && node.style.borderStartWidth >= 0 && isRowDirection(axis)) {
  4975. return node.style.borderStartWidth;
  4976. }
  4977. var value = null;
  4978. switch (axis) {
  4979. case 'row':
  4980. value = node.style.borderLeftWidth;
  4981. break;
  4982. case 'row-reverse':
  4983. value = node.style.borderRightWidth;
  4984. break;
  4985. case 'column':
  4986. value = node.style.borderTopWidth;
  4987. break;
  4988. case 'column-reverse':
  4989. value = node.style.borderBottomWidth;
  4990. break;
  4991. }
  4992. if (value != null && value >= 0) {
  4993. return value;
  4994. }
  4995. if (node.style.borderWidth !== undefined && node.style.borderWidth >= 0) {
  4996. return node.style.borderWidth;
  4997. }
  4998. return 0;
  4999. }
  5000. function getTrailingBorder(node, axis) {
  5001. if (node.style.borderEndWidth !== undefined && node.style.borderEndWidth >= 0 && isRowDirection(axis)) {
  5002. return node.style.borderEndWidth;
  5003. }
  5004. var value = null;
  5005. switch (axis) {
  5006. case 'row':
  5007. value = node.style.borderRightWidth;
  5008. break;
  5009. case 'row-reverse':
  5010. value = node.style.borderLeftWidth;
  5011. break;
  5012. case 'column':
  5013. value = node.style.borderBottomWidth;
  5014. break;
  5015. case 'column-reverse':
  5016. value = node.style.borderTopWidth;
  5017. break;
  5018. }
  5019. if (value != null && value >= 0) {
  5020. return value;
  5021. }
  5022. if (node.style.borderWidth !== undefined && node.style.borderWidth >= 0) {
  5023. return node.style.borderWidth;
  5024. }
  5025. return 0;
  5026. }
  5027. function getLeadingPaddingAndBorder(node, axis) {
  5028. return getLeadingPadding(node, axis) + getLeadingBorder(node, axis);
  5029. }
  5030. function getTrailingPaddingAndBorder(node, axis) {
  5031. return getTrailingPadding(node, axis) + getTrailingBorder(node, axis);
  5032. }
  5033. function getBorderAxis(node, axis) {
  5034. return getLeadingBorder(node, axis) + getTrailingBorder(node, axis);
  5035. }
  5036. function getMarginAxis(node, axis) {
  5037. return getLeadingMargin(node, axis) + getTrailingMargin(node, axis);
  5038. }
  5039. function getPaddingAndBorderAxis(node, axis) {
  5040. return getLeadingPaddingAndBorder(node, axis) + getTrailingPaddingAndBorder(node, axis);
  5041. }
  5042. function getJustifyContent(node) {
  5043. if (node.style.justifyContent) {
  5044. return node.style.justifyContent;
  5045. }
  5046. return 'flex-start';
  5047. }
  5048. function getAlignContent(node) {
  5049. if (node.style.alignContent) {
  5050. return node.style.alignContent;
  5051. }
  5052. return 'flex-start';
  5053. }
  5054. function getAlignItem(node, child) {
  5055. if (child.style.alignSelf) {
  5056. return child.style.alignSelf;
  5057. }
  5058. if (node.style.alignItems) {
  5059. return node.style.alignItems;
  5060. }
  5061. return 'stretch';
  5062. }
  5063. function resolveAxis(axis, direction) {
  5064. if (direction === CSS_DIRECTION_RTL) {
  5065. if (axis === CSS_FLEX_DIRECTION_ROW) {
  5066. return CSS_FLEX_DIRECTION_ROW_REVERSE;
  5067. } else if (axis === CSS_FLEX_DIRECTION_ROW_REVERSE) {
  5068. return CSS_FLEX_DIRECTION_ROW;
  5069. }
  5070. }
  5071. return axis;
  5072. }
  5073. function resolveDirection(node, parentDirection) {
  5074. var direction;
  5075. if (node.style.direction) {
  5076. direction = node.style.direction;
  5077. } else {
  5078. direction = CSS_DIRECTION_INHERIT;
  5079. }
  5080. if (direction === CSS_DIRECTION_INHERIT) {
  5081. direction = parentDirection === undefined ? CSS_DIRECTION_LTR : parentDirection;
  5082. }
  5083. return direction;
  5084. }
  5085. function getFlexDirection(node) {
  5086. if (node.style.flexDirection) {
  5087. return node.style.flexDirection;
  5088. }
  5089. return CSS_FLEX_DIRECTION_COLUMN;
  5090. }
  5091. function getCrossFlexDirection(flexDirection, direction) {
  5092. if (isColumnDirection(flexDirection)) {
  5093. return resolveAxis(CSS_FLEX_DIRECTION_ROW, direction);
  5094. } else {
  5095. return CSS_FLEX_DIRECTION_COLUMN;
  5096. }
  5097. }
  5098. function getPositionType(node) {
  5099. if (node.style.position) {
  5100. return node.style.position;
  5101. }
  5102. return 'relative';
  5103. }
  5104. function isFlex(node) {
  5105. return getPositionType(node) === CSS_POSITION_RELATIVE && node.style.flex > 0;
  5106. }
  5107. function isFlexWrap(node) {
  5108. return node.style.flexWrap === 'wrap';
  5109. }
  5110. function getDimWithMargin(node, axis) {
  5111. return node.layout[dim[axis]] + getMarginAxis(node, axis);
  5112. }
  5113. function isDimDefined(node, axis) {
  5114. return node.style[dim[axis]] !== undefined && node.style[dim[axis]] >= 0;
  5115. }
  5116. function isPosDefined(node, pos) {
  5117. return node.style[pos] !== undefined;
  5118. }
  5119. function isMeasureDefined(node) {
  5120. return node.style.measure !== undefined;
  5121. }
  5122. function getPosition(node, pos) {
  5123. if (node.style[pos] !== undefined) {
  5124. return node.style[pos];
  5125. }
  5126. return 0;
  5127. }
  5128. function boundAxis(node, axis, value) {
  5129. var min = {
  5130. row: node.style.minWidth,
  5131. 'row-reverse': node.style.minWidth,
  5132. column: node.style.minHeight,
  5133. 'column-reverse': node.style.minHeight
  5134. }[axis];
  5135. var max = {
  5136. row: node.style.maxWidth,
  5137. 'row-reverse': node.style.maxWidth,
  5138. column: node.style.maxHeight,
  5139. 'column-reverse': node.style.maxHeight
  5140. }[axis];
  5141. var boundValue = value;
  5142. if (max !== undefined && max >= 0 && boundValue > max) {
  5143. boundValue = max;
  5144. }
  5145. if (min !== undefined && min >= 0 && boundValue < min) {
  5146. boundValue = min;
  5147. }
  5148. return boundValue;
  5149. }
  5150. function fmaxf(a, b) {
  5151. if (a > b) {
  5152. return a;
  5153. }
  5154. return b;
  5155. }
  5156. // When the user specifically sets a value for width or height
  5157. function setDimensionFromStyle(node, axis) {
  5158. // The parent already computed us a width or height. We just skip it
  5159. if (node.layout[dim[axis]] !== undefined) {
  5160. return;
  5161. }
  5162. // We only run if there's a width or height defined
  5163. if (!isDimDefined(node, axis)) {
  5164. return;
  5165. }
  5166. // The dimensions can never be smaller than the padding and border
  5167. node.layout[dim[axis]] = fmaxf(boundAxis(node, axis, node.style[dim[axis]]), getPaddingAndBorderAxis(node, axis));
  5168. }
  5169. function setTrailingPosition(node, child, axis) {
  5170. child.layout[trailing[axis]] = node.layout[dim[axis]] - child.layout[dim[axis]] - child.layout[pos[axis]];
  5171. }
  5172. // If both left and right are defined, then use left. Otherwise return
  5173. // +left or -right depending on which is defined.
  5174. function getRelativePosition$1(node, axis) {
  5175. if (node.style[leading[axis]] !== undefined) {
  5176. return getPosition(node, leading[axis]);
  5177. }
  5178. return -getPosition(node, trailing[axis]);
  5179. }
  5180. function layoutNodeImpl(node, parentMaxWidth, /*css_direction_t*/parentDirection) {
  5181. var /*css_direction_t*/direction = resolveDirection(node, parentDirection);
  5182. var /*(c)!css_flex_direction_t*/ /*(java)!int*/mainAxis = resolveAxis(getFlexDirection(node), direction);
  5183. var /*(c)!css_flex_direction_t*/ /*(java)!int*/crossAxis = getCrossFlexDirection(mainAxis, direction);
  5184. var /*(c)!css_flex_direction_t*/ /*(java)!int*/resolvedRowAxis = resolveAxis(CSS_FLEX_DIRECTION_ROW, direction);
  5185. // Handle width and height style attributes
  5186. setDimensionFromStyle(node, mainAxis);
  5187. setDimensionFromStyle(node, crossAxis);
  5188. // Set the resolved resolution in the node's layout
  5189. node.layout.direction = direction;
  5190. // The position is set by the parent, but we need to complete it with a
  5191. // delta composed of the margin and left/top/right/bottom
  5192. node.layout[leading[mainAxis]] += getLeadingMargin(node, mainAxis) + getRelativePosition$1(node, mainAxis);
  5193. node.layout[trailing[mainAxis]] += getTrailingMargin(node, mainAxis) + getRelativePosition$1(node, mainAxis);
  5194. node.layout[leading[crossAxis]] += getLeadingMargin(node, crossAxis) + getRelativePosition$1(node, crossAxis);
  5195. node.layout[trailing[crossAxis]] += getTrailingMargin(node, crossAxis) + getRelativePosition$1(node, crossAxis);
  5196. // Inline immutable values from the target node to avoid excessive method
  5197. // invocations during the layout calculation.
  5198. var /*int*/childCount = node.children.length;
  5199. var /*float*/paddingAndBorderAxisResolvedRow = getPaddingAndBorderAxis(node, resolvedRowAxis);
  5200. if (isMeasureDefined(node)) {
  5201. var /*bool*/isResolvedRowDimDefined = !isUndefined$1(node.layout[dim[resolvedRowAxis]]);
  5202. var /*float*/width = CSS_UNDEFINED;
  5203. if (isDimDefined(node, resolvedRowAxis)) {
  5204. width = node.style.width;
  5205. } else if (isResolvedRowDimDefined) {
  5206. width = node.layout[dim[resolvedRowAxis]];
  5207. } else {
  5208. width = parentMaxWidth - getMarginAxis(node, resolvedRowAxis);
  5209. }
  5210. width -= paddingAndBorderAxisResolvedRow;
  5211. // We only need to give a dimension for the text if we haven't got any
  5212. // for it computed yet. It can either be from the style attribute or because
  5213. // the element is flexible.
  5214. var /*bool*/isRowUndefined = !isDimDefined(node, resolvedRowAxis) && !isResolvedRowDimDefined;
  5215. var /*bool*/isColumnUndefined = !isDimDefined(node, CSS_FLEX_DIRECTION_COLUMN) && isUndefined$1(node.layout[dim[CSS_FLEX_DIRECTION_COLUMN]]);
  5216. // Let's not measure the text if we already know both dimensions
  5217. if (isRowUndefined || isColumnUndefined) {
  5218. var /*css_dim_t*/measureDim = node.style.measure( /*(c)!node->context,*/
  5219. /*(java)!layoutContext.measureOutput,*/
  5220. width);
  5221. if (isRowUndefined) {
  5222. node.layout.width = measureDim.width + paddingAndBorderAxisResolvedRow;
  5223. }
  5224. if (isColumnUndefined) {
  5225. node.layout.height = measureDim.height + getPaddingAndBorderAxis(node, CSS_FLEX_DIRECTION_COLUMN);
  5226. }
  5227. }
  5228. if (childCount === 0) {
  5229. return;
  5230. }
  5231. }
  5232. var /*bool*/isNodeFlexWrap = isFlexWrap(node);
  5233. var /*css_justify_t*/justifyContent = getJustifyContent(node);
  5234. var /*float*/leadingPaddingAndBorderMain = getLeadingPaddingAndBorder(node, mainAxis);
  5235. var /*float*/leadingPaddingAndBorderCross = getLeadingPaddingAndBorder(node, crossAxis);
  5236. var /*float*/paddingAndBorderAxisMain = getPaddingAndBorderAxis(node, mainAxis);
  5237. var /*float*/paddingAndBorderAxisCross = getPaddingAndBorderAxis(node, crossAxis);
  5238. var /*bool*/isMainDimDefined = !isUndefined$1(node.layout[dim[mainAxis]]);
  5239. var /*bool*/isCrossDimDefined = !isUndefined$1(node.layout[dim[crossAxis]]);
  5240. var /*bool*/isMainRowDirection = isRowDirection(mainAxis);
  5241. var /*int*/i;
  5242. var /*int*/ii;
  5243. var /*css_node_t**/child;
  5244. var /*(c)!css_flex_direction_t*/ /*(java)!int*/axis;
  5245. var /*css_node_t**/firstAbsoluteChild = null;
  5246. var /*css_node_t**/currentAbsoluteChild = null;
  5247. var /*float*/definedMainDim = CSS_UNDEFINED;
  5248. if (isMainDimDefined) {
  5249. definedMainDim = node.layout[dim[mainAxis]] - paddingAndBorderAxisMain;
  5250. }
  5251. // We want to execute the next two loops one per line with flex-wrap
  5252. var /*int*/startLine = 0;
  5253. var /*int*/endLine = 0;
  5254. // var/*int*/ nextOffset = 0;
  5255. var /*int*/alreadyComputedNextLayout = 0;
  5256. // We aggregate the total dimensions of the container in those two variables
  5257. var /*float*/linesCrossDim = 0;
  5258. var /*float*/linesMainDim = 0;
  5259. var /*int*/linesCount = 0;
  5260. while (endLine < childCount) {
  5261. // <Loop A> Layout non flexible children and count children by type
  5262. // mainContentDim is accumulation of the dimensions and margin of all the
  5263. // non flexible children. This will be used in order to either set the
  5264. // dimensions of the node if none already exist, or to compute the
  5265. // remaining space left for the flexible children.
  5266. var /*float*/mainContentDim = 0;
  5267. // There are three kind of children, non flexible, flexible and absolute.
  5268. // We need to know how many there are in order to distribute the space.
  5269. var /*int*/flexibleChildrenCount = 0;
  5270. var /*float*/totalFlexible = 0;
  5271. var /*int*/nonFlexibleChildrenCount = 0;
  5272. // Use the line loop to position children in the main axis for as long
  5273. // as they are using a simple stacking behaviour. Children that are
  5274. // immediately stacked in the initial loop will not be touched again
  5275. // in <Loop C>.
  5276. var /*bool*/isSimpleStackMain = isMainDimDefined && justifyContent === CSS_JUSTIFY_FLEX_START || !isMainDimDefined && justifyContent !== CSS_JUSTIFY_CENTER;
  5277. var /*int*/firstComplexMain = isSimpleStackMain ? childCount : startLine;
  5278. // Use the initial line loop to position children in the cross axis for
  5279. // as long as they are relatively positioned with alignment STRETCH or
  5280. // FLEX_START. Children that are immediately stacked in the initial loop
  5281. // will not be touched again in <Loop D>.
  5282. var /*bool*/isSimpleStackCross = true;
  5283. var /*int*/firstComplexCross = childCount;
  5284. var /*css_node_t**/firstFlexChild = null;
  5285. var /*css_node_t**/currentFlexChild = null;
  5286. var /*float*/mainDim = leadingPaddingAndBorderMain;
  5287. var /*float*/crossDim = 0;
  5288. var /*float*/maxWidth;
  5289. for (i = startLine; i < childCount; ++i) {
  5290. child = node.children[i];
  5291. child.lineIndex = linesCount;
  5292. child.nextAbsoluteChild = null;
  5293. child.nextFlexChild = null;
  5294. var /*css_align_t*/alignItem = getAlignItem(node, child);
  5295. // Pre-fill cross axis dimensions when the child is using stretch before
  5296. // we call the recursive layout pass
  5297. if (alignItem === CSS_ALIGN_STRETCH && getPositionType(child) === CSS_POSITION_RELATIVE && isCrossDimDefined && !isDimDefined(child, crossAxis)) {
  5298. child.layout[dim[crossAxis]] = fmaxf(boundAxis(child, crossAxis, node.layout[dim[crossAxis]] - paddingAndBorderAxisCross - getMarginAxis(child, crossAxis)),
  5299. // You never want to go smaller than padding
  5300. getPaddingAndBorderAxis(child, crossAxis));
  5301. } else if (getPositionType(child) === CSS_POSITION_ABSOLUTE) {
  5302. // Store a private linked list of absolutely positioned children
  5303. // so that we can efficiently traverse them later.
  5304. if (firstAbsoluteChild === null) {
  5305. firstAbsoluteChild = child;
  5306. }
  5307. if (currentAbsoluteChild !== null) {
  5308. currentAbsoluteChild.nextAbsoluteChild = child;
  5309. }
  5310. currentAbsoluteChild = child;
  5311. // Pre-fill dimensions when using absolute position and both offsets for the axis are defined (either both
  5312. // left and right or top and bottom).
  5313. for (ii = 0; ii < 2; ii++) {
  5314. axis = ii !== 0 ? CSS_FLEX_DIRECTION_ROW : CSS_FLEX_DIRECTION_COLUMN;
  5315. if (!isUndefined$1(node.layout[dim[axis]]) && !isDimDefined(child, axis) && isPosDefined(child, leading[axis]) && isPosDefined(child, trailing[axis])) {
  5316. child.layout[dim[axis]] = fmaxf(boundAxis(child, axis, node.layout[dim[axis]] - getPaddingAndBorderAxis(node, axis) - getMarginAxis(child, axis) - getPosition(child, leading[axis]) - getPosition(child, trailing[axis])),
  5317. // You never want to go smaller than padding
  5318. getPaddingAndBorderAxis(child, axis));
  5319. }
  5320. }
  5321. }
  5322. var /*float*/nextContentDim = 0;
  5323. // It only makes sense to consider a child flexible if we have a computed
  5324. // dimension for the node.
  5325. if (isMainDimDefined && isFlex(child)) {
  5326. flexibleChildrenCount++;
  5327. totalFlexible += child.style.flex;
  5328. // Store a private linked list of flexible children so that we can
  5329. // efficiently traverse them later.
  5330. if (firstFlexChild === null) {
  5331. firstFlexChild = child;
  5332. }
  5333. if (currentFlexChild !== null) {
  5334. currentFlexChild.nextFlexChild = child;
  5335. }
  5336. currentFlexChild = child;
  5337. // Even if we don't know its exact size yet, we already know the padding,
  5338. // border and margin. We'll use this partial information, which represents
  5339. // the smallest possible size for the child, to compute the remaining
  5340. // available space.
  5341. nextContentDim = getPaddingAndBorderAxis(child, mainAxis) + getMarginAxis(child, mainAxis);
  5342. } else {
  5343. maxWidth = CSS_UNDEFINED;
  5344. if (!isMainRowDirection) {
  5345. if (isDimDefined(node, resolvedRowAxis)) {
  5346. maxWidth = node.layout[dim[resolvedRowAxis]] - paddingAndBorderAxisResolvedRow;
  5347. } else {
  5348. maxWidth = parentMaxWidth - getMarginAxis(node, resolvedRowAxis) - paddingAndBorderAxisResolvedRow;
  5349. }
  5350. }
  5351. // This is the main recursive call. We layout non flexible children.
  5352. if (alreadyComputedNextLayout === 0) {
  5353. layoutNode( /*(java)!layoutContext, */child, maxWidth, direction);
  5354. }
  5355. // Absolute positioned elements do not take part of the layout, so we
  5356. // don't use them to compute mainContentDim
  5357. if (getPositionType(child) === CSS_POSITION_RELATIVE) {
  5358. nonFlexibleChildrenCount++;
  5359. // At this point we know the final size and margin of the element.
  5360. nextContentDim = getDimWithMargin(child, mainAxis);
  5361. }
  5362. }
  5363. // The element we are about to add would make us go to the next line
  5364. if (isNodeFlexWrap && isMainDimDefined && mainContentDim + nextContentDim > definedMainDim &&
  5365. // If there's only one element, then it's bigger than the content
  5366. // and needs its own line
  5367. i !== startLine) {
  5368. nonFlexibleChildrenCount--;
  5369. alreadyComputedNextLayout = 1;
  5370. break;
  5371. }
  5372. // Disable simple stacking in the main axis for the current line as
  5373. // we found a non-trivial child. The remaining children will be laid out
  5374. // in <Loop C>.
  5375. if (isSimpleStackMain && (getPositionType(child) !== CSS_POSITION_RELATIVE || isFlex(child))) {
  5376. isSimpleStackMain = false;
  5377. firstComplexMain = i;
  5378. }
  5379. // Disable simple stacking in the cross axis for the current line as
  5380. // we found a non-trivial child. The remaining children will be laid out
  5381. // in <Loop D>.
  5382. if (isSimpleStackCross && (getPositionType(child) !== CSS_POSITION_RELATIVE || alignItem !== CSS_ALIGN_STRETCH && alignItem !== CSS_ALIGN_FLEX_START || isUndefined$1(child.layout[dim[crossAxis]]))) {
  5383. isSimpleStackCross = false;
  5384. firstComplexCross = i;
  5385. }
  5386. if (isSimpleStackMain) {
  5387. child.layout[pos[mainAxis]] += mainDim;
  5388. if (isMainDimDefined) {
  5389. setTrailingPosition(node, child, mainAxis);
  5390. }
  5391. mainDim += getDimWithMargin(child, mainAxis);
  5392. crossDim = fmaxf(crossDim, boundAxis(child, crossAxis, getDimWithMargin(child, crossAxis)));
  5393. }
  5394. if (isSimpleStackCross) {
  5395. child.layout[pos[crossAxis]] += linesCrossDim + leadingPaddingAndBorderCross;
  5396. if (isCrossDimDefined) {
  5397. setTrailingPosition(node, child, crossAxis);
  5398. }
  5399. }
  5400. alreadyComputedNextLayout = 0;
  5401. mainContentDim += nextContentDim;
  5402. endLine = i + 1;
  5403. }
  5404. // <Loop B> Layout flexible children and allocate empty space
  5405. // In order to position the elements in the main axis, we have two
  5406. // controls. The space between the beginning and the first element
  5407. // and the space between each two elements.
  5408. var /*float*/leadingMainDim = 0;
  5409. var /*float*/betweenMainDim = 0;
  5410. // The remaining available space that needs to be allocated
  5411. var /*float*/remainingMainDim = 0;
  5412. if (isMainDimDefined) {
  5413. remainingMainDim = definedMainDim - mainContentDim;
  5414. } else {
  5415. remainingMainDim = fmaxf(mainContentDim, 0) - mainContentDim;
  5416. }
  5417. // If there are flexible children in the mix, they are going to fill the
  5418. // remaining space
  5419. if (flexibleChildrenCount !== 0) {
  5420. var /*float*/flexibleMainDim = remainingMainDim / totalFlexible;
  5421. var /*float*/baseMainDim;
  5422. var /*float*/boundMainDim;
  5423. // If the flex share of remaining space doesn't meet min/max bounds,
  5424. // remove this child from flex calculations.
  5425. currentFlexChild = firstFlexChild;
  5426. while (currentFlexChild !== null) {
  5427. baseMainDim = flexibleMainDim * currentFlexChild.style.flex + getPaddingAndBorderAxis(currentFlexChild, mainAxis);
  5428. boundMainDim = boundAxis(currentFlexChild, mainAxis, baseMainDim);
  5429. if (baseMainDim !== boundMainDim) {
  5430. remainingMainDim -= boundMainDim;
  5431. totalFlexible -= currentFlexChild.style.flex;
  5432. }
  5433. currentFlexChild = currentFlexChild.nextFlexChild;
  5434. }
  5435. flexibleMainDim = remainingMainDim / totalFlexible;
  5436. // The non flexible children can overflow the container, in this case
  5437. // we should just assume that there is no space available.
  5438. if (flexibleMainDim < 0) {
  5439. flexibleMainDim = 0;
  5440. }
  5441. currentFlexChild = firstFlexChild;
  5442. while (currentFlexChild !== null) {
  5443. // At this point we know the final size of the element in the main
  5444. // dimension
  5445. currentFlexChild.layout[dim[mainAxis]] = boundAxis(currentFlexChild, mainAxis, flexibleMainDim * currentFlexChild.style.flex + getPaddingAndBorderAxis(currentFlexChild, mainAxis));
  5446. maxWidth = CSS_UNDEFINED;
  5447. if (isDimDefined(node, resolvedRowAxis)) {
  5448. maxWidth = node.layout[dim[resolvedRowAxis]] - paddingAndBorderAxisResolvedRow;
  5449. } else if (!isMainRowDirection) {
  5450. maxWidth = parentMaxWidth - getMarginAxis(node, resolvedRowAxis) - paddingAndBorderAxisResolvedRow;
  5451. }
  5452. // And we recursively call the layout algorithm for this child
  5453. layoutNode( /*(java)!layoutContext, */currentFlexChild, maxWidth, direction);
  5454. child = currentFlexChild;
  5455. currentFlexChild = currentFlexChild.nextFlexChild;
  5456. child.nextFlexChild = null;
  5457. }
  5458. // We use justifyContent to figure out how to allocate the remaining
  5459. // space available
  5460. } else if (justifyContent !== CSS_JUSTIFY_FLEX_START) {
  5461. if (justifyContent === CSS_JUSTIFY_CENTER) {
  5462. leadingMainDim = remainingMainDim / 2;
  5463. } else if (justifyContent === CSS_JUSTIFY_FLEX_END) {
  5464. leadingMainDim = remainingMainDim;
  5465. } else if (justifyContent === CSS_JUSTIFY_SPACE_BETWEEN) {
  5466. remainingMainDim = fmaxf(remainingMainDim, 0);
  5467. if (flexibleChildrenCount + nonFlexibleChildrenCount - 1 !== 0) {
  5468. betweenMainDim = remainingMainDim / (flexibleChildrenCount + nonFlexibleChildrenCount - 1);
  5469. } else {
  5470. betweenMainDim = 0;
  5471. }
  5472. } else if (justifyContent === CSS_JUSTIFY_SPACE_AROUND) {
  5473. // Space on the edges is half of the space between elements
  5474. betweenMainDim = remainingMainDim / (flexibleChildrenCount + nonFlexibleChildrenCount);
  5475. leadingMainDim = betweenMainDim / 2;
  5476. }
  5477. }
  5478. // <Loop C> Position elements in the main axis and compute dimensions
  5479. // At this point, all the children have their dimensions set. We need to
  5480. // find their position. In order to do that, we accumulate data in
  5481. // variables that are also useful to compute the total dimensions of the
  5482. // container!
  5483. mainDim += leadingMainDim;
  5484. for (i = firstComplexMain; i < endLine; ++i) {
  5485. child = node.children[i];
  5486. if (getPositionType(child) === CSS_POSITION_ABSOLUTE && isPosDefined(child, leading[mainAxis])) {
  5487. // In case the child is position absolute and has left/top being
  5488. // defined, we override the position to whatever the user said
  5489. // (and margin/border).
  5490. child.layout[pos[mainAxis]] = getPosition(child, leading[mainAxis]) + getLeadingBorder(node, mainAxis) + getLeadingMargin(child, mainAxis);
  5491. } else {
  5492. // If the child is position absolute (without top/left) or relative,
  5493. // we put it at the current accumulated offset.
  5494. child.layout[pos[mainAxis]] += mainDim;
  5495. // Define the trailing position accordingly.
  5496. if (isMainDimDefined) {
  5497. setTrailingPosition(node, child, mainAxis);
  5498. }
  5499. // Now that we placed the element, we need to update the variables
  5500. // We only need to do that for relative elements. Absolute elements
  5501. // do not take part in that phase.
  5502. if (getPositionType(child) === CSS_POSITION_RELATIVE) {
  5503. // The main dimension is the sum of all the elements dimension plus
  5504. // the spacing.
  5505. mainDim += betweenMainDim + getDimWithMargin(child, mainAxis);
  5506. // The cross dimension is the max of the elements dimension since there
  5507. // can only be one element in that cross dimension.
  5508. crossDim = fmaxf(crossDim, boundAxis(child, crossAxis, getDimWithMargin(child, crossAxis)));
  5509. }
  5510. }
  5511. }
  5512. var /*float*/containerCrossAxis = node.layout[dim[crossAxis]];
  5513. if (!isCrossDimDefined) {
  5514. containerCrossAxis = fmaxf(
  5515. // For the cross dim, we add both sides at the end because the value
  5516. // is aggregate via a max function. Intermediate negative values
  5517. // can mess this computation otherwise
  5518. boundAxis(node, crossAxis, crossDim + paddingAndBorderAxisCross), paddingAndBorderAxisCross);
  5519. }
  5520. // <Loop D> Position elements in the cross axis
  5521. for (i = firstComplexCross; i < endLine; ++i) {
  5522. child = node.children[i];
  5523. if (getPositionType(child) === CSS_POSITION_ABSOLUTE && isPosDefined(child, leading[crossAxis])) {
  5524. // In case the child is absolutely positionned and has a
  5525. // top/left/bottom/right being set, we override all the previously
  5526. // computed positions to set it correctly.
  5527. child.layout[pos[crossAxis]] = getPosition(child, leading[crossAxis]) + getLeadingBorder(node, crossAxis) + getLeadingMargin(child, crossAxis);
  5528. } else {
  5529. var /*float*/leadingCrossDim = leadingPaddingAndBorderCross;
  5530. // For a relative children, we're either using alignItems (parent) or
  5531. // alignSelf (child) in order to determine the position in the cross axis
  5532. if (getPositionType(child) === CSS_POSITION_RELATIVE) {
  5533. // This variable is intentionally re-defined as the code is transpiled to a block scope language
  5534. var /*css_align_t*/alignItem = getAlignItem(node, child);
  5535. if (alignItem === CSS_ALIGN_STRETCH) {
  5536. // You can only stretch if the dimension has not already been set
  5537. // previously.
  5538. if (isUndefined$1(child.layout[dim[crossAxis]])) {
  5539. child.layout[dim[crossAxis]] = fmaxf(boundAxis(child, crossAxis, containerCrossAxis - paddingAndBorderAxisCross - getMarginAxis(child, crossAxis)),
  5540. // You never want to go smaller than padding
  5541. getPaddingAndBorderAxis(child, crossAxis));
  5542. }
  5543. } else if (alignItem !== CSS_ALIGN_FLEX_START) {
  5544. // The remaining space between the parent dimensions+padding and child
  5545. // dimensions+margin.
  5546. var /*float*/remainingCrossDim = containerCrossAxis - paddingAndBorderAxisCross - getDimWithMargin(child, crossAxis);
  5547. if (alignItem === CSS_ALIGN_CENTER) {
  5548. leadingCrossDim += remainingCrossDim / 2;
  5549. } else {
  5550. // CSS_ALIGN_FLEX_END
  5551. leadingCrossDim += remainingCrossDim;
  5552. }
  5553. }
  5554. }
  5555. // And we apply the position
  5556. child.layout[pos[crossAxis]] += linesCrossDim + leadingCrossDim;
  5557. // Define the trailing position accordingly.
  5558. if (isCrossDimDefined) {
  5559. setTrailingPosition(node, child, crossAxis);
  5560. }
  5561. }
  5562. }
  5563. linesCrossDim += crossDim;
  5564. linesMainDim = fmaxf(linesMainDim, mainDim);
  5565. linesCount += 1;
  5566. startLine = endLine;
  5567. }
  5568. // <Loop E>
  5569. //
  5570. // Note(prenaux): More than one line, we need to layout the crossAxis
  5571. // according to alignContent.
  5572. //
  5573. // Note that we could probably remove <Loop D> and handle the one line case
  5574. // here too, but for the moment this is safer since it won't interfere with
  5575. // previously working code.
  5576. //
  5577. // See specs:
  5578. // http://www.w3.org/TR/2012/CR-css3-flexbox-20120918/#layout-algorithm
  5579. // section 9.4
  5580. //
  5581. if (linesCount > 1 && isCrossDimDefined) {
  5582. var /*float*/nodeCrossAxisInnerSize = node.layout[dim[crossAxis]] - paddingAndBorderAxisCross;
  5583. var /*float*/remainingAlignContentDim = nodeCrossAxisInnerSize - linesCrossDim;
  5584. var /*float*/crossDimLead = 0;
  5585. var /*float*/currentLead = leadingPaddingAndBorderCross;
  5586. var /*css_align_t*/alignContent = getAlignContent(node);
  5587. if (alignContent === CSS_ALIGN_FLEX_END) {
  5588. currentLead += remainingAlignContentDim;
  5589. } else if (alignContent === CSS_ALIGN_CENTER) {
  5590. currentLead += remainingAlignContentDim / 2;
  5591. } else if (alignContent === CSS_ALIGN_STRETCH) {
  5592. if (nodeCrossAxisInnerSize > linesCrossDim) {
  5593. crossDimLead = remainingAlignContentDim / linesCount;
  5594. }
  5595. }
  5596. var /*int*/endIndex = 0;
  5597. for (i = 0; i < linesCount; ++i) {
  5598. var /*int*/startIndex = endIndex;
  5599. // compute the line's height and find the endIndex
  5600. var /*float*/lineHeight = 0;
  5601. for (ii = startIndex; ii < childCount; ++ii) {
  5602. child = node.children[ii];
  5603. if (getPositionType(child) !== CSS_POSITION_RELATIVE) {
  5604. continue;
  5605. }
  5606. if (child.lineIndex !== i) {
  5607. break;
  5608. }
  5609. if (!isUndefined$1(child.layout[dim[crossAxis]])) {
  5610. lineHeight = fmaxf(lineHeight, child.layout[dim[crossAxis]] + getMarginAxis(child, crossAxis));
  5611. }
  5612. }
  5613. endIndex = ii;
  5614. lineHeight += crossDimLead;
  5615. for (ii = startIndex; ii < endIndex; ++ii) {
  5616. child = node.children[ii];
  5617. if (getPositionType(child) !== CSS_POSITION_RELATIVE) {
  5618. continue;
  5619. }
  5620. var /*css_align_t*/alignContentAlignItem = getAlignItem(node, child);
  5621. if (alignContentAlignItem === CSS_ALIGN_FLEX_START) {
  5622. child.layout[pos[crossAxis]] = currentLead + getLeadingMargin(child, crossAxis);
  5623. } else if (alignContentAlignItem === CSS_ALIGN_FLEX_END) {
  5624. child.layout[pos[crossAxis]] = currentLead + lineHeight - getTrailingMargin(child, crossAxis) - child.layout[dim[crossAxis]];
  5625. } else if (alignContentAlignItem === CSS_ALIGN_CENTER) {
  5626. var /*float*/childHeight = child.layout[dim[crossAxis]];
  5627. child.layout[pos[crossAxis]] = currentLead + (lineHeight - childHeight) / 2;
  5628. } else if (alignContentAlignItem === CSS_ALIGN_STRETCH) {
  5629. child.layout[pos[crossAxis]] = currentLead + getLeadingMargin(child, crossAxis);
  5630. // TODO(prenaux): Correctly set the height of items with undefined
  5631. // (auto) crossAxis dimension.
  5632. }
  5633. }
  5634. currentLead += lineHeight;
  5635. }
  5636. }
  5637. var /*bool*/needsMainTrailingPos = false;
  5638. var /*bool*/needsCrossTrailingPos = false;
  5639. // If the user didn't specify a width or height, and it has not been set
  5640. // by the container, then we set it via the children.
  5641. if (!isMainDimDefined) {
  5642. node.layout[dim[mainAxis]] = fmaxf(
  5643. // We're missing the last padding at this point to get the final
  5644. // dimension
  5645. boundAxis(node, mainAxis, linesMainDim + getTrailingPaddingAndBorder(node, mainAxis)),
  5646. // We can never assign a width smaller than the padding and borders
  5647. paddingAndBorderAxisMain);
  5648. if (mainAxis === CSS_FLEX_DIRECTION_ROW_REVERSE || mainAxis === CSS_FLEX_DIRECTION_COLUMN_REVERSE) {
  5649. needsMainTrailingPos = true;
  5650. }
  5651. }
  5652. if (!isCrossDimDefined) {
  5653. node.layout[dim[crossAxis]] = fmaxf(
  5654. // For the cross dim, we add both sides at the end because the value
  5655. // is aggregate via a max function. Intermediate negative values
  5656. // can mess this computation otherwise
  5657. boundAxis(node, crossAxis, linesCrossDim + paddingAndBorderAxisCross), paddingAndBorderAxisCross);
  5658. if (crossAxis === CSS_FLEX_DIRECTION_ROW_REVERSE || crossAxis === CSS_FLEX_DIRECTION_COLUMN_REVERSE) {
  5659. needsCrossTrailingPos = true;
  5660. }
  5661. }
  5662. // <Loop F> Set trailing position if necessary
  5663. if (needsMainTrailingPos || needsCrossTrailingPos) {
  5664. for (i = 0; i < childCount; ++i) {
  5665. child = node.children[i];
  5666. if (needsMainTrailingPos) {
  5667. setTrailingPosition(node, child, mainAxis);
  5668. }
  5669. if (needsCrossTrailingPos) {
  5670. setTrailingPosition(node, child, crossAxis);
  5671. }
  5672. }
  5673. }
  5674. // <Loop G> Calculate dimensions for absolutely positioned elements
  5675. currentAbsoluteChild = firstAbsoluteChild;
  5676. while (currentAbsoluteChild !== null) {
  5677. // Pre-fill dimensions when using absolute position and both offsets for
  5678. // the axis are defined (either both left and right or top and bottom).
  5679. for (ii = 0; ii < 2; ii++) {
  5680. axis = ii !== 0 ? CSS_FLEX_DIRECTION_ROW : CSS_FLEX_DIRECTION_COLUMN;
  5681. if (!isUndefined$1(node.layout[dim[axis]]) && !isDimDefined(currentAbsoluteChild, axis) && isPosDefined(currentAbsoluteChild, leading[axis]) && isPosDefined(currentAbsoluteChild, trailing[axis])) {
  5682. currentAbsoluteChild.layout[dim[axis]] = fmaxf(boundAxis(currentAbsoluteChild, axis, node.layout[dim[axis]] - getBorderAxis(node, axis) - getMarginAxis(currentAbsoluteChild, axis) - getPosition(currentAbsoluteChild, leading[axis]) - getPosition(currentAbsoluteChild, trailing[axis])),
  5683. // You never want to go smaller than padding
  5684. getPaddingAndBorderAxis(currentAbsoluteChild, axis));
  5685. }
  5686. if (isPosDefined(currentAbsoluteChild, trailing[axis]) && !isPosDefined(currentAbsoluteChild, leading[axis])) {
  5687. currentAbsoluteChild.layout[leading[axis]] = node.layout[dim[axis]] - currentAbsoluteChild.layout[dim[axis]] - getPosition(currentAbsoluteChild, trailing[axis]);
  5688. }
  5689. }
  5690. child = currentAbsoluteChild;
  5691. currentAbsoluteChild = currentAbsoluteChild.nextAbsoluteChild;
  5692. child.nextAbsoluteChild = null;
  5693. }
  5694. }
  5695. // 在外层做的margin补丁
  5696. function saveMargin(node) {
  5697. var style = node.style;
  5698. var margin = {};
  5699. ['marginTop', 'marginRight', 'marginBottom', 'marginLeft' // 只支持marginLeft
  5700. ].forEach(function (key) {
  5701. // 只处理百分号
  5702. var value = style[key];
  5703. if (value && /^-?\d+%$/.test(value)) {
  5704. margin[key] = value;
  5705. style[key] = 0;
  5706. }
  5707. });
  5708. node.margin = margin;
  5709. }
  5710. function percent2Num(value) {
  5711. var percent = Number(value.substr(0, value.length - 1));
  5712. return percent / 100;
  5713. }
  5714. function layoutMargin(node) {
  5715. var margin = node.margin,
  5716. layout = node.layout;
  5717. Object.keys(margin).forEach(function (key) {
  5718. var percent = percent2Num(margin[key]);
  5719. if ((key === 'marginLeft' || key === 'marginRight') && layout.width) {
  5720. layout.left += layout.width * percent;
  5721. } else if ((key === 'marginTop' || key === 'marginBottom') && layout.height) {
  5722. layout.top += layout.height * percent;
  5723. }
  5724. });
  5725. }
  5726. function layoutNode(node, parentMaxWidth, parentDirection) {
  5727. node.shouldUpdate = true;
  5728. // hack
  5729. saveMargin(node);
  5730. var direction = node.style.direction || CSS_DIRECTION_LTR;
  5731. var skipLayout = !node.isDirty && node.lastLayout && node.lastLayout.requestedHeight === node.layout.height && node.lastLayout.requestedWidth === node.layout.width && node.lastLayout.parentMaxWidth === parentMaxWidth && node.lastLayout.direction === direction;
  5732. if (skipLayout) {
  5733. node.layout.width = node.lastLayout.width;
  5734. node.layout.height = node.lastLayout.height;
  5735. node.layout.top = node.lastLayout.top;
  5736. node.layout.left = node.lastLayout.left;
  5737. } else {
  5738. if (!node.lastLayout) {
  5739. node.lastLayout = {};
  5740. }
  5741. node.lastLayout.requestedWidth = node.layout.width;
  5742. node.lastLayout.requestedHeight = node.layout.height;
  5743. node.lastLayout.parentMaxWidth = parentMaxWidth;
  5744. node.lastLayout.direction = direction;
  5745. // Reset child layouts
  5746. node.children.forEach(function (child) {
  5747. child.layout.width = undefined;
  5748. child.layout.height = undefined;
  5749. child.layout.top = 0;
  5750. child.layout.left = 0;
  5751. });
  5752. layoutNodeImpl(node, parentMaxWidth, parentDirection);
  5753. node.lastLayout.width = node.layout.width;
  5754. node.lastLayout.height = node.layout.height;
  5755. node.lastLayout.top = node.layout.top;
  5756. node.lastLayout.left = node.layout.left;
  5757. }
  5758. // hack
  5759. layoutMargin(node);
  5760. }
  5761. /* eslint-enable */
  5762. function computeLayout(node) {
  5763. if (!node) return node;
  5764. var style = node.style,
  5765. children = node.children;
  5766. if (style) {
  5767. fillNodes(node);
  5768. layoutNode(node, null, null);
  5769. return node;
  5770. }
  5771. if (children && children.length) {
  5772. for (var i = 0, len = children.length; i < len; i++) {
  5773. computeLayout(children[i]);
  5774. }
  5775. }
  5776. return node;
  5777. }
  5778. var rect = (function (layout) {
  5779. var left = layout.left,
  5780. top = layout.top,
  5781. width = layout.width,
  5782. height = layout.height;
  5783. return {
  5784. x: left,
  5785. y: top,
  5786. width: width,
  5787. height: height
  5788. };
  5789. });
  5790. var line = (function (layout) {
  5791. var left = layout.left,
  5792. top = layout.top,
  5793. width = layout.width,
  5794. height = layout.height;
  5795. return {
  5796. x1: left,
  5797. y1: top,
  5798. x2: left + width,
  5799. y2: top + height
  5800. };
  5801. });
  5802. var text = (function (layout) {
  5803. var height = layout.height,
  5804. left = layout.left,
  5805. top = layout.top;
  5806. return {
  5807. x: left,
  5808. y: top + height / 2,
  5809. // 通过middle + top 才能比较好的实现文本对齐
  5810. textBaseline: 'middle'
  5811. };
  5812. });
  5813. var circle = (function (layout) {
  5814. var left = layout.left,
  5815. top = layout.top,
  5816. width = layout.width;
  5817. var r = width / 2;
  5818. return {
  5819. x: left + r,
  5820. y: top + r,
  5821. r: r
  5822. };
  5823. });
  5824. var marker = (function (layout) {
  5825. var left = layout.left,
  5826. top = layout.top,
  5827. width = layout.width;
  5828. var r = width / 2;
  5829. return {
  5830. x: left + r,
  5831. y: top,
  5832. radius: r
  5833. };
  5834. });
  5835. var map$2 = {
  5836. rect: rect,
  5837. line: line,
  5838. text: text,
  5839. circle: circle,
  5840. marker: marker,
  5841. group: rect
  5842. };
  5843. var getShapeAttrs = (function (type, layout) {
  5844. if (!layout) return null;
  5845. var fn = map$2[type] || rect;
  5846. return fn(layout);
  5847. });
  5848. var ELEMENT_APPEAR = 'appear';
  5849. // 标识元素更新
  5850. var ELEMENT_UPDATE = 'update';
  5851. // 标识是删除的元素
  5852. var ELEMENT_DELETE = 'delete';
  5853. function createClipElement(type, config) {
  5854. return new Shape[upperFirst(type)](config);
  5855. }
  5856. var getAnimation = (function (element, animation, nextAttrs, lastAttrs) {
  5857. if (!animation) return null;
  5858. // 获取shape的默认属性
  5859. var status = element.get('status');
  5860. var clip = animation.clip,
  5861. start = animation.start,
  5862. end = animation.end,
  5863. easing = animation.easing,
  5864. delay = animation.delay,
  5865. duration = animation.duration;
  5866. var clipConfig = isFunction(clip) ? clip(element._attrs.attrs) : clip;
  5867. // 裁剪动画
  5868. if (clipConfig) {
  5869. var type = clipConfig.type,
  5870. attrs = clipConfig.attrs,
  5871. clipStart = clipConfig.start;
  5872. var clipElement = createClipElement(type, {
  5873. attrs: _objectSpread(_objectSpread({}, attrs), clipStart)
  5874. });
  5875. // 默认用 animation 配置里的 easing 和 duration
  5876. clipConfig.easing = clipConfig.easing || easing;
  5877. clipConfig.delay = typeof clipConfig.delay === 'number' ? clipConfig.delay : delay;
  5878. clipConfig.duration = clipConfig.duration || duration;
  5879. clipConfig.element = clipElement;
  5880. }
  5881. var defaultAttrs = element.getDefaultAttrs();
  5882. return _objectSpread(_objectSpread({}, animation), {}, {
  5883. clip: clipConfig,
  5884. start: _objectSpread(_objectSpread(_objectSpread({}, defaultAttrs), lastAttrs), start),
  5885. end: _objectSpread(_objectSpread({}, status === ELEMENT_DELETE ? null : nextAttrs), end)
  5886. });
  5887. });
  5888. // 转换成布局所需要的布局树
  5889. function createNodeTree(element, container, px2hd) {
  5890. var key = element.key,
  5891. ref = element.ref,
  5892. _cache = element._cache,
  5893. type = element.type,
  5894. props = element.props,
  5895. status = element.status,
  5896. animation = element.animation;
  5897. var children = extendMap(props.children, function (child) {
  5898. return createNodeTree(child, container, px2hd);
  5899. });
  5900. // const { style, attrs } = props;
  5901. var style = px2hd(props.style);
  5902. var attrs = px2hd(props.attrs);
  5903. // 文本要自动计算文本的宽高, TODO, 后面再优化
  5904. if (type === 'text') {
  5905. var shape = container.addShape(type, {
  5906. attrs: _objectSpread({
  5907. x: 0,
  5908. y: 0
  5909. }, attrs)
  5910. });
  5911. var _shape$getBBox = shape.getBBox(),
  5912. width = _shape$getBBox.width,
  5913. height = _shape$getBBox.height;
  5914. style = _objectSpread({
  5915. width: width,
  5916. height: height
  5917. }, style);
  5918. // 无用,销毁掉
  5919. shape.remove(true);
  5920. }
  5921. return {
  5922. key: key,
  5923. ref: ref,
  5924. _cache: _cache,
  5925. type: type,
  5926. props: props,
  5927. children: children,
  5928. status: status,
  5929. animation: animation,
  5930. // 处理px2hd之后的配置
  5931. style: style,
  5932. attrs: attrs
  5933. };
  5934. }
  5935. function mergeLayout(parent, layout) {
  5936. if (!parent || !layout) return layout;
  5937. var parentLeft = parent.left,
  5938. parentTop = parent.top;
  5939. var left = layout.left,
  5940. top = layout.top;
  5941. return _objectSpread(_objectSpread({}, layout), {}, {
  5942. left: parentLeft + left,
  5943. top: parentTop + top
  5944. });
  5945. }
  5946. function createElement(node, container, parentLayout, animate) {
  5947. var _node$_cache = node._cache,
  5948. _cache = _node$_cache === void 0 ? {} : _node$_cache,
  5949. ref = node.ref,
  5950. type = node.type,
  5951. props = node.props,
  5952. attrs = node.attrs,
  5953. originLayout = node.layout,
  5954. renderChildren = node.renderChildren,
  5955. nodeChildren = node.children,
  5956. status = node.status,
  5957. animation = node.animation;
  5958. var layout = mergeLayout(parentLayout, originLayout);
  5959. // 该元素上一次的attrs
  5960. var lastAttrs = _cache.attrs;
  5961. var elementAttrs = _objectSpread(_objectSpread(_objectSpread({}, getShapeAttrs(type, layout)), status === ELEMENT_DELETE ? lastAttrs : null), attrs);
  5962. // 缓存这次新的attrs
  5963. _cache.attrs = elementAttrs;
  5964. if (elementAttrs.clip) {
  5965. var clip = elementAttrs.clip;
  5966. var clipConfig = isFunction(clip) ? clip(elementAttrs) : clip;
  5967. elementAttrs.clip = createClipElement(clipConfig.type, clipConfig);
  5968. }
  5969. var element;
  5970. if (type === 'group') {
  5971. element = container.addGroup(_objectSpread(_objectSpread({}, omit(props, ['children'])), {}, {
  5972. status: status,
  5973. attrs: elementAttrs
  5974. }));
  5975. // 如果元素被删除了,就不会有renderChildren, 直接拿node.children渲染
  5976. var children = renderChildren ? renderChildren : nodeChildren;
  5977. // 只有group才需要处理children
  5978. if (children && children.length) {
  5979. for (var i = 0, len = children.length; i < len; i++) {
  5980. createElement(children[i], element, layout, animate);
  5981. }
  5982. }
  5983. } else {
  5984. element = container.addShape(type, _objectSpread(_objectSpread({}, props), {}, {
  5985. status: status,
  5986. attrs: elementAttrs
  5987. }));
  5988. }
  5989. if (animate !== false) {
  5990. element.set('animation', getAnimation(element, animation, elementAttrs, lastAttrs));
  5991. }
  5992. if (ref) {
  5993. ref.current = element;
  5994. }
  5995. return element;
  5996. }
  5997. // 过滤删除的元素,让其不参与布局计算
  5998. function filterDeleteElement(node) {
  5999. var status = node.status,
  6000. children = node.children;
  6001. if (status === ELEMENT_DELETE) {
  6002. return null;
  6003. }
  6004. if (!children || !children.length) {
  6005. return node;
  6006. }
  6007. var newChildren = children.filter(function (child) {
  6008. return !!filterDeleteElement(child);
  6009. });
  6010. // 要保留引用
  6011. node.children = newChildren;
  6012. node.renderChildren = children;
  6013. return node;
  6014. }
  6015. function render(element, container, animate) {
  6016. var px2hd$1 = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : px2hd;
  6017. if (!element) {
  6018. return;
  6019. }
  6020. var nodeTree = createNodeTree(element, container, px2hd$1);
  6021. var computeLayoutTree = filterDeleteElement(nodeTree);
  6022. computeLayout(computeLayoutTree);
  6023. return createElement(nodeTree, container, null, animate);
  6024. }
  6025. var render$1 = (function (element, container, animate) {
  6026. return render(element, container, animate);
  6027. });
  6028. // 主要是把function节点,全部转换成string标签节点
  6029. function renderJSXElement(element, context, updater) {
  6030. if (!element) return element;
  6031. var _element = element,
  6032. type = _element.type,
  6033. key = _element.key,
  6034. ref = _element.ref,
  6035. props = _element.props,
  6036. _element$_cache = _element._cache,
  6037. _cache = _element$_cache === void 0 ? {} : _element$_cache;
  6038. // render children first
  6039. var children = Children.map(props.children, function (child) {
  6040. return renderJSXElement(child, context, updater);
  6041. });
  6042. element = {
  6043. type: type,
  6044. key: key,
  6045. ref: ref,
  6046. _cache: _cache,
  6047. props: _objectSpread(_objectSpread({}, props), {}, {
  6048. children: children
  6049. })
  6050. };
  6051. if (typeof type === 'function') {
  6052. // @ts-ignore
  6053. var newElement = type(element.props, context, updater);
  6054. if (!newElement) return newElement;
  6055. // recursive render until type is string
  6056. return renderJSXElement(_objectSpread(_objectSpread({}, newElement), {}, {
  6057. // 保留原始的key和ref
  6058. key: key !== undefined ? key : newElement.key,
  6059. ref: ref !== undefined ? ref : newElement.ref
  6060. }), context, updater);
  6061. }
  6062. // return element if type is string
  6063. return element;
  6064. }
  6065. var renderJSXElement$1 = (function (element, context, updater) {
  6066. return renderJSXElement(element, context, updater);
  6067. });
  6068. var _excluded$1 = ["children", "animation"],
  6069. _excluded2 = ["children", "animation"],
  6070. _excluded3 = ["children", "animation"],
  6071. _excluded4 = ["animation"],
  6072. _excluded5 = ["animation"];
  6073. // 处理删除的元素
  6074. function deleteElement(element) {
  6075. // 是否有非空的子元素
  6076. var hasElement = false;
  6077. var receiveElement = Children.map(element, function (item) {
  6078. if (!item) return item;
  6079. var ref = item.ref,
  6080. key = item.key,
  6081. type = item.type,
  6082. props = item.props,
  6083. _cache = item._cache;
  6084. var children = props.children,
  6085. animation = props.animation,
  6086. receiveProps = _objectWithoutProperties(props, _excluded$1);
  6087. var status = ELEMENT_DELETE;
  6088. var receiveAnimation = animation && animation.leave;
  6089. var receiveChildren = deleteElement(children);
  6090. // 没有子元素,且自身也不需要动画,则直接删除
  6091. if (!receiveChildren && !receiveAnimation) {
  6092. return null;
  6093. }
  6094. hasElement = true;
  6095. return {
  6096. ref: ref,
  6097. key: key,
  6098. type: type,
  6099. props: _objectSpread(_objectSpread({}, receiveProps), {}, {
  6100. children: receiveChildren
  6101. }),
  6102. _cache: _cache,
  6103. animation: receiveAnimation,
  6104. status: status
  6105. };
  6106. });
  6107. // 如果没有非空的子元素,都删除
  6108. if (!hasElement) {
  6109. return null;
  6110. }
  6111. return receiveElement;
  6112. }
  6113. function appearElement(element) {
  6114. return Children.map(element, function (item) {
  6115. if (!item) return item;
  6116. var ref = item.ref,
  6117. key = item.key,
  6118. type = item.type,
  6119. props = item.props,
  6120. _cache = item._cache;
  6121. var children = props.children,
  6122. animation = props.animation,
  6123. receiveProps = _objectWithoutProperties(props, _excluded2);
  6124. var status = ELEMENT_APPEAR;
  6125. var receiveAnimation = animation && animation.appear;
  6126. var receiveChildren = appearElement(children);
  6127. return {
  6128. ref: ref,
  6129. key: key,
  6130. type: type,
  6131. props: _objectSpread(_objectSpread({}, receiveProps), {}, {
  6132. children: receiveChildren
  6133. }),
  6134. _cache: _cache,
  6135. animation: receiveAnimation,
  6136. status: status
  6137. };
  6138. });
  6139. }
  6140. function updateElement(nextElement, lastElement) {
  6141. var ref = nextElement.ref,
  6142. key = nextElement.key,
  6143. type = nextElement.type,
  6144. _nextCache = nextElement._cache,
  6145. nextProps = nextElement.props;
  6146. var _lastCache = lastElement._cache,
  6147. lastProps = lastElement.props;
  6148. var nextChildren = nextProps.children,
  6149. nextAnimation = nextProps.animation,
  6150. nextReceiveProps = _objectWithoutProperties(nextProps, _excluded3);
  6151. var lastChildren = lastProps.children;
  6152. // 继续比较子元素
  6153. var children = compareElement(nextChildren, lastChildren);
  6154. // 保留缓存值
  6155. var _cache = mix(_nextCache, _lastCache);
  6156. // 动画
  6157. var animation = nextAnimation && nextAnimation.update;
  6158. // 生成新对象
  6159. return {
  6160. ref: ref,
  6161. key: key,
  6162. type: type,
  6163. props: _objectSpread(_objectSpread({}, nextReceiveProps), {}, {
  6164. children: children
  6165. }),
  6166. _cache: _cache,
  6167. animation: animation,
  6168. status: ELEMENT_UPDATE
  6169. };
  6170. }
  6171. // 形变动画, TODO
  6172. function morphElement(nextElement, lastElement) {
  6173. return [deleteElement(lastElement), appearElement(nextElement)];
  6174. }
  6175. function changeTypeToGroup(nextGroupElement, lastShapeElement) {
  6176. var key = nextGroupElement.key,
  6177. type = nextGroupElement.type,
  6178. ref = nextGroupElement.ref,
  6179. groupProps = nextGroupElement.props,
  6180. _groupCache = nextGroupElement._cache;
  6181. var lastType = lastShapeElement.type,
  6182. _lastCache = lastShapeElement._cache;
  6183. var groupChildren = groupProps.children;
  6184. // let existTransform = false;
  6185. var children = Children.map(groupChildren, function (nextElement) {
  6186. if (!nextElement) return nextElement;
  6187. var key = nextElement.key,
  6188. ref = nextElement.ref,
  6189. nextType = nextElement.type,
  6190. nextProps = nextElement.props,
  6191. _nextCache = nextElement._cache;
  6192. // if (nextType === 'group') {
  6193. // return changeTypeToGroup(nextElement, lastShapeElement);
  6194. // }
  6195. if (nextType !== lastType) {
  6196. return morphElement(nextElement, lastShapeElement);
  6197. }
  6198. // existTransform = true;
  6199. var nextAnimation = nextProps.animation,
  6200. nextReceiveProps = _objectWithoutProperties(nextProps, _excluded4);
  6201. var animation = nextAnimation && nextAnimation.update;
  6202. return {
  6203. ref: ref,
  6204. key: key,
  6205. type: nextType,
  6206. props: nextReceiveProps,
  6207. _cache: mix(_nextCache, _lastCache),
  6208. animation: animation,
  6209. status: ELEMENT_UPDATE
  6210. };
  6211. });
  6212. return {
  6213. key: key,
  6214. type: type,
  6215. ref: ref,
  6216. props: _objectSpread(_objectSpread({}, groupProps), {}, {
  6217. children: children
  6218. }),
  6219. _cache: _groupCache,
  6220. status: ELEMENT_UPDATE
  6221. };
  6222. }
  6223. function changeTypeFromGroup(nextShapeElement, lastGroupElement) {
  6224. var nextRef = nextShapeElement.ref,
  6225. nextKey = nextShapeElement.key,
  6226. nextType = nextShapeElement.type,
  6227. nextShapeProps = nextShapeElement.props,
  6228. _nextCache = nextShapeElement._cache;
  6229. var lastType = lastGroupElement.type,
  6230. lastProps = lastGroupElement.props;
  6231. var nextAnimation = nextShapeProps.animation,
  6232. nextReceiveProps = _objectWithoutProperties(nextShapeProps, _excluded5);
  6233. var groupChildren = lastProps.children;
  6234. var animation = nextAnimation && nextAnimation.update;
  6235. if (!animation) {
  6236. return [deleteElement(lastGroupElement), appearElement[nextShapeElement]];
  6237. }
  6238. var transformChild = null;
  6239. var children = Children.map(groupChildren, function (child) {
  6240. if (!child) return child;
  6241. var childType = child.type,
  6242. _childCache = child._cache;
  6243. if (childType !== nextType) {
  6244. // TODO: child 形变
  6245. return deleteElement(child);
  6246. }
  6247. if (!transformChild) {
  6248. transformChild = child;
  6249. }
  6250. return {
  6251. type: nextType,
  6252. props: nextShapeProps,
  6253. _cache: _childCache,
  6254. animation: animation,
  6255. status: ELEMENT_UPDATE
  6256. };
  6257. });
  6258. if (!transformChild) {
  6259. return [deleteElement(lastGroupElement), appearElement(nextShapeElement)];
  6260. }
  6261. var nextElement = {
  6262. ref: nextRef,
  6263. key: nextKey,
  6264. type: nextType,
  6265. props: nextReceiveProps,
  6266. _cache: mix(_nextCache, transformChild._cache),
  6267. animation: animation,
  6268. status: ELEMENT_UPDATE
  6269. };
  6270. // 保留group 结构
  6271. return [{
  6272. type: lastType,
  6273. props: _objectSpread(_objectSpread({}, lastProps), {}, {
  6274. children: children
  6275. }),
  6276. status: ELEMENT_DELETE
  6277. }, nextElement];
  6278. }
  6279. function changeElementType(nextElement, lastElement) {
  6280. var nextType = nextElement.type;
  6281. var lastType = lastElement.type;
  6282. if (nextType === 'group') {
  6283. return changeTypeToGroup(nextElement, lastElement);
  6284. }
  6285. if (lastType === 'group') {
  6286. return changeTypeFromGroup(nextElement, lastElement);
  6287. }
  6288. // 都不是group, 形变动画 TODO
  6289. return morphElement(nextElement, lastElement);
  6290. }
  6291. // 对比2个数组
  6292. function compareArray$1(nextElements, lastElements) {
  6293. var keyed = {};
  6294. var nextLength = nextElements.length;
  6295. var lastLength = lastElements.length;
  6296. for (var i = 0; i < lastLength; i++) {
  6297. var element = lastElements[i];
  6298. if (element && !isNil(element.key)) {
  6299. var key = element.key;
  6300. keyed[key] = element;
  6301. }
  6302. }
  6303. // 比较元素
  6304. var maxLength = Math.max(nextLength, lastLength);
  6305. var returnElements = [];
  6306. for (var _i = 0; _i < maxLength; _i++) {
  6307. var nextElement = nextElements[_i];
  6308. if (!nextElement) {
  6309. returnElements.push(compareElement(nextElement, lastElements[_i]));
  6310. continue;
  6311. }
  6312. var _key = nextElement.key;
  6313. // 有key值定义
  6314. if (!isNil(_key)) {
  6315. var lastElement = keyed[_key];
  6316. if (lastElement) delete keyed[_key];
  6317. returnElements.push(compareElement(nextElement, lastElement));
  6318. continue;
  6319. }
  6320. returnElements.push(compareElement(nextElement, lastElements[_i]));
  6321. }
  6322. // 说明是删除的元素
  6323. Object.keys(keyed).forEach(function (key) {
  6324. returnElements.push(compareElement(null, keyed[key]));
  6325. });
  6326. return returnElements;
  6327. }
  6328. // 比较2个元素,会被递归执行
  6329. function compareElement(nextElement, lastElement) {
  6330. // 都为空
  6331. if (!nextElement && !lastElement) {
  6332. return null;
  6333. }
  6334. // 新增
  6335. if (!lastElement) {
  6336. return appearElement(nextElement);
  6337. }
  6338. // 删除
  6339. if (!nextElement) {
  6340. return deleteElement(lastElement);
  6341. }
  6342. // nextElement & lastElement 都不为空了
  6343. // 如果有数组,比较数组
  6344. if (isArray(nextElement) || isArray(lastElement)) {
  6345. var nextElementArray = isArray(nextElement) ? nextElement : [nextElement];
  6346. var lastElementArray = isArray(lastElement) ? lastElement : [lastElement];
  6347. return compareArray$1(nextElementArray, lastElementArray);
  6348. }
  6349. // 普通的jsx元素, 且都非空
  6350. var nextKey = nextElement.key,
  6351. nextType = nextElement.type;
  6352. var lastKey = lastElement.key,
  6353. lastType = lastElement.type;
  6354. // key 值不相等
  6355. if (!isNil(nextKey) && nextKey !== lastKey) {
  6356. return [deleteElement(lastElement), appearElement(nextElement)];
  6357. }
  6358. // shape 类型的变化
  6359. if (nextType !== lastType) {
  6360. // return [deleteElement(lastElement), nextElement];
  6361. return changeElementType(nextElement, lastElement);
  6362. }
  6363. return updateElement(nextElement, lastElement);
  6364. }
  6365. function objToString(obj) {
  6366. return Object.prototype.toString.call(obj);
  6367. }
  6368. function objectKeys(obj) {
  6369. return Object.keys(obj);
  6370. }
  6371. function equal(a, b) {
  6372. if (a === b) return true;
  6373. if (_typeof(a) !== _typeof(b)) {
  6374. return false;
  6375. }
  6376. // null 和 undefined
  6377. if (a == null || b == null) {
  6378. return false;
  6379. }
  6380. // 特殊处理NaN
  6381. if (Number.isNaN(a) && Number.isNaN(b)) {
  6382. return true;
  6383. }
  6384. if (objToString(a) !== objToString(b)) {
  6385. return false;
  6386. }
  6387. // 如果是function, 则认为是相对
  6388. if (isFunction(a)) {
  6389. return true;
  6390. }
  6391. // 值类型,Number String Boolean
  6392. if (_typeof(a) !== 'object') {
  6393. return false;
  6394. }
  6395. if (isArray(a)) {
  6396. if (a.length !== b.length) {
  6397. return false;
  6398. }
  6399. for (var i = a.length - 1; i >= 0; i--) {
  6400. if (!equal(a[i], b[i])) {
  6401. return false;
  6402. }
  6403. }
  6404. return true;
  6405. }
  6406. if (!isPlainObject(a)) {
  6407. return false;
  6408. }
  6409. var ka = objectKeys(a);
  6410. var kb = objectKeys(b);
  6411. // having the same number of owned properties (keys incorporates hasOwnProperty)
  6412. if (ka.length !== kb.length) {
  6413. return false;
  6414. }
  6415. // the same set of keys (although not necessarily the same order),
  6416. ka.sort();
  6417. kb.sort();
  6418. // ~~~cheap key test
  6419. for (var _i = ka.length - 1; _i >= 0; _i--) {
  6420. if (ka[_i] != kb[_i]) {
  6421. return false;
  6422. }
  6423. }
  6424. // equivalent values for every corresponding key, and ~~~possibly expensive deep test
  6425. for (var _i2 = ka.length - 1; _i2 >= 0; _i2--) {
  6426. var key = ka[_i2];
  6427. if (!equal(a[key], b[key])) {
  6428. return false;
  6429. }
  6430. }
  6431. return true;
  6432. }
  6433. var _excluded$2 = ["transformFrom"];
  6434. function pickElement(element) {
  6435. if (!element) return element;
  6436. return Children.map(element, function (item) {
  6437. if (!item) return item;
  6438. // 只需要这几个元素就可以了
  6439. return pick(item, ['key', 'ref', 'type', 'props']);
  6440. });
  6441. }
  6442. function renderShape(component, children, animate) {
  6443. var container = component.container,
  6444. context = component.context,
  6445. updater = component.updater,
  6446. __lastElement = component.__lastElement,
  6447. transformFrom = component.transformFrom,
  6448. componentAnimate = component.animate;
  6449. // 先清空绘制内容
  6450. container.clear();
  6451. animate = isBoolean(animate) ? animate : componentAnimate;
  6452. var px2hd = context.px2hd;
  6453. var lastElement = __lastElement || transformFrom && transformFrom.__lastElement;
  6454. // children 是 shape 的 jsx 结构, component.render() 返回的结构
  6455. var shapeElement = renderJSXElement$1(children, context, updater);
  6456. // @ts-ignore
  6457. component.__lastElement = shapeElement;
  6458. var renderElement = animate !== false ? compareElement(shapeElement, lastElement) : shapeElement;
  6459. if (!renderElement) return null;
  6460. // 生成G的节点树, 存在数组的情况是根节点有变化,之前的树删除,新的树创建
  6461. if (isArray(renderElement)) {
  6462. return renderElement.map(function (element) {
  6463. return render(element, container, animate, px2hd);
  6464. });
  6465. } else {
  6466. return render(renderElement, container, animate, px2hd);
  6467. }
  6468. }
  6469. function setComponentAnimate(child, parent) {
  6470. var parentAnimate = parent.animate;
  6471. // 如果父组件不需要动画,子组件全不不执行动画
  6472. if (parentAnimate === false) {
  6473. child.animate = false;
  6474. return;
  6475. }
  6476. var childProps = child.props;
  6477. var childAnimate = childProps.animate;
  6478. child.animate = isBoolean(childAnimate) ? childAnimate : parentAnimate;
  6479. }
  6480. function getTransformComponent(component) {
  6481. if (!component) return null;
  6482. // @ts-ignore
  6483. var __lastElement = component.__lastElement,
  6484. children = component.children;
  6485. if (__lastElement) {
  6486. return component;
  6487. }
  6488. if (!children) {
  6489. return null;
  6490. }
  6491. var componentFromChildren = null;
  6492. Children.map(children, function (item) {
  6493. if (componentFromChildren) return;
  6494. if (!item) return;
  6495. var component = getTransformComponent(item.component);
  6496. if (component) {
  6497. componentFromChildren = component;
  6498. }
  6499. });
  6500. return componentFromChildren;
  6501. }
  6502. function getTransformFromComponentRef(transformFromRef) {
  6503. if (!transformFromRef || !transformFromRef.current) {
  6504. return null;
  6505. }
  6506. var transformFromComponent = transformFromRef.current;
  6507. return getTransformComponent(transformFromComponent);
  6508. }
  6509. function createComponent(parent, element) {
  6510. var type = element.type,
  6511. props = element.props,
  6512. ref = element.ref;
  6513. var container = parent.container,
  6514. context = parent.context,
  6515. updater = parent.updater,
  6516. transformFrom = parent.transformFrom;
  6517. var transformFromRef = props.transformFrom,
  6518. receiveProps = _objectWithoutProperties(props, _excluded$2);
  6519. var component;
  6520. // @ts-ignore
  6521. if (type.prototype && type.prototype.isF2Component) {
  6522. // @ts-ignore
  6523. component = new type(receiveProps, context, updater);
  6524. } else {
  6525. component = new Component(receiveProps, context, updater);
  6526. component.render = function () {
  6527. // @ts-ignore
  6528. return type(this.props, context, updater);
  6529. };
  6530. }
  6531. // 设置ref
  6532. if (ref) {
  6533. ref.current = component;
  6534. }
  6535. // 因为view 可能在子组件,所以这里要透传到子组件
  6536. if (transformFrom) {
  6537. // @ts-ignore
  6538. component.transformFrom = transformFrom;
  6539. }
  6540. if (transformFromRef) {
  6541. var transformFromComponent = transformFromRef ? getTransformFromComponentRef(transformFromRef) : null;
  6542. // @ts-ignore
  6543. component.transformFrom = transformFromComponent;
  6544. }
  6545. var zIndex = props.zIndex;
  6546. // 每个组件都新建一个独立容器
  6547. component.container = container.addGroup({
  6548. zIndex: zIndex
  6549. });
  6550. component.context = context;
  6551. component.updater = updater;
  6552. return component;
  6553. }
  6554. function renderComponent(component) {
  6555. Children.map(component, function (item) {
  6556. var lastChildren = item.children;
  6557. var mount = isUndefined(lastChildren);
  6558. if (mount) {
  6559. if (item.willMount) item.willMount();
  6560. } else if (item.willUpdate) {
  6561. item.willUpdate();
  6562. }
  6563. });
  6564. Children.map(component, function (item) {
  6565. var lastChildren = item.children;
  6566. var mount = isUndefined(lastChildren);
  6567. var newChildren = item.render();
  6568. renderChildren(item, newChildren, lastChildren);
  6569. if (mount) {
  6570. if (item.didMount) item.didMount();
  6571. } else if (item.didUpdate) {
  6572. item.didUpdate();
  6573. }
  6574. });
  6575. }
  6576. function destroyElement(elements) {
  6577. Children.map(elements, function (element) {
  6578. if (!element) return;
  6579. var component = element.component;
  6580. if (!component) {
  6581. return;
  6582. }
  6583. if (component.willUnmount) {
  6584. component.willUnmount();
  6585. }
  6586. destroyElement(component.children);
  6587. var container = component.container;
  6588. container.remove(true);
  6589. if (component.didUnmount) {
  6590. component.didUnmount();
  6591. }
  6592. component.destroy();
  6593. });
  6594. }
  6595. function diffElement(parent, nextElement, lastElement) {
  6596. if (!nextElement && !lastElement) {
  6597. return null;
  6598. }
  6599. // 删除
  6600. if (!nextElement && lastElement) {
  6601. destroyElement(lastElement);
  6602. return null;
  6603. }
  6604. // 新建
  6605. if (nextElement && !lastElement) {
  6606. return nextElement;
  6607. }
  6608. // diff
  6609. var nextType = nextElement.type,
  6610. nextProps = nextElement.props;
  6611. var lastType = lastElement.type,
  6612. lastProps = lastElement.props,
  6613. lastComponent = lastElement.component;
  6614. if (nextType !== lastType) {
  6615. destroyElement(lastElement);
  6616. return nextElement;
  6617. }
  6618. // 保留component, 等下一阶段处理
  6619. nextElement.component = lastComponent;
  6620. if (equal(nextProps, lastProps) && lastComponent.context === parent.context) {
  6621. return null;
  6622. }
  6623. return nextElement;
  6624. }
  6625. function diff(parent, nextChildren, lastChildren) {
  6626. // destroy
  6627. // 生命周期的几个阶段
  6628. // should create / update
  6629. // create / Receive props
  6630. // willMount / willUpdate
  6631. // render
  6632. // didMount / didUpdate
  6633. var childrenArray = [];
  6634. // 1. 第一轮比较, 直接destroy的元素处理掉,destroy 的元素不需要进入下一阶段
  6635. Children.compare(nextChildren, lastChildren, function (next, last) {
  6636. var element = diffElement(parent, next, last);
  6637. if (element) {
  6638. childrenArray = childrenArray.concat(Children.toArray(element).filter(Boolean));
  6639. }
  6640. });
  6641. // 2. 处理 shouldCreate 和 shouldUpdate
  6642. var shouldProcessChildren = childrenArray.filter(function (element) {
  6643. var component = element.component,
  6644. props = element.props;
  6645. // 说明是新增的元素,需要新建
  6646. if (!component) return true;
  6647. // 不需要更新
  6648. if (component.shouldUpdate && component.shouldUpdate(props) === false) {
  6649. return false;
  6650. }
  6651. return true;
  6652. });
  6653. // 3. 处理 create 和 Receive props
  6654. var shouldRenderComponent = shouldProcessChildren.map(function (element) {
  6655. var component = element.component;
  6656. if (!component) {
  6657. component = createComponent(parent, element);
  6658. } else {
  6659. var props = element.props;
  6660. if (component.willReceiveProps) {
  6661. component.willReceiveProps(props, parent.context);
  6662. }
  6663. var zIndex = props.zIndex;
  6664. component.container.set('zIndex', zIndex);
  6665. component.props = props;
  6666. component.context = parent.context;
  6667. }
  6668. element.component = component;
  6669. setComponentAnimate(component, parent);
  6670. return component;
  6671. });
  6672. // 4. 处理 render
  6673. renderComponent(shouldRenderComponent);
  6674. // 按子组件顺序渲染内容
  6675. childrenArray.forEach(function (element) {
  6676. var component = element.component;
  6677. var parentGroup = parent.container;
  6678. parentGroup.add(component.container);
  6679. });
  6680. return nextChildren;
  6681. }
  6682. function isContainer(children) {
  6683. if (!children) return false;
  6684. if (!isArray(children)) {
  6685. var type = children.type;
  6686. return typeof type === 'function';
  6687. }
  6688. for (var i = 0, len = children.length; i < len; i++) {
  6689. if (isContainer(children[i])) {
  6690. return true;
  6691. }
  6692. }
  6693. return false;
  6694. }
  6695. function renderChildren(parent, nextChildren, lastChildren) {
  6696. // react 生成的 element 是 not extensible 的,这里新建一个新对象,并把需要的内容pick 出来
  6697. nextChildren = pickElement(nextChildren);
  6698. parent.children = nextChildren;
  6699. if (isContainer(nextChildren)) {
  6700. nextChildren = diff(parent, nextChildren, lastChildren);
  6701. } else {
  6702. renderShape(parent, nextChildren);
  6703. }
  6704. return nextChildren;
  6705. }
  6706. var arrayWithHoles = createCommonjsModule(function (module) {
  6707. function _arrayWithHoles(arr) {
  6708. if (Array.isArray(arr)) return arr;
  6709. }
  6710. module.exports = _arrayWithHoles, module.exports.__esModule = true, module.exports["default"] = module.exports;
  6711. });
  6712. var iterableToArrayLimit = createCommonjsModule(function (module) {
  6713. function _iterableToArrayLimit(arr, i) {
  6714. var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"];
  6715. if (null != _i) {
  6716. var _s,
  6717. _e,
  6718. _x,
  6719. _r,
  6720. _arr = [],
  6721. _n = !0,
  6722. _d = !1;
  6723. try {
  6724. if (_x = (_i = _i.call(arr)).next, 0 === i) {
  6725. if (Object(_i) !== _i) return;
  6726. _n = !1;
  6727. } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0) {
  6728. ;
  6729. }
  6730. } catch (err) {
  6731. _d = !0, _e = err;
  6732. } finally {
  6733. try {
  6734. if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return;
  6735. } finally {
  6736. if (_d) throw _e;
  6737. }
  6738. }
  6739. return _arr;
  6740. }
  6741. }
  6742. module.exports = _iterableToArrayLimit, module.exports.__esModule = true, module.exports["default"] = module.exports;
  6743. });
  6744. var arrayLikeToArray = createCommonjsModule(function (module) {
  6745. function _arrayLikeToArray(arr, len) {
  6746. if (len == null || len > arr.length) len = arr.length;
  6747. for (var i = 0, arr2 = new Array(len); i < len; i++) {
  6748. arr2[i] = arr[i];
  6749. }
  6750. return arr2;
  6751. }
  6752. module.exports = _arrayLikeToArray, module.exports.__esModule = true, module.exports["default"] = module.exports;
  6753. });
  6754. var unsupportedIterableToArray = createCommonjsModule(function (module) {
  6755. function _unsupportedIterableToArray(o, minLen) {
  6756. if (!o) return;
  6757. if (typeof o === "string") return arrayLikeToArray(o, minLen);
  6758. var n = Object.prototype.toString.call(o).slice(8, -1);
  6759. if (n === "Object" && o.constructor) n = o.constructor.name;
  6760. if (n === "Map" || n === "Set") return Array.from(o);
  6761. if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return arrayLikeToArray(o, minLen);
  6762. }
  6763. module.exports = _unsupportedIterableToArray, module.exports.__esModule = true, module.exports["default"] = module.exports;
  6764. });
  6765. var nonIterableRest = createCommonjsModule(function (module) {
  6766. function _nonIterableRest() {
  6767. throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
  6768. }
  6769. module.exports = _nonIterableRest, module.exports.__esModule = true, module.exports["default"] = module.exports;
  6770. });
  6771. var slicedToArray = createCommonjsModule(function (module) {
  6772. function _slicedToArray(arr, i) {
  6773. return arrayWithHoles(arr) || iterableToArrayLimit(arr, i) || unsupportedIterableToArray(arr, i) || nonIterableRest();
  6774. }
  6775. module.exports = _slicedToArray, module.exports.__esModule = true, module.exports["default"] = module.exports;
  6776. });
  6777. var _slicedToArray = /*@__PURE__*/getDefaultExportFromCjs(slicedToArray);
  6778. var Layout = /*#__PURE__*/function () {
  6779. function Layout(layout) {
  6780. _classCallCheck(this, Layout);
  6781. this.left = 0;
  6782. this.top = 0;
  6783. this.width = 0;
  6784. this.height = 0;
  6785. this.update(layout);
  6786. }
  6787. _createClass(Layout, [{
  6788. key: "update",
  6789. value: function update(layout) {
  6790. mix(this, layout);
  6791. var left = this.left,
  6792. top = this.top,
  6793. width = this.width,
  6794. height = this.height;
  6795. this.right = left + width;
  6796. this.bottom = top + height;
  6797. return this;
  6798. }
  6799. }, {
  6800. key: "padding",
  6801. value: function padding(style) {
  6802. if (!style) {
  6803. return this;
  6804. }
  6805. var _style$top = style.top,
  6806. paddingTop = _style$top === void 0 ? 0 : _style$top,
  6807. _style$right = style.right,
  6808. paddingRight = _style$right === void 0 ? 0 : _style$right,
  6809. _style$bottom = style.bottom,
  6810. paddingBottom = _style$bottom === void 0 ? 0 : _style$bottom,
  6811. _style$left = style.left,
  6812. paddingLeft = _style$left === void 0 ? 0 : _style$left;
  6813. var top = this.top,
  6814. right = this.right,
  6815. bottom = this.bottom,
  6816. left = this.left;
  6817. this.top = top + paddingTop;
  6818. this.right = right - paddingRight;
  6819. this.bottom = bottom - paddingBottom;
  6820. this.left = left + paddingLeft;
  6821. this.width = this.right - this.left;
  6822. this.height = this.bottom - this.top;
  6823. return this;
  6824. }
  6825. }, {
  6826. key: "clone",
  6827. value: function clone() {
  6828. var left = this.left,
  6829. top = this.top,
  6830. width = this.width,
  6831. height = this.height;
  6832. return new Layout({
  6833. left: left,
  6834. top: top,
  6835. width: width,
  6836. height: height
  6837. });
  6838. }
  6839. }], [{
  6840. key: "fromStyle",
  6841. value: function fromStyle(style) {
  6842. var left = style.left,
  6843. top = style.top,
  6844. width = style.width,
  6845. height = style.height,
  6846. padding = style.padding;
  6847. var _padding = _slicedToArray(padding, 4),
  6848. paddingTop = _padding[0],
  6849. paddingRight = _padding[1],
  6850. paddingBottom = _padding[2],
  6851. paddingLeft = _padding[3];
  6852. return new Layout({
  6853. left: left + paddingLeft,
  6854. top: top + paddingTop,
  6855. width: width - paddingLeft - paddingRight,
  6856. height: height - paddingTop - paddingBottom
  6857. });
  6858. }
  6859. }]);
  6860. return Layout;
  6861. }();
  6862. function createUpdater(canvas) {
  6863. var setStateQueue = [];
  6864. var renderQueue = [];
  6865. var callbackQueue = [];
  6866. function process() {
  6867. var item;
  6868. // let component;
  6869. while (item = setStateQueue.shift()) {
  6870. var _item = item,
  6871. state = _item.state,
  6872. component = _item.component,
  6873. callback = _item.callback;
  6874. if (component.destroyed) {
  6875. continue;
  6876. }
  6877. // 如果没有prevState,则将当前的state作为初始的prevState
  6878. if (!component.prevState) {
  6879. component.prevState = Object.assign({}, component.state);
  6880. }
  6881. // 如果stateChange是一个方法,也就是setState的第二种形式
  6882. if (typeof state === 'function') {
  6883. Object.assign(component.state, state(component.prevState, component.props));
  6884. } else {
  6885. // 如果stateChange是一个对象,则直接合并到setState中
  6886. Object.assign(component.state, state);
  6887. }
  6888. component.prevState = component.state;
  6889. if (typeof callback === 'function') {
  6890. callbackQueue.push({
  6891. callback: callback,
  6892. component: component
  6893. });
  6894. }
  6895. }
  6896. var renderComponents = [].concat(renderQueue);
  6897. canvas.renderComponents(renderComponents);
  6898. // callback queue
  6899. commitRenderQueue();
  6900. // 清空
  6901. renderQueue.length = 0;
  6902. callbackQueue.length = 0;
  6903. }
  6904. function enqueueSetState(component, state, callback) {
  6905. if (setStateQueue.length === 0) {
  6906. setTimeout(process, 0);
  6907. }
  6908. setStateQueue.push({
  6909. component: component,
  6910. state: state,
  6911. callback: callback
  6912. });
  6913. if (renderQueue.indexOf(component) < 0) {
  6914. renderQueue.push(component);
  6915. }
  6916. }
  6917. function commitRenderQueue() {
  6918. for (var i = 0; i < callbackQueue.length; i++) {
  6919. var _callbackQueue$i = callbackQueue[i],
  6920. callback = _callbackQueue$i.callback,
  6921. component = _callbackQueue$i.component;
  6922. callback.call(component);
  6923. }
  6924. }
  6925. var updater = {
  6926. // isMounted: function(publicInstance) {
  6927. // return false;
  6928. // },
  6929. enqueueForceUpdate: enqueueSetState,
  6930. // enqueueReplaceState: function(publicInstance, completeState) {
  6931. // },
  6932. enqueueSetState: enqueueSetState
  6933. };
  6934. return updater;
  6935. }
  6936. var axis = {
  6937. labelOffset: '15px',
  6938. line: {
  6939. stroke: '#E8E8E8',
  6940. lineWidth: '1px'
  6941. },
  6942. label: {
  6943. fill: '#808080',
  6944. fontSize: '20px'
  6945. },
  6946. grid: {
  6947. stroke: '#E8E8E8',
  6948. lineWidth: '1px',
  6949. lineDash: ['4px']
  6950. }
  6951. };
  6952. var guide = {
  6953. line: {
  6954. style: {
  6955. stroke: '#a3a3a3',
  6956. lineWidth: 1
  6957. },
  6958. offsetX: 0,
  6959. offsetY: 0
  6960. },
  6961. text: {
  6962. style: {
  6963. fill: '#787878',
  6964. // textAlign: 'center',
  6965. textBaseline: 'middle'
  6966. },
  6967. offsetX: 0,
  6968. offsetY: 0
  6969. },
  6970. rect: {
  6971. style: {
  6972. fill: '#fafafa'
  6973. }
  6974. },
  6975. arc: {
  6976. style: {
  6977. stroke: '#a3a3a3'
  6978. }
  6979. },
  6980. html: {
  6981. offsetX: 0,
  6982. offsetY: 0,
  6983. alignX: 'center',
  6984. alignY: 'middle'
  6985. },
  6986. tag: {
  6987. offsetX: 0,
  6988. offsetY: 0,
  6989. side: 4,
  6990. background: {
  6991. padding: 5,
  6992. radius: 2,
  6993. fill: '#1890FF'
  6994. },
  6995. textStyle: {
  6996. fontSize: 12,
  6997. fill: '#fff',
  6998. textAlign: 'center',
  6999. textBaseline: 'middle'
  7000. }
  7001. },
  7002. point: {
  7003. offsetX: 0,
  7004. offsetY: 0,
  7005. style: {
  7006. fill: '#fff',
  7007. r: 3,
  7008. lineWidth: 2,
  7009. stroke: '#1890ff'
  7010. }
  7011. }
  7012. };
  7013. var chart = {
  7014. padding: ['30px', '30px', '30px', '30px']
  7015. };
  7016. var Theme = {
  7017. fontFamily: '"Helvetica Neue", Helvetica, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", Arial, sans-serif',
  7018. pixelRatio: 1,
  7019. padding: [0, 0, 0, 0],
  7020. chart: chart,
  7021. colors: ['#1890FF', '#2FC25B', '#FACC14', '#223273', '#8543E0', '#13C2C2', '#3436C7', '#F04864'],
  7022. shapes: {
  7023. line: ['line', 'dash', 'smooth'],
  7024. point: ['circle', 'hollowCircle', 'rect'],
  7025. area: ['area', 'smooth'],
  7026. interval: ['rect', 'pyramid', 'funnel']
  7027. },
  7028. sizes: ['4px', '6px', '8px', '10px', '12px'],
  7029. shape: {
  7030. line: {
  7031. default: {
  7032. lineWidth: '4px',
  7033. lineJoin: 'round',
  7034. lineCap: 'round'
  7035. },
  7036. smooth: {
  7037. smooth: true
  7038. },
  7039. dash: {
  7040. lineDash: ['8px', '8px']
  7041. }
  7042. },
  7043. point: {
  7044. default: {
  7045. size: '6px'
  7046. },
  7047. hollowCircle: {
  7048. lineWidth: '2px'
  7049. }
  7050. },
  7051. area: {
  7052. default: {
  7053. fillOpacity: 0.1
  7054. }
  7055. },
  7056. interval: {
  7057. default: {}
  7058. }
  7059. },
  7060. axis: axis,
  7061. guide: guide
  7062. };
  7063. var requestAnimationFrame$2 = (typeof window === "undefined" ? "undefined" : _typeof(window)) === 'object' && window.requestAnimationFrame ? window.requestAnimationFrame : function (fn) {
  7064. return setTimeout(fn, 16);
  7065. };
  7066. var cancelAnimationFrame$1 = (typeof window === "undefined" ? "undefined" : _typeof(window)) === 'object' && window.cancelAnimationFrame ? window.cancelAnimationFrame : function (number) {
  7067. return clearTimeout(number);
  7068. };
  7069. var clock = (typeof performance === "undefined" ? "undefined" : _typeof(performance)) === 'object' && performance.now ? performance : Date;
  7070. var Timeline$1 = /*#__PURE__*/function () {
  7071. function Timeline() {
  7072. _classCallCheck(this, Timeline);
  7073. this.playing = false;
  7074. // 暂停中
  7075. this.paused = false;
  7076. // 暂停的时间点
  7077. this.pausedTime = 0;
  7078. }
  7079. _createClass(Timeline, [{
  7080. key: "play",
  7081. value: function play(duration, onUpdate, onEnd) {
  7082. var _this = this;
  7083. if (duration <= 0) {
  7084. onEnd();
  7085. return;
  7086. }
  7087. // 上次动画未结束
  7088. if (this.playing) {
  7089. return;
  7090. }
  7091. // 记录 duration、onUpdate、onEnd
  7092. this.duration = duration;
  7093. this.onUpdate = onUpdate;
  7094. this.onEnd = onEnd;
  7095. var paused = this.paused,
  7096. pausedTime = this.pausedTime;
  7097. this.playing = true;
  7098. var startTime = clock.now();
  7099. // 如果当前正在暂停状态, 从暂停态继续播放
  7100. if (paused && pausedTime) {
  7101. startTime = startTime - pausedTime;
  7102. this.paused = false;
  7103. this.pausedTime = 0;
  7104. }
  7105. var play = function play() {
  7106. var now = clock.now();
  7107. var time = now - startTime;
  7108. if (time >= duration) {
  7109. onUpdate(duration);
  7110. onEnd();
  7111. _this.playing = false;
  7112. return;
  7113. }
  7114. if (_this.paused) {
  7115. onUpdate(time);
  7116. _this.pausedTime = time;
  7117. _this.playing = false;
  7118. return;
  7119. }
  7120. onUpdate(time);
  7121. _this.animationFrameNumber = requestAnimationFrame$2(play);
  7122. };
  7123. this.animationFrameNumber = requestAnimationFrame$2(play);
  7124. }
  7125. }, {
  7126. key: "pause",
  7127. value: function pause() {
  7128. this.paused = true;
  7129. }
  7130. }, {
  7131. key: "stop",
  7132. value: function stop() {
  7133. this.playing = false;
  7134. }
  7135. }, {
  7136. key: "end",
  7137. value: function end() {
  7138. if (!this.playing) {
  7139. return;
  7140. }
  7141. // 停掉动画
  7142. this.abort();
  7143. // 更新到最后一帧状态
  7144. this.onUpdate(this.duration);
  7145. this.onEnd();
  7146. }
  7147. }, {
  7148. key: "abort",
  7149. value: function abort() {
  7150. if (!this.animationFrameNumber) {
  7151. return;
  7152. }
  7153. cancelAnimationFrame$1(this.animationFrameNumber);
  7154. this.playing = false;
  7155. this.animationFrameNumber = null;
  7156. }
  7157. }]);
  7158. return Timeline;
  7159. }();
  7160. function define (constructor, factory, prototype) {
  7161. constructor.prototype = factory.prototype = prototype;
  7162. prototype.constructor = constructor;
  7163. }
  7164. function extend(parent, definition) {
  7165. var prototype = Object.create(parent.prototype);
  7166. for (var key in definition) {
  7167. prototype[key] = definition[key];
  7168. }
  7169. return prototype;
  7170. }
  7171. function Color() {}
  7172. var _darker = 0.7;
  7173. var _brighter = 1 / _darker;
  7174. var reI = "\\s*([+-]?\\d+)\\s*",
  7175. reN = "\\s*([+-]?\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)\\s*",
  7176. reP = "\\s*([+-]?\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)%\\s*",
  7177. reHex = /^#([0-9a-f]{3,8})$/,
  7178. reRgbInteger = new RegExp("^rgb\\(" + [reI, reI, reI] + "\\)$"),
  7179. reRgbPercent = new RegExp("^rgb\\(" + [reP, reP, reP] + "\\)$"),
  7180. reRgbaInteger = new RegExp("^rgba\\(" + [reI, reI, reI, reN] + "\\)$"),
  7181. reRgbaPercent = new RegExp("^rgba\\(" + [reP, reP, reP, reN] + "\\)$"),
  7182. reHslPercent = new RegExp("^hsl\\(" + [reN, reP, reP] + "\\)$"),
  7183. reHslaPercent = new RegExp("^hsla\\(" + [reN, reP, reP, reN] + "\\)$");
  7184. var named = {
  7185. aliceblue: 0xf0f8ff,
  7186. antiquewhite: 0xfaebd7,
  7187. aqua: 0x00ffff,
  7188. aquamarine: 0x7fffd4,
  7189. azure: 0xf0ffff,
  7190. beige: 0xf5f5dc,
  7191. bisque: 0xffe4c4,
  7192. black: 0x000000,
  7193. blanchedalmond: 0xffebcd,
  7194. blue: 0x0000ff,
  7195. blueviolet: 0x8a2be2,
  7196. brown: 0xa52a2a,
  7197. burlywood: 0xdeb887,
  7198. cadetblue: 0x5f9ea0,
  7199. chartreuse: 0x7fff00,
  7200. chocolate: 0xd2691e,
  7201. coral: 0xff7f50,
  7202. cornflowerblue: 0x6495ed,
  7203. cornsilk: 0xfff8dc,
  7204. crimson: 0xdc143c,
  7205. cyan: 0x00ffff,
  7206. darkblue: 0x00008b,
  7207. darkcyan: 0x008b8b,
  7208. darkgoldenrod: 0xb8860b,
  7209. darkgray: 0xa9a9a9,
  7210. darkgreen: 0x006400,
  7211. darkgrey: 0xa9a9a9,
  7212. darkkhaki: 0xbdb76b,
  7213. darkmagenta: 0x8b008b,
  7214. darkolivegreen: 0x556b2f,
  7215. darkorange: 0xff8c00,
  7216. darkorchid: 0x9932cc,
  7217. darkred: 0x8b0000,
  7218. darksalmon: 0xe9967a,
  7219. darkseagreen: 0x8fbc8f,
  7220. darkslateblue: 0x483d8b,
  7221. darkslategray: 0x2f4f4f,
  7222. darkslategrey: 0x2f4f4f,
  7223. darkturquoise: 0x00ced1,
  7224. darkviolet: 0x9400d3,
  7225. deeppink: 0xff1493,
  7226. deepskyblue: 0x00bfff,
  7227. dimgray: 0x696969,
  7228. dimgrey: 0x696969,
  7229. dodgerblue: 0x1e90ff,
  7230. firebrick: 0xb22222,
  7231. floralwhite: 0xfffaf0,
  7232. forestgreen: 0x228b22,
  7233. fuchsia: 0xff00ff,
  7234. gainsboro: 0xdcdcdc,
  7235. ghostwhite: 0xf8f8ff,
  7236. gold: 0xffd700,
  7237. goldenrod: 0xdaa520,
  7238. gray: 0x808080,
  7239. green: 0x008000,
  7240. greenyellow: 0xadff2f,
  7241. grey: 0x808080,
  7242. honeydew: 0xf0fff0,
  7243. hotpink: 0xff69b4,
  7244. indianred: 0xcd5c5c,
  7245. indigo: 0x4b0082,
  7246. ivory: 0xfffff0,
  7247. khaki: 0xf0e68c,
  7248. lavender: 0xe6e6fa,
  7249. lavenderblush: 0xfff0f5,
  7250. lawngreen: 0x7cfc00,
  7251. lemonchiffon: 0xfffacd,
  7252. lightblue: 0xadd8e6,
  7253. lightcoral: 0xf08080,
  7254. lightcyan: 0xe0ffff,
  7255. lightgoldenrodyellow: 0xfafad2,
  7256. lightgray: 0xd3d3d3,
  7257. lightgreen: 0x90ee90,
  7258. lightgrey: 0xd3d3d3,
  7259. lightpink: 0xffb6c1,
  7260. lightsalmon: 0xffa07a,
  7261. lightseagreen: 0x20b2aa,
  7262. lightskyblue: 0x87cefa,
  7263. lightslategray: 0x778899,
  7264. lightslategrey: 0x778899,
  7265. lightsteelblue: 0xb0c4de,
  7266. lightyellow: 0xffffe0,
  7267. lime: 0x00ff00,
  7268. limegreen: 0x32cd32,
  7269. linen: 0xfaf0e6,
  7270. magenta: 0xff00ff,
  7271. maroon: 0x800000,
  7272. mediumaquamarine: 0x66cdaa,
  7273. mediumblue: 0x0000cd,
  7274. mediumorchid: 0xba55d3,
  7275. mediumpurple: 0x9370db,
  7276. mediumseagreen: 0x3cb371,
  7277. mediumslateblue: 0x7b68ee,
  7278. mediumspringgreen: 0x00fa9a,
  7279. mediumturquoise: 0x48d1cc,
  7280. mediumvioletred: 0xc71585,
  7281. midnightblue: 0x191970,
  7282. mintcream: 0xf5fffa,
  7283. mistyrose: 0xffe4e1,
  7284. moccasin: 0xffe4b5,
  7285. navajowhite: 0xffdead,
  7286. navy: 0x000080,
  7287. oldlace: 0xfdf5e6,
  7288. olive: 0x808000,
  7289. olivedrab: 0x6b8e23,
  7290. orange: 0xffa500,
  7291. orangered: 0xff4500,
  7292. orchid: 0xda70d6,
  7293. palegoldenrod: 0xeee8aa,
  7294. palegreen: 0x98fb98,
  7295. paleturquoise: 0xafeeee,
  7296. palevioletred: 0xdb7093,
  7297. papayawhip: 0xffefd5,
  7298. peachpuff: 0xffdab9,
  7299. peru: 0xcd853f,
  7300. pink: 0xffc0cb,
  7301. plum: 0xdda0dd,
  7302. powderblue: 0xb0e0e6,
  7303. purple: 0x800080,
  7304. rebeccapurple: 0x663399,
  7305. red: 0xff0000,
  7306. rosybrown: 0xbc8f8f,
  7307. royalblue: 0x4169e1,
  7308. saddlebrown: 0x8b4513,
  7309. salmon: 0xfa8072,
  7310. sandybrown: 0xf4a460,
  7311. seagreen: 0x2e8b57,
  7312. seashell: 0xfff5ee,
  7313. sienna: 0xa0522d,
  7314. silver: 0xc0c0c0,
  7315. skyblue: 0x87ceeb,
  7316. slateblue: 0x6a5acd,
  7317. slategray: 0x708090,
  7318. slategrey: 0x708090,
  7319. snow: 0xfffafa,
  7320. springgreen: 0x00ff7f,
  7321. steelblue: 0x4682b4,
  7322. tan: 0xd2b48c,
  7323. teal: 0x008080,
  7324. thistle: 0xd8bfd8,
  7325. tomato: 0xff6347,
  7326. turquoise: 0x40e0d0,
  7327. violet: 0xee82ee,
  7328. wheat: 0xf5deb3,
  7329. white: 0xffffff,
  7330. whitesmoke: 0xf5f5f5,
  7331. yellow: 0xffff00,
  7332. yellowgreen: 0x9acd32
  7333. };
  7334. define(Color, color, {
  7335. copy: function copy(channels) {
  7336. return Object.assign(new this.constructor(), this, channels);
  7337. },
  7338. displayable: function displayable() {
  7339. return this.rgb().displayable();
  7340. },
  7341. hex: color_formatHex,
  7342. // Deprecated! Use color.formatHex.
  7343. formatHex: color_formatHex,
  7344. formatHsl: color_formatHsl,
  7345. formatRgb: color_formatRgb,
  7346. toString: color_formatRgb
  7347. });
  7348. function color_formatHex() {
  7349. return this.rgb().formatHex();
  7350. }
  7351. function color_formatHsl() {
  7352. return hslConvert(this).formatHsl();
  7353. }
  7354. function color_formatRgb() {
  7355. return this.rgb().formatRgb();
  7356. }
  7357. function color(format) {
  7358. var m, l;
  7359. format = (format + "").trim().toLowerCase();
  7360. return (m = reHex.exec(format)) ? (l = m[1].length, m = parseInt(m[1], 16), l === 6 ? rgbn(m) // #ff0000
  7361. : l === 3 ? new Rgb(m >> 8 & 0xf | m >> 4 & 0xf0, m >> 4 & 0xf | m & 0xf0, (m & 0xf) << 4 | m & 0xf, 1) // #f00
  7362. : l === 8 ? rgba(m >> 24 & 0xff, m >> 16 & 0xff, m >> 8 & 0xff, (m & 0xff) / 0xff) // #ff000000
  7363. : l === 4 ? rgba(m >> 12 & 0xf | m >> 8 & 0xf0, m >> 8 & 0xf | m >> 4 & 0xf0, m >> 4 & 0xf | m & 0xf0, ((m & 0xf) << 4 | m & 0xf) / 0xff) // #f000
  7364. : null // invalid hex
  7365. ) : (m = reRgbInteger.exec(format)) ? new Rgb(m[1], m[2], m[3], 1) // rgb(255, 0, 0)
  7366. : (m = reRgbPercent.exec(format)) ? new Rgb(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, 1) // rgb(100%, 0%, 0%)
  7367. : (m = reRgbaInteger.exec(format)) ? rgba(m[1], m[2], m[3], m[4]) // rgba(255, 0, 0, 1)
  7368. : (m = reRgbaPercent.exec(format)) ? rgba(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, m[4]) // rgb(100%, 0%, 0%, 1)
  7369. : (m = reHslPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, 1) // hsl(120, 50%, 50%)
  7370. : (m = reHslaPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, m[4]) // hsla(120, 50%, 50%, 1)
  7371. : named.hasOwnProperty(format) ? rgbn(named[format]) // eslint-disable-line no-prototype-builtins
  7372. : format === "transparent" ? new Rgb(NaN, NaN, NaN, 0) : null;
  7373. }
  7374. function rgbn(n) {
  7375. return new Rgb(n >> 16 & 0xff, n >> 8 & 0xff, n & 0xff, 1);
  7376. }
  7377. function rgba(r, g, b, a) {
  7378. if (a <= 0) r = g = b = NaN;
  7379. return new Rgb(r, g, b, a);
  7380. }
  7381. function rgbConvert(o) {
  7382. if (!(o instanceof Color)) o = color(o);
  7383. if (!o) return new Rgb();
  7384. o = o.rgb();
  7385. return new Rgb(o.r, o.g, o.b, o.opacity);
  7386. }
  7387. function rgb(r, g, b, opacity) {
  7388. return arguments.length === 1 ? rgbConvert(r) : new Rgb(r, g, b, opacity == null ? 1 : opacity);
  7389. }
  7390. function Rgb(r, g, b, opacity) {
  7391. this.r = +r;
  7392. this.g = +g;
  7393. this.b = +b;
  7394. this.opacity = +opacity;
  7395. }
  7396. define(Rgb, rgb, extend(Color, {
  7397. brighter: function brighter(k) {
  7398. k = k == null ? _brighter : Math.pow(_brighter, k);
  7399. return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);
  7400. },
  7401. darker: function darker(k) {
  7402. k = k == null ? _darker : Math.pow(_darker, k);
  7403. return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);
  7404. },
  7405. rgb: function rgb() {
  7406. return this;
  7407. },
  7408. displayable: function displayable() {
  7409. return -0.5 <= this.r && this.r < 255.5 && -0.5 <= this.g && this.g < 255.5 && -0.5 <= this.b && this.b < 255.5 && 0 <= this.opacity && this.opacity <= 1;
  7410. },
  7411. hex: rgb_formatHex,
  7412. // Deprecated! Use color.formatHex.
  7413. formatHex: rgb_formatHex,
  7414. formatRgb: rgb_formatRgb,
  7415. toString: rgb_formatRgb
  7416. }));
  7417. function rgb_formatHex() {
  7418. return "#" + hex(this.r) + hex(this.g) + hex(this.b);
  7419. }
  7420. function rgb_formatRgb() {
  7421. var a = this.opacity;
  7422. a = isNaN(a) ? 1 : Math.max(0, Math.min(1, a));
  7423. return (a === 1 ? "rgb(" : "rgba(") + Math.max(0, Math.min(255, Math.round(this.r) || 0)) + ", " + Math.max(0, Math.min(255, Math.round(this.g) || 0)) + ", " + Math.max(0, Math.min(255, Math.round(this.b) || 0)) + (a === 1 ? ")" : ", " + a + ")");
  7424. }
  7425. function hex(value) {
  7426. value = Math.max(0, Math.min(255, Math.round(value) || 0));
  7427. return (value < 16 ? "0" : "") + value.toString(16);
  7428. }
  7429. function hsla(h, s, l, a) {
  7430. if (a <= 0) h = s = l = NaN;else if (l <= 0 || l >= 1) h = s = NaN;else if (s <= 0) h = NaN;
  7431. return new Hsl(h, s, l, a);
  7432. }
  7433. function hslConvert(o) {
  7434. if (o instanceof Hsl) return new Hsl(o.h, o.s, o.l, o.opacity);
  7435. if (!(o instanceof Color)) o = color(o);
  7436. if (!o) return new Hsl();
  7437. if (o instanceof Hsl) return o;
  7438. o = o.rgb();
  7439. var r = o.r / 255,
  7440. g = o.g / 255,
  7441. b = o.b / 255,
  7442. min = Math.min(r, g, b),
  7443. max = Math.max(r, g, b),
  7444. h = NaN,
  7445. s = max - min,
  7446. l = (max + min) / 2;
  7447. if (s) {
  7448. if (r === max) h = (g - b) / s + (g < b) * 6;else if (g === max) h = (b - r) / s + 2;else h = (r - g) / s + 4;
  7449. s /= l < 0.5 ? max + min : 2 - max - min;
  7450. h *= 60;
  7451. } else {
  7452. s = l > 0 && l < 1 ? 0 : h;
  7453. }
  7454. return new Hsl(h, s, l, o.opacity);
  7455. }
  7456. function hsl(h, s, l, opacity) {
  7457. return arguments.length === 1 ? hslConvert(h) : new Hsl(h, s, l, opacity == null ? 1 : opacity);
  7458. }
  7459. function Hsl(h, s, l, opacity) {
  7460. this.h = +h;
  7461. this.s = +s;
  7462. this.l = +l;
  7463. this.opacity = +opacity;
  7464. }
  7465. define(Hsl, hsl, extend(Color, {
  7466. brighter: function brighter(k) {
  7467. k = k == null ? _brighter : Math.pow(_brighter, k);
  7468. return new Hsl(this.h, this.s, this.l * k, this.opacity);
  7469. },
  7470. darker: function darker(k) {
  7471. k = k == null ? _darker : Math.pow(_darker, k);
  7472. return new Hsl(this.h, this.s, this.l * k, this.opacity);
  7473. },
  7474. rgb: function rgb() {
  7475. var h = this.h % 360 + (this.h < 0) * 360,
  7476. s = isNaN(h) || isNaN(this.s) ? 0 : this.s,
  7477. l = this.l,
  7478. m2 = l + (l < 0.5 ? l : 1 - l) * s,
  7479. m1 = 2 * l - m2;
  7480. return new Rgb(hsl2rgb(h >= 240 ? h - 240 : h + 120, m1, m2), hsl2rgb(h, m1, m2), hsl2rgb(h < 120 ? h + 240 : h - 120, m1, m2), this.opacity);
  7481. },
  7482. displayable: function displayable() {
  7483. return (0 <= this.s && this.s <= 1 || isNaN(this.s)) && 0 <= this.l && this.l <= 1 && 0 <= this.opacity && this.opacity <= 1;
  7484. },
  7485. formatHsl: function formatHsl() {
  7486. var a = this.opacity;
  7487. a = isNaN(a) ? 1 : Math.max(0, Math.min(1, a));
  7488. return (a === 1 ? "hsl(" : "hsla(") + (this.h || 0) + ", " + (this.s || 0) * 100 + "%, " + (this.l || 0) * 100 + "%" + (a === 1 ? ")" : ", " + a + ")");
  7489. }
  7490. }));
  7491. /* From FvD 13.37, CSS Color Module Level 3 */
  7492. function hsl2rgb(h, m1, m2) {
  7493. return (h < 60 ? m1 + (m2 - m1) * h / 60 : h < 180 ? m2 : h < 240 ? m1 + (m2 - m1) * (240 - h) / 60 : m1) * 255;
  7494. }
  7495. var constant = (function (x) {
  7496. return function () {
  7497. return x;
  7498. };
  7499. });
  7500. function linear(a, d) {
  7501. return function (t) {
  7502. return a + t * d;
  7503. };
  7504. }
  7505. function exponential(a, b, y) {
  7506. return a = Math.pow(a, y), b = Math.pow(b, y) - a, y = 1 / y, function (t) {
  7507. return Math.pow(a + t * b, y);
  7508. };
  7509. }
  7510. function gamma(y) {
  7511. return (y = +y) === 1 ? nogamma : function (a, b) {
  7512. return b - a ? exponential(a, b, y) : constant(isNaN(a) ? b : a);
  7513. };
  7514. }
  7515. function nogamma(a, b) {
  7516. var d = b - a;
  7517. return d ? linear(a, d) : constant(isNaN(a) ? b : a);
  7518. }
  7519. var interpolateRgb = (function rgbGamma(y) {
  7520. var color = gamma(y);
  7521. function rgb$1(start, end) {
  7522. var r = color((start = rgb(start)).r, (end = rgb(end)).r),
  7523. g = color(start.g, end.g),
  7524. b = color(start.b, end.b),
  7525. opacity = nogamma(start.opacity, end.opacity);
  7526. return function (t) {
  7527. start.r = r(t);
  7528. start.g = g(t);
  7529. start.b = b(t);
  7530. start.opacity = opacity(t);
  7531. return start + '';
  7532. };
  7533. }
  7534. rgb$1.gamma = rgbGamma;
  7535. return rgb$1;
  7536. })(1);
  7537. function interpolateNumberArray (a, b) {
  7538. if (!b) b = [];
  7539. var n = a ? Math.min(b.length, a.length) : 0,
  7540. c = b.slice(),
  7541. i;
  7542. return function (t) {
  7543. for (i = 0; i < n; ++i) {
  7544. c[i] = a[i] * (1 - t) + b[i] * t;
  7545. }
  7546. return c;
  7547. };
  7548. }
  7549. function isNumberArray(x) {
  7550. return ArrayBuffer.isView(x) && !(x instanceof DataView);
  7551. }
  7552. function genericArray(a, b) {
  7553. var nb = b ? b.length : 0,
  7554. na = a ? Math.min(nb, a.length) : 0,
  7555. x = new Array(na),
  7556. c = new Array(nb),
  7557. i;
  7558. for (i = 0; i < na; ++i) {
  7559. x[i] = interpolate(a[i], b[i]);
  7560. }
  7561. for (; i < nb; ++i) {
  7562. c[i] = b[i];
  7563. }
  7564. return function (t) {
  7565. for (i = 0; i < na; ++i) {
  7566. c[i] = x[i](t);
  7567. }
  7568. return c;
  7569. };
  7570. }
  7571. function date (a, b) {
  7572. var d = new Date();
  7573. return a = +a, b = +b, function (t) {
  7574. return d.setTime(a * (1 - t) + b * t), d;
  7575. };
  7576. }
  7577. function interpolateNumber (a, b) {
  7578. return a = +a, b = +b, function (t) {
  7579. return a * (1 - t) + b * t;
  7580. };
  7581. }
  7582. function interpolateObject (a, b) {
  7583. var i = {},
  7584. c = {},
  7585. k;
  7586. if (a === null || _typeof(a) !== "object") a = {};
  7587. if (b === null || _typeof(b) !== "object") b = {};
  7588. for (k in b) {
  7589. if (k in a) {
  7590. i[k] = interpolate(a[k], b[k]);
  7591. } else {
  7592. c[k] = b[k];
  7593. }
  7594. }
  7595. return function (t) {
  7596. for (k in i) {
  7597. c[k] = i[k](t);
  7598. }
  7599. return c;
  7600. };
  7601. }
  7602. var reA = /[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,
  7603. reB = new RegExp(reA.source, "g");
  7604. function zero(b) {
  7605. return function () {
  7606. return b;
  7607. };
  7608. }
  7609. function one(b) {
  7610. return function (t) {
  7611. return b(t) + "";
  7612. };
  7613. }
  7614. function string (a, b) {
  7615. var bi = reA.lastIndex = reB.lastIndex = 0,
  7616. // scan index for next number in b
  7617. am,
  7618. // current match in a
  7619. bm,
  7620. // current match in b
  7621. bs,
  7622. // string preceding current number in b, if any
  7623. i = -1,
  7624. // index in s
  7625. s = [],
  7626. // string constants and placeholders
  7627. q = []; // number interpolators
  7628. // Coerce inputs to strings.
  7629. a = a + "", b = b + "";
  7630. // Interpolate pairs of numbers in a & b.
  7631. while ((am = reA.exec(a)) && (bm = reB.exec(b))) {
  7632. if ((bs = bm.index) > bi) {
  7633. // a string precedes the next number in b
  7634. bs = b.slice(bi, bs);
  7635. if (s[i]) s[i] += bs; // coalesce with previous string
  7636. else s[++i] = bs;
  7637. }
  7638. if ((am = am[0]) === (bm = bm[0])) {
  7639. // numbers in a & b match
  7640. if (s[i]) s[i] += bm; // coalesce with previous string
  7641. else s[++i] = bm;
  7642. } else {
  7643. // interpolate non-matching numbers
  7644. s[++i] = null;
  7645. q.push({
  7646. i: i,
  7647. x: interpolateNumber(am, bm)
  7648. });
  7649. }
  7650. bi = reB.lastIndex;
  7651. }
  7652. // Add remains of b.
  7653. if (bi < b.length) {
  7654. bs = b.slice(bi);
  7655. if (s[i]) s[i] += bs; // coalesce with previous string
  7656. else s[++i] = bs;
  7657. }
  7658. // Special optimization for only a single match.
  7659. // Otherwise, interpolate each of the numbers and rejoin the string.
  7660. return s.length < 2 ? q[0] ? one(q[0].x) : zero(b) : (b = q.length, function (t) {
  7661. for (var i = 0, o; i < b; ++i) {
  7662. s[(o = q[i]).i] = o.x(t);
  7663. }
  7664. return s.join("");
  7665. });
  7666. }
  7667. function interpolate (a, b) {
  7668. var t = _typeof(b),
  7669. c;
  7670. return b == null || t === 'boolean' ? constant(b) : (t === 'number' ? interpolateNumber : t === 'string' ? (c = color(b)) ? (b = c, interpolateRgb) : string : b instanceof color ? interpolateRgb : b instanceof Date ? date : isNumberArray(b) ? interpolateNumberArray : Array.isArray(b) ? genericArray : typeof b.valueOf !== 'function' && typeof b.toString !== 'function' || isNaN(b) ? interpolateObject : interpolateNumber)(a, b);
  7671. }
  7672. function interpolateObjectArray(a, b) {
  7673. var na = a ? a.length : 0;
  7674. var nb = b ? b.length : 0;
  7675. var maxLen = Math.max(nb, na);
  7676. var c = new Array(maxLen);
  7677. var x = new Array(maxLen);
  7678. var i;
  7679. // 将a、b长度补齐后再进行插值计算
  7680. for (i = 0; i < maxLen; i++) {
  7681. var ia = i < na ? (a || [])[i] : (a || [])[na - 1];
  7682. var ib = i < nb ? (b || [])[i] : (b || [])[nb - 1];
  7683. x[i] = interpolateObject(ia, ib);
  7684. }
  7685. return function (t) {
  7686. // 清除补间的多余点
  7687. if (t >= 1) {
  7688. return b;
  7689. }
  7690. for (i = 0; i < maxLen; ++i) {
  7691. c[i] = x[i](t);
  7692. }
  7693. return c;
  7694. };
  7695. }
  7696. var interpolate$1 = (function (a, b) {
  7697. if (typeof b === 'string') {
  7698. return interpolateRgb(a, b);
  7699. }
  7700. if (Array.isArray(b)) {
  7701. if (typeof b[0] !== 'number') {
  7702. // if (hasNaN(a[0])) {
  7703. // return interpolateObjectArray(b, b);
  7704. // }
  7705. return interpolateObjectArray(a, b);
  7706. }
  7707. return interpolateNumberArray(a, b);
  7708. }
  7709. // if (isNaN(a)) {
  7710. // return interpolateNumber(b, b);
  7711. // }
  7712. return interpolateNumber(a, b);
  7713. });
  7714. // https://github.com/tweenjs/tween.js
  7715. function linear$1(k) {
  7716. return k;
  7717. }
  7718. function quadraticIn(k) {
  7719. return k * k;
  7720. }
  7721. function quadraticOut(k) {
  7722. return k * (2 - k);
  7723. }
  7724. function quadraticInOut(k) {
  7725. if ((k *= 2) < 1) {
  7726. return 0.5 * k * k;
  7727. }
  7728. return -0.5 * (--k * (k - 2) - 1);
  7729. }
  7730. function cubicIn(k) {
  7731. return k * k * k;
  7732. }
  7733. function cubicOut(k) {
  7734. return --k * k * k + 1;
  7735. }
  7736. function cubicInOut(k) {
  7737. if ((k *= 2) < 1) {
  7738. return 0.5 * k * k * k;
  7739. }
  7740. return 0.5 * ((k -= 2) * k * k + 2);
  7741. }
  7742. function quarticIn(k) {
  7743. return k * k * k * k;
  7744. }
  7745. function quarticOut(k) {
  7746. return 1 - k * k * k * k;
  7747. }
  7748. function quarticInOut(k) {
  7749. if ((k *= 2) < 1) {
  7750. return 0.5 * k * k * k * k;
  7751. }
  7752. return -0.5 * ((k -= 2) * k * k * k - 2);
  7753. }
  7754. function quinticIn(k) {
  7755. return k * k * k * k * k;
  7756. }
  7757. function quinticOut(k) {
  7758. return --k * k * k * k * k + 1;
  7759. }
  7760. function quinticInOut(k) {
  7761. if ((k *= 2) < 1) {
  7762. return 0.5 * k * k * k * k * k;
  7763. }
  7764. return 0.5 * ((k -= 2) * k * k * k * k + 2);
  7765. }
  7766. function exponentialIn(k) {
  7767. return k === 0 ? 0 : Math.pow(1024, k - 1);
  7768. }
  7769. function exponentialOut(k) {
  7770. return k === 1 ? 1 : 1 - Math.pow(2, -10 * k);
  7771. }
  7772. function elasticIn(k) {
  7773. var s;
  7774. var a = 0.1;
  7775. var p = 0.4;
  7776. if (k === 0) return 0;
  7777. if (k === 1) return 1;
  7778. if (!a || a < 1) {
  7779. a = 1;
  7780. s = p / 4;
  7781. } else {
  7782. s = p / (2 * Math.PI) * Math.asin(1 / a);
  7783. }
  7784. return -(a * Math.pow(2, 10 * (k -= 1)) * Math.sin((k - s) * (2 * Math.PI) / p));
  7785. }
  7786. function elasticOut(k) {
  7787. var s;
  7788. var a = 0.1;
  7789. var p = 0.4;
  7790. if (k === 0) return 0;
  7791. if (k === 1) return 1;
  7792. if (!a || a < 1) {
  7793. a = 1;
  7794. s = p / 4;
  7795. } else {
  7796. s = p / (2 * Math.PI) * Math.asin(1 / a);
  7797. }
  7798. return a * Math.pow(2, -10 * k) * Math.sin((k - s) * (2 * Math.PI) / p) + 1;
  7799. }
  7800. function elasticInOut(k) {
  7801. var s;
  7802. var a = 0.1;
  7803. var p = 0.4;
  7804. if (k === 0) return 0;
  7805. if (k === 1) return 1;
  7806. if (!a || a < 1) {
  7807. a = 1;
  7808. s = p / 4;
  7809. } else {
  7810. s = p / (2 * Math.PI) * Math.asin(1 / a);
  7811. }
  7812. if ((k *= 2) < 1) {
  7813. return -0.5 * (a * Math.pow(2, 10 * (k -= 1)) * Math.sin((k - s) * (2 * Math.PI) / p));
  7814. }
  7815. return a * Math.pow(2, -10 * (k -= 1)) * Math.sin((k - s) * (2 * Math.PI) / p) * 0.5 + 1;
  7816. }
  7817. function backIn(k) {
  7818. var s = 1.70158;
  7819. return k * k * ((s + 1) * k - s);
  7820. }
  7821. function backOut(k) {
  7822. var s = 1.70158;
  7823. return (k = k - 1) * k * ((s + 1) * k + s) + 1;
  7824. }
  7825. function backInOut(k) {
  7826. var s = 1.70158 * 1.525;
  7827. if ((k *= 2) < 1) {
  7828. return 0.5 * (k * k * ((s + 1) * k - s));
  7829. }
  7830. return 0.5 * ((k -= 2) * k * ((s + 1) * k + s) + 2);
  7831. }
  7832. function bounceIn(k) {
  7833. return 1 - bounceOut(1 - k);
  7834. }
  7835. function bounceOut(k) {
  7836. if ((k /= 1) < 1 / 2.75) {
  7837. return 7.5625 * k * k;
  7838. } else if (k < 2 / 2.75) {
  7839. return 7.5625 * (k -= 1.5 / 2.75) * k + 0.75;
  7840. } else if (k < 2.5 / 2.75) {
  7841. return 7.5625 * (k -= 2.25 / 2.75) * k + 0.9375;
  7842. }
  7843. return 7.5625 * (k -= 2.625 / 2.75) * k + 0.984375;
  7844. }
  7845. function bounceInOut(k) {
  7846. if (k < 0.5) {
  7847. return bounceIn(k * 2) * 0.5;
  7848. }
  7849. return bounceOut(k * 2 - 1) * 0.5 + 0.5;
  7850. }
  7851. var Easing = /*#__PURE__*/Object.freeze({
  7852. __proto__: null,
  7853. linear: linear$1,
  7854. quadraticIn: quadraticIn,
  7855. quadraticOut: quadraticOut,
  7856. quadraticInOut: quadraticInOut,
  7857. cubicIn: cubicIn,
  7858. cubicOut: cubicOut,
  7859. cubicInOut: cubicInOut,
  7860. quarticIn: quarticIn,
  7861. quarticOut: quarticOut,
  7862. quarticInOut: quarticInOut,
  7863. elasticIn: elasticIn,
  7864. elasticOut: elasticOut,
  7865. elasticInOut: elasticInOut,
  7866. backIn: backIn,
  7867. backOut: backOut,
  7868. backInOut: backInOut,
  7869. bounceIn: bounceIn,
  7870. bounceOut: bounceOut,
  7871. bounceInOut: bounceInOut,
  7872. exponentialIn: exponentialIn,
  7873. exponentialOut: exponentialOut,
  7874. quinticIn: quinticIn,
  7875. quinticOut: quinticOut,
  7876. quinticInOut: quinticInOut
  7877. });
  7878. var Animator = /*#__PURE__*/function () {
  7879. function Animator(element, animation) {
  7880. _classCallCheck(this, Animator);
  7881. // 是否是裁剪动画
  7882. this.isClip = false;
  7883. this.end = false;
  7884. this.element = element;
  7885. this.animation = animation;
  7886. var _animation$property = animation.property,
  7887. property = _animation$property === void 0 ? [] : _animation$property,
  7888. easing = animation.easing,
  7889. duration = animation.duration,
  7890. _animation$delay = animation.delay,
  7891. delay = _animation$delay === void 0 ? 0 : _animation$delay,
  7892. start = animation.start,
  7893. end = animation.end,
  7894. onFrame = animation.onFrame,
  7895. isClip = animation.isClip;
  7896. var interpolates = property.map(function (name) {
  7897. if (isString(name)) {
  7898. return interpolate$1(start[name], end[name]);
  7899. }
  7900. // @ts-ignore
  7901. if (name.interpolate) {
  7902. // @ts-ignore
  7903. return name.interpolate(start, end);
  7904. }
  7905. });
  7906. this.easing = typeof easing === 'function' ? easing : Easing[easing] || linear$1;
  7907. this.property = property;
  7908. this.interpolates = interpolates;
  7909. this.duration = duration;
  7910. this.delay = delay;
  7911. this.onFrame = onFrame;
  7912. this.totalDuration = duration + delay;
  7913. this.isClip = isClip;
  7914. // 更新到初始状态
  7915. this.update(0, 0);
  7916. }
  7917. _createClass(Animator, [{
  7918. key: "to",
  7919. value: function to(time) {
  7920. var duration = this.duration,
  7921. delay = this.delay,
  7922. totalDuration = this.totalDuration,
  7923. easing = this.easing,
  7924. end = this.end;
  7925. // 已结束
  7926. if (end) {
  7927. return;
  7928. }
  7929. // 未开始
  7930. if (time <= delay || !duration) {
  7931. return;
  7932. }
  7933. // 最大为1
  7934. var t = time >= totalDuration ? 1 : (time - delay) / duration;
  7935. this.update(easing(t), time);
  7936. // 最后一帧
  7937. if (t === 1) {
  7938. this.onEnd();
  7939. }
  7940. }
  7941. }, {
  7942. key: "update",
  7943. value: function update(t, time) {
  7944. var element = this.element,
  7945. interpolates = this.interpolates,
  7946. property = this.property,
  7947. onFrame = this.onFrame;
  7948. var attrs = {};
  7949. for (var i = property.length - 1; i >= 0; i--) {
  7950. var name = property[i];
  7951. if (isString(name)) {
  7952. attrs[name] = interpolates[i](t);
  7953. } else {
  7954. // @ts-ignore
  7955. attrs[name.name] = interpolates[i](t);
  7956. }
  7957. }
  7958. if (onFrame) {
  7959. attrs = _objectSpread(_objectSpread({}, attrs), this.onFrame(t, time));
  7960. }
  7961. element.attr(attrs);
  7962. }
  7963. }, {
  7964. key: "onEnd",
  7965. value: function onEnd() {
  7966. var animation = this.animation,
  7967. isClip = this.isClip,
  7968. element = this.element;
  7969. var onEnd = animation.onEnd;
  7970. onEnd && onEnd.call(this);
  7971. if (isClip) {
  7972. // 如果是裁剪区动画,要移除裁剪区
  7973. element.remove(true);
  7974. }
  7975. // 如果当前元素状态被标记为删除,等动画结束后直接删除
  7976. if (element._attrs.status === ELEMENT_DELETE) {
  7977. element.remove(true);
  7978. }
  7979. // 清空 不需要重复执行
  7980. element.set('animation', null);
  7981. this.end = true;
  7982. }
  7983. }]);
  7984. return Animator;
  7985. }();
  7986. // 遍历全部节点
  7987. function eachElement(element, fn) {
  7988. fn(element);
  7989. var children = element.get('children');
  7990. if (children && children.length) {
  7991. for (var i = 0, len = children.length; i < len; i++) {
  7992. var child = children[i];
  7993. eachElement(child, fn);
  7994. }
  7995. }
  7996. }
  7997. var Animation = /*#__PURE__*/function () {
  7998. function Animation(canvas) {
  7999. _classCallCheck(this, Animation);
  8000. this.timeline = new Timeline$1();
  8001. this.canvas = canvas;
  8002. }
  8003. _createClass(Animation, [{
  8004. key: "createAnimator",
  8005. value: function createAnimator(element, animation) {
  8006. var duration = animation.duration,
  8007. property = animation.property,
  8008. onFrame = animation.onFrame;
  8009. // 校验关键参数
  8010. if (!duration || (!property || !property.length) && !onFrame) {
  8011. return;
  8012. }
  8013. return new Animator(element, animation);
  8014. }
  8015. }, {
  8016. key: "play",
  8017. value: function play(container, onAnimationEnd) {
  8018. var _this = this;
  8019. var canvas = this.canvas;
  8020. var animators = [];
  8021. var maxDuration = 0;
  8022. var deleteElements = [];
  8023. // 遍历整个树,找到全部需要动画的元素
  8024. eachElement(container, function (element) {
  8025. // TODO: status 需要提取状态
  8026. var _element$_attrs = element._attrs,
  8027. animation = _element$_attrs.animation,
  8028. status = _element$_attrs.status;
  8029. if (!animation) {
  8030. if (status === ELEMENT_DELETE) {
  8031. // element.remove(true);
  8032. deleteElements.push(element);
  8033. }
  8034. return;
  8035. }
  8036. var animator = _this.createAnimator(element, animation);
  8037. if (animator) {
  8038. maxDuration = Math.max(maxDuration, animator.totalDuration);
  8039. animators.push(animator);
  8040. }
  8041. var clip = animation.clip;
  8042. // 如果有裁剪区动画,处理裁剪区动画
  8043. if (clip) {
  8044. clip.isClip = true;
  8045. var clipElement = clip.element;
  8046. var _animator = _this.createAnimator(clipElement, clip);
  8047. if (_animator) {
  8048. maxDuration = Math.max(maxDuration, _animator.totalDuration);
  8049. element.attr('clip', clipElement);
  8050. animators.push(_animator);
  8051. }
  8052. }
  8053. });
  8054. for (var i = 0, len = deleteElements.length; i < len; i++) {
  8055. var element = deleteElements[i];
  8056. var children = element._attrs.children;
  8057. // 因为group的子元素也有可能有动画,所以这里先把叶子节点删除掉,等动画结束后,再把所有删除的元素删除掉
  8058. if (!children || !children.length) {
  8059. element.remove(true);
  8060. }
  8061. }
  8062. // 开始播放动画
  8063. this.timeline.play(maxDuration, function (time) {
  8064. for (var _i = 0, _len = animators.length; _i < _len; _i++) {
  8065. var animator = animators[_i];
  8066. animator.to(time);
  8067. }
  8068. // 最后一帧放在end里统一draw, 避免重复draw
  8069. if (time < maxDuration) {
  8070. canvas.draw();
  8071. }
  8072. }, function () {
  8073. for (var _i2 = 0, _len2 = deleteElements.length; _i2 < _len2; _i2++) {
  8074. var _element = deleteElements[_i2];
  8075. _element.remove(true);
  8076. }
  8077. canvas.draw();
  8078. onAnimationEnd && onAnimationEnd();
  8079. });
  8080. }
  8081. // 直接跳到动画最终态
  8082. }, {
  8083. key: "end",
  8084. value: function end() {
  8085. this.timeline.end();
  8086. }
  8087. }, {
  8088. key: "abort",
  8089. value: function abort() {
  8090. this.timeline.abort();
  8091. }
  8092. }]);
  8093. return Animation;
  8094. }();
  8095. function measureText$2(canvas, px2hd) {
  8096. return function (text, font) {
  8097. var _ref = font || {},
  8098. fontSize = _ref.fontSize,
  8099. fontFamily = _ref.fontFamily,
  8100. fontStyle = _ref.fontStyle,
  8101. fontWeight = _ref.fontWeight,
  8102. fontVariant = _ref.fontVariant;
  8103. var shape = canvas.addShape('text', {
  8104. attrs: {
  8105. x: 0,
  8106. y: 0,
  8107. fontSize: px2hd(fontSize),
  8108. fontFamily: fontFamily,
  8109. fontStyle: fontStyle,
  8110. fontWeight: fontWeight,
  8111. fontVariant: fontVariant,
  8112. text: text
  8113. }
  8114. });
  8115. var _shape$getBBox = shape.getBBox(),
  8116. width = _shape$getBBox.width,
  8117. height = _shape$getBBox.height;
  8118. shape.remove(true);
  8119. return {
  8120. width: width,
  8121. height: height
  8122. };
  8123. };
  8124. }
  8125. // 顶层Canvas标签
  8126. var Canvas$1 = /*#__PURE__*/function (_Component) {
  8127. _inherits(Canvas, _Component);
  8128. var _super = _createSuper(Canvas);
  8129. function Canvas(props) {
  8130. var _this;
  8131. _classCallCheck(this, Canvas);
  8132. _this = _super.call(this, props);
  8133. var context = props.context,
  8134. pixelRatio = props.pixelRatio,
  8135. width = props.width,
  8136. height = props.height,
  8137. _props$animate = props.animate,
  8138. animate = _props$animate === void 0 ? true : _props$animate,
  8139. customPx2hd = props.px2hd,
  8140. customTheme = props.theme,
  8141. customStyle = props.style,
  8142. createImage = props.createImage,
  8143. landscape = props.landscape;
  8144. var px2hd$1 = isFunction(customPx2hd) ? batch2hd(customPx2hd) : px2hd;
  8145. var theme = px2hd$1(deepMix({}, Theme, customTheme));
  8146. // 创建G的canvas
  8147. var canvas = createCanvas({
  8148. context: context,
  8149. pixelRatio: pixelRatio,
  8150. fontFamily: theme.fontFamily,
  8151. width: width,
  8152. height: height,
  8153. createImage: createImage,
  8154. landscape: landscape
  8155. });
  8156. // 组件更新器
  8157. var updater = createUpdater(_assertThisInitialized(_this));
  8158. // 供全局使用的一些变量
  8159. var componentContext = {
  8160. root: _assertThisInitialized(_this),
  8161. canvas: canvas,
  8162. theme: theme,
  8163. px2hd: px2hd$1,
  8164. measureText: measureText$2(canvas, px2hd$1)
  8165. };
  8166. // 动画模块
  8167. var animation = new Animation(canvas);
  8168. _this.canvas = canvas;
  8169. _this.container = canvas;
  8170. _this.context = componentContext;
  8171. _this.updater = updater;
  8172. _this.animate = animate;
  8173. _this.animation = animation;
  8174. _this.theme = theme;
  8175. _this._ee = new EventEmitter();
  8176. _this.updateLayout(props);
  8177. return _this;
  8178. }
  8179. _createClass(Canvas, [{
  8180. key: "renderComponents",
  8181. value: function renderComponents(components) {
  8182. if (!components || !components.length) {
  8183. return;
  8184. }
  8185. renderComponent(components);
  8186. this.draw();
  8187. }
  8188. }, {
  8189. key: "update",
  8190. value: function update(nextProps) {
  8191. var props = this.props;
  8192. if (equal(nextProps, props)) {
  8193. return;
  8194. }
  8195. this.props = nextProps;
  8196. this.render();
  8197. }
  8198. }, {
  8199. key: "resize",
  8200. value: function resize(width, height) {
  8201. var _this$canvas$_attrs = this.canvas._attrs,
  8202. canvasWidth = _this$canvas$_attrs.width,
  8203. canvasHeight = _this$canvas$_attrs.height;
  8204. this.canvas.changeSize(width || canvasWidth, height || canvasHeight);
  8205. // this.canvas.clear();
  8206. // this.children = null;
  8207. this.updateLayout(_objectSpread(_objectSpread({}, this.props), {}, {
  8208. width: width,
  8209. height: height
  8210. }));
  8211. this.render();
  8212. }
  8213. }, {
  8214. key: "updateLayout",
  8215. value: function updateLayout(props) {
  8216. var _this$canvas$_attrs2 = this.canvas._attrs,
  8217. canvasWidth = _this$canvas$_attrs2.width,
  8218. canvasHeight = _this$canvas$_attrs2.height;
  8219. var style = this.context.px2hd(_objectSpread({
  8220. left: 0,
  8221. top: 0,
  8222. width: (props === null || props === void 0 ? void 0 : props.width) || canvasWidth,
  8223. height: (props === null || props === void 0 ? void 0 : props.height) || canvasHeight,
  8224. padding: this.theme.padding
  8225. }, props.style));
  8226. this.layout = Layout.fromStyle(style);
  8227. this.context = _objectSpread(_objectSpread({}, this.context), {}, {
  8228. left: this.layout.left,
  8229. top: this.layout.top,
  8230. width: this.layout.width,
  8231. height: this.layout.height
  8232. });
  8233. }
  8234. }, {
  8235. key: "draw",
  8236. value: function draw() {
  8237. var canvas = this.canvas,
  8238. animate = this.animate;
  8239. if (animate === false) {
  8240. canvas.draw();
  8241. return;
  8242. }
  8243. this.play();
  8244. }
  8245. }, {
  8246. key: "play",
  8247. value: function play() {
  8248. var _this2 = this;
  8249. var canvas = this.canvas,
  8250. animation = this.animation;
  8251. // 执行动画
  8252. animation.abort();
  8253. animation.play(canvas, function () {
  8254. _this2.emit('animationEnd');
  8255. });
  8256. }
  8257. }, {
  8258. key: "render",
  8259. value: function render() {
  8260. var lastChildren = this.children,
  8261. props = this.props;
  8262. var nextChildren = props.children;
  8263. renderChildren(this, nextChildren, lastChildren);
  8264. this.draw();
  8265. return null;
  8266. }
  8267. }, {
  8268. key: "destroy",
  8269. value: function destroy() {
  8270. var canvas = this.canvas,
  8271. children = this.children;
  8272. destroyElement(children);
  8273. canvas.destroy();
  8274. }
  8275. }, {
  8276. key: "on",
  8277. value: function on(type, listener) {
  8278. this._ee.on(type, listener);
  8279. }
  8280. }, {
  8281. key: "emit",
  8282. value: function emit(type, event) {
  8283. this._ee.emit(type, event);
  8284. }
  8285. }, {
  8286. key: "off",
  8287. value: function off(type, listener) {
  8288. this._ee.off(type, listener);
  8289. }
  8290. }]);
  8291. return Canvas;
  8292. }(Component);
  8293. var LayoutController = /*#__PURE__*/function () {
  8294. function LayoutController() {
  8295. _classCallCheck(this, LayoutController);
  8296. }
  8297. _createClass(LayoutController, [{
  8298. key: "getRectRange",
  8299. value: function getRectRange(style) {
  8300. var left = style.left,
  8301. top = style.top,
  8302. width = style.width,
  8303. height = style.height,
  8304. padding = style.padding;
  8305. var _padding = _slicedToArray(padding, 4),
  8306. paddingTop = _padding[0],
  8307. paddingRight = _padding[1],
  8308. paddingBottom = _padding[2],
  8309. paddingLeft = _padding[3];
  8310. return {
  8311. left: left + paddingLeft,
  8312. top: top + paddingTop,
  8313. width: width - paddingLeft - paddingRight,
  8314. height: height - paddingTop - paddingBottom
  8315. };
  8316. }
  8317. }, {
  8318. key: "create",
  8319. value: function create(style) {
  8320. var rectRange = this.getRectRange(style);
  8321. var layout = new Layout(rectRange);
  8322. this.layout = layout;
  8323. return layout;
  8324. }
  8325. }, {
  8326. key: "update",
  8327. value: function update(style) {
  8328. var rectRange = this.getRectRange(style);
  8329. var layout = this.layout;
  8330. layout.update(rectRange);
  8331. return layout;
  8332. }
  8333. }]);
  8334. return LayoutController;
  8335. }();
  8336. var superPropBase = createCommonjsModule(function (module) {
  8337. function _superPropBase(object, property) {
  8338. while (!Object.prototype.hasOwnProperty.call(object, property)) {
  8339. object = getPrototypeOf(object);
  8340. if (object === null) break;
  8341. }
  8342. return object;
  8343. }
  8344. module.exports = _superPropBase, module.exports.__esModule = true, module.exports["default"] = module.exports;
  8345. });
  8346. var get$1 = createCommonjsModule(function (module) {
  8347. function _get() {
  8348. if (typeof Reflect !== "undefined" && Reflect.get) {
  8349. module.exports = _get = Reflect.get.bind(), module.exports.__esModule = true, module.exports["default"] = module.exports;
  8350. } else {
  8351. module.exports = _get = function _get(target, property, receiver) {
  8352. var base = superPropBase(target, property);
  8353. if (!base) return;
  8354. var desc = Object.getOwnPropertyDescriptor(base, property);
  8355. if (desc.get) {
  8356. return desc.get.call(arguments.length < 3 ? target : receiver);
  8357. }
  8358. return desc.value;
  8359. }, module.exports.__esModule = true, module.exports["default"] = module.exports;
  8360. }
  8361. return _get.apply(this, arguments);
  8362. }
  8363. module.exports = _get, module.exports.__esModule = true, module.exports["default"] = module.exports;
  8364. });
  8365. var _get$1 = /*@__PURE__*/getDefaultExportFromCjs(get$1);
  8366. function transposedRect(_ref) {
  8367. var xMin = _ref.xMin,
  8368. xMax = _ref.xMax,
  8369. yMin = _ref.yMin,
  8370. yMax = _ref.yMax;
  8371. return {
  8372. xMin: yMin,
  8373. xMax: yMax,
  8374. yMin: xMin,
  8375. yMax: xMax
  8376. };
  8377. }
  8378. function _convertRect(_ref2) {
  8379. var x = _ref2.x,
  8380. y = _ref2.y,
  8381. size = _ref2.size,
  8382. y0 = _ref2.y0;
  8383. var xMin;
  8384. var xMax;
  8385. if (isArray(x)) {
  8386. xMin = x[0];
  8387. xMax = x[1];
  8388. } else {
  8389. xMin = x - size / 2;
  8390. xMax = x + size / 2;
  8391. }
  8392. var yMin;
  8393. var yMax;
  8394. if (isArray(y)) {
  8395. yMin = y[0];
  8396. yMax = y[1];
  8397. } else {
  8398. yMin = Math.min(y0, y);
  8399. yMax = Math.max(y0, y);
  8400. }
  8401. return {
  8402. xMin: xMin,
  8403. xMax: xMax,
  8404. yMin: yMin,
  8405. yMax: yMax
  8406. };
  8407. }
  8408. /**
  8409. * 直角坐标系
  8410. * convert相关的方法,涉及将标准坐标系映射到实际坐标系内
  8411. * transform相关的方法,是仅将某一种关键点转换成另一种关键点 (比如将x/y/size/y0转换成yMin/yMax/..)
  8412. */
  8413. var Base = /*#__PURE__*/function (_Layout) {
  8414. _inherits(Base, _Layout);
  8415. var _super = _createSuper(Base);
  8416. function Base(option) {
  8417. var _this;
  8418. _classCallCheck(this, Base);
  8419. _this = _super.call(this, option);
  8420. // x y 调换
  8421. _this.transposed = false;
  8422. // x,y 的值域,在极坐标中对应的就是弧度和半径
  8423. _this.x = [0, 1];
  8424. _this.y = [0, 1];
  8425. _this.update(option);
  8426. return _this;
  8427. }
  8428. _createClass(Base, [{
  8429. key: "update",
  8430. value: function update(option) {
  8431. _get$1(_getPrototypeOf(Base.prototype), "update", this).call(this, option);
  8432. var left = this.left,
  8433. top = this.top,
  8434. width = this.width,
  8435. height = this.height;
  8436. this.center = {
  8437. x: left + width / 2,
  8438. y: top + height / 2
  8439. };
  8440. return this;
  8441. }
  8442. // 是循环, 比如极坐标是以 2π 循环的
  8443. }, {
  8444. key: "isCyclic",
  8445. value: function isCyclic() {
  8446. return false;
  8447. }
  8448. }, {
  8449. key: "_zoomVal",
  8450. value: function _zoomVal(val, func) {
  8451. return isArray(val) ? val.map(function (v) {
  8452. return func(v);
  8453. }) : func(val);
  8454. }
  8455. /**
  8456. * 把归一后的值映射到对应的定义域
  8457. * @param point
  8458. */
  8459. }, {
  8460. key: "convert",
  8461. value: function convert(point) {
  8462. var transposed = this.transposed,
  8463. x = this.x,
  8464. y = this.y;
  8465. var xDim = transposed ? 'y' : 'x';
  8466. var yDim = transposed ? 'x' : 'y';
  8467. var pointX = point[xDim];
  8468. var pointY = point[yDim];
  8469. // 超出边界不绘制
  8470. if (pointX < 0 || pointX > 1 || pointY < 0 || pointY > 1) {
  8471. return {
  8472. x: NaN,
  8473. y: NaN
  8474. };
  8475. }
  8476. return {
  8477. x: this._zoomVal(point[xDim], function (v) {
  8478. return x[0] + (x[1] - x[0]) * v;
  8479. }),
  8480. y: this._zoomVal(point[yDim], function (v) {
  8481. return y[0] + (y[1] - y[0]) * v;
  8482. })
  8483. };
  8484. }
  8485. /**
  8486. * convert 的反处理,把定义域的值,反处理到归一的值
  8487. */
  8488. }, {
  8489. key: "invert",
  8490. value: function invert(point) {
  8491. var _ref3;
  8492. var transposed = this.transposed,
  8493. x = this.x,
  8494. y = this.y;
  8495. var xDim = transposed ? 'y' : 'x';
  8496. var yDim = transposed ? 'x' : 'y';
  8497. return _ref3 = {}, _defineProperty(_ref3, xDim, this._zoomVal(point.x, function (v) {
  8498. return (v - x[0]) / (x[1] - x[0]);
  8499. })), _defineProperty(_ref3, yDim, this._zoomVal(point.y, function (v) {
  8500. return (v - y[0]) / (y[1] - y[0]);
  8501. })), _ref3;
  8502. }
  8503. /**
  8504. * 把归一化的值映射到 canvas 的坐标点
  8505. * @param point
  8506. * @returns
  8507. */
  8508. }, {
  8509. key: "convertPoint",
  8510. value: function convertPoint(point) {
  8511. return this.convert(point);
  8512. }
  8513. /**
  8514. * 把canvas坐标的点位映射回归一的值
  8515. */
  8516. }, {
  8517. key: "invertPoint",
  8518. value: function invertPoint(point) {
  8519. return this.invert(point);
  8520. }
  8521. // 将标准坐标系下的矩形绘制关键点映射成实际绘制的坐标点
  8522. }, {
  8523. key: "convertRect",
  8524. value: function convertRect(rectPoint) {
  8525. var xRange = this.x,
  8526. yRange = this.y,
  8527. transposed = this.transposed;
  8528. var _xRange = _slicedToArray(xRange, 2),
  8529. xStart = _xRange[0],
  8530. xEnd = _xRange[1];
  8531. var _yRange = _slicedToArray(yRange, 2),
  8532. yStart = _yRange[0],
  8533. yEnd = _yRange[1];
  8534. var rect = _convertRect(rectPoint);
  8535. var _ref4 = transposed ? transposedRect(rect) : rect,
  8536. xMin = _ref4.xMin,
  8537. xMax = _ref4.xMax,
  8538. yMin = _ref4.yMin,
  8539. yMax = _ref4.yMax;
  8540. var x0 = xStart + (xEnd - xStart) * xMin;
  8541. var x1 = xStart + (xEnd - xStart) * xMax;
  8542. var y0 = yStart + (yEnd - yStart) * yMin;
  8543. var y1 = yStart + (yEnd - yStart) * yMax;
  8544. return {
  8545. xMin: Math.min(x0, x1),
  8546. xMax: Math.max(x0, x1),
  8547. yMin: Math.min(y0, y1),
  8548. yMax: Math.max(y0, y1)
  8549. };
  8550. }
  8551. // 将已经映射好的矩形绘制关键点转换成实际绘制的坐标点
  8552. }, {
  8553. key: "transformToRect",
  8554. value: function transformToRect(rectPoint) {
  8555. var x = rectPoint.x,
  8556. y = rectPoint.y,
  8557. y0 = rectPoint.y0,
  8558. size = rectPoint.size;
  8559. var coordOrigin = this.convertPoint({
  8560. x: 0,
  8561. y: y0
  8562. });
  8563. var transposed = this.transposed;
  8564. var _rectPoint = {
  8565. size: size,
  8566. x: transposed ? y : x,
  8567. y: transposed ? x : y,
  8568. y0: transposed ? coordOrigin.x : coordOrigin.y
  8569. };
  8570. var rect = _convertRect(_rectPoint);
  8571. var _ref5 = transposed ? transposedRect(rect) : rect,
  8572. xMin = _ref5.xMin,
  8573. xMax = _ref5.xMax,
  8574. yMin = _ref5.yMin,
  8575. yMax = _ref5.yMax;
  8576. return {
  8577. xMin: xMin,
  8578. xMax: xMax,
  8579. yMin: yMin,
  8580. yMax: yMax
  8581. };
  8582. }
  8583. }]);
  8584. return Base;
  8585. }(Layout);
  8586. var Rect$2 = /*#__PURE__*/function (_Base) {
  8587. _inherits(Rect, _Base);
  8588. var _super = _createSuper(Rect);
  8589. function Rect() {
  8590. var _this;
  8591. _classCallCheck(this, Rect);
  8592. _this = _super.apply(this, arguments);
  8593. _this.type = 'rect';
  8594. return _this;
  8595. }
  8596. _createClass(Rect, [{
  8597. key: "update",
  8598. value: function update(option) {
  8599. _get$1(_getPrototypeOf(Rect.prototype), "update", this).call(this, option);
  8600. var left = this.left,
  8601. top = this.top,
  8602. right = this.right,
  8603. bottom = this.bottom;
  8604. var x = [left, right];
  8605. var y = [bottom, top];
  8606. this.x = x;
  8607. this.y = y;
  8608. return this;
  8609. }
  8610. }]);
  8611. return Rect;
  8612. }(Base);
  8613. var Polar = /*#__PURE__*/function (_Base) {
  8614. _inherits(Polar, _Base);
  8615. var _super = _createSuper(Polar);
  8616. function Polar() {
  8617. var _this;
  8618. _classCallCheck(this, Polar);
  8619. _this = _super.apply(this, arguments);
  8620. _this.type = 'polar';
  8621. _this.isPolar = true;
  8622. return _this;
  8623. }
  8624. _createClass(Polar, [{
  8625. key: "update",
  8626. value: function update(option) {
  8627. _get$1(_getPrototypeOf(Polar.prototype), "update", this).call(this, option);
  8628. if (!this.option) {
  8629. this.option = option;
  8630. }
  8631. var _this$option = this.option,
  8632. _this$option$radius = _this$option.radius,
  8633. radiusRatio = _this$option$radius === void 0 ? 1 : _this$option$radius,
  8634. _this$option$innerRad = _this$option.innerRadius,
  8635. innerRadiusRatio = _this$option$innerRad === void 0 ? 0 : _this$option$innerRad;
  8636. var width = this.width,
  8637. height = this.height,
  8638. _this$startAngle = this.startAngle,
  8639. startAngle = _this$startAngle === void 0 ? -Math.PI / 2 : _this$startAngle,
  8640. _this$endAngle = this.endAngle,
  8641. endAngle = _this$endAngle === void 0 ? Math.PI * 3 / 2 : _this$endAngle;
  8642. // 半径取宽高的最小值
  8643. var radius = radiusRatio * (Math.min(width, height) / 2);
  8644. // 极坐标下 x 表示弧度, y 代表 半径
  8645. var x = [startAngle, endAngle];
  8646. var y = [innerRadiusRatio * radius, radius];
  8647. this.x = x;
  8648. this.y = y;
  8649. this.startAngle = startAngle;
  8650. this.endAngle = endAngle;
  8651. this.radius = radius;
  8652. this.innnerRadius = innerRadiusRatio * radius;
  8653. return this;
  8654. }
  8655. }, {
  8656. key: "isCyclic",
  8657. value: function isCyclic() {
  8658. var startAngle = this.startAngle,
  8659. endAngle = this.endAngle;
  8660. if (endAngle - startAngle < Math.PI * 2) {
  8661. return false;
  8662. }
  8663. return true;
  8664. }
  8665. }, {
  8666. key: "convertPoint",
  8667. value: function convertPoint(point) {
  8668. var center = this.center,
  8669. transposed = this.transposed,
  8670. x = this.x,
  8671. y = this.y;
  8672. var xDim = transposed ? 'y' : 'x';
  8673. var yDim = transposed ? 'x' : 'y';
  8674. var _x = _slicedToArray(x, 2),
  8675. xStart = _x[0],
  8676. xEnd = _x[1];
  8677. var _y = _slicedToArray(y, 2),
  8678. yStart = _y[0],
  8679. yEnd = _y[1];
  8680. var angle = xStart + (xEnd - xStart) * point[xDim];
  8681. var radius = yStart + (yEnd - yStart) * point[yDim];
  8682. return {
  8683. x: center.x + Math.cos(angle) * radius,
  8684. y: center.y + Math.sin(angle) * radius
  8685. };
  8686. }
  8687. }, {
  8688. key: "invertPoint",
  8689. value: function invertPoint(point) {
  8690. var center = this.center,
  8691. transposed = this.transposed,
  8692. x = this.x,
  8693. y = this.y;
  8694. var xDim = transposed ? 'y' : 'x';
  8695. var yDim = transposed ? 'x' : 'y';
  8696. var _x2 = _slicedToArray(x, 2),
  8697. xStart = _x2[0],
  8698. xEnd = _x2[1];
  8699. var _y2 = _slicedToArray(y, 2),
  8700. yStart = _y2[0],
  8701. yEnd = _y2[1];
  8702. var m = [1, 0, 0, 1, 0, 0];
  8703. Matrix.rotate(m, m, xStart);
  8704. var startV = [1, 0];
  8705. Vector2.transformMat2d(startV, startV, m);
  8706. startV = [startV[0], startV[1]];
  8707. var pointV = [point.x - center.x, point.y - center.y];
  8708. if (Vector2.zero(pointV)) {
  8709. return {
  8710. x: 0,
  8711. y: 0
  8712. };
  8713. }
  8714. var theta = Vector2.angleTo(startV, pointV, xEnd < xStart);
  8715. if (Math.abs(theta - Math.PI * 2) < 0.001) {
  8716. theta = 0;
  8717. }
  8718. var l = Vector2.length(pointV);
  8719. var percentX = theta / (xEnd - xStart);
  8720. percentX = xEnd - xStart > 0 ? percentX : -percentX;
  8721. var percentY = (l - yStart) / (yEnd - yStart);
  8722. var rst = {};
  8723. rst[xDim] = percentX;
  8724. rst[yDim] = percentY;
  8725. return rst;
  8726. }
  8727. }]);
  8728. return Polar;
  8729. }(Base);
  8730. var coordMap = {
  8731. rect: Rect$2,
  8732. polar: Polar
  8733. };
  8734. var coordController = /*#__PURE__*/function () {
  8735. function coordController() {
  8736. _classCallCheck(this, coordController);
  8737. }
  8738. _createClass(coordController, [{
  8739. key: "getOption",
  8740. value: function getOption(cfg) {
  8741. if (isString(cfg)) {
  8742. return {
  8743. type: coordMap[cfg] || Rect$2
  8744. };
  8745. }
  8746. if (isFunction(cfg)) {
  8747. return {
  8748. type: cfg
  8749. };
  8750. }
  8751. var _ref = cfg || {},
  8752. type = _ref.type;
  8753. return _objectSpread(_objectSpread({}, cfg), {}, {
  8754. // 默认直角坐标系
  8755. type: isFunction(type) ? type : coordMap[type] || Rect$2
  8756. });
  8757. }
  8758. }, {
  8759. key: "create",
  8760. value: function create(cfg, layout) {
  8761. var option = this.getOption(cfg);
  8762. var type = option.type;
  8763. var coord = new type(_objectSpread(_objectSpread({}, option), layout));
  8764. this.coord = coord;
  8765. return coord;
  8766. }
  8767. }, {
  8768. key: "updateLayout",
  8769. value: function updateLayout(layout) {
  8770. this.coord.update(layout);
  8771. }
  8772. }, {
  8773. key: "update",
  8774. value: function update() {}
  8775. }]);
  8776. return coordController;
  8777. }();
  8778. var methodCache = {};
  8779. /**
  8780. * 获取计算 ticks 的方法
  8781. * @param key 键值
  8782. * @returns 计算 ticks 的方法
  8783. */
  8784. function getTickMethod(key) {
  8785. return methodCache[key];
  8786. }
  8787. /**
  8788. * 注册计算 ticks 的方法
  8789. * @param key 键值
  8790. * @param method 方法
  8791. */
  8792. function registerTickMethod(key, method) {
  8793. methodCache[key] = method;
  8794. }
  8795. var Scale = /** @class */ (function () {
  8796. function Scale(cfg) {
  8797. /**
  8798. * 度量的类型
  8799. */
  8800. this.type = 'base';
  8801. /**
  8802. * 是否分类类型的度量
  8803. */
  8804. this.isCategory = false;
  8805. /**
  8806. * 是否线性度量,有linear, time 度量
  8807. */
  8808. this.isLinear = false;
  8809. /**
  8810. * 是否连续类型的度量,linear,time,log, pow, quantile, quantize 都支持
  8811. */
  8812. this.isContinuous = false;
  8813. /**
  8814. * 是否是常量的度量,传入和传出一致
  8815. */
  8816. this.isIdentity = false;
  8817. this.values = [];
  8818. this.range = [0, 1];
  8819. this.ticks = [];
  8820. this.__cfg__ = cfg;
  8821. this.initCfg();
  8822. this.init();
  8823. }
  8824. // 对于原始值的必要转换,如分类、时间字段需转换成数值,用transform/map命名可能更好
  8825. Scale.prototype.translate = function (v) {
  8826. return v;
  8827. };
  8828. /** 重新初始化 */
  8829. Scale.prototype.change = function (cfg) {
  8830. // 覆盖配置项,而不替代
  8831. mix(this.__cfg__, cfg);
  8832. this.init();
  8833. };
  8834. Scale.prototype.clone = function () {
  8835. return this.constructor(this.__cfg__);
  8836. };
  8837. /** 获取坐标轴需要的ticks */
  8838. Scale.prototype.getTicks = function () {
  8839. var _this = this;
  8840. return map(this.ticks, function (tick, idx) {
  8841. if (isObject(tick)) {
  8842. // 仅当符合Tick类型时才有意义
  8843. return tick;
  8844. }
  8845. return {
  8846. text: _this.getText(tick, idx),
  8847. tickValue: tick,
  8848. value: _this.scale(tick),
  8849. };
  8850. });
  8851. };
  8852. /** 获取Tick的格式化结果 */
  8853. Scale.prototype.getText = function (value, key) {
  8854. var formatter = this.formatter;
  8855. var res = formatter ? formatter(value, key) : value;
  8856. if (isNil(res) || !isFunction(res.toString)) {
  8857. return '';
  8858. }
  8859. return res.toString();
  8860. };
  8861. // 获取配置项中的值,当前 scale 上的值可能会被修改
  8862. Scale.prototype.getConfig = function (key) {
  8863. return this.__cfg__[key];
  8864. };
  8865. // scale初始化
  8866. Scale.prototype.init = function () {
  8867. mix(this, this.__cfg__);
  8868. this.setDomain();
  8869. if (isEmpty(this.getConfig('ticks'))) {
  8870. this.ticks = this.calculateTicks();
  8871. }
  8872. };
  8873. // 子类上覆盖某些属性,不能直接在类上声明,否则会被覆盖
  8874. Scale.prototype.initCfg = function () { };
  8875. Scale.prototype.setDomain = function () { };
  8876. Scale.prototype.calculateTicks = function () {
  8877. var tickMethod = this.tickMethod;
  8878. var ticks = [];
  8879. if (isString(tickMethod)) {
  8880. var method = getTickMethod(tickMethod);
  8881. if (!method) {
  8882. throw new Error('There is no method to to calculate ticks!');
  8883. }
  8884. ticks = method(this);
  8885. }
  8886. else if (isFunction(tickMethod)) {
  8887. ticks = tickMethod(this);
  8888. }
  8889. return ticks;
  8890. };
  8891. // range 的最小值
  8892. Scale.prototype.rangeMin = function () {
  8893. return this.range[0];
  8894. };
  8895. // range 的最大值
  8896. Scale.prototype.rangeMax = function () {
  8897. return this.range[1];
  8898. };
  8899. /** 定义域转 0~1 */
  8900. Scale.prototype.calcPercent = function (value, min, max) {
  8901. if (isNumber(value)) {
  8902. return (value - min) / (max - min);
  8903. }
  8904. return NaN;
  8905. };
  8906. /** 0~1转定义域 */
  8907. Scale.prototype.calcValue = function (percent, min, max) {
  8908. return min + percent * (max - min);
  8909. };
  8910. return Scale;
  8911. }());
  8912. /**
  8913. * 分类度量
  8914. * @class
  8915. */
  8916. var Category = /** @class */ (function (_super) {
  8917. __extends(Category, _super);
  8918. function Category() {
  8919. var _this = _super !== null && _super.apply(this, arguments) || this;
  8920. _this.type = 'cat';
  8921. _this.isCategory = true;
  8922. return _this;
  8923. }
  8924. Category.prototype.buildIndexMap = function () {
  8925. if (!this.translateIndexMap) {
  8926. this.translateIndexMap = new Map();
  8927. // 重新构建缓存
  8928. for (var i = 0; i < this.values.length; i++) {
  8929. this.translateIndexMap.set(this.values[i], i);
  8930. }
  8931. }
  8932. };
  8933. Category.prototype.translate = function (value) {
  8934. // 按需构建 map
  8935. this.buildIndexMap();
  8936. // 找得到
  8937. var idx = this.translateIndexMap.get(value);
  8938. if (idx === undefined) {
  8939. idx = isNumber(value) ? value : NaN;
  8940. }
  8941. return idx;
  8942. };
  8943. Category.prototype.scale = function (value) {
  8944. var order = this.translate(value);
  8945. // 分类数据允许 0.5 范围内调整
  8946. // if (order < this.min - 0.5 || order > this.max + 0.5) {
  8947. // return NaN;
  8948. // }
  8949. var percent = this.calcPercent(order, this.min, this.max);
  8950. return this.calcValue(percent, this.rangeMin(), this.rangeMax());
  8951. };
  8952. Category.prototype.invert = function (scaledValue) {
  8953. var domainRange = this.max - this.min;
  8954. var percent = this.calcPercent(scaledValue, this.rangeMin(), this.rangeMax());
  8955. var idx = Math.round(domainRange * percent) + this.min;
  8956. if (idx < this.min || idx > this.max) {
  8957. return NaN;
  8958. }
  8959. return this.values[idx];
  8960. };
  8961. Category.prototype.getText = function (value) {
  8962. var args = [];
  8963. for (var _i = 1; _i < arguments.length; _i++) {
  8964. args[_i - 1] = arguments[_i];
  8965. }
  8966. var v = value;
  8967. // value为index
  8968. if (isNumber(value) && !this.values.includes(value)) {
  8969. v = this.values[v];
  8970. }
  8971. return _super.prototype.getText.apply(this, __spreadArrays([v], args));
  8972. };
  8973. // 复写属性
  8974. Category.prototype.initCfg = function () {
  8975. this.tickMethod = 'cat';
  8976. };
  8977. // 设置 min, max
  8978. Category.prototype.setDomain = function () {
  8979. // 用户有可能设置 min
  8980. if (isNil(this.getConfig('min'))) {
  8981. this.min = 0;
  8982. }
  8983. if (isNil(this.getConfig('max'))) {
  8984. var size = this.values.length;
  8985. this.max = size > 1 ? size - 1 : size;
  8986. }
  8987. // scale.init 的时候清除缓存
  8988. if (this.translateIndexMap) {
  8989. this.translateIndexMap = undefined;
  8990. }
  8991. };
  8992. return Category;
  8993. }(Scale));
  8994. var token = /d{1,4}|M{1,4}|YY(?:YY)?|S{1,3}|Do|ZZ|Z|([HhMsDm])\1?|[aA]|"[^"]*"|'[^']*'/g;
  8995. var twoDigitsOptional = "\\d\\d?";
  8996. var twoDigits = "\\d\\d";
  8997. var threeDigits = "\\d{3}";
  8998. var fourDigits = "\\d{4}";
  8999. var word = "[^\\s]+";
  9000. var literal = /\[([^]*?)\]/gm;
  9001. function shorten(arr, sLen) {
  9002. var newArr = [];
  9003. for (var i = 0, len = arr.length; i < len; i++) {
  9004. newArr.push(arr[i].substr(0, sLen));
  9005. }
  9006. return newArr;
  9007. }
  9008. var monthUpdate = function (arrName) { return function (v, i18n) {
  9009. var lowerCaseArr = i18n[arrName].map(function (v) { return v.toLowerCase(); });
  9010. var index = lowerCaseArr.indexOf(v.toLowerCase());
  9011. if (index > -1) {
  9012. return index;
  9013. }
  9014. return null;
  9015. }; };
  9016. function assign(origObj) {
  9017. var args = [];
  9018. for (var _i = 1; _i < arguments.length; _i++) {
  9019. args[_i - 1] = arguments[_i];
  9020. }
  9021. for (var _a = 0, args_1 = args; _a < args_1.length; _a++) {
  9022. var obj = args_1[_a];
  9023. for (var key in obj) {
  9024. // @ts-ignore ex
  9025. origObj[key] = obj[key];
  9026. }
  9027. }
  9028. return origObj;
  9029. }
  9030. var dayNames = [
  9031. "Sunday",
  9032. "Monday",
  9033. "Tuesday",
  9034. "Wednesday",
  9035. "Thursday",
  9036. "Friday",
  9037. "Saturday"
  9038. ];
  9039. var monthNames = [
  9040. "January",
  9041. "February",
  9042. "March",
  9043. "April",
  9044. "May",
  9045. "June",
  9046. "July",
  9047. "August",
  9048. "September",
  9049. "October",
  9050. "November",
  9051. "December"
  9052. ];
  9053. var monthNamesShort = shorten(monthNames, 3);
  9054. var dayNamesShort = shorten(dayNames, 3);
  9055. var defaultI18n = {
  9056. dayNamesShort: dayNamesShort,
  9057. dayNames: dayNames,
  9058. monthNamesShort: monthNamesShort,
  9059. monthNames: monthNames,
  9060. amPm: ["am", "pm"],
  9061. DoFn: function (dayOfMonth) {
  9062. return (dayOfMonth +
  9063. ["th", "st", "nd", "rd"][dayOfMonth % 10 > 3
  9064. ? 0
  9065. : ((dayOfMonth - (dayOfMonth % 10) !== 10 ? 1 : 0) * dayOfMonth) % 10]);
  9066. }
  9067. };
  9068. var globalI18n = assign({}, defaultI18n);
  9069. var setGlobalDateI18n = function (i18n) {
  9070. return (globalI18n = assign(globalI18n, i18n));
  9071. };
  9072. var regexEscape = function (str) {
  9073. return str.replace(/[|\\{()[^$+*?.-]/g, "\\$&");
  9074. };
  9075. var pad = function (val, len) {
  9076. if (len === void 0) { len = 2; }
  9077. val = String(val);
  9078. while (val.length < len) {
  9079. val = "0" + val;
  9080. }
  9081. return val;
  9082. };
  9083. var formatFlags = {
  9084. D: function (dateObj) { return String(dateObj.getDate()); },
  9085. DD: function (dateObj) { return pad(dateObj.getDate()); },
  9086. Do: function (dateObj, i18n) {
  9087. return i18n.DoFn(dateObj.getDate());
  9088. },
  9089. d: function (dateObj) { return String(dateObj.getDay()); },
  9090. dd: function (dateObj) { return pad(dateObj.getDay()); },
  9091. ddd: function (dateObj, i18n) {
  9092. return i18n.dayNamesShort[dateObj.getDay()];
  9093. },
  9094. dddd: function (dateObj, i18n) {
  9095. return i18n.dayNames[dateObj.getDay()];
  9096. },
  9097. M: function (dateObj) { return String(dateObj.getMonth() + 1); },
  9098. MM: function (dateObj) { return pad(dateObj.getMonth() + 1); },
  9099. MMM: function (dateObj, i18n) {
  9100. return i18n.monthNamesShort[dateObj.getMonth()];
  9101. },
  9102. MMMM: function (dateObj, i18n) {
  9103. return i18n.monthNames[dateObj.getMonth()];
  9104. },
  9105. YY: function (dateObj) {
  9106. return pad(String(dateObj.getFullYear()), 4).substr(2);
  9107. },
  9108. YYYY: function (dateObj) { return pad(dateObj.getFullYear(), 4); },
  9109. h: function (dateObj) { return String(dateObj.getHours() % 12 || 12); },
  9110. hh: function (dateObj) { return pad(dateObj.getHours() % 12 || 12); },
  9111. H: function (dateObj) { return String(dateObj.getHours()); },
  9112. HH: function (dateObj) { return pad(dateObj.getHours()); },
  9113. m: function (dateObj) { return String(dateObj.getMinutes()); },
  9114. mm: function (dateObj) { return pad(dateObj.getMinutes()); },
  9115. s: function (dateObj) { return String(dateObj.getSeconds()); },
  9116. ss: function (dateObj) { return pad(dateObj.getSeconds()); },
  9117. S: function (dateObj) {
  9118. return String(Math.round(dateObj.getMilliseconds() / 100));
  9119. },
  9120. SS: function (dateObj) {
  9121. return pad(Math.round(dateObj.getMilliseconds() / 10), 2);
  9122. },
  9123. SSS: function (dateObj) { return pad(dateObj.getMilliseconds(), 3); },
  9124. a: function (dateObj, i18n) {
  9125. return dateObj.getHours() < 12 ? i18n.amPm[0] : i18n.amPm[1];
  9126. },
  9127. A: function (dateObj, i18n) {
  9128. return dateObj.getHours() < 12
  9129. ? i18n.amPm[0].toUpperCase()
  9130. : i18n.amPm[1].toUpperCase();
  9131. },
  9132. ZZ: function (dateObj) {
  9133. var offset = dateObj.getTimezoneOffset();
  9134. return ((offset > 0 ? "-" : "+") +
  9135. pad(Math.floor(Math.abs(offset) / 60) * 100 + (Math.abs(offset) % 60), 4));
  9136. },
  9137. Z: function (dateObj) {
  9138. var offset = dateObj.getTimezoneOffset();
  9139. return ((offset > 0 ? "-" : "+") +
  9140. pad(Math.floor(Math.abs(offset) / 60), 2) +
  9141. ":" +
  9142. pad(Math.abs(offset) % 60, 2));
  9143. }
  9144. };
  9145. var monthParse = function (v) { return +v - 1; };
  9146. var emptyDigits = [null, twoDigitsOptional];
  9147. var emptyWord = [null, word];
  9148. var amPm = [
  9149. "isPm",
  9150. word,
  9151. function (v, i18n) {
  9152. var val = v.toLowerCase();
  9153. if (val === i18n.amPm[0]) {
  9154. return 0;
  9155. }
  9156. else if (val === i18n.amPm[1]) {
  9157. return 1;
  9158. }
  9159. return null;
  9160. }
  9161. ];
  9162. var timezoneOffset = [
  9163. "timezoneOffset",
  9164. "[^\\s]*?[\\+\\-]\\d\\d:?\\d\\d|[^\\s]*?Z?",
  9165. function (v) {
  9166. var parts = (v + "").match(/([+-]|\d\d)/gi);
  9167. if (parts) {
  9168. var minutes = +parts[1] * 60 + parseInt(parts[2], 10);
  9169. return parts[0] === "+" ? minutes : -minutes;
  9170. }
  9171. return 0;
  9172. }
  9173. ];
  9174. var parseFlags = {
  9175. D: ["day", twoDigitsOptional],
  9176. DD: ["day", twoDigits],
  9177. Do: ["day", twoDigitsOptional + word, function (v) { return parseInt(v, 10); }],
  9178. M: ["month", twoDigitsOptional, monthParse],
  9179. MM: ["month", twoDigits, monthParse],
  9180. YY: [
  9181. "year",
  9182. twoDigits,
  9183. function (v) {
  9184. var now = new Date();
  9185. var cent = +("" + now.getFullYear()).substr(0, 2);
  9186. return +("" + (+v > 68 ? cent - 1 : cent) + v);
  9187. }
  9188. ],
  9189. h: ["hour", twoDigitsOptional, undefined, "isPm"],
  9190. hh: ["hour", twoDigits, undefined, "isPm"],
  9191. H: ["hour", twoDigitsOptional],
  9192. HH: ["hour", twoDigits],
  9193. m: ["minute", twoDigitsOptional],
  9194. mm: ["minute", twoDigits],
  9195. s: ["second", twoDigitsOptional],
  9196. ss: ["second", twoDigits],
  9197. YYYY: ["year", fourDigits],
  9198. S: ["millisecond", "\\d", function (v) { return +v * 100; }],
  9199. SS: ["millisecond", twoDigits, function (v) { return +v * 10; }],
  9200. SSS: ["millisecond", threeDigits],
  9201. d: emptyDigits,
  9202. dd: emptyDigits,
  9203. ddd: emptyWord,
  9204. dddd: emptyWord,
  9205. MMM: ["month", word, monthUpdate("monthNamesShort")],
  9206. MMMM: ["month", word, monthUpdate("monthNames")],
  9207. a: amPm,
  9208. A: amPm,
  9209. ZZ: timezoneOffset,
  9210. Z: timezoneOffset
  9211. };
  9212. // Some common format strings
  9213. var globalMasks = {
  9214. default: "ddd MMM DD YYYY HH:mm:ss",
  9215. shortDate: "M/D/YY",
  9216. mediumDate: "MMM D, YYYY",
  9217. longDate: "MMMM D, YYYY",
  9218. fullDate: "dddd, MMMM D, YYYY",
  9219. isoDate: "YYYY-MM-DD",
  9220. isoDateTime: "YYYY-MM-DDTHH:mm:ssZ",
  9221. shortTime: "HH:mm",
  9222. mediumTime: "HH:mm:ss",
  9223. longTime: "HH:mm:ss.SSS"
  9224. };
  9225. var setGlobalDateMasks = function (masks) { return assign(globalMasks, masks); };
  9226. /***
  9227. * Format a date
  9228. * @method format
  9229. * @param {Date|number} dateObj
  9230. * @param {string} mask Format of the date, i.e. 'mm-dd-yy' or 'shortDate'
  9231. * @returns {string} Formatted date string
  9232. */
  9233. var format = function (dateObj, mask, i18n) {
  9234. if (mask === void 0) { mask = globalMasks["default"]; }
  9235. if (i18n === void 0) { i18n = {}; }
  9236. if (typeof dateObj === "number") {
  9237. dateObj = new Date(dateObj);
  9238. }
  9239. if (Object.prototype.toString.call(dateObj) !== "[object Date]" ||
  9240. isNaN(dateObj.getTime())) {
  9241. throw new Error("Invalid Date pass to format");
  9242. }
  9243. mask = globalMasks[mask] || mask;
  9244. var literals = [];
  9245. // Make literals inactive by replacing them with @@@
  9246. mask = mask.replace(literal, function ($0, $1) {
  9247. literals.push($1);
  9248. return "@@@";
  9249. });
  9250. var combinedI18nSettings = assign(assign({}, globalI18n), i18n);
  9251. // Apply formatting rules
  9252. mask = mask.replace(token, function ($0) {
  9253. return formatFlags[$0](dateObj, combinedI18nSettings);
  9254. });
  9255. // Inline literal values back into the formatted value
  9256. return mask.replace(/@@@/g, function () { return literals.shift(); });
  9257. };
  9258. /**
  9259. * Parse a date string into a Javascript Date object /
  9260. * @method parse
  9261. * @param {string} dateStr Date string
  9262. * @param {string} format Date parse format
  9263. * @param {i18n} I18nSettingsOptional Full or subset of I18N settings
  9264. * @returns {Date|null} Returns Date object. Returns null what date string is invalid or doesn't match format
  9265. */
  9266. function parse(dateStr, format, i18n) {
  9267. if (i18n === void 0) { i18n = {}; }
  9268. if (typeof format !== "string") {
  9269. throw new Error("Invalid format in fecha parse");
  9270. }
  9271. // Check to see if the format is actually a mask
  9272. format = globalMasks[format] || format;
  9273. // Avoid regular expression denial of service, fail early for really long strings
  9274. // https://www.owasp.org/index.php/Regular_expression_Denial_of_Service_-_ReDoS
  9275. if (dateStr.length > 1000) {
  9276. return null;
  9277. }
  9278. // Default to the beginning of the year.
  9279. var today = new Date();
  9280. var dateInfo = {
  9281. year: today.getFullYear(),
  9282. month: 0,
  9283. day: 1,
  9284. hour: 0,
  9285. minute: 0,
  9286. second: 0,
  9287. millisecond: 0,
  9288. isPm: null,
  9289. timezoneOffset: null
  9290. };
  9291. var parseInfo = [];
  9292. var literals = [];
  9293. // Replace all the literals with @@@. Hopefully a string that won't exist in the format
  9294. var newFormat = format.replace(literal, function ($0, $1) {
  9295. literals.push(regexEscape($1));
  9296. return "@@@";
  9297. });
  9298. var specifiedFields = {};
  9299. var requiredFields = {};
  9300. // Change every token that we find into the correct regex
  9301. newFormat = regexEscape(newFormat).replace(token, function ($0) {
  9302. var info = parseFlags[$0];
  9303. var field = info[0], regex = info[1], requiredField = info[3];
  9304. // Check if the person has specified the same field twice. This will lead to confusing results.
  9305. if (specifiedFields[field]) {
  9306. throw new Error("Invalid format. " + field + " specified twice in format");
  9307. }
  9308. specifiedFields[field] = true;
  9309. // Check if there are any required fields. For instance, 12 hour time requires AM/PM specified
  9310. if (requiredField) {
  9311. requiredFields[requiredField] = true;
  9312. }
  9313. parseInfo.push(info);
  9314. return "(" + regex + ")";
  9315. });
  9316. // Check all the required fields are present
  9317. Object.keys(requiredFields).forEach(function (field) {
  9318. if (!specifiedFields[field]) {
  9319. throw new Error("Invalid format. " + field + " is required in specified format");
  9320. }
  9321. });
  9322. // Add back all the literals after
  9323. newFormat = newFormat.replace(/@@@/g, function () { return literals.shift(); });
  9324. // Check if the date string matches the format. If it doesn't return null
  9325. var matches = dateStr.match(new RegExp(newFormat, "i"));
  9326. if (!matches) {
  9327. return null;
  9328. }
  9329. var combinedI18nSettings = assign(assign({}, globalI18n), i18n);
  9330. // For each match, call the parser function for that date part
  9331. for (var i = 1; i < matches.length; i++) {
  9332. var _a = parseInfo[i - 1], field = _a[0], parser = _a[2];
  9333. var value = parser
  9334. ? parser(matches[i], combinedI18nSettings)
  9335. : +matches[i];
  9336. // If the parser can't make sense of the value, return null
  9337. if (value == null) {
  9338. return null;
  9339. }
  9340. dateInfo[field] = value;
  9341. }
  9342. if (dateInfo.isPm === 1 && dateInfo.hour != null && +dateInfo.hour !== 12) {
  9343. dateInfo.hour = +dateInfo.hour + 12;
  9344. }
  9345. else if (dateInfo.isPm === 0 && +dateInfo.hour === 12) {
  9346. dateInfo.hour = 0;
  9347. }
  9348. var dateTZ;
  9349. if (dateInfo.timezoneOffset == null) {
  9350. dateTZ = new Date(dateInfo.year, dateInfo.month, dateInfo.day, dateInfo.hour, dateInfo.minute, dateInfo.second, dateInfo.millisecond);
  9351. var validateFields = [
  9352. ["month", "getMonth"],
  9353. ["day", "getDate"],
  9354. ["hour", "getHours"],
  9355. ["minute", "getMinutes"],
  9356. ["second", "getSeconds"]
  9357. ];
  9358. for (var i = 0, len = validateFields.length; i < len; i++) {
  9359. // Check to make sure the date field is within the allowed range. Javascript dates allows values
  9360. // outside the allowed range. If the values don't match the value was invalid
  9361. if (specifiedFields[validateFields[i][0]] &&
  9362. dateInfo[validateFields[i][0]] !== dateTZ[validateFields[i][1]]()) {
  9363. return null;
  9364. }
  9365. }
  9366. }
  9367. else {
  9368. dateTZ = new Date(Date.UTC(dateInfo.year, dateInfo.month, dateInfo.day, dateInfo.hour, dateInfo.minute - dateInfo.timezoneOffset, dateInfo.second, dateInfo.millisecond));
  9369. // We can't validate dates in another timezone unfortunately. Do a basic check instead
  9370. if (dateInfo.month > 11 ||
  9371. dateInfo.month < 0 ||
  9372. dateInfo.day > 31 ||
  9373. dateInfo.day < 1 ||
  9374. dateInfo.hour > 23 ||
  9375. dateInfo.hour < 0 ||
  9376. dateInfo.minute > 59 ||
  9377. dateInfo.minute < 0 ||
  9378. dateInfo.second > 59 ||
  9379. dateInfo.second < 0) {
  9380. return null;
  9381. }
  9382. }
  9383. // Don't allow invalid dates
  9384. return dateTZ;
  9385. }
  9386. var fecha = {
  9387. format: format,
  9388. parse: parse,
  9389. defaultI18n: defaultI18n,
  9390. setGlobalDateI18n: setGlobalDateI18n,
  9391. setGlobalDateMasks: setGlobalDateMasks
  9392. };
  9393. var fecha1 = /*#__PURE__*/Object.freeze({
  9394. __proto__: null,
  9395. 'default': fecha,
  9396. assign: assign,
  9397. format: format,
  9398. parse: parse,
  9399. defaultI18n: defaultI18n,
  9400. setGlobalDateI18n: setGlobalDateI18n,
  9401. setGlobalDateMasks: setGlobalDateMasks
  9402. });
  9403. /**
  9404. * 二分右侧查找
  9405. * https://github.com/d3/d3-array/blob/master/src/bisector.js
  9406. */
  9407. function bisector (getter) {
  9408. /**
  9409. * x: 目标值
  9410. * lo: 起始位置
  9411. * hi: 结束位置
  9412. */
  9413. return function (a, x, _lo, _hi) {
  9414. var lo = isNil(_lo) ? 0 : _lo;
  9415. var hi = isNil(_hi) ? a.length : _hi;
  9416. while (lo < hi) {
  9417. var mid = (lo + hi) >>> 1;
  9418. if (getter(a[mid]) > x) {
  9419. hi = mid;
  9420. }
  9421. else {
  9422. lo = mid + 1;
  9423. }
  9424. }
  9425. return lo;
  9426. };
  9427. }
  9428. var FORMAT_METHOD = 'format';
  9429. function timeFormat(time, mask) {
  9430. var method = fecha1[FORMAT_METHOD] || fecha[FORMAT_METHOD];
  9431. return method(time, mask);
  9432. }
  9433. /**
  9434. * 转换成时间戳
  9435. * @param value 时间值
  9436. */
  9437. function toTimeStamp$1(value) {
  9438. if (isString(value)) {
  9439. if (value.indexOf('T') > 0) {
  9440. value = new Date(value).getTime();
  9441. }
  9442. else {
  9443. // new Date('2010/01/10') 和 new Date('2010-01-10') 的差别在于:
  9444. // 如果仅有年月日时,前者是带有时区的: Fri Jan 10 2020 02:40:13 GMT+0800 (中国标准时间)
  9445. // 后者会格式化成 Sun Jan 10 2010 08:00:00 GMT+0800 (中国标准时间)
  9446. value = new Date(value.replace(/-/gi, '/')).getTime();
  9447. }
  9448. }
  9449. if (isDate(value)) {
  9450. value = value.getTime();
  9451. }
  9452. return value;
  9453. }
  9454. var SECOND = 1000;
  9455. var MINUTE = 60 * SECOND;
  9456. var HOUR = 60 * MINUTE;
  9457. var DAY = 24 * HOUR;
  9458. var MONTH = DAY * 31;
  9459. var YEAR = DAY * 365;
  9460. var intervals = [
  9461. ['HH:mm:ss', SECOND],
  9462. ['HH:mm:ss', SECOND * 10],
  9463. ['HH:mm:ss', SECOND * 30],
  9464. ['HH:mm', MINUTE],
  9465. ['HH:mm', MINUTE * 10],
  9466. ['HH:mm', MINUTE * 30],
  9467. ['HH', HOUR],
  9468. ['HH', HOUR * 6],
  9469. ['HH', HOUR * 12],
  9470. ['YYYY-MM-DD', DAY],
  9471. ['YYYY-MM-DD', DAY * 4],
  9472. ['YYYY-WW', DAY * 7],
  9473. ['YYYY-MM', MONTH],
  9474. ['YYYY-MM', MONTH * 4],
  9475. ['YYYY-MM', MONTH * 6],
  9476. ['YYYY', DAY * 380],
  9477. ];
  9478. function getTickInterval(min, max, tickCount) {
  9479. var target = (max - min) / tickCount;
  9480. var idx = bisector(function (o) { return o[1]; })(intervals, target) - 1;
  9481. var interval = intervals[idx];
  9482. if (idx < 0) {
  9483. interval = intervals[0];
  9484. }
  9485. else if (idx >= intervals.length) {
  9486. interval = last(intervals);
  9487. }
  9488. return interval;
  9489. }
  9490. /**
  9491. * 时间分类度量
  9492. * @class
  9493. */
  9494. var TimeCat = /** @class */ (function (_super) {
  9495. __extends(TimeCat, _super);
  9496. function TimeCat() {
  9497. var _this = _super !== null && _super.apply(this, arguments) || this;
  9498. _this.type = 'timeCat';
  9499. return _this;
  9500. }
  9501. /**
  9502. * @override
  9503. */
  9504. TimeCat.prototype.translate = function (value) {
  9505. value = toTimeStamp$1(value);
  9506. var index = this.values.indexOf(value);
  9507. if (index === -1) {
  9508. if (isNumber(value) && value < this.values.length) {
  9509. index = value;
  9510. }
  9511. else {
  9512. index = NaN;
  9513. }
  9514. }
  9515. return index;
  9516. };
  9517. /**
  9518. * 由于时间类型数据需要转换一下,所以复写 getText
  9519. * @override
  9520. */
  9521. TimeCat.prototype.getText = function (value, tickIndex) {
  9522. var index = this.translate(value);
  9523. if (index > -1) {
  9524. var result = this.values[index];
  9525. var formatter = this.formatter;
  9526. result = formatter ? formatter(result, tickIndex) : timeFormat(result, this.mask);
  9527. return result;
  9528. }
  9529. return value;
  9530. };
  9531. TimeCat.prototype.initCfg = function () {
  9532. this.tickMethod = 'time-cat';
  9533. this.mask = 'YYYY-MM-DD';
  9534. this.tickCount = 7; // 一般时间数据会显示 7, 14, 30 天的数字
  9535. };
  9536. TimeCat.prototype.setDomain = function () {
  9537. var values = this.values;
  9538. // 针对时间分类类型,会将时间统一转换为时间戳
  9539. each(values, function (v, i) {
  9540. values[i] = toTimeStamp$1(v);
  9541. });
  9542. values.sort(function (v1, v2) {
  9543. return v1 - v2;
  9544. });
  9545. _super.prototype.setDomain.call(this);
  9546. };
  9547. return TimeCat;
  9548. }(Category));
  9549. /**
  9550. * 连续度量的基类
  9551. * @class
  9552. */
  9553. var Continuous = /** @class */ (function (_super) {
  9554. __extends(Continuous, _super);
  9555. function Continuous() {
  9556. var _this = _super !== null && _super.apply(this, arguments) || this;
  9557. _this.isContinuous = true;
  9558. return _this;
  9559. }
  9560. Continuous.prototype.scale = function (value) {
  9561. if (isNil(value)) {
  9562. return NaN;
  9563. }
  9564. var rangeMin = this.rangeMin();
  9565. var rangeMax = this.rangeMax();
  9566. var max = this.max;
  9567. var min = this.min;
  9568. if (max === min) {
  9569. return rangeMin;
  9570. }
  9571. var percent = this.getScalePercent(value);
  9572. return rangeMin + percent * (rangeMax - rangeMin);
  9573. };
  9574. Continuous.prototype.init = function () {
  9575. _super.prototype.init.call(this);
  9576. // init 完成后保证 min, max 包含 ticks 的范围
  9577. var ticks = this.ticks;
  9578. var firstTick = head(ticks);
  9579. var lastTick = last(ticks);
  9580. if (firstTick < this.min) {
  9581. this.min = firstTick;
  9582. }
  9583. if (lastTick > this.max) {
  9584. this.max = lastTick;
  9585. }
  9586. // strict-limit 方式
  9587. if (!isNil(this.minLimit)) {
  9588. this.min = firstTick;
  9589. }
  9590. if (!isNil(this.maxLimit)) {
  9591. this.max = lastTick;
  9592. }
  9593. };
  9594. Continuous.prototype.setDomain = function () {
  9595. var _a = getRange(this.values), min = _a.min, max = _a.max;
  9596. if (isNil(this.min)) {
  9597. this.min = min;
  9598. }
  9599. if (isNil(this.max)) {
  9600. this.max = max;
  9601. }
  9602. if (this.min > this.max) {
  9603. this.min = min;
  9604. this.max = max;
  9605. }
  9606. };
  9607. Continuous.prototype.calculateTicks = function () {
  9608. var _this = this;
  9609. var ticks = _super.prototype.calculateTicks.call(this);
  9610. if (!this.nice) {
  9611. ticks = filter(ticks, function (tick) {
  9612. return tick >= _this.min && tick <= _this.max;
  9613. });
  9614. }
  9615. return ticks;
  9616. };
  9617. // 计算原始值值占的百分比
  9618. Continuous.prototype.getScalePercent = function (value) {
  9619. var max = this.max;
  9620. var min = this.min;
  9621. return (value - min) / (max - min);
  9622. };
  9623. Continuous.prototype.getInvertPercent = function (value) {
  9624. return (value - this.rangeMin()) / (this.rangeMax() - this.rangeMin());
  9625. };
  9626. return Continuous;
  9627. }(Scale));
  9628. /**
  9629. * 线性度量
  9630. * @class
  9631. */
  9632. var Linear = /** @class */ (function (_super) {
  9633. __extends(Linear, _super);
  9634. function Linear() {
  9635. var _this = _super !== null && _super.apply(this, arguments) || this;
  9636. _this.type = 'linear';
  9637. _this.isLinear = true;
  9638. return _this;
  9639. }
  9640. Linear.prototype.invert = function (value) {
  9641. var percent = this.getInvertPercent(value);
  9642. return this.min + percent * (this.max - this.min);
  9643. };
  9644. Linear.prototype.initCfg = function () {
  9645. this.tickMethod = 'wilkinson-extended';
  9646. this.nice = false;
  9647. };
  9648. return Linear;
  9649. }(Continuous));
  9650. // 求以a为次幂,结果为b的基数,如 x^^a = b;求x
  9651. // 虽然数学上 b 不支持负数,但是这里需要支持 负数
  9652. function calBase(a, b) {
  9653. var e = Math.E;
  9654. var value;
  9655. if (b >= 0) {
  9656. value = Math.pow(e, Math.log(b) / a); // 使用换底公式求底
  9657. }
  9658. else {
  9659. value = Math.pow(e, Math.log(-b) / a) * -1; // 使用换底公式求底
  9660. }
  9661. return value;
  9662. }
  9663. function log(a, b) {
  9664. if (a === 1) {
  9665. return 1;
  9666. }
  9667. return Math.log(b) / Math.log(a);
  9668. }
  9669. function getLogPositiveMin(values, base, max) {
  9670. if (isNil(max)) {
  9671. max = Math.max.apply(null, values);
  9672. }
  9673. var positiveMin = max;
  9674. each(values, function (value) {
  9675. if (value > 0 && value < positiveMin) {
  9676. positiveMin = value;
  9677. }
  9678. });
  9679. if (positiveMin === max) {
  9680. positiveMin = max / base;
  9681. }
  9682. if (positiveMin > 1) {
  9683. positiveMin = 1;
  9684. }
  9685. return positiveMin;
  9686. }
  9687. /**
  9688. * Log 度量,处理非均匀分布
  9689. */
  9690. var Log = /** @class */ (function (_super) {
  9691. __extends(Log, _super);
  9692. function Log() {
  9693. var _this = _super !== null && _super.apply(this, arguments) || this;
  9694. _this.type = 'log';
  9695. return _this;
  9696. }
  9697. /**
  9698. * @override
  9699. */
  9700. Log.prototype.invert = function (value) {
  9701. var base = this.base;
  9702. var max = log(base, this.max);
  9703. var rangeMin = this.rangeMin();
  9704. var range = this.rangeMax() - rangeMin;
  9705. var min;
  9706. var positiveMin = this.positiveMin;
  9707. if (positiveMin) {
  9708. if (value === 0) {
  9709. return 0;
  9710. }
  9711. min = log(base, positiveMin / base);
  9712. var appendPercent = (1 / (max - min)) * range; // 0 到 positiveMin的占比
  9713. if (value < appendPercent) {
  9714. // 落到 0 - positiveMin 之间
  9715. return (value / appendPercent) * positiveMin;
  9716. }
  9717. }
  9718. else {
  9719. min = log(base, this.min);
  9720. }
  9721. var percent = (value - rangeMin) / range;
  9722. var tmp = percent * (max - min) + min;
  9723. return Math.pow(base, tmp);
  9724. };
  9725. Log.prototype.initCfg = function () {
  9726. this.tickMethod = 'log';
  9727. this.base = 10;
  9728. this.tickCount = 6;
  9729. this.nice = true;
  9730. };
  9731. // 设置
  9732. Log.prototype.setDomain = function () {
  9733. _super.prototype.setDomain.call(this);
  9734. var min = this.min;
  9735. if (min < 0) {
  9736. throw new Error('When you use log scale, the minimum value must be greater than zero!');
  9737. }
  9738. if (min === 0) {
  9739. this.positiveMin = getLogPositiveMin(this.values, this.base, this.max);
  9740. }
  9741. };
  9742. // 根据当前值获取占比
  9743. Log.prototype.getScalePercent = function (value) {
  9744. var max = this.max;
  9745. var min = this.min;
  9746. if (max === min) {
  9747. return 0;
  9748. }
  9749. // 如果值小于等于0,则按照0处理
  9750. if (value <= 0) {
  9751. return 0;
  9752. }
  9753. var base = this.base;
  9754. var positiveMin = this.positiveMin;
  9755. // 如果min == 0, 则根据比0大的最小值,计算比例关系。这个最小值作为坐标轴上的第二个tick,第一个是0但是不显示
  9756. if (positiveMin) {
  9757. min = (positiveMin * 1) / base;
  9758. }
  9759. var percent;
  9760. // 如果数值小于次小值,那么就计算 value / 次小值 占整体的比例
  9761. if (value < positiveMin) {
  9762. percent = value / positiveMin / (log(base, max) - log(base, min));
  9763. }
  9764. else {
  9765. percent = (log(base, value) - log(base, min)) / (log(base, max) - log(base, min));
  9766. }
  9767. return percent;
  9768. };
  9769. return Log;
  9770. }(Continuous));
  9771. /**
  9772. * Pow 度量,处理非均匀分布
  9773. */
  9774. var Pow = /** @class */ (function (_super) {
  9775. __extends(Pow, _super);
  9776. function Pow() {
  9777. var _this = _super !== null && _super.apply(this, arguments) || this;
  9778. _this.type = 'pow';
  9779. return _this;
  9780. }
  9781. /**
  9782. * @override
  9783. */
  9784. Pow.prototype.invert = function (value) {
  9785. var percent = this.getInvertPercent(value);
  9786. var exponent = this.exponent;
  9787. var max = calBase(exponent, this.max);
  9788. var min = calBase(exponent, this.min);
  9789. var tmp = percent * (max - min) + min;
  9790. var factor = tmp >= 0 ? 1 : -1;
  9791. return Math.pow(tmp, exponent) * factor;
  9792. };
  9793. Pow.prototype.initCfg = function () {
  9794. this.tickMethod = 'pow';
  9795. this.exponent = 2;
  9796. this.tickCount = 5;
  9797. this.nice = true;
  9798. };
  9799. // 获取度量计算时,value占的定义域百分比
  9800. Pow.prototype.getScalePercent = function (value) {
  9801. var max = this.max;
  9802. var min = this.min;
  9803. if (max === min) {
  9804. return 0;
  9805. }
  9806. var exponent = this.exponent;
  9807. var percent = (calBase(exponent, value) - calBase(exponent, min)) / (calBase(exponent, max) - calBase(exponent, min));
  9808. return percent;
  9809. };
  9810. return Pow;
  9811. }(Continuous));
  9812. /**
  9813. * 时间度量
  9814. * @class
  9815. */
  9816. var Time = /** @class */ (function (_super) {
  9817. __extends(Time, _super);
  9818. function Time() {
  9819. var _this = _super !== null && _super.apply(this, arguments) || this;
  9820. _this.type = 'time';
  9821. return _this;
  9822. }
  9823. /**
  9824. * @override
  9825. */
  9826. Time.prototype.getText = function (value, index) {
  9827. var numberValue = this.translate(value);
  9828. var formatter = this.formatter;
  9829. return formatter ? formatter(numberValue, index) : timeFormat(numberValue, this.mask);
  9830. };
  9831. /**
  9832. * @override
  9833. */
  9834. Time.prototype.scale = function (value) {
  9835. var v = value;
  9836. if (isString(v) || isDate(v)) {
  9837. v = this.translate(v);
  9838. }
  9839. return _super.prototype.scale.call(this, v);
  9840. };
  9841. /**
  9842. * 将时间转换成数字
  9843. * @override
  9844. */
  9845. Time.prototype.translate = function (v) {
  9846. return toTimeStamp$1(v);
  9847. };
  9848. Time.prototype.initCfg = function () {
  9849. this.tickMethod = 'time-pretty';
  9850. this.mask = 'YYYY-MM-DD';
  9851. this.tickCount = 7;
  9852. this.nice = false;
  9853. };
  9854. Time.prototype.setDomain = function () {
  9855. var values = this.values;
  9856. // 是否设置了 min, max,而不是直接取 this.min, this.max
  9857. var minConfig = this.getConfig('min');
  9858. var maxConfig = this.getConfig('max');
  9859. // 如果设置了 min,max 则转换成时间戳
  9860. if (!isNil(minConfig) || !isNumber(minConfig)) {
  9861. this.min = this.translate(this.min);
  9862. }
  9863. if (!isNil(maxConfig) || !isNumber(maxConfig)) {
  9864. this.max = this.translate(this.max);
  9865. }
  9866. // 没有设置 min, max 时
  9867. if (values && values.length) {
  9868. // 重新计算最大最小值
  9869. var timeStamps_1 = [];
  9870. var min_1 = Infinity; // 最小值
  9871. var secondMin_1 = min_1; // 次小值
  9872. var max_1 = 0;
  9873. // 使用一个循环,计算min,max,secondMin
  9874. each(values, function (v) {
  9875. var timeStamp = toTimeStamp$1(v);
  9876. if (isNaN(timeStamp)) {
  9877. throw new TypeError("Invalid Time: " + v + " in time scale!");
  9878. }
  9879. if (min_1 > timeStamp) {
  9880. secondMin_1 = min_1;
  9881. min_1 = timeStamp;
  9882. }
  9883. else if (secondMin_1 > timeStamp) {
  9884. secondMin_1 = timeStamp;
  9885. }
  9886. if (max_1 < timeStamp) {
  9887. max_1 = timeStamp;
  9888. }
  9889. timeStamps_1.push(timeStamp);
  9890. });
  9891. // 存在多个值时,设置最小间距
  9892. if (values.length > 1) {
  9893. this.minTickInterval = secondMin_1 - min_1;
  9894. }
  9895. if (isNil(minConfig)) {
  9896. this.min = min_1;
  9897. }
  9898. if (isNil(maxConfig)) {
  9899. this.max = max_1;
  9900. }
  9901. }
  9902. };
  9903. return Time;
  9904. }(Linear));
  9905. /**
  9906. * 分段度量
  9907. */
  9908. var Quantize = /** @class */ (function (_super) {
  9909. __extends(Quantize, _super);
  9910. function Quantize() {
  9911. var _this = _super !== null && _super.apply(this, arguments) || this;
  9912. _this.type = 'quantize';
  9913. return _this;
  9914. }
  9915. Quantize.prototype.invert = function (value) {
  9916. var ticks = this.ticks;
  9917. var length = ticks.length;
  9918. var percent = this.getInvertPercent(value);
  9919. var minIndex = Math.floor(percent * (length - 1));
  9920. // 最后一个
  9921. if (minIndex >= length - 1) {
  9922. return last(ticks);
  9923. }
  9924. // 超出左边界, 则取第一个
  9925. if (minIndex < 0) {
  9926. return head(ticks);
  9927. }
  9928. var minTick = ticks[minIndex];
  9929. var nextTick = ticks[minIndex + 1];
  9930. // 比当前值小的 tick 在度量上的占比
  9931. var minIndexPercent = minIndex / (length - 1);
  9932. var maxIndexPercent = (minIndex + 1) / (length - 1);
  9933. return minTick + (percent - minIndexPercent) / (maxIndexPercent - minIndexPercent) * (nextTick - minTick);
  9934. };
  9935. Quantize.prototype.initCfg = function () {
  9936. this.tickMethod = 'r-pretty';
  9937. this.tickCount = 5;
  9938. this.nice = true;
  9939. };
  9940. Quantize.prototype.calculateTicks = function () {
  9941. var ticks = _super.prototype.calculateTicks.call(this);
  9942. if (!this.nice) { // 如果 nice = false ,补充 min, max
  9943. if (last(ticks) !== this.max) {
  9944. ticks.push(this.max);
  9945. }
  9946. if (head(ticks) !== this.min) {
  9947. ticks.unshift(this.min);
  9948. }
  9949. }
  9950. return ticks;
  9951. };
  9952. // 计算当前值在刻度中的占比
  9953. Quantize.prototype.getScalePercent = function (value) {
  9954. var ticks = this.ticks;
  9955. // 超出左边界
  9956. if (value < head(ticks)) {
  9957. return 0;
  9958. }
  9959. // 超出右边界
  9960. if (value > last(ticks)) {
  9961. return 1;
  9962. }
  9963. var minIndex = 0;
  9964. each(ticks, function (tick, index) {
  9965. if (value >= tick) {
  9966. minIndex = index;
  9967. }
  9968. else {
  9969. return false;
  9970. }
  9971. });
  9972. return minIndex / (ticks.length - 1);
  9973. };
  9974. return Quantize;
  9975. }(Continuous));
  9976. var Quantile = /** @class */ (function (_super) {
  9977. __extends(Quantile, _super);
  9978. function Quantile() {
  9979. var _this = _super !== null && _super.apply(this, arguments) || this;
  9980. _this.type = 'quantile';
  9981. return _this;
  9982. }
  9983. Quantile.prototype.initCfg = function () {
  9984. this.tickMethod = 'quantile';
  9985. this.tickCount = 5;
  9986. this.nice = true;
  9987. };
  9988. return Quantile;
  9989. }(Quantize));
  9990. var map$3 = {};
  9991. function getClass(key) {
  9992. return map$3[key];
  9993. }
  9994. function registerClass(key, cls) {
  9995. if (getClass(key)) {
  9996. throw new Error("type '" + key + "' existed.");
  9997. }
  9998. map$3[key] = cls;
  9999. }
  10000. /**
  10001. * identity scale原则上是定义域和值域一致,scale/invert方法也是一致的
  10002. * 参考R的实现:https://github.com/r-lib/scales/blob/master/R/pal-identity.r
  10003. * 参考d3的实现(做了下转型):https://github.com/d3/d3-scale/blob/master/src/identity.js
  10004. */
  10005. var Identity = /** @class */ (function (_super) {
  10006. __extends(Identity, _super);
  10007. function Identity() {
  10008. var _this = _super !== null && _super.apply(this, arguments) || this;
  10009. _this.type = 'identity';
  10010. _this.isIdentity = true;
  10011. return _this;
  10012. }
  10013. Identity.prototype.calculateTicks = function () {
  10014. return this.values;
  10015. };
  10016. Identity.prototype.scale = function (value) {
  10017. // 如果传入的值不等于 identity 的值,则直接返回,用于一维图时的 dodge
  10018. if (this.values[0] !== value && isNumber(value)) {
  10019. return value;
  10020. }
  10021. return this.range[0];
  10022. };
  10023. Identity.prototype.invert = function (value) {
  10024. var range = this.range;
  10025. if (value < range[0] || value > range[1]) {
  10026. return NaN;
  10027. }
  10028. return this.values[0];
  10029. };
  10030. return Identity;
  10031. }(Scale));
  10032. /**
  10033. * 计算分类 ticks
  10034. * @param cfg 度量的配置项
  10035. * @returns 计算后的 ticks
  10036. */
  10037. function calculateCatTicks(cfg) {
  10038. var values = cfg.values, tickInterval = cfg.tickInterval, tickCount = cfg.tickCount, showLast = cfg.showLast;
  10039. if (isNumber(tickInterval)) {
  10040. var ticks_1 = filter(values, function (__, i) { return i % tickInterval === 0; });
  10041. var lastValue = last(values);
  10042. if (showLast && last(ticks_1) !== lastValue) {
  10043. ticks_1.push(lastValue);
  10044. }
  10045. return ticks_1;
  10046. }
  10047. var len = values.length;
  10048. var min = cfg.min, max = cfg.max;
  10049. if (isNil(min)) {
  10050. min = 0;
  10051. }
  10052. if (isNil(max)) {
  10053. max = values.length - 1;
  10054. }
  10055. if (!isNumber(tickCount) || tickCount >= len)
  10056. return values.slice(min, max + 1);
  10057. if (tickCount <= 0 || max <= 0)
  10058. return [];
  10059. var interval = tickCount === 1 ? len : Math.floor(len / (tickCount - 1));
  10060. var ticks = [];
  10061. var idx = min;
  10062. for (var i = 0; i < tickCount; i++) {
  10063. if (idx >= max)
  10064. break;
  10065. idx = Math.min(min + i * interval, max);
  10066. if (i === tickCount - 1 && showLast)
  10067. ticks.push(values[max]);
  10068. else
  10069. ticks.push(values[idx]);
  10070. }
  10071. return ticks;
  10072. }
  10073. function d3Linear(cfg) {
  10074. var min = cfg.min, max = cfg.max, nice = cfg.nice, tickCount = cfg.tickCount;
  10075. var linear = new D3Linear();
  10076. linear.domain([min, max]);
  10077. if (nice) {
  10078. linear.nice(tickCount);
  10079. }
  10080. return linear.ticks(tickCount);
  10081. }
  10082. var DEFAULT_COUNT = 5;
  10083. var e10 = Math.sqrt(50);
  10084. var e5 = Math.sqrt(10);
  10085. var e2 = Math.sqrt(2);
  10086. // https://github.com/d3/d3-scale
  10087. var D3Linear = /** @class */ (function () {
  10088. function D3Linear() {
  10089. this._domain = [0, 1];
  10090. }
  10091. D3Linear.prototype.domain = function (domain) {
  10092. if (domain) {
  10093. this._domain = Array.from(domain, Number);
  10094. return this;
  10095. }
  10096. return this._domain.slice();
  10097. };
  10098. D3Linear.prototype.nice = function (count) {
  10099. var _a, _b;
  10100. if (count === void 0) { count = DEFAULT_COUNT; }
  10101. var d = this._domain.slice();
  10102. var i0 = 0;
  10103. var i1 = this._domain.length - 1;
  10104. var start = this._domain[i0];
  10105. var stop = this._domain[i1];
  10106. var step;
  10107. if (stop < start) {
  10108. _a = [stop, start], start = _a[0], stop = _a[1];
  10109. _b = [i1, i0], i0 = _b[0], i1 = _b[1];
  10110. }
  10111. step = tickIncrement(start, stop, count);
  10112. if (step > 0) {
  10113. start = Math.floor(start / step) * step;
  10114. stop = Math.ceil(stop / step) * step;
  10115. step = tickIncrement(start, stop, count);
  10116. }
  10117. else if (step < 0) {
  10118. start = Math.ceil(start * step) / step;
  10119. stop = Math.floor(stop * step) / step;
  10120. step = tickIncrement(start, stop, count);
  10121. }
  10122. if (step > 0) {
  10123. d[i0] = Math.floor(start / step) * step;
  10124. d[i1] = Math.ceil(stop / step) * step;
  10125. this.domain(d);
  10126. }
  10127. else if (step < 0) {
  10128. d[i0] = Math.ceil(start * step) / step;
  10129. d[i1] = Math.floor(stop * step) / step;
  10130. this.domain(d);
  10131. }
  10132. return this;
  10133. };
  10134. D3Linear.prototype.ticks = function (count) {
  10135. if (count === void 0) { count = DEFAULT_COUNT; }
  10136. return d3ArrayTicks(this._domain[0], this._domain[this._domain.length - 1], count || DEFAULT_COUNT);
  10137. };
  10138. return D3Linear;
  10139. }());
  10140. function d3ArrayTicks(start, stop, count) {
  10141. var reverse;
  10142. var i = -1;
  10143. var n;
  10144. var ticks;
  10145. var step;
  10146. (stop = +stop), (start = +start), (count = +count);
  10147. if (start === stop && count > 0) {
  10148. return [start];
  10149. }
  10150. // tslint:disable-next-line
  10151. if ((reverse = stop < start)) {
  10152. (n = start), (start = stop), (stop = n);
  10153. }
  10154. // tslint:disable-next-line
  10155. if ((step = tickIncrement(start, stop, count)) === 0 || !isFinite(step)) {
  10156. return [];
  10157. }
  10158. if (step > 0) {
  10159. start = Math.ceil(start / step);
  10160. stop = Math.floor(stop / step);
  10161. ticks = new Array((n = Math.ceil(stop - start + 1)));
  10162. while (++i < n) {
  10163. ticks[i] = (start + i) * step;
  10164. }
  10165. }
  10166. else {
  10167. start = Math.floor(start * step);
  10168. stop = Math.ceil(stop * step);
  10169. ticks = new Array((n = Math.ceil(start - stop + 1)));
  10170. while (++i < n) {
  10171. ticks[i] = (start - i) / step;
  10172. }
  10173. }
  10174. if (reverse) {
  10175. ticks.reverse();
  10176. }
  10177. return ticks;
  10178. }
  10179. function tickIncrement(start, stop, count) {
  10180. var step = (stop - start) / Math.max(0, count);
  10181. var power = Math.floor(Math.log(step) / Math.LN10);
  10182. var error = step / Math.pow(10, power);
  10183. return power >= 0
  10184. ? (error >= e10 ? 10 : error >= e5 ? 5 : error >= e2 ? 2 : 1) * Math.pow(10, power)
  10185. : -Math.pow(10, -power) / (error >= e10 ? 10 : error >= e5 ? 5 : error >= e2 ? 2 : 1);
  10186. }
  10187. function snapMultiple(v, base, snapType) {
  10188. var div;
  10189. if (snapType === 'ceil') {
  10190. div = Math.ceil(v / base);
  10191. }
  10192. else if (snapType === 'floor') {
  10193. div = Math.floor(v / base);
  10194. }
  10195. else {
  10196. div = Math.round(v / base);
  10197. }
  10198. return div * base;
  10199. }
  10200. function intervalTicks(min, max, interval) {
  10201. // 变成 interval 的倍数
  10202. var minTick = snapMultiple(min, interval, 'floor');
  10203. var maxTick = snapMultiple(max, interval, 'ceil');
  10204. // 统一小数位数
  10205. minTick = fixedBase(minTick, interval);
  10206. maxTick = fixedBase(maxTick, interval);
  10207. var ticks = [];
  10208. // https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Errors/Invalid_array_length
  10209. var availableInterval = Math.max((maxTick - minTick) / (Math.pow(2, 12) - 1), interval);
  10210. for (var i = minTick; i <= maxTick; i = i + availableInterval) {
  10211. var tickValue = fixedBase(i, availableInterval); // 防止浮点数加法出现问题
  10212. ticks.push(tickValue);
  10213. }
  10214. return {
  10215. min: minTick,
  10216. max: maxTick,
  10217. ticks: ticks
  10218. };
  10219. }
  10220. /**
  10221. * 按照给定的 minLimit/maxLimit/tickCount 均匀计算出刻度 ticks
  10222. *
  10223. * @param cfg Scale 配置项
  10224. * @return ticks
  10225. */
  10226. function strictLimit(cfg, defaultMin, defaultMax) {
  10227. var _a;
  10228. var minLimit = cfg.minLimit, maxLimit = cfg.maxLimit, min = cfg.min, max = cfg.max, _b = cfg.tickCount, tickCount = _b === void 0 ? 5 : _b;
  10229. var tickMin = isNil(minLimit) ? (isNil(defaultMin) ? min : defaultMin) : minLimit;
  10230. var tickMax = isNil(maxLimit) ? (isNil(defaultMax) ? max : defaultMax) : maxLimit;
  10231. if (tickMin > tickMax) {
  10232. _a = [tickMin, tickMax], tickMax = _a[0], tickMin = _a[1];
  10233. }
  10234. if (tickCount <= 2) {
  10235. return [tickMin, tickMax];
  10236. }
  10237. var step = (tickMax - tickMin) / (tickCount - 1);
  10238. var ticks = [];
  10239. for (var i = 0; i < tickCount; i++) {
  10240. ticks.push(tickMin + step * i);
  10241. }
  10242. return ticks;
  10243. }
  10244. function d3LinearTickMethod(cfg) {
  10245. var min = cfg.min, max = cfg.max, tickInterval = cfg.tickInterval, minLimit = cfg.minLimit, maxLimit = cfg.maxLimit;
  10246. var ticks = d3Linear(cfg);
  10247. if (!isNil(minLimit) || !isNil(maxLimit)) {
  10248. return strictLimit(cfg, head(ticks), last(ticks));
  10249. }
  10250. if (tickInterval) {
  10251. return intervalTicks(min, max, tickInterval).ticks;
  10252. }
  10253. return ticks;
  10254. }
  10255. // 为了解决 js 运算的精度问题
  10256. function prettyNumber(n) {
  10257. return Math.abs(n) < 1e-15 ? n : parseFloat(n.toFixed(15));
  10258. }
  10259. var DEFAULT_Q = [1, 5, 2, 2.5, 4, 3];
  10260. var eps = Number.EPSILON * 100;
  10261. function mod(n, m) {
  10262. return ((n % m) + m) % m;
  10263. }
  10264. function round(n) {
  10265. return Math.round(n * 1e12) / 1e12;
  10266. }
  10267. function simplicity(q, Q, j, lmin, lmax, lstep) {
  10268. var n = size(Q);
  10269. var i = indexOf(Q, q);
  10270. var v = 0;
  10271. var m = mod(lmin, lstep);
  10272. if ((m < eps || lstep - m < eps) && lmin <= 0 && lmax >= 0) {
  10273. v = 1;
  10274. }
  10275. return 1 - i / (n - 1) - j + v;
  10276. }
  10277. function simplicityMax(q, Q, j) {
  10278. var n = size(Q);
  10279. var i = indexOf(Q, q);
  10280. var v = 1;
  10281. return 1 - i / (n - 1) - j + v;
  10282. }
  10283. function density(k, m, dMin, dMax, lMin, lMax) {
  10284. var r = (k - 1) / (lMax - lMin);
  10285. var rt = (m - 1) / (Math.max(lMax, dMax) - Math.min(dMin, lMin));
  10286. return 2 - Math.max(r / rt, rt / r);
  10287. }
  10288. function densityMax(k, m) {
  10289. if (k >= m) {
  10290. return 2 - (k - 1) / (m - 1);
  10291. }
  10292. return 1;
  10293. }
  10294. function coverage(dMin, dMax, lMin, lMax) {
  10295. var range = dMax - dMin;
  10296. return 1 - (0.5 * (Math.pow((dMax - lMax), 2) + Math.pow((dMin - lMin), 2))) / Math.pow((0.1 * range), 2);
  10297. }
  10298. function coverageMax(dMin, dMax, span) {
  10299. var range = dMax - dMin;
  10300. if (span > range) {
  10301. var half = (span - range) / 2;
  10302. return 1 - Math.pow(half, 2) / Math.pow((0.1 * range), 2);
  10303. }
  10304. return 1;
  10305. }
  10306. function legibility() {
  10307. return 1;
  10308. }
  10309. /**
  10310. * An Extension of Wilkinson's Algorithm for Position Tick Labels on Axes
  10311. * https://www.yuque.com/preview/yuque/0/2019/pdf/185317/1546999150858-45c3b9c2-4e86-4223-bf1a-8a732e8195ed.pdf
  10312. * @param dMin 最小值
  10313. * @param dMax 最大值
  10314. * @param m tick个数
  10315. * @param onlyLoose 是否允许扩展min、max,不绝对强制,例如[3, 97]
  10316. * @param Q nice numbers集合
  10317. * @param w 四个优化组件的权重
  10318. */
  10319. function extended(dMin, dMax, n, onlyLoose, Q, w) {
  10320. if (n === void 0) { n = 5; }
  10321. if (onlyLoose === void 0) { onlyLoose = true; }
  10322. if (Q === void 0) { Q = DEFAULT_Q; }
  10323. if (w === void 0) { w = [0.25, 0.2, 0.5, 0.05]; }
  10324. // 处理小于 0 和小数的 tickCount
  10325. var m = n < 0 ? 0 : Math.round(n);
  10326. // nan 也会导致异常
  10327. if (Number.isNaN(dMin) || Number.isNaN(dMax) || typeof dMin !== 'number' || typeof dMax !== 'number' || !m) {
  10328. return {
  10329. min: 0,
  10330. max: 0,
  10331. ticks: [],
  10332. };
  10333. }
  10334. // js 极大值极小值问题,差值小于 1e-15 会导致计算出错
  10335. if (dMax - dMin < 1e-15 || m === 1) {
  10336. return {
  10337. min: dMin,
  10338. max: dMax,
  10339. ticks: [dMin],
  10340. };
  10341. }
  10342. // js 超大值问题
  10343. if (dMax - dMin > 1e148) {
  10344. var count = n || 5;
  10345. var step_1 = (dMax - dMin) / count;
  10346. return {
  10347. min: dMin,
  10348. max: dMax,
  10349. ticks: Array(count).fill(null).map(function (_, idx) {
  10350. return prettyNumber(dMin + step_1 * idx);
  10351. }),
  10352. };
  10353. }
  10354. var best = {
  10355. score: -2,
  10356. lmin: 0,
  10357. lmax: 0,
  10358. lstep: 0,
  10359. };
  10360. var j = 1;
  10361. while (j < Infinity) {
  10362. for (var i = 0; i < Q.length; i += 1) {
  10363. var q = Q[i];
  10364. var sm = simplicityMax(q, Q, j);
  10365. if (w[0] * sm + w[1] + w[2] + w[3] < best.score) {
  10366. j = Infinity;
  10367. break;
  10368. }
  10369. var k = 2;
  10370. while (k < Infinity) {
  10371. var dm = densityMax(k, m);
  10372. if (w[0] * sm + w[1] + w[2] * dm + w[3] < best.score) {
  10373. break;
  10374. }
  10375. var delta = (dMax - dMin) / (k + 1) / j / q;
  10376. var z = Math.ceil(Math.log10(delta));
  10377. while (z < Infinity) {
  10378. var step = j * q * Math.pow(10, z);
  10379. var cm = coverageMax(dMin, dMax, step * (k - 1));
  10380. if (w[0] * sm + w[1] * cm + w[2] * dm + w[3] < best.score) {
  10381. break;
  10382. }
  10383. var minStart = Math.floor(dMax / step) * j - (k - 1) * j;
  10384. var maxStart = Math.ceil(dMin / step) * j;
  10385. if (minStart <= maxStart) {
  10386. var count = maxStart - minStart;
  10387. for (var i_1 = 0; i_1 <= count; i_1 += 1) {
  10388. var start = minStart + i_1;
  10389. var lMin = start * (step / j);
  10390. var lMax = lMin + step * (k - 1);
  10391. var lStep = step;
  10392. var s = simplicity(q, Q, j, lMin, lMax, lStep);
  10393. var c = coverage(dMin, dMax, lMin, lMax);
  10394. var g = density(k, m, dMin, dMax, lMin, lMax);
  10395. var l = legibility();
  10396. var score = w[0] * s + w[1] * c + w[2] * g + w[3] * l;
  10397. if (score > best.score && (!onlyLoose || (lMin <= dMin && lMax >= dMax))) {
  10398. best.lmin = lMin;
  10399. best.lmax = lMax;
  10400. best.lstep = lStep;
  10401. best.score = score;
  10402. }
  10403. }
  10404. }
  10405. z += 1;
  10406. }
  10407. k += 1;
  10408. }
  10409. }
  10410. j += 1;
  10411. }
  10412. // 处理精度问题,保证这三个数没有精度问题
  10413. var lmax = prettyNumber(best.lmax);
  10414. var lmin = prettyNumber(best.lmin);
  10415. var lstep = prettyNumber(best.lstep);
  10416. // 加 round 是为处理 extended(0.94, 1, 5)
  10417. // 保证生成的 tickCount 没有精度问题
  10418. var tickCount = Math.floor(round((lmax - lmin) / lstep)) + 1;
  10419. var ticks = new Array(tickCount);
  10420. // 少用乘法:防止出现 -1.2 + 1.2 * 3 = 2.3999999999999995 的情况
  10421. ticks[0] = prettyNumber(lmin);
  10422. for (var i = 1; i < tickCount; i++) {
  10423. ticks[i] = prettyNumber(ticks[i - 1] + lstep);
  10424. }
  10425. return {
  10426. min: Math.min(dMin, head(ticks)),
  10427. max: Math.max(dMax, last(ticks)),
  10428. ticks: ticks,
  10429. };
  10430. }
  10431. /**
  10432. * 计算线性的 ticks,使用 wilkinson extended 方法
  10433. * @param cfg 度量的配置项
  10434. * @returns 计算后的 ticks
  10435. */
  10436. function linear$2(cfg) {
  10437. var min = cfg.min, max = cfg.max, tickCount = cfg.tickCount, nice = cfg.nice, tickInterval = cfg.tickInterval, minLimit = cfg.minLimit, maxLimit = cfg.maxLimit;
  10438. var ticks = extended(min, max, tickCount, nice).ticks;
  10439. if (!isNil(minLimit) || !isNil(maxLimit)) {
  10440. return strictLimit(cfg, head(ticks), last(ticks));
  10441. }
  10442. if (tickInterval) {
  10443. return intervalTicks(min, max, tickInterval).ticks;
  10444. }
  10445. return ticks;
  10446. }
  10447. /**
  10448. * 计算 log 的 ticks,考虑 min = 0 的场景
  10449. * @param cfg 度量的配置项
  10450. * @returns 计算后的 ticks
  10451. */
  10452. function calculateLogTicks(cfg) {
  10453. var base = cfg.base, tickCount = cfg.tickCount, min = cfg.min, max = cfg.max, values = cfg.values;
  10454. var minTick;
  10455. var maxTick = log(base, max);
  10456. if (min > 0) {
  10457. minTick = Math.floor(log(base, min));
  10458. }
  10459. else {
  10460. var positiveMin = getLogPositiveMin(values, base, max);
  10461. minTick = Math.floor(log(base, positiveMin));
  10462. }
  10463. var count = maxTick - minTick;
  10464. var avg = Math.ceil(count / tickCount);
  10465. var ticks = [];
  10466. for (var i = minTick; i < maxTick + avg; i = i + avg) {
  10467. ticks.push(Math.pow(base, i));
  10468. }
  10469. if (min <= 0) {
  10470. // 最小值 <= 0 时显示 0
  10471. ticks.unshift(0);
  10472. }
  10473. return ticks;
  10474. }
  10475. function pretty(min, max, m) {
  10476. if (m === void 0) { m = 5; }
  10477. if (min === max) {
  10478. return {
  10479. max: max,
  10480. min: min,
  10481. ticks: [min],
  10482. };
  10483. }
  10484. var n = m < 0 ? 0 : Math.round(m);
  10485. if (n === 0)
  10486. return { max: max, min: min, ticks: [] };
  10487. /*
  10488. R pretty:
  10489. https://svn.r-project.org/R/trunk/src/appl/pretty.c
  10490. https://www.rdocumentation.org/packages/base/versions/3.5.2/topics/pretty
  10491. */
  10492. var h = 1.5; // high.u.bias
  10493. var h5 = 0.5 + 1.5 * h; // u5.bias
  10494. // 反正我也不会调参,跳过所有判断步骤
  10495. var d = max - min;
  10496. var c = d / n;
  10497. // 当d非常小的时候触发,但似乎没什么用
  10498. // const min_n = Math.floor(n / 3);
  10499. // const shrink_sml = Math.pow(2, 5);
  10500. // if (Math.log10(d) < -2) {
  10501. // c = (_.max([ Math.abs(max), Math.abs(min) ]) * shrink_sml) / min_n;
  10502. // }
  10503. var base = Math.pow(10, Math.floor(Math.log10(c)));
  10504. var unit = base;
  10505. if (2 * base - c < h * (c - unit)) {
  10506. unit = 2 * base;
  10507. if (5 * base - c < h5 * (c - unit)) {
  10508. unit = 5 * base;
  10509. if (10 * base - c < h * (c - unit)) {
  10510. unit = 10 * base;
  10511. }
  10512. }
  10513. }
  10514. var nu = Math.ceil(max / unit);
  10515. var ns = Math.floor(min / unit);
  10516. var hi = Math.max(nu * unit, max);
  10517. var lo = Math.min(ns * unit, min);
  10518. var size = Math.floor((hi - lo) / unit) + 1;
  10519. var ticks = new Array(size);
  10520. for (var i = 0; i < size; i++) {
  10521. ticks[i] = prettyNumber(lo + i * unit);
  10522. }
  10523. return {
  10524. min: lo,
  10525. max: hi,
  10526. ticks: ticks,
  10527. };
  10528. }
  10529. /**
  10530. * 计算 Pow 的 ticks
  10531. * @param cfg 度量的配置项
  10532. * @returns 计算后的 ticks
  10533. */
  10534. function calculatePowTicks(cfg) {
  10535. var exponent = cfg.exponent, tickCount = cfg.tickCount;
  10536. var max = Math.ceil(calBase(exponent, cfg.max));
  10537. var min = Math.floor(calBase(exponent, cfg.min));
  10538. var ticks = pretty(min, max, tickCount).ticks;
  10539. return ticks.map(function (tick) {
  10540. var factor = tick >= 0 ? 1 : -1;
  10541. return Math.pow(tick, exponent) * factor;
  10542. });
  10543. }
  10544. /**
  10545. * 计算几分位 https://github.com/simple-statistics/simple-statistics/blob/master/src/quantile_sorted.js
  10546. * @param x 数组
  10547. * @param p 百分比
  10548. */
  10549. function quantileSorted(x, p) {
  10550. var idx = x.length * p;
  10551. /*if (x.length === 0) { // 当前场景这些条件不可能命中
  10552. throw new Error('quantile requires at least one value.');
  10553. } else if (p < 0 || p > 1) {
  10554. throw new Error('quantiles must be between 0 and 1');
  10555. } else */
  10556. if (p === 1) {
  10557. // If p is 1, directly return the last element
  10558. return x[x.length - 1];
  10559. }
  10560. else if (p === 0) {
  10561. // If p is 0, directly return the first element
  10562. return x[0];
  10563. }
  10564. else if (idx % 1 !== 0) {
  10565. // If p is not integer, return the next element in array
  10566. return x[Math.ceil(idx) - 1];
  10567. }
  10568. else if (x.length % 2 === 0) {
  10569. // If the list has even-length, we'll take the average of this number
  10570. // and the next value, if there is one
  10571. return (x[idx - 1] + x[idx]) / 2;
  10572. }
  10573. else {
  10574. // Finally, in the simple case of an integer value
  10575. // with an odd-length list, return the x value at the index.
  10576. return x[idx];
  10577. }
  10578. }
  10579. function calculateTicks(cfg) {
  10580. var tickCount = cfg.tickCount, values = cfg.values;
  10581. if (!values || !values.length) {
  10582. return [];
  10583. }
  10584. var sorted = values.slice().sort(function (a, b) {
  10585. return a - b;
  10586. });
  10587. var ticks = [];
  10588. for (var i = 0; i < tickCount; i++) {
  10589. var p = i / (tickCount - 1);
  10590. ticks.push(quantileSorted(sorted, p));
  10591. }
  10592. return ticks;
  10593. }
  10594. /**
  10595. * 计算线性的 ticks,使用 R's pretty 方法
  10596. * @param cfg 度量的配置项
  10597. * @returns 计算后的 ticks
  10598. */
  10599. function linearPretty(cfg) {
  10600. var min = cfg.min, max = cfg.max, tickCount = cfg.tickCount, tickInterval = cfg.tickInterval, minLimit = cfg.minLimit, maxLimit = cfg.maxLimit;
  10601. var ticks = pretty(min, max, tickCount).ticks;
  10602. if (!isNil(minLimit) || !isNil(maxLimit)) {
  10603. return strictLimit(cfg, head(ticks), last(ticks));
  10604. }
  10605. if (tickInterval) {
  10606. return intervalTicks(min, max, tickInterval).ticks;
  10607. }
  10608. return ticks;
  10609. }
  10610. function calculateTimeTicks(cfg) {
  10611. var min = cfg.min, max = cfg.max, minTickInterval = cfg.minTickInterval;
  10612. var tickInterval = cfg.tickInterval;
  10613. var tickCount = cfg.tickCount;
  10614. // 指定 tickInterval 后 tickCount 不生效,需要重新计算
  10615. if (tickInterval) {
  10616. tickCount = Math.ceil((max - min) / tickInterval);
  10617. }
  10618. else {
  10619. tickInterval = getTickInterval(min, max, tickCount)[1];
  10620. var count = (max - min) / tickInterval;
  10621. var ratio = count / tickCount;
  10622. if (ratio > 1) {
  10623. tickInterval = tickInterval * Math.ceil(ratio);
  10624. }
  10625. // 如果设置了最小间距,则使用最小间距
  10626. if (minTickInterval && tickInterval < minTickInterval) {
  10627. tickInterval = minTickInterval;
  10628. }
  10629. }
  10630. tickInterval = Math.max(Math.floor((max - min) / (Math.pow(2, 12) - 1)), tickInterval);
  10631. var ticks = [];
  10632. for (var i = min; i < max + tickInterval; i += tickInterval) {
  10633. ticks.push(i);
  10634. }
  10635. return ticks;
  10636. }
  10637. /**
  10638. * 计算时间分类的 ticks, 保头,保尾
  10639. * @param cfg 度量的配置项
  10640. * @returns 计算后的 ticks
  10641. */
  10642. function timeCat(cfg) {
  10643. // 默认保留最后一条
  10644. var ticks = calculateCatTicks(__assign({ showLast: true }, cfg));
  10645. return ticks;
  10646. }
  10647. function getYear(date) {
  10648. return new Date(date).getFullYear();
  10649. }
  10650. function createYear(year) {
  10651. return new Date(year, 0, 1).getTime();
  10652. }
  10653. function getMonth(date) {
  10654. return new Date(date).getMonth();
  10655. }
  10656. function diffMonth(min, max) {
  10657. var minYear = getYear(min);
  10658. var maxYear = getYear(max);
  10659. var minMonth = getMonth(min);
  10660. var maxMonth = getMonth(max);
  10661. return (maxYear - minYear) * 12 + ((maxMonth - minMonth) % 12);
  10662. }
  10663. function creatMonth(year, month) {
  10664. return new Date(year, month, 1).getTime();
  10665. }
  10666. function diffDay(min, max) {
  10667. return Math.ceil((max - min) / DAY);
  10668. }
  10669. function diffHour(min, max) {
  10670. return Math.ceil((max - min) / HOUR);
  10671. }
  10672. function diffMinus(min, max) {
  10673. return Math.ceil((max - min) / (60 * 1000));
  10674. }
  10675. /**
  10676. * 计算 time 的 ticks,对 month, year 进行 pretty 处理
  10677. * @param cfg 度量的配置项
  10678. * @returns 计算后的 ticks
  10679. */
  10680. function timePretty(cfg) {
  10681. var min = cfg.min, max = cfg.max, minTickInterval = cfg.minTickInterval, tickCount = cfg.tickCount;
  10682. var tickInterval = cfg.tickInterval;
  10683. var ticks = [];
  10684. // 指定 tickInterval 后 tickCount 不生效,需要重新计算
  10685. if (!tickInterval) {
  10686. tickInterval = (max - min) / tickCount;
  10687. // 如果设置了最小间距,则使用最小间距
  10688. if (minTickInterval && tickInterval < minTickInterval) {
  10689. tickInterval = minTickInterval;
  10690. }
  10691. }
  10692. tickInterval = Math.max(Math.floor((max - min) / (Math.pow(2, 12) - 1)), tickInterval);
  10693. var minYear = getYear(min);
  10694. // 如果间距大于 1 年,则将开始日期从整年开始
  10695. if (tickInterval > YEAR) {
  10696. var maxYear = getYear(max);
  10697. var yearInterval = Math.ceil(tickInterval / YEAR);
  10698. for (var i = minYear; i <= maxYear + yearInterval; i = i + yearInterval) {
  10699. ticks.push(createYear(i));
  10700. }
  10701. }
  10702. else if (tickInterval > MONTH) {
  10703. // 大于月时
  10704. var monthInterval = Math.ceil(tickInterval / MONTH);
  10705. var mmMoth = getMonth(min);
  10706. var dMonths = diffMonth(min, max);
  10707. for (var i = 0; i <= dMonths + monthInterval; i = i + monthInterval) {
  10708. ticks.push(creatMonth(minYear, i + mmMoth));
  10709. }
  10710. }
  10711. else if (tickInterval > DAY) {
  10712. // 大于天
  10713. var date = new Date(min);
  10714. var year = date.getFullYear();
  10715. var month = date.getMonth();
  10716. var mday = date.getDate();
  10717. var day = Math.ceil(tickInterval / DAY);
  10718. var ddays = diffDay(min, max);
  10719. for (var i = 0; i < ddays + day; i = i + day) {
  10720. ticks.push(new Date(year, month, mday + i).getTime());
  10721. }
  10722. }
  10723. else if (tickInterval > HOUR) {
  10724. // 大于小时
  10725. var date = new Date(min);
  10726. var year = date.getFullYear();
  10727. var month = date.getMonth();
  10728. var day = date.getDate();
  10729. var hour = date.getHours();
  10730. var hours = Math.ceil(tickInterval / HOUR);
  10731. var dHours = diffHour(min, max);
  10732. for (var i = 0; i <= dHours + hours; i = i + hours) {
  10733. ticks.push(new Date(year, month, day, hour + i).getTime());
  10734. }
  10735. }
  10736. else if (tickInterval > MINUTE) {
  10737. // 大于分钟
  10738. var dMinus = diffMinus(min, max);
  10739. var minutes = Math.ceil(tickInterval / MINUTE);
  10740. for (var i = 0; i <= dMinus + minutes; i = i + minutes) {
  10741. ticks.push(min + i * MINUTE);
  10742. }
  10743. }
  10744. else {
  10745. // 小于分钟
  10746. var interval = tickInterval;
  10747. if (interval < SECOND) {
  10748. interval = SECOND;
  10749. }
  10750. var minSecond = Math.floor(min / SECOND) * SECOND;
  10751. var dSeconds = Math.ceil((max - min) / SECOND);
  10752. var seconds = Math.ceil(interval / SECOND);
  10753. for (var i = 0; i < dSeconds + seconds; i = i + seconds) {
  10754. ticks.push(minSecond + i * SECOND);
  10755. }
  10756. }
  10757. // 最好是能从算法能解决这个问题,但是如果指定了 tickInterval,计算 ticks,也只能这么算,所以
  10758. // 打印警告提示
  10759. if (ticks.length >= 512) {
  10760. console.warn("Notice: current ticks length(" + ticks.length + ") >= 512, may cause performance issues, even out of memory. Because of the configure \"tickInterval\"(in milliseconds, current is " + tickInterval + ") is too small, increase the value to solve the problem!");
  10761. }
  10762. return ticks;
  10763. }
  10764. registerTickMethod('cat', calculateCatTicks);
  10765. registerTickMethod('time-cat', timeCat);
  10766. registerTickMethod('wilkinson-extended', linear$2);
  10767. registerTickMethod('r-pretty', linearPretty);
  10768. registerTickMethod('time', calculateTimeTicks);
  10769. registerTickMethod('time-pretty', timePretty);
  10770. registerTickMethod('log', calculateLogTicks);
  10771. registerTickMethod('pow', calculatePowTicks);
  10772. registerTickMethod('quantile', calculateTicks);
  10773. registerTickMethod('d3-linear', d3LinearTickMethod);
  10774. registerClass('cat', Category);
  10775. registerClass('category', Category);
  10776. registerClass('identity', Identity);
  10777. registerClass('linear', Linear);
  10778. registerClass('log', Log);
  10779. registerClass('pow', Pow);
  10780. registerClass('time', Time);
  10781. registerClass('timeCat', TimeCat);
  10782. registerClass('quantize', Quantize);
  10783. registerClass('quantile', Quantile);
  10784. // cat平均算法,保头保尾
  10785. var CatTick = (function (cfg) {
  10786. var values = cfg.values,
  10787. tickCount = cfg.tickCount;
  10788. if (!tickCount) {
  10789. return values;
  10790. }
  10791. if (values.length <= 1) {
  10792. return values;
  10793. }
  10794. // 获取间隔步长, 最小是1
  10795. var step = Math.floor(values.length / (tickCount - 1)) || 1;
  10796. var ticks = [];
  10797. // 按间隔数取对应节点
  10798. for (var index = 0; index < values.length; index = index + step) {
  10799. ticks.push(values[index]);
  10800. }
  10801. var last = values[values.length - 1];
  10802. // 如果最后一个tick不等于原数据的最后一个
  10803. if (ticks[ticks.length - 1] !== last) {
  10804. if (ticks.length >= tickCount) {
  10805. // 如果当前的tick个数满足要求
  10806. ticks[ticks.length - 1] = last;
  10807. } else {
  10808. // 不满足tickCount则直接加入最后一个
  10809. ticks.push(last);
  10810. }
  10811. }
  10812. return ticks;
  10813. });
  10814. // 认为是nice的刻度
  10815. var SNAP_COUNT_ARRAY = [1, 1.2, 1.5, 2, 2.2, 2.4, 2.5, 3, 4, 5, 6, 7.5, 8, 10];
  10816. var DEFAULT_COUNT$1 = 5; // 默认刻度值
  10817. var LinearTick = (function (cfg) {
  10818. var _ref = cfg || {},
  10819. tickCount = _ref.tickCount,
  10820. tickInterval = _ref.tickInterval;
  10821. var _ref2 = cfg || {},
  10822. min = _ref2.min,
  10823. max = _ref2.max;
  10824. min = isNaN(min) ? 0 : min;
  10825. max = isNaN(max) ? 0 : max;
  10826. var count = tickCount && tickCount >= 2 ? tickCount : DEFAULT_COUNT$1;
  10827. // 计算interval, 优先取tickInterval
  10828. var interval = tickInterval || getBestInterval({
  10829. tickCount: count,
  10830. max: max,
  10831. min: min
  10832. });
  10833. // 通过interval计算最小tick
  10834. var minTick = Math.floor(min / interval) * interval;
  10835. // 如果指定了tickInterval, count 需要根据指定的tickInterval来算计
  10836. if (tickInterval) {
  10837. var intervalCount = Math.abs(Math.ceil((max - minTick) / tickInterval)) + 1;
  10838. // tickCount 作为最小 count 处理
  10839. count = Math.max(count, intervalCount);
  10840. }
  10841. var tickLength = 0;
  10842. var fixedLength = getFixedLength(interval);
  10843. if (min < 0 && max > 0 && count === 2) {
  10844. return [toFixed(minTick, fixedLength), toFixed(Math.ceil(max / interval) * interval, fixedLength)];
  10845. }
  10846. var ticks = [];
  10847. while (tickLength < count) {
  10848. ticks.push(toFixed(minTick + tickLength * interval, fixedLength));
  10849. tickLength++;
  10850. }
  10851. return ticks;
  10852. });
  10853. var DECIMAL_LENGTH = 12;
  10854. function getFactor(number) {
  10855. // 取正数
  10856. number = Math.abs(number);
  10857. var factor = 1;
  10858. if (number === 0) {
  10859. return factor;
  10860. }
  10861. // 小于1,逐渐放大
  10862. if (number < 1) {
  10863. var count = 0;
  10864. while (number < 1) {
  10865. factor = factor / 10;
  10866. number = number * 10;
  10867. count++;
  10868. }
  10869. // 浮点数计算出现问题
  10870. if (factor.toString().length > DECIMAL_LENGTH) {
  10871. factor = parseFloat(factor.toFixed(count));
  10872. }
  10873. return factor;
  10874. }
  10875. // 大于10逐渐缩小
  10876. while (number > 10) {
  10877. factor = factor * 10;
  10878. number = number / 10;
  10879. }
  10880. return factor;
  10881. }
  10882. // 获取最佳匹配刻度
  10883. function getBestInterval(_ref3) {
  10884. var tickCount = _ref3.tickCount,
  10885. min = _ref3.min,
  10886. max = _ref3.max;
  10887. // 如果最大最小相等,则直接按1处理
  10888. if (min === max) {
  10889. return 1 * getFactor(max);
  10890. }
  10891. // 1.计算平均刻度间隔
  10892. var avgInterval = (max - min) / (tickCount - 1);
  10893. // 2.数据标准归一化 映射到[1-10]区间
  10894. var factor = getFactor(avgInterval);
  10895. var calInterval = avgInterval / factor;
  10896. var calMax = max / factor;
  10897. var calMin = min / factor;
  10898. // 根据平均值推算最逼近刻度值
  10899. var similarityIndex = 0;
  10900. for (var index = 0; index < SNAP_COUNT_ARRAY.length; index++) {
  10901. var item = SNAP_COUNT_ARRAY[index];
  10902. if (calInterval <= item) {
  10903. similarityIndex = index;
  10904. break;
  10905. }
  10906. }
  10907. var similarityInterval = min < 0 && max > 0 && tickCount === 2 ? SNAP_COUNT_ARRAY[similarityIndex] : getInterval(similarityIndex, tickCount, calMin, calMax);
  10908. // 小数点位数还原到数据的位数, 因为similarityIndex有可能是小数,所以需要保留similarityIndex自己的小数位数
  10909. var fixedLength = getFixedLength(similarityInterval) + getFixedLength(factor);
  10910. return toFixed(similarityInterval * factor, fixedLength);
  10911. }
  10912. function getInterval(startIndex, tickCount, min, max) {
  10913. var verify = false;
  10914. var interval = SNAP_COUNT_ARRAY[startIndex];
  10915. // 刻度值校验,如果不满足,循环下去
  10916. for (var i = startIndex; i < SNAP_COUNT_ARRAY.length; i++) {
  10917. if (intervalIsVerify({
  10918. interval: SNAP_COUNT_ARRAY[i],
  10919. tickCount: tickCount,
  10920. max: max,
  10921. min: min
  10922. })) {
  10923. // 有符合条件的interval
  10924. interval = SNAP_COUNT_ARRAY[i];
  10925. verify = true;
  10926. break;
  10927. }
  10928. }
  10929. // 如果不满足, 依次缩小10倍,再计算
  10930. if (!verify) {
  10931. return 10 * getInterval(0, tickCount, min / 10, max / 10);
  10932. }
  10933. return interval;
  10934. }
  10935. // 刻度是否满足展示需求
  10936. function intervalIsVerify(_ref4) {
  10937. var interval = _ref4.interval,
  10938. tickCount = _ref4.tickCount,
  10939. max = _ref4.max,
  10940. min = _ref4.min;
  10941. var minTick = Math.floor(min / interval) * interval;
  10942. if (minTick + (tickCount - 1) * interval >= max) {
  10943. return true;
  10944. }
  10945. return false;
  10946. }
  10947. // 计算小数点应该保留的位数
  10948. function getFixedLength(num) {
  10949. var str = num.toString();
  10950. var index = str.indexOf('.');
  10951. var indexOfExp = str.indexOf('e-');
  10952. var length = indexOfExp >= 0 ? parseInt(str.substr(indexOfExp + 2), 10) : str.substr(index + 1).length;
  10953. if (length > 20) {
  10954. // 最多保留20位小数
  10955. length = 20;
  10956. }
  10957. return length;
  10958. }
  10959. // @antv/util fixedbase不支持科学计数法的判断,需要提mr
  10960. function toFixed(v, length) {
  10961. return parseFloat(v.toFixed(length));
  10962. }
  10963. // 覆盖0.3.x的 cat 方法
  10964. registerTickMethod('cat', CatTick);
  10965. registerTickMethod('time-cat', CatTick);
  10966. // 覆盖linear 度量的tick算法
  10967. registerTickMethod('wilkinson-extended', LinearTick);
  10968. var ScaleController = /*#__PURE__*/function () {
  10969. function ScaleController(data) {
  10970. _classCallCheck(this, ScaleController);
  10971. this.data = data;
  10972. this.options = {};
  10973. this.scales = {};
  10974. }
  10975. _createClass(ScaleController, [{
  10976. key: "_getType",
  10977. value: function _getType(option) {
  10978. var type = option.type,
  10979. values = option.values,
  10980. field = option.field;
  10981. if (type) {
  10982. return type;
  10983. }
  10984. if (isNumber(field) || isNil(values[0]) && field) {
  10985. return 'identity';
  10986. }
  10987. if (typeof values[0] === 'number') {
  10988. return 'linear';
  10989. }
  10990. return 'cat';
  10991. }
  10992. }, {
  10993. key: "_getOption",
  10994. value: function _getOption(option) {
  10995. var values = option.values,
  10996. field = option.field,
  10997. justifyContent = option.justifyContent;
  10998. var type = this._getType(option);
  10999. option.type = type;
  11000. // identity
  11001. if (type === 'identity') {
  11002. option.field = field.toString();
  11003. option.values = [field];
  11004. return option;
  11005. }
  11006. // linear 类型
  11007. if (type === 'linear') {
  11008. // 设置默认nice
  11009. if (typeof option.nice !== 'boolean') {
  11010. option.nice = true;
  11011. }
  11012. // 重置最大最小
  11013. var _getRange = getRange(values),
  11014. min = _getRange.min,
  11015. max = _getRange.max;
  11016. if (isNil(option.min)) {
  11017. option.min = min;
  11018. }
  11019. if (isNil(option.max)) {
  11020. option.max = max;
  11021. }
  11022. option.values = values.sort(function (a, b) {
  11023. return a - b;
  11024. });
  11025. return option;
  11026. }
  11027. // 分类类型和 timeCat 类型,调整 range
  11028. if (type === 'cat' || type === 'timeCat') {
  11029. if (option.range) {
  11030. return option;
  11031. }
  11032. var count = values.length;
  11033. var range = [0, 1];
  11034. // 如果只有一项,显示在中间
  11035. if (count === 1) {
  11036. range = [0.5, 1];
  11037. } else if (justifyContent) {
  11038. // 居中
  11039. var offset = 1 / count * 0.5;
  11040. range = [offset, 1 - offset];
  11041. } else {
  11042. // 最后留 1 / count
  11043. var _offset = 1 / count;
  11044. range = [0, 1 - _offset];
  11045. }
  11046. option.range = range;
  11047. }
  11048. return option;
  11049. }
  11050. }, {
  11051. key: "createScale",
  11052. value: function createScale(option) {
  11053. var type = option.type;
  11054. if (isFunction(type)) {
  11055. return new type(option);
  11056. }
  11057. var ScaleClass = getClass(type);
  11058. return new ScaleClass(option);
  11059. }
  11060. // 更新或创建scale
  11061. }, {
  11062. key: "setScale",
  11063. value: function setScale(field, option) {
  11064. var options = this.options,
  11065. scales = this.scales;
  11066. options[field] = mix({}, options[field], option);
  11067. // 如果scale有更新,scale 也需要重新创建
  11068. if (scales[field]) {
  11069. delete scales[field];
  11070. }
  11071. }
  11072. }, {
  11073. key: "create",
  11074. value: function create(options) {
  11075. this.update(options);
  11076. }
  11077. }, {
  11078. key: "update",
  11079. value: function update(options) {
  11080. var _this = this;
  11081. if (!options) return;
  11082. each(options, function (option, field) {
  11083. _this.setScale(field, option);
  11084. });
  11085. // 为了让外部感知到scale有变化
  11086. this.scales = _objectSpread({}, this.scales);
  11087. }
  11088. }, {
  11089. key: "changeData",
  11090. value: function changeData(data) {
  11091. this.data = data;
  11092. this.scales = {};
  11093. }
  11094. }, {
  11095. key: "getData",
  11096. value: function getData() {
  11097. return this.data;
  11098. }
  11099. }, {
  11100. key: "getScale",
  11101. value: function getScale(field) {
  11102. var scales = this.scales,
  11103. options = this.options,
  11104. data = this.data;
  11105. var scale = scales[field];
  11106. if (scale) {
  11107. return scale;
  11108. }
  11109. var option = options[field];
  11110. if (!option) {
  11111. return null;
  11112. }
  11113. var values = option.values ? option.values : data ? valuesOfKey(data, field) : [];
  11114. var scaleOption = this._getOption(_objectSpread(_objectSpread({}, option), {}, {
  11115. field: field,
  11116. values: values
  11117. }));
  11118. var newScale = this.createScale(scaleOption);
  11119. scales[field] = newScale;
  11120. return newScale;
  11121. }
  11122. }, {
  11123. key: "getScales",
  11124. value: function getScales() {
  11125. var _this2 = this;
  11126. var options = this.options,
  11127. scales = this.scales;
  11128. each(options, function (option, field) {
  11129. _this2.getScale(field);
  11130. });
  11131. return scales;
  11132. }
  11133. }, {
  11134. key: "adjustStartZero",
  11135. value: function adjustStartZero(scale) {
  11136. var options = this.options;
  11137. var field = scale.field,
  11138. min = scale.min,
  11139. max = scale.max;
  11140. var option = options[field];
  11141. // 如果有定义,则不处理
  11142. if (option && option.min) {
  11143. return;
  11144. }
  11145. if (min > 0) {
  11146. scale.change({
  11147. min: 0
  11148. });
  11149. } else if (max < 0) {
  11150. scale.change({
  11151. max: 0
  11152. });
  11153. }
  11154. }
  11155. // 饼图下的scale调整
  11156. }, {
  11157. key: "adjustPieScale",
  11158. value: function adjustPieScale(scale) {
  11159. var options = this.options;
  11160. var field = scale.field;
  11161. var option = options[field];
  11162. if (option && !isNil(option.nice)) {
  11163. return null;
  11164. }
  11165. scale.change({
  11166. nice: false
  11167. });
  11168. }
  11169. // 获取scale 在 0点对位置的值
  11170. }, {
  11171. key: "getZeroValue",
  11172. value: function getZeroValue(scale) {
  11173. var min = scale.min,
  11174. max = scale.max;
  11175. var value;
  11176. if (min >= 0) {
  11177. value = min;
  11178. } else if (max <= 0) {
  11179. value = max;
  11180. } else {
  11181. value = 0;
  11182. }
  11183. return scale.scale(value);
  11184. }
  11185. }]);
  11186. return ScaleController;
  11187. }();
  11188. // 统计图表
  11189. var Chart = /*#__PURE__*/function (_Component) {
  11190. _inherits(Chart, _Component);
  11191. var _super = _createSuper(Chart);
  11192. function Chart(props, context, updater) {
  11193. var _this;
  11194. _classCallCheck(this, Chart);
  11195. _this = _super.call(this, props, context, updater);
  11196. _this.componentsPosition = [];
  11197. var data = props.data,
  11198. coordOption = props.coord,
  11199. _props$scale = props.scale,
  11200. scale = _props$scale === void 0 ? [] : _props$scale;
  11201. _this.layoutController = new LayoutController();
  11202. _this.coordController = new coordController();
  11203. _this.scaleController = new ScaleController(data);
  11204. _this.scale = _this.scaleController;
  11205. var _assertThisInitialize = _assertThisInitialized(_this),
  11206. layoutController = _assertThisInitialize.layoutController,
  11207. coordController$1 = _assertThisInitialize.coordController,
  11208. scaleController = _assertThisInitialize.scaleController;
  11209. // 布局
  11210. var style = _this.getStyle(props, context);
  11211. _this.layout = layoutController.create(style);
  11212. // 坐标系
  11213. _this.coord = coordController$1.create(coordOption, _this.layout);
  11214. // scale
  11215. scaleController.create(scale);
  11216. _this.data = data;
  11217. // state
  11218. _this.state = {
  11219. filters: {}
  11220. };
  11221. return _this;
  11222. }
  11223. // props 更新
  11224. _createClass(Chart, [{
  11225. key: "willReceiveProps",
  11226. value: function willReceiveProps(nextProps, context) {
  11227. var layoutController = this.layoutController,
  11228. coordController = this.coordController,
  11229. scaleController = this.scaleController,
  11230. lastProps = this.props;
  11231. var nextStyle = nextProps.style,
  11232. nextData = nextProps.data,
  11233. nextScale = nextProps.scale;
  11234. var lastStyle = lastProps.style,
  11235. lastData = lastProps.data,
  11236. lastScale = lastProps.scale;
  11237. // 布局
  11238. if (!equal(nextStyle, lastStyle) || context !== this.context) {
  11239. var style = this.getStyle(nextProps, context);
  11240. this.layout = layoutController.create(style);
  11241. coordController.updateLayout(this.layout);
  11242. }
  11243. if (nextData !== lastData) {
  11244. scaleController.changeData(nextData);
  11245. }
  11246. // scale
  11247. if (!equal(nextScale, lastScale)) {
  11248. scaleController.update(nextScale);
  11249. }
  11250. }
  11251. }, {
  11252. key: "willUpdate",
  11253. value: function willUpdate() {
  11254. var coordController = this.coordController,
  11255. props = this.props;
  11256. // render 时要重置 coord 范围,重置后需要让所有子组件都重新render
  11257. // 所以这里不比较是否有差异,每次都新建,让所有子组件重新render
  11258. this.coord = coordController.create(props.coord, this.layout);
  11259. }
  11260. }, {
  11261. key: "getStyle",
  11262. value: function getStyle(props, context) {
  11263. var theme = context.theme,
  11264. px2hd = context.px2hd,
  11265. left = context.left,
  11266. top = context.top,
  11267. width = context.width,
  11268. height = context.height;
  11269. var style = props.style;
  11270. return px2hd(_objectSpread(_objectSpread({
  11271. left: left,
  11272. top: top,
  11273. width: width,
  11274. height: height
  11275. }, theme.chart), style));
  11276. }
  11277. // 给需要显示的组件留空
  11278. }, {
  11279. key: "layoutCoord",
  11280. value: function layoutCoord(layout) {
  11281. var coord = this.coord;
  11282. var position = layout.position,
  11283. boxWidth = layout.width,
  11284. boxHeight = layout.height;
  11285. var left = coord.left,
  11286. top = coord.top,
  11287. width = coord.width,
  11288. height = coord.height;
  11289. switch (position) {
  11290. case 'left':
  11291. left += boxWidth;
  11292. width = Math.max(0, width - boxWidth);
  11293. break;
  11294. case 'right':
  11295. width = Math.max(0, width - boxWidth);
  11296. break;
  11297. case 'top':
  11298. top += boxHeight;
  11299. height = Math.max(0, height - boxHeight);
  11300. break;
  11301. case 'bottom':
  11302. height = Math.max(0, height - boxHeight);
  11303. break;
  11304. }
  11305. coord.update({
  11306. left: left,
  11307. top: top,
  11308. width: width,
  11309. height: height
  11310. });
  11311. }
  11312. }, {
  11313. key: "resetCoordLayout",
  11314. value: function resetCoordLayout() {
  11315. var coord = this.coord,
  11316. layout = this.layout;
  11317. coord.update(layout);
  11318. }
  11319. }, {
  11320. key: "updateCoordLayout",
  11321. value: function updateCoordLayout(layout) {
  11322. var _this2 = this;
  11323. if (isArray(layout)) {
  11324. layout.forEach(function (item) {
  11325. _this2.layoutCoord(item);
  11326. });
  11327. return;
  11328. }
  11329. this.layoutCoord(layout);
  11330. }
  11331. }, {
  11332. key: "updateCoordFor",
  11333. value: function updateCoordFor(component, layout) {
  11334. var _this3 = this;
  11335. if (!layout) return;
  11336. var componentsPosition = this.componentsPosition;
  11337. var componentPosition = {
  11338. component: component,
  11339. layout: layout
  11340. };
  11341. var existIndex = findIndex(componentsPosition, function (item) {
  11342. return item.component === component;
  11343. });
  11344. // 说明是已经存在的组件
  11345. if (existIndex > -1) {
  11346. componentsPosition.splice(existIndex, 1, componentPosition);
  11347. // 先重置,然后整体重新算一次
  11348. this.resetCoordLayout();
  11349. componentsPosition.forEach(function (componentPosition) {
  11350. var layout = componentPosition.layout;
  11351. _this3.updateCoordLayout(layout);
  11352. });
  11353. return;
  11354. }
  11355. // 是新组件,直接添加
  11356. componentsPosition.push(componentPosition);
  11357. this.updateCoordLayout(layout);
  11358. }
  11359. }, {
  11360. key: "getGeometrys",
  11361. value: function getGeometrys() {
  11362. var children = this.children;
  11363. var geometrys = [];
  11364. // @ts-ignore
  11365. Children.toArray(children).forEach(function (element) {
  11366. if (!element) return false;
  11367. var component = element.component;
  11368. if (component && component.isGeometry) {
  11369. geometrys.push(component);
  11370. }
  11371. });
  11372. return geometrys;
  11373. }
  11374. /**
  11375. * calculate dataset's position on canvas
  11376. * @param {Object} record the dataset
  11377. * @return {Object} return the position
  11378. */
  11379. }, {
  11380. key: "getPosition",
  11381. value: function getPosition(record) {
  11382. var coord = this.getCoord();
  11383. var xScale = this.getXScales()[0];
  11384. var xField = xScale.field;
  11385. var yScales = this.getYScales();
  11386. // default first
  11387. var yScale = yScales[0];
  11388. var yField = yScale.field;
  11389. for (var i = 0, len = yScales.length; i < len; i++) {
  11390. var scale = yScales[i];
  11391. var field = scale.field;
  11392. if (record[field]) {
  11393. yScale = scale;
  11394. yField = field;
  11395. break;
  11396. }
  11397. }
  11398. var x = xScale.scale(record[xField]);
  11399. var y = yScale.scale(record[yField]);
  11400. return coord.convertPoint({
  11401. x: x,
  11402. y: y
  11403. });
  11404. }
  11405. }, {
  11406. key: "getSnapRecords",
  11407. value: function getSnapRecords(point, inCoordRange) {
  11408. var geometrys = this.getGeometrys();
  11409. if (!geometrys.length) return;
  11410. // @ts-ignore
  11411. return geometrys[0].getSnapRecords(point, inCoordRange);
  11412. }
  11413. }, {
  11414. key: "getLegendItems",
  11415. value: function getLegendItems(point) {
  11416. var geometrys = this.getGeometrys();
  11417. if (!geometrys.length) return;
  11418. // @ts-ignore
  11419. return geometrys[0].getLegendItems(point);
  11420. }
  11421. }, {
  11422. key: "setScale",
  11423. value: function setScale(field, option) {
  11424. this.scaleController.setScale(field, option);
  11425. }
  11426. }, {
  11427. key: "getScale",
  11428. value: function getScale(field) {
  11429. return this.scaleController.getScale(field);
  11430. }
  11431. }, {
  11432. key: "getScales",
  11433. value: function getScales() {
  11434. return this.scaleController.getScales();
  11435. }
  11436. }, {
  11437. key: "getXScales",
  11438. value: function getXScales() {
  11439. var geometrys = this.getGeometrys();
  11440. return geometrys.map(function (component) {
  11441. // @ts-ignore
  11442. return component.getXScale();
  11443. });
  11444. }
  11445. }, {
  11446. key: "getYScales",
  11447. value: function getYScales() {
  11448. var geometrys = this.getGeometrys();
  11449. return geometrys.map(function (component) {
  11450. // @ts-ignore
  11451. return component.getYScale();
  11452. });
  11453. }
  11454. }, {
  11455. key: "getCoord",
  11456. value: function getCoord() {
  11457. return this.coord;
  11458. }
  11459. }, {
  11460. key: "filter",
  11461. value: function filter(field, condition) {
  11462. var filters = this.state.filters;
  11463. this.setState({
  11464. filters: _objectSpread(_objectSpread({}, filters), {}, _defineProperty({}, field, condition))
  11465. });
  11466. }
  11467. }, {
  11468. key: "_getRenderData",
  11469. value: function _getRenderData() {
  11470. var props = this.props,
  11471. state = this.state;
  11472. var data = props.data;
  11473. var filters = state.filters;
  11474. if (!filters || !Object.keys(filters).length) {
  11475. return data;
  11476. }
  11477. var filteredData = data;
  11478. each(filters, function (condition, field) {
  11479. if (!condition) return;
  11480. filteredData = filteredData.filter(function (record) {
  11481. return condition(record[field], record);
  11482. });
  11483. });
  11484. return filteredData;
  11485. }
  11486. }, {
  11487. key: "render",
  11488. value: function render() {
  11489. var _this4 = this;
  11490. var props = this.props,
  11491. layout = this.layout,
  11492. coord = this.coord;
  11493. var children = props.children,
  11494. originData = props.data;
  11495. if (!originData) return null;
  11496. var data = this._getRenderData();
  11497. return Children.map(children, function (child) {
  11498. return Children.cloneElement(child, {
  11499. chart: _this4,
  11500. coord: coord,
  11501. data: data,
  11502. layout: layout
  11503. });
  11504. });
  11505. }
  11506. }]);
  11507. return Chart;
  11508. }(Component);
  11509. function isEqual(origin1, origin2, fields) {
  11510. if (origin1 === origin2) {
  11511. return true;
  11512. }
  11513. for (var i = 0, len = fields.length; i < len; i++) {
  11514. var field = fields[i];
  11515. if (origin1[field] !== origin2[field]) {
  11516. return false;
  11517. }
  11518. }
  11519. return true;
  11520. }
  11521. var Selection = /*#__PURE__*/function (_Component) {
  11522. _inherits(Selection, _Component);
  11523. var _super = _createSuper(Selection);
  11524. function Selection(props, context) {
  11525. var _this;
  11526. _classCallCheck(this, Selection);
  11527. _this = _super.call(this, props, context);
  11528. var selection = props.selection;
  11529. if (!selection) return _possibleConstructorReturn(_this);
  11530. var defaultSelected = selection.defaultSelected;
  11531. _this.state.selected = defaultSelected;
  11532. return _this;
  11533. }
  11534. _createClass(Selection, [{
  11535. key: "didMount",
  11536. value: function didMount() {
  11537. var _this2 = this;
  11538. var props = this.props,
  11539. state = this.state,
  11540. container = this.container;
  11541. var canvas = container.get('canvas');
  11542. var selection = props.selection,
  11543. chart = props.chart;
  11544. if (!selection) return;
  11545. // 默认为 click
  11546. var _selection$triggerOn = selection.triggerOn,
  11547. triggerOn = _selection$triggerOn === void 0 ? 'click' : _selection$triggerOn;
  11548. canvas.on(triggerOn, function (ev) {
  11549. var points = ev.points;
  11550. var records = _this2.getSnapRecords(points[0]);
  11551. var _selection$type = selection.type,
  11552. type = _selection$type === void 0 ? 'single' : _selection$type,
  11553. _selection$cancelable = selection.cancelable,
  11554. cancelable = _selection$cancelable === void 0 ? true : _selection$cancelable;
  11555. if (!records || !records.length) {
  11556. if (cancelable) {
  11557. _this2.setState({
  11558. selected: null
  11559. });
  11560. }
  11561. return;
  11562. }
  11563. var selected = state.selected;
  11564. var origins = records.map(function (record) {
  11565. return record.origin;
  11566. });
  11567. if (!selected || !selected.length) {
  11568. _this2.setState({
  11569. selected: origins
  11570. });
  11571. }
  11572. if (type === 'single') {
  11573. if (!cancelable) {
  11574. _this2.setState({
  11575. selected: origins
  11576. });
  11577. return;
  11578. }
  11579. var _newSelected = [];
  11580. records.forEach(function (record) {
  11581. if (!_this2.isSelected(record)) {
  11582. _newSelected.push(record.origin);
  11583. }
  11584. });
  11585. _this2.setState({
  11586. selected: _newSelected
  11587. });
  11588. return;
  11589. }
  11590. // 多选
  11591. var scales = chart.getScales();
  11592. var fields = Object.keys(scales);
  11593. var selectedMap = {};
  11594. selected.forEach(function (item) {
  11595. var key = fields.map(function (field) {
  11596. return item[field];
  11597. }).join('-');
  11598. selectedMap[key] = item;
  11599. });
  11600. records.forEach(function (record) {
  11601. var origin = record.origin;
  11602. var key = fields.map(function (field) {
  11603. return origin[field];
  11604. }).join('-');
  11605. selectedMap[key] = selectedMap[key] ? null : origin;
  11606. });
  11607. var newSelected = Object.keys(selectedMap).map(function (key) {
  11608. return selectedMap[key];
  11609. }).filter(Boolean);
  11610. _this2.setState({
  11611. selected: newSelected
  11612. });
  11613. });
  11614. }
  11615. }, {
  11616. key: "willReceiveProps",
  11617. value: function willReceiveProps(nextProps) {
  11618. var nextSelection = nextProps.selection;
  11619. var lastSelection = this.props.selection;
  11620. if (!nextSelection || !lastSelection) {
  11621. return;
  11622. }
  11623. var nextDefaultSelected = nextSelection.defaultSelected;
  11624. var lastDefaultSelected = lastSelection.defaultSelected;
  11625. if (!equal(nextDefaultSelected, lastDefaultSelected)) {
  11626. this.state.selected = nextDefaultSelected;
  11627. }
  11628. }
  11629. }, {
  11630. key: "getSnapRecords",
  11631. value: function getSnapRecords(_point) {
  11632. return null;
  11633. }
  11634. }, {
  11635. key: "isSelected",
  11636. value: function isSelected(record) {
  11637. var state = this.state,
  11638. props = this.props;
  11639. var selected = state.selected;
  11640. if (!selected || !selected.length) {
  11641. return false;
  11642. }
  11643. var chart = props.chart;
  11644. var scales = chart.getScales();
  11645. var fields = Object.keys(scales);
  11646. for (var i = 0, len = selected.length; i < len; i++) {
  11647. var item = selected[i];
  11648. if (isEqual(record.origin, item, fields)) {
  11649. return true;
  11650. }
  11651. }
  11652. return false;
  11653. }
  11654. }, {
  11655. key: "getSelectionStyle",
  11656. value: function getSelectionStyle(record) {
  11657. var state = this.state,
  11658. props = this.props;
  11659. var selected = state.selected;
  11660. if (!selected || !selected.length) {
  11661. return null;
  11662. }
  11663. var selection = props.selection;
  11664. var selectedStyle = selection.selectedStyle,
  11665. unSelectedStyle = selection.unSelectedStyle;
  11666. var isSelected = this.isSelected(record);
  11667. if (isSelected) {
  11668. return isFunction(selectedStyle) ? selectedStyle(record) : selectedStyle;
  11669. }
  11670. return isFunction(unSelectedStyle) ? unSelectedStyle(record) : unSelectedStyle;
  11671. }
  11672. }]);
  11673. return Selection;
  11674. }(Component);
  11675. var DEFAULT_Y = 0; // 默认的 y 的值
  11676. // 偏移之后,间距
  11677. var MARGIN_RATIO = 1 / 2;
  11678. var DODGE_RATIO = 1 / 2;
  11679. // 散点分开之后,距离边界的距离
  11680. var GAP = 0.05;
  11681. var Adjust = /** @class */ (function () {
  11682. function Adjust(cfg) {
  11683. var xField = cfg.xField, yField = cfg.yField, _a = cfg.adjustNames, adjustNames = _a === void 0 ? ['x', 'y'] : _a, dimValuesMap = cfg.dimValuesMap;
  11684. this.adjustNames = adjustNames;
  11685. this.xField = xField;
  11686. this.yField = yField;
  11687. this.dimValuesMap = dimValuesMap;
  11688. }
  11689. /**
  11690. * 查看维度是否是 adjust 字段
  11691. * @param dim
  11692. */
  11693. Adjust.prototype.isAdjust = function (dim) {
  11694. return this.adjustNames.indexOf(dim) >= 0;
  11695. };
  11696. Adjust.prototype.getAdjustRange = function (dim, dimValue, values) {
  11697. var yField = this.yField;
  11698. var index = values.indexOf(dimValue);
  11699. var length = values.length;
  11700. var pre;
  11701. var next;
  11702. // 没有 y 字段,但是需要根据 y 调整
  11703. if (!yField && this.isAdjust('y')) {
  11704. pre = 0;
  11705. next = 1;
  11706. }
  11707. else if (length > 1) {
  11708. // 如果以其开头,则取之,否则取他前面一个
  11709. pre = values[index === 0 ? 0 : index - 1];
  11710. // 如果以其结尾,则取之,否则取他后面一个
  11711. next = values[index === length - 1 ? length - 1 : index + 1];
  11712. if (index !== 0) {
  11713. pre += (dimValue - pre) / 2;
  11714. }
  11715. else {
  11716. pre -= (next - dimValue) / 2;
  11717. }
  11718. if (index !== length - 1) {
  11719. next -= (next - dimValue) / 2;
  11720. }
  11721. else {
  11722. next += (dimValue - values[length - 2]) / 2;
  11723. }
  11724. }
  11725. else {
  11726. pre = dimValue === 0 ? 0 : dimValue - 0.5;
  11727. next = dimValue === 0 ? 1 : dimValue + 0.5;
  11728. }
  11729. return {
  11730. pre: pre,
  11731. next: next,
  11732. };
  11733. };
  11734. Adjust.prototype.adjustData = function (groupedDataArray, mergedData) {
  11735. var _this = this;
  11736. // 所有调整维度的值数组
  11737. var dimValuesMap = this.getDimValues(mergedData);
  11738. // 按照每一个分组来进行调整
  11739. each(groupedDataArray, function (dataArray, index) {
  11740. // 遍历所有数据集合
  11741. // 每个分组中,分别按照不同的 dim 进行调整
  11742. each(dimValuesMap, function (values, dim) {
  11743. // 根据不同的度量分别调整位置
  11744. _this.adjustDim(dim, values, dataArray, index);
  11745. });
  11746. });
  11747. };
  11748. /**
  11749. * 对数据进行分组adjustData
  11750. * @param data 数据
  11751. * @param dim 分组的字段
  11752. * @return 分组结果
  11753. */
  11754. Adjust.prototype.groupData = function (data, dim) {
  11755. // 补齐数据空数据为默认值
  11756. each(data, function (record) {
  11757. if (record[dim] === undefined) {
  11758. record[dim] = DEFAULT_Y;
  11759. }
  11760. });
  11761. // 按照 dim 维度分组
  11762. return groupBy(data, dim);
  11763. };
  11764. /** @override */
  11765. Adjust.prototype.adjustDim = function (dim, values, data, index) { };
  11766. /**
  11767. * 获取可调整度量对应的值
  11768. * @param mergedData 数据
  11769. * @return 值的映射
  11770. */
  11771. Adjust.prototype.getDimValues = function (mergedData) {
  11772. var _a = this, xField = _a.xField, yField = _a.yField;
  11773. var dimValuesMap = mix({}, this.dimValuesMap);
  11774. // 所有的维度
  11775. var dims = [];
  11776. if (xField && this.isAdjust('x')) {
  11777. dims.push(xField);
  11778. }
  11779. if (yField && this.isAdjust('y')) {
  11780. dims.push(yField);
  11781. }
  11782. dims.forEach(function (dim) {
  11783. if (dimValuesMap && dimValuesMap[dim]) {
  11784. return;
  11785. }
  11786. // 在每个维度上,所有的值
  11787. dimValuesMap[dim] = valuesOfKey(mergedData, dim).sort(function (v1, v2) { return v1 - v2; });
  11788. });
  11789. // 只有一维的情况下,同时调整 y,赋予默认值
  11790. if (!yField && this.isAdjust('y')) {
  11791. var dim = 'y';
  11792. dimValuesMap[dim] = [DEFAULT_Y, 1]; // 默认分布在 y 轴的 0 与 1 之间
  11793. }
  11794. return dimValuesMap;
  11795. };
  11796. return Adjust;
  11797. }());
  11798. var ADJUST_MAP = {};
  11799. /**
  11800. * 根据类型获取 Adjust 类
  11801. * @param type
  11802. */
  11803. var getAdjust = function (type) {
  11804. return ADJUST_MAP[type.toLowerCase()];
  11805. };
  11806. /**
  11807. * 注册自定义 Adjust
  11808. * @param type
  11809. * @param ctor
  11810. */
  11811. var registerAdjust = function (type, ctor) {
  11812. // 注册的时候,需要校验 type 重名,不区分大小写
  11813. if (getAdjust(type)) {
  11814. throw new Error("Adjust type '" + type + "' existed.");
  11815. }
  11816. // 存储到 map 中
  11817. ADJUST_MAP[type.toLowerCase()] = ctor;
  11818. };
  11819. /*! *****************************************************************************
  11820. Copyright (c) Microsoft Corporation.
  11821. Permission to use, copy, modify, and/or distribute this software for any
  11822. purpose with or without fee is hereby granted.
  11823. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
  11824. REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  11825. AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
  11826. INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11827. LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  11828. OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  11829. PERFORMANCE OF THIS SOFTWARE.
  11830. ***************************************************************************** */
  11831. /* global Reflect, Promise */
  11832. var _extendStatics = function extendStatics(d, b) {
  11833. _extendStatics = Object.setPrototypeOf || {
  11834. __proto__: []
  11835. } instanceof Array && function (d, b) {
  11836. d.__proto__ = b;
  11837. } || function (d, b) {
  11838. for (var p in b) {
  11839. if (b.hasOwnProperty(p)) d[p] = b[p];
  11840. }
  11841. };
  11842. return _extendStatics(d, b);
  11843. };
  11844. function __extends$1(d, b) {
  11845. _extendStatics(d, b);
  11846. function __() {
  11847. this.constructor = d;
  11848. }
  11849. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  11850. }
  11851. var _assign = function __assign() {
  11852. _assign = Object.assign || function __assign(t) {
  11853. for (var s, i = 1, n = arguments.length; i < n; i++) {
  11854. s = arguments[i];
  11855. for (var p in s) {
  11856. if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
  11857. }
  11858. }
  11859. return t;
  11860. };
  11861. return _assign.apply(this, arguments);
  11862. };
  11863. var Dodge = /** @class */ (function (_super) {
  11864. __extends$1(Dodge, _super);
  11865. function Dodge(cfg) {
  11866. var _this = _super.call(this, cfg) || this;
  11867. _this.cacheMap = {};
  11868. _this.adjustDataArray = [];
  11869. _this.mergeData = [];
  11870. var _a = cfg.marginRatio, marginRatio = _a === void 0 ? MARGIN_RATIO : _a, _b = cfg.dodgeRatio, dodgeRatio = _b === void 0 ? DODGE_RATIO : _b, dodgeBy = cfg.dodgeBy, intervalPadding = cfg.intervalPadding, dodgePadding = cfg.dodgePadding, xDimensionLength = cfg.xDimensionLength, groupNum = cfg.groupNum, defaultSize = cfg.defaultSize, maxColumnWidth = cfg.maxColumnWidth, minColumnWidth = cfg.minColumnWidth, columnWidthRatio = cfg.columnWidthRatio, customOffset = cfg.customOffset;
  11871. _this.marginRatio = marginRatio;
  11872. _this.dodgeRatio = dodgeRatio;
  11873. _this.dodgeBy = dodgeBy;
  11874. _this.intervalPadding = intervalPadding;
  11875. _this.dodgePadding = dodgePadding;
  11876. _this.xDimensionLegenth = xDimensionLength;
  11877. _this.groupNum = groupNum;
  11878. _this.defaultSize = defaultSize;
  11879. _this.maxColumnWidth = maxColumnWidth;
  11880. _this.minColumnWidth = minColumnWidth;
  11881. _this.columnWidthRatio = columnWidthRatio;
  11882. _this.customOffset = customOffset;
  11883. return _this;
  11884. }
  11885. Dodge.prototype.process = function (groupDataArray) {
  11886. var groupedDataArray = clone(groupDataArray);
  11887. // 将数据数组展开一层
  11888. var mergeData = flatten(groupedDataArray);
  11889. var dodgeBy = this.dodgeBy;
  11890. // 如果指定了分组 dim 的字段
  11891. var adjustDataArray = dodgeBy ? group(mergeData, dodgeBy) : groupedDataArray;
  11892. this.cacheMap = {};
  11893. this.adjustDataArray = adjustDataArray;
  11894. this.mergeData = mergeData;
  11895. this.adjustData(adjustDataArray, mergeData);
  11896. this.adjustDataArray = [];
  11897. this.mergeData = [];
  11898. return groupedDataArray;
  11899. };
  11900. Dodge.prototype.adjustDim = function (dim, values, data, frameIndex) {
  11901. var _this = this;
  11902. var customOffset = this.customOffset;
  11903. var map = this.getDistribution(dim);
  11904. var groupData = this.groupData(data, dim); // 根据值分组
  11905. each(groupData, function (group, key) {
  11906. var range;
  11907. // xField 中只有一个值,不需要做 dodge
  11908. if (values.length === 1) {
  11909. range = {
  11910. pre: values[0] - 1,
  11911. next: values[0] + 1,
  11912. };
  11913. }
  11914. else {
  11915. // 如果有多个,则需要获取调整的范围
  11916. range = _this.getAdjustRange(dim, parseFloat(key), values);
  11917. }
  11918. each(group, function (d) {
  11919. var value = d[dim];
  11920. var valueArr = map[value];
  11921. var valIndex = valueArr.indexOf(frameIndex);
  11922. if (!isNil(customOffset)) {
  11923. var pre = range.pre, next = range.next;
  11924. d[dim] = isFunction(customOffset) ? customOffset(d, range) : (pre + next) / 2 + customOffset;
  11925. }
  11926. else {
  11927. d[dim] = _this.getDodgeOffset(range, valIndex, valueArr.length);
  11928. }
  11929. });
  11930. });
  11931. return [];
  11932. };
  11933. Dodge.prototype.getDodgeOffset = function (range, idx, len) {
  11934. var _a = this, dodgeRatio = _a.dodgeRatio, marginRatio = _a.marginRatio, intervalPadding = _a.intervalPadding, dodgePadding = _a.dodgePadding;
  11935. var pre = range.pre, next = range.next;
  11936. var tickLength = next - pre;
  11937. var position;
  11938. // 分多种输入情况
  11939. if (!isNil(intervalPadding) && isNil(dodgePadding) && intervalPadding >= 0) {
  11940. // 仅配置intervalPadding
  11941. var offset = this.getIntervalOnlyOffset(len, idx);
  11942. position = pre + offset;
  11943. }
  11944. else if (!isNil(dodgePadding) && isNil(intervalPadding) && dodgePadding >= 0) {
  11945. // 仅配置dodgePadding
  11946. var offset = this.getDodgeOnlyOffset(len, idx);
  11947. position = pre + offset;
  11948. }
  11949. else if (!isNil(intervalPadding) &&
  11950. !isNil(dodgePadding) &&
  11951. intervalPadding >= 0 &&
  11952. dodgePadding >= 0) {
  11953. // 同时配置intervalPadding和dodgePadding
  11954. var offset = this.getIntervalAndDodgeOffset(len, idx);
  11955. position = pre + offset;
  11956. }
  11957. else {
  11958. // 默认情况
  11959. var width = (tickLength * dodgeRatio) / len;
  11960. var margin = marginRatio * width;
  11961. var offset = (1 / 2) * (tickLength - len * width - (len - 1) * margin) +
  11962. ((idx + 1) * width + idx * margin) -
  11963. (1 / 2) * width -
  11964. (1 / 2) * tickLength;
  11965. position = (pre + next) / 2 + offset;
  11966. }
  11967. return position;
  11968. };
  11969. Dodge.prototype.getIntervalOnlyOffset = function (len, idx) {
  11970. var _a = this, defaultSize = _a.defaultSize, intervalPadding = _a.intervalPadding, xDimensionLegenth = _a.xDimensionLegenth, groupNum = _a.groupNum, dodgeRatio = _a.dodgeRatio, maxColumnWidth = _a.maxColumnWidth, minColumnWidth = _a.minColumnWidth, columnWidthRatio = _a.columnWidthRatio;
  11971. var normalizedIntervalPadding = intervalPadding / xDimensionLegenth;
  11972. var normalizedDodgePadding = (1 - (groupNum - 1) * normalizedIntervalPadding) / groupNum * dodgeRatio / (len - 1);
  11973. var geomWidth = ((1 - normalizedIntervalPadding * (groupNum - 1)) / groupNum - normalizedDodgePadding * (len - 1)) / len;
  11974. // 根据columnWidthRatio/defaultSize/maxColumnWidth/minColumnWidth调整宽度
  11975. geomWidth = (!isNil(columnWidthRatio)) ? 1 / groupNum / len * columnWidthRatio : geomWidth;
  11976. if (!isNil(maxColumnWidth)) {
  11977. var normalizedMaxWidht = maxColumnWidth / xDimensionLegenth;
  11978. geomWidth = Math.min(geomWidth, normalizedMaxWidht);
  11979. }
  11980. if (!isNil(minColumnWidth)) {
  11981. var normalizedMinWidht = minColumnWidth / xDimensionLegenth;
  11982. geomWidth = Math.max(geomWidth, normalizedMinWidht);
  11983. }
  11984. geomWidth = defaultSize ? (defaultSize / xDimensionLegenth) : geomWidth;
  11985. // 调整组内间隔
  11986. normalizedDodgePadding = ((1 - (groupNum - 1) * normalizedIntervalPadding) / groupNum - len * geomWidth) / (len - 1);
  11987. var offset = ((1 / 2 + idx) * geomWidth + idx * normalizedDodgePadding +
  11988. (1 / 2) * normalizedIntervalPadding) * groupNum -
  11989. normalizedIntervalPadding / 2;
  11990. return offset;
  11991. };
  11992. Dodge.prototype.getDodgeOnlyOffset = function (len, idx) {
  11993. var _a = this, defaultSize = _a.defaultSize, dodgePadding = _a.dodgePadding, xDimensionLegenth = _a.xDimensionLegenth, groupNum = _a.groupNum, marginRatio = _a.marginRatio, maxColumnWidth = _a.maxColumnWidth, minColumnWidth = _a.minColumnWidth, columnWidthRatio = _a.columnWidthRatio;
  11994. var normalizedDodgePadding = dodgePadding / xDimensionLegenth;
  11995. var normalizedIntervalPadding = 1 * marginRatio / (groupNum - 1);
  11996. var geomWidth = ((1 - normalizedIntervalPadding * (groupNum - 1)) / groupNum - normalizedDodgePadding * (len - 1)) / len;
  11997. // 根据columnWidthRatio/defaultSize/maxColumnWidth/minColumnWidth调整宽度
  11998. geomWidth = columnWidthRatio ? 1 / groupNum / len * columnWidthRatio : geomWidth;
  11999. if (!isNil(maxColumnWidth)) {
  12000. var normalizedMaxWidht = maxColumnWidth / xDimensionLegenth;
  12001. geomWidth = Math.min(geomWidth, normalizedMaxWidht);
  12002. }
  12003. if (!isNil(minColumnWidth)) {
  12004. var normalizedMinWidht = minColumnWidth / xDimensionLegenth;
  12005. geomWidth = Math.max(geomWidth, normalizedMinWidht);
  12006. }
  12007. geomWidth = defaultSize ? (defaultSize / xDimensionLegenth) : geomWidth;
  12008. // 调整组间距
  12009. normalizedIntervalPadding = (1 - (geomWidth * len + normalizedDodgePadding * (len - 1)) * groupNum) / (groupNum - 1);
  12010. var offset = ((1 / 2 + idx) * geomWidth + idx * normalizedDodgePadding +
  12011. (1 / 2) * normalizedIntervalPadding) * groupNum -
  12012. normalizedIntervalPadding / 2;
  12013. return offset;
  12014. };
  12015. Dodge.prototype.getIntervalAndDodgeOffset = function (len, idx) {
  12016. var _a = this, intervalPadding = _a.intervalPadding, dodgePadding = _a.dodgePadding, xDimensionLegenth = _a.xDimensionLegenth, groupNum = _a.groupNum;
  12017. var normalizedIntervalPadding = intervalPadding / xDimensionLegenth;
  12018. var normalizedDodgePadding = dodgePadding / xDimensionLegenth;
  12019. var geomWidth = ((1 - normalizedIntervalPadding * (groupNum - 1)) / groupNum - normalizedDodgePadding * (len - 1)) / len;
  12020. var offset = ((1 / 2 + idx) * geomWidth + idx * normalizedDodgePadding +
  12021. (1 / 2) * normalizedIntervalPadding) * groupNum -
  12022. normalizedIntervalPadding / 2;
  12023. return offset;
  12024. };
  12025. Dodge.prototype.getDistribution = function (dim) {
  12026. var groupedDataArray = this.adjustDataArray;
  12027. var cacheMap = this.cacheMap;
  12028. var map = cacheMap[dim];
  12029. if (!map) {
  12030. map = {};
  12031. each(groupedDataArray, function (data, index) {
  12032. var values = valuesOfKey(data, dim);
  12033. if (!values.length) {
  12034. values.push(0);
  12035. }
  12036. each(values, function (val) {
  12037. if (!map[val]) {
  12038. map[val] = [];
  12039. }
  12040. map[val].push(index);
  12041. });
  12042. });
  12043. cacheMap[dim] = map;
  12044. }
  12045. return map;
  12046. };
  12047. return Dodge;
  12048. }(Adjust));
  12049. function randomNumber(min, max) {
  12050. return (max - min) * Math.random() + min;
  12051. }
  12052. var Jitter = /** @class */ (function (_super) {
  12053. __extends$1(Jitter, _super);
  12054. function Jitter() {
  12055. return _super !== null && _super.apply(this, arguments) || this;
  12056. }
  12057. Jitter.prototype.process = function (groupDataArray) {
  12058. var groupedDataArray = clone(groupDataArray);
  12059. // 之前分组之后的数据,然后有合并回去(和分组前可以理解成是一样的)
  12060. var mergeData = flatten(groupedDataArray);
  12061. // 返回值
  12062. this.adjustData(groupedDataArray, mergeData);
  12063. return groupedDataArray;
  12064. };
  12065. /**
  12066. * 当前数据分组(index)中,按照维度 dim 进行 jitter 调整
  12067. * @param dim
  12068. * @param values
  12069. * @param dataArray
  12070. */
  12071. Jitter.prototype.adjustDim = function (dim, values, dataArray) {
  12072. var _this = this;
  12073. // 在每一个分组中,将数据再按照 dim 分组,用于散列
  12074. var groupDataArray = this.groupData(dataArray, dim);
  12075. return each(groupDataArray, function (data, dimValue) {
  12076. return _this.adjustGroup(data, dim, parseFloat(dimValue), values);
  12077. });
  12078. };
  12079. // 随机出来的字段值
  12080. Jitter.prototype.getAdjustOffset = function (range) {
  12081. var pre = range.pre, next = range.next;
  12082. // 随机的范围
  12083. var margin = (next - pre) * GAP;
  12084. return randomNumber(pre + margin, next - margin);
  12085. };
  12086. // adjust group data
  12087. Jitter.prototype.adjustGroup = function (group, dim, dimValue, values) {
  12088. var _this = this;
  12089. // 调整范围
  12090. var range = this.getAdjustRange(dim, dimValue, values);
  12091. each(group, function (data) {
  12092. data[dim] = _this.getAdjustOffset(range); // 获取调整的位置
  12093. });
  12094. return group;
  12095. };
  12096. return Jitter;
  12097. }(Adjust));
  12098. var Cache = default_1;
  12099. var Stack = /** @class */ (function (_super) {
  12100. __extends$1(Stack, _super);
  12101. function Stack(cfg) {
  12102. var _this = _super.call(this, cfg) || this;
  12103. var _a = cfg.adjustNames, adjustNames = _a === void 0 ? ['y'] : _a, _b = cfg.height, height = _b === void 0 ? NaN : _b, _c = cfg.size, size = _c === void 0 ? 10 : _c, _d = cfg.reverseOrder, reverseOrder = _d === void 0 ? false : _d;
  12104. _this.adjustNames = adjustNames;
  12105. _this.height = height;
  12106. _this.size = size;
  12107. _this.reverseOrder = reverseOrder;
  12108. return _this;
  12109. }
  12110. /**
  12111. * 方法入参是经过数据分组、数据数字化之后的二维数组
  12112. * @param groupDataArray 分组之后的数据
  12113. */
  12114. Stack.prototype.process = function (groupDataArray) {
  12115. var _a = this, yField = _a.yField, reverseOrder = _a.reverseOrder;
  12116. // 如果有指定 y 字段,那么按照 y 字段来 stack
  12117. // 否则,按照高度均分
  12118. var d = yField ? this.processStack(groupDataArray) : this.processOneDimStack(groupDataArray);
  12119. return reverseOrder ? this.reverse(d) : d;
  12120. };
  12121. Stack.prototype.reverse = function (groupedDataArray) {
  12122. return groupedDataArray.slice(0).reverse();
  12123. };
  12124. Stack.prototype.processStack = function (groupDataArray) {
  12125. var _a = this, xField = _a.xField, yField = _a.yField, reverseOrder = _a.reverseOrder;
  12126. // 层叠顺序翻转
  12127. var groupedDataArray = reverseOrder ? this.reverse(groupDataArray) : groupDataArray;
  12128. // 用来缓存,正数和负数的堆叠问题
  12129. var positive = new Cache();
  12130. var negative = new Cache();
  12131. return groupedDataArray.map(function (dataArray) {
  12132. return dataArray.map(function (data) {
  12133. var _a;
  12134. var x = get(data, xField, 0);
  12135. var y = get(data, [yField]);
  12136. var xKey = x.toString();
  12137. // todo 是否应该取 _origin?因为 y 可能取到的值不正确,比如先 symmetric,再 stack!
  12138. y = isArray(y) ? y[1] : y;
  12139. if (!isNil(y)) {
  12140. var cache = y >= 0 ? positive : negative;
  12141. if (!cache.has(xKey)) {
  12142. cache.set(xKey, 0);
  12143. }
  12144. var xValue = cache.get(xKey);
  12145. var newXValue = y + xValue;
  12146. // 存起来
  12147. cache.set(xKey, newXValue);
  12148. return _assign(_assign({}, data), (_a = {}, _a[yField] = [xValue, newXValue], _a));
  12149. }
  12150. // 没有修改,则直接返回
  12151. return data;
  12152. });
  12153. });
  12154. };
  12155. Stack.prototype.processOneDimStack = function (groupDataArray) {
  12156. var _this = this;
  12157. var _a = this, xField = _a.xField, height = _a.height, reverseOrder = _a.reverseOrder;
  12158. var yField = 'y';
  12159. // 如果层叠的顺序翻转
  12160. var groupedDataArray = reverseOrder ? this.reverse(groupDataArray) : groupDataArray;
  12161. // 缓存累加数据
  12162. var cache = new Cache();
  12163. return groupedDataArray.map(function (dataArray) {
  12164. return dataArray.map(function (data) {
  12165. var _a;
  12166. var size = _this.size;
  12167. var xValue = data[xField];
  12168. // todo 没有看到这个 stack 计算原理
  12169. var stackHeight = (size * 2) / height;
  12170. if (!cache.has(xValue)) {
  12171. cache.set(xValue, stackHeight / 2); // 初始值大小
  12172. }
  12173. var stackValue = cache.get(xValue);
  12174. // 增加一层 stackHeight
  12175. cache.set(xValue, stackValue + stackHeight);
  12176. return _assign(_assign({}, data), (_a = {}, _a[yField] = stackValue, _a));
  12177. });
  12178. });
  12179. };
  12180. return Stack;
  12181. }(Adjust));
  12182. var Symmetric = /** @class */ (function (_super) {
  12183. __extends$1(Symmetric, _super);
  12184. function Symmetric() {
  12185. return _super !== null && _super.apply(this, arguments) || this;
  12186. }
  12187. Symmetric.prototype.process = function (groupDataArray) {
  12188. var mergeData = flatten(groupDataArray);
  12189. var _a = this, xField = _a.xField, yField = _a.yField;
  12190. // 每个 x 值对应的 最大值
  12191. var cache = this.getXValuesMaxMap(mergeData);
  12192. // 所有数据的最大的值
  12193. var max = Math.max.apply(Math, Object.keys(cache).map(function (key) { return cache[key]; }));
  12194. return map(groupDataArray, function (dataArray) {
  12195. return map(dataArray, function (data) {
  12196. var _a, _b;
  12197. var yValue = data[yField];
  12198. var xValue = data[xField];
  12199. // 数组处理逻辑
  12200. if (isArray(yValue)) {
  12201. var off_1 = (max - cache[xValue]) / 2;
  12202. return _assign(_assign({}, data), (_a = {}, _a[yField] = map(yValue, function (y) { return off_1 + y; }), _a));
  12203. }
  12204. // 非数组处理逻辑
  12205. var offset = (max - yValue) / 2;
  12206. return _assign(_assign({}, data), (_b = {}, _b[yField] = [offset, yValue + offset], _b));
  12207. });
  12208. });
  12209. };
  12210. // 获取每个 x 对应的最大的值
  12211. Symmetric.prototype.getXValuesMaxMap = function (mergeData) {
  12212. var _this = this;
  12213. var _a = this, xField = _a.xField, yField = _a.yField;
  12214. // 根据 xField 的值进行分组
  12215. var groupDataArray = groupBy(mergeData, function (data) { return data[xField]; });
  12216. // 获取每个 xField 值中的最大值
  12217. return mapValues(groupDataArray, function (dataArray) { return _this.getDimMaxValue(dataArray, yField); });
  12218. };
  12219. Symmetric.prototype.getDimMaxValue = function (mergeData, dim) {
  12220. // 所有的 value 值
  12221. var dimValues = map(mergeData, function (data) { return get(data, dim, []); });
  12222. // 将数组打平(dim value 有可能是数组,比如 stack 之后的)
  12223. var flattenValues = flatten(dimValues);
  12224. // 求出数组的最大值
  12225. return Math.max.apply(Math, flattenValues);
  12226. };
  12227. return Symmetric;
  12228. }(Adjust));
  12229. // 注册内置的 adjust
  12230. registerAdjust('Dodge', Dodge);
  12231. registerAdjust('Jitter', Jitter);
  12232. registerAdjust('Stack', Stack);
  12233. registerAdjust('Symmetric', Symmetric);
  12234. var Base$1 = /*#__PURE__*/function () {
  12235. function Base(options) {
  12236. _classCallCheck(this, Base);
  12237. mix(this, options);
  12238. var scale = this.scale,
  12239. field = this.field,
  12240. data = this.data;
  12241. if (!scale && data) {
  12242. var values = valuesOfKey(data, field);
  12243. this.scale = this.createScale({
  12244. values: values,
  12245. field: field
  12246. });
  12247. }
  12248. }
  12249. _createClass(Base, [{
  12250. key: "createScale",
  12251. value: function createScale(_scaleConfig) {
  12252. return null;
  12253. }
  12254. // 数据映射方法
  12255. }, {
  12256. key: "_mapping",
  12257. value: function _mapping(value) {
  12258. return value;
  12259. }
  12260. }, {
  12261. key: "update",
  12262. value: function update(options) {
  12263. mix(this, options);
  12264. }
  12265. }, {
  12266. key: "setRange",
  12267. value: function setRange(range) {
  12268. this.range = range;
  12269. }
  12270. // 归一化,参数是原始数据,返回是归一化的数据
  12271. }, {
  12272. key: "normalize",
  12273. value: function normalize(value) {
  12274. var scale = this.scale;
  12275. if (isArray(value)) {
  12276. return value.map(function (v) {
  12277. return scale.scale(v);
  12278. });
  12279. }
  12280. return scale.scale(value);
  12281. }
  12282. // convert 参数是归一化的数据,返回定义域的值
  12283. }, {
  12284. key: "convert",
  12285. value: function convert(value) {
  12286. return value;
  12287. }
  12288. // 等于 normalize + convert, 参数是原始数据,返回是定义域的值
  12289. }, {
  12290. key: "mapping",
  12291. value: function mapping(value) {
  12292. var child = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
  12293. var rst = isFunction(this.callback) ? this.callback(value, child) : null;
  12294. if (!isNil(rst)) {
  12295. return rst;
  12296. }
  12297. return this._mapping(value);
  12298. }
  12299. }]);
  12300. return Base;
  12301. }();
  12302. var Linear$1 = /*#__PURE__*/function (_Base) {
  12303. _inherits(Linear$1, _Base);
  12304. var _super = _createSuper(Linear$1);
  12305. function Linear$1(options) {
  12306. var _this;
  12307. _classCallCheck(this, Linear$1);
  12308. _this = _super.call(this, options);
  12309. _this._updateInterpolate();
  12310. return _this;
  12311. }
  12312. _createClass(Linear$1, [{
  12313. key: "createScale",
  12314. value: function createScale(scaleConfig) {
  12315. return new Linear(scaleConfig);
  12316. }
  12317. }, {
  12318. key: "_updateInterpolate",
  12319. value: function _updateInterpolate() {
  12320. var _this$range = _slicedToArray(this.range, 2),
  12321. min = _this$range[0],
  12322. max = _this$range[1];
  12323. this.interpolate = interpolate(min, max);
  12324. }
  12325. }, {
  12326. key: "update",
  12327. value: function update(options) {
  12328. _get$1(_getPrototypeOf(Linear$1.prototype), "update", this).call(this, options);
  12329. this._updateInterpolate();
  12330. }
  12331. }, {
  12332. key: "_mapping",
  12333. value: function _mapping(value) {
  12334. var scale = this.scale,
  12335. interpolate = this.interpolate;
  12336. if (isArray(value)) {
  12337. return value.map(function (v) {
  12338. return interpolate(scale.scale(v));
  12339. });
  12340. }
  12341. return interpolate(scale.scale(value));
  12342. }
  12343. }, {
  12344. key: "normalize",
  12345. value: function normalize(value) {
  12346. var scale = this.scale;
  12347. if (isArray(value)) {
  12348. return value.map(function (v) {
  12349. return scale.scale(v);
  12350. });
  12351. }
  12352. return scale.scale(value);
  12353. }
  12354. }, {
  12355. key: "convert",
  12356. value: function convert(value) {
  12357. var range = this.range;
  12358. var _range = _slicedToArray(range, 2),
  12359. min = _range[0],
  12360. max = _range[1];
  12361. if (isArray(value)) {
  12362. return value.map(function (v) {
  12363. return min + (max - min) * v;
  12364. });
  12365. }
  12366. return min + (max - min) * value;
  12367. }
  12368. }]);
  12369. return Linear$1;
  12370. }(Base$1);
  12371. var Category$1 = /*#__PURE__*/function (_Base) {
  12372. _inherits(Category$1, _Base);
  12373. var _super = _createSuper(Category$1);
  12374. function Category$1() {
  12375. _classCallCheck(this, Category$1);
  12376. return _super.apply(this, arguments);
  12377. }
  12378. _createClass(Category$1, [{
  12379. key: "createScale",
  12380. value: function createScale(scaleConfig) {
  12381. return new Category(scaleConfig);
  12382. }
  12383. }, {
  12384. key: "_mapping",
  12385. value: function _mapping(value) {
  12386. var scale = this.scale,
  12387. range = this.range;
  12388. if (scale.type === 'cat') {
  12389. var _index = scale.translate(value);
  12390. return range[_index % range.length];
  12391. }
  12392. var normalizeValue = scale.scale(value);
  12393. var index = Math.round(normalizeValue * (range.length - 1));
  12394. return range[index];
  12395. }
  12396. }]);
  12397. return Category$1;
  12398. }(Base$1);
  12399. var Identity$1 = /*#__PURE__*/function (_Base) {
  12400. _inherits(Identity$1, _Base);
  12401. var _super = _createSuper(Identity$1);
  12402. function Identity$1() {
  12403. _classCallCheck(this, Identity$1);
  12404. return _super.apply(this, arguments);
  12405. }
  12406. _createClass(Identity$1, [{
  12407. key: "createScale",
  12408. value: function createScale(scaleConfig) {
  12409. return new Identity(scaleConfig);
  12410. }
  12411. }, {
  12412. key: "_mapping",
  12413. value: function _mapping() {
  12414. var field = this.field,
  12415. range = this.range;
  12416. return field || range && range[0];
  12417. }
  12418. }]);
  12419. return Identity$1;
  12420. }(Base$1);
  12421. var Attrs = /*#__PURE__*/Object.freeze({
  12422. __proto__: null,
  12423. Attr: Base$1,
  12424. Linear: Linear$1,
  12425. Category: Category$1,
  12426. Identity: Identity$1
  12427. });
  12428. var Identity$2 = Identity$1,
  12429. Linear$2 = Linear$1,
  12430. Category$2 = Category$1;
  12431. // 需要映射的属性名
  12432. var ATTRS = ['x', 'y', 'color', 'size', 'shape'];
  12433. // 分组处理的属性
  12434. var GROUP_ATTRS = ['color', 'size', 'shape'];
  12435. function cloneScale(scale, scaleConfig) {
  12436. // @ts-ignore
  12437. return new scale.constructor(_objectSpread(_objectSpread({}, scale.__cfg__), scaleConfig));
  12438. }
  12439. var AttrController = /*#__PURE__*/function () {
  12440. function AttrController(scaleController, attrsRange) {
  12441. _classCallCheck(this, AttrController);
  12442. this.scaleController = scaleController;
  12443. this.attrsRange = attrsRange;
  12444. this.options = {};
  12445. this.attrs = {};
  12446. }
  12447. _createClass(AttrController, [{
  12448. key: "parseOption",
  12449. value: function parseOption(option, attrName) {
  12450. if (!option) {
  12451. return {
  12452. type: 'identity'
  12453. };
  12454. }
  12455. if (isString(option)) {
  12456. return {
  12457. field: option,
  12458. type: 'category'
  12459. };
  12460. }
  12461. if (isNumber(option)) {
  12462. if (attrName === 'size') {
  12463. return {
  12464. type: 'identity',
  12465. field: option
  12466. };
  12467. }
  12468. }
  12469. if (isArray(option)) {
  12470. return {
  12471. field: option[0],
  12472. range: option[1]
  12473. };
  12474. }
  12475. return option;
  12476. }
  12477. }, {
  12478. key: "getAttrOptions",
  12479. value: function getAttrOptions(props, justifyContentCenter) {
  12480. var _this = this;
  12481. if (!props.x || !props.y) {
  12482. throw new Error('x, y are required !');
  12483. }
  12484. var options = {};
  12485. var ranges = this.attrsRange;
  12486. ATTRS.forEach(function (attrName) {
  12487. if (!props[attrName]) return;
  12488. var option = _this.parseOption(props[attrName], attrName);
  12489. if (!option.range) {
  12490. option.range = ranges[attrName];
  12491. }
  12492. options[attrName] = option;
  12493. });
  12494. // @ts-ignore
  12495. var x = options.x,
  12496. y = options.y;
  12497. x.justifyContent = justifyContentCenter;
  12498. // x, y 都是固定Linear 映射
  12499. x.type = Linear$2;
  12500. y.type = Linear$2;
  12501. return options;
  12502. }
  12503. }, {
  12504. key: "getDefaultAttrValues",
  12505. value: function getDefaultAttrValues() {
  12506. var _this$attrsRange = this.attrsRange,
  12507. color = _this$attrsRange.color,
  12508. shape = _this$attrsRange.shape;
  12509. return {
  12510. color: color[0],
  12511. shape: shape && shape[0]
  12512. };
  12513. }
  12514. }, {
  12515. key: "getGroupScales",
  12516. value: function getGroupScales() {
  12517. var attrs = this.attrs;
  12518. var scales = [];
  12519. each(GROUP_ATTRS, function (attrName) {
  12520. var attr = attrs[attrName];
  12521. if (!attr) {
  12522. return;
  12523. }
  12524. var scale = attr.scale;
  12525. if (scale && scale.isCategory && scales.indexOf(scale) === -1) {
  12526. scales.push(scale);
  12527. }
  12528. });
  12529. return scales;
  12530. }
  12531. }, {
  12532. key: "createAttr",
  12533. value: function createAttr(option) {
  12534. var type = option.type,
  12535. field = option.field,
  12536. scaleConfig = option.scale;
  12537. if (isNil(field) || type === Identity$2) {
  12538. return new Identity$2(option);
  12539. }
  12540. var scale = this.scaleController.getScale(field);
  12541. var attrOption = _objectSpread(_objectSpread({}, option), {}, {
  12542. data: this.scaleController.getData(),
  12543. // scaleConfig 只在属性映射中生效
  12544. scale: scaleConfig ? cloneScale(scale, scaleConfig) : scale
  12545. });
  12546. // identity
  12547. if (scale && scale.type === 'identity') {
  12548. return new Identity$2(attrOption);
  12549. }
  12550. // Attr的默认类型和scale类型保持一致
  12551. var AttrConstructor = scale.isLinear ? Linear$2 : Category$2;
  12552. // custom Attr Constructor
  12553. if (isFunction(type)) {
  12554. AttrConstructor = type;
  12555. }
  12556. if (isString(type) && Attrs[upperFirst(type)]) {
  12557. AttrConstructor = Attrs[upperFirst(type)];
  12558. }
  12559. return new AttrConstructor(attrOption);
  12560. }
  12561. }, {
  12562. key: "create",
  12563. value: function create(options) {
  12564. this.update(options);
  12565. }
  12566. }, {
  12567. key: "update",
  12568. value: function update(nextOptions) {
  12569. var scaleController = this.scaleController,
  12570. lastOptions = this.options,
  12571. lastAttrs = this.attrs;
  12572. var nextAttrs = {};
  12573. each(nextOptions, function (nextOption, attrName) {
  12574. var lastOption = lastOptions[attrName];
  12575. if (equal(nextOption, lastOption)) {
  12576. nextAttrs[attrName] = lastAttrs[attrName];
  12577. }
  12578. var field = nextOption.field,
  12579. justifyContent = nextOption.justifyContent;
  12580. if (field) {
  12581. scaleController.setScale(field, {
  12582. justifyContent: justifyContent
  12583. });
  12584. }
  12585. });
  12586. this.options = nextOptions;
  12587. this.attrs = nextAttrs;
  12588. }
  12589. }, {
  12590. key: "getAttr",
  12591. value: function getAttr(attrName) {
  12592. var attrs = this.attrs,
  12593. options = this.options;
  12594. var attr = attrs[attrName];
  12595. if (attr) {
  12596. return attr;
  12597. }
  12598. var option = options[attrName];
  12599. if (!option) {
  12600. return null;
  12601. }
  12602. var newAttr = this.createAttr(option);
  12603. attrs[attrName] = newAttr;
  12604. return newAttr;
  12605. }
  12606. }, {
  12607. key: "getAttrs",
  12608. value: function getAttrs() {
  12609. var _this2 = this;
  12610. var options = this.options,
  12611. attrs = this.attrs;
  12612. each(options, function (option, attrName) {
  12613. _this2.getAttr(attrName);
  12614. });
  12615. return attrs;
  12616. }
  12617. }, {
  12618. key: "isGroupAttr",
  12619. value: function isGroupAttr(attrName) {
  12620. return GROUP_ATTRS.indexOf(attrName) !== -1;
  12621. }
  12622. }, {
  12623. key: "getAttrsByLinear",
  12624. value: function getAttrsByLinear() {
  12625. var attrs = this.attrs;
  12626. var attrNames = Object.keys(attrs);
  12627. var linearAttrs = [];
  12628. var nonlinearAttrs = [];
  12629. attrNames.forEach(function (attrName) {
  12630. if (attrName === 'x' || attrName === 'y') {
  12631. linearAttrs.push(attrName);
  12632. return;
  12633. }
  12634. var scale = attrs[attrName].scale;
  12635. if (scale && scale.type === 'linear') {
  12636. linearAttrs.push(attrName);
  12637. } else {
  12638. nonlinearAttrs.push(attrName);
  12639. }
  12640. });
  12641. return {
  12642. linearAttrs: linearAttrs,
  12643. nonlinearAttrs: nonlinearAttrs
  12644. };
  12645. }
  12646. }]);
  12647. return AttrController;
  12648. }();
  12649. var _excluded$3 = ["field"];
  12650. // 保留原始数据的字段
  12651. var FIELD_ORIGIN = 'origin';
  12652. var Geometry = /*#__PURE__*/function (_Selection) {
  12653. _inherits(Geometry, _Selection);
  12654. var _super = _createSuper(Geometry);
  12655. function Geometry(props, context) {
  12656. var _this;
  12657. _classCallCheck(this, Geometry);
  12658. _this = _super.call(this, props, context);
  12659. _this.isGeometry = true;
  12660. // x 轴居中
  12661. _this.justifyContent = false;
  12662. // y 轴是否从0开始
  12663. _this.startOnZero = false;
  12664. // 是否连接空值
  12665. _this.connectNulls = false;
  12666. // 是否需要排序
  12667. _this.sortable = false;
  12668. mix(_assertThisInitialized(_this), _this.getDefaultCfg());
  12669. var chart = props.chart,
  12670. coord = props.coord;
  12671. var attrsRange = _this._getThemeAttrsRange();
  12672. _this.attrController = new AttrController(chart.scale, attrsRange);
  12673. var _assertThisInitialize = _assertThisInitialized(_this),
  12674. attrController = _assertThisInitialize.attrController,
  12675. justifyContent = _assertThisInitialize.justifyContent;
  12676. var attrOptions = attrController.getAttrOptions(props, !coord.isCyclic() || justifyContent);
  12677. attrController.create(attrOptions);
  12678. return _this;
  12679. }
  12680. _createClass(Geometry, [{
  12681. key: "getDefaultCfg",
  12682. value: function getDefaultCfg() {
  12683. return {};
  12684. }
  12685. }, {
  12686. key: "willReceiveProps",
  12687. value: function willReceiveProps(nextProps) {
  12688. _get$1(_getPrototypeOf(Geometry.prototype), "willReceiveProps", this).call(this, nextProps);
  12689. var lastProps = this.props,
  12690. attrController = this.attrController,
  12691. justifyContent = this.justifyContent;
  12692. var nextData = nextProps.data,
  12693. nextAdjust = nextProps.adjust,
  12694. nextZoomRange = nextProps.zoomRange,
  12695. coord = nextProps.coord;
  12696. var lastData = lastProps.data,
  12697. lastAdjust = lastProps.adjust,
  12698. lastZoomRange = lastProps.zoomRange;
  12699. var justifyContentCenter = !coord.isCyclic() || justifyContent;
  12700. var nextAttrOptions = attrController.getAttrOptions(nextProps, justifyContentCenter);
  12701. var lastAttrOptions = attrController.getAttrOptions(lastProps, justifyContentCenter);
  12702. if (!equal(nextAttrOptions, lastAttrOptions)) {
  12703. attrController.update(nextAttrOptions);
  12704. this.records = null;
  12705. }
  12706. // 重新处理数据
  12707. if (nextData !== lastData) {
  12708. this.records = null;
  12709. }
  12710. // 重新处理数据
  12711. if (nextAdjust !== lastAdjust) {
  12712. this.records = null;
  12713. }
  12714. // zoomRange发生变化,records也需要重新计算
  12715. if (!equal(nextZoomRange, lastZoomRange)) {
  12716. this.records = null;
  12717. }
  12718. }
  12719. }, {
  12720. key: "willMount",
  12721. value: function willMount() {
  12722. this._createAttrs();
  12723. if (!this.records) {
  12724. this._processData();
  12725. }
  12726. }
  12727. }, {
  12728. key: "willUpdate",
  12729. value: function willUpdate() {
  12730. this._createAttrs();
  12731. if (!this.records) {
  12732. this._processData();
  12733. }
  12734. }
  12735. }, {
  12736. key: "didMount",
  12737. value: function didMount() {
  12738. _get$1(_getPrototypeOf(Geometry.prototype), "didMount", this).call(this);
  12739. this._initEvent();
  12740. }
  12741. }, {
  12742. key: "_createAttrs",
  12743. value: function _createAttrs() {
  12744. var attrController = this.attrController;
  12745. attrController.attrs = {};
  12746. this.attrs = attrController.getAttrs();
  12747. }
  12748. }, {
  12749. key: "_getThemeAttrsRange",
  12750. value: function _getThemeAttrsRange() {
  12751. var context = this.context,
  12752. props = this.props,
  12753. geomType = this.geomType;
  12754. var coord = props.coord;
  12755. var theme = context.theme;
  12756. var colors = theme.colors,
  12757. sizes = theme.sizes,
  12758. shapes = theme.shapes;
  12759. return {
  12760. x: coord.x,
  12761. y: coord.y,
  12762. color: colors,
  12763. size: sizes,
  12764. shape: shapes[geomType]
  12765. };
  12766. }
  12767. }, {
  12768. key: "_adjustScales",
  12769. value: function _adjustScales() {
  12770. var attrs = this.attrs,
  12771. props = this.props,
  12772. defaultStartOnZero = this.startOnZero;
  12773. var chart = props.chart,
  12774. _props$startOnZero = props.startOnZero,
  12775. startOnZero = _props$startOnZero === void 0 ? defaultStartOnZero : _props$startOnZero,
  12776. coord = props.coord,
  12777. adjust = props.adjust;
  12778. var isPolar = coord.isPolar,
  12779. transposed = coord.transposed;
  12780. var y = attrs.y;
  12781. var yField = y.field;
  12782. // 如果从 0 开始,只调整 y 轴 scale
  12783. if (startOnZero) {
  12784. var _y = attrs.y;
  12785. chart.scale.adjustStartZero(_y.scale);
  12786. }
  12787. // 饼图的scale调整,关闭nice
  12788. if (isPolar && transposed && (adjust === 'stack' || (adjust === null || adjust === void 0 ? void 0 : adjust.type) === 'stack')) {
  12789. var _y2 = attrs.y;
  12790. chart.scale.adjustPieScale(_y2.scale);
  12791. }
  12792. if (adjust === 'stack' || (adjust === null || adjust === void 0 ? void 0 : adjust.type) === 'stack') {
  12793. this._updateStackRange(yField, y.scale, this.dataArray);
  12794. }
  12795. }
  12796. }, {
  12797. key: "_groupData",
  12798. value: function _groupData(data) {
  12799. var attrController = this.attrController;
  12800. var groupScales = attrController.getGroupScales();
  12801. if (!groupScales.length) {
  12802. return [{
  12803. children: data
  12804. }];
  12805. }
  12806. var names = [];
  12807. groupScales.forEach(function (scale) {
  12808. var field = scale.field;
  12809. names.push(field);
  12810. });
  12811. var groups = groupToMap(data, names);
  12812. var records = [];
  12813. for (var key in groups) {
  12814. records.push({
  12815. key: key.replace(/^_/, ''),
  12816. children: groups[key]
  12817. });
  12818. }
  12819. return records;
  12820. }
  12821. }, {
  12822. key: "_saveOrigin",
  12823. value: function _saveOrigin(originData) {
  12824. var len = originData.length;
  12825. var data = new Array(len);
  12826. for (var i = 0; i < len; i++) {
  12827. var record = originData[i];
  12828. data[i] = _objectSpread(_objectSpread({}, record), {}, _defineProperty({}, FIELD_ORIGIN, record));
  12829. }
  12830. return data;
  12831. }
  12832. }, {
  12833. key: "_numberic",
  12834. value: function _numberic(data) {
  12835. var attrs = this.attrs;
  12836. var scales = [attrs.x.scale, attrs.y.scale];
  12837. for (var j = 0, len = data.length; j < len; j++) {
  12838. var obj = data[j];
  12839. var count = scales.length;
  12840. for (var i = 0; i < count; i++) {
  12841. var scale = scales[i];
  12842. if (scale.isCategory) {
  12843. var field = scale.field;
  12844. obj[field] = scale.translate(obj[field]);
  12845. }
  12846. }
  12847. }
  12848. }
  12849. }, {
  12850. key: "_adjustData",
  12851. value: function _adjustData(records) {
  12852. var attrs = this.attrs,
  12853. props = this.props;
  12854. var adjust = props.adjust;
  12855. // groupedArray 是二维数组
  12856. var groupedArray = records.map(function (record) {
  12857. return record.children;
  12858. });
  12859. if (!adjust) {
  12860. return groupedArray;
  12861. }
  12862. var adjustCfg = typeof adjust === 'string' ? {
  12863. type: adjust
  12864. } : adjust;
  12865. var adjustType = upperFirst(adjustCfg.type);
  12866. var AdjustConstructor = getAdjust(adjustType);
  12867. if (!AdjustConstructor) {
  12868. throw new Error('not support such adjust : ' + adjust);
  12869. }
  12870. if (adjustType === 'Dodge') {
  12871. for (var i = 0, len = groupedArray.length; i < len; i++) {
  12872. // 如果是dodge, 需要处理数字再处理
  12873. this._numberic(groupedArray[i]);
  12874. }
  12875. adjustCfg.adjustNames = ['x'];
  12876. }
  12877. var x = attrs.x,
  12878. y = attrs.y;
  12879. adjustCfg.xField = x.field;
  12880. adjustCfg.yField = y.field;
  12881. var adjustInstance = new AdjustConstructor(adjustCfg);
  12882. var adjustData = adjustInstance.process(groupedArray);
  12883. this.adjust = {
  12884. type: adjustCfg.type,
  12885. adjust: adjustInstance
  12886. };
  12887. // process 返回的是新数组,所以要修改 records
  12888. records.forEach(function (record, index) {
  12889. record.children = adjustData[index];
  12890. });
  12891. return adjustData;
  12892. }
  12893. }, {
  12894. key: "_updateStackRange",
  12895. value: function _updateStackRange(field, scale, dataArray) {
  12896. var flattenArray = flatten(dataArray);
  12897. var min = Infinity;
  12898. var max = -Infinity;
  12899. for (var i = 0, len = flattenArray.length; i < len; i++) {
  12900. var obj = flattenArray[i];
  12901. var tmpMin = Math.min.apply(null, obj[field]);
  12902. var tmpMax = Math.max.apply(null, obj[field]);
  12903. if (tmpMin < min) {
  12904. min = tmpMin;
  12905. }
  12906. if (tmpMax > max) {
  12907. max = tmpMax;
  12908. }
  12909. }
  12910. if (min !== scale.min || max !== scale.max) {
  12911. scale.change({
  12912. min: min,
  12913. max: max
  12914. });
  12915. }
  12916. }
  12917. }, {
  12918. key: "_processData",
  12919. value: function _processData() {
  12920. var props = this.props;
  12921. var originData = props.data;
  12922. var data = this._saveOrigin(originData);
  12923. // 根据分类度量进行数据分组
  12924. var records = this._groupData(data);
  12925. // 根据adjust分组
  12926. var dataArray = this._adjustData(records);
  12927. this.dataArray = dataArray;
  12928. // scale适配调整,主要是调整 y 轴是否从 0 开始 以及 饼图
  12929. this._adjustScales();
  12930. // 数据排序(非必须)
  12931. if (this.sortable) {
  12932. this._sortData(records);
  12933. }
  12934. this.records = records;
  12935. }
  12936. }, {
  12937. key: "_sortData",
  12938. value: function _sortData(records) {
  12939. var xScale = this.getXScale();
  12940. var field = xScale.field,
  12941. type = xScale.type;
  12942. if (type !== 'identity' && xScale.values.length > 1) {
  12943. each(records, function (_ref) {
  12944. var children = _ref.children;
  12945. children.sort(function (record1, record2) {
  12946. if (type === 'timeCat') {
  12947. return toTimeStamp(record1[FIELD_ORIGIN][field]) - toTimeStamp(record2[FIELD_ORIGIN][field]);
  12948. }
  12949. return xScale.translate(record1[FIELD_ORIGIN][field]) - xScale.translate(record2[FIELD_ORIGIN][field]);
  12950. });
  12951. });
  12952. }
  12953. }
  12954. }, {
  12955. key: "_initEvent",
  12956. value: function _initEvent() {
  12957. var _this2 = this;
  12958. var container = this.container,
  12959. props = this.props;
  12960. var canvas = container.get('canvas');
  12961. ['onPressStart', 'onPress', 'onPressEnd', 'onPan', 'onPanStart', 'onPanEnd'].forEach(function (eventName) {
  12962. if (props[eventName]) {
  12963. canvas.on(eventName.substr(2).toLowerCase(), function (ev) {
  12964. ev.geometry = _this2;
  12965. props[eventName](ev);
  12966. });
  12967. }
  12968. });
  12969. }
  12970. }, {
  12971. key: "getY0Value",
  12972. value: function getY0Value() {
  12973. var attrs = this.attrs,
  12974. props = this.props;
  12975. var chart = props.chart;
  12976. var field = attrs.y.field;
  12977. var scale = chart.getScale(field);
  12978. return chart.scale.getZeroValue(scale);
  12979. }
  12980. // 根据各属性映射的值域来获取真正的绘图属性
  12981. }, {
  12982. key: "_getShapeStyle",
  12983. value: function _getShapeStyle(shape, origin) {
  12984. var context = this.context,
  12985. props = this.props,
  12986. geomType = this.geomType;
  12987. var theme = context.theme;
  12988. var shapeTheme = theme.shape[geomType] || {};
  12989. var defaultShapeStyle = shapeTheme.default;
  12990. var shapeThemeStyle = shapeTheme[shape];
  12991. var style = props.style;
  12992. var shapeStyle = _objectSpread(_objectSpread({}, defaultShapeStyle), shapeThemeStyle);
  12993. if (!style || !isObject(style)) {
  12994. return shapeStyle;
  12995. }
  12996. // @ts-ignore
  12997. var field = style.field,
  12998. styles = _objectWithoutProperties(style, _excluded$3);
  12999. var value = field ? origin[field] : origin;
  13000. each(styles, function (attr, key) {
  13001. if (isFunction(attr)) {
  13002. shapeStyle[key] = attr(value);
  13003. } else {
  13004. shapeStyle[key] = attr;
  13005. }
  13006. });
  13007. return shapeStyle;
  13008. }
  13009. /**
  13010. * 数据映射到视图属性核心逻辑
  13011. * x、y 每个元素走 normalize 然后 convertPoint
  13012. * color、size、shape
  13013. * 如果是Linear,则每个元素 走 mapping
  13014. * 如果是Category/Identity 则第一个元素走 mapping
  13015. */
  13016. }, {
  13017. key: "_mapping",
  13018. value: function _mapping(records) {
  13019. var attrs = this.attrs,
  13020. props = this.props,
  13021. attrController = this.attrController;
  13022. var coord = props.coord;
  13023. var _attrController$getAt = attrController.getAttrsByLinear(),
  13024. linearAttrs = _attrController$getAt.linearAttrs,
  13025. nonlinearAttrs = _attrController$getAt.nonlinearAttrs;
  13026. var defaultAttrValues = attrController.getDefaultAttrValues();
  13027. for (var i = 0, len = records.length; i < len; i++) {
  13028. var record = records[i];
  13029. var children = record.children;
  13030. var attrValues = _objectSpread({}, defaultAttrValues);
  13031. var firstChild = children[0];
  13032. if (children.length === 0) {
  13033. continue;
  13034. }
  13035. // 非线性映射
  13036. for (var k = 0, _len = nonlinearAttrs.length; k < _len; k++) {
  13037. var attrName = nonlinearAttrs[k];
  13038. var attr = attrs[attrName];
  13039. // 非线性映射只用映射第一项就可以了
  13040. attrValues[attrName] = attr.mapping(firstChild[attr.field]);
  13041. }
  13042. // 线性属性映射
  13043. for (var j = 0, childrenLen = children.length; j < childrenLen; j++) {
  13044. var child = children[j];
  13045. var normalized = {};
  13046. for (var _k = 0; _k < linearAttrs.length; _k++) {
  13047. var _attrName = linearAttrs[_k];
  13048. var _attr = attrs[_attrName];
  13049. // 分类属性的线性映射
  13050. if (attrController.isGroupAttr(_attrName)) {
  13051. attrValues[_attrName] = _attr.mapping(child[_attr.field], child);
  13052. } else {
  13053. normalized[_attrName] = _attr.normalize(child[_attr.field]);
  13054. }
  13055. }
  13056. var _coord$convertPoint = coord.convertPoint({
  13057. x: normalized.x,
  13058. y: normalized.y
  13059. }),
  13060. x = _coord$convertPoint.x,
  13061. y = _coord$convertPoint.y;
  13062. // 获取 shape 的 style
  13063. var shapeName = attrValues.shape;
  13064. var shape = this._getShapeStyle(shapeName, child.origin);
  13065. var selected = this.isSelected(child);
  13066. mix(child, attrValues, {
  13067. normalized: normalized,
  13068. x: x,
  13069. y: y,
  13070. shapeName: shapeName,
  13071. shape: shape,
  13072. selected: selected
  13073. });
  13074. }
  13075. }
  13076. return records;
  13077. }
  13078. // 数据映射
  13079. }, {
  13080. key: "mapping",
  13081. value: function mapping() {
  13082. var records = this.records;
  13083. // 数据映射
  13084. this._mapping(records);
  13085. return records;
  13086. }
  13087. }, {
  13088. key: "getClip",
  13089. value: function getClip() {
  13090. var _this$props = this.props,
  13091. coord = _this$props.coord,
  13092. viewClip = _this$props.viewClip;
  13093. var contentWidth = coord.width,
  13094. contentHeight = coord.height,
  13095. left = coord.left,
  13096. top = coord.top;
  13097. if (viewClip) {
  13098. return {
  13099. type: 'rect',
  13100. attrs: {
  13101. x: left,
  13102. y: top,
  13103. width: contentWidth,
  13104. height: contentHeight
  13105. }
  13106. };
  13107. }
  13108. return null;
  13109. }
  13110. }, {
  13111. key: "getAttr",
  13112. value: function getAttr(attrName) {
  13113. return this.attrController.getAttr(attrName);
  13114. }
  13115. }, {
  13116. key: "getXScale",
  13117. value: function getXScale() {
  13118. return this.getAttr('x').scale;
  13119. }
  13120. }, {
  13121. key: "getYScale",
  13122. value: function getYScale() {
  13123. return this.getAttr('y').scale;
  13124. }
  13125. }, {
  13126. key: "_getXSnap",
  13127. value: function _getXSnap(invertPointX) {
  13128. var xScale = this.getXScale();
  13129. if (xScale.isCategory) {
  13130. return xScale.invert(invertPointX);
  13131. }
  13132. // linear 类型
  13133. var invertValue = xScale.invert(invertPointX);
  13134. var values = xScale.values;
  13135. var len = values.length;
  13136. // 如果只有1个点直接返回第1个点
  13137. if (len === 1) {
  13138. return values[0];
  13139. }
  13140. // 第1个点和第2个点之间
  13141. if ((values[0] + values[1]) / 2 > invertValue) {
  13142. return values[0];
  13143. }
  13144. // 最后2个点
  13145. if ((values[len - 2] + values[len - 1]) / 2 <= invertValue) {
  13146. return values[len - 1];
  13147. }
  13148. for (var i = 1; i < len; i++) {
  13149. // 中间的点
  13150. if ((values[i - 1] + values[i]) / 2 <= invertValue && (values[i + 1] + values[i]) / 2 > invertValue) {
  13151. return values[i];
  13152. }
  13153. }
  13154. return null;
  13155. }
  13156. }, {
  13157. key: "_getYSnapRecords",
  13158. value: function _getYSnapRecords(invertPointY, records) {
  13159. var yScale = this.getYScale();
  13160. var yField = yScale.field;
  13161. var yValue = yScale.invert(invertPointY);
  13162. // category
  13163. if (yScale.isCategory) {
  13164. return records.filter(function (record) {
  13165. return record[FIELD_ORIGIN][yField] === yValue;
  13166. });
  13167. }
  13168. // linear
  13169. return records.filter(function (record) {
  13170. var rangeY = record[yField];
  13171. if (rangeY[0] <= yValue && rangeY[1] >= yValue) {
  13172. return true;
  13173. }
  13174. return false;
  13175. });
  13176. }
  13177. // 把 records 拍平
  13178. }, {
  13179. key: "flatRecords",
  13180. value: function flatRecords() {
  13181. var records = this.records;
  13182. return records.reduce(function (prevRecords, record) {
  13183. return prevRecords.concat(record.children);
  13184. }, []);
  13185. }
  13186. }, {
  13187. key: "getSnapRecords",
  13188. value: function getSnapRecords(point, inCoordRange) {
  13189. var props = this.props;
  13190. var coord = props.coord,
  13191. adjust = props.adjust;
  13192. var invertPoint = coord.invertPoint(point);
  13193. var xScale = this.getXScale();
  13194. var yScale = this.getYScale();
  13195. // 如果不在coord坐标范围内,直接返回空
  13196. // if (invertPoint.x < 0 || invertPoint.y < 0) {
  13197. // return [];
  13198. // }
  13199. // 是否调整 point,默认为不调整
  13200. if (inCoordRange) {
  13201. var xRange = xScale.range;
  13202. var yRange = yScale.range;
  13203. // 如果 inCoordRange=true,当 point 不在 coord 坐标范围内时,调整到 range 内
  13204. invertPoint.x = Math.min(Math.max(invertPoint.x, xRange[0]), xRange[1]);
  13205. invertPoint.y = Math.min(Math.max(invertPoint.y, yRange[0]), yRange[1]);
  13206. }
  13207. var records = this.flatRecords();
  13208. // 处理饼图
  13209. if (adjust === 'stack' && coord.isPolar && coord.transposed) {
  13210. // 弧度在半径范围内
  13211. if (invertPoint.x >= 0 && invertPoint.x <= 1) {
  13212. var snapRecords = this._getYSnapRecords(invertPoint.y, records);
  13213. return snapRecords;
  13214. }
  13215. }
  13216. var rst = [];
  13217. var value = this._getXSnap(invertPoint.x);
  13218. if (!value) {
  13219. return rst;
  13220. }
  13221. var xField = xScale.field;
  13222. var yField = yScale.field;
  13223. for (var i = 0, len = records.length; i < len; i++) {
  13224. var record = _objectSpread(_objectSpread({}, records[i]), {}, {
  13225. xField: xField,
  13226. yField: yField
  13227. });
  13228. var originValue = record[FIELD_ORIGIN][xField];
  13229. if (xScale.type === 'timeCat' && toTimeStamp(originValue) === value) {
  13230. rst.push(record);
  13231. } else if (originValue === value) {
  13232. rst.push(record);
  13233. }
  13234. }
  13235. return rst;
  13236. }
  13237. }, {
  13238. key: "getLegendItems",
  13239. value: function getLegendItems() {
  13240. var attrController = this.attrController;
  13241. var colorAttr = attrController.getAttr('color');
  13242. if (!colorAttr) return null;
  13243. var scale = colorAttr.scale;
  13244. if (!scale.isCategory) return null;
  13245. var ticks = scale.getTicks();
  13246. var items = ticks.map(function (tick) {
  13247. var text = tick.text,
  13248. tickValue = tick.tickValue;
  13249. var color = colorAttr.mapping(tickValue);
  13250. return {
  13251. field: scale.field,
  13252. color: color,
  13253. name: text,
  13254. tickValue: tickValue
  13255. };
  13256. });
  13257. return items;
  13258. }
  13259. }]);
  13260. return Geometry;
  13261. }(Selection);
  13262. var arrayWithoutHoles = createCommonjsModule(function (module) {
  13263. function _arrayWithoutHoles(arr) {
  13264. if (Array.isArray(arr)) return arrayLikeToArray(arr);
  13265. }
  13266. module.exports = _arrayWithoutHoles, module.exports.__esModule = true, module.exports["default"] = module.exports;
  13267. });
  13268. var iterableToArray = createCommonjsModule(function (module) {
  13269. function _iterableToArray(iter) {
  13270. if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
  13271. }
  13272. module.exports = _iterableToArray, module.exports.__esModule = true, module.exports["default"] = module.exports;
  13273. });
  13274. var nonIterableSpread = createCommonjsModule(function (module) {
  13275. function _nonIterableSpread() {
  13276. throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
  13277. }
  13278. module.exports = _nonIterableSpread, module.exports.__esModule = true, module.exports["default"] = module.exports;
  13279. });
  13280. var toConsumableArray = createCommonjsModule(function (module) {
  13281. function _toConsumableArray(arr) {
  13282. return arrayWithoutHoles(arr) || iterableToArray(arr) || unsupportedIterableToArray(arr) || nonIterableSpread();
  13283. }
  13284. module.exports = _toConsumableArray, module.exports.__esModule = true, module.exports["default"] = module.exports;
  13285. });
  13286. var _toConsumableArray = /*@__PURE__*/getDefaultExportFromCjs(toConsumableArray);
  13287. var withLine = (function (View) {
  13288. return /*#__PURE__*/function (_Geometry) {
  13289. _inherits(Line, _Geometry);
  13290. var _super = _createSuper(Line);
  13291. function Line() {
  13292. _classCallCheck(this, Line);
  13293. return _super.apply(this, arguments);
  13294. }
  13295. _createClass(Line, [{
  13296. key: "getDefaultCfg",
  13297. value: function getDefaultCfg() {
  13298. return {
  13299. geomType: 'line',
  13300. sortable: true
  13301. };
  13302. }
  13303. }, {
  13304. key: "splitPoints",
  13305. value: function splitPoints(points) {
  13306. var topPoints = [];
  13307. var bottomPoints = [];
  13308. for (var i = 0, len = points.length; i < len; i++) {
  13309. var point = points[i];
  13310. var x = point.x,
  13311. y = point.y;
  13312. topPoints.push(_objectSpread(_objectSpread({}, point), {}, {
  13313. x: x,
  13314. y: y[1]
  13315. }));
  13316. bottomPoints.push(_objectSpread(_objectSpread({}, point), {}, {
  13317. x: x,
  13318. y: y[0]
  13319. }));
  13320. }
  13321. return [topPoints, bottomPoints];
  13322. }
  13323. }, {
  13324. key: "splitNulls",
  13325. value: function splitNulls(points, connectNulls) {
  13326. if (connectNulls) {
  13327. var _tmpPoints = [];
  13328. for (var i = 0, len = points.length; i < len; i++) {
  13329. var point = points[i];
  13330. var y = point.y;
  13331. if (isArray(y)) {
  13332. if (isNaN(y[0])) {
  13333. continue;
  13334. }
  13335. _tmpPoints.push(point);
  13336. continue;
  13337. }
  13338. if (isNaN(y)) {
  13339. continue;
  13340. }
  13341. _tmpPoints.push(point);
  13342. }
  13343. if (_tmpPoints.length) {
  13344. return [_tmpPoints];
  13345. }
  13346. return [];
  13347. }
  13348. var result = [];
  13349. var tmpPoints = [];
  13350. for (var _i = 0, _len = points.length; _i < _len; _i++) {
  13351. var _point = points[_i];
  13352. var _y = _point.y;
  13353. if (isArray(_y)) {
  13354. if (isNaN(_y[0])) {
  13355. if (tmpPoints.length) {
  13356. result.push(tmpPoints);
  13357. tmpPoints = [];
  13358. }
  13359. continue;
  13360. }
  13361. tmpPoints.push(_point);
  13362. continue;
  13363. }
  13364. if (isNaN(_y)) {
  13365. if (tmpPoints.length) {
  13366. result.push(tmpPoints);
  13367. tmpPoints = [];
  13368. }
  13369. continue;
  13370. }
  13371. tmpPoints.push(_point);
  13372. }
  13373. if (tmpPoints.length) {
  13374. result.push(tmpPoints);
  13375. }
  13376. return result;
  13377. }
  13378. }, {
  13379. key: "mapping",
  13380. value: function mapping() {
  13381. var _this = this;
  13382. var records = _get$1(_getPrototypeOf(Line.prototype), "mapping", this).call(this);
  13383. var props = this.props,
  13384. defaultConnectNulls = this.connectNulls;
  13385. var coord = props.coord,
  13386. _props$connectNulls = props.connectNulls,
  13387. connectNulls = _props$connectNulls === void 0 ? defaultConnectNulls : _props$connectNulls;
  13388. return records.map(function (record) {
  13389. var children = record.children;
  13390. // children 有可能为空
  13391. var _ref = children[0] || {},
  13392. size = _ref.size,
  13393. color = _ref.color,
  13394. shape = _ref.shape,
  13395. y = _ref.y;
  13396. // 极坐标时,需加入起点,从而闭合所绘图形
  13397. var points = coord.isPolar ? [].concat(_toConsumableArray(children), [children[0]]) : children;
  13398. var splitPoints = _this.splitNulls(points, connectNulls);
  13399. var newChildren = splitPoints.map(function (points) {
  13400. var _ref2 = isArray(y) ? _this.splitPoints(points) : [points, undefined],
  13401. _ref3 = _slicedToArray(_ref2, 2),
  13402. topPoints = _ref3[0],
  13403. bottomPoints = _ref3[1];
  13404. return {
  13405. size: size,
  13406. color: color,
  13407. shape: shape,
  13408. points: topPoints,
  13409. bottomPoints: bottomPoints
  13410. };
  13411. });
  13412. return _objectSpread(_objectSpread({}, record), {}, {
  13413. children: newChildren
  13414. });
  13415. });
  13416. }
  13417. }, {
  13418. key: "render",
  13419. value: function render() {
  13420. var props = this.props;
  13421. var coord = props.coord;
  13422. var records = this.mapping();
  13423. var clip = this.getClip();
  13424. return jsx(View, _objectSpread(_objectSpread({}, props), {}, {
  13425. coord: coord,
  13426. records: records,
  13427. clip: clip
  13428. }));
  13429. }
  13430. }]);
  13431. return Line;
  13432. }(Geometry);
  13433. });
  13434. function concatPoints(children) {
  13435. var result = [];
  13436. for (var i = 0; i < children.length; i++) {
  13437. var child = children[i];
  13438. result = result.concat(child.points);
  13439. }
  13440. return result;
  13441. }
  13442. function formatPoint(point) {
  13443. var y = point.y;
  13444. return {
  13445. x: point.x,
  13446. y: isArray(y) ? y[1] : y
  13447. };
  13448. }
  13449. function getPoint$1(points, t) {
  13450. var formatedPoints = points.map(function (p) {
  13451. return formatPoint(p);
  13452. });
  13453. var firstPoint = formatedPoints[0];
  13454. var lastPoint = formatedPoints[formatedPoints.length - 1];
  13455. var xOffset = lastPoint.x - firstPoint.x;
  13456. var x = firstPoint.x + xOffset * t;
  13457. for (var i = 1; i < formatedPoints.length; i++) {
  13458. var point = formatedPoints[i];
  13459. var prevPoint = formatedPoints[i - 1];
  13460. if (x >= prevPoint.x && x <= point.x) {
  13461. // x 在 2 点之间的比例,根据比例再算出 y 的值
  13462. var ratio = (x - prevPoint.x) / (point.x - prevPoint.x);
  13463. return {
  13464. x: x,
  13465. y: prevPoint.y + (point.y - prevPoint.y) * ratio
  13466. };
  13467. }
  13468. }
  13469. }
  13470. function AnimationEndView(props) {
  13471. var record = props.record,
  13472. appear = props.appear,
  13473. EndView = props.EndView;
  13474. var children = record.children;
  13475. var points = concatPoints(children);
  13476. var origin = points[0].origin;
  13477. return jsx("group", {
  13478. animation: {
  13479. appear: {
  13480. easing: appear.easing,
  13481. duration: appear.duration,
  13482. onFrame: function onFrame(t) {
  13483. // 这段逻辑有点恶心。。
  13484. var element = this.element;
  13485. var children = element.get('children');
  13486. var point = getPoint$1(points, t);
  13487. children.forEach(function (child) {
  13488. child.moveTo(point.x, point.y);
  13489. });
  13490. }
  13491. }
  13492. }
  13493. }, jsx(EndView, {
  13494. origin: origin
  13495. }));
  13496. }
  13497. var LineView = (function (props) {
  13498. var records = props.records,
  13499. coord = props.coord,
  13500. animation = props.animation,
  13501. EndView = props.endView,
  13502. clip = props.clip;
  13503. var left = coord.left,
  13504. top = coord.top,
  13505. width = coord.width,
  13506. height = coord.height,
  13507. center = coord.center,
  13508. startAngle = coord.startAngle,
  13509. endAngle = coord.endAngle,
  13510. radius = coord.radius;
  13511. var appear = coord.isPolar ? {
  13512. easing: 'quadraticOut',
  13513. duration: 450,
  13514. clip: {
  13515. type: 'sector',
  13516. property: ['endAngle'],
  13517. attrs: {
  13518. x: center.x,
  13519. y: center.y,
  13520. startAngle: startAngle,
  13521. r: radius
  13522. },
  13523. start: {
  13524. endAngle: startAngle
  13525. },
  13526. end: {
  13527. endAngle: endAngle
  13528. }
  13529. }
  13530. } : {
  13531. easing: 'quadraticOut',
  13532. duration: 450,
  13533. clip: {
  13534. type: 'rect',
  13535. property: ['width'],
  13536. attrs: {
  13537. x: left,
  13538. y: top,
  13539. height: height
  13540. },
  13541. start: {
  13542. width: 0
  13543. },
  13544. end: {
  13545. width: width
  13546. }
  13547. }
  13548. };
  13549. return jsx("group", {
  13550. attrs: {
  13551. clip: clip
  13552. }
  13553. }, records.map(function (record) {
  13554. var key = record.key,
  13555. children = record.children;
  13556. return jsx("group", {
  13557. key: key
  13558. }, children.map(function (child) {
  13559. var points = child.points,
  13560. color = child.color,
  13561. size = child.size,
  13562. shape = child.shape;
  13563. return jsx("polyline", {
  13564. attrs: _objectSpread(_objectSpread({
  13565. points: points.map(function (point) {
  13566. return {
  13567. x: point.x,
  13568. y: point.y
  13569. };
  13570. }),
  13571. stroke: color
  13572. }, shape), {}, {
  13573. lineWidth: size || shape.lineWidth
  13574. }),
  13575. animation: deepMix({
  13576. update: {
  13577. easing: 'linear',
  13578. duration: 450,
  13579. property: ['points']
  13580. },
  13581. appear: appear
  13582. }, animation)
  13583. });
  13584. }), EndView ? jsx(AnimationEndView, {
  13585. record: record,
  13586. EndView: EndView,
  13587. appear: appear
  13588. }) : null);
  13589. }));
  13590. });
  13591. var index = withLine(LineView);
  13592. var withArea = (function (View) {
  13593. return /*#__PURE__*/function (_withLine) {
  13594. _inherits(Area, _withLine);
  13595. var _super = _createSuper(Area);
  13596. function Area() {
  13597. _classCallCheck(this, Area);
  13598. return _super.apply(this, arguments);
  13599. }
  13600. _createClass(Area, [{
  13601. key: "getDefaultCfg",
  13602. value: function getDefaultCfg() {
  13603. return {
  13604. geomType: 'area',
  13605. // 面积图默认设为从0开始
  13606. startOnZero: true,
  13607. // 点需要排序
  13608. sortable: true
  13609. };
  13610. }
  13611. }, {
  13612. key: "mapping",
  13613. value: function mapping() {
  13614. var records = _get$1(_getPrototypeOf(Area.prototype), "mapping", this).call(this);
  13615. // 坐标轴 y0
  13616. var y0 = this.getY0Value();
  13617. var props = this.props,
  13618. defaultStartOnZero = this.startOnZero;
  13619. var coord = props.coord,
  13620. _props$startOnZero = props.startOnZero,
  13621. startOnZero = _props$startOnZero === void 0 ? defaultStartOnZero : _props$startOnZero;
  13622. var baseY = coord.y[0];
  13623. if (startOnZero) {
  13624. // 零点映射到绝对坐标
  13625. var originCoord = coord.convertPoint({
  13626. x: 0,
  13627. y: y0
  13628. });
  13629. baseY = originCoord.y;
  13630. }
  13631. for (var i = 0, len = records.length; i < len; i++) {
  13632. var record = records[i];
  13633. var children = record.children;
  13634. for (var j = 0, _len = children.length; j < _len; j++) {
  13635. var child = children[j];
  13636. var points = child.points,
  13637. bottomPoints = child.bottomPoints;
  13638. if (bottomPoints && bottomPoints.length) {
  13639. bottomPoints.reverse();
  13640. child.points = points.concat(bottomPoints);
  13641. } else {
  13642. points.push({
  13643. x: points[points.length - 1].x,
  13644. y: baseY
  13645. });
  13646. points.push({
  13647. x: points[0].x,
  13648. y: baseY
  13649. });
  13650. }
  13651. }
  13652. }
  13653. return records;
  13654. }
  13655. }]);
  13656. return Area;
  13657. }(withLine(View));
  13658. });
  13659. var AreaView = (function (props) {
  13660. var coord = props.coord,
  13661. records = props.records,
  13662. shape = props.shape,
  13663. animation = props.animation;
  13664. var isSmooth = shape === 'smooth';
  13665. var left = coord.left,
  13666. top = coord.top,
  13667. width = coord.width,
  13668. height = coord.height,
  13669. center = coord.center,
  13670. startAngle = coord.startAngle,
  13671. endAngle = coord.endAngle,
  13672. radius = coord.radius;
  13673. var appear = coord.isPolar ? {
  13674. easing: 'quadraticOut',
  13675. duration: 450,
  13676. clip: {
  13677. type: 'sector',
  13678. property: ['endAngle'],
  13679. attrs: {
  13680. x: center.x,
  13681. y: center.y,
  13682. startAngle: startAngle,
  13683. r: radius
  13684. },
  13685. start: {
  13686. endAngle: startAngle
  13687. },
  13688. end: {
  13689. endAngle: endAngle
  13690. }
  13691. }
  13692. } : {
  13693. easing: 'quadraticOut',
  13694. duration: 450,
  13695. clip: {
  13696. type: 'rect',
  13697. property: ['width'],
  13698. attrs: {
  13699. x: left,
  13700. y: top,
  13701. height: height
  13702. },
  13703. start: {
  13704. width: 0
  13705. },
  13706. end: {
  13707. width: width
  13708. }
  13709. }
  13710. };
  13711. return jsx("group", null, records.map(function (record) {
  13712. var key = record.key,
  13713. children = record.children;
  13714. return jsx("group", {
  13715. key: key
  13716. }, children.map(function (child) {
  13717. var points = child.points,
  13718. bottomPoints = child.bottomPoints,
  13719. color = child.color,
  13720. shape = child.shape;
  13721. if (isSmooth) {
  13722. return jsx("custom", {
  13723. attrs: _objectSpread({
  13724. points: points,
  13725. lineWidth: '2px',
  13726. fill: color
  13727. }, shape),
  13728. createPath: function createPath(context) {
  13729. var constaint = [[0, 0], [1, 1]];
  13730. var bottomPointsLen = (bottomPoints === null || bottomPoints === void 0 ? void 0 : bottomPoints.length) || 0;
  13731. var topPoints = points.slice(0, points.length - bottomPointsLen);
  13732. var topSps = catmullRom2bezier(topPoints, false, constaint);
  13733. context.beginPath();
  13734. context.moveTo(topPoints[0].x, topPoints[0].y);
  13735. for (var i = 0, n = topSps.length; i < n; i++) {
  13736. var sp = topSps[i];
  13737. context.bezierCurveTo(sp[1], sp[2], sp[3], sp[4], sp[5], sp[6]);
  13738. }
  13739. if (bottomPointsLen) {
  13740. var bottomSps = catmullRom2bezier(bottomPoints, false, constaint);
  13741. context.lineTo(bottomPoints[0].x, bottomPoints[0].y);
  13742. for (var _i = 0, _n = bottomSps.length; _i < _n; _i++) {
  13743. var _sp = bottomSps[_i];
  13744. context.bezierCurveTo(_sp[1], _sp[2], _sp[3], _sp[4], _sp[5], _sp[6]);
  13745. }
  13746. }
  13747. context.closePath();
  13748. },
  13749. calculateBox: function calculateBox() {
  13750. return getBBoxFromPoints(points);
  13751. }
  13752. });
  13753. }
  13754. return jsx("polygon", {
  13755. attrs: _objectSpread({
  13756. points: points,
  13757. lineWidth: '2px',
  13758. fill: color
  13759. }, shape),
  13760. animation: deepMix({
  13761. appear: appear,
  13762. update: {
  13763. easing: 'linear',
  13764. duration: 450,
  13765. property: ['points']
  13766. }
  13767. }, animation)
  13768. });
  13769. }));
  13770. }));
  13771. });
  13772. var index$1 = withArea(AreaView);
  13773. /**
  13774. * 计算两个坐标的中点坐标
  13775. * @param start 起始点{x:number, y:number}
  13776. * @param end 结束点{x:number, y:number}
  13777. * @returns 中点坐标{x:number, y:number}
  13778. */
  13779. function getMiddlePoint(start, end) {
  13780. var x = (end.x - start.x) / 2 + start.x;
  13781. var y = (end.y - start.y) / 2 + start.y;
  13782. return {
  13783. x: x,
  13784. y: y
  13785. };
  13786. }
  13787. var DEFAULT_LABEL_CFG = {
  13788. textBaseline: 'middle',
  13789. fill: '#808080'
  13790. };
  13791. function LabelView(props) {
  13792. var record = props.record,
  13793. offsetX = props.offsetX,
  13794. offsetY = props.offsetY,
  13795. points = props.points,
  13796. label = props.label,
  13797. guide = props.guide;
  13798. var origin = record.origin,
  13799. color = record.color;
  13800. var labelAttrs, guideAttrs;
  13801. if (isFunction(label)) {
  13802. var point = points.length === 4 // 如果是金字塔图,顶部只有 3 个点
  13803. ? getMiddlePoint(points[1], points[2]) : getMiddlePoint(points[0], points[1]);
  13804. labelAttrs = mix({
  13805. x: point.x + offsetX,
  13806. y: point.y + offsetY
  13807. }, DEFAULT_LABEL_CFG, label(origin, color));
  13808. }
  13809. if (isFunction(guide)) {
  13810. var _points$;
  13811. var _point = getMiddlePoint(points.length === 4 ? getMiddlePoint(points[0], points[1]) : points[0], getMiddlePoint(points[2], (_points$ = points[3]) !== null && _points$ !== void 0 ? _points$ : points[1]));
  13812. guideAttrs = mix({
  13813. x: _point.x,
  13814. y: _point.y,
  13815. textBaseline: 'middle',
  13816. textAlign: 'center'
  13817. }, DEFAULT_LABEL_CFG, guide(origin, color));
  13818. }
  13819. return jsx("group", null, labelAttrs && jsx("text", {
  13820. attrs: labelAttrs
  13821. }), guideAttrs && jsx("text", {
  13822. attrs: guideAttrs
  13823. }));
  13824. }
  13825. var LabelViews = /*#__PURE__*/Object.freeze({
  13826. __proto__: null,
  13827. pyramid: LabelView,
  13828. funnel: LabelView
  13829. });
  13830. var withInterval = (function (Views) {
  13831. return /*#__PURE__*/function (_Geometry) {
  13832. _inherits(Interval, _Geometry);
  13833. var _super = _createSuper(Interval);
  13834. function Interval() {
  13835. _classCallCheck(this, Interval);
  13836. return _super.apply(this, arguments);
  13837. }
  13838. _createClass(Interval, [{
  13839. key: "getDefaultCfg",
  13840. value: function getDefaultCfg() {
  13841. return {
  13842. geomType: 'interval',
  13843. justifyContent: true,
  13844. startOnZero: true
  13845. };
  13846. }
  13847. }, {
  13848. key: "getDefaultSize",
  13849. value: function getDefaultSize() {
  13850. var attrs = this.attrs,
  13851. props = this.props,
  13852. adjust = this.adjust,
  13853. records = this.records;
  13854. var coord = props.coord,
  13855. sizeRatio = props.sizeRatio;
  13856. var x = attrs.x;
  13857. var scale = x.scale;
  13858. var values = scale.values;
  13859. if (sizeRatio) {
  13860. return 1 / values.length * sizeRatio;
  13861. }
  13862. var defaultWithRatio = {
  13863. column: 1 / 2,
  13864. rose: 0.999999,
  13865. multiplePie: 3 / 4 // 多饼图
  13866. };
  13867. var count = values.length;
  13868. var ratio;
  13869. if (coord.isPolar) {
  13870. if (coord.transposed && count > 1) {
  13871. ratio = defaultWithRatio.multiplePie;
  13872. } else {
  13873. ratio = defaultWithRatio.rose;
  13874. }
  13875. } else {
  13876. ratio = defaultWithRatio.column;
  13877. }
  13878. var size = 1 / values.length * ratio;
  13879. // 分组时size要除以类别个数
  13880. if (adjust && adjust.type === 'dodge') {
  13881. return size / records.length;
  13882. }
  13883. return size;
  13884. }
  13885. }, {
  13886. key: "mapping",
  13887. value: function mapping() {
  13888. var records = _get$1(_getPrototypeOf(Interval.prototype), "mapping", this).call(this);
  13889. var props = this.props;
  13890. var coord = props.coord;
  13891. var y0 = this.getY0Value();
  13892. var defaultSize = this.getDefaultSize();
  13893. for (var i = 0, len = records.length; i < len; i++) {
  13894. var record = records[i];
  13895. var children = record.children;
  13896. for (var j = 0, _len = children.length; j < _len; j++) {
  13897. var child = children[j];
  13898. var normalized = child.normalized,
  13899. mappedSize = child.size;
  13900. // 没有指定size,则根据数据来计算默认size
  13901. if (isNil(mappedSize)) {
  13902. var x = normalized.x,
  13903. y = normalized.y,
  13904. _normalized$size = normalized.size,
  13905. size = _normalized$size === void 0 ? defaultSize : _normalized$size;
  13906. mix(child, coord.convertRect({
  13907. x: x,
  13908. y: y,
  13909. y0: y0,
  13910. size: size
  13911. }));
  13912. } else {
  13913. var _child = child,
  13914. _x = _child.x,
  13915. _y = _child.y;
  13916. var rect = {
  13917. size: mappedSize,
  13918. x: _x,
  13919. y: _y,
  13920. y0: y0
  13921. };
  13922. mix(child, coord.transformToRect(rect));
  13923. }
  13924. mix(child.shape, this.getSelectionStyle(child));
  13925. }
  13926. }
  13927. return records;
  13928. }
  13929. // 获取Y轴坐标零点的画布位置
  13930. }, {
  13931. key: "getPointY0",
  13932. value: function getPointY0() {
  13933. var props = this.props;
  13934. var coord = props.coord;
  13935. var y0 = this.getY0Value();
  13936. var y0Point = coord.convertPoint({
  13937. y: y0,
  13938. x: 0
  13939. });
  13940. return y0Point === null || y0Point === void 0 ? void 0 : y0Point.y;
  13941. }
  13942. }, {
  13943. key: "render",
  13944. value: function render() {
  13945. var props = this.props,
  13946. state = this.state,
  13947. container = this.container;
  13948. var coord = props.coord,
  13949. _props$shape = props.shape,
  13950. shape = _props$shape === void 0 ? 'rect' : _props$shape,
  13951. animation = props.animation,
  13952. showLabel = props.showLabel,
  13953. customLabelCfg = props.labelCfg;
  13954. var View = isFunction(Views) ? Views : Views[shape];
  13955. var LabelView = LabelViews[shape];
  13956. var labelCfg = deepMix({
  13957. label: null,
  13958. offsetX: 0,
  13959. offsetY: 0
  13960. }, customLabelCfg);
  13961. if (!View) return null;
  13962. var selected = state.selected;
  13963. var records = this.mapping();
  13964. var pointY0 = this.getPointY0();
  13965. var clip = this.getClip();
  13966. return jsx(View, {
  13967. coord: coord,
  13968. records: records,
  13969. selected: selected,
  13970. shape: shape,
  13971. animation: animation,
  13972. showLabel: showLabel,
  13973. labelCfg: labelCfg,
  13974. LabelView: LabelView,
  13975. y0: pointY0,
  13976. clip: clip
  13977. });
  13978. }
  13979. }]);
  13980. return Interval;
  13981. }(Geometry);
  13982. });
  13983. var Rect$3 = (function (props) {
  13984. var records = props.records,
  13985. animation = props.animation,
  13986. y0 = props.y0,
  13987. clip = props.clip;
  13988. return jsx("group", {
  13989. attrs: {
  13990. clip: clip
  13991. }
  13992. }, records.map(function (record) {
  13993. var key = record.key,
  13994. children = record.children;
  13995. return jsx("group", {
  13996. key: key
  13997. }, children.map(function (item) {
  13998. var key = item.key,
  13999. xMin = item.xMin,
  14000. xMax = item.xMax,
  14001. yMin = item.yMin,
  14002. yMax = item.yMax,
  14003. color = item.color,
  14004. shape = item.shape;
  14005. if (isNaN(xMin) || isNaN(xMax) || isNaN(yMin) || isNaN(yMax)) {
  14006. return null;
  14007. }
  14008. return jsx("rect", {
  14009. key: key,
  14010. attrs: _objectSpread({
  14011. x: xMin,
  14012. y: yMin,
  14013. width: xMax - xMin,
  14014. height: yMax - yMin,
  14015. fill: color
  14016. }, shape),
  14017. animation: deepMix({
  14018. appear: {
  14019. easing: 'linear',
  14020. duration: 450,
  14021. property: ['y', 'height'],
  14022. start: {
  14023. y: y0,
  14024. height: 0
  14025. }
  14026. },
  14027. update: {
  14028. easing: 'linear',
  14029. duration: 450,
  14030. property: ['x', 'y', 'width', 'height']
  14031. }
  14032. }, animation)
  14033. });
  14034. }));
  14035. }));
  14036. });
  14037. var Polar$1 = (function (props) {
  14038. var coord = props.coord,
  14039. records = props.records,
  14040. animation = props.animation;
  14041. var center = coord.center,
  14042. startAngle = coord.startAngle,
  14043. endAngle = coord.endAngle,
  14044. radius = coord.radius;
  14045. return jsx("group", {
  14046. animation: {
  14047. appear: _objectSpread(_objectSpread({
  14048. easing: 'quadraticOut',
  14049. duration: 450
  14050. }, animation && animation.appear), {}, {
  14051. clip: {
  14052. type: 'sector',
  14053. property: ['endAngle'],
  14054. attrs: {
  14055. x: center.x,
  14056. y: center.y,
  14057. startAngle: startAngle,
  14058. r: radius
  14059. },
  14060. start: {
  14061. endAngle: startAngle
  14062. },
  14063. end: {
  14064. endAngle: endAngle
  14065. }
  14066. }
  14067. })
  14068. }
  14069. }, records.map(function (record) {
  14070. var key = record.key,
  14071. children = record.children;
  14072. return jsx("group", {
  14073. key: key
  14074. }, children.map(function (item) {
  14075. var key = item.key,
  14076. xMin = item.xMin,
  14077. xMax = item.xMax,
  14078. yMin = item.yMin,
  14079. yMax = item.yMax,
  14080. color = item.color,
  14081. shape = item.shape;
  14082. return jsx("sector", {
  14083. key: key,
  14084. attrs: _objectSpread({
  14085. x: center.x,
  14086. y: center.y,
  14087. fill: color,
  14088. startAngle: xMin,
  14089. endAngle: xMax,
  14090. r0: yMin,
  14091. r: yMax
  14092. }, shape),
  14093. animation: deepMix({
  14094. update: {
  14095. easing: 'linear',
  14096. duration: 450,
  14097. property: ['x', 'y', 'startAngle', 'endAngle', 'r0', 'r']
  14098. }
  14099. }, animation)
  14100. });
  14101. }));
  14102. }));
  14103. });
  14104. var intervalView = (function (props) {
  14105. var coord = props.coord;
  14106. var coordType = coord.type;
  14107. // 直角坐标系
  14108. if (coordType === 'rect') {
  14109. return jsx(Rect$3, _objectSpread({}, props));
  14110. }
  14111. // 极坐标系
  14112. return jsx(Polar$1, _objectSpread({}, props));
  14113. });
  14114. function convertToPoints(_ref) {
  14115. var xMin = _ref.xMin,
  14116. xMax = _ref.xMax,
  14117. yMin = _ref.yMin,
  14118. yMax = _ref.yMax;
  14119. return [{
  14120. x: xMin,
  14121. y: yMin
  14122. }, {
  14123. x: xMax,
  14124. y: yMin
  14125. }, {
  14126. x: xMax,
  14127. y: yMax
  14128. }, {
  14129. x: xMin,
  14130. y: yMax
  14131. } // bl
  14132. ];
  14133. }
  14134. // 金字塔图和漏斗图的View
  14135. var polygonView = (function (props) {
  14136. var records = props.records,
  14137. shape = props.shape,
  14138. showLabel = props.showLabel,
  14139. labelCfg = props.labelCfg,
  14140. LabelView = props.LabelView;
  14141. // 是否倒置
  14142. var overturn = false;
  14143. return jsx("group", null, records.map(function (record, index) {
  14144. var key = record.key,
  14145. children = record.children;
  14146. var isLastRecord = index === records.length - 1;
  14147. var nextRecord = isLastRecord ? record : records[index + 1];
  14148. var nextChildren = nextRecord.children;
  14149. var nextFirstPoint = convertToPoints(nextChildren[0]);
  14150. var nextLastPoints = convertToPoints(nextChildren[nextChildren.length - 1]);
  14151. if (!overturn) {
  14152. overturn = nextChildren[0].yMax > children[0].yMax;
  14153. }
  14154. if (overturn) {
  14155. nextFirstPoint.reverse();
  14156. nextLastPoints.reverse();
  14157. }
  14158. var polygonPoints = children.map(function (child, childIndex) {
  14159. var points = convertToPoints(child);
  14160. if (overturn) {
  14161. points.reverse();
  14162. }
  14163. if (isLastRecord) {
  14164. if (shape === 'pyramid') {
  14165. points = [getMiddlePoint(points[0], points[1]), points[2], points[3]];
  14166. }
  14167. } else {
  14168. if (childIndex === 0) {
  14169. points[0] = nextFirstPoint[3];
  14170. }
  14171. if (childIndex === children.length - 1) {
  14172. points[1] = nextLastPoints[2];
  14173. }
  14174. }
  14175. return _objectSpread(_objectSpread({}, child), {}, {
  14176. points: points
  14177. });
  14178. });
  14179. return jsx("group", {
  14180. key: key
  14181. }, polygonPoints.map(function (child) {
  14182. var points = child.points,
  14183. color = child.color,
  14184. shape = child.shape;
  14185. return jsx("group", null, jsx("polygon", {
  14186. attrs: _objectSpread({
  14187. points: points,
  14188. fill: color
  14189. }, shape)
  14190. }), showLabel && LabelView ? jsx(LabelView, _objectSpread({
  14191. record: child,
  14192. points: points
  14193. }, labelCfg)) : null);
  14194. }));
  14195. }));
  14196. });
  14197. // 柱图/条图
  14198. var Views = /*#__PURE__*/Object.freeze({
  14199. __proto__: null,
  14200. rect: intervalView,
  14201. pyramid: polygonView,
  14202. funnel: polygonView
  14203. });
  14204. var index$2 = withInterval(Views);
  14205. var withPoint = (function (View) {
  14206. return /*#__PURE__*/function (_Geometry) {
  14207. _inherits(Point, _Geometry);
  14208. var _super = _createSuper(Point);
  14209. function Point() {
  14210. _classCallCheck(this, Point);
  14211. return _super.apply(this, arguments);
  14212. }
  14213. _createClass(Point, [{
  14214. key: "getDefaultCfg",
  14215. value: function getDefaultCfg() {
  14216. return {
  14217. geomType: 'point'
  14218. };
  14219. }
  14220. }, {
  14221. key: "render",
  14222. value: function render() {
  14223. var props = this.props,
  14224. container = this.container;
  14225. var coord = props.coord;
  14226. var records = this.mapping();
  14227. var clip = this.getClip();
  14228. return jsx(View, _objectSpread(_objectSpread({}, props), {}, {
  14229. coord: coord,
  14230. records: records,
  14231. clip: clip
  14232. }));
  14233. }
  14234. }]);
  14235. return Point;
  14236. }(Geometry);
  14237. });
  14238. var PointView = (function (props) {
  14239. var records = props.records,
  14240. animation = props.animation,
  14241. clip = props.clip;
  14242. return jsx("group", {
  14243. attrs: {
  14244. clip: clip
  14245. }
  14246. }, records.map(function (record) {
  14247. var key = record.key,
  14248. children = record.children;
  14249. return jsx("group", {
  14250. key: key
  14251. }, children.map(function (item) {
  14252. var x = item.x,
  14253. y = item.y,
  14254. size = item.size,
  14255. color = item.color,
  14256. shapeName = item.shapeName,
  14257. shape = item.shape;
  14258. if (isNaN(x) || isNaN(y)) {
  14259. return null;
  14260. }
  14261. if (shapeName === 'rect') {
  14262. var rectSize = isNil(size) ? shape.size : size;
  14263. return jsx("rect", {
  14264. attrs: _objectSpread(_objectSpread({
  14265. x: x - rectSize,
  14266. y: y - rectSize,
  14267. fill: color,
  14268. stroke: color
  14269. }, shape), {}, {
  14270. width: rectSize * 2,
  14271. height: rectSize * 2
  14272. }),
  14273. animation: deepMix({
  14274. appear: {
  14275. easing: 'linear',
  14276. duration: 450
  14277. },
  14278. update: {
  14279. easing: 'linear',
  14280. duration: 450,
  14281. property: ['x', 'y', 'width', 'height', 'fill']
  14282. }
  14283. }, animation)
  14284. });
  14285. }
  14286. return jsx("circle", {
  14287. attrs: _objectSpread(_objectSpread({
  14288. x: x,
  14289. y: y,
  14290. fill: shapeName === 'circle' ? color : null,
  14291. stroke: shapeName === 'hollowCircle' ? color : null
  14292. }, shape), {}, {
  14293. r: isNil(size) ? shape.size : size
  14294. }),
  14295. animation: deepMix({
  14296. appear: {
  14297. easing: 'linear',
  14298. duration: 450
  14299. },
  14300. update: {
  14301. easing: 'linear',
  14302. duration: 450,
  14303. property: ['x', 'y', 'r', 'fill']
  14304. }
  14305. }, animation)
  14306. });
  14307. }));
  14308. }));
  14309. });
  14310. var index$3 = withPoint(PointView);
  14311. var withAxis = (function (View) {
  14312. return /*#__PURE__*/function (_Component) {
  14313. _inherits(Axis, _Component);
  14314. var _super = _createSuper(Axis);
  14315. function Axis(props) {
  14316. var _this;
  14317. _classCallCheck(this, Axis);
  14318. _this = _super.call(this, props);
  14319. _this.style = {};
  14320. var _this$props = _this.props,
  14321. chart = _this$props.chart,
  14322. field = _this$props.field;
  14323. var scaleOption = _this.getScaleOption(props);
  14324. chart.setScale(field, scaleOption);
  14325. return _this;
  14326. }
  14327. _createClass(Axis, [{
  14328. key: "willReceiveProps",
  14329. value: function willReceiveProps(nextProps) {
  14330. var lastProps = this.props;
  14331. var chart = nextProps.chart,
  14332. field = nextProps.field;
  14333. var nextScaleOption = this.getScaleOption(nextProps);
  14334. var lastScaleOption = this.getScaleOption(lastProps);
  14335. if (!equal(nextScaleOption, lastScaleOption)) {
  14336. chart.setScale(field, nextScaleOption);
  14337. }
  14338. }
  14339. }, {
  14340. key: "willMount",
  14341. value: function willMount() {
  14342. this.updateCoord();
  14343. }
  14344. }, {
  14345. key: "willUpdate",
  14346. value: function willUpdate() {
  14347. this.updateCoord();
  14348. }
  14349. }, {
  14350. key: "getScaleOption",
  14351. value: function getScaleOption(props) {
  14352. var type = props.type,
  14353. tickCount = props.tickCount,
  14354. range = props.range,
  14355. mask = props.mask,
  14356. formatter = props.formatter,
  14357. ticks = props.ticks,
  14358. min = props.min,
  14359. max = props.max,
  14360. nice = props.nice;
  14361. return {
  14362. type: type,
  14363. tickCount: tickCount,
  14364. range: range,
  14365. mask: mask,
  14366. formatter: formatter,
  14367. min: min,
  14368. max: max,
  14369. nice: nice,
  14370. ticks: ticks
  14371. };
  14372. }
  14373. }, {
  14374. key: "_getDimType",
  14375. value: function _getDimType() {
  14376. var props = this.props;
  14377. var field = props.field,
  14378. chart = props.chart;
  14379. var xScales = chart.getXScales();
  14380. var scales = xScales.filter(function (scale) {
  14381. return scale.field === field;
  14382. });
  14383. return scales.length > 0 ? 'x' : 'y';
  14384. }
  14385. // 获取ticks最大的宽高
  14386. }, {
  14387. key: "getMaxBBox",
  14388. value: function getMaxBBox(ticks, style) {
  14389. var context = this.context;
  14390. var measureText = context.measureText;
  14391. var label = style.label,
  14392. labelOffset = style.labelOffset;
  14393. var width = 0;
  14394. var height = 0;
  14395. ticks.forEach(function (tick) {
  14396. if (!label) return;
  14397. var _tick$labelStyle = tick.labelStyle,
  14398. labelStyle = _tick$labelStyle === void 0 ? {} : _tick$labelStyle,
  14399. text = tick.text;
  14400. var bbox = measureText(labelStyle.text || text, _objectSpread(_objectSpread({}, label), labelStyle));
  14401. width = Math.max(width, bbox.width);
  14402. height = Math.max(height, bbox.height);
  14403. });
  14404. if (!width && !height) {
  14405. return {
  14406. width: width,
  14407. height: height
  14408. };
  14409. }
  14410. var bbox = {
  14411. width: width + labelOffset,
  14412. height: height + labelOffset
  14413. };
  14414. return bbox;
  14415. }
  14416. }, {
  14417. key: "_getPosition",
  14418. value: function _getPosition() {
  14419. var props = this.props;
  14420. var position = props.position,
  14421. coord = props.coord;
  14422. if (position) {
  14423. return position;
  14424. }
  14425. var dimType = this._getDimType();
  14426. if (coord.transposed) {
  14427. return dimType === 'x' ? 'left' : 'bottom';
  14428. }
  14429. return dimType === 'x' ? 'bottom' : 'left';
  14430. }
  14431. }, {
  14432. key: "getTicks",
  14433. value: function getTicks() {
  14434. var props = this.props;
  14435. var field = props.field,
  14436. chart = props.chart;
  14437. var scale = chart.getScale(field);
  14438. var ticks = scale.getTicks();
  14439. // 设置tick的样式
  14440. ticks = this._setTicksStyle(ticks);
  14441. ticks = this._generateGridPoints(ticks);
  14442. return ticks;
  14443. }
  14444. /**
  14445. * 生成极坐标下网格线的交叉点
  14446. * @param ticks
  14447. * @returns
  14448. */
  14449. }, {
  14450. key: "_generateGridPoints",
  14451. value: function _generateGridPoints(ticks) {
  14452. var props = this.props;
  14453. var chart = props.chart,
  14454. coord = props.coord;
  14455. if (!coord.isPolar) {
  14456. return ticks;
  14457. }
  14458. var dimType = this._getDimType();
  14459. // 只需要在 y 的时候生成
  14460. if (dimType !== 'y') {
  14461. return ticks;
  14462. }
  14463. var xScale = chart.getXScales()[0];
  14464. var xTicks = xScale.getTicks();
  14465. ticks.forEach(function (tick) {
  14466. var gridPoints = xTicks.map(function (xTick) {
  14467. return coord.convertPoint({
  14468. x: xTick.value,
  14469. y: tick.value
  14470. });
  14471. });
  14472. // 添加第 1 个点,形成环状
  14473. gridPoints.push(gridPoints[0]);
  14474. tick.gridPoints = gridPoints;
  14475. });
  14476. return ticks;
  14477. }
  14478. }, {
  14479. key: "_setTicksStyle",
  14480. value: function _setTicksStyle(ticks) {
  14481. var _this2 = this;
  14482. var props = this.props,
  14483. context = this.context;
  14484. var theme = context.theme,
  14485. px2hd = context.px2hd;
  14486. var _props$style = props.style,
  14487. style = _props$style === void 0 ? {} : _props$style;
  14488. var themeAxis = theme.axis;
  14489. each(themeAxis, function (value, key) {
  14490. // 关闭tick的样式
  14491. if (style[key] === null) {
  14492. return;
  14493. }
  14494. var styleValue = isFunction(style[key]) ? undefined : style[key];
  14495. if (isString(value) || isNumber(value)) {
  14496. _this2.style[key] = px2hd(styleValue) || value;
  14497. } else {
  14498. _this2.style[key] = px2hd(deepMix(clone(value), styleValue));
  14499. }
  14500. });
  14501. return ticks.map(function (tick, index) {
  14502. var label = style.label,
  14503. grid = style.grid;
  14504. var defaultLabelStyle = themeAxis.label,
  14505. defaultGridStyle = themeAxis.grid;
  14506. if (isFunction(label)) {
  14507. tick.labelStyle = px2hd(mix({}, defaultLabelStyle, label(tick.text, index, ticks)));
  14508. }
  14509. if (isFunction(grid)) {
  14510. tick.gridStyle = px2hd(mix({}, defaultGridStyle, grid(tick.text, index, ticks.length)));
  14511. }
  14512. return tick;
  14513. });
  14514. }
  14515. }, {
  14516. key: "convertTicks",
  14517. value: function convertTicks(ticks) {
  14518. var props = this.props;
  14519. var coord = props.coord;
  14520. var dimType = this._getDimType();
  14521. var otherDim = dimType === 'x' ? 'y' : 'x';
  14522. return ticks.map(function (tick) {
  14523. var _coord$convertPoint, _coord$convertPoint2;
  14524. var start = coord.convertPoint((_coord$convertPoint = {}, _defineProperty(_coord$convertPoint, dimType, tick.value), _defineProperty(_coord$convertPoint, otherDim, 0), _coord$convertPoint));
  14525. var end = coord.convertPoint((_coord$convertPoint2 = {}, _defineProperty(_coord$convertPoint2, dimType, tick.value), _defineProperty(_coord$convertPoint2, otherDim, 1), _coord$convertPoint2));
  14526. return _objectSpread(_objectSpread({}, tick), {}, {
  14527. points: [start, end]
  14528. });
  14529. });
  14530. }
  14531. }, {
  14532. key: "measureLayout",
  14533. value: function measureLayout() {
  14534. var props = this.props;
  14535. var visible = props.visible,
  14536. coord = props.coord;
  14537. if (visible === false) {
  14538. return null;
  14539. }
  14540. var ticks = this.getTicks();
  14541. var bbox = this.getMaxBBox(ticks, this.style);
  14542. var isPolar = coord.isPolar;
  14543. var dimType = this._getDimType();
  14544. var width = bbox.width,
  14545. height = bbox.height;
  14546. if (isPolar) {
  14547. // 机坐标系的 y 不占位置
  14548. if (dimType === 'y') {
  14549. return null;
  14550. }
  14551. // 4 个方向都需要留空
  14552. return ['top', 'right', 'bottom', 'left'].map(function (position) {
  14553. return {
  14554. position: position,
  14555. width: width,
  14556. height: height
  14557. };
  14558. });
  14559. }
  14560. // 直角坐标系下
  14561. var position = this._getPosition();
  14562. return {
  14563. position: position,
  14564. width: width,
  14565. height: height
  14566. };
  14567. }
  14568. // 主要是计算coord的布局
  14569. }, {
  14570. key: "updateCoord",
  14571. value: function updateCoord() {
  14572. var props = this.props;
  14573. var chart = props.chart;
  14574. var layout = this.measureLayout();
  14575. chart.updateCoordFor(this, layout);
  14576. }
  14577. }, {
  14578. key: "render",
  14579. value: function render() {
  14580. var props = this.props,
  14581. style = this.style;
  14582. var visible = props.visible,
  14583. coord = props.coord;
  14584. if (visible === false) {
  14585. return null;
  14586. }
  14587. var ticks = this.getTicks();
  14588. var position = this._getPosition();
  14589. var dimType = this._getDimType();
  14590. return jsx(View, _objectSpread(_objectSpread({}, props), {}, {
  14591. style: style,
  14592. ticks: this.convertTicks(ticks),
  14593. coord: coord,
  14594. position: position,
  14595. dimType: dimType
  14596. }));
  14597. }
  14598. }]);
  14599. return Axis;
  14600. }(Component);
  14601. });
  14602. // const { Vector2 } = G;
  14603. // 相对圆心偏移量的点
  14604. function getOffsetPoint(center, point, offset) {
  14605. var vectorX = point.x - center.x;
  14606. var vectorY = point.y - center.y;
  14607. var vector = [vectorX, vectorY];
  14608. var vectorLength = Vector2.length(vector);
  14609. var offsetLength = vectorLength + offset;
  14610. var x = vectorX / vectorLength * offsetLength;
  14611. var y = vectorY / vectorLength * offsetLength;
  14612. return {
  14613. x: center.x + x,
  14614. y: center.y + y
  14615. };
  14616. }
  14617. // 获取文本的对齐方式
  14618. function getTextAlignInfo(center, point) {
  14619. // 文本点向量
  14620. var vector = [point.x - center.x, point.y - center.y];
  14621. var align;
  14622. var baseLine;
  14623. // 水平对齐
  14624. if (vector[0] > 0) {
  14625. align = 'left';
  14626. } else if (vector[0] < 0) {
  14627. align = 'right';
  14628. } else {
  14629. align = 'center';
  14630. }
  14631. // 垂直对齐
  14632. if (vector[1] > 0) {
  14633. baseLine = 'top';
  14634. } else if (vector[1] < 0) {
  14635. baseLine = 'bottom';
  14636. } else {
  14637. baseLine = 'middle';
  14638. }
  14639. return {
  14640. textAlign: align,
  14641. textBaseline: baseLine
  14642. };
  14643. }
  14644. var Line$1 = function Line(props) {
  14645. var line = props.line,
  14646. gridType = props.gridType,
  14647. center = props.center,
  14648. radius = props.radius,
  14649. ticks = props.ticks;
  14650. if (!line) return null;
  14651. if (gridType !== 'line') {
  14652. return jsx("arc", {
  14653. attrs: _objectSpread({
  14654. x: center.x,
  14655. y: center.y,
  14656. r: radius
  14657. }, line)
  14658. });
  14659. }
  14660. var points = ticks.map(function (tick) {
  14661. var points = tick.points;
  14662. return points[points.length - 1];
  14663. });
  14664. // 头尾相连
  14665. points.push(points[0]);
  14666. return jsx("polyline", {
  14667. attrs: _objectSpread({
  14668. points: points
  14669. }, line)
  14670. });
  14671. };
  14672. var PolarX = (function (props) {
  14673. var ticks = props.ticks,
  14674. coord = props.coord,
  14675. style = props.style,
  14676. gridType = props.grid;
  14677. var center = coord.center;
  14678. var grid = style.grid,
  14679. tickLine = style.tickLine,
  14680. line = style.line,
  14681. labelOffset = style.labelOffset,
  14682. label = style.label;
  14683. var firstTicks = ticks[0];
  14684. var points = firstTicks.points;
  14685. var end = points[points.length - 1];
  14686. var radius = Vector2.length([end.x - center.x, end.y - center.y]);
  14687. return jsx("group", null, grid ? ticks.map(function (tick) {
  14688. var points = tick.points,
  14689. gridStyle = tick.gridStyle;
  14690. var end = points[points.length - 1];
  14691. return jsx("line", {
  14692. attrs: _objectSpread(_objectSpread({
  14693. x1: center.x,
  14694. y1: center.y,
  14695. x2: end.x,
  14696. y2: end.y
  14697. }, grid), gridStyle)
  14698. });
  14699. }) : null, tickLine && tickLine.length ? ticks.map(function (tick) {
  14700. var points = tick.points;
  14701. var end = points[points.length - 1];
  14702. var offsetPoint = getOffsetPoint(center, end, tickLine.length);
  14703. return jsx("line", {
  14704. attrs: _objectSpread({
  14705. x1: end.x,
  14706. y1: end.y,
  14707. x2: offsetPoint.x,
  14708. y2: offsetPoint.y
  14709. }, tickLine)
  14710. });
  14711. }) : null, jsx(Line$1, {
  14712. line: line,
  14713. gridType: gridType,
  14714. center: center,
  14715. radius: radius,
  14716. ticks: ticks
  14717. }), label ? ticks.map(function (tick) {
  14718. var points = tick.points,
  14719. text = tick.text,
  14720. labelStyle = tick.labelStyle;
  14721. var end = points[points.length - 1];
  14722. var offsetPoint = getOffsetPoint(center, end, labelOffset);
  14723. return jsx("text", {
  14724. attrs: _objectSpread(_objectSpread(_objectSpread({
  14725. x: offsetPoint.x,
  14726. y: offsetPoint.y,
  14727. text: text
  14728. }, getTextAlignInfo(center, end)), label), labelStyle)
  14729. });
  14730. }) : null);
  14731. });
  14732. var PolarY = (function (props) {
  14733. var ticks = props.ticks,
  14734. coord = props.coord,
  14735. style = props.style,
  14736. gridType = props.grid;
  14737. var center = coord.center;
  14738. var grid = style.grid,
  14739. tickLine = style.tickLine,
  14740. line = style.line,
  14741. labelOffset = style.labelOffset,
  14742. label = style.label;
  14743. return jsx("group", null, grid ? ticks.map(function (tick) {
  14744. var points = tick.points,
  14745. gridStyle = tick.gridStyle,
  14746. gridPoints = tick.gridPoints;
  14747. var end = points[points.length - 1];
  14748. if (gridType !== 'line') {
  14749. return jsx("arc", {
  14750. attrs: _objectSpread(_objectSpread({
  14751. x: center.x,
  14752. y: center.y,
  14753. r: Vector2.length([end.x - center.x, end.y - center.y])
  14754. }, grid), gridStyle)
  14755. });
  14756. }
  14757. return jsx("polyline", {
  14758. attrs: _objectSpread(_objectSpread({
  14759. points: gridPoints
  14760. }, grid), gridStyle)
  14761. });
  14762. }) : null, tickLine && tickLine.length ? ticks.map(function (tick) {
  14763. var points = tick.points;
  14764. var end = points[points.length - 1];
  14765. return jsx("line", {
  14766. attrs: _objectSpread({
  14767. x1: end.x,
  14768. y1: end.y,
  14769. x2: end.x - tickLine.length,
  14770. y2: end.y
  14771. }, tickLine)
  14772. });
  14773. }) : null, line ? jsx("line", {
  14774. attrs: _objectSpread({
  14775. x1: ticks[0].points[0].x,
  14776. y1: ticks[0].points[0].y,
  14777. x2: ticks[ticks.length - 1].points[0].x,
  14778. y2: ticks[ticks.length - 1].points[0].y
  14779. }, line)
  14780. }) : null, label ? ticks.map(function (tick) {
  14781. var points = tick.points,
  14782. text = tick.text,
  14783. labelStyle = tick.labelStyle;
  14784. var end = points[points.length - 1];
  14785. return jsx("text", {
  14786. attrs: _objectSpread(_objectSpread({
  14787. x: end.x - labelOffset,
  14788. y: end.y,
  14789. text: text,
  14790. textAlign: 'right',
  14791. textBaseline: 'middle'
  14792. }, label), labelStyle)
  14793. });
  14794. }) : null);
  14795. });
  14796. var Top = (function (props) {
  14797. var ticks = props.ticks,
  14798. coord = props.coord,
  14799. style = props.style;
  14800. var left = coord.left,
  14801. top = coord.top,
  14802. right = coord.right;
  14803. var grid = style.grid,
  14804. tickLine = style.tickLine,
  14805. line = style.line,
  14806. labelOffset = style.labelOffset,
  14807. label = style.label;
  14808. return jsx("group", null, grid ? ticks.map(function (tick) {
  14809. var points = tick.points,
  14810. gridStyle = tick.gridStyle;
  14811. var start = points[0];
  14812. var end = points[points.length - 1];
  14813. return jsx("line", {
  14814. attrs: _objectSpread(_objectSpread({
  14815. x1: start.x,
  14816. y1: start.y,
  14817. x2: end.x,
  14818. y2: end.y
  14819. }, grid), gridStyle)
  14820. });
  14821. }) : null, tickLine && tickLine.length ? ticks.map(function (tick) {
  14822. var points = tick.points;
  14823. var end = points[points.length - 1];
  14824. return jsx("line", {
  14825. attrs: _objectSpread({
  14826. x1: end.x,
  14827. y1: end.y,
  14828. x2: end.x,
  14829. y2: end.y - tickLine.length
  14830. }, tickLine)
  14831. });
  14832. }) : null, line ? jsx("line", {
  14833. attrs: _objectSpread({
  14834. x1: left,
  14835. y1: top,
  14836. x2: right,
  14837. y2: top
  14838. }, line)
  14839. }) : null, label ? ticks.map(function (tick, _index) {
  14840. var points = tick.points,
  14841. text = tick.text,
  14842. labelStyle = tick.labelStyle;
  14843. var end = points[points.length - 1];
  14844. return jsx("text", {
  14845. attrs: _objectSpread(_objectSpread({
  14846. x: end.x,
  14847. y: end.y - labelOffset,
  14848. textAlign: 'center',
  14849. textBaseline: 'bottom',
  14850. text: text
  14851. }, label), labelStyle)
  14852. });
  14853. }) : null);
  14854. });
  14855. var Bottom = (function (props, context) {
  14856. var ticks = props.ticks,
  14857. coord = props.coord,
  14858. style = props.style,
  14859. animation = props.animation;
  14860. var px2hd = context.px2hd;
  14861. var left = coord.left,
  14862. right = coord.right,
  14863. bottom = coord.bottom;
  14864. var grid = style.grid,
  14865. tickLine = style.tickLine,
  14866. line = style.line,
  14867. labelOffset = style.labelOffset,
  14868. label = style.label;
  14869. return jsx("group", null, grid ? ticks.map(function (tick) {
  14870. var points = tick.points,
  14871. tickValue = tick.tickValue,
  14872. gridStyle = tick.gridStyle;
  14873. var start = points[0];
  14874. var end = points[points.length - 1];
  14875. return jsx("line", {
  14876. key: tickValue,
  14877. attrs: _objectSpread(_objectSpread({
  14878. x1: start.x,
  14879. y1: start.y,
  14880. x2: end.x,
  14881. y2: end.y
  14882. }, grid), gridStyle)
  14883. });
  14884. }) : null, tickLine && tickLine.length ? ticks.map(function (tick) {
  14885. var points = tick.points,
  14886. tickValue = tick.tickValue;
  14887. var start = points[0];
  14888. return jsx("line", {
  14889. key: tickValue,
  14890. attrs: _objectSpread({
  14891. x1: start.x,
  14892. y1: start.y,
  14893. x2: start.x,
  14894. y2: start.y + px2hd(tickLine.length)
  14895. }, tickLine)
  14896. });
  14897. }) : null, line ? jsx("line", {
  14898. attrs: _objectSpread({
  14899. x1: left,
  14900. y1: bottom,
  14901. x2: right,
  14902. y2: bottom
  14903. }, line)
  14904. }) : null, label ? ticks.map(function (tick, index) {
  14905. var points = tick.points,
  14906. text = tick.text,
  14907. tickValue = tick.tickValue,
  14908. labelStyle = tick.labelStyle;
  14909. var start = points[0];
  14910. var _ref = labelStyle || label || {},
  14911. _ref$align = _ref.align,
  14912. align = _ref$align === void 0 ? 'center' : _ref$align;
  14913. var textAttrs = _objectSpread(_objectSpread({
  14914. x: start.x,
  14915. y: start.y + labelOffset,
  14916. textBaseline: 'top',
  14917. text: text
  14918. }, label), labelStyle);
  14919. if (align === 'between') {
  14920. if (index === 0) {
  14921. textAttrs.textAlign = 'start';
  14922. } else if (index === ticks.length - 1) {
  14923. textAttrs.textAlign = 'end';
  14924. } else {
  14925. textAttrs.textAlign = 'center';
  14926. }
  14927. } else {
  14928. textAttrs.textAlign = align;
  14929. }
  14930. return jsx("text", {
  14931. key: tickValue,
  14932. attrs: textAttrs,
  14933. animation: animation || {
  14934. appear: {
  14935. easing: 'linear',
  14936. duration: 300,
  14937. delay: 0,
  14938. property: ['fillOpacity'],
  14939. start: {
  14940. fillOpacity: 0
  14941. },
  14942. end: {
  14943. fillOpacity: 1
  14944. }
  14945. },
  14946. update: {
  14947. easing: 'linear',
  14948. duration: 450,
  14949. delay: 0,
  14950. property: ['x', 'y']
  14951. },
  14952. leave: {
  14953. easing: 'linear',
  14954. duration: 450,
  14955. delay: 0,
  14956. property: ['fillOpacity'],
  14957. start: {
  14958. fillOpacity: 1
  14959. },
  14960. end: {
  14961. fillOpacity: 0
  14962. }
  14963. }
  14964. }
  14965. });
  14966. }) : null);
  14967. });
  14968. var Right = (function (props) {
  14969. var ticks = props.ticks,
  14970. coord = props.coord,
  14971. style = props.style;
  14972. var top = coord.top,
  14973. right = coord.right,
  14974. bottom = coord.bottom;
  14975. var grid = style.grid,
  14976. tickLine = style.tickLine,
  14977. line = style.line,
  14978. labelOffset = style.labelOffset,
  14979. label = style.label;
  14980. return jsx("group", null, grid ? ticks.map(function (tick) {
  14981. var points = tick.points,
  14982. gridStyle = tick.gridStyle;
  14983. var start = points[0];
  14984. var end = points[points.length - 1];
  14985. return jsx("line", {
  14986. attrs: _objectSpread(_objectSpread({
  14987. x1: start.x,
  14988. y1: start.y,
  14989. x2: end.x,
  14990. y2: end.y
  14991. }, grid), gridStyle)
  14992. });
  14993. }) : null, tickLine && tickLine.length ? ticks.map(function (tick) {
  14994. var points = tick.points;
  14995. var end = points[points.length - 1];
  14996. return jsx("line", {
  14997. attrs: _objectSpread({
  14998. x1: end.x,
  14999. y1: end.y,
  15000. x2: end.x + tickLine.length,
  15001. y2: end.y
  15002. }, tickLine)
  15003. });
  15004. }) : null, line ? jsx("line", {
  15005. attrs: _objectSpread({
  15006. x1: right,
  15007. y1: top,
  15008. x2: right,
  15009. y2: bottom
  15010. }, line)
  15011. }) : null, label ? ticks.map(function (tick, _index) {
  15012. var points = tick.points,
  15013. text = tick.text,
  15014. labelStyle = tick.labelStyle;
  15015. var end = points[points.length - 1];
  15016. return jsx("text", {
  15017. attrs: _objectSpread(_objectSpread({
  15018. x: end.x + labelOffset,
  15019. y: end.y,
  15020. textAlign: 'left',
  15021. textBaseline: 'middle',
  15022. text: text
  15023. }, label), labelStyle)
  15024. });
  15025. }) : null);
  15026. });
  15027. var Left = (function (props) {
  15028. var ticks = props.ticks,
  15029. coord = props.coord,
  15030. style = props.style,
  15031. animation = props.animation;
  15032. var left = coord.left,
  15033. top = coord.top,
  15034. bottom = coord.bottom;
  15035. var grid = style.grid,
  15036. tickLine = style.tickLine,
  15037. line = style.line,
  15038. labelOffset = style.labelOffset,
  15039. label = style.label;
  15040. return jsx("group", null, grid ? ticks.map(function (tick) {
  15041. var points = tick.points,
  15042. tickValue = tick.tickValue,
  15043. gridStyle = tick.gridStyle;
  15044. var start = points[0];
  15045. var end = points[points.length - 1];
  15046. return jsx("line", {
  15047. key: tickValue,
  15048. attrs: _objectSpread(_objectSpread({
  15049. x1: start.x,
  15050. y1: start.y,
  15051. x2: end.x,
  15052. y2: end.y
  15053. }, grid), gridStyle)
  15054. });
  15055. }) : null, tickLine && tickLine.length ? ticks.map(function (tick) {
  15056. var points = tick.points,
  15057. tickValue = tick.tickValue;
  15058. var start = points[0];
  15059. return jsx("line", {
  15060. key: tickValue,
  15061. attrs: _objectSpread({
  15062. x1: start.x,
  15063. y1: start.y,
  15064. x2: start.x - tickLine.length,
  15065. y2: start.y
  15066. }, tickLine)
  15067. });
  15068. }) : null, line ? jsx("line", {
  15069. attrs: _objectSpread({
  15070. x1: left,
  15071. y1: top,
  15072. x2: left,
  15073. y2: bottom
  15074. }, line)
  15075. }) : null, label ? ticks.map(function (tick, _index) {
  15076. var tickValue = tick.tickValue,
  15077. points = tick.points,
  15078. text = tick.text,
  15079. labelStyle = tick.labelStyle;
  15080. var start = points[0];
  15081. return jsx("text", {
  15082. key: tickValue,
  15083. attrs: _objectSpread(_objectSpread({
  15084. x: start.x - labelOffset,
  15085. y: start.y,
  15086. textAlign: 'right',
  15087. textBaseline: 'middle',
  15088. text: text
  15089. }, label), labelStyle),
  15090. animation: animation || {
  15091. appear: {
  15092. easing: 'linear',
  15093. duration: 300,
  15094. delay: 0,
  15095. property: ['fillOpacity'],
  15096. start: {
  15097. fillOpacity: 0
  15098. },
  15099. end: {
  15100. fillOpacity: 1
  15101. }
  15102. },
  15103. update: {
  15104. easing: 'linear',
  15105. duration: 450,
  15106. delay: 0,
  15107. property: ['x', 'y']
  15108. },
  15109. leave: {
  15110. easing: 'linear',
  15111. duration: 450,
  15112. delay: 0,
  15113. property: ['fillOpacity'],
  15114. start: {
  15115. fillOpacity: 1
  15116. },
  15117. end: {
  15118. fillOpacity: 0
  15119. }
  15120. }
  15121. }
  15122. });
  15123. }) : null);
  15124. });
  15125. function isPolar(props) {
  15126. return props.coord.isPolar;
  15127. }
  15128. var AxisView = (function (props) {
  15129. // 极坐标
  15130. if (isPolar(props)) {
  15131. var dimType = props.dimType;
  15132. if (dimType === 'x') {
  15133. return jsx(PolarX, _objectSpread({}, props));
  15134. }
  15135. return jsx(PolarY, _objectSpread({}, props));
  15136. }
  15137. var position = props.position;
  15138. // 直角坐标
  15139. if (position === 'right') {
  15140. return jsx(Right, _objectSpread({}, props));
  15141. }
  15142. if (position === 'left') {
  15143. return jsx(Left, _objectSpread({}, props));
  15144. }
  15145. if (position === 'top') {
  15146. return jsx(Top, _objectSpread({}, props));
  15147. }
  15148. return jsx(Bottom, _objectSpread({}, props));
  15149. });
  15150. var index$4 = withAxis(AxisView);
  15151. var withLegend = (function (View) {
  15152. return /*#__PURE__*/function (_Component) {
  15153. _inherits(Legend, _Component);
  15154. var _super = _createSuper(Legend);
  15155. function Legend(props) {
  15156. var _this;
  15157. _classCallCheck(this, Legend);
  15158. _this = _super.call(this, props);
  15159. _this.state = {
  15160. filtered: {},
  15161. items: []
  15162. };
  15163. return _this;
  15164. }
  15165. _createClass(Legend, [{
  15166. key: "getOriginItems",
  15167. value: function getOriginItems() {
  15168. var chart = this.props.chart;
  15169. return chart.getLegendItems();
  15170. }
  15171. }, {
  15172. key: "getItems",
  15173. value: function getItems() {
  15174. var _props$items;
  15175. var props = this.props,
  15176. state = this.state;
  15177. var filtered = state.filtered;
  15178. var renderItems = ((_props$items = props.items) === null || _props$items === void 0 ? void 0 : _props$items.length) ? props.items : this.getOriginItems();
  15179. if (!renderItems) return null;
  15180. return renderItems.map(function (item) {
  15181. var tickValue = item.tickValue;
  15182. return _objectSpread(_objectSpread({}, item), {}, {
  15183. filtered: filtered[tickValue]
  15184. });
  15185. });
  15186. }
  15187. }, {
  15188. key: "setItems",
  15189. value: function setItems(items) {
  15190. this.setState({
  15191. items: items
  15192. });
  15193. }
  15194. }, {
  15195. key: "getMaxItemBox",
  15196. value: function getMaxItemBox(legendShape) {
  15197. var maxItemWidth = 0;
  15198. var maxItemHeight = 0;
  15199. (legendShape.get('children') || []).forEach(function (child) {
  15200. var _child$get = child.get('attrs'),
  15201. width = _child$get.width,
  15202. height = _child$get.height;
  15203. maxItemWidth = Math.max(maxItemWidth, width);
  15204. maxItemHeight = Math.max(maxItemHeight, height);
  15205. });
  15206. return {
  15207. width: maxItemWidth,
  15208. height: maxItemHeight
  15209. };
  15210. }
  15211. // 计算 legend 的位置
  15212. }, {
  15213. key: "_init",
  15214. value: function _init() {
  15215. var props = this.props,
  15216. context = this.context;
  15217. var parentLayout = props.layout,
  15218. customWidth = props.width,
  15219. customHeight = props.height,
  15220. _props$position = props.position,
  15221. position = _props$position === void 0 ? 'top' : _props$position;
  15222. var items = this.getItems();
  15223. if (!items || !items.length) return;
  15224. var left = parentLayout.left,
  15225. top = parentLayout.top,
  15226. right = parentLayout.right,
  15227. bottom = parentLayout.bottom,
  15228. layoutWidth = parentLayout.width,
  15229. layoutHeight = parentLayout.height;
  15230. var width = context.px2hd(customWidth) || layoutWidth;
  15231. var shape = renderShape(this, this.render(), false);
  15232. var _this$getMaxItemBox = this.getMaxItemBox(shape),
  15233. itemMaxWidth = _this$getMaxItemBox.width,
  15234. itemMaxHeight = _this$getMaxItemBox.height;
  15235. // 每行最多的个数
  15236. var lineMaxCount = Math.floor(width / itemMaxWidth);
  15237. var itemCount = items.length;
  15238. // legend item 的行数
  15239. var lineCount = Math.ceil(itemCount / lineMaxCount);
  15240. var itemWidth = width / lineMaxCount;
  15241. var autoHeight = itemMaxHeight * lineCount;
  15242. var style = {
  15243. left: left,
  15244. top: top,
  15245. width: width,
  15246. // height 默认自适应
  15247. height: undefined,
  15248. flexDirection: 'row',
  15249. flexWrap: 'wrap',
  15250. alignItems: 'center',
  15251. justifyContent: 'flex-start'
  15252. };
  15253. // 如果只有一行,2端对齐
  15254. if (lineCount === 1) {
  15255. style.justifyContent = 'space-between';
  15256. }
  15257. if (position === 'top') {
  15258. style.height = customHeight ? customHeight : autoHeight;
  15259. }
  15260. if (position === 'left') {
  15261. style.flexDirection = 'column';
  15262. style.justifyContent = 'center';
  15263. style.width = itemMaxWidth;
  15264. style.height = customHeight ? customHeight : layoutHeight;
  15265. }
  15266. if (position === 'right') {
  15267. style.flexDirection = 'column';
  15268. style.alignItems = 'flex-start';
  15269. style.justifyContent = 'center';
  15270. style.width = itemMaxWidth;
  15271. style.height = customHeight ? customHeight : layoutHeight;
  15272. style.left = right - itemMaxWidth;
  15273. }
  15274. if (position === 'bottom') {
  15275. style.top = bottom - autoHeight;
  15276. style.height = customHeight ? customHeight : autoHeight;
  15277. }
  15278. this.itemWidth = itemWidth;
  15279. this.style = style;
  15280. shape.remove();
  15281. }
  15282. }, {
  15283. key: "updateCoord",
  15284. value: function updateCoord() {
  15285. var context = this.context,
  15286. props = this.props,
  15287. style = this.style;
  15288. var _props$position2 = props.position,
  15289. position = _props$position2 === void 0 ? 'top' : _props$position2,
  15290. _props$margin = props.margin,
  15291. margin = _props$margin === void 0 ? '30px' : _props$margin,
  15292. chart = props.chart;
  15293. var width = style.width,
  15294. height = style.height;
  15295. var marginNumber = context.px2hd(margin);
  15296. chart.updateCoordFor(this, {
  15297. position: position,
  15298. width: width + marginNumber,
  15299. height: height + marginNumber
  15300. });
  15301. }
  15302. }, {
  15303. key: "willMount",
  15304. value: function willMount() {
  15305. var items = this.getItems();
  15306. if (!items || !items.length) return;
  15307. this._init();
  15308. this.updateCoord();
  15309. }
  15310. }, {
  15311. key: "didMount",
  15312. value: function didMount() {
  15313. this._initEvent();
  15314. }
  15315. }, {
  15316. key: "willUpdate",
  15317. value: function willUpdate() {
  15318. var items = this.getItems();
  15319. if (!items || !items.length) return;
  15320. this.updateCoord();
  15321. }
  15322. }, {
  15323. key: "_initEvent",
  15324. value: function _initEvent() {
  15325. var _this2 = this;
  15326. var context = this.context,
  15327. props = this.props,
  15328. container = this.container;
  15329. var canvas = context.canvas;
  15330. var chart = props.chart,
  15331. _props$clickable = props.clickable,
  15332. clickable = _props$clickable === void 0 ? true : _props$clickable,
  15333. onClick = props.onClick;
  15334. if (!clickable) return;
  15335. // item 点击事件
  15336. canvas.on('click', function (ev) {
  15337. var points = ev.points;
  15338. var point = points[0];
  15339. var bbox = container.getBBox();
  15340. if (!isInBBox(bbox, point)) {
  15341. return;
  15342. }
  15343. var legendItems = getElementsByClassName('legend-item', container);
  15344. if (!legendItems.length) {
  15345. return;
  15346. }
  15347. var clickItem = find(legendItems, function (item) {
  15348. var itemBBox = item.getBBox();
  15349. return isInBBox(itemBBox, point);
  15350. });
  15351. if (!clickItem) {
  15352. return;
  15353. }
  15354. var dataItem = clickItem.get('data-item');
  15355. if (!dataItem) {
  15356. return;
  15357. }
  15358. if (isFunction(onClick)) {
  15359. onClick(dataItem);
  15360. }
  15361. var field = dataItem.field,
  15362. tickValue = dataItem.tickValue;
  15363. var prevFiltered = _this2.state.filtered;
  15364. var filtered = _objectSpread(_objectSpread({}, prevFiltered), {}, _defineProperty({}, tickValue, !prevFiltered[tickValue]));
  15365. _this2.setState({
  15366. filtered: filtered
  15367. });
  15368. chart.filter(field, function (value) {
  15369. return !filtered[value];
  15370. });
  15371. });
  15372. }
  15373. }, {
  15374. key: "render",
  15375. value: function render() {
  15376. var props = this.props,
  15377. itemWidth = this.itemWidth,
  15378. style = this.style;
  15379. var items = this.getItems();
  15380. if (!items || !items.length) {
  15381. return null;
  15382. }
  15383. return jsx(View, _objectSpread(_objectSpread({}, props), {}, {
  15384. items: items,
  15385. itemWidth: itemWidth,
  15386. style: _objectSpread(_objectSpread({}, style), props.style)
  15387. }));
  15388. }
  15389. }]);
  15390. return Legend;
  15391. }(Component);
  15392. });
  15393. var Marker$1 = function Marker(_ref) {
  15394. var type = _ref.type,
  15395. color = _ref.color;
  15396. if (type === 'square') {
  15397. return jsx("rect", {
  15398. style: {
  15399. width: '12px',
  15400. height: '12px',
  15401. marginRight: '10px'
  15402. },
  15403. attrs: {
  15404. fill: color
  15405. }
  15406. });
  15407. }
  15408. if (type === 'line') {
  15409. return jsx("line", {
  15410. style: {
  15411. width: '19px',
  15412. marginRight: '10px'
  15413. },
  15414. attrs: {
  15415. strokeStyle: color,
  15416. lineCap: 'round',
  15417. lineWidth: '4px'
  15418. }
  15419. });
  15420. }
  15421. return jsx("circle", {
  15422. style: {
  15423. width: '12px',
  15424. height: '12px',
  15425. marginRight: '10px'
  15426. },
  15427. attrs: {
  15428. fill: color
  15429. }
  15430. });
  15431. };
  15432. var LegendView = (function (props) {
  15433. var items = props.items,
  15434. itemWidth = props.itemWidth,
  15435. itemFormatter = props.itemFormatter,
  15436. style = props.style,
  15437. _props$marker = props.marker,
  15438. marker = _props$marker === void 0 ? 'circle' : _props$marker,
  15439. itemStyle = props.itemStyle,
  15440. nameStyle = props.nameStyle,
  15441. valueStyle = props.valueStyle,
  15442. valuePrefix = props.valuePrefix;
  15443. var formatValue = function formatValue(value) {
  15444. var valuePrefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ': ';
  15445. return "".concat(valuePrefix).concat(value);
  15446. };
  15447. return jsx("group", {
  15448. style: style
  15449. }, items.map(function (item) {
  15450. var color = item.color,
  15451. name = item.name,
  15452. value = item.value,
  15453. filtered = item.filtered,
  15454. tickValue = item.tickValue;
  15455. var valueText = isFunction(itemFormatter) ? itemFormatter(value, tickValue) : value;
  15456. return jsx("group", {
  15457. className: "legend-item",
  15458. style: _objectSpread({
  15459. width: itemWidth,
  15460. display: 'flex',
  15461. flexDirection: 'row',
  15462. alignItems: 'center',
  15463. justifyContent: 'flex-start',
  15464. padding: ['6px', '6px', '6px', 0]
  15465. }, itemStyle),
  15466. "data-item": item
  15467. }, jsx(Marker$1, {
  15468. color: filtered ? '#bfbfbf' : color,
  15469. type: marker
  15470. }), jsx("text", {
  15471. attrs: _objectSpread({
  15472. fill: filtered ? '#bfbfbf' : '#808080',
  15473. text: name
  15474. }, nameStyle)
  15475. }), valueText ? jsx("text", {
  15476. attrs: _objectSpread({
  15477. fill: '#808080',
  15478. text: formatValue(valueText, valuePrefix)
  15479. }, valueStyle)
  15480. }) : null);
  15481. }));
  15482. });
  15483. var index$5 = withLegend(LegendView);
  15484. function isInBBox$1(bbox, point) {
  15485. var minX = bbox.minX,
  15486. maxX = bbox.maxX,
  15487. minY = bbox.minY,
  15488. maxY = bbox.maxY;
  15489. var x = point.x,
  15490. y = point.y;
  15491. return minX <= x && maxX >= x && minY <= y && maxY >= y;
  15492. }
  15493. var withGuide = (function (View) {
  15494. return /*#__PURE__*/function (_Component) {
  15495. _inherits(Guide, _Component);
  15496. var _super = _createSuper(Guide);
  15497. function Guide(props) {
  15498. var _this;
  15499. _classCallCheck(this, Guide);
  15500. _this = _super.call(this, props);
  15501. // 创建ref
  15502. _this.triggerRef = {};
  15503. _this.state = {};
  15504. return _this;
  15505. }
  15506. _createClass(Guide, [{
  15507. key: "willMount",
  15508. value: function willMount() {
  15509. _get$1(_getPrototypeOf(Guide.prototype), "willMount", this).call(this);
  15510. this.getGuideBBox();
  15511. }
  15512. }, {
  15513. key: "didMount",
  15514. value: function didMount() {
  15515. var _this2 = this;
  15516. var context = this.context,
  15517. props = this.props;
  15518. var canvas = context.canvas;
  15519. var onClick = props.onClick;
  15520. canvas.on('click', function (ev) {
  15521. var points = ev.points;
  15522. var shape = _this2.triggerRef.current;
  15523. if (!shape || shape.isDestroyed()) return;
  15524. var bbox = shape.getBBox();
  15525. if (isInBBox$1(bbox, points[0])) {
  15526. ev.shape = shape;
  15527. onClick && onClick(ev);
  15528. }
  15529. });
  15530. }
  15531. }, {
  15532. key: "didUpdate",
  15533. value: function didUpdate() {
  15534. _get$1(_getPrototypeOf(Guide.prototype), "didUpdate", this).call(this);
  15535. var shape = this.triggerRef.current;
  15536. if (!shape || shape.isDestroyed()) return;
  15537. var _shape$get = shape.get('attrs'),
  15538. x = _shape$get.x,
  15539. y = _shape$get.y,
  15540. width = _shape$get.width,
  15541. height = _shape$get.height;
  15542. var bbox = {
  15543. minX: x,
  15544. minY: y,
  15545. maxX: x + width,
  15546. maxY: y + height,
  15547. width: width,
  15548. height: height
  15549. };
  15550. this.setState({
  15551. guideBBox: bbox
  15552. });
  15553. }
  15554. }, {
  15555. key: "getGuideBBox",
  15556. value: function getGuideBBox() {
  15557. var shape = renderShape(this, this.render(), false);
  15558. var _shape$get2 = shape.get('attrs'),
  15559. x = _shape$get2.x,
  15560. y = _shape$get2.y,
  15561. width = _shape$get2.width,
  15562. height = _shape$get2.height;
  15563. // getBBox 没有包含 padding 所以这里手动计算 bbox
  15564. var bbox = {
  15565. minX: x,
  15566. minY: y,
  15567. maxX: x + width,
  15568. maxY: y + height,
  15569. width: width,
  15570. height: height
  15571. };
  15572. this.setState({
  15573. guideBBox: bbox
  15574. });
  15575. shape.destroy();
  15576. }
  15577. // 解析record里的模板字符串,如min、max、50%...
  15578. }, {
  15579. key: "parseReplaceStr",
  15580. value: function parseReplaceStr(value, scale) {
  15581. var replaceMap = {
  15582. min: 0,
  15583. max: 1,
  15584. median: 0.5
  15585. };
  15586. // 传入的是 min、max、median 的
  15587. if (!isNil(replaceMap[value])) {
  15588. return replaceMap[value];
  15589. }
  15590. // 传入的是 xx%
  15591. if (isString(value) && value.indexOf('%') != -1 && !isNaN(Number(value.slice(0, -1)))) {
  15592. var rateValue = Number(value.slice(0, -1));
  15593. var percent = rateValue / 100;
  15594. return percent;
  15595. }
  15596. return scale.scale(value);
  15597. }
  15598. }, {
  15599. key: "parsePoint",
  15600. value: function parsePoint(record) {
  15601. var props = this.props;
  15602. var chart = props.chart,
  15603. coord = props.coord;
  15604. var xScale = chart.getXScales()[0];
  15605. // 只取第一个yScale
  15606. var yScale = chart.getYScales()[0];
  15607. // 解析 record 为归一化后的坐标
  15608. var x = this.parseReplaceStr(record[xScale.field], xScale);
  15609. var y = this.parseReplaceStr(record[yScale.field], yScale);
  15610. return coord.convertPoint({
  15611. x: x,
  15612. y: y
  15613. });
  15614. }
  15615. }, {
  15616. key: "convertPoints",
  15617. value: function convertPoints(records) {
  15618. var _this3 = this;
  15619. return records.map(function (record) {
  15620. return _this3.parsePoint(record);
  15621. });
  15622. }
  15623. }, {
  15624. key: "getGuideTheme",
  15625. value: function getGuideTheme() {
  15626. var context = this.context;
  15627. var theme = context.theme;
  15628. return theme.guide;
  15629. }
  15630. }, {
  15631. key: "render",
  15632. value: function render() {
  15633. var props = this.props,
  15634. context = this.context;
  15635. var coord = props.coord,
  15636. _props$records = props.records,
  15637. records = _props$records === void 0 ? [] : _props$records,
  15638. animation = props.animation,
  15639. chart = props.chart;
  15640. var width = context.width,
  15641. height = context.height;
  15642. var points = this.convertPoints(records);
  15643. var theme = this.getGuideTheme();
  15644. var guideBBox = this.state.guideBBox;
  15645. var animationCfg = animation;
  15646. if (isFunction(animation)) {
  15647. // 透传绘制关键点和chart实例
  15648. animationCfg = animation(points, chart);
  15649. }
  15650. return jsx(View, _objectSpread(_objectSpread({
  15651. triggerRef: this.triggerRef,
  15652. points: points,
  15653. theme: theme,
  15654. coord: coord
  15655. }, props), {}, {
  15656. canvasWidth: width,
  15657. canvasHeight: height,
  15658. guideBBox: guideBBox,
  15659. animation: animationCfg
  15660. }));
  15661. }
  15662. }]);
  15663. return Guide;
  15664. }(Component);
  15665. });
  15666. var TextGuideView = (function (props, context) {
  15667. var _props$theme = props.theme,
  15668. theme = _props$theme === void 0 ? {} : _props$theme;
  15669. var _deepMix = deepMix(_objectSpread({}, theme.text), props),
  15670. points = _deepMix.points,
  15671. style = _deepMix.style,
  15672. offsetX = _deepMix.offsetX,
  15673. offsetY = _deepMix.offsetY,
  15674. content = _deepMix.content,
  15675. animation = _deepMix.animation;
  15676. var _ref = points[0] || {},
  15677. x = _ref.x,
  15678. y = _ref.y;
  15679. var offsetXNum = context.px2hd(offsetX);
  15680. var offsetYNum = context.px2hd(offsetY);
  15681. var posX = x + (offsetXNum || 0);
  15682. var posY = y + (offsetYNum || 0);
  15683. return jsx("text", {
  15684. attrs: _objectSpread({
  15685. text: content,
  15686. x: posX,
  15687. y: posY
  15688. }, style),
  15689. animation: deepMix({
  15690. update: {
  15691. easing: 'linear',
  15692. duration: 450,
  15693. property: ['x', 'y']
  15694. }
  15695. }, animation)
  15696. });
  15697. });
  15698. var PointGuideView = (function (props, context) {
  15699. var theme = props.theme;
  15700. var _deepMix = deepMix(_objectSpread({}, theme.point), props),
  15701. points = _deepMix.points,
  15702. style = _deepMix.style,
  15703. offsetX = _deepMix.offsetX,
  15704. offsetY = _deepMix.offsetY,
  15705. animation = _deepMix.animation;
  15706. var _ref = points[0] || {},
  15707. x = _ref.x,
  15708. y = _ref.y;
  15709. var offsetXNum = context.px2hd(offsetX);
  15710. var offsetYNum = context.px2hd(offsetY);
  15711. var posX = x + (offsetXNum || 0);
  15712. var posY = y + (offsetYNum || 0);
  15713. return jsx("group", null, jsx("circle", {
  15714. attrs: _objectSpread({
  15715. x: posX,
  15716. y: posY
  15717. }, style),
  15718. animation: animation
  15719. }));
  15720. });
  15721. var LineGuideView = (function (props, context) {
  15722. var _props$theme = props.theme,
  15723. theme = _props$theme === void 0 ? {} : _props$theme;
  15724. var _deepMix = deepMix(_objectSpread({}, theme.line), props),
  15725. points = _deepMix.points,
  15726. style = _deepMix.style,
  15727. offsetX = _deepMix.offsetX,
  15728. offsetY = _deepMix.offsetY,
  15729. animation = _deepMix.animation;
  15730. var _ref = points[0] || {},
  15731. x1 = _ref.x,
  15732. y1 = _ref.y;
  15733. var _ref2 = points[1] || {},
  15734. x2 = _ref2.x,
  15735. y2 = _ref2.y;
  15736. var offsetXNum = context.px2hd(offsetX);
  15737. var offsetYNum = context.px2hd(offsetY);
  15738. var posX1 = x1 + (isArray(offsetXNum) ? offsetXNum[0] || 0 : offsetXNum || 0);
  15739. var posY1 = y1 + (isArray(offsetYNum) ? offsetYNum[0] || 0 : offsetYNum || 0);
  15740. var posX2 = x2 + (isArray(offsetXNum) ? offsetXNum[1] || 0 : offsetXNum || 0);
  15741. var posY2 = y2 + (isArray(offsetYNum) ? offsetYNum[1] || 0 : offsetYNum || 0);
  15742. return jsx("group", null, jsx("line", {
  15743. attrs: _objectSpread({
  15744. x1: posX1,
  15745. y1: posY1,
  15746. x2: posX2,
  15747. y2: posY2
  15748. }, style),
  15749. animation: animation
  15750. }));
  15751. });
  15752. var ArcGuideView = (function (props) {
  15753. var _props$theme = props.theme,
  15754. theme = _props$theme === void 0 ? {} : _props$theme;
  15755. var _deepMix = deepMix(_objectSpread({}, theme.line), props),
  15756. coord = _deepMix.coord,
  15757. points = _deepMix.points,
  15758. style = _deepMix.style,
  15759. animation = _deepMix.animation;
  15760. var start = points[0] || {};
  15761. var end = points[1] || {};
  15762. var coordCenter = coord.center;
  15763. var radius = Math.sqrt((start.x - coordCenter.x) * (start.x - coordCenter.x) + (start.y - coordCenter.y) * (start.y - coordCenter.y));
  15764. var startAngle = Math.atan2(start.y - coordCenter.y, start.x - coordCenter.x);
  15765. var endAngle = Math.atan2(end.y - coordCenter.y, end.x - coordCenter.x);
  15766. return jsx("group", null, jsx("arc", {
  15767. attrs: _objectSpread({
  15768. x: coordCenter.x,
  15769. y: coordCenter.y,
  15770. r: radius,
  15771. startAngle: startAngle,
  15772. endAngle: endAngle
  15773. }, style),
  15774. animation: animation
  15775. }));
  15776. });
  15777. var RectGuideView = (function (props) {
  15778. var _props$theme = props.theme,
  15779. theme = _props$theme === void 0 ? {} : _props$theme;
  15780. var _deepMix = deepMix(_objectSpread({}, theme.rect), props),
  15781. points = _deepMix.points,
  15782. style = _deepMix.style,
  15783. animation = _deepMix.animation;
  15784. var start = points[0] || {};
  15785. var end = points[1] || {};
  15786. return jsx("group", null, jsx("rect", {
  15787. attrs: _objectSpread({
  15788. x: Math.min(start.x, end.x),
  15789. y: Math.min(start.y, end.y),
  15790. width: Math.abs(end.x - start.x),
  15791. height: Math.abs(start.y - end.y)
  15792. }, style),
  15793. animation: animation
  15794. }));
  15795. });
  15796. var defaultProps = {
  15797. offsetX: 0,
  15798. offsetY: 0,
  15799. points: [],
  15800. src: ''
  15801. };
  15802. var baseAttrs = {
  15803. height: '20px',
  15804. width: '20px'
  15805. };
  15806. var ImageGuideView = (function (props, context) {
  15807. var cfg = deepMix({}, defaultProps, props);
  15808. var points = cfg.points,
  15809. style = cfg.style,
  15810. attrs = cfg.attrs,
  15811. offsetX = cfg.offsetX,
  15812. offsetY = cfg.offsetY,
  15813. src = cfg.src,
  15814. animation = cfg.animation;
  15815. var _ref = points[0] || {},
  15816. x = _ref.x,
  15817. y = _ref.y;
  15818. var _attrs$height = attrs.height,
  15819. height = _attrs$height === void 0 ? 0 : _attrs$height,
  15820. _attrs$width = attrs.width,
  15821. width = _attrs$width === void 0 ? 0 : _attrs$width;
  15822. var heightNum = context.px2hd(height + 'px');
  15823. var widthNum = context.px2hd(width + 'px');
  15824. var offsetXNum = context.px2hd(offsetX);
  15825. var offsetYNum = context.px2hd(offsetY);
  15826. var posX = x + (offsetXNum || 0) - widthNum / 2;
  15827. var posY = y + (offsetYNum || 0) - heightNum / 2;
  15828. return jsx("group", {
  15829. style: style
  15830. }, jsx("image", {
  15831. attrs: _objectSpread(_objectSpread(_objectSpread({}, baseAttrs), attrs), {}, {
  15832. height: heightNum,
  15833. width: widthNum,
  15834. x: posX,
  15835. y: posY,
  15836. src: src
  15837. }),
  15838. cacheImage: true,
  15839. animation: deepMix({
  15840. update: {
  15841. easing: 'linear',
  15842. duration: 450,
  15843. property: ['x', 'y']
  15844. }
  15845. }, animation)
  15846. }));
  15847. });
  15848. var defaultProps$1 = {
  15849. offsetX: 0,
  15850. offsetY: 0,
  15851. points: [],
  15852. direct: 'tl',
  15853. side: 6,
  15854. autoAdjust: true
  15855. };
  15856. var defaultStyle = {
  15857. container: {
  15858. fill: '#1677FF',
  15859. radius: 2,
  15860. padding: [3, 5]
  15861. },
  15862. text: {
  15863. fontSize: '22px',
  15864. fill: '#fff'
  15865. },
  15866. arrow: {
  15867. fill: '#1677FF'
  15868. }
  15869. };
  15870. var TagGuideView = (function (props, context) {
  15871. var cfg = _objectSpread(_objectSpread({}, defaultProps$1), props);
  15872. var points = cfg.points,
  15873. content = cfg.content,
  15874. offsetX = cfg.offsetX,
  15875. offsetY = cfg.offsetY,
  15876. direct = cfg.direct,
  15877. side = cfg.side,
  15878. autoAdjust = cfg.autoAdjust,
  15879. canvasWidth = cfg.canvasWidth,
  15880. canvasHeight = cfg.canvasHeight,
  15881. guideBBox = cfg.guideBBox,
  15882. background = cfg.background,
  15883. textStyle = cfg.textStyle,
  15884. triggerRef = cfg.triggerRef;
  15885. var _ref = points[0] || {},
  15886. x = _ref.x,
  15887. y = _ref.y;
  15888. var _ref2 = guideBBox || {},
  15889. guideWidth = _ref2.width,
  15890. guideHeight = _ref2.height;
  15891. var offsetXNum = context.px2hd(offsetX);
  15892. var offsetYNum = context.px2hd(offsetY);
  15893. var posX = x + (offsetXNum || 0);
  15894. var posY = y + (offsetYNum || 0);
  15895. var _getDirect = function _getDirect(point) {
  15896. var newDirect = direct;
  15897. var x = point.x,
  15898. y = point.y;
  15899. var vertical = newDirect[0];
  15900. var horizontal = newDirect[1];
  15901. // adjust for vertical direction
  15902. if (vertical === 't' && y - side - guideHeight < 0) {
  15903. vertical = 'b';
  15904. } else if (vertical === 'b' && y + side + guideHeight > canvasHeight) {
  15905. vertical = 't';
  15906. }
  15907. // adjust for horizontal direction
  15908. var diff = vertical === 'c' ? side : 0;
  15909. if (horizontal === 'l' && x - diff - guideWidth < 0) {
  15910. horizontal = 'r';
  15911. } else if (horizontal === 'r' && x + diff + guideWidth > canvasWidth) {
  15912. horizontal = 'l';
  15913. } else if (horizontal === 'c') {
  15914. if (guideWidth / 2 + x + diff > canvasWidth) {
  15915. horizontal = 'l';
  15916. } else if (x - guideWidth / 2 - diff < 0) {
  15917. horizontal = 'r';
  15918. }
  15919. }
  15920. newDirect = vertical + horizontal;
  15921. return newDirect;
  15922. };
  15923. var _getArrowPoints = function _getArrowPoints(direct) {
  15924. var arrowPoints = [];
  15925. // const { minX, minY } = guideBBox || {};
  15926. if (direct === 'tl') {
  15927. arrowPoints = [{
  15928. x: posX,
  15929. y: posY - side - 1
  15930. }, {
  15931. x: posX,
  15932. y: posY
  15933. }, {
  15934. x: posX - side,
  15935. y: posY - side - 1
  15936. }];
  15937. posX -= guideWidth || 0;
  15938. posY = posY - (guideHeight || 0) - side;
  15939. } else if (direct === 'cl') {
  15940. arrowPoints = [{
  15941. x: posX - side - 1,
  15942. y: posY - side
  15943. }, {
  15944. x: posX - side - 1,
  15945. y: posY + side
  15946. }, {
  15947. x: posX,
  15948. y: posY
  15949. }];
  15950. posX = posX - (guideWidth || 0) - side;
  15951. posY -= guideHeight / 2 || 0;
  15952. } else if (direct === 'bl') {
  15953. arrowPoints = [{
  15954. x: posX,
  15955. y: posY
  15956. }, {
  15957. x: posX,
  15958. y: posY + side + 1
  15959. }, {
  15960. x: posX - side,
  15961. y: posY + side + 1
  15962. }];
  15963. posX = posX - (guideWidth || 0);
  15964. posY += side;
  15965. } else if (direct === 'bc') {
  15966. // 有问题
  15967. arrowPoints = [{
  15968. x: posX,
  15969. y: posY
  15970. }, {
  15971. x: posX - side,
  15972. y: posY + side + 1
  15973. }, {
  15974. x: posX + side,
  15975. y: posY + side + 1
  15976. }];
  15977. posX = posX - (guideWidth / 2 || 0);
  15978. posY = posY + side;
  15979. } else if (direct === 'br') {
  15980. arrowPoints = [{
  15981. x: posX,
  15982. y: posY
  15983. }, {
  15984. x: posX,
  15985. y: posY + side + 1
  15986. }, {
  15987. x: posX + side,
  15988. y: posY + side + 1
  15989. }];
  15990. posY += side;
  15991. } else if (direct === 'cr') {
  15992. arrowPoints = [{
  15993. x: posX,
  15994. y: posY
  15995. }, {
  15996. x: posX + side,
  15997. y: posY - side
  15998. }, {
  15999. x: posX + side,
  16000. y: posY + side
  16001. }];
  16002. posX += side;
  16003. posY -= guideHeight / 2 || 0;
  16004. } else if (direct === 'tr') {
  16005. arrowPoints = [{
  16006. x: posX,
  16007. y: posY
  16008. }, {
  16009. x: posX,
  16010. y: posY - side - 1
  16011. }, {
  16012. x: posX + side,
  16013. y: posY - side - 1
  16014. }];
  16015. posY = posY - (guideHeight || 0) - side;
  16016. } else if (direct === 'tc') {
  16017. arrowPoints = [{
  16018. x: posX,
  16019. y: posY
  16020. }, {
  16021. x: posX - side,
  16022. y: posY - side - 1
  16023. }, {
  16024. x: posX + side,
  16025. y: posY - side - 1
  16026. }];
  16027. posX -= guideWidth / 2 || 0;
  16028. posY = posY - (guideHeight || 0) - side;
  16029. }
  16030. return arrowPoints;
  16031. };
  16032. var dr = autoAdjust ? _getDirect(points[0]) : direct;
  16033. var arrowPoints = _getArrowPoints(dr);
  16034. return jsx("group", {
  16035. attrs: _objectSpread({
  16036. fill: defaultStyle.container.fill,
  16037. radius: defaultStyle.container.radius
  16038. }, background),
  16039. style: _objectSpread({
  16040. left: posX,
  16041. top: posY,
  16042. padding: defaultStyle.container.padding
  16043. }, background),
  16044. ref: triggerRef
  16045. }, jsx("text", {
  16046. attrs: _objectSpread({
  16047. text: content,
  16048. fontSize: defaultStyle.text.fontSize,
  16049. fill: defaultStyle.text.fill
  16050. }, textStyle)
  16051. }), guideBBox && jsx("polygon", {
  16052. attrs: {
  16053. points: arrowPoints,
  16054. fill: (background === null || background === void 0 ? void 0 : background.fill) || defaultStyle.arrow.fill
  16055. }
  16056. }));
  16057. });
  16058. var DefaultGuideView = function DefaultGuideView() {
  16059. return null;
  16060. };
  16061. var TextGuide = withGuide(TextGuideView);
  16062. var PointGuide = withGuide(PointGuideView);
  16063. var LineGuide = withGuide(LineGuideView);
  16064. var ArcGuide = withGuide(ArcGuideView);
  16065. var RectGuide = withGuide(RectGuideView);
  16066. var ImageGuide = withGuide(ImageGuideView);
  16067. var TagGuide = withGuide(TagGuideView);
  16068. var index$6 = withGuide(DefaultGuideView);
  16069. var withTooltip = (function (View) {
  16070. return /*#__PURE__*/function (_Component) {
  16071. _inherits(Tooltip, _Component);
  16072. var _super = _createSuper(Tooltip);
  16073. function Tooltip(props) {
  16074. var _this;
  16075. _classCallCheck(this, Tooltip);
  16076. _this = _super.call(this, props);
  16077. _this._triggerOn = function (ev) {
  16078. var points = ev.points;
  16079. _this.show(points[0], ev);
  16080. };
  16081. _this._triggerOff = function () {
  16082. var _assertThisInitialize = _assertThisInitialized(_this),
  16083. _assertThisInitialize2 = _assertThisInitialize.props.alwaysShow,
  16084. alwaysShow = _assertThisInitialize2 === void 0 ? false : _assertThisInitialize2;
  16085. if (!alwaysShow) {
  16086. _this.hide();
  16087. }
  16088. };
  16089. _this.state = {
  16090. records: null
  16091. };
  16092. return _this;
  16093. }
  16094. _createClass(Tooltip, [{
  16095. key: "updateCoord",
  16096. value: function updateCoord() {
  16097. var props = this.props,
  16098. context = this.context;
  16099. var _props$padding = props.padding,
  16100. padding = _props$padding === void 0 ? '10px' : _props$padding,
  16101. chart = props.chart;
  16102. chart.updateCoordFor(this, {
  16103. position: 'top',
  16104. width: 0,
  16105. height: context.px2hd(padding)
  16106. });
  16107. }
  16108. }, {
  16109. key: "willMount",
  16110. value: function willMount() {
  16111. this.updateCoord();
  16112. }
  16113. }, {
  16114. key: "didMount",
  16115. value: function didMount() {
  16116. this._initShow();
  16117. this._initEvent();
  16118. }
  16119. }, {
  16120. key: "willReceiveProps",
  16121. value: function willReceiveProps(nextProps) {
  16122. var nextDefaultItem = nextProps.defaultItem,
  16123. nextCoord = nextProps.coord;
  16124. var _this$props = this.props,
  16125. lastDefaultItem = _this$props.defaultItem,
  16126. lastCoord = _this$props.coord;
  16127. // 默认元素或坐标有变动,均需重新渲染
  16128. if (!equal(nextDefaultItem, lastDefaultItem) || !equal(nextCoord, lastCoord)) {
  16129. this._showByData(nextDefaultItem);
  16130. }
  16131. }
  16132. }, {
  16133. key: "_initShow",
  16134. value: function _initShow() {
  16135. var props = this.props;
  16136. var defaultItem = props.defaultItem;
  16137. this._showByData(defaultItem);
  16138. }
  16139. }, {
  16140. key: "_showByData",
  16141. value: function _showByData(dataItem) {
  16142. var _this2 = this;
  16143. if (!dataItem) return;
  16144. var props = this.props;
  16145. var chart = props.chart;
  16146. // 因为 tooltip 有可能在 geometry 之前,所以需要等 geometry render 完后再执行
  16147. setTimeout(function () {
  16148. var point = chart.getPosition(dataItem);
  16149. _this2.show(point);
  16150. }, 0);
  16151. }
  16152. }, {
  16153. key: "_initEvent",
  16154. value: function _initEvent() {
  16155. var context = this.context,
  16156. props = this.props;
  16157. var canvas = context.canvas;
  16158. var _props$triggerOn = props.triggerOn,
  16159. triggerOn = _props$triggerOn === void 0 ? 'press' : _props$triggerOn,
  16160. _props$triggerOff = props.triggerOff,
  16161. triggerOff = _props$triggerOff === void 0 ? 'pressend' : _props$triggerOff;
  16162. canvas.on(triggerOn, this._triggerOn);
  16163. canvas.on(triggerOff, this._triggerOff);
  16164. }
  16165. }, {
  16166. key: "didUnmount",
  16167. value: function didUnmount() {
  16168. this._clearEvents();
  16169. }
  16170. }, {
  16171. key: "_clearEvents",
  16172. value: function _clearEvents() {
  16173. var context = this.context,
  16174. props = this.props;
  16175. var canvas = context.canvas;
  16176. var _props$triggerOn2 = props.triggerOn,
  16177. triggerOn = _props$triggerOn2 === void 0 ? 'press' : _props$triggerOn2,
  16178. _props$triggerOff2 = props.triggerOff,
  16179. triggerOff = _props$triggerOff2 === void 0 ? 'pressend' : _props$triggerOff2;
  16180. // 解绑事件
  16181. canvas.off(triggerOn, this._triggerOn);
  16182. canvas.off(triggerOff, this._triggerOff);
  16183. }
  16184. }, {
  16185. key: "show",
  16186. value: function show(point, _ev) {
  16187. var props = this.props;
  16188. var chart = props.chart,
  16189. onChange = props.onChange;
  16190. var snapRecords = chart.getSnapRecords(point, true); // 超出边界会自动调整
  16191. if (!snapRecords || !snapRecords.length) return;
  16192. var legendItems = chart.getLegendItems();
  16193. var _snapRecords$ = snapRecords[0],
  16194. xField = _snapRecords$.xField,
  16195. yField = _snapRecords$.yField;
  16196. var xScale = chart.getScale(xField);
  16197. var yScale = chart.getScale(yField);
  16198. var records = snapRecords.map(function (record) {
  16199. var origin = record.origin,
  16200. xField = record.xField,
  16201. yField = record.yField;
  16202. var value = yScale.getText(origin[yField]);
  16203. // 默认取 alias 的配置
  16204. var name = yScale.alias;
  16205. if (!name) {
  16206. name = xScale.getText(origin[xField]);
  16207. if (legendItems && legendItems.length) {
  16208. var item = find(legendItems, function (item) {
  16209. var field = item.field,
  16210. tickValue = item.tickValue;
  16211. return origin[field] === tickValue;
  16212. });
  16213. if (item && item.name) {
  16214. name = item.name;
  16215. }
  16216. }
  16217. }
  16218. return _objectSpread(_objectSpread({}, record), {}, {
  16219. name: name,
  16220. value: value
  16221. });
  16222. });
  16223. if (!isArray(records) || !records.length) {
  16224. return;
  16225. }
  16226. this.setState({
  16227. records: records
  16228. });
  16229. if (isFunction(onChange)) {
  16230. onChange(records);
  16231. }
  16232. }
  16233. }, {
  16234. key: "hide",
  16235. value: function hide() {
  16236. this.setState({
  16237. records: null
  16238. });
  16239. }
  16240. }, {
  16241. key: "render",
  16242. value: function render() {
  16243. var props = this.props,
  16244. state = this.state;
  16245. var visible = props.visible;
  16246. if (visible === false) {
  16247. return null;
  16248. }
  16249. var records = state.records;
  16250. if (!records || !records.length) return null;
  16251. return jsx(View, _objectSpread(_objectSpread({}, props), {}, {
  16252. records: records
  16253. }));
  16254. }
  16255. }]);
  16256. return Tooltip;
  16257. }(Component);
  16258. });
  16259. function createRef() {
  16260. var ref = {
  16261. current: null
  16262. };
  16263. return ref;
  16264. }
  16265. // view 的默认配置
  16266. var defaultStyle$1 = {
  16267. showTitle: false,
  16268. showCrosshairs: false,
  16269. crosshairsType: 'y',
  16270. crosshairsStyle: {
  16271. stroke: 'rgba(0, 0, 0, 0.25)',
  16272. lineWidth: '2px'
  16273. },
  16274. showTooltipMarker: false,
  16275. markerBackgroundStyle: {
  16276. fill: '#CCD6EC',
  16277. opacity: 0.3,
  16278. padding: '6px'
  16279. },
  16280. tooltipMarkerStyle: {
  16281. fill: '#fff',
  16282. lineWidth: '3px'
  16283. },
  16284. background: {
  16285. radius: '4px',
  16286. fill: 'rgba(0, 0, 0, 0.65)',
  16287. padding: ['6px', '10px']
  16288. },
  16289. titleStyle: {
  16290. fontSize: '24px',
  16291. fill: '#fff',
  16292. textAlign: 'start',
  16293. textBaseline: 'top'
  16294. },
  16295. nameStyle: {
  16296. fontSize: '24px',
  16297. fill: 'rgba(255, 255, 255, 0.65)',
  16298. textAlign: 'start',
  16299. textBaseline: 'middle'
  16300. },
  16301. valueStyle: {
  16302. fontSize: '24px',
  16303. fill: '#fff',
  16304. textAlign: 'start',
  16305. textBaseline: 'middle'
  16306. },
  16307. joinString: ': ',
  16308. showItemMarker: true,
  16309. itemMarkerStyle: {
  16310. width: '12px',
  16311. radius: '6px',
  16312. symbol: 'circle',
  16313. lineWidth: '2px',
  16314. stroke: '#fff'
  16315. },
  16316. layout: 'horizontal',
  16317. snap: false,
  16318. xTipTextStyle: {
  16319. fontSize: '24px',
  16320. fill: '#fff'
  16321. },
  16322. yTipTextStyle: {
  16323. fontSize: '24px',
  16324. fill: '#fff'
  16325. },
  16326. xTipBackground: {
  16327. radius: '4px',
  16328. fill: 'rgba(0, 0, 0, 0.65)',
  16329. padding: ['6px', '10px'],
  16330. marginLeft: '-50%',
  16331. marginTop: '6px'
  16332. },
  16333. yTipBackground: {
  16334. radius: '4px',
  16335. fill: 'rgba(0, 0, 0, 0.65)',
  16336. padding: ['6px', '10px'],
  16337. marginLeft: '-100%',
  16338. marginTop: '-50%'
  16339. }
  16340. };
  16341. function directionEnabled(mode, dir) {
  16342. if (mode === undefined) {
  16343. return true;
  16344. } else if (typeof mode === 'string') {
  16345. return mode.indexOf(dir) !== -1;
  16346. }
  16347. return false;
  16348. }
  16349. var RenderItemMarker = function RenderItemMarker(props) {
  16350. var records = props.records,
  16351. coord = props.coord,
  16352. context = props.context,
  16353. markerBackgroundStyle = props.markerBackgroundStyle;
  16354. var point = coord.convertPoint({
  16355. x: 1,
  16356. y: 1
  16357. });
  16358. var padding = context.px2hd(markerBackgroundStyle.padding || '6px');
  16359. var xPoints = [].concat(_toConsumableArray(records.map(function (record) {
  16360. return record.xMin;
  16361. })), _toConsumableArray(records.map(function (record) {
  16362. return record.xMax;
  16363. })));
  16364. var yPoints = [].concat(_toConsumableArray(records.map(function (record) {
  16365. return record.yMin;
  16366. })), _toConsumableArray(records.map(function (record) {
  16367. return record.yMax;
  16368. })));
  16369. if (coord.transposed) {
  16370. xPoints.push(point.x);
  16371. } else {
  16372. yPoints.push(point.y);
  16373. }
  16374. var xMin = Math.min.apply(null, xPoints);
  16375. var xMax = Math.max.apply(null, xPoints);
  16376. var yMin = Math.min.apply(null, yPoints);
  16377. var yMax = Math.max.apply(null, yPoints);
  16378. var x = coord.transposed ? xMin : xMin - padding;
  16379. var y = coord.transposed ? yMin - padding : yMin;
  16380. var width = coord.transposed ? xMax - xMin : xMax - xMin + 2 * padding;
  16381. var height = coord.transposed ? yMax - yMin + 2 * padding : yMax - yMin;
  16382. return jsx("rect", {
  16383. attrs: _objectSpread({
  16384. x: x,
  16385. y: y,
  16386. width: width,
  16387. height: height
  16388. }, markerBackgroundStyle)
  16389. });
  16390. };
  16391. var RenderCrosshairs = function RenderCrosshairs(props) {
  16392. var records = props.records,
  16393. coord = props.coord,
  16394. chart = props.chart,
  16395. crosshairsType = props.crosshairsType,
  16396. crosshairsStyle = props.crosshairsStyle;
  16397. var coordLeft = coord.left,
  16398. coordTop = coord.top,
  16399. coordRight = coord.right,
  16400. coordBottom = coord.bottom,
  16401. center = coord.center;
  16402. var firstRecord = records[0];
  16403. var x = firstRecord.x,
  16404. y = firstRecord.y,
  16405. origin = firstRecord.origin,
  16406. xField = firstRecord.xField;
  16407. if (coord.isPolar) {
  16408. // 极坐标下的辅助线
  16409. var xScale = chart.getScale(xField);
  16410. var ticks = xScale.getTicks();
  16411. var tick = find(ticks, function (tick) {
  16412. return origin[xField] === tick.tickValue;
  16413. });
  16414. var end = coord.convertPoint({
  16415. x: tick.value,
  16416. y: 1
  16417. });
  16418. return jsx("line", {
  16419. attrs: _objectSpread({
  16420. x1: center.x,
  16421. y1: center.y,
  16422. x2: end.x,
  16423. y2: end.y
  16424. }, crosshairsStyle)
  16425. });
  16426. }
  16427. return jsx("group", null, directionEnabled(crosshairsType, 'x') ? jsx("line", {
  16428. attrs: _objectSpread({
  16429. x1: coordLeft,
  16430. y1: y,
  16431. x2: coordRight,
  16432. y2: y
  16433. }, crosshairsStyle)
  16434. }) : null, directionEnabled(crosshairsType, 'y') ? jsx("line", {
  16435. attrs: _objectSpread({
  16436. x1: x,
  16437. y1: coordTop,
  16438. x2: x,
  16439. y2: coordBottom
  16440. }, crosshairsStyle)
  16441. }) : null);
  16442. };
  16443. var TooltipView = /*#__PURE__*/function (_Component) {
  16444. _inherits(TooltipView, _Component);
  16445. var _super = _createSuper(TooltipView);
  16446. function TooltipView(props) {
  16447. var _this;
  16448. _classCallCheck(this, TooltipView);
  16449. _this = _super.call(this, props);
  16450. _this.rootRef = createRef();
  16451. _this.arrowRef = createRef();
  16452. return _this;
  16453. }
  16454. // 调整 显示的位置
  16455. _createClass(TooltipView, [{
  16456. key: "_position",
  16457. value: function _position() {
  16458. var props = this.props,
  16459. context = this.context,
  16460. rootRef = this.rootRef,
  16461. arrowRef = this.arrowRef;
  16462. var group = rootRef.current;
  16463. if (!group) {
  16464. return;
  16465. }
  16466. var records = props.records,
  16467. coord = props.coord;
  16468. var arrowWidth = context.px2hd('6px');
  16469. var record = records[0];
  16470. // 中心点
  16471. var x = record.x;
  16472. var coordLeft = coord.left,
  16473. coordWidth = coord.width;
  16474. var _group$get = group.get('attrs'),
  16475. y = _group$get.y,
  16476. width = _group$get.width,
  16477. height = _group$get.height,
  16478. radius = _group$get.radius;
  16479. var halfWidth = width / 2;
  16480. // 让 tooltip 限制在 coord 的显示范围内
  16481. var offsetX = Math.min(Math.max(x - coordLeft - halfWidth, -arrowWidth - radius), coordWidth - width + arrowWidth + radius);
  16482. // 因为默认是从 coord 的范围内显示的,所以要往上移,移出 coord,避免挡住 geometry
  16483. var offset = Math.min(y, height + arrowWidth); // 因为不能超出 canvas 画布区域,所以最大只能是 y
  16484. group.moveTo(offsetX, -offset);
  16485. arrowRef.current.moveTo(0, height - offset);
  16486. }
  16487. }, {
  16488. key: "didMount",
  16489. value: function didMount() {
  16490. this._position();
  16491. }
  16492. }, {
  16493. key: "didUpdate",
  16494. value: function didUpdate() {
  16495. this._position();
  16496. }
  16497. }, {
  16498. key: "render",
  16499. value: function render() {
  16500. var props = this.props,
  16501. context = this.context;
  16502. var records = props.records,
  16503. coord = props.coord;
  16504. var coordLeft = coord.left,
  16505. coordTop = coord.top,
  16506. coordBottom = coord.bottom;
  16507. var firstRecord = records[0];
  16508. var x = firstRecord.x,
  16509. y = firstRecord.y;
  16510. var xFirstText = firstRecord.name,
  16511. yFirstText = firstRecord.value;
  16512. var chart = props.chart,
  16513. customBackground = props.background,
  16514. _props$showTooltipMar = props.showTooltipMarker,
  16515. showTooltipMarker = _props$showTooltipMar === void 0 ? defaultStyle$1.showTooltipMarker : _props$showTooltipMar,
  16516. _props$markerBackgrou = props.markerBackgroundStyle,
  16517. markerBackgroundStyle = _props$markerBackgrou === void 0 ? defaultStyle$1.markerBackgroundStyle : _props$markerBackgrou,
  16518. _props$showItemMarker = props.showItemMarker,
  16519. showItemMarker = _props$showItemMarker === void 0 ? defaultStyle$1.showItemMarker : _props$showItemMarker,
  16520. customItemMarkerStyle = props.itemMarkerStyle,
  16521. nameStyle = props.nameStyle,
  16522. valueStyle = props.valueStyle,
  16523. _props$joinString = props.joinString,
  16524. joinString = _props$joinString === void 0 ? defaultStyle$1.joinString : _props$joinString,
  16525. _props$showCrosshairs = props.showCrosshairs,
  16526. showCrosshairs = _props$showCrosshairs === void 0 ? defaultStyle$1.showCrosshairs : _props$showCrosshairs,
  16527. crosshairsStyle = props.crosshairsStyle,
  16528. _props$crosshairsType = props.crosshairsType,
  16529. crosshairsType = _props$crosshairsType === void 0 ? defaultStyle$1.crosshairsType : _props$crosshairsType,
  16530. _props$snap = props.snap,
  16531. snap = _props$snap === void 0 ? defaultStyle$1.snap : _props$snap,
  16532. _props$tooltipMarkerS = props.tooltipMarkerStyle,
  16533. tooltipMarkerStyle = _props$tooltipMarkerS === void 0 ? defaultStyle$1.tooltipMarkerStyle : _props$tooltipMarkerS,
  16534. showXTip = props.showXTip,
  16535. showYTip = props.showYTip,
  16536. xTip = props.xTip,
  16537. yTip = props.yTip,
  16538. _props$xTipTextStyle = props.xTipTextStyle,
  16539. xTipTextStyle = _props$xTipTextStyle === void 0 ? defaultStyle$1.xTipTextStyle : _props$xTipTextStyle,
  16540. _props$yTipTextStyle = props.yTipTextStyle,
  16541. yTipTextStyle = _props$yTipTextStyle === void 0 ? defaultStyle$1.yTipTextStyle : _props$yTipTextStyle,
  16542. _props$xTipBackground = props.xTipBackground,
  16543. xTipBackground = _props$xTipBackground === void 0 ? defaultStyle$1.xTipBackground : _props$xTipBackground,
  16544. _props$yTipBackground = props.yTipBackground,
  16545. yTipBackground = _props$yTipBackground === void 0 ? defaultStyle$1.yTipBackground : _props$yTipBackground,
  16546. _props$custom = props.custom,
  16547. custom = _props$custom === void 0 ? false : _props$custom,
  16548. customText = props.customText;
  16549. var itemMarkerStyle = _objectSpread(_objectSpread({}, customItemMarkerStyle), defaultStyle$1.itemMarkerStyle);
  16550. var background = _objectSpread(_objectSpread({}, defaultStyle$1.background), customBackground);
  16551. var arrowWidth = context.px2hd('6px');
  16552. return jsx("group", null, jsx("group", {
  16553. style: {
  16554. left: coordLeft,
  16555. top: coordTop
  16556. }
  16557. }, !custom && jsx("group", null, jsx("group", {
  16558. ref: this.rootRef,
  16559. style: background,
  16560. attrs: background
  16561. }, jsx("group", {
  16562. style: {
  16563. display: 'flex',
  16564. flexDirection: 'row',
  16565. flexWrap: 'wrap',
  16566. padding: [0, 0, 0, '6px']
  16567. }
  16568. }, records.map(function (record) {
  16569. var name = record.name,
  16570. value = record.value;
  16571. return jsx("group", {
  16572. style: {
  16573. display: 'flex',
  16574. flexDirection: 'row',
  16575. alignItems: 'center',
  16576. padding: [0, '6px', 0, 0]
  16577. }
  16578. }, showItemMarker ? jsx("marker", {
  16579. style: {
  16580. width: itemMarkerStyle.width,
  16581. marginRight: '6px'
  16582. },
  16583. attrs: _objectSpread(_objectSpread({}, itemMarkerStyle), {}, {
  16584. fill: record.color
  16585. })
  16586. }) : null, customText && isFunction(customText) ? customText(record) : jsx("group", {
  16587. style: {
  16588. display: 'flex',
  16589. flexDirection: 'row'
  16590. }
  16591. }, jsx("text", {
  16592. attrs: _objectSpread(_objectSpread(_objectSpread({}, defaultStyle$1.nameStyle), nameStyle), {}, {
  16593. text: value ? "".concat(name).concat(joinString) : name
  16594. })
  16595. }), jsx("text", {
  16596. attrs: _objectSpread(_objectSpread(_objectSpread({}, defaultStyle$1.valueStyle), valueStyle), {}, {
  16597. text: value
  16598. })
  16599. })));
  16600. }))), jsx("polygon", {
  16601. ref: this.arrowRef,
  16602. attrs: {
  16603. points: [{
  16604. x: x - arrowWidth,
  16605. y: coordTop
  16606. }, {
  16607. x: x + arrowWidth,
  16608. y: coordTop
  16609. }, {
  16610. x: x,
  16611. y: coordTop + arrowWidth
  16612. }],
  16613. fill: background.fill
  16614. }
  16615. })), showTooltipMarker ? jsx(RenderItemMarker, {
  16616. coord: coord,
  16617. context: context,
  16618. records: records,
  16619. markerBackgroundStyle: markerBackgroundStyle
  16620. }) : null, showCrosshairs ? jsx(RenderCrosshairs, {
  16621. chart: chart,
  16622. coord: coord,
  16623. records: records,
  16624. crosshairsType: crosshairsType,
  16625. crosshairsStyle: _objectSpread(_objectSpread({}, defaultStyle$1.crosshairsStyle), crosshairsStyle)
  16626. }) : null, snap ? records.map(function (item) {
  16627. var x = item.x,
  16628. y = item.y,
  16629. color = item.color,
  16630. shape = item.shape;
  16631. return jsx("circle", {
  16632. attrs: _objectSpread(_objectSpread({
  16633. x: x,
  16634. y: y,
  16635. r: '6px',
  16636. stroke: color,
  16637. fill: color
  16638. }, shape), tooltipMarkerStyle)
  16639. });
  16640. }) : null), showXTip && jsx("group", {
  16641. style: _objectSpread(_objectSpread({
  16642. left: x,
  16643. top: coordBottom
  16644. }, defaultStyle$1.xTipBackground), xTipBackground),
  16645. attrs: _objectSpread(_objectSpread({}, defaultStyle$1.xTipBackground), xTipBackground)
  16646. }, jsx("text", {
  16647. attrs: _objectSpread(_objectSpread(_objectSpread({}, defaultStyle$1.xTipTextStyle), xTipTextStyle), {}, {
  16648. text: isFunction(xTip) ? xTip(xFirstText) : xFirstText
  16649. })
  16650. })), showYTip && jsx("group", {
  16651. style: _objectSpread(_objectSpread({
  16652. left: coordLeft,
  16653. top: y
  16654. }, defaultStyle$1.yTipBackground), yTipBackground),
  16655. attrs: _objectSpread(_objectSpread({}, defaultStyle$1.yTipBackground), yTipBackground)
  16656. }, jsx("text", {
  16657. attrs: _objectSpread(_objectSpread(_objectSpread({}, defaultStyle$1.yTipTextStyle), yTipTextStyle), {}, {
  16658. text: isFunction(yTip) ? yTip(yFirstText) : yFirstText
  16659. })
  16660. })));
  16661. }
  16662. }]);
  16663. return TooltipView;
  16664. }(Component);
  16665. var index$7 = withTooltip(TooltipView);
  16666. function count(node) {
  16667. var sum = 0,
  16668. children = node.children,
  16669. i = children && children.length;
  16670. if (!i) sum = 1;else while (--i >= 0) {
  16671. sum += children[i].value;
  16672. }
  16673. node.value = sum;
  16674. }
  16675. function node_count () {
  16676. return this.eachAfter(count);
  16677. }
  16678. var createForOfIteratorHelper = createCommonjsModule(function (module) {
  16679. function _createForOfIteratorHelper(o, allowArrayLike) {
  16680. var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
  16681. if (!it) {
  16682. if (Array.isArray(o) || (it = unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
  16683. if (it) o = it;
  16684. var i = 0;
  16685. var F = function F() {};
  16686. return {
  16687. s: F,
  16688. n: function n() {
  16689. if (i >= o.length) return {
  16690. done: true
  16691. };
  16692. return {
  16693. done: false,
  16694. value: o[i++]
  16695. };
  16696. },
  16697. e: function e(_e) {
  16698. throw _e;
  16699. },
  16700. f: F
  16701. };
  16702. }
  16703. throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
  16704. }
  16705. var normalCompletion = true,
  16706. didErr = false,
  16707. err;
  16708. return {
  16709. s: function s() {
  16710. it = it.call(o);
  16711. },
  16712. n: function n() {
  16713. var step = it.next();
  16714. normalCompletion = step.done;
  16715. return step;
  16716. },
  16717. e: function e(_e2) {
  16718. didErr = true;
  16719. err = _e2;
  16720. },
  16721. f: function f() {
  16722. try {
  16723. if (!normalCompletion && it["return"] != null) it["return"]();
  16724. } finally {
  16725. if (didErr) throw err;
  16726. }
  16727. }
  16728. };
  16729. }
  16730. module.exports = _createForOfIteratorHelper, module.exports.__esModule = true, module.exports["default"] = module.exports;
  16731. });
  16732. var _createForOfIteratorHelper = /*@__PURE__*/getDefaultExportFromCjs(createForOfIteratorHelper);
  16733. function node_each (callback, that) {
  16734. var index = -1;
  16735. var _iterator = _createForOfIteratorHelper(this),
  16736. _step;
  16737. try {
  16738. for (_iterator.s(); !(_step = _iterator.n()).done;) {
  16739. var node = _step.value;
  16740. callback.call(that, node, ++index, this);
  16741. }
  16742. } catch (err) {
  16743. _iterator.e(err);
  16744. } finally {
  16745. _iterator.f();
  16746. }
  16747. return this;
  16748. }
  16749. function node_eachBefore (callback, that) {
  16750. var node = this,
  16751. nodes = [node],
  16752. children,
  16753. i,
  16754. index = -1;
  16755. while (node = nodes.pop()) {
  16756. callback.call(that, node, ++index, this);
  16757. if (children = node.children) {
  16758. for (i = children.length - 1; i >= 0; --i) {
  16759. nodes.push(children[i]);
  16760. }
  16761. }
  16762. }
  16763. return this;
  16764. }
  16765. function node_eachAfter (callback, that) {
  16766. var node = this,
  16767. nodes = [node],
  16768. next = [],
  16769. children,
  16770. i,
  16771. n,
  16772. index = -1;
  16773. while (node = nodes.pop()) {
  16774. next.push(node);
  16775. if (children = node.children) {
  16776. for (i = 0, n = children.length; i < n; ++i) {
  16777. nodes.push(children[i]);
  16778. }
  16779. }
  16780. }
  16781. while (node = next.pop()) {
  16782. callback.call(that, node, ++index, this);
  16783. }
  16784. return this;
  16785. }
  16786. function node_find (callback, that) {
  16787. var index = -1;
  16788. var _iterator = _createForOfIteratorHelper(this),
  16789. _step;
  16790. try {
  16791. for (_iterator.s(); !(_step = _iterator.n()).done;) {
  16792. var node = _step.value;
  16793. if (callback.call(that, node, ++index, this)) {
  16794. return node;
  16795. }
  16796. }
  16797. } catch (err) {
  16798. _iterator.e(err);
  16799. } finally {
  16800. _iterator.f();
  16801. }
  16802. }
  16803. function node_sum (value) {
  16804. return this.eachAfter(function (node) {
  16805. var sum = +value(node.data) || 0,
  16806. children = node.children,
  16807. i = children && children.length;
  16808. while (--i >= 0) {
  16809. sum += children[i].value;
  16810. }
  16811. node.value = sum;
  16812. });
  16813. }
  16814. function node_sort (compare) {
  16815. return this.eachBefore(function (node) {
  16816. if (node.children) {
  16817. node.children.sort(compare);
  16818. }
  16819. });
  16820. }
  16821. function node_path (end) {
  16822. var start = this,
  16823. ancestor = leastCommonAncestor(start, end),
  16824. nodes = [start];
  16825. while (start !== ancestor) {
  16826. start = start.parent;
  16827. nodes.push(start);
  16828. }
  16829. var k = nodes.length;
  16830. while (end !== ancestor) {
  16831. nodes.splice(k, 0, end);
  16832. end = end.parent;
  16833. }
  16834. return nodes;
  16835. }
  16836. function leastCommonAncestor(a, b) {
  16837. if (a === b) return a;
  16838. var aNodes = a.ancestors(),
  16839. bNodes = b.ancestors(),
  16840. c = null;
  16841. a = aNodes.pop();
  16842. b = bNodes.pop();
  16843. while (a === b) {
  16844. c = a;
  16845. a = aNodes.pop();
  16846. b = bNodes.pop();
  16847. }
  16848. return c;
  16849. }
  16850. function node_ancestors () {
  16851. var node = this,
  16852. nodes = [node];
  16853. while (node = node.parent) {
  16854. nodes.push(node);
  16855. }
  16856. return nodes;
  16857. }
  16858. function node_descendants () {
  16859. return Array.from(this);
  16860. }
  16861. function node_leaves () {
  16862. var leaves = [];
  16863. this.eachBefore(function (node) {
  16864. if (!node.children) {
  16865. leaves.push(node);
  16866. }
  16867. });
  16868. return leaves;
  16869. }
  16870. function node_links () {
  16871. var root = this,
  16872. links = [];
  16873. root.each(function (node) {
  16874. if (node !== root) {
  16875. // Don’t include the root’s parent, if any.
  16876. links.push({
  16877. source: node.parent,
  16878. target: node
  16879. });
  16880. }
  16881. });
  16882. return links;
  16883. }
  16884. var regeneratorRuntime$1 = createCommonjsModule(function (module) {
  16885. var _typeof = _typeof_1["default"];
  16886. function _regeneratorRuntime() {
  16887. module.exports = _regeneratorRuntime = function _regeneratorRuntime() {
  16888. return exports;
  16889. }, module.exports.__esModule = true, module.exports["default"] = module.exports;
  16890. var exports = {},
  16891. Op = Object.prototype,
  16892. hasOwn = Op.hasOwnProperty,
  16893. defineProperty = Object.defineProperty || function (obj, key, desc) {
  16894. obj[key] = desc.value;
  16895. },
  16896. $Symbol = "function" == typeof Symbol ? Symbol : {},
  16897. iteratorSymbol = $Symbol.iterator || "@@iterator",
  16898. asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator",
  16899. toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
  16900. function define(obj, key, value) {
  16901. return Object.defineProperty(obj, key, {
  16902. value: value,
  16903. enumerable: !0,
  16904. configurable: !0,
  16905. writable: !0
  16906. }), obj[key];
  16907. }
  16908. try {
  16909. define({}, "");
  16910. } catch (err) {
  16911. define = function define(obj, key, value) {
  16912. return obj[key] = value;
  16913. };
  16914. }
  16915. function wrap(innerFn, outerFn, self, tryLocsList) {
  16916. var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator,
  16917. generator = Object.create(protoGenerator.prototype),
  16918. context = new Context(tryLocsList || []);
  16919. return defineProperty(generator, "_invoke", {
  16920. value: makeInvokeMethod(innerFn, self, context)
  16921. }), generator;
  16922. }
  16923. function tryCatch(fn, obj, arg) {
  16924. try {
  16925. return {
  16926. type: "normal",
  16927. arg: fn.call(obj, arg)
  16928. };
  16929. } catch (err) {
  16930. return {
  16931. type: "throw",
  16932. arg: err
  16933. };
  16934. }
  16935. }
  16936. exports.wrap = wrap;
  16937. var ContinueSentinel = {};
  16938. function Generator() {}
  16939. function GeneratorFunction() {}
  16940. function GeneratorFunctionPrototype() {}
  16941. var IteratorPrototype = {};
  16942. define(IteratorPrototype, iteratorSymbol, function () {
  16943. return this;
  16944. });
  16945. var getProto = Object.getPrototypeOf,
  16946. NativeIteratorPrototype = getProto && getProto(getProto(values([])));
  16947. NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype);
  16948. var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
  16949. function defineIteratorMethods(prototype) {
  16950. ["next", "throw", "return"].forEach(function (method) {
  16951. define(prototype, method, function (arg) {
  16952. return this._invoke(method, arg);
  16953. });
  16954. });
  16955. }
  16956. function AsyncIterator(generator, PromiseImpl) {
  16957. function invoke(method, arg, resolve, reject) {
  16958. var record = tryCatch(generator[method], generator, arg);
  16959. if ("throw" !== record.type) {
  16960. var result = record.arg,
  16961. value = result.value;
  16962. return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
  16963. invoke("next", value, resolve, reject);
  16964. }, function (err) {
  16965. invoke("throw", err, resolve, reject);
  16966. }) : PromiseImpl.resolve(value).then(function (unwrapped) {
  16967. result.value = unwrapped, resolve(result);
  16968. }, function (error) {
  16969. return invoke("throw", error, resolve, reject);
  16970. });
  16971. }
  16972. reject(record.arg);
  16973. }
  16974. var previousPromise;
  16975. defineProperty(this, "_invoke", {
  16976. value: function value(method, arg) {
  16977. function callInvokeWithMethodAndArg() {
  16978. return new PromiseImpl(function (resolve, reject) {
  16979. invoke(method, arg, resolve, reject);
  16980. });
  16981. }
  16982. return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
  16983. }
  16984. });
  16985. }
  16986. function makeInvokeMethod(innerFn, self, context) {
  16987. var state = "suspendedStart";
  16988. return function (method, arg) {
  16989. if ("executing" === state) throw new Error("Generator is already running");
  16990. if ("completed" === state) {
  16991. if ("throw" === method) throw arg;
  16992. return doneResult();
  16993. }
  16994. for (context.method = method, context.arg = arg;;) {
  16995. var delegate = context.delegate;
  16996. if (delegate) {
  16997. var delegateResult = maybeInvokeDelegate(delegate, context);
  16998. if (delegateResult) {
  16999. if (delegateResult === ContinueSentinel) continue;
  17000. return delegateResult;
  17001. }
  17002. }
  17003. if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) {
  17004. if ("suspendedStart" === state) throw state = "completed", context.arg;
  17005. context.dispatchException(context.arg);
  17006. } else "return" === context.method && context.abrupt("return", context.arg);
  17007. state = "executing";
  17008. var record = tryCatch(innerFn, self, context);
  17009. if ("normal" === record.type) {
  17010. if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue;
  17011. return {
  17012. value: record.arg,
  17013. done: context.done
  17014. };
  17015. }
  17016. "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg);
  17017. }
  17018. };
  17019. }
  17020. function maybeInvokeDelegate(delegate, context) {
  17021. var methodName = context.method,
  17022. method = delegate.iterator[methodName];
  17023. if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator["return"] && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel;
  17024. var record = tryCatch(method, delegate.iterator, context.arg);
  17025. if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel;
  17026. var info = record.arg;
  17027. return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel);
  17028. }
  17029. function pushTryEntry(locs) {
  17030. var entry = {
  17031. tryLoc: locs[0]
  17032. };
  17033. 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry);
  17034. }
  17035. function resetTryEntry(entry) {
  17036. var record = entry.completion || {};
  17037. record.type = "normal", delete record.arg, entry.completion = record;
  17038. }
  17039. function Context(tryLocsList) {
  17040. this.tryEntries = [{
  17041. tryLoc: "root"
  17042. }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0);
  17043. }
  17044. function values(iterable) {
  17045. if (iterable) {
  17046. var iteratorMethod = iterable[iteratorSymbol];
  17047. if (iteratorMethod) return iteratorMethod.call(iterable);
  17048. if ("function" == typeof iterable.next) return iterable;
  17049. if (!isNaN(iterable.length)) {
  17050. var i = -1,
  17051. next = function next() {
  17052. for (; ++i < iterable.length;) {
  17053. if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next;
  17054. }
  17055. return next.value = undefined, next.done = !0, next;
  17056. };
  17057. return next.next = next;
  17058. }
  17059. }
  17060. return {
  17061. next: doneResult
  17062. };
  17063. }
  17064. function doneResult() {
  17065. return {
  17066. value: undefined,
  17067. done: !0
  17068. };
  17069. }
  17070. return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", {
  17071. value: GeneratorFunctionPrototype,
  17072. configurable: !0
  17073. }), defineProperty(GeneratorFunctionPrototype, "constructor", {
  17074. value: GeneratorFunction,
  17075. configurable: !0
  17076. }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) {
  17077. var ctor = "function" == typeof genFun && genFun.constructor;
  17078. return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name));
  17079. }, exports.mark = function (genFun) {
  17080. return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun;
  17081. }, exports.awrap = function (arg) {
  17082. return {
  17083. __await: arg
  17084. };
  17085. }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
  17086. return this;
  17087. }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
  17088. void 0 === PromiseImpl && (PromiseImpl = Promise);
  17089. var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
  17090. return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) {
  17091. return result.done ? result.value : iter.next();
  17092. });
  17093. }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () {
  17094. return this;
  17095. }), define(Gp, "toString", function () {
  17096. return "[object Generator]";
  17097. }), exports.keys = function (val) {
  17098. var object = Object(val),
  17099. keys = [];
  17100. for (var key in object) {
  17101. keys.push(key);
  17102. }
  17103. return keys.reverse(), function next() {
  17104. for (; keys.length;) {
  17105. var key = keys.pop();
  17106. if (key in object) return next.value = key, next.done = !1, next;
  17107. }
  17108. return next.done = !0, next;
  17109. };
  17110. }, exports.values = values, Context.prototype = {
  17111. constructor: Context,
  17112. reset: function reset(skipTempReset) {
  17113. if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) {
  17114. "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined);
  17115. }
  17116. },
  17117. stop: function stop() {
  17118. this.done = !0;
  17119. var rootRecord = this.tryEntries[0].completion;
  17120. if ("throw" === rootRecord.type) throw rootRecord.arg;
  17121. return this.rval;
  17122. },
  17123. dispatchException: function dispatchException(exception) {
  17124. if (this.done) throw exception;
  17125. var context = this;
  17126. function handle(loc, caught) {
  17127. return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught;
  17128. }
  17129. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  17130. var entry = this.tryEntries[i],
  17131. record = entry.completion;
  17132. if ("root" === entry.tryLoc) return handle("end");
  17133. if (entry.tryLoc <= this.prev) {
  17134. var hasCatch = hasOwn.call(entry, "catchLoc"),
  17135. hasFinally = hasOwn.call(entry, "finallyLoc");
  17136. if (hasCatch && hasFinally) {
  17137. if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
  17138. if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
  17139. } else if (hasCatch) {
  17140. if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
  17141. } else {
  17142. if (!hasFinally) throw new Error("try statement without catch or finally");
  17143. if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
  17144. }
  17145. }
  17146. }
  17147. },
  17148. abrupt: function abrupt(type, arg) {
  17149. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  17150. var entry = this.tryEntries[i];
  17151. if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
  17152. var finallyEntry = entry;
  17153. break;
  17154. }
  17155. }
  17156. finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null);
  17157. var record = finallyEntry ? finallyEntry.completion : {};
  17158. return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record);
  17159. },
  17160. complete: function complete(record, afterLoc) {
  17161. if ("throw" === record.type) throw record.arg;
  17162. return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel;
  17163. },
  17164. finish: function finish(finallyLoc) {
  17165. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  17166. var entry = this.tryEntries[i];
  17167. if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel;
  17168. }
  17169. },
  17170. "catch": function _catch(tryLoc) {
  17171. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  17172. var entry = this.tryEntries[i];
  17173. if (entry.tryLoc === tryLoc) {
  17174. var record = entry.completion;
  17175. if ("throw" === record.type) {
  17176. var thrown = record.arg;
  17177. resetTryEntry(entry);
  17178. }
  17179. return thrown;
  17180. }
  17181. }
  17182. throw new Error("illegal catch attempt");
  17183. },
  17184. delegateYield: function delegateYield(iterable, resultName, nextLoc) {
  17185. return this.delegate = {
  17186. iterator: values(iterable),
  17187. resultName: resultName,
  17188. nextLoc: nextLoc
  17189. }, "next" === this.method && (this.arg = undefined), ContinueSentinel;
  17190. }
  17191. }, exports;
  17192. }
  17193. module.exports = _regeneratorRuntime, module.exports.__esModule = true, module.exports["default"] = module.exports;
  17194. });
  17195. // TODO(Babel 8): Remove this file.
  17196. var runtime = regeneratorRuntime$1();
  17197. var regenerator = runtime;
  17198. // Copied from https://github.com/facebook/regenerator/blob/main/packages/runtime/runtime.js#L736=
  17199. try {
  17200. regeneratorRuntime = runtime;
  17201. } catch (accidentalStrictMode) {
  17202. if (typeof globalThis === "object") {
  17203. globalThis.regeneratorRuntime = runtime;
  17204. } else {
  17205. Function("r", "regeneratorRuntime = r")(runtime);
  17206. }
  17207. }
  17208. var _marked = /*#__PURE__*/regenerator.mark(_callee);
  17209. function _callee() {
  17210. var node, current, next, children, i, n;
  17211. return regenerator.wrap(function _callee$(_context) {
  17212. while (1) {
  17213. switch (_context.prev = _context.next) {
  17214. case 0:
  17215. node = this, next = [node];
  17216. case 1:
  17217. current = next.reverse(), next = [];
  17218. case 2:
  17219. if (!(node = current.pop())) {
  17220. _context.next = 8;
  17221. break;
  17222. }
  17223. _context.next = 5;
  17224. return node;
  17225. case 5:
  17226. if (children = node.children) {
  17227. for (i = 0, n = children.length; i < n; ++i) {
  17228. next.push(children[i]);
  17229. }
  17230. }
  17231. _context.next = 2;
  17232. break;
  17233. case 8:
  17234. if (next.length) {
  17235. _context.next = 1;
  17236. break;
  17237. }
  17238. case 9:
  17239. case "end":
  17240. return _context.stop();
  17241. }
  17242. }
  17243. }, _marked, this);
  17244. }
  17245. function hierarchy(data, children) {
  17246. if (data instanceof Map) {
  17247. data = [undefined, data];
  17248. if (children === undefined) children = mapChildren;
  17249. } else if (children === undefined) {
  17250. children = objectChildren;
  17251. }
  17252. var root = new Node(data),
  17253. node,
  17254. nodes = [root],
  17255. child,
  17256. childs,
  17257. i,
  17258. n;
  17259. while (node = nodes.pop()) {
  17260. if ((childs = children(node.data)) && (n = (childs = Array.from(childs)).length)) {
  17261. node.children = childs;
  17262. for (i = n - 1; i >= 0; --i) {
  17263. nodes.push(child = childs[i] = new Node(childs[i]));
  17264. child.parent = node;
  17265. child.depth = node.depth + 1;
  17266. }
  17267. }
  17268. }
  17269. return root.eachBefore(computeHeight);
  17270. }
  17271. function node_copy() {
  17272. return hierarchy(this).eachBefore(copyData);
  17273. }
  17274. function objectChildren(d) {
  17275. return d.children;
  17276. }
  17277. function mapChildren(d) {
  17278. return Array.isArray(d) ? d[1] : null;
  17279. }
  17280. function copyData(node) {
  17281. if (node.data.value !== undefined) node.value = node.data.value;
  17282. node.data = node.data.data;
  17283. }
  17284. function computeHeight(node) {
  17285. var height = 0;
  17286. do {
  17287. node.height = height;
  17288. } while ((node = node.parent) && node.height < ++height);
  17289. }
  17290. function Node(data) {
  17291. this.data = data;
  17292. this.depth = this.height = 0;
  17293. this.parent = null;
  17294. }
  17295. Node.prototype = hierarchy.prototype = _defineProperty({
  17296. constructor: Node,
  17297. count: node_count,
  17298. each: node_each,
  17299. eachAfter: node_eachAfter,
  17300. eachBefore: node_eachBefore,
  17301. find: node_find,
  17302. sum: node_sum,
  17303. sort: node_sort,
  17304. path: node_path,
  17305. ancestors: node_ancestors,
  17306. descendants: node_descendants,
  17307. leaves: node_leaves,
  17308. links: node_links,
  17309. copy: node_copy
  17310. }, Symbol.iterator, _callee);
  17311. function required(f) {
  17312. if (typeof f !== "function") throw new Error();
  17313. return f;
  17314. }
  17315. function constantZero() {
  17316. return 0;
  17317. }
  17318. function constant$1 (x) {
  17319. return function () {
  17320. return x;
  17321. };
  17322. }
  17323. function roundNode (node) {
  17324. node.x0 = Math.round(node.x0);
  17325. node.y0 = Math.round(node.y0);
  17326. node.x1 = Math.round(node.x1);
  17327. node.y1 = Math.round(node.y1);
  17328. }
  17329. function treemapDice (parent, x0, y0, x1, y1) {
  17330. var nodes = parent.children,
  17331. node,
  17332. i = -1,
  17333. n = nodes.length,
  17334. k = parent.value && (x1 - x0) / parent.value;
  17335. while (++i < n) {
  17336. node = nodes[i], node.y0 = y0, node.y1 = y1;
  17337. node.x0 = x0, node.x1 = x0 += node.value * k;
  17338. }
  17339. }
  17340. function partition () {
  17341. var dx = 1,
  17342. dy = 1,
  17343. padding = 0,
  17344. round = false;
  17345. function partition(root) {
  17346. var n = root.height + 1;
  17347. root.x0 = root.y0 = padding;
  17348. root.x1 = dx;
  17349. root.y1 = dy / n;
  17350. root.eachBefore(positionNode(dy, n));
  17351. if (round) root.eachBefore(roundNode);
  17352. return root;
  17353. }
  17354. function positionNode(dy, n) {
  17355. return function (node) {
  17356. if (node.children) {
  17357. treemapDice(node, node.x0, dy * (node.depth + 1) / n, node.x1, dy * (node.depth + 2) / n);
  17358. }
  17359. var x0 = node.x0,
  17360. y0 = node.y0,
  17361. x1 = node.x1 - padding,
  17362. y1 = node.y1 - padding;
  17363. if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
  17364. if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
  17365. node.x0 = x0;
  17366. node.y0 = y0;
  17367. node.x1 = x1;
  17368. node.y1 = y1;
  17369. };
  17370. }
  17371. partition.round = function (x) {
  17372. return arguments.length ? (round = !!x, partition) : round;
  17373. };
  17374. partition.size = function (x) {
  17375. return arguments.length ? (dx = +x[0], dy = +x[1], partition) : [dx, dy];
  17376. };
  17377. partition.padding = function (x) {
  17378. return arguments.length ? (padding = +x, partition) : padding;
  17379. };
  17380. return partition;
  17381. }
  17382. function treemapSlice (parent, x0, y0, x1, y1) {
  17383. var nodes = parent.children,
  17384. node,
  17385. i = -1,
  17386. n = nodes.length,
  17387. k = parent.value && (y1 - y0) / parent.value;
  17388. while (++i < n) {
  17389. node = nodes[i], node.x0 = x0, node.x1 = x1;
  17390. node.y0 = y0, node.y1 = y0 += node.value * k;
  17391. }
  17392. }
  17393. var phi = (1 + Math.sqrt(5)) / 2;
  17394. function squarifyRatio(ratio, parent, x0, y0, x1, y1) {
  17395. var rows = [],
  17396. nodes = parent.children,
  17397. row,
  17398. nodeValue,
  17399. i0 = 0,
  17400. i1 = 0,
  17401. n = nodes.length,
  17402. dx,
  17403. dy,
  17404. value = parent.value,
  17405. sumValue,
  17406. minValue,
  17407. maxValue,
  17408. newRatio,
  17409. minRatio,
  17410. alpha,
  17411. beta;
  17412. while (i0 < n) {
  17413. dx = x1 - x0, dy = y1 - y0;
  17414. // Find the next non-empty node.
  17415. do {
  17416. sumValue = nodes[i1++].value;
  17417. } while (!sumValue && i1 < n);
  17418. minValue = maxValue = sumValue;
  17419. alpha = Math.max(dy / dx, dx / dy) / (value * ratio);
  17420. beta = sumValue * sumValue * alpha;
  17421. minRatio = Math.max(maxValue / beta, beta / minValue);
  17422. // Keep adding nodes while the aspect ratio maintains or improves.
  17423. for (; i1 < n; ++i1) {
  17424. sumValue += nodeValue = nodes[i1].value;
  17425. if (nodeValue < minValue) minValue = nodeValue;
  17426. if (nodeValue > maxValue) maxValue = nodeValue;
  17427. beta = sumValue * sumValue * alpha;
  17428. newRatio = Math.max(maxValue / beta, beta / minValue);
  17429. if (newRatio > minRatio) {
  17430. sumValue -= nodeValue;
  17431. break;
  17432. }
  17433. minRatio = newRatio;
  17434. }
  17435. // Position and record the row orientation.
  17436. rows.push(row = {
  17437. value: sumValue,
  17438. dice: dx < dy,
  17439. children: nodes.slice(i0, i1)
  17440. });
  17441. if (row.dice) treemapDice(row, x0, y0, x1, value ? y0 += dy * sumValue / value : y1);else treemapSlice(row, x0, y0, value ? x0 += dx * sumValue / value : x1, y1);
  17442. value -= sumValue, i0 = i1;
  17443. }
  17444. return rows;
  17445. }
  17446. var squarify = (function custom(ratio) {
  17447. function squarify(parent, x0, y0, x1, y1) {
  17448. squarifyRatio(ratio, parent, x0, y0, x1, y1);
  17449. }
  17450. squarify.ratio = function (x) {
  17451. return custom((x = +x) > 1 ? x : 1);
  17452. };
  17453. return squarify;
  17454. })(phi);
  17455. function treemap () {
  17456. var tile = squarify,
  17457. round = false,
  17458. dx = 1,
  17459. dy = 1,
  17460. paddingStack = [0],
  17461. paddingInner = constantZero,
  17462. paddingTop = constantZero,
  17463. paddingRight = constantZero,
  17464. paddingBottom = constantZero,
  17465. paddingLeft = constantZero;
  17466. function treemap(root) {
  17467. root.x0 = root.y0 = 0;
  17468. root.x1 = dx;
  17469. root.y1 = dy;
  17470. root.eachBefore(positionNode);
  17471. paddingStack = [0];
  17472. if (round) root.eachBefore(roundNode);
  17473. return root;
  17474. }
  17475. function positionNode(node) {
  17476. var p = paddingStack[node.depth],
  17477. x0 = node.x0 + p,
  17478. y0 = node.y0 + p,
  17479. x1 = node.x1 - p,
  17480. y1 = node.y1 - p;
  17481. if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
  17482. if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
  17483. node.x0 = x0;
  17484. node.y0 = y0;
  17485. node.x1 = x1;
  17486. node.y1 = y1;
  17487. if (node.children) {
  17488. p = paddingStack[node.depth + 1] = paddingInner(node) / 2;
  17489. x0 += paddingLeft(node) - p;
  17490. y0 += paddingTop(node) - p;
  17491. x1 -= paddingRight(node) - p;
  17492. y1 -= paddingBottom(node) - p;
  17493. if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
  17494. if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
  17495. tile(node, x0, y0, x1, y1);
  17496. }
  17497. }
  17498. treemap.round = function (x) {
  17499. return arguments.length ? (round = !!x, treemap) : round;
  17500. };
  17501. treemap.size = function (x) {
  17502. return arguments.length ? (dx = +x[0], dy = +x[1], treemap) : [dx, dy];
  17503. };
  17504. treemap.tile = function (x) {
  17505. return arguments.length ? (tile = required(x), treemap) : tile;
  17506. };
  17507. treemap.padding = function (x) {
  17508. return arguments.length ? treemap.paddingInner(x).paddingOuter(x) : treemap.paddingInner();
  17509. };
  17510. treemap.paddingInner = function (x) {
  17511. return arguments.length ? (paddingInner = typeof x === "function" ? x : constant$1(+x), treemap) : paddingInner;
  17512. };
  17513. treemap.paddingOuter = function (x) {
  17514. return arguments.length ? treemap.paddingTop(x).paddingRight(x).paddingBottom(x).paddingLeft(x) : treemap.paddingTop();
  17515. };
  17516. treemap.paddingTop = function (x) {
  17517. return arguments.length ? (paddingTop = typeof x === "function" ? x : constant$1(+x), treemap) : paddingTop;
  17518. };
  17519. treemap.paddingRight = function (x) {
  17520. return arguments.length ? (paddingRight = typeof x === "function" ? x : constant$1(+x), treemap) : paddingRight;
  17521. };
  17522. treemap.paddingBottom = function (x) {
  17523. return arguments.length ? (paddingBottom = typeof x === "function" ? x : constant$1(+x), treemap) : paddingBottom;
  17524. };
  17525. treemap.paddingLeft = function (x) {
  17526. return arguments.length ? (paddingLeft = typeof x === "function" ? x : constant$1(+x), treemap) : paddingLeft;
  17527. };
  17528. return treemap;
  17529. }
  17530. function treemapBinary (parent, x0, y0, x1, y1) {
  17531. var nodes = parent.children,
  17532. i,
  17533. n = nodes.length,
  17534. sum,
  17535. sums = new Array(n + 1);
  17536. for (sums[0] = sum = i = 0; i < n; ++i) {
  17537. sums[i + 1] = sum += nodes[i].value;
  17538. }
  17539. partition(0, n, parent.value, x0, y0, x1, y1);
  17540. function partition(i, j, value, x0, y0, x1, y1) {
  17541. if (i >= j - 1) {
  17542. var node = nodes[i];
  17543. node.x0 = x0, node.y0 = y0;
  17544. node.x1 = x1, node.y1 = y1;
  17545. return;
  17546. }
  17547. var valueOffset = sums[i],
  17548. valueTarget = value / 2 + valueOffset,
  17549. k = i + 1,
  17550. hi = j - 1;
  17551. while (k < hi) {
  17552. var mid = k + hi >>> 1;
  17553. if (sums[mid] < valueTarget) k = mid + 1;else hi = mid;
  17554. }
  17555. if (valueTarget - sums[k - 1] < sums[k] - valueTarget && i + 1 < k) --k;
  17556. var valueLeft = sums[k] - valueOffset,
  17557. valueRight = value - valueLeft;
  17558. if (x1 - x0 > y1 - y0) {
  17559. var xk = value ? (x0 * valueRight + x1 * valueLeft) / value : x1;
  17560. partition(i, k, valueLeft, x0, y0, xk, y1);
  17561. partition(k, j, valueRight, xk, y0, x1, y1);
  17562. } else {
  17563. var yk = value ? (y0 * valueRight + y1 * valueLeft) / value : y1;
  17564. partition(i, k, valueLeft, x0, y0, x1, yk);
  17565. partition(k, j, valueRight, x0, yk, x1, y1);
  17566. }
  17567. }
  17568. }
  17569. var withTreemap = (function (View) {
  17570. return /*#__PURE__*/function (_Component) {
  17571. _inherits(Treemap, _Component);
  17572. var _super = _createSuper(Treemap);
  17573. function Treemap(props, context, updater) {
  17574. var _this;
  17575. _classCallCheck(this, Treemap);
  17576. _this = _super.call(this, props, context, updater);
  17577. var coord = props.coord,
  17578. color = props.color,
  17579. data = props.data;
  17580. var width = context.width,
  17581. height = context.height,
  17582. theme = context.theme;
  17583. _this.coordController = new coordController();
  17584. var _assertThisInitialize = _assertThisInitialized(_this),
  17585. coordController$1 = _assertThisInitialize.coordController;
  17586. _this.coord = coordController$1.create(coord, {
  17587. width: width,
  17588. height: height
  17589. });
  17590. _this.color = new Category$1(_objectSpread(_objectSpread({
  17591. range: theme.colors
  17592. }, color), {}, {
  17593. data: data
  17594. }));
  17595. return _this;
  17596. }
  17597. _createClass(Treemap, [{
  17598. key: "treemapLayout",
  17599. value: function treemapLayout() {
  17600. var props = this.props,
  17601. coord = this.coord,
  17602. colorAttr = this.color;
  17603. var data = props.data,
  17604. value = props.value;
  17605. var root = hierarchy({
  17606. children: data
  17607. }).sum(function (d) {
  17608. return d[value];
  17609. }).sort(function (a, b) {
  17610. return b[value] - a[value];
  17611. });
  17612. var treemapLayout = treemap()
  17613. // 默认treemapSquarify
  17614. .tile(treemapBinary)
  17615. // .size([1, 1])
  17616. // @ts-ignore
  17617. .round(false);
  17618. // .padding(space)
  17619. // .paddingInner(space);
  17620. // .paddingOuter(options.paddingOuter)
  17621. // .paddingTop(options.paddingTop)
  17622. // .paddingRight(options.paddingRight)
  17623. // .paddingBottom(options.paddingBottom)
  17624. // .paddingLeft(options.paddingLeft);
  17625. var nodes = treemapLayout(root);
  17626. return nodes.children.map(function (item) {
  17627. var data = item.data,
  17628. x0 = item.x0,
  17629. y0 = item.y0,
  17630. x1 = item.x1,
  17631. y1 = item.y1;
  17632. var color = colorAttr.mapping(data[colorAttr.field]);
  17633. var rect = coord.convertRect({
  17634. x: [x0, x1],
  17635. y: [y0, y1]
  17636. });
  17637. return _objectSpread({
  17638. key: data.key,
  17639. origin: data,
  17640. color: color
  17641. }, rect);
  17642. });
  17643. }
  17644. }, {
  17645. key: "render",
  17646. value: function render() {
  17647. var nodes = this.treemapLayout();
  17648. var props = this.props,
  17649. coord = this.coord;
  17650. return jsx(View, _objectSpread(_objectSpread({
  17651. nodes: nodes
  17652. }, props), {}, {
  17653. coord: coord
  17654. }));
  17655. }
  17656. }]);
  17657. return Treemap;
  17658. }(Component);
  17659. });
  17660. var TreemapView = (function (props) {
  17661. var nodes = props.nodes,
  17662. coord = props.coord;
  17663. if (coord.isPolar) {
  17664. var center = coord.center;
  17665. var x = center.x,
  17666. y = center.y;
  17667. return jsx("group", null, nodes.map(function (node) {
  17668. var xMin = node.xMin,
  17669. xMax = node.xMax,
  17670. yMin = node.yMin,
  17671. yMax = node.yMax,
  17672. color = node.color;
  17673. return jsx("sector", {
  17674. attrs: {
  17675. x: x,
  17676. y: y,
  17677. lineWidth: '1px',
  17678. stroke: '#fff',
  17679. startAngle: xMin,
  17680. endAngle: xMax,
  17681. r0: yMin,
  17682. r: yMax,
  17683. anticlockwise: false,
  17684. fill: color
  17685. }
  17686. });
  17687. }));
  17688. }
  17689. return jsx("group", null, nodes.map(function (node) {
  17690. var key = node.key,
  17691. xMin = node.xMin,
  17692. xMax = node.xMax,
  17693. yMin = node.yMin,
  17694. yMax = node.yMax,
  17695. color = node.color;
  17696. return jsx("rect", {
  17697. key: key,
  17698. attrs: {
  17699. x: xMin,
  17700. y: yMin,
  17701. width: xMax - xMin,
  17702. height: yMax - yMin,
  17703. fill: color,
  17704. lineWidth: '4px',
  17705. stroke: '#fff',
  17706. radius: '8px'
  17707. },
  17708. animation: {
  17709. appear: {
  17710. easing: 'linear',
  17711. duration: 450,
  17712. property: ['fillOpacity', 'strokeOpacity'],
  17713. start: {
  17714. fillOpacity: 0,
  17715. strokeOpacity: 0
  17716. },
  17717. end: {
  17718. fillOpacity: 1,
  17719. strokeOpacity: 1
  17720. }
  17721. },
  17722. update: {
  17723. easing: 'linear',
  17724. duration: 450,
  17725. property: ['x', 'y', 'width', 'height', 'radius', 'lineWidth']
  17726. }
  17727. }
  17728. });
  17729. }));
  17730. });
  17731. var index$8 = withTreemap(TreemapView);
  17732. function rootParent(data) {
  17733. var d = data;
  17734. while (d.depth > 1) {
  17735. d = d.parent;
  17736. }
  17737. return d;
  17738. }
  17739. var withSunburst = (function (View) {
  17740. return /*#__PURE__*/function (_Component) {
  17741. _inherits(Sunburst, _Component);
  17742. var _super = _createSuper(Sunburst);
  17743. function Sunburst(props, context) {
  17744. var _this;
  17745. _classCallCheck(this, Sunburst);
  17746. _this = _super.call(this, props, context);
  17747. var coord = props.coord,
  17748. color = props.color,
  17749. data = props.data;
  17750. var width = context.width,
  17751. height = context.height,
  17752. theme = context.theme;
  17753. _this.coordController = new coordController();
  17754. var _assertThisInitialize = _assertThisInitialized(_this),
  17755. coordController$1 = _assertThisInitialize.coordController;
  17756. _this.coord = coordController$1.create(coord, {
  17757. width: width,
  17758. height: height
  17759. });
  17760. _this.color = new Category$1(_objectSpread(_objectSpread({
  17761. range: theme.colors
  17762. }, color), {}, {
  17763. data: data
  17764. }));
  17765. return _this;
  17766. }
  17767. _createClass(Sunburst, [{
  17768. key: "didMount",
  17769. value: function didMount() {
  17770. var _this2 = this;
  17771. var props = this.props,
  17772. container = this.container;
  17773. var onClick = props.onClick;
  17774. var canvas = container.get('canvas');
  17775. this.triggerRef = [];
  17776. canvas.on('click', function (ev) {
  17777. var points = ev.points;
  17778. var shape = _this2.triggerRef.find(function (ref) {
  17779. return isInBBox(ref.current.getBBox(), points[0]);
  17780. });
  17781. if (shape) {
  17782. ev.shape = shape;
  17783. // @ts-ignore
  17784. ev.payload = shape.payload;
  17785. onClick && onClick(ev);
  17786. }
  17787. });
  17788. }
  17789. }, {
  17790. key: "_mapping",
  17791. value: function _mapping(children) {
  17792. var colorAttr = this.color,
  17793. coord = this.coord;
  17794. for (var i = 0, len = children.length; i < len; i++) {
  17795. var node = children[i];
  17796. var root = rootParent(node);
  17797. var color = colorAttr.mapping(root.data[colorAttr.field]);
  17798. node.color = color;
  17799. var x0 = node.x0,
  17800. x1 = node.x1,
  17801. y0 = node.y0,
  17802. y1 = node.y1;
  17803. var rect = coord.convertRect({
  17804. x: [x0, x1],
  17805. y: [y0, y1]
  17806. });
  17807. mix(node, rect);
  17808. // 递归处理
  17809. if (node.children && node.children.length) {
  17810. this._mapping(node.children);
  17811. }
  17812. }
  17813. }
  17814. }, {
  17815. key: "sunburst",
  17816. value: function sunburst() {
  17817. var props = this.props;
  17818. var data = props.data,
  17819. value = props.value,
  17820. _props$sort = props.sort,
  17821. sort = _props$sort === void 0 ? true : _props$sort;
  17822. var root = hierarchy({
  17823. children: data
  17824. }).sum(function (d) {
  17825. return d[value];
  17826. });
  17827. // 内置按value大小顺序排序,支持传入sort函数
  17828. if (sort === true || isFunction(sort)) {
  17829. var sortFn = isFunction(sort) ? sort : function (a, b) {
  17830. return b[value] - a[value];
  17831. };
  17832. root.sort(sortFn);
  17833. }
  17834. var nodes = partition()(root);
  17835. var children = nodes.children;
  17836. this._mapping(children);
  17837. return nodes;
  17838. }
  17839. }, {
  17840. key: "render",
  17841. value: function render() {
  17842. var node = this.sunburst();
  17843. var coord = this.coord,
  17844. props = this.props;
  17845. return jsx(View, _objectSpread(_objectSpread({}, props), {}, {
  17846. coord: coord,
  17847. node: node,
  17848. triggerRef: this.triggerRef
  17849. }));
  17850. }
  17851. }]);
  17852. return Sunburst;
  17853. }(Component);
  17854. });
  17855. var SunburstView = (function (props) {
  17856. var coord = props.coord,
  17857. node = props.node;
  17858. var children = node.children;
  17859. var _coord$center = coord.center,
  17860. x = _coord$center.x,
  17861. y = _coord$center.y;
  17862. var renderNodes = function renderNodes(nodes) {
  17863. return jsx("group", null, nodes.map(function (node) {
  17864. var xMin = node.xMin,
  17865. xMax = node.xMax,
  17866. yMin = node.yMin,
  17867. yMax = node.yMax,
  17868. color = node.color,
  17869. children = node.children;
  17870. return jsx("group", null, jsx("sector", {
  17871. attrs: {
  17872. x: x,
  17873. y: y,
  17874. lineWidth: '1px',
  17875. stroke: '#fff',
  17876. startAngle: xMin,
  17877. endAngle: xMax,
  17878. r0: yMin,
  17879. r: yMax,
  17880. anticlockwise: false,
  17881. fill: color
  17882. }
  17883. }), children && children.length ? renderNodes(children) : null);
  17884. }));
  17885. };
  17886. return renderNodes(children);
  17887. });
  17888. var IcicleView = (function (props) {
  17889. var node = props.node;
  17890. var children = node.children;
  17891. var renderNodes = function renderNodes(nodes) {
  17892. return jsx("group", null, nodes.map(function (node) {
  17893. var xMin = node.xMin,
  17894. xMax = node.xMax,
  17895. yMin = node.yMin,
  17896. yMax = node.yMax,
  17897. color = node.color,
  17898. children = node.children;
  17899. return jsx("group", null, jsx("rect", {
  17900. attrs: {
  17901. x: xMin,
  17902. y: yMin,
  17903. width: xMax - xMin,
  17904. height: yMax - yMin,
  17905. lineWidth: '1px',
  17906. stroke: '#fff',
  17907. fill: color
  17908. }
  17909. }), children && children.length ? renderNodes(children) : null);
  17910. }));
  17911. };
  17912. return renderNodes(children);
  17913. });
  17914. var View = (function (props) {
  17915. var coord = props.coord;
  17916. if (coord.type === 'polar') {
  17917. return jsx(SunburstView, _objectSpread({}, props));
  17918. }
  17919. return jsx(IcicleView, _objectSpread({}, props));
  17920. });
  17921. var index$9 = withSunburst(View);
  17922. var DEFAULT_CONFIG = {
  17923. anchorOffset: '10px',
  17924. inflectionOffset: '30px',
  17925. sidePadding: '15px',
  17926. height: '64px',
  17927. adjustOffset: '30',
  17928. triggerOn: 'click',
  17929. // activeShape: false, // 当有图形被选中的时候,是否激活图形
  17930. // activeStyle: {
  17931. // offset: '1px',
  17932. // appendRadius: '8px',
  17933. // fillOpacity: 0.5,
  17934. // },
  17935. label1OffsetY: '-4px',
  17936. label2OffsetY: '4px'
  17937. };
  17938. function getEndPoint(center, angle, r) {
  17939. return {
  17940. x: center.x + r * Math.cos(angle),
  17941. y: center.y + r * Math.sin(angle)
  17942. };
  17943. }
  17944. // 计算中间角度
  17945. function getMiddleAngle(startAngle, endAngle) {
  17946. if (endAngle < startAngle) {
  17947. endAngle += Math.PI * 2;
  17948. }
  17949. return (endAngle + startAngle) / 2;
  17950. }
  17951. function move(from, to, count, center) {
  17952. var x = center.x;
  17953. var sort = from.sort(function (a, b) {
  17954. var aDistance = Math.abs(a.x - x);
  17955. var bDistance = Math.abs(b.x - x);
  17956. return bDistance - aDistance;
  17957. });
  17958. return [sort.slice(0, sort.length - count), sort.slice(sort.length - count).concat(to)];
  17959. }
  17960. // 第一象限
  17961. function isFirstQuadrant(angle) {
  17962. return angle >= -Math.PI / 2 && angle < 0;
  17963. }
  17964. // 第二象限
  17965. function isSecondQuadrant(angle) {
  17966. return angle >= 0 && angle < Math.PI / 2;
  17967. }
  17968. function isThirdQuadrant(angle) {
  17969. return angle >= Math.PI / 2 && angle < Math.PI;
  17970. }
  17971. function isFourthQuadrant(angle) {
  17972. return angle >= Math.PI && angle < Math.PI * 3 / 2;
  17973. }
  17974. function findShapeByClassName(shape, point, className) {
  17975. var targetShapes = getElementsByClassName(className, shape);
  17976. for (var i = 0, len = targetShapes.length; i < len; i++) {
  17977. var _shape = targetShapes[i];
  17978. if (isInBBox(_shape.getBBox(), point)) {
  17979. return _shape;
  17980. }
  17981. }
  17982. }
  17983. var withPieLabel = (function (View) {
  17984. return /*#__PURE__*/function (_Component) {
  17985. _inherits(PieLabel, _Component);
  17986. var _super = _createSuper(PieLabel);
  17987. function PieLabel(props) {
  17988. var _this;
  17989. _classCallCheck(this, PieLabel);
  17990. _this = _super.call(this, props);
  17991. _this._handleEvent = function (ev) {
  17992. var _this$props = _this.props,
  17993. chart = _this$props.chart,
  17994. onClick = _this$props.onClick;
  17995. var ele = _this.triggerRef.current;
  17996. var point = ev.points[0];
  17997. var shape = findShapeByClassName(ele, point, 'click');
  17998. var pieData = chart.getSnapRecords(point);
  17999. if (typeof onClick === 'function') {
  18000. // 点击label
  18001. if (shape) {
  18002. onClick(shape.get('data'));
  18003. }
  18004. // 点击饼图
  18005. else if (isArray(pieData) && pieData.length > 0) {
  18006. onClick(pieData);
  18007. }
  18008. }
  18009. };
  18010. _this.triggerRef = {};
  18011. return _this;
  18012. }
  18013. _createClass(PieLabel, [{
  18014. key: "willMount",
  18015. value: function willMount() {}
  18016. /**
  18017. * 绑定事件
  18018. */
  18019. }, {
  18020. key: "didMount",
  18021. value: function didMount() {
  18022. this._initEvent();
  18023. }
  18024. }, {
  18025. key: "getLabels",
  18026. value: function getLabels(props) {
  18027. var chart = props.chart,
  18028. coord = props.coord,
  18029. anchorOffset = props.anchorOffset,
  18030. inflectionOffset = props.inflectionOffset,
  18031. label1 = props.label1,
  18032. label2 = props.label2,
  18033. itemHeight = props.height,
  18034. sidePadding = props.sidePadding;
  18035. var center = coord.center,
  18036. radius = coord.radius,
  18037. coordWidth = coord.width,
  18038. coordHeight = coord.height,
  18039. coordLeft = coord.left,
  18040. coordRight = coord.right,
  18041. coordTop = coord.top;
  18042. var maxCountForOneSide = Math.floor(coordHeight / itemHeight);
  18043. var maxCount = maxCountForOneSide * 2;
  18044. var geometry = chart.getGeometrys()[0];
  18045. var records = geometry.flatRecords()
  18046. // 按角度大到小排序
  18047. .sort(function (a, b) {
  18048. var angle1 = a.xMax - a.xMin;
  18049. var angle2 = b.xMax - b.xMin;
  18050. return angle2 - angle1;
  18051. })
  18052. // 只取前 maxCount 个显示
  18053. .slice(0, maxCount);
  18054. // 存储左右 labels
  18055. var halves = [[], [] // right
  18056. ];
  18057. records.forEach(function (record) {
  18058. var xMin = record.xMin,
  18059. xMax = record.xMax,
  18060. color = record.color,
  18061. origin = record.origin;
  18062. // 锚点角度
  18063. var anchorAngle = getMiddleAngle(xMin, xMax);
  18064. // 锚点坐标
  18065. var anchorPoint = getEndPoint(center, anchorAngle, radius + anchorOffset);
  18066. // 拐点坐标
  18067. var inflectionPoint = getEndPoint(center, anchorAngle, radius + inflectionOffset);
  18068. // 锚点方向
  18069. var side = anchorPoint.x < center.x ? 'left' : 'right';
  18070. var label = {
  18071. origin: origin,
  18072. angle: anchorAngle,
  18073. anchor: anchorPoint,
  18074. inflection: inflectionPoint,
  18075. side: side,
  18076. x: inflectionPoint.x,
  18077. y: inflectionPoint.y,
  18078. r: radius + inflectionOffset,
  18079. color: color,
  18080. label1: isFunction(label1) ? label1(origin, record) : label1,
  18081. label2: isFunction(label2) ? label2(origin, record) : label2
  18082. };
  18083. // 判断文本的方向
  18084. if (side === 'left') {
  18085. halves[0].push(label);
  18086. } else {
  18087. halves[1].push(label);
  18088. }
  18089. });
  18090. // 判断是有一边超过了显示的最大
  18091. if (halves[0].length > maxCountForOneSide) {
  18092. halves = move(halves[0], halves[1], halves[0].length - maxCountForOneSide, center);
  18093. } else if (halves[1].length > maxCountForOneSide) {
  18094. var _move = move(halves[1], halves[0], halves[1].length - maxCountForOneSide, center),
  18095. _move2 = _slicedToArray(_move, 2),
  18096. right = _move2[0],
  18097. left = _move2[1];
  18098. halves = [left, right];
  18099. }
  18100. // label 的最大宽度
  18101. var labelWidth = coordWidth / 2 - radius - anchorOffset - inflectionOffset - 2 * sidePadding;
  18102. var labels = [];
  18103. halves.forEach(function (half, index) {
  18104. var showSide = index === 0 ? 'left' : 'right';
  18105. // 顺时针方向排序
  18106. half.sort(function (a, b) {
  18107. var aAngle = a.angle;
  18108. var bAngle = b.angle;
  18109. if (showSide === 'left') {
  18110. // 是否在第一象限
  18111. aAngle = isFirstQuadrant(aAngle) ? aAngle + Math.PI * 2 : aAngle;
  18112. bAngle = isFirstQuadrant(bAngle) ? bAngle + Math.PI * 2 : bAngle;
  18113. return bAngle - aAngle;
  18114. } else {
  18115. // 是否在第四象限
  18116. aAngle = isFourthQuadrant(aAngle) ? aAngle - Math.PI * 2 : aAngle;
  18117. bAngle = isFourthQuadrant(bAngle) ? bAngle - Math.PI * 2 : bAngle;
  18118. return aAngle - bAngle;
  18119. }
  18120. });
  18121. var pointsY = half.map(function (label) {
  18122. return label.y;
  18123. });
  18124. var maxY = Math.max.apply(null, pointsY);
  18125. var minY = Math.min.apply(null, pointsY);
  18126. // 每个 label 占用的高度
  18127. var labelCount = half.length;
  18128. var labelHeight = coordHeight / labelCount;
  18129. var halfLabelHeight = labelHeight / 2;
  18130. // 线之间的间隔
  18131. var lineInterval = 2;
  18132. if (showSide === 'left') {
  18133. half.forEach(function (label, index) {
  18134. var anchor = label.anchor,
  18135. inflection = label.inflection,
  18136. angle = label.angle,
  18137. x = label.x,
  18138. y = label.y;
  18139. var points = [anchor, inflection];
  18140. var endX = coordLeft + sidePadding;
  18141. var endY = coordTop + halfLabelHeight + labelHeight * index;
  18142. // 文本开始点
  18143. var labelStart = {
  18144. x: endX + labelWidth + lineInterval * index,
  18145. y: endY
  18146. };
  18147. // 文本结束点
  18148. var labelEnd = {
  18149. x: endX,
  18150. y: endY
  18151. };
  18152. // 第四象限
  18153. if (isFirstQuadrant(angle)) {
  18154. var pointY = minY - lineInterval * (labelCount - index);
  18155. points.push({
  18156. x: x,
  18157. y: pointY
  18158. });
  18159. points.push({
  18160. x: labelStart.x,
  18161. y: pointY
  18162. });
  18163. } else if (isThirdQuadrant(angle) || isFourthQuadrant(angle)) {
  18164. points.push({
  18165. x: labelStart.x,
  18166. y: y
  18167. });
  18168. } else if (isSecondQuadrant(angle)) {
  18169. var _pointY = maxY + lineInterval * index;
  18170. points.push({
  18171. x: x,
  18172. y: _pointY
  18173. });
  18174. points.push({
  18175. x: labelStart.x,
  18176. y: _pointY
  18177. });
  18178. }
  18179. points.push(labelStart);
  18180. points.push(labelEnd);
  18181. label.points = points;
  18182. label.side = showSide;
  18183. labels.push(label);
  18184. });
  18185. } else {
  18186. half.forEach(function (label, index) {
  18187. var anchor = label.anchor,
  18188. inflection = label.inflection,
  18189. angle = label.angle,
  18190. x = label.x,
  18191. y = label.y;
  18192. // 折线的点
  18193. var points = [anchor, inflection];
  18194. var endX = coordRight - sidePadding;
  18195. var endY = coordTop + halfLabelHeight + labelHeight * index;
  18196. // 文本开始点
  18197. var labelStart = {
  18198. x: endX - labelWidth - lineInterval * index,
  18199. y: endY
  18200. };
  18201. // 文本结束点
  18202. var labelEnd = {
  18203. x: endX,
  18204. y: endY
  18205. };
  18206. // 第四象限
  18207. if (isFourthQuadrant(angle)) {
  18208. var pointY = minY - lineInterval * (labelCount - index);
  18209. points.push({
  18210. x: x,
  18211. y: pointY
  18212. });
  18213. points.push({
  18214. x: labelStart.x,
  18215. y: pointY
  18216. });
  18217. } else if (isFirstQuadrant(angle) || isSecondQuadrant(angle)) {
  18218. points.push({
  18219. x: labelStart.x,
  18220. y: y
  18221. });
  18222. } else if (isThirdQuadrant(angle)) {
  18223. var _pointY2 = maxY + lineInterval * index;
  18224. points.push({
  18225. x: x,
  18226. y: _pointY2
  18227. });
  18228. points.push({
  18229. x: labelStart.x,
  18230. y: _pointY2
  18231. });
  18232. }
  18233. points.push(labelStart);
  18234. points.push(labelEnd);
  18235. label.points = points;
  18236. label.side = showSide;
  18237. labels.push(label);
  18238. });
  18239. }
  18240. });
  18241. return labels;
  18242. }
  18243. }, {
  18244. key: "_initEvent",
  18245. value: function _initEvent() {
  18246. var context = this.context,
  18247. props = this.props;
  18248. var canvas = context.canvas;
  18249. var _props$triggerOn = props.triggerOn,
  18250. triggerOn = _props$triggerOn === void 0 ? DEFAULT_CONFIG.triggerOn : _props$triggerOn;
  18251. canvas.on(triggerOn, this._handleEvent);
  18252. }
  18253. }, {
  18254. key: "render",
  18255. value: function render() {
  18256. var context = this.context;
  18257. var props = context.px2hd(deepMix({}, DEFAULT_CONFIG, this.props));
  18258. var labels = this.getLabels(props);
  18259. return jsx(View, _objectSpread(_objectSpread({
  18260. labels: labels
  18261. }, props), {}, {
  18262. triggerRef: this.triggerRef
  18263. }));
  18264. }
  18265. }]);
  18266. return PieLabel;
  18267. }(Component);
  18268. });
  18269. var PieLabelView = (function (props) {
  18270. var lineStyle = props.lineStyle,
  18271. anchorStyle = props.anchorStyle,
  18272. labels = props.labels,
  18273. label1OffsetY = props.label1OffsetY,
  18274. label2OffsetY = props.label2OffsetY,
  18275. triggerRef = props.triggerRef;
  18276. return jsx("group", {
  18277. ref: triggerRef
  18278. }, labels.map(function (label) {
  18279. var origin = label.origin,
  18280. anchor = label.anchor,
  18281. side = label.side,
  18282. color = label.color,
  18283. label1 = label.label1,
  18284. label2 = label.label2,
  18285. points = label.points;
  18286. var end = points[points.length - 1];
  18287. return jsx("group", null, jsx("circle", {
  18288. attrs: _objectSpread({
  18289. r: '4px',
  18290. x: anchor.x,
  18291. y: anchor.y,
  18292. fill: color
  18293. }, anchorStyle)
  18294. }), jsx("polyline", {
  18295. attrs: _objectSpread({
  18296. points: points,
  18297. lineWidth: '2px',
  18298. stroke: color
  18299. }, lineStyle)
  18300. }), jsx("text", {
  18301. className: "click",
  18302. attrs: _objectSpread({
  18303. x: end.x,
  18304. y: end.y + label1OffsetY,
  18305. fontSize: '24px',
  18306. lineHeight: '24px',
  18307. fill: color,
  18308. textBaseline: 'bottom',
  18309. textAlign: side === 'left' ? 'left' : 'right'
  18310. }, label1),
  18311. data: origin
  18312. }), jsx("text", {
  18313. className: "click",
  18314. attrs: _objectSpread({
  18315. x: end.x,
  18316. y: end.y + label2OffsetY,
  18317. fontSize: '24px',
  18318. lineHeight: '24px',
  18319. fill: '#808080',
  18320. textBaseline: 'top',
  18321. textAlign: side === 'left' ? 'left' : 'right'
  18322. }, label2),
  18323. data: origin
  18324. }));
  18325. }));
  18326. });
  18327. var index$a = withPieLabel(PieLabelView);
  18328. var getPoint$2 = function getPoint(cener, angle, r) {
  18329. var x = cener.x + Math.cos(angle) * r;
  18330. var y = cener.y + Math.sin(angle) * r;
  18331. return {
  18332. x: x,
  18333. y: y
  18334. };
  18335. };
  18336. var getTicks = function getTicks(start, end, tickCount, center, r, tickOffset, tickLength) {
  18337. var ticks = [];
  18338. var diff = end - start;
  18339. for (var i = 0; i <= tickCount; i++) {
  18340. var tickValue = start + diff * i / tickCount;
  18341. var startPoint = getPoint$2(center, tickValue, r + tickOffset - tickLength);
  18342. var endPoint = getPoint$2(center, tickValue, r + tickOffset);
  18343. ticks.push({
  18344. tickValue: tickValue,
  18345. start: startPoint,
  18346. end: endPoint
  18347. });
  18348. }
  18349. return ticks;
  18350. };
  18351. var withGauge = (function (View) {
  18352. return /*#__PURE__*/function (_Component) {
  18353. _inherits(Guage, _Component);
  18354. var _super = _createSuper(Guage);
  18355. function Guage() {
  18356. _classCallCheck(this, Guage);
  18357. return _super.apply(this, arguments);
  18358. }
  18359. _createClass(Guage, [{
  18360. key: "render",
  18361. value: function render() {
  18362. var props = this.props,
  18363. context = this.context;
  18364. var startAngle = props.startAngle,
  18365. endAngle = props.endAngle,
  18366. tickCount = props.tickCount,
  18367. center = props.center,
  18368. r = props.r,
  18369. tickOffset = props.tickOffset,
  18370. tickLength = props.tickLength;
  18371. var ticks = getTicks(startAngle, endAngle, tickCount, center, context.px2hd(r), context.px2hd(tickOffset), context.px2hd(tickLength));
  18372. return jsx(View, _objectSpread(_objectSpread({}, props), {}, {
  18373. ticks: ticks
  18374. }));
  18375. }
  18376. }]);
  18377. return Guage;
  18378. }(Component);
  18379. });
  18380. var GaugeView = (function (props) {
  18381. var center = props.center,
  18382. startAngle = props.startAngle,
  18383. endAngle = props.endAngle,
  18384. r = props.r,
  18385. percent = props.percent,
  18386. ticks = props.ticks;
  18387. var x = center.x,
  18388. y = center.y;
  18389. var diff = endAngle - startAngle;
  18390. return jsx("group", null, jsx("arc", {
  18391. attrs: {
  18392. x: x,
  18393. y: y,
  18394. r: r,
  18395. startAngle: startAngle,
  18396. endAngle: endAngle,
  18397. lineWidth: '20px',
  18398. lineCap: 'round',
  18399. stroke: '#e7e7e7'
  18400. }
  18401. }), jsx("arc", {
  18402. attrs: {
  18403. x: x,
  18404. y: y,
  18405. r: r,
  18406. startAngle: startAngle,
  18407. endAngle: startAngle,
  18408. lineWidth: '40px',
  18409. lineCap: 'round',
  18410. stroke: '#0075ff'
  18411. },
  18412. animation: {
  18413. appear: {
  18414. easing: 'linear',
  18415. duration: 500,
  18416. property: ['endAngle'],
  18417. start: {
  18418. endAngle: startAngle
  18419. },
  18420. end: {
  18421. endAngle: startAngle + diff * percent
  18422. }
  18423. }
  18424. }
  18425. }), ticks.map(function (tick) {
  18426. var start = tick.start,
  18427. end = tick.end;
  18428. return jsx("line", {
  18429. attrs: {
  18430. x1: start.x,
  18431. y1: start.y,
  18432. x2: end.x,
  18433. y2: end.y,
  18434. lineWidth: '6px',
  18435. lineCap: 'round',
  18436. stroke: '#e7e7e7'
  18437. }
  18438. });
  18439. }));
  18440. });
  18441. var index$b = withGauge(GaugeView);
  18442. // 判断新老values是否相等,这里只要判断前后是否相等即可
  18443. function isValuesEqual(values, newValues) {
  18444. if (values.length !== newValues.length) {
  18445. return false;
  18446. }
  18447. var lastIndex = values.length - 1;
  18448. return values[0] === newValues[0] && values[lastIndex] === newValues[lastIndex];
  18449. }
  18450. function updateCategoryRange(scale, originScale, range) {
  18451. var currentValues = scale.values,
  18452. currentTicks = scale.ticks,
  18453. tickMethod = scale.tickMethod,
  18454. tickCount = scale.tickCount;
  18455. var originValues = originScale.values;
  18456. var _range = _slicedToArray(range, 2),
  18457. start = _range[0],
  18458. end = _range[1];
  18459. var len = originValues.length;
  18460. var valueStart = start * len;
  18461. var valueEnd = end * len;
  18462. // 保持滑动时个数的稳定
  18463. var count = Math.round(valueEnd - valueStart);
  18464. var sliceSatrt = Math.round(valueStart);
  18465. // 从原始数据里截取需要显示的数据
  18466. var newValues = originValues.slice(sliceSatrt, sliceSatrt + count);
  18467. // 根据当前数据的比例,和定义的tickCount计算应该需要多少个ticks
  18468. var newTickCount = Math.round(tickCount * originValues.length / newValues.length);
  18469. // 计算新的ticks
  18470. var catTicks = getTickMethod(tickMethod);
  18471. var newTicks = catTicks({
  18472. tickCount: newTickCount,
  18473. values: originValues
  18474. });
  18475. // 如果新数组和当前显示的数组相同,则不更新
  18476. if (isValuesEqual(currentValues, newValues) && isValuesEqual(currentTicks, newTicks)) {
  18477. return;
  18478. }
  18479. scale.change({
  18480. values: newValues,
  18481. ticks: newTicks
  18482. });
  18483. return scale;
  18484. }
  18485. function updateLinearRange(scale, originScale, range) {
  18486. var min = originScale.min,
  18487. max = originScale.max;
  18488. var _range2 = _slicedToArray(range, 2),
  18489. start = _range2[0],
  18490. end = _range2[1];
  18491. var newMin = min + (max - min) * start;
  18492. var newMax = min + (max - min) * end;
  18493. scale.change({
  18494. min: newMin,
  18495. max: newMax,
  18496. nice: false
  18497. });
  18498. }
  18499. function updateScale(scale, values) {
  18500. var isLinear = scale.isLinear;
  18501. if (isLinear) {
  18502. var _getRange = getRange(values),
  18503. min = _getRange.min,
  18504. max = _getRange.max;
  18505. return scale.change({
  18506. min: min,
  18507. max: max,
  18508. nice: true
  18509. });
  18510. }
  18511. }
  18512. function updateRange(scale, originScale, range) {
  18513. var isCategory = scale.isCategory,
  18514. isLinear = scale.isLinear;
  18515. if (isCategory) {
  18516. return updateCategoryRange(scale, originScale, range);
  18517. }
  18518. if (isLinear) {
  18519. return updateLinearRange(scale, originScale, range);
  18520. }
  18521. }
  18522. function updateFollow(scales, mainScale, data) {
  18523. var mainField = mainScale.field,
  18524. mainType = mainScale.type,
  18525. mainValues = mainScale.values;
  18526. // 转成 map 提高查询性能
  18527. var mainValuesMap = {};
  18528. mainValues.forEach(function (item) {
  18529. mainValuesMap[item] = true;
  18530. });
  18531. return scales.map(function (scale) {
  18532. var followField = scale.field;
  18533. var values = [];
  18534. data.forEach(function (item) {
  18535. var value = mainType === 'timeCat' ? toTimeStamp(item[mainField]) : item[mainField];
  18536. if (mainValuesMap[value]) {
  18537. values.push(item[followField]);
  18538. }
  18539. });
  18540. return updateScale(scale, values);
  18541. });
  18542. }
  18543. function lerp(min, max, fraction) {
  18544. return (max - min) * fraction + min;
  18545. }
  18546. function isEqual$1(aRange, bRange) {
  18547. for (var i in aRange) {
  18548. if (!isNumberEqual(aRange[i], bRange[i])) return false;
  18549. }
  18550. return true;
  18551. }
  18552. function cloneScale$1(scale, scaleConfig) {
  18553. // @ts-ignore
  18554. return new scale.constructor(_objectSpread(_objectSpread({}, scale.__cfg__), scaleConfig));
  18555. }
  18556. // 缩放
  18557. var Zoom = /*#__PURE__*/function (_Component) {
  18558. _inherits(Zoom, _Component);
  18559. var _super = _createSuper(Zoom);
  18560. function Zoom(props) {
  18561. var _this;
  18562. _classCallCheck(this, Zoom);
  18563. var defaultProps = {
  18564. onPanStart: function onPanStart() {},
  18565. onPinchStart: function onPinchStart() {},
  18566. onPan: function onPan() {},
  18567. onPinch: function onPinch() {},
  18568. onInit: function onInit() {},
  18569. onPanEnd: function onPanEnd() {},
  18570. onPinchEnd: function onPinchEnd() {},
  18571. minCount: 10
  18572. };
  18573. _this = _super.call(this, _objectSpread(_objectSpread({}, defaultProps), props));
  18574. _this.scale = {};
  18575. _this.originScale = {};
  18576. //swipe end x y
  18577. _this.swipeEnd = {
  18578. startX: 0,
  18579. startY: 0,
  18580. endX: 0,
  18581. endY: 0
  18582. };
  18583. _this.onStart = function () {
  18584. var _assertThisInitialize = _assertThisInitialized(_this),
  18585. state = _assertThisInitialize.state;
  18586. var range = state.range;
  18587. _this.startRange = range;
  18588. _this.loop && cancelAnimationFrame(_this.loop);
  18589. };
  18590. _this.onPan = function (ev) {
  18591. var _assertThisInitialize2 = _assertThisInitialized(_this),
  18592. dims = _assertThisInitialize2.dims;
  18593. var range = {};
  18594. each(dims, function (dim) {
  18595. if (dim === 'x') {
  18596. range['x'] = _this._doXPan(ev);
  18597. return;
  18598. }
  18599. if (dim === 'y') {
  18600. range['y'] = _this._doYPan(ev);
  18601. return;
  18602. }
  18603. });
  18604. if (isEqual$1(range, _this.state.range)) return;
  18605. _this.setState({
  18606. range: range
  18607. });
  18608. // console.log('pan range', range);
  18609. };
  18610. _this.onSwipe = function (ev) {
  18611. var swipe = _this.props.swipe;
  18612. if (_this.props.mode.length < 2 || !swipe) return;
  18613. var _ev$velocityX = ev.velocityX,
  18614. velocityX = _ev$velocityX === void 0 ? 0 : _ev$velocityX,
  18615. _ev$velocityY = ev.velocityY,
  18616. velocityY = _ev$velocityY === void 0 ? 0 : _ev$velocityY,
  18617. points = ev.points;
  18618. var range = _this.state.range;
  18619. var _points$ = points[0],
  18620. x = _points$.x,
  18621. y = _points$.y;
  18622. // 边界处理
  18623. if (Math.abs((range === null || range === void 0 ? void 0 : range.x[0]) - 0) < 0.0005 && velocityX > 0) return;
  18624. if (Math.abs((range === null || range === void 0 ? void 0 : range.x[1]) - 1) < 0.0005 && velocityX < 0) return;
  18625. if (Math.abs((range === null || range === void 0 ? void 0 : range.y[0]) - 0) < 0.0005 && velocityY < 0) return;
  18626. if (Math.abs((range === null || range === void 0 ? void 0 : range.x[1]) - 1) < 0.0005 && velocityY > 0) return;
  18627. _this.swipeEnd = {
  18628. startX: x,
  18629. startY: y,
  18630. endX: x + velocityX * 50,
  18631. endY: y - velocityY * 50
  18632. };
  18633. _this.onStart();
  18634. _this.update();
  18635. };
  18636. _this.onPinch = function (ev) {
  18637. var _assertThisInitialize3 = _assertThisInitialized(_this),
  18638. dims = _assertThisInitialize3.dims;
  18639. var range = {};
  18640. each(dims, function (dim) {
  18641. if (dim === 'x') {
  18642. range['x'] = _this._doXPinch(ev);
  18643. return;
  18644. }
  18645. if (dim === 'y') {
  18646. range['y'] = _this._doYPinch(ev);
  18647. return;
  18648. }
  18649. });
  18650. if (isEqual$1(range, _this.state.range)) return;
  18651. _this.setState({
  18652. range: range
  18653. });
  18654. };
  18655. _this.onEnd = function () {
  18656. _this.startRange = null;
  18657. };
  18658. var _props$range = props.range,
  18659. mode = props.mode;
  18660. _this.dims = mode instanceof Array ? mode : [mode];
  18661. return _this;
  18662. }
  18663. _createClass(Zoom, [{
  18664. key: "didMount",
  18665. value: function didMount() {
  18666. this._bindEvents();
  18667. }
  18668. }, {
  18669. key: "willReceiveProps",
  18670. value: function willReceiveProps(nextProps) {
  18671. var nextRange = nextProps.range;
  18672. var lastRange = this.props.range;
  18673. if (!equal(nextRange, lastRange)) {
  18674. var cacheRange = {};
  18675. each(this.dims, function (dim) {
  18676. cacheRange[dim] = nextRange;
  18677. });
  18678. this.state = {
  18679. range: cacheRange
  18680. };
  18681. }
  18682. }
  18683. }, {
  18684. key: "willMount",
  18685. value: function willMount() {
  18686. var _this2 = this;
  18687. var props = this.props,
  18688. dims = this.dims,
  18689. state = this.state;
  18690. var minCount = props.minCount,
  18691. range = props.range;
  18692. // const { range } = state;
  18693. var valueLength = Number.MIN_VALUE;
  18694. var cacheRange = {};
  18695. each(dims, function (dim) {
  18696. var scale = _this2._getScale(dim);
  18697. var values = scale.values;
  18698. valueLength = values.length > valueLength ? values.length : valueLength;
  18699. _this2.scale[dim] = scale;
  18700. _this2.originScale[dim] = cloneScale$1(scale);
  18701. _this2.updateRange(range, dim);
  18702. cacheRange[dim] = range;
  18703. });
  18704. // 图表上最少显示 MIN_COUNT 个数据
  18705. this.minScale = minCount / valueLength;
  18706. this.state = {
  18707. range: cacheRange
  18708. };
  18709. }
  18710. }, {
  18711. key: "didUnmount",
  18712. value: function didUnmount() {
  18713. this.loop && cancelAnimationFrame(this.loop);
  18714. this._clearEvents();
  18715. }
  18716. }, {
  18717. key: "update",
  18718. value: function update() {
  18719. var _this3 = this;
  18720. var _this$swipeEnd = this.swipeEnd,
  18721. startX = _this$swipeEnd.startX,
  18722. startY = _this$swipeEnd.startY,
  18723. endX = _this$swipeEnd.endX,
  18724. endY = _this$swipeEnd.endY;
  18725. var x = lerp(startX, endX, 0.05);
  18726. var y = lerp(startY, endY, 0.05);
  18727. this.swipeEnd = {
  18728. startX: x,
  18729. startY: y,
  18730. endX: endX,
  18731. endY: endY
  18732. };
  18733. var props = this.props;
  18734. var coord = props.coord;
  18735. var coordWidth = coord.width,
  18736. coordHeight = coord.height;
  18737. var range = {};
  18738. range['x'] = this._doPan((x - startX) / coordWidth, 'x');
  18739. range['y'] = this._doPan((y - startY) / coordHeight, 'y');
  18740. this.setState({
  18741. range: range
  18742. });
  18743. this.startRange = range;
  18744. this.loop = requestAnimationFrame(function () {
  18745. return _this3.update();
  18746. });
  18747. if (Math.abs(x - endX) < 0.0005 && Math.abs(y - endY) < 0.0005) {
  18748. this.onEnd();
  18749. cancelAnimationFrame(this.loop);
  18750. }
  18751. }
  18752. }, {
  18753. key: "_doXPan",
  18754. value: function _doXPan(ev) {
  18755. var direction = ev.direction,
  18756. deltaX = ev.deltaX;
  18757. if (this.props.mode.length === 1 && (direction === 'up' || direction === 'down')) {
  18758. return this.state.range['x'];
  18759. }
  18760. ev.preventDefault && ev.preventDefault();
  18761. var props = this.props;
  18762. var coord = props.coord,
  18763. _props$panSensitive = props.panSensitive,
  18764. panSensitive = _props$panSensitive === void 0 ? 1 : _props$panSensitive;
  18765. var coordWidth = coord.width;
  18766. var ratio = deltaX / coordWidth * panSensitive;
  18767. var newRange = this._doPan(ratio, 'x');
  18768. return newRange;
  18769. }
  18770. }, {
  18771. key: "_doYPan",
  18772. value: function _doYPan(ev) {
  18773. var direction = ev.direction,
  18774. deltaY = ev.deltaY;
  18775. if (this.props.mode.length === 1 && (direction === 'left' || direction === 'right')) {
  18776. return this.state.range['y'];
  18777. }
  18778. ev.preventDefault && ev.preventDefault();
  18779. var props = this.props;
  18780. var coord = props.coord,
  18781. _props$panSensitive2 = props.panSensitive,
  18782. panSensitive = _props$panSensitive2 === void 0 ? 1 : _props$panSensitive2;
  18783. var coordHeight = coord.height;
  18784. var ratio = -deltaY / coordHeight * panSensitive;
  18785. var newRange = this._doPan(ratio, 'y');
  18786. return newRange;
  18787. }
  18788. }, {
  18789. key: "_doPan",
  18790. value: function _doPan(ratio, dim) {
  18791. var startRange = this.startRange;
  18792. var _startRange$dim = _slicedToArray(startRange[dim], 2),
  18793. start = _startRange$dim[0],
  18794. end = _startRange$dim[1];
  18795. var rangeLen = end - start;
  18796. var rangeOffset = rangeLen * ratio;
  18797. var newStart = start - rangeOffset;
  18798. var newEnd = end - rangeOffset;
  18799. var newRange = this.updateRange([newStart, newEnd], dim);
  18800. return newRange;
  18801. }
  18802. }, {
  18803. key: "_doXPinch",
  18804. value: function _doXPinch(ev) {
  18805. ev.preventDefault && ev.preventDefault();
  18806. var zoom = ev.zoom,
  18807. center = ev.center;
  18808. var props = this.props;
  18809. var coord = props.coord;
  18810. var coordWidth = coord.width,
  18811. left = coord.left,
  18812. right = coord.right;
  18813. var leftLen = Math.abs(center.x - left);
  18814. var rightLen = Math.abs(right - center.x);
  18815. // 计算左右缩放的比例
  18816. var leftZoom = leftLen / coordWidth;
  18817. var rightZoom = rightLen / coordWidth;
  18818. var newRange = this._doPinch(leftZoom, rightZoom, zoom, 'x');
  18819. return newRange;
  18820. }
  18821. }, {
  18822. key: "_doYPinch",
  18823. value: function _doYPinch(ev) {
  18824. ev.preventDefault && ev.preventDefault();
  18825. var zoom = ev.zoom,
  18826. center = ev.center;
  18827. var props = this.props;
  18828. var coord = props.coord;
  18829. var coordHeight = coord.height,
  18830. top = coord.top,
  18831. bottom = coord.bottom;
  18832. var topLen = Math.abs(center.y - top);
  18833. var bottomLen = Math.abs(bottom - center.y);
  18834. // 计算左右缩放的比例
  18835. var topZoom = topLen / coordHeight;
  18836. var bottomZoom = bottomLen / coordHeight;
  18837. var newRange = this._doPinch(topZoom, bottomZoom, zoom, 'y');
  18838. return newRange;
  18839. }
  18840. }, {
  18841. key: "_doPinch",
  18842. value: function _doPinch(startRatio, endRatio, zoom, dim) {
  18843. var startRange = this.startRange,
  18844. minScale = this.minScale,
  18845. props = this.props;
  18846. var _props$pinchSensitive = props.pinchSensitive,
  18847. pinchSensitive = _props$pinchSensitive === void 0 ? 1 : _props$pinchSensitive;
  18848. var _startRange$dim2 = _slicedToArray(startRange[dim], 2),
  18849. start = _startRange$dim2[0],
  18850. end = _startRange$dim2[1];
  18851. var zoomOffset = zoom < 1 ? (1 / zoom - 1) * pinchSensitive : (1 - zoom) * pinchSensitive;
  18852. var rangeLen = end - start;
  18853. var rangeOffset = rangeLen * zoomOffset;
  18854. var startOffset = rangeOffset * startRatio;
  18855. var endOffset = rangeOffset * endRatio;
  18856. var newStart = Math.max(0, start - startOffset);
  18857. var newEnd = Math.min(1, end + endOffset);
  18858. var newRange = [newStart, newEnd];
  18859. // 如果已经到了最小比例,则不能再继续再放大
  18860. if (newEnd - newStart < minScale) {
  18861. return this.state.range[dim];
  18862. }
  18863. return this.updateRange(newRange, dim);
  18864. }
  18865. }, {
  18866. key: "updateRange",
  18867. value: function updateRange$1(originalRange, dim) {
  18868. if (!originalRange) return;
  18869. var _originalRange = _slicedToArray(originalRange, 2),
  18870. start = _originalRange[0],
  18871. end = _originalRange[1];
  18872. var rangeLength = end - start;
  18873. // 处理边界值
  18874. var newRange;
  18875. if (start < 0) {
  18876. newRange = [0, rangeLength];
  18877. } else if (end > 1) {
  18878. newRange = [1 - rangeLength, 1];
  18879. } else {
  18880. newRange = originalRange;
  18881. }
  18882. var props = this.props,
  18883. scale = this.scale,
  18884. originScale = this.originScale,
  18885. state = this.state;
  18886. var chart = props.chart,
  18887. data = props.data,
  18888. autoFit = props.autoFit;
  18889. var range = state.range;
  18890. if (range && isEqual$1(newRange, range[dim])) return newRange;
  18891. // 更新主 scale
  18892. updateRange(scale[dim], originScale[dim], newRange);
  18893. if (autoFit) {
  18894. var followScale = this._getFollowScales(dim);
  18895. this.updateFollow(followScale, scale[dim], data);
  18896. }
  18897. // 手势变化不执行动画
  18898. var animate = chart.animate;
  18899. chart.setAnimate(false);
  18900. chart.forceUpdate(function () {
  18901. chart.setAnimate(animate);
  18902. });
  18903. return newRange;
  18904. }
  18905. }, {
  18906. key: "updateFollow",
  18907. value: function updateFollow$1(scales, mainScale, data) {
  18908. updateFollow(scales, mainScale, data);
  18909. }
  18910. }, {
  18911. key: "_getScale",
  18912. value: function _getScale(dim) {
  18913. var _this$props = this.props,
  18914. coord = _this$props.coord,
  18915. chart = _this$props.chart;
  18916. if (dim === 'x') {
  18917. return coord.transposed ? chart.getYScales()[0] : chart.getXScales()[0];
  18918. } else {
  18919. return coord.transposed ? chart.getXScales()[0] : chart.getYScales()[0];
  18920. }
  18921. }
  18922. }, {
  18923. key: "_getFollowScales",
  18924. value: function _getFollowScales(dim) {
  18925. var _this$props2 = this.props,
  18926. coord = _this$props2.coord,
  18927. chart = _this$props2.chart;
  18928. if (dim === 'x') {
  18929. return coord.transposed ? chart.getXScales() : chart.getYScales();
  18930. }
  18931. if (dim === 'y') {
  18932. return coord.transposed ? chart.getYScales() : chart.getXScales();
  18933. }
  18934. }
  18935. }, {
  18936. key: "_bindEvents",
  18937. value: function _bindEvents() {
  18938. var _this4 = this;
  18939. var context = this.context,
  18940. props = this.props,
  18941. scale = this.scale;
  18942. var canvas = context.canvas;
  18943. var onPinchStart = props.onPinchStart,
  18944. onPanStart = props.onPanStart,
  18945. onPanEnd = props.onPanEnd,
  18946. pan = props.pan,
  18947. pinch = props.pinch,
  18948. swipe = props.swipe,
  18949. onInit = props.onInit,
  18950. onPan = props.onPan,
  18951. onPinch = props.onPinch,
  18952. onPinchEnd = props.onPinchEnd;
  18953. // 统一绑定事件
  18954. if (pan !== false) {
  18955. canvas.on('panstart', function () {
  18956. _this4.onStart();
  18957. onPanStart({
  18958. scale: scale
  18959. });
  18960. });
  18961. canvas.on('pan', function (ev) {
  18962. _this4.onPan(ev);
  18963. onPan(ev);
  18964. });
  18965. canvas.on('panend', function () {
  18966. _this4.onEnd();
  18967. onPanEnd({
  18968. scale: scale
  18969. });
  18970. });
  18971. }
  18972. if (pinch !== false) {
  18973. canvas.on('pinchstart', function () {
  18974. _this4.onStart();
  18975. onPinchStart();
  18976. });
  18977. canvas.on('pinch', function (ev) {
  18978. _this4.onPinch(ev);
  18979. onPinch(ev);
  18980. });
  18981. canvas.on('pinchend', function () {
  18982. _this4.onEnd();
  18983. onPinchEnd({
  18984. scale: scale
  18985. });
  18986. });
  18987. }
  18988. if (swipe !== false) {
  18989. canvas.on('swipe', this.onSwipe);
  18990. }
  18991. onInit({
  18992. scale: scale
  18993. });
  18994. }
  18995. }, {
  18996. key: "_clearEvents",
  18997. value: function _clearEvents() {
  18998. var _this5 = this;
  18999. var context = this.context,
  19000. props = this.props,
  19001. scale = this.scale;
  19002. var canvas = context.canvas;
  19003. var onPinchEnd = props.onPinchEnd,
  19004. onPanEnd = props.onPanEnd,
  19005. onPinchStart = props.onPinchStart,
  19006. pan = props.pan,
  19007. pinch = props.pinch,
  19008. onPan = props.onPan,
  19009. onPinch = props.onPinch,
  19010. swipe = props.swipe;
  19011. // 统一解绑事件
  19012. if (pan !== false) {
  19013. canvas.off('panstart', function () {
  19014. _this5.onStart();
  19015. onPinchStart();
  19016. });
  19017. canvas.off('pan', function (ev) {
  19018. _this5.onPan(ev);
  19019. onPan(ev);
  19020. });
  19021. canvas.off('panend', function () {
  19022. _this5.onEnd();
  19023. onPanEnd({
  19024. scale: scale
  19025. });
  19026. });
  19027. }
  19028. if (pinch !== false) {
  19029. canvas.off('pinchstart', function () {
  19030. _this5.onStart();
  19031. onPinchStart();
  19032. });
  19033. canvas.off('pinch', function (ev) {
  19034. _this5.onPinch(ev);
  19035. onPinch(ev);
  19036. });
  19037. canvas.off('pinchend', function () {
  19038. _this5.onEnd();
  19039. onPinchEnd({
  19040. scale: scale
  19041. });
  19042. });
  19043. }
  19044. if (swipe !== false) {
  19045. canvas.off('swipe', this.onSwipe);
  19046. }
  19047. }
  19048. }]);
  19049. return Zoom;
  19050. }(Component);
  19051. var withScrollBar = (function (View) {
  19052. return /*#__PURE__*/function (_Zoom) {
  19053. _inherits(ScrollBar, _Zoom);
  19054. var _super = _createSuper(ScrollBar);
  19055. function ScrollBar() {
  19056. _classCallCheck(this, ScrollBar);
  19057. return _super.apply(this, arguments);
  19058. }
  19059. _createClass(ScrollBar, [{
  19060. key: "willMount",
  19061. value: function willMount() {
  19062. _get$1(_getPrototypeOf(ScrollBar.prototype), "willMount", this).call(this);
  19063. var context = this.context,
  19064. props = this.props;
  19065. var visible = props.visible,
  19066. _props$position = props.position,
  19067. position = _props$position === void 0 ? 'bottom' : _props$position,
  19068. _props$margin = props.margin,
  19069. margin = _props$margin === void 0 ? '16px' : _props$margin,
  19070. chart = props.chart;
  19071. var marginNumber = context.px2hd(margin);
  19072. if (visible === false) {
  19073. return null;
  19074. }
  19075. chart.updateCoordFor(this, {
  19076. position: position,
  19077. width: position === 'left' || position === 'right' ? marginNumber : 0,
  19078. height: position === 'bottom' || position === 'top' ? marginNumber : 0
  19079. });
  19080. }
  19081. }, {
  19082. key: "render",
  19083. value: function render() {
  19084. var props = this.props,
  19085. state = this.state;
  19086. var visible = props.visible;
  19087. if (visible === false) {
  19088. return null;
  19089. }
  19090. return jsx(View, _objectSpread(_objectSpread({
  19091. position: "bottom"
  19092. }, props), state));
  19093. }
  19094. }]);
  19095. return ScrollBar;
  19096. }(Zoom);
  19097. });
  19098. var Horizontal = (function (props, context) {
  19099. var coord = props.coord,
  19100. range = props.range,
  19101. position = props.position,
  19102. layout = props.layout;
  19103. var left = coord.left,
  19104. width = coord.width;
  19105. var top = layout.top,
  19106. height = layout.height;
  19107. var _ref = (range === null || range === void 0 ? void 0 : range.x) || (range === null || range === void 0 ? void 0 : range.y),
  19108. _ref2 = _slicedToArray(_ref, 2),
  19109. start = _ref2[0],
  19110. end = _ref2[1];
  19111. var barLeft = width * start;
  19112. var barWidth = width * (end - start);
  19113. return jsx("group", {
  19114. style: {
  19115. left: left,
  19116. top: position === 'top' ? top - context.px2hd('8px') : top + height
  19117. }
  19118. }, jsx("line", {
  19119. style: {
  19120. position: 'absolute',
  19121. left: 0,
  19122. width: width,
  19123. height: 0
  19124. },
  19125. attrs: {
  19126. stroke: 'rgba(202, 215, 239, .2)',
  19127. lineCap: 'round',
  19128. lineWidth: '8px'
  19129. }
  19130. }), jsx("line", {
  19131. style: {
  19132. position: 'absolute',
  19133. left: barLeft,
  19134. width: barWidth,
  19135. height: 0
  19136. },
  19137. attrs: {
  19138. stroke: 'rgba(202, 215, 239, .5)',
  19139. lineCap: 'round',
  19140. lineWidth: '8px'
  19141. }
  19142. }));
  19143. });
  19144. var Vertical = (function (props, context) {
  19145. var coord = props.coord,
  19146. range = props.range,
  19147. position = props.position,
  19148. layout = props.layout;
  19149. var top = coord.top,
  19150. height = coord.height;
  19151. var left = layout.left,
  19152. width = layout.width;
  19153. var _ref = (range === null || range === void 0 ? void 0 : range.y) || (range === null || range === void 0 ? void 0 : range.x),
  19154. _ref2 = _slicedToArray(_ref, 2),
  19155. start = _ref2[0],
  19156. end = _ref2[1];
  19157. var barTop = height * start;
  19158. var barHeight = height * (end - start);
  19159. return jsx("group", {
  19160. style: {
  19161. top: top,
  19162. left: position === 'left' ? left - context.px2hd('8px') : left + width
  19163. }
  19164. }, jsx("line", {
  19165. style: {
  19166. position: 'absolute',
  19167. top: 0,
  19168. left: 0,
  19169. width: 0,
  19170. height: height
  19171. },
  19172. attrs: {
  19173. stroke: 'rgba(202, 215, 239, .2)',
  19174. lineCap: 'round',
  19175. lineWidth: '8px'
  19176. }
  19177. }), jsx("line", {
  19178. style: {
  19179. position: 'absolute',
  19180. top: barTop,
  19181. width: 0,
  19182. height: barHeight
  19183. },
  19184. attrs: {
  19185. stroke: 'rgba(202, 215, 239, .5)',
  19186. lineCap: 'round',
  19187. lineWidth: '8px'
  19188. }
  19189. }));
  19190. });
  19191. var ScrollBarView = (function (props) {
  19192. var position = props.position,
  19193. mode = props.mode;
  19194. if (mode.length > 1) {
  19195. return jsx("group", null, jsx(Vertical, _objectSpread({}, props)), jsx(Horizontal, _objectSpread({}, props)));
  19196. }
  19197. if (position === 'left' || position === 'right') {
  19198. return jsx(Vertical, _objectSpread({}, props));
  19199. }
  19200. return jsx(Horizontal, _objectSpread({}, props));
  19201. });
  19202. var index$c = withScrollBar(ScrollBarView);
  19203. exports.ArcGuide = ArcGuide;
  19204. exports.Area = index$1;
  19205. exports.AreaView = AreaView;
  19206. exports.Axis = index$4;
  19207. exports.AxisView = AxisView;
  19208. exports.Canvas = Canvas$1;
  19209. exports.Chart = Chart;
  19210. exports.Children = Children;
  19211. exports.Component = Component;
  19212. exports.Fragment = fragment;
  19213. exports.Gauge = index$b;
  19214. exports.GaugeView = GaugeView;
  19215. exports.Geometry = Geometry;
  19216. exports.Guide = index$6;
  19217. exports.ImageGuide = ImageGuide;
  19218. exports.Interval = index$2;
  19219. exports.IntervalView = intervalView;
  19220. exports.Legend = index$5;
  19221. exports.LegendView = LegendView;
  19222. exports.Line = index;
  19223. exports.LineGuide = LineGuide;
  19224. exports.LineView = LineView;
  19225. exports.PieLabel = index$a;
  19226. exports.PieLabelView = PieLabelView;
  19227. exports.Point = index$3;
  19228. exports.PointGuide = PointGuide;
  19229. exports.PointView = PointView;
  19230. exports.RectGuide = RectGuide;
  19231. exports.ScrollBar = index$c;
  19232. exports.ScrollBarView = ScrollBarView;
  19233. exports.Sunburst = index$9;
  19234. exports.SunburstView = SunburstView;
  19235. exports.TagGuide = TagGuide;
  19236. exports.TextGuide = TextGuide;
  19237. exports.Timeline = Timeline;
  19238. exports.Tooltip = index$7;
  19239. exports.TooltipView = TooltipView;
  19240. exports.Treemap = index$8;
  19241. exports.TreemapView = TreemapView;
  19242. exports.Zoom = Zoom;
  19243. exports.createElement = jsx;
  19244. exports.createRef = createRef;
  19245. exports.jsx = jsx;
  19246. exports.render = render$1;
  19247. exports.renderShape = renderShape;
  19248. exports.withArea = withArea;
  19249. exports.withAxis = withAxis;
  19250. exports.withGauge = withGauge;
  19251. exports.withGuide = withGuide;
  19252. exports.withInterval = withInterval;
  19253. exports.withLegend = withLegend;
  19254. exports.withLine = withLine;
  19255. exports.withPieLabel = withPieLabel;
  19256. exports.withPoint = withPoint;
  19257. exports.withScrollBar = withScrollBar;
  19258. exports.withSunburst = withSunburst;
  19259. exports.withTooltip = withTooltip;
  19260. exports.withTreemap = withTreemap;
  19261. Object.defineProperty(exports, '__esModule', { value: true });
  19262. })));