index.js 603 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804
  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 defineProperty = createCommonjsModule(function (module) {
  22. function _defineProperty(obj, key, value) {
  23. if (key in obj) {
  24. Object.defineProperty(obj, key, {
  25. value: value,
  26. enumerable: true,
  27. configurable: true,
  28. writable: true
  29. });
  30. } else {
  31. obj[key] = value;
  32. }
  33. return obj;
  34. }
  35. module.exports = _defineProperty, module.exports.__esModule = true, module.exports["default"] = module.exports;
  36. });
  37. var _defineProperty = /*@__PURE__*/getDefaultExportFromCjs(defineProperty);
  38. var objectSpread2 = createCommonjsModule(function (module) {
  39. function ownKeys(object, enumerableOnly) {
  40. var keys = Object.keys(object);
  41. if (Object.getOwnPropertySymbols) {
  42. var symbols = Object.getOwnPropertySymbols(object);
  43. enumerableOnly && (symbols = symbols.filter(function (sym) {
  44. return Object.getOwnPropertyDescriptor(object, sym).enumerable;
  45. })), keys.push.apply(keys, symbols);
  46. }
  47. return keys;
  48. }
  49. function _objectSpread2(target) {
  50. for (var i = 1; i < arguments.length; i++) {
  51. var source = null != arguments[i] ? arguments[i] : {};
  52. i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
  53. defineProperty(target, key, source[key]);
  54. }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
  55. Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
  56. });
  57. }
  58. return target;
  59. }
  60. module.exports = _objectSpread2, module.exports.__esModule = true, module.exports["default"] = module.exports;
  61. });
  62. var _objectSpread = /*@__PURE__*/getDefaultExportFromCjs(objectSpread2);
  63. var isArrayLike = function (value) {
  64. /**
  65. * isArrayLike([1, 2, 3]) => true
  66. * isArrayLike(document.body.children) => true
  67. * isArrayLike('abc') => true
  68. * isArrayLike(Function) => false
  69. */
  70. return value !== null && typeof value !== 'function' && isFinite(value.length);
  71. };
  72. var filter = function (arr, func) {
  73. if (!isArrayLike(arr)) {
  74. return arr;
  75. }
  76. var result = [];
  77. for (var index = 0; index < arr.length; index++) {
  78. var value = arr[index];
  79. if (func(value, index)) {
  80. result.push(value);
  81. }
  82. }
  83. return result;
  84. };
  85. var toString = {}.toString;
  86. var isType = function (value, type) { return toString.call(value) === '[object ' + type + ']'; };
  87. /**
  88. * 是否为函数
  89. * @param {*} fn 对象
  90. * @return {Boolean} 是否函数
  91. */
  92. var isFunction = (function (value) {
  93. return isType(value, 'Function');
  94. });
  95. // isFinite,
  96. var isNil = function (value) {
  97. /**
  98. * isNil(null) => true
  99. * isNil() => true
  100. */
  101. return value === null || value === undefined;
  102. };
  103. var isArray = (function (value) {
  104. return Array.isArray ?
  105. Array.isArray(value) :
  106. isType(value, 'Array');
  107. });
  108. var isObject = (function (value) {
  109. /**
  110. * isObject({}) => true
  111. * isObject([1, 2, 3]) => true
  112. * isObject(Function) => true
  113. * isObject(null) => false
  114. */
  115. var type = typeof value;
  116. return value !== null && type === 'object' || type === 'function';
  117. });
  118. function each(elements, func) {
  119. if (!elements) {
  120. return;
  121. }
  122. var rst;
  123. if (isArray(elements)) {
  124. for (var i = 0, len = elements.length; i < len; i++) {
  125. rst = func(elements[i], i);
  126. if (rst === false) {
  127. break;
  128. }
  129. }
  130. }
  131. else if (isObject(elements)) {
  132. for (var k in elements) {
  133. if (elements.hasOwnProperty(k)) {
  134. rst = func(elements[k], k);
  135. if (rst === false) {
  136. break;
  137. }
  138. }
  139. }
  140. }
  141. }
  142. var keys = Object.keys ? function (obj) { return Object.keys(obj); } : function (obj) {
  143. var result = [];
  144. each(obj, function (value, key) {
  145. if (!(isFunction(obj) && key === 'prototype')) {
  146. result.push(key);
  147. }
  148. });
  149. return result;
  150. };
  151. function isMatch(obj, attrs) {
  152. var _keys = keys(attrs);
  153. var length = _keys.length;
  154. if (isNil(obj))
  155. return !length;
  156. for (var i = 0; i < length; i += 1) {
  157. var key = _keys[i];
  158. if (attrs[key] !== obj[key] || !(key in obj)) {
  159. return false;
  160. }
  161. }
  162. return true;
  163. }
  164. var isObjectLike = function (value) {
  165. /**
  166. * isObjectLike({}) => true
  167. * isObjectLike([1, 2, 3]) => true
  168. * isObjectLike(Function) => false
  169. * isObjectLike(null) => false
  170. */
  171. return typeof value === 'object' && value !== null;
  172. };
  173. var isPlainObject = function (value) {
  174. /**
  175. * isObjectLike(new Foo) => false
  176. * isObjectLike([1, 2, 3]) => false
  177. * isObjectLike({ x: 0, y: 0 }) => true
  178. * isObjectLike(Object.create(null)) => true
  179. */
  180. if (!isObjectLike(value) || !isType(value, 'Object')) {
  181. return false;
  182. }
  183. if (Object.getPrototypeOf(value) === null) {
  184. return true;
  185. }
  186. var proto = value;
  187. while (Object.getPrototypeOf(proto) !== null) {
  188. proto = Object.getPrototypeOf(proto);
  189. }
  190. return Object.getPrototypeOf(value) === proto;
  191. };
  192. function find(arr, predicate) {
  193. if (!isArray(arr))
  194. return null;
  195. var _predicate;
  196. if (isFunction(predicate)) {
  197. _predicate = predicate;
  198. }
  199. if (isPlainObject(predicate)) {
  200. _predicate = function (a) { return isMatch(a, predicate); };
  201. }
  202. if (_predicate) {
  203. for (var i = 0; i < arr.length; i += 1) {
  204. if (_predicate(arr[i])) {
  205. return arr[i];
  206. }
  207. }
  208. }
  209. return null;
  210. }
  211. function findIndex(arr, predicate, fromIndex) {
  212. if (fromIndex === void 0) { fromIndex = 0; }
  213. for (var i = fromIndex; i < arr.length; i++) {
  214. if (predicate(arr[i], i)) {
  215. // 找到终止循环
  216. return i;
  217. }
  218. }
  219. return -1;
  220. }
  221. /**
  222. * Flattens `array` a single level deep.
  223. *
  224. * @param {Array} arr The array to flatten.
  225. * @return {Array} Returns the new flattened array.
  226. * @example
  227. *
  228. * flatten([1, [2, [3, [4]], 5]]); // => [1, 2, [3, [4]], 5]
  229. */
  230. var flatten = function (arr) {
  231. if (!isArray(arr)) {
  232. return [];
  233. }
  234. var rst = [];
  235. for (var i = 0; i < arr.length; i++) {
  236. rst = rst.concat(arr[i]);
  237. }
  238. return rst;
  239. };
  240. /**
  241. * @param {Array} arr The array to iterate over.
  242. * @return {*} Returns the maximum value.
  243. * @example
  244. *
  245. * max([1, 2]);
  246. * // => 2
  247. *
  248. * max([]);
  249. * // => undefined
  250. *
  251. * const data = new Array(1250010).fill(1).map((d,idx) => idx);
  252. *
  253. * max(data);
  254. * // => 1250010
  255. * // Math.max(...data) will encounter "Maximum call stack size exceeded" error
  256. */
  257. var getMax = (function (arr) {
  258. if (!isArray(arr)) {
  259. return undefined;
  260. }
  261. return arr.reduce(function (prev, curr) {
  262. return Math.max(prev, curr);
  263. }, arr[0]);
  264. });
  265. /**
  266. * @param {Array} arr The array to iterate over.
  267. * @return {*} Returns the minimum value.
  268. * @example
  269. *
  270. * min([1, 2]);
  271. * // => 1
  272. *
  273. * min([]);
  274. * // => undefined
  275. *
  276. * const data = new Array(1250010).fill(1).map((d,idx) => idx);
  277. *
  278. * min(data);
  279. * // => 1250010
  280. * // Math.min(...data) will encounter "Maximum call stack size exceeded" error
  281. */
  282. var getMin = (function (arr) {
  283. if (!isArray(arr)) {
  284. return undefined;
  285. }
  286. return arr.reduce(function (prev, curr) {
  287. return Math.min(prev, curr);
  288. }, arr[0]);
  289. });
  290. var getRange = function (values) {
  291. // 存在 NaN 时,min,max 判定会出问题
  292. var filterValues = values.filter(function (v) { return !isNaN(v); });
  293. if (!filterValues.length) {
  294. // 如果没有数值则直接返回0
  295. return {
  296. min: 0,
  297. max: 0,
  298. };
  299. }
  300. if (isArray(values[0])) {
  301. var tmp = [];
  302. for (var i = 0; i < values.length; i++) {
  303. tmp = tmp.concat(values[i]);
  304. }
  305. filterValues = tmp;
  306. }
  307. var max = getMax(filterValues);
  308. var min = getMin(filterValues);
  309. return {
  310. min: min,
  311. max: max,
  312. };
  313. };
  314. var reduce = function (arr, fn, init) {
  315. if (!isArray(arr) && !isPlainObject(arr)) {
  316. return arr;
  317. }
  318. var result = init;
  319. each(arr, function (data, i) {
  320. result = fn(result, data, i);
  321. });
  322. return result;
  323. };
  324. var isString = (function (str) {
  325. return isType(str, 'String');
  326. });
  327. var valuesOfKey = (function (data, name) {
  328. var rst = [];
  329. var tmpMap = {};
  330. for (var i = 0; i < data.length; i++) {
  331. var obj = data[i];
  332. var value = obj[name];
  333. if (!isNil(value)) {
  334. // flatten
  335. if (!isArray(value)) {
  336. value = [value];
  337. }
  338. for (var j = 0; j < value.length; j++) {
  339. var val = value[j];
  340. // unique
  341. if (!tmpMap[val]) {
  342. rst.push(val);
  343. tmpMap[val] = true;
  344. }
  345. }
  346. }
  347. }
  348. return rst;
  349. });
  350. function head(o) {
  351. if (isArrayLike(o)) {
  352. return o[0];
  353. }
  354. return undefined;
  355. }
  356. function last(o) {
  357. if (isArrayLike(o)) {
  358. var arr = o;
  359. return arr[arr.length - 1];
  360. }
  361. return undefined;
  362. }
  363. var hasOwnProperty = Object.prototype.hasOwnProperty;
  364. function groupBy(data, condition) {
  365. if (!condition || !isArray(data)) {
  366. return {};
  367. }
  368. var result = {};
  369. // 兼容方法和 字符串的写法
  370. var predicate = isFunction(condition) ? condition : function (item) { return item[condition]; };
  371. var key;
  372. for (var i = 0; i < data.length; i++) {
  373. var item = data[i];
  374. key = predicate(item);
  375. if (hasOwnProperty.call(result, key)) {
  376. result[key].push(item);
  377. }
  378. else {
  379. result[key] = [item];
  380. }
  381. }
  382. return result;
  383. }
  384. /**
  385. * 将数据分组成 map
  386. * @param data
  387. * @param condition
  388. */
  389. function groupToMap(data, condition) {
  390. if (!condition) {
  391. return {
  392. 0: data,
  393. };
  394. }
  395. if (!isFunction(condition)) {
  396. // 如果是字符串,则按照 a*b 风格成数组
  397. var paramscondition_1 = isArray(condition) ? condition : condition.replace(/\s+/g, '').split('*');
  398. condition = function (row) {
  399. var unique = '_'; // 避免出现数字作为Key的情况,会进行按照数字的排序
  400. // 根据字段列表的值,拼接成 key
  401. for (var i = 0, l = paramscondition_1.length; i < l; i++) {
  402. unique += row[paramscondition_1[i]] && row[paramscondition_1[i]].toString();
  403. }
  404. return unique;
  405. };
  406. }
  407. return groupBy(data, condition);
  408. }
  409. var group = (function (data, condition) {
  410. if (!condition) {
  411. // 没有条件,则自身改成数组
  412. return [data];
  413. }
  414. var groups = groupToMap(data, condition);
  415. var array = [];
  416. for (var i in groups) {
  417. array.push(groups[i]);
  418. }
  419. return array;
  420. });
  421. var fixedBase = function (v, base) {
  422. var str = base.toString();
  423. var index = str.indexOf('.');
  424. if (index === -1) {
  425. return Math.round(v);
  426. }
  427. var length = str.substr(index + 1).length;
  428. if (length > 20) {
  429. length = 20;
  430. }
  431. return parseFloat(v.toFixed(length));
  432. };
  433. /**
  434. * 判断是否数字
  435. * @return {Boolean} 是否数字
  436. */
  437. var isNumber = function (value) {
  438. return isType(value, 'Number');
  439. };
  440. var PRECISION = 0.00001; // numbers less than this is considered as 0
  441. function isNumberEqual(a, b, precision) {
  442. if (precision === void 0) { precision = PRECISION; }
  443. return Math.abs((a - b)) < precision;
  444. }
  445. // @ts-ignore
  446. var values = Object.values ? function (obj) { return Object.values(obj); } : function (obj) {
  447. var result = [];
  448. each(obj, function (value, key) {
  449. if (!(isFunction(obj) && key === 'prototype')) {
  450. result.push(value);
  451. }
  452. });
  453. return result;
  454. };
  455. var toString$1 = (function (value) {
  456. if (isNil(value))
  457. return '';
  458. return value.toString();
  459. });
  460. function substitute(str, o) {
  461. if (!str || !o) {
  462. return str;
  463. }
  464. return str.replace(/\\?\{([^{}]+)\}/g, function (match, name) {
  465. if (match.charAt(0) === '\\') {
  466. return match.slice(1);
  467. }
  468. return (o[name] === undefined) ? '' : o[name];
  469. });
  470. }
  471. var upperFirst = function (value) {
  472. var str = toString$1(value);
  473. return str.charAt(0).toUpperCase() + str.substring(1);
  474. };
  475. var toString$2 = {}.toString;
  476. var getType = function (value) {
  477. return toString$2.call(value).replace(/^\[object /, '').replace(/]$/, '');
  478. };
  479. /**
  480. * 是否是布尔类型
  481. *
  482. * @param {Object} value 测试的值
  483. * @return {Boolean}
  484. */
  485. var isBoolean = function (value) {
  486. return isType(value, 'Boolean');
  487. };
  488. var isDate = function (value) {
  489. return isType(value, 'Date');
  490. };
  491. var objectProto = Object.prototype;
  492. var isPrototype = function (value) {
  493. var Ctor = value && value.constructor;
  494. var proto = (typeof Ctor === 'function' && Ctor.prototype) || objectProto;
  495. return value === proto;
  496. };
  497. var isUndefined = function (value) {
  498. return value === undefined;
  499. };
  500. // FIXME: Mutable param should be forbidden in static lang.
  501. function _mix(dist, obj) {
  502. for (var key in obj) {
  503. if (obj.hasOwnProperty(key) && key !== 'constructor' && obj[key] !== undefined) {
  504. dist[key] = obj[key];
  505. }
  506. }
  507. }
  508. function mix(dist, src1, src2, src3) {
  509. if (src1)
  510. _mix(dist, src1);
  511. if (src2)
  512. _mix(dist, src2);
  513. if (src3)
  514. _mix(dist, src3);
  515. return dist;
  516. }
  517. var clone = function (obj) {
  518. if (typeof obj !== 'object' || obj === null) {
  519. return obj;
  520. }
  521. var rst;
  522. if (isArray(obj)) {
  523. rst = [];
  524. for (var i = 0, l = obj.length; i < l; i++) {
  525. if (typeof obj[i] === 'object' && obj[i] != null) {
  526. rst[i] = clone(obj[i]);
  527. }
  528. else {
  529. rst[i] = obj[i];
  530. }
  531. }
  532. }
  533. else {
  534. rst = {};
  535. for (var k in obj) {
  536. if (typeof obj[k] === 'object' && obj[k] != null) {
  537. rst[k] = clone(obj[k]);
  538. }
  539. else {
  540. rst[k] = obj[k];
  541. }
  542. }
  543. }
  544. return rst;
  545. };
  546. /**
  547. * _.memoize(calColor);
  548. * _.memoize(calColor, (...args) => args[0]);
  549. * @param f
  550. * @param resolver
  551. */
  552. var memoize = (function (f, resolver) {
  553. if (!isFunction(f)) {
  554. throw new TypeError('Expected a function');
  555. }
  556. var memoized = function () {
  557. var args = [];
  558. for (var _i = 0; _i < arguments.length; _i++) {
  559. args[_i] = arguments[_i];
  560. }
  561. // 使用方法构造 key,如果不存在 resolver,则直接取第一个参数作为 key
  562. var key = resolver ? resolver.apply(this, args) : args[0];
  563. var cache = memoized.cache;
  564. if (cache.has(key)) {
  565. return cache.get(key);
  566. }
  567. var result = f.apply(this, args);
  568. // 缓存起来
  569. cache.set(key, result);
  570. return result;
  571. };
  572. memoized.cache = new Map();
  573. return memoized;
  574. });
  575. var MAX_MIX_LEVEL = 5;
  576. function _deepMix(dist, src, level, maxLevel) {
  577. level = level || 0;
  578. maxLevel = maxLevel || MAX_MIX_LEVEL;
  579. for (var key in src) {
  580. if (src.hasOwnProperty(key)) {
  581. var value = src[key];
  582. if (value !== null && isPlainObject(value)) {
  583. if (!isPlainObject(dist[key])) {
  584. dist[key] = {};
  585. }
  586. if (level < maxLevel) {
  587. _deepMix(dist[key], value, level + 1, maxLevel);
  588. }
  589. else {
  590. dist[key] = src[key];
  591. }
  592. }
  593. else if (isArray(value)) {
  594. dist[key] = [];
  595. dist[key] = dist[key].concat(value);
  596. }
  597. else if (value !== undefined) {
  598. dist[key] = value;
  599. }
  600. }
  601. }
  602. }
  603. // todo 重写
  604. var deepMix = function (rst) {
  605. var args = [];
  606. for (var _i = 1; _i < arguments.length; _i++) {
  607. args[_i - 1] = arguments[_i];
  608. }
  609. for (var i = 0; i < args.length; i += 1) {
  610. _deepMix(rst, args[i]);
  611. }
  612. return rst;
  613. };
  614. var indexOf = function (arr, obj) {
  615. if (!isArrayLike(arr)) {
  616. return -1;
  617. }
  618. var m = Array.prototype.indexOf;
  619. if (m) {
  620. return m.call(arr, obj);
  621. }
  622. var index = -1;
  623. for (var i = 0; i < arr.length; i++) {
  624. if (arr[i] === obj) {
  625. index = i;
  626. break;
  627. }
  628. }
  629. return index;
  630. };
  631. var hasOwnProperty$1 = Object.prototype.hasOwnProperty;
  632. function isEmpty(value) {
  633. /**
  634. * isEmpty(null) => true
  635. * isEmpty() => true
  636. * isEmpty(true) => true
  637. * isEmpty(1) => true
  638. * isEmpty([1, 2, 3]) => false
  639. * isEmpty('abc') => false
  640. * isEmpty({ a: 1 }) => false
  641. */
  642. if (isNil(value)) {
  643. return true;
  644. }
  645. if (isArrayLike(value)) {
  646. return !value.length;
  647. }
  648. var type = getType(value);
  649. if (type === 'Map' || type === 'Set') {
  650. return !value.size;
  651. }
  652. if (isPrototype(value)) {
  653. return !Object.keys(value).length;
  654. }
  655. for (var key in value) {
  656. if (hasOwnProperty$1.call(value, key)) {
  657. return false;
  658. }
  659. }
  660. return true;
  661. }
  662. var map = function (arr, func) {
  663. if (!isArrayLike(arr)) {
  664. // @ts-ignore
  665. return arr;
  666. }
  667. var result = [];
  668. for (var index = 0; index < arr.length; index++) {
  669. var value = arr[index];
  670. result.push(func(value, index));
  671. }
  672. return result;
  673. };
  674. var identity = function (v) { return v; };
  675. var mapValues = (function (object, func) {
  676. if (func === void 0) { func = identity; }
  677. var r = {};
  678. if (isObject(object) && !isNil(object)) {
  679. Object.keys(object).forEach(function (key) {
  680. // @ts-ignore
  681. r[key] = func(object[key], key);
  682. });
  683. }
  684. return r;
  685. });
  686. /**
  687. * https://github.com/developit/dlv/blob/master/index.js
  688. * @param obj
  689. * @param key
  690. * @param defaultValue
  691. */
  692. var get = (function (obj, key, defaultValue) {
  693. var p = 0;
  694. var keyArr = isString(key) ? key.split('.') : key;
  695. while (obj && p < keyArr.length) {
  696. obj = obj[keyArr[p++]];
  697. }
  698. return (obj === undefined || p < keyArr.length) ? defaultValue : obj;
  699. });
  700. var hasOwnProperty$2 = Object.prototype.hasOwnProperty;
  701. var pick = (function (object, keys) {
  702. if (object === null || !isPlainObject(object)) {
  703. return {};
  704. }
  705. var result = {};
  706. each(keys, function (key) {
  707. if (hasOwnProperty$2.call(object, key)) {
  708. result[key] = object[key];
  709. }
  710. });
  711. return result;
  712. });
  713. var omit = (function (obj, keys) {
  714. return reduce(obj, function (r, curr, key) {
  715. if (!keys.includes(key)) {
  716. r[key] = curr;
  717. }
  718. return r;
  719. }, {});
  720. });
  721. function size(o) {
  722. if (isNil(o)) {
  723. return 0;
  724. }
  725. if (isArrayLike(o)) {
  726. return o.length;
  727. }
  728. return Object.keys(o).length;
  729. }
  730. /******************************************************************************
  731. Copyright (c) Microsoft Corporation.
  732. Permission to use, copy, modify, and/or distribute this software for any
  733. purpose with or without fee is hereby granted.
  734. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
  735. REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  736. AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
  737. INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  738. LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  739. OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  740. PERFORMANCE OF THIS SOFTWARE.
  741. ***************************************************************************** */
  742. /* global Reflect, Promise */
  743. var extendStatics = function(d, b) {
  744. extendStatics = Object.setPrototypeOf ||
  745. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  746. function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
  747. return extendStatics(d, b);
  748. };
  749. function __extends(d, b) {
  750. if (typeof b !== "function" && b !== null)
  751. throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
  752. extendStatics(d, b);
  753. function __() { this.constructor = d; }
  754. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  755. }
  756. var __assign = function() {
  757. __assign = Object.assign || function __assign(t) {
  758. for (var s, i = 1, n = arguments.length; i < n; i++) {
  759. s = arguments[i];
  760. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
  761. }
  762. return t;
  763. };
  764. return __assign.apply(this, arguments);
  765. };
  766. /** @deprecated */
  767. function __spreadArrays() {
  768. for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
  769. for (var r = Array(s), k = 0, i = 0; i < il; i++)
  770. for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
  771. r[k] = a[j];
  772. return r;
  773. }
  774. var ctx;
  775. /**
  776. * 计算文本的宽度
  777. */
  778. memoize(function (text, font) {
  779. if (font === void 0) { font = {}; }
  780. var fontSize = font.fontSize, fontFamily = font.fontFamily, fontWeight = font.fontWeight, fontStyle = font.fontStyle, fontVariant = font.fontVariant;
  781. if (!ctx) {
  782. ctx = document.createElement('canvas').getContext('2d');
  783. }
  784. ctx.font = [fontStyle, fontVariant, fontWeight, fontSize + "px", fontFamily].join(' ');
  785. return ctx.measureText(isString(text) ? text : '').width;
  786. }, function (text, font) {
  787. if (font === void 0) { font = {}; }
  788. return __spreadArrays([text], values(font)).join('');
  789. });
  790. /**
  791. * k-v 存储
  792. */
  793. var default_1 = /** @class */ (function () {
  794. function default_1() {
  795. this.map = {};
  796. }
  797. default_1.prototype.has = function (key) {
  798. return this.map[key] !== undefined;
  799. };
  800. default_1.prototype.get = function (key, def) {
  801. var v = this.map[key];
  802. return v === undefined ? def : v;
  803. };
  804. default_1.prototype.set = function (key, value) {
  805. this.map[key] = value;
  806. };
  807. default_1.prototype.clear = function () {
  808. this.map = {};
  809. };
  810. default_1.prototype.delete = function (key) {
  811. delete this.map[key];
  812. };
  813. default_1.prototype.size = function () {
  814. return Object.keys(this.map).length;
  815. };
  816. return default_1;
  817. }());
  818. function cloneElement(element, props) {
  819. if (!element) return element;
  820. return _objectSpread(_objectSpread({}, element), {}, {
  821. props: _objectSpread(_objectSpread({}, element.props), props)
  822. });
  823. }
  824. function map$1(children, fn) {
  825. if (!children) {
  826. return fn(children);
  827. }
  828. if (isArray(children)) {
  829. return children.map(function (child) {
  830. return map$1(child, fn);
  831. });
  832. }
  833. return fn(children);
  834. }
  835. function compareArray(nextElements, lastElements, callback) {
  836. var keyed = {};
  837. var nextLength = nextElements.length;
  838. var lastLength = lastElements.length;
  839. for (var i = 0, len = lastLength; i < len; i++) {
  840. var element = lastElements[i];
  841. if (element && !isNil(element.key)) {
  842. var key = element.key;
  843. keyed[key] = element;
  844. }
  845. } // 比较元素
  846. for (var _i = 0, _len = Math.max(nextLength, lastLength); _i < _len; _i++) {
  847. var _element = nextElements[_i];
  848. if (!_element) {
  849. compare(_element, lastElements[_i], callback);
  850. continue;
  851. }
  852. var _key = _element.key; // 有key值定义
  853. if (!isNil(_element.key)) {
  854. var lastElement = keyed[_key];
  855. if (lastElement) delete keyed[_key];
  856. compare(_element, lastElement, callback);
  857. continue;
  858. }
  859. compare(_element, lastElements[_i], callback);
  860. } // 说明是删除的元素
  861. Object.keys(keyed).forEach(function (key) {
  862. compare(null, keyed[key], callback);
  863. });
  864. } // 比较2棵树
  865. function compare(nextElement, lastElement, callback) {
  866. // 有一个为空
  867. if (!nextElement || !lastElement) {
  868. callback(nextElement, lastElement);
  869. return;
  870. }
  871. if (isArray(nextElement) || isArray(lastElement)) {
  872. var nextElementArray = isArray(nextElement) ? nextElement : [nextElement];
  873. var lastElementArray = isArray(lastElement) ? lastElement : [lastElement];
  874. compareArray(nextElementArray, lastElementArray, callback);
  875. return;
  876. }
  877. callback(nextElement, lastElement);
  878. }
  879. function toArray(element) {
  880. if (!element) {
  881. return element;
  882. }
  883. if (!isArray(element)) {
  884. return [element];
  885. }
  886. var newArray = [];
  887. for (var i = 0, len = element.length; i < len; i++) {
  888. var item = element[i];
  889. if (isArray(item)) {
  890. // @ts-ignore
  891. newArray = newArray.concat(toArray(item));
  892. } else {
  893. newArray.push(item);
  894. }
  895. }
  896. return newArray;
  897. }
  898. var Children = {
  899. cloneElement: cloneElement,
  900. map: map$1,
  901. toArray: toArray,
  902. compare: compare
  903. };
  904. var classCallCheck = createCommonjsModule(function (module) {
  905. function _classCallCheck(instance, Constructor) {
  906. if (!(instance instanceof Constructor)) {
  907. throw new TypeError("Cannot call a class as a function");
  908. }
  909. }
  910. module.exports = _classCallCheck, module.exports.__esModule = true, module.exports["default"] = module.exports;
  911. });
  912. var _classCallCheck = /*@__PURE__*/getDefaultExportFromCjs(classCallCheck);
  913. var createClass = createCommonjsModule(function (module) {
  914. function _defineProperties(target, props) {
  915. for (var i = 0; i < props.length; i++) {
  916. var descriptor = props[i];
  917. descriptor.enumerable = descriptor.enumerable || false;
  918. descriptor.configurable = true;
  919. if ("value" in descriptor) descriptor.writable = true;
  920. Object.defineProperty(target, descriptor.key, descriptor);
  921. }
  922. }
  923. function _createClass(Constructor, protoProps, staticProps) {
  924. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  925. if (staticProps) _defineProperties(Constructor, staticProps);
  926. Object.defineProperty(Constructor, "prototype", {
  927. writable: false
  928. });
  929. return Constructor;
  930. }
  931. module.exports = _createClass, module.exports.__esModule = true, module.exports["default"] = module.exports;
  932. });
  933. var _createClass = /*@__PURE__*/getDefaultExportFromCjs(createClass);
  934. var Component = /*#__PURE__*/function () {
  935. function Component(props, context, updater) {
  936. _classCallCheck(this, Component);
  937. this.destroyed = false;
  938. this.props = props;
  939. this.state = {};
  940. this.context = context;
  941. this.updater = updater;
  942. }
  943. _createClass(Component, [{
  944. key: "willMount",
  945. value: function willMount() {}
  946. }, {
  947. key: "didMount",
  948. value: function didMount() {}
  949. }, {
  950. key: "willReceiveProps",
  951. value: function willReceiveProps(_props, context) {}
  952. }, {
  953. key: "willUpdate",
  954. value: function willUpdate() {}
  955. }, {
  956. key: "didUpdate",
  957. value: function didUpdate() {}
  958. }, {
  959. key: "render",
  960. value: function render() {
  961. return null;
  962. }
  963. }, {
  964. key: "didUnmount",
  965. value: function didUnmount() {}
  966. }, {
  967. key: "setState",
  968. value: function setState(partialState, callback) {
  969. this.updater.enqueueSetState(this, partialState, callback);
  970. }
  971. }, {
  972. key: "forceUpdate",
  973. value: function forceUpdate(callback) {
  974. this.updater.enqueueForceUpdate(this, {}, callback);
  975. }
  976. }, {
  977. key: "setAnimate",
  978. value: function setAnimate(animate) {
  979. this.animate = animate;
  980. }
  981. }, {
  982. key: "destroy",
  983. value: function destroy() {
  984. this.destroyed = true;
  985. }
  986. }]);
  987. return Component;
  988. }(); // 标识是否是组件
  989. // @ts-ignore
  990. Component.prototype.isF2Component = true;
  991. var assertThisInitialized = createCommonjsModule(function (module) {
  992. function _assertThisInitialized(self) {
  993. if (self === void 0) {
  994. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  995. }
  996. return self;
  997. }
  998. module.exports = _assertThisInitialized, module.exports.__esModule = true, module.exports["default"] = module.exports;
  999. });
  1000. var _assertThisInitialized = /*@__PURE__*/getDefaultExportFromCjs(assertThisInitialized);
  1001. var setPrototypeOf = createCommonjsModule(function (module) {
  1002. function _setPrototypeOf(o, p) {
  1003. module.exports = _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
  1004. o.__proto__ = p;
  1005. return o;
  1006. }, module.exports.__esModule = true, module.exports["default"] = module.exports;
  1007. return _setPrototypeOf(o, p);
  1008. }
  1009. module.exports = _setPrototypeOf, module.exports.__esModule = true, module.exports["default"] = module.exports;
  1010. });
  1011. var inherits = createCommonjsModule(function (module) {
  1012. function _inherits(subClass, superClass) {
  1013. if (typeof superClass !== "function" && superClass !== null) {
  1014. throw new TypeError("Super expression must either be null or a function");
  1015. }
  1016. subClass.prototype = Object.create(superClass && superClass.prototype, {
  1017. constructor: {
  1018. value: subClass,
  1019. writable: true,
  1020. configurable: true
  1021. }
  1022. });
  1023. Object.defineProperty(subClass, "prototype", {
  1024. writable: false
  1025. });
  1026. if (superClass) setPrototypeOf(subClass, superClass);
  1027. }
  1028. module.exports = _inherits, module.exports.__esModule = true, module.exports["default"] = module.exports;
  1029. });
  1030. var _inherits = /*@__PURE__*/getDefaultExportFromCjs(inherits);
  1031. var getPrototypeOf = createCommonjsModule(function (module) {
  1032. function _getPrototypeOf(o) {
  1033. module.exports = _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) {
  1034. return o.__proto__ || Object.getPrototypeOf(o);
  1035. }, module.exports.__esModule = true, module.exports["default"] = module.exports;
  1036. return _getPrototypeOf(o);
  1037. }
  1038. module.exports = _getPrototypeOf, module.exports.__esModule = true, module.exports["default"] = module.exports;
  1039. });
  1040. var _getPrototypeOf = /*@__PURE__*/getDefaultExportFromCjs(getPrototypeOf);
  1041. var isNativeReflectConstruct = createCommonjsModule(function (module) {
  1042. function _isNativeReflectConstruct() {
  1043. if (typeof Reflect === "undefined" || !Reflect.construct) return false;
  1044. if (Reflect.construct.sham) return false;
  1045. if (typeof Proxy === "function") return true;
  1046. try {
  1047. Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
  1048. return true;
  1049. } catch (e) {
  1050. return false;
  1051. }
  1052. }
  1053. module.exports = _isNativeReflectConstruct, module.exports.__esModule = true, module.exports["default"] = module.exports;
  1054. });
  1055. var _typeof_1 = createCommonjsModule(function (module) {
  1056. function _typeof(obj) {
  1057. "@babel/helpers - typeof";
  1058. return (module.exports = _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
  1059. return typeof obj;
  1060. } : function (obj) {
  1061. return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  1062. }, module.exports.__esModule = true, module.exports["default"] = module.exports), _typeof(obj);
  1063. }
  1064. module.exports = _typeof, module.exports.__esModule = true, module.exports["default"] = module.exports;
  1065. });
  1066. var _typeof = /*@__PURE__*/getDefaultExportFromCjs(_typeof_1);
  1067. var possibleConstructorReturn = createCommonjsModule(function (module) {
  1068. var _typeof = _typeof_1["default"];
  1069. function _possibleConstructorReturn(self, call) {
  1070. if (call && (_typeof(call) === "object" || typeof call === "function")) {
  1071. return call;
  1072. } else if (call !== void 0) {
  1073. throw new TypeError("Derived constructors may only return object or undefined");
  1074. }
  1075. return assertThisInitialized(self);
  1076. }
  1077. module.exports = _possibleConstructorReturn, module.exports.__esModule = true, module.exports["default"] = module.exports;
  1078. });
  1079. var _possibleConstructorReturn = /*@__PURE__*/getDefaultExportFromCjs(possibleConstructorReturn);
  1080. var createSuper = createCommonjsModule(function (module) {
  1081. function _createSuper(Derived) {
  1082. var hasNativeReflectConstruct = isNativeReflectConstruct();
  1083. return function _createSuperInternal() {
  1084. var Super = getPrototypeOf(Derived),
  1085. result;
  1086. if (hasNativeReflectConstruct) {
  1087. var NewTarget = getPrototypeOf(this).constructor;
  1088. result = Reflect.construct(Super, arguments, NewTarget);
  1089. } else {
  1090. result = Super.apply(this, arguments);
  1091. }
  1092. return possibleConstructorReturn(this, result);
  1093. };
  1094. }
  1095. module.exports = _createSuper, module.exports.__esModule = true, module.exports["default"] = module.exports;
  1096. });
  1097. var _createSuper = /*@__PURE__*/getDefaultExportFromCjs(createSuper);
  1098. var Timeline = /*#__PURE__*/function (_Component) {
  1099. _inherits(Timeline, _Component);
  1100. var _super = _createSuper(Timeline);
  1101. function Timeline(props) {
  1102. var _this;
  1103. _classCallCheck(this, Timeline);
  1104. _this = _super.call(this, props);
  1105. _this.next = function () {
  1106. var _assertThisInitialize = _assertThisInitialized(_this),
  1107. state = _assertThisInitialize.state,
  1108. props = _assertThisInitialize.props;
  1109. var index = state.index,
  1110. count = state.count,
  1111. delay = state.delay;
  1112. var loop = props.loop;
  1113. var next = loop ? (index + 1) % count : index + 1;
  1114. if (next < count) {
  1115. setTimeout(function () {
  1116. _this.setState({
  1117. index: next
  1118. });
  1119. }, delay || 0);
  1120. }
  1121. };
  1122. var delay = props.delay,
  1123. _props$start = props.start,
  1124. start = _props$start === void 0 ? 0 : _props$start,
  1125. children = props.children;
  1126. var count = Children.toArray(children).length;
  1127. _this.state = {
  1128. delay: delay,
  1129. count: count,
  1130. index: start
  1131. };
  1132. return _this;
  1133. }
  1134. _createClass(Timeline, [{
  1135. key: "didMount",
  1136. value: function didMount() {
  1137. var context = this.context;
  1138. var root = context.root;
  1139. root.on('animationEnd', this.next);
  1140. }
  1141. }, {
  1142. key: "didUnmount",
  1143. value: function didUnmount() {
  1144. var context = this.context;
  1145. var root = context.root;
  1146. root.off('animationEnd', this.next);
  1147. }
  1148. }, {
  1149. key: "render",
  1150. value: function render() {
  1151. var state = this.state,
  1152. props = this.props;
  1153. var children = props.children;
  1154. var index = state.index;
  1155. var childrenArray = Children.toArray(children);
  1156. return childrenArray[index];
  1157. }
  1158. }]);
  1159. return Timeline;
  1160. }(Component);
  1161. var Matrix = {
  1162. generateDefault: function generateDefault() {
  1163. return [1, 0, 0, 1, 0, 0];
  1164. },
  1165. isChanged: function isChanged(m) {
  1166. return m[0] !== 1 || m[1] !== 0 || m[2] !== 0 || m[3] !== 1 || m[4] !== 0 || m[5] !== 0;
  1167. },
  1168. multiply: function multiply(m1, m2) {
  1169. var m11 = m1[0] * m2[0] + m1[2] * m2[1];
  1170. var m12 = m1[1] * m2[0] + m1[3] * m2[1];
  1171. var m21 = m1[0] * m2[2] + m1[2] * m2[3];
  1172. var m22 = m1[1] * m2[2] + m1[3] * m2[3];
  1173. var dx = m1[0] * m2[4] + m1[2] * m2[5] + m1[4];
  1174. var dy = m1[1] * m2[4] + m1[3] * m2[5] + m1[5];
  1175. return [m11, m12, m21, m22, dx, dy];
  1176. },
  1177. scale: function scale(out, m, v) {
  1178. out[0] = m[0] * v[0];
  1179. out[1] = m[1] * v[0];
  1180. out[2] = m[2] * v[1];
  1181. out[3] = m[3] * v[1];
  1182. out[4] = m[4];
  1183. out[5] = m[5];
  1184. return out;
  1185. },
  1186. rotate: function rotate(out, m, radian) {
  1187. var c = Math.cos(radian);
  1188. var s = Math.sin(radian);
  1189. var m11 = m[0] * c + m[2] * s;
  1190. var m12 = m[1] * c + m[3] * s;
  1191. var m21 = m[0] * -s + m[2] * c;
  1192. var m22 = m[1] * -s + m[3] * c;
  1193. out[0] = m11;
  1194. out[1] = m12;
  1195. out[2] = m21;
  1196. out[3] = m22;
  1197. out[4] = m[4];
  1198. out[5] = m[5];
  1199. return out;
  1200. },
  1201. translate: function translate(out, m, v) {
  1202. out[0] = m[0];
  1203. out[1] = m[1];
  1204. out[2] = m[2];
  1205. out[3] = m[3];
  1206. out[4] = m[4] + m[0] * v[0] + m[2] * v[1];
  1207. out[5] = m[5] + m[1] * v[0] + m[3] * v[1];
  1208. return out;
  1209. },
  1210. transform: function transform(m, actions) {
  1211. var out = [].concat(m);
  1212. for (var i = 0, len = actions.length; i < len; i++) {
  1213. var action = actions[i];
  1214. switch (action[0]) {
  1215. case 't':
  1216. Matrix.translate(out, out, [action[1], action[2]]);
  1217. break;
  1218. case 's':
  1219. Matrix.scale(out, out, [action[1], action[2]]);
  1220. break;
  1221. case 'r':
  1222. Matrix.rotate(out, out, action[1]);
  1223. break;
  1224. }
  1225. }
  1226. return out;
  1227. }
  1228. };
  1229. /**
  1230. * 2 Dimensional Vector
  1231. * @module vector2
  1232. */
  1233. var Vector2 = {
  1234. /**
  1235. * Creates a new, empty vector2
  1236. *
  1237. * @return {vector2} a new 2D vector
  1238. */
  1239. create: function create() {
  1240. return [0, 0];
  1241. },
  1242. /**
  1243. * Calculates the length of a vector2
  1244. *
  1245. * @param {vector2} v vector to calculate length of
  1246. * @return {Number} length of v
  1247. */
  1248. length: function length(v) {
  1249. var x = v[0];
  1250. var y = v[1];
  1251. return Math.sqrt(x * x + y * y);
  1252. },
  1253. /**
  1254. * Normalize a vector2
  1255. *
  1256. * @param {vector2} out the receiving vector
  1257. * @param {vector2} v vector to normalize
  1258. * @return {vector2} out
  1259. */
  1260. normalize: function normalize(out, v) {
  1261. var len = this.length(v);
  1262. if (len === 0) {
  1263. out[0] = 0;
  1264. out[1] = 0;
  1265. } else {
  1266. out[0] = v[0] / len;
  1267. out[1] = v[1] / len;
  1268. }
  1269. return out;
  1270. },
  1271. /**
  1272. * Adds two vector2's
  1273. *
  1274. * @param {vector2} out the receiving vector
  1275. * @param {vector2} v1 the first operand
  1276. * @param {vector2} v2 the second operand
  1277. * @return {vector2} out
  1278. */
  1279. add: function add(out, v1, v2) {
  1280. out[0] = v1[0] + v2[0];
  1281. out[1] = v1[1] + v2[1];
  1282. return out;
  1283. },
  1284. /**
  1285. * Subtracts vector v2 from vector v1
  1286. *
  1287. * @param {vector2} out the receiving vector
  1288. * @param {vector2} v1 the first operand
  1289. * @param {vector2} v2 the second operand
  1290. * @return {vector2} out
  1291. */
  1292. sub: function sub(out, v1, v2) {
  1293. out[0] = v1[0] - v2[0];
  1294. out[1] = v1[1] - v2[1];
  1295. return out;
  1296. },
  1297. /**
  1298. * Scales a vector2 by a scalar number
  1299. *
  1300. * @param {vector2} out the receiving vector
  1301. * @param {vector2} v the vector to scale
  1302. * @param {Number} s amount to scale the vector by
  1303. * @return {vector2} out
  1304. */
  1305. scale: function scale(out, v, s) {
  1306. out[0] = v[0] * s;
  1307. out[1] = v[1] * s;
  1308. return out;
  1309. },
  1310. /**
  1311. * Calculates the dot product of two vector2's
  1312. *
  1313. * @param {vector2} v1 the first operand
  1314. * @param {vector2} v2 the second operand
  1315. * @return {Number} dot product of v1 and v2
  1316. */
  1317. dot: function dot(v1, v2) {
  1318. return v1[0] * v2[0] + v1[1] * v2[1];
  1319. },
  1320. /**
  1321. * Calculates the direction of two vector2's
  1322. *
  1323. * @param {vector2} v1 the first operand
  1324. * @param {vector2} v2 the second operand
  1325. * @return {Boolean} the direction of v1 and v2
  1326. */
  1327. direction: function direction(v1, v2) {
  1328. return v1[0] * v2[1] - v2[0] * v1[1];
  1329. },
  1330. /**
  1331. * Calculates the angle of two vector2's
  1332. *
  1333. * @param {vector2} v1 the first operand
  1334. * @param {vector2} v2 the second operand
  1335. * @return {Number} angle of v1 and v2
  1336. */
  1337. angle: function angle(v1, v2) {
  1338. var theta = this.dot(v1, v2) / (this.length(v1) * this.length(v2));
  1339. return Math.acos(theta);
  1340. },
  1341. /**
  1342. * Calculates the angle of two vector2's with direction
  1343. *
  1344. * @param {vector2} v1 the first operand
  1345. * @param {vector2} v2 the second operand
  1346. * @param {Boolean} direction the direction of two vector2's
  1347. * @return {Number} angle of v1 and v2
  1348. */
  1349. angleTo: function angleTo(v1, v2, direction) {
  1350. var angle = this.angle(v1, v2);
  1351. var angleLargeThanPI = this.direction(v1, v2) >= 0;
  1352. if (direction) {
  1353. if (angleLargeThanPI) {
  1354. return Math.PI * 2 - angle;
  1355. }
  1356. return angle;
  1357. }
  1358. if (angleLargeThanPI) {
  1359. return angle;
  1360. }
  1361. return Math.PI * 2 - angle;
  1362. },
  1363. /**
  1364. * whether a vector2 is zero vector
  1365. *
  1366. * @param {vector2} v vector to calculate
  1367. * @return {Boolean} is or not a zero vector
  1368. */
  1369. zero: function zero(v) {
  1370. return v[0] === 0 && v[1] === 0;
  1371. },
  1372. /**
  1373. * Calculates the euclidian distance between two vector2's
  1374. *
  1375. * @param {vector2} v1 the first operand
  1376. * @param {vector2} v2 the second operand
  1377. * @return {Number} distance between a and b
  1378. */
  1379. distance: function distance(v1, v2) {
  1380. var x = v2[0] - v1[0];
  1381. var y = v2[1] - v1[1];
  1382. return Math.sqrt(x * x + y * y);
  1383. },
  1384. /**
  1385. * Creates a new vector2 initialized with values from an existing vector
  1386. *
  1387. * @param {vector2} v vector to clone
  1388. * @return {Array} a new 2D vector
  1389. */
  1390. clone: function clone(v) {
  1391. return [v[0], v[1]];
  1392. },
  1393. /**
  1394. * Return the minimum of two vector2's
  1395. *
  1396. * @param {vector2} out the receiving vector
  1397. * @param {vector2} v1 the first operand
  1398. * @param {vector2} v2 the second operand
  1399. * @return {vector2} out
  1400. */
  1401. min: function min(out, v1, v2) {
  1402. out[0] = Math.min(v1[0], v2[0]);
  1403. out[1] = Math.min(v1[1], v2[1]);
  1404. return out;
  1405. },
  1406. /**
  1407. * Return the maximum of two vector2's
  1408. *
  1409. * @param {vector2} out the receiving vector
  1410. * @param {vector2} v1 the first operand
  1411. * @param {vector2} v2 the second operand
  1412. * @return {vector2} out
  1413. */
  1414. max: function max(out, v1, v2) {
  1415. out[0] = Math.max(v1[0], v2[0]);
  1416. out[1] = Math.max(v1[1], v2[1]);
  1417. return out;
  1418. },
  1419. /**
  1420. * Transforms the vector2 with a mat2d
  1421. *
  1422. * @param {vector2} out the receiving vector
  1423. * @param {vector2} v the vector to transform
  1424. * @param {mat2d} m matrix to transform with
  1425. * @return {vector2} out
  1426. */
  1427. transformMat2d: function transformMat2d(out, v, m) {
  1428. var x = v[0];
  1429. var y = v[1];
  1430. out[0] = m[0] * x + m[2] * y + m[4];
  1431. out[1] = m[1] * x + m[3] * y + m[5];
  1432. return out;
  1433. }
  1434. };
  1435. /**
  1436. * @fileOverview convert the line to curve
  1437. * @author dxq613@gmail.com
  1438. */
  1439. function getPoint(v) {
  1440. return [v.x, v.y];
  1441. }
  1442. function smoothBezier(points, smooth, isLoop, constraint) {
  1443. var cps = [];
  1444. var prevPoint;
  1445. var nextPoint;
  1446. var hasConstraint = !!constraint;
  1447. var min;
  1448. var max;
  1449. var point;
  1450. var len;
  1451. var l;
  1452. var i;
  1453. if (hasConstraint) {
  1454. min = [Infinity, Infinity];
  1455. max = [-Infinity, -Infinity];
  1456. for (i = 0, l = points.length; i < l; i++) {
  1457. point = getPoint(points[i]);
  1458. Vector2.min(min, min, point);
  1459. Vector2.max(max, max, point);
  1460. }
  1461. Vector2.min(min, min, constraint[0]);
  1462. Vector2.max(max, max, constraint[1]);
  1463. }
  1464. for (i = 0, len = points.length; i < len; i++) {
  1465. point = getPoint(points[i]);
  1466. if (isLoop) {
  1467. prevPoint = getPoint(points[i ? i - 1 : len - 1]);
  1468. nextPoint = getPoint(points[(i + 1) % len]);
  1469. } else {
  1470. if (i === 0 || i === len - 1) {
  1471. cps.push([point[0], point[1]]);
  1472. continue;
  1473. } else {
  1474. prevPoint = getPoint(points[i - 1]);
  1475. nextPoint = getPoint(points[i + 1]);
  1476. }
  1477. }
  1478. var v = Vector2.sub([], nextPoint, prevPoint);
  1479. Vector2.scale(v, v, smooth);
  1480. var d0 = Vector2.distance(point, prevPoint);
  1481. var d1 = Vector2.distance(point, nextPoint);
  1482. var sum = d0 + d1;
  1483. if (sum !== 0) {
  1484. d0 /= sum;
  1485. d1 /= sum;
  1486. }
  1487. var v1 = Vector2.scale([], v, -d0);
  1488. var v2 = Vector2.scale([], v, d1);
  1489. var cp0 = Vector2.add([], point, v1);
  1490. var cp1 = Vector2.add([], point, v2);
  1491. if (hasConstraint) {
  1492. Vector2.max(cp0, cp0, min);
  1493. Vector2.min(cp0, cp0, max);
  1494. Vector2.max(cp1, cp1, min);
  1495. Vector2.min(cp1, cp1, max);
  1496. }
  1497. cps.push([cp0[0], cp0[1]]);
  1498. cps.push([cp1[0], cp1[1]]);
  1499. }
  1500. if (isLoop) {
  1501. cps.push(cps.shift());
  1502. }
  1503. return cps;
  1504. }
  1505. function catmullRom2bezier(pointList, z, constraint) {
  1506. var isLoop = !!z;
  1507. var controlPointList = smoothBezier(pointList, 0.4, isLoop, constraint);
  1508. var len = pointList.length;
  1509. var d1 = [];
  1510. var cp1;
  1511. var cp2;
  1512. var p;
  1513. for (var i = 0; i < len - 1; i++) {
  1514. cp1 = controlPointList[i * 2];
  1515. cp2 = controlPointList[i * 2 + 1];
  1516. p = pointList[i + 1];
  1517. d1.push(['C', cp1[0], cp1[1], cp2[0], cp2[1], p.x, p.y]);
  1518. }
  1519. if (isLoop) {
  1520. cp1 = controlPointList[len];
  1521. cp2 = controlPointList[len + 1];
  1522. p = pointList[0];
  1523. d1.push(['C', cp1[0], cp1[1], cp2[0], cp2[1], p.x, p.y]);
  1524. }
  1525. return d1;
  1526. }
  1527. var start = Vector2.create();
  1528. var end = Vector2.create();
  1529. var extremity = Vector2.create();
  1530. function getCubicBezierXYatT(startPt, controlPt1, controlPt2, endPt, T) {
  1531. var x = CubicN(T, startPt.x, controlPt1.x, controlPt2.x, endPt.x);
  1532. var y = CubicN(T, startPt.y, controlPt1.y, controlPt2.y, endPt.y);
  1533. return {
  1534. x: x,
  1535. y: y
  1536. };
  1537. } // cubic helper formula at T distance
  1538. function CubicN(T, a, b, c, d) {
  1539. var t2 = T * T;
  1540. var t3 = t2 * T;
  1541. 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;
  1542. }
  1543. function cubicBezierBounds(c) {
  1544. var minX = Infinity;
  1545. var maxX = -Infinity;
  1546. var minY = Infinity;
  1547. var maxY = -Infinity;
  1548. var s = {
  1549. x: c[0],
  1550. y: c[1]
  1551. };
  1552. var c1 = {
  1553. x: c[2],
  1554. y: c[3]
  1555. };
  1556. var c2 = {
  1557. x: c[4],
  1558. y: c[5]
  1559. };
  1560. var e = {
  1561. x: c[6],
  1562. y: c[7]
  1563. };
  1564. for (var t = 0; t < 100; t++) {
  1565. var pt = getCubicBezierXYatT(s, c1, c2, e, t / 100);
  1566. if (pt.x < minX) {
  1567. minX = pt.x;
  1568. }
  1569. if (pt.x > maxX) {
  1570. maxX = pt.x;
  1571. }
  1572. if (pt.y < minY) {
  1573. minY = pt.y;
  1574. }
  1575. if (pt.y > maxY) {
  1576. maxY = pt.y;
  1577. }
  1578. }
  1579. return {
  1580. minX: minX,
  1581. minY: minY,
  1582. maxX: maxX,
  1583. maxY: maxY
  1584. };
  1585. }
  1586. function getBBoxFromPoints(points, lineWidth) {
  1587. if (points.length === 0) {
  1588. return;
  1589. }
  1590. var p = points[0];
  1591. var left = p.x;
  1592. var right = p.x;
  1593. var top = p.y;
  1594. var bottom = p.y;
  1595. var len = points.length;
  1596. for (var i = 1; i < len; i++) {
  1597. p = points[i];
  1598. left = Math.min(left, p.x);
  1599. right = Math.max(right, p.x);
  1600. top = Math.min(top, p.y);
  1601. bottom = Math.max(bottom, p.y);
  1602. }
  1603. lineWidth = lineWidth / 2 || 0;
  1604. return {
  1605. minX: left - lineWidth,
  1606. minY: top - lineWidth,
  1607. maxX: right + lineWidth,
  1608. maxY: bottom + lineWidth
  1609. };
  1610. }
  1611. function getBBoxFromLine(x0, y0, x1, y1, lineWidth) {
  1612. lineWidth = lineWidth / 2 || 0;
  1613. return {
  1614. minX: Math.min(x0, x1) - lineWidth,
  1615. minY: Math.min(y0, y1) - lineWidth,
  1616. maxX: Math.max(x0, x1) + lineWidth,
  1617. maxY: Math.max(y0, y1) + lineWidth
  1618. };
  1619. }
  1620. function getBBoxFromArc(x, y, r, startAngle, endAngle, anticlockwise) {
  1621. var diff = Math.abs(startAngle - endAngle);
  1622. if (diff % (Math.PI * 2) < 1e-4 && diff > 1e-4) {
  1623. // Is a circle
  1624. return {
  1625. minX: x - r,
  1626. minY: y - r,
  1627. maxX: x + r,
  1628. maxY: y + r
  1629. };
  1630. }
  1631. start[0] = Math.cos(startAngle) * r + x;
  1632. start[1] = Math.sin(startAngle) * r + y;
  1633. end[0] = Math.cos(endAngle) * r + x;
  1634. end[1] = Math.sin(endAngle) * r + y;
  1635. var min = [0, 0];
  1636. var max = [0, 0];
  1637. Vector2.min(min, start, end);
  1638. Vector2.max(max, start, end); // Thresh to [0, Math.PI * 2]
  1639. startAngle = startAngle % (Math.PI * 2);
  1640. if (startAngle < 0) {
  1641. startAngle = startAngle + Math.PI * 2;
  1642. }
  1643. endAngle = endAngle % (Math.PI * 2);
  1644. if (endAngle < 0) {
  1645. endAngle = endAngle + Math.PI * 2;
  1646. }
  1647. if (startAngle > endAngle && !anticlockwise) {
  1648. endAngle += Math.PI * 2;
  1649. } else if (startAngle < endAngle && anticlockwise) {
  1650. startAngle += Math.PI * 2;
  1651. }
  1652. if (anticlockwise) {
  1653. var tmp = endAngle;
  1654. endAngle = startAngle;
  1655. startAngle = tmp;
  1656. }
  1657. for (var angle = 0; angle < endAngle; angle += Math.PI / 2) {
  1658. if (angle > startAngle) {
  1659. extremity[0] = Math.cos(angle) * r + x;
  1660. extremity[1] = Math.sin(angle) * r + y;
  1661. Vector2.min(min, extremity, min);
  1662. Vector2.max(max, extremity, max);
  1663. }
  1664. }
  1665. return {
  1666. minX: min[0],
  1667. minY: min[1],
  1668. maxX: max[0],
  1669. maxY: max[1]
  1670. };
  1671. }
  1672. function getBBoxFromBezierGroup(points, lineWidth) {
  1673. var minX = Infinity;
  1674. var maxX = -Infinity;
  1675. var minY = Infinity;
  1676. var maxY = -Infinity;
  1677. for (var i = 0, len = points.length; i < len; i++) {
  1678. var bbox = cubicBezierBounds(points[i]);
  1679. if (bbox.minX < minX) {
  1680. minX = bbox.minX;
  1681. }
  1682. if (bbox.maxX > maxX) {
  1683. maxX = bbox.maxX;
  1684. }
  1685. if (bbox.minY < minY) {
  1686. minY = bbox.minY;
  1687. }
  1688. if (bbox.maxY > maxY) {
  1689. maxY = bbox.maxY;
  1690. }
  1691. }
  1692. lineWidth = lineWidth / 2 || 0;
  1693. return {
  1694. minX: minX - lineWidth,
  1695. minY: minY - lineWidth,
  1696. maxX: maxX + lineWidth,
  1697. maxY: maxY + lineWidth
  1698. };
  1699. }
  1700. function _classCallCheck$1(instance, Constructor) {
  1701. if (!(instance instanceof Constructor)) {
  1702. throw new TypeError("Cannot call a class as a function");
  1703. }
  1704. }
  1705. function _defineProperties(target, props) {
  1706. for (var i = 0; i < props.length; i++) {
  1707. var descriptor = props[i];
  1708. descriptor.enumerable = descriptor.enumerable || false;
  1709. descriptor.configurable = true;
  1710. if ("value" in descriptor) descriptor.writable = true;
  1711. Object.defineProperty(target, descriptor.key, descriptor);
  1712. }
  1713. }
  1714. function _createClass$1(Constructor, protoProps, staticProps) {
  1715. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  1716. if (staticProps) _defineProperties(Constructor, staticProps);
  1717. Object.defineProperty(Constructor, "prototype", {
  1718. writable: false
  1719. });
  1720. return Constructor;
  1721. }
  1722. function _setPrototypeOf(o, p) {
  1723. _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
  1724. o.__proto__ = p;
  1725. return o;
  1726. };
  1727. return _setPrototypeOf(o, p);
  1728. }
  1729. function _inherits$1(subClass, superClass) {
  1730. if (typeof superClass !== "function" && superClass !== null) {
  1731. throw new TypeError("Super expression must either be null or a function");
  1732. }
  1733. subClass.prototype = Object.create(superClass && superClass.prototype, {
  1734. constructor: {
  1735. value: subClass,
  1736. writable: true,
  1737. configurable: true
  1738. }
  1739. });
  1740. Object.defineProperty(subClass, "prototype", {
  1741. writable: false
  1742. });
  1743. if (superClass) _setPrototypeOf(subClass, superClass);
  1744. }
  1745. function _getPrototypeOf$1(o) {
  1746. _getPrototypeOf$1 = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) {
  1747. return o.__proto__ || Object.getPrototypeOf(o);
  1748. };
  1749. return _getPrototypeOf$1(o);
  1750. }
  1751. function _isNativeReflectConstruct() {
  1752. if (typeof Reflect === "undefined" || !Reflect.construct) return false;
  1753. if (Reflect.construct.sham) return false;
  1754. if (typeof Proxy === "function") return true;
  1755. try {
  1756. Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
  1757. return true;
  1758. } catch (e) {
  1759. return false;
  1760. }
  1761. }
  1762. function _typeof$1(obj) {
  1763. "@babel/helpers - typeof";
  1764. return _typeof$1 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
  1765. return typeof obj;
  1766. } : function (obj) {
  1767. return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  1768. }, _typeof$1(obj);
  1769. }
  1770. function _assertThisInitialized$1(self) {
  1771. if (self === void 0) {
  1772. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  1773. }
  1774. return self;
  1775. }
  1776. function _possibleConstructorReturn$1(self, call) {
  1777. if (call && (_typeof$1(call) === "object" || typeof call === "function")) {
  1778. return call;
  1779. } else if (call !== void 0) {
  1780. throw new TypeError("Derived constructors may only return object or undefined");
  1781. }
  1782. return _assertThisInitialized$1(self);
  1783. }
  1784. function _createSuper$1(Derived) {
  1785. var hasNativeReflectConstruct = _isNativeReflectConstruct();
  1786. return function _createSuperInternal() {
  1787. var Super = _getPrototypeOf$1(Derived),
  1788. result;
  1789. if (hasNativeReflectConstruct) {
  1790. var NewTarget = _getPrototypeOf$1(this).constructor;
  1791. result = Reflect.construct(Super, arguments, NewTarget);
  1792. } else {
  1793. result = Super.apply(this, arguments);
  1794. }
  1795. return _possibleConstructorReturn$1(this, result);
  1796. };
  1797. }
  1798. var EventEmit = /*#__PURE__*/function () {
  1799. function EventEmit() {
  1800. _classCallCheck$1(this, EventEmit);
  1801. this.__events = {};
  1802. }
  1803. _createClass$1(EventEmit, [{
  1804. key: "on",
  1805. value: function on(type, listener) {
  1806. if (!type || !listener) {
  1807. return;
  1808. }
  1809. var events = this.__events[type] || [];
  1810. events.push(listener);
  1811. this.__events[type] = events;
  1812. }
  1813. }, {
  1814. key: "emit",
  1815. value: function emit(type, e) {
  1816. var _this = this;
  1817. if (isObject(type)) {
  1818. e = type;
  1819. type = e && e.type;
  1820. }
  1821. if (!type) {
  1822. return;
  1823. }
  1824. var events = this.__events[type];
  1825. if (!events || !events.length) {
  1826. return;
  1827. }
  1828. events.forEach(function (listener) {
  1829. listener.call(_this, e);
  1830. });
  1831. }
  1832. }, {
  1833. key: "off",
  1834. value: function off(type, listener) {
  1835. var __events = this.__events;
  1836. var events = __events[type];
  1837. if (!events || !events.length) {
  1838. return;
  1839. } // 如果没有指定方法,则删除所有项
  1840. if (!listener) {
  1841. delete __events[type];
  1842. return;
  1843. } // 删除指定的 listener
  1844. for (var i = 0, len = events.length; i < len; i++) {
  1845. if (events[i] === listener) {
  1846. events.splice(i, 1);
  1847. i--;
  1848. }
  1849. }
  1850. }
  1851. }]);
  1852. return EventEmit;
  1853. }();
  1854. /**
  1855. * Detects support for options object argument in addEventListener.
  1856. * https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#Safely_detecting_option_support
  1857. * @private
  1858. */
  1859. var supportsEventListenerOptions = function () {
  1860. var supports = false;
  1861. try {
  1862. var options = Object.defineProperty({}, 'passive', {
  1863. get: function get() {
  1864. supports = true;
  1865. }
  1866. });
  1867. window.addEventListener('e', null, options);
  1868. } catch (e) {// continue regardless of error
  1869. }
  1870. return supports;
  1871. }(); // Default passive to true as expected by Chrome for 'touchstart' and 'touchend' events.
  1872. /* global wx, my */
  1873. // weixin miniprogram
  1874. // @ts-ignore
  1875. var isWx = (typeof wx === "undefined" ? "undefined" : _typeof$1(wx)) === 'object' && typeof wx.getSystemInfoSync === 'function'; // ant miniprogram
  1876. // @ts-ignore
  1877. var isMy = (typeof my === "undefined" ? "undefined" : _typeof$1(my)) === 'object' && typeof my.getSystemInfoSync === 'function'; // in node
  1878. // @ts-ignore
  1879. var isNode = (typeof global === "undefined" ? "undefined" : _typeof$1(global)) && !(typeof window === "undefined" ? "undefined" : _typeof$1(window)); // in browser
  1880. function isCanvasElement(el) {
  1881. if (!el || _typeof$1(el) !== 'object') return false;
  1882. if (el.nodeType === 1 && el.nodeName) {
  1883. // HTMLCanvasElement
  1884. return true;
  1885. } // CanvasElement
  1886. return !!el.isCanvasElement;
  1887. }
  1888. function getPixelRatio() {
  1889. return window && window.devicePixelRatio || 1;
  1890. }
  1891. function getStyle(el, property) {
  1892. return el.currentStyle ? el.currentStyle[property] : document.defaultView.getComputedStyle(el, null).getPropertyValue(property);
  1893. }
  1894. function getWidth(el) {
  1895. var width = getStyle(el, 'width');
  1896. if (width === 'auto') {
  1897. width = el.offsetWidth;
  1898. }
  1899. return parseFloat(width);
  1900. }
  1901. function getHeight(el) {
  1902. var height = getStyle(el, 'height');
  1903. if (height === 'auto') {
  1904. height = el.offsetHeight;
  1905. }
  1906. return parseFloat(height);
  1907. }
  1908. function getDomById(id) {
  1909. if (!id) {
  1910. return null;
  1911. }
  1912. return document.getElementById(id);
  1913. }
  1914. function getRelativePosition(point, canvas) {
  1915. var canvasDom = canvas.get('el');
  1916. if (!canvasDom) return point;
  1917. var _canvasDom$getBoundin = canvasDom.getBoundingClientRect(),
  1918. top = _canvasDom$getBoundin.top,
  1919. left = _canvasDom$getBoundin.left;
  1920. var paddingLeft = parseFloat(getStyle(canvasDom, 'padding-left'));
  1921. var paddingTop = parseFloat(getStyle(canvasDom, 'padding-top'));
  1922. var mouseX = point.x - left - paddingLeft;
  1923. var mouseY = point.y - top - paddingTop;
  1924. return {
  1925. x: mouseX,
  1926. y: mouseY
  1927. };
  1928. }
  1929. function landscapePoint(point, canvas) {
  1930. var landscape = canvas.get('landscape');
  1931. if (!landscape) {
  1932. return point;
  1933. }
  1934. if (isFunction(landscape)) {
  1935. return landscape(point, canvas);
  1936. } // 默认顺时针旋转90度
  1937. var height = canvas.get('height');
  1938. var x = point.y;
  1939. var y = height - point.x;
  1940. return {
  1941. x: x,
  1942. y: y
  1943. };
  1944. }
  1945. function convertPoints(ev, canvas) {
  1946. var touches = ev.touches; // 认为是mouse事件
  1947. if (!touches) {
  1948. var point = getRelativePosition({
  1949. x: ev.clientX,
  1950. y: ev.clientY
  1951. }, canvas);
  1952. return [landscapePoint(point, canvas)];
  1953. } // 单指 touchend 后,touchs 会变空,最后的触点要从changedTouches里拿
  1954. if (!touches.length) {
  1955. // 为了防止万一,加个空逻辑
  1956. touches = ev.changedTouches || [];
  1957. }
  1958. var points = [];
  1959. for (var i = 0, len = touches.length; i < len; i++) {
  1960. var touch = touches[i]; // x, y: 相对canvas原点的位置,clientX, clientY 相对于可视窗口的位置
  1961. var x = touch.x,
  1962. y = touch.y,
  1963. clientX = touch.clientX,
  1964. clientY = touch.clientY;
  1965. var _point = void 0; // 小程序环境会有x,y
  1966. if (isNumber(x) || isNumber(y)) {
  1967. _point = {
  1968. x: x,
  1969. y: y
  1970. };
  1971. } else {
  1972. // 浏览器环境再计算下canvas的相对位置
  1973. _point = getRelativePosition({
  1974. x: clientX,
  1975. y: clientY
  1976. }, canvas);
  1977. }
  1978. points.push(landscapePoint(_point, canvas));
  1979. }
  1980. return points;
  1981. }
  1982. function measureText(text, font, ctx) {
  1983. if (!ctx) {
  1984. ctx = document.createElement('canvas').getContext('2d');
  1985. }
  1986. ctx.font = font || '12px sans-serif';
  1987. return ctx.measureText(text);
  1988. }
  1989. var convertPoints$1 = convertPoints; // 计算滑动的方向
  1990. var calcDirection = function calcDirection(start, end) {
  1991. var xDistance = end.x - start.x;
  1992. var yDistance = end.y - start.y; // x 的距离大于y 说明是横向,否则就是纵向
  1993. if (Math.abs(xDistance) > Math.abs(yDistance)) {
  1994. return xDistance > 0 ? 'right' : 'left';
  1995. }
  1996. return yDistance > 0 ? 'down' : 'up';
  1997. }; // 计算2点之间的距离
  1998. var calcDistance = function calcDistance(point1, point2) {
  1999. var xDistance = Math.abs(point2.x - point1.x);
  2000. var yDistance = Math.abs(point2.y - point1.y);
  2001. return Math.sqrt(xDistance * xDistance + yDistance * yDistance);
  2002. };
  2003. var getCenter = function getCenter(point1, point2) {
  2004. var x = point1.x + (point2.x - point1.x) / 2;
  2005. var y = point1.y + (point2.y - point1.y) / 2;
  2006. return {
  2007. x: x,
  2008. y: y
  2009. };
  2010. };
  2011. var PRESS_DELAY = 250;
  2012. var EventController = /*#__PURE__*/function () {
  2013. function EventController(_ref) {
  2014. var _this = this;
  2015. var canvas = _ref.canvas,
  2016. el = _ref.el;
  2017. _classCallCheck$1(this, EventController);
  2018. this._click = function (ev) {
  2019. var points = convertPoints$1(ev, _this.canvas);
  2020. ev.points = points;
  2021. _this.emitEvent('click', ev);
  2022. };
  2023. this._start = function (ev) {
  2024. var points = convertPoints$1(ev, _this.canvas);
  2025. if (!points) {
  2026. return;
  2027. }
  2028. ev.points = points;
  2029. _this.emitEvent('touchstart', ev); // 防止上次的内容没有清理掉,重新reset下
  2030. _this.reset(); // 记录touch start 的时间
  2031. _this.startTime = Date.now(); // 记录touch start 的点
  2032. _this.startPoints = points;
  2033. if (points.length > 1) {
  2034. _this.startDistance = calcDistance(points[0], points[1]);
  2035. _this.center = getCenter(points[0], points[1]);
  2036. } else {
  2037. // 如果touchstart后停顿250ms, 则也触发press事件
  2038. _this.pressTimeout = setTimeout(function () {
  2039. // 这里固定触发press事件
  2040. var eventType = 'press';
  2041. var direction = 'none';
  2042. ev.direction = direction;
  2043. _this.emitStart(eventType, ev);
  2044. _this.emitEvent(eventType, ev);
  2045. _this.eventType = eventType;
  2046. _this.direction = direction;
  2047. }, PRESS_DELAY);
  2048. }
  2049. };
  2050. this._move = function (ev) {
  2051. var points = convertPoints$1(ev, _this.canvas);
  2052. if (!points) return;
  2053. _this.clearPressTimeout();
  2054. ev.points = points;
  2055. _this.emitEvent('touchmove', ev);
  2056. var startPoints = _this.startPoints;
  2057. if (!startPoints) return; // 多指触控
  2058. if (points.length > 1) {
  2059. // touchstart的距离
  2060. var startDistance = _this.startDistance;
  2061. var currentDistance = calcDistance(points[0], points[1]);
  2062. ev.zoom = currentDistance / startDistance;
  2063. ev.center = _this.center; // 触发缩放事件
  2064. _this.emitStart('pinch', ev);
  2065. _this.emitEvent('pinch', ev);
  2066. } else {
  2067. var deltaX = points[0].x - startPoints[0].x;
  2068. var deltaY = points[0].y - startPoints[0].y;
  2069. var direction = _this.direction || calcDirection(startPoints[0], points[0]);
  2070. _this.direction = direction; // 获取press或者pan的事件类型
  2071. // press 按住滑动, pan表示平移
  2072. // 如果start后立刻move,则触发pan, 如果有停顿,则触发press
  2073. var eventType = _this.getEventType(points);
  2074. ev.direction = direction;
  2075. ev.deltaX = deltaX;
  2076. ev.deltaY = deltaY;
  2077. _this.emitStart(eventType, ev);
  2078. _this.emitEvent(eventType, ev); // 记录最后2次move的时间和坐标,为了给swipe事件用
  2079. var prevMoveTime = _this.lastMoveTime;
  2080. var now = Date.now(); // 最后2次的时间间隔一定要大于0,否则swipe没发计算
  2081. if (now - prevMoveTime > 0) {
  2082. _this.prevMoveTime = prevMoveTime;
  2083. _this.prevMovePoints = _this.lastMovePoints;
  2084. _this.lastMoveTime = now;
  2085. _this.lastMovePoints = points;
  2086. }
  2087. }
  2088. };
  2089. this._end = function (ev) {
  2090. var points = convertPoints$1(ev, _this.canvas);
  2091. ev.points = points;
  2092. _this.emitEnd(ev);
  2093. _this.emitEvent('touchend', ev); // swipe事件处理, 在touchend之后触发
  2094. var lastMoveTime = _this.lastMoveTime;
  2095. var now = Date.now(); // 做这个判断是为了最后一次touchmove后到end前,还有一个停顿的过程
  2096. // 100 是拍的一个值,理论这个值会很短,一般不卡顿的话在10ms以内
  2097. if (now - lastMoveTime < 100) {
  2098. var prevMoveTime = _this.prevMoveTime || _this.startTime;
  2099. var intervalTime = lastMoveTime - prevMoveTime; // 时间间隔一定要大于0, 否则计算没意义
  2100. if (intervalTime > 0) {
  2101. var prevMovePoints = _this.prevMovePoints || _this.startPoints;
  2102. var lastMovePoints = _this.lastMovePoints; // move速率
  2103. var velocity = calcDistance(prevMovePoints[0], lastMovePoints[0]) / intervalTime; // 0.3 是参考hammerjs的设置
  2104. if (velocity > 0.3) {
  2105. ev.velocity = velocity;
  2106. ev.direction = calcDirection(prevMovePoints[0], lastMovePoints[0]);
  2107. ev.velocityX = (lastMovePoints[0].x - prevMovePoints[0].x) / intervalTime;
  2108. ev.velocityY = (lastMovePoints[0].y - prevMovePoints[0].y) / intervalTime;
  2109. _this.emitEvent('swipe', ev);
  2110. }
  2111. }
  2112. }
  2113. _this.reset();
  2114. var touches = ev.touches; // 当多指只释放了1指时也会触发end, 这时重新触发一次start
  2115. if (touches && touches.length > 0) {
  2116. _this._start(ev);
  2117. }
  2118. };
  2119. this._cancel = function (ev) {
  2120. _this.emitEvent('touchcancel', ev);
  2121. _this.reset();
  2122. }; // canvasEl
  2123. this.canvas = canvas;
  2124. this.delegateEvent(el); // 用来记录当前触发的事件
  2125. this.processEvent = {};
  2126. }
  2127. _createClass$1(EventController, [{
  2128. key: "delegateEvent",
  2129. value: function delegateEvent(canvasEl) {
  2130. // 代理这几个事件
  2131. canvasEl.addEventListener('click', this._click);
  2132. canvasEl.addEventListener('touchstart', this._start);
  2133. canvasEl.addEventListener('touchmove', this._move);
  2134. canvasEl.addEventListener('touchend', this._end);
  2135. canvasEl.addEventListener('touchcancel', this._cancel);
  2136. }
  2137. }, {
  2138. key: "emitEvent",
  2139. value: function emitEvent(type, ev) {
  2140. var canvas = this.canvas;
  2141. canvas.emit(type, ev);
  2142. }
  2143. }, {
  2144. key: "getEventType",
  2145. value: function getEventType(points) {
  2146. var eventType = this.eventType,
  2147. canvas = this.canvas,
  2148. startTime = this.startTime,
  2149. startPoints = this.startPoints;
  2150. if (eventType) {
  2151. return eventType;
  2152. }
  2153. var type;
  2154. var panEventListeners = canvas.__events.pan; // 如果没有pan事件的监听,默认都是press
  2155. if (!panEventListeners || !panEventListeners.length) {
  2156. type = 'press';
  2157. } else {
  2158. // 如果有pan事件的处理,press则需要停顿250ms, 且移动距离小于10
  2159. var now = Date.now();
  2160. if (now - startTime > PRESS_DELAY && calcDistance(startPoints[0], points[0]) < 10) {
  2161. type = 'press';
  2162. } else {
  2163. type = 'pan';
  2164. }
  2165. }
  2166. this.eventType = type;
  2167. return type;
  2168. }
  2169. }, {
  2170. key: "enable",
  2171. value: function enable(eventType) {
  2172. this.processEvent[eventType] = true;
  2173. } // 是否进行中的事件
  2174. }, {
  2175. key: "isProcess",
  2176. value: function isProcess(eventType) {
  2177. return this.processEvent[eventType];
  2178. } // 触发start事件
  2179. }, {
  2180. key: "emitStart",
  2181. value: function emitStart(type, ev) {
  2182. if (this.isProcess(type)) {
  2183. return;
  2184. }
  2185. this.enable(type);
  2186. this.emitEvent("".concat(type, "start"), ev);
  2187. } // 触发end事件
  2188. }, {
  2189. key: "emitEnd",
  2190. value: function emitEnd(ev) {
  2191. var _this2 = this;
  2192. var processEvent = this.processEvent;
  2193. Object.keys(processEvent).forEach(function (type) {
  2194. _this2.emitEvent("".concat(type, "end"), ev);
  2195. delete processEvent[type];
  2196. });
  2197. }
  2198. }, {
  2199. key: "clearPressTimeout",
  2200. value: function clearPressTimeout() {
  2201. if (this.pressTimeout) {
  2202. clearTimeout(this.pressTimeout);
  2203. this.pressTimeout = null;
  2204. }
  2205. }
  2206. }, {
  2207. key: "reset",
  2208. value: function reset() {
  2209. this.clearPressTimeout();
  2210. this.startTime = 0;
  2211. this.startPoints = null;
  2212. this.startDistance = 0;
  2213. this.direction = null;
  2214. this.eventType = null;
  2215. this.pinch = false;
  2216. this.prevMoveTime = 0;
  2217. this.prevMovePoints = null;
  2218. this.lastMoveTime = 0;
  2219. this.lastMovePoints = null;
  2220. }
  2221. }]);
  2222. return EventController;
  2223. }();
  2224. var CanvasElement = /*#__PURE__*/function (_EventEmit) {
  2225. _inherits$1(CanvasElement, _EventEmit);
  2226. var _super = _createSuper$1(CanvasElement);
  2227. /* eslint-enable */
  2228. function CanvasElement(ctx) {
  2229. var _this;
  2230. _classCallCheck$1(this, CanvasElement);
  2231. _this = _super.call(this);
  2232. _this.context = ctx; // canvas实际的宽高 (width/height) * pixelRatio
  2233. // 有可能是 node canvas 创建的 context 对象
  2234. var canvas = ctx.canvas || {};
  2235. _this.width = canvas.width || 0;
  2236. _this.height = canvas.height || 0;
  2237. _this.style = {};
  2238. _this.currentStyle = {};
  2239. _this.attrs = {}; // 用来标识是CanvasElement实例
  2240. _this.isCanvasElement = true;
  2241. return _this;
  2242. }
  2243. _createClass$1(CanvasElement, [{
  2244. key: "getContext",
  2245. value: function
  2246. /* type */
  2247. getContext() {
  2248. return this.context;
  2249. }
  2250. }, {
  2251. key: "getBoundingClientRect",
  2252. value: function getBoundingClientRect() {
  2253. var width = this.width;
  2254. var height = this.height; // 默认都处理成可视窗口的顶部位置
  2255. return {
  2256. top: 0,
  2257. right: width,
  2258. bottom: height,
  2259. left: 0
  2260. };
  2261. }
  2262. }, {
  2263. key: "setAttribute",
  2264. value: function setAttribute(key, value) {
  2265. this.attrs[key] = value;
  2266. }
  2267. }, {
  2268. key: "addEventListener",
  2269. value: function addEventListener(type, listener) {
  2270. this.on(type, listener);
  2271. }
  2272. }, {
  2273. key: "removeEventListener",
  2274. value: function removeEventListener(type, listener) {
  2275. this.off(type, listener);
  2276. }
  2277. }, {
  2278. key: "dispatchEvent",
  2279. value: function dispatchEvent(type, e) {
  2280. this.emit(type, e);
  2281. }
  2282. }]);
  2283. return CanvasElement;
  2284. }(EventEmit);
  2285. function supportEventListener(canvas) {
  2286. if (!canvas) {
  2287. return false;
  2288. } // 非 HTMLCanvasElement
  2289. if (canvas.nodeType !== 1 || !canvas.nodeName || canvas.nodeName.toLowerCase() !== 'canvas') {
  2290. return false;
  2291. } // 微信小程序canvas.getContext('2d')时也是CanvasRenderingContext2D
  2292. // 也会有ctx.canvas, 而且nodeType也是1,所以还要在看下是否支持addEventListener
  2293. var support = false;
  2294. try {
  2295. canvas.addEventListener('eventTest', function () {
  2296. support = true;
  2297. });
  2298. canvas.dispatchEvent(new Event('eventTest'));
  2299. } catch (error) {
  2300. support = false;
  2301. }
  2302. return support;
  2303. }
  2304. var CanvasElement$1 = {
  2305. create: function create(ctx) {
  2306. if (!ctx) {
  2307. return null;
  2308. }
  2309. if (supportEventListener(ctx.canvas)) {
  2310. return ctx.canvas;
  2311. }
  2312. return new CanvasElement(ctx);
  2313. }
  2314. };
  2315. function remove(arr, obj) {
  2316. if (!arr) {
  2317. return;
  2318. }
  2319. var index = arr.indexOf(obj);
  2320. if (index !== -1) {
  2321. arr.splice(index, 1);
  2322. }
  2323. }
  2324. function _defineProperty$1(obj, key, value) {
  2325. if (key in obj) {
  2326. Object.defineProperty(obj, key, {
  2327. value: value,
  2328. enumerable: true,
  2329. configurable: true,
  2330. writable: true
  2331. });
  2332. } else {
  2333. obj[key] = value;
  2334. }
  2335. return obj;
  2336. }
  2337. function ownKeys(object, enumerableOnly) {
  2338. var keys = Object.keys(object);
  2339. if (Object.getOwnPropertySymbols) {
  2340. var symbols = Object.getOwnPropertySymbols(object);
  2341. enumerableOnly && (symbols = symbols.filter(function (sym) {
  2342. return Object.getOwnPropertyDescriptor(object, sym).enumerable;
  2343. })), keys.push.apply(keys, symbols);
  2344. }
  2345. return keys;
  2346. }
  2347. function _objectSpread2(target) {
  2348. for (var i = 1; i < arguments.length; i++) {
  2349. var source = null != arguments[i] ? arguments[i] : {};
  2350. i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
  2351. _defineProperty$1(target, key, source[key]);
  2352. }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
  2353. Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
  2354. });
  2355. }
  2356. return target;
  2357. }
  2358. function _mod(n, m) {
  2359. return (n % m + m) % m;
  2360. }
  2361. function _addStop(steps, gradient) {
  2362. each(steps, function (item) {
  2363. item = item.split(':');
  2364. gradient.addColorStop(Number(item[0]), item[1]);
  2365. });
  2366. } // the string format: 'l(0) 0:#ffffff 0.5:#7ec2f3 1:#1890ff'
  2367. function _parseLineGradient(color, shape, context) {
  2368. var arr = color.split(' ');
  2369. var angle = arr[0].slice(2, arr[0].length - 1);
  2370. angle = _mod(parseFloat(angle) * Math.PI / 180, Math.PI * 2);
  2371. var steps = arr.slice(1);
  2372. var _shape$getBBox = shape.getBBox(),
  2373. minX = _shape$getBBox.minX,
  2374. minY = _shape$getBBox.minY,
  2375. maxX = _shape$getBBox.maxX,
  2376. maxY = _shape$getBBox.maxY;
  2377. var start;
  2378. var end;
  2379. if (angle >= 0 && angle < 0.5 * Math.PI) {
  2380. start = {
  2381. x: minX,
  2382. y: minY
  2383. };
  2384. end = {
  2385. x: maxX,
  2386. y: maxY
  2387. };
  2388. } else if (0.5 * Math.PI <= angle && angle < Math.PI) {
  2389. start = {
  2390. x: maxX,
  2391. y: minY
  2392. };
  2393. end = {
  2394. x: minX,
  2395. y: maxY
  2396. };
  2397. } else if (Math.PI <= angle && angle < 1.5 * Math.PI) {
  2398. start = {
  2399. x: maxX,
  2400. y: maxY
  2401. };
  2402. end = {
  2403. x: minX,
  2404. y: minY
  2405. };
  2406. } else {
  2407. start = {
  2408. x: minX,
  2409. y: maxY
  2410. };
  2411. end = {
  2412. x: maxX,
  2413. y: minY
  2414. };
  2415. }
  2416. var tanTheta = Math.tan(angle);
  2417. var tanTheta2 = tanTheta * tanTheta;
  2418. var x = (end.x - start.x + tanTheta * (end.y - start.y)) / (tanTheta2 + 1) + start.x;
  2419. var y = tanTheta * (end.x - start.x + tanTheta * (end.y - start.y)) / (tanTheta2 + 1) + start.y;
  2420. var gradient = context.createLinearGradient(start.x, start.y, x, y);
  2421. _addStop(steps, gradient);
  2422. return gradient;
  2423. } // the string format: 'r(0.5, 0.5, 0.1) 0:#ffffff 1:#1890ff'
  2424. function _parseRadialGradient(color, shape, context) {
  2425. var arr = color.split(' ');
  2426. var circleCfg = arr[0].slice(2, arr[0].length - 1);
  2427. circleCfg = circleCfg.split(',');
  2428. var fx = parseFloat(circleCfg[0]);
  2429. var fy = parseFloat(circleCfg[1]);
  2430. var fr = parseFloat(circleCfg[2]);
  2431. var steps = arr.slice(1); // if radius is 0, no gradient, stroke with the last color
  2432. if (fr === 0) {
  2433. var _color = steps[steps.length - 1];
  2434. return _color.split(':')[1];
  2435. }
  2436. var _shape$getBBox2 = shape.getBBox(),
  2437. width = _shape$getBBox2.width,
  2438. height = _shape$getBBox2.height,
  2439. minX = _shape$getBBox2.minX,
  2440. minY = _shape$getBBox2.minY;
  2441. var r = Math.sqrt(width * width + height * height) / 2;
  2442. var gradient = context.createRadialGradient(minX + width * fx, minY + height * fy, fr * r, minX + width / 2, minY + height / 2, r);
  2443. _addStop(steps, gradient);
  2444. return gradient;
  2445. }
  2446. function parseStyle(color, shape, context) {
  2447. if (color[1] === '(') {
  2448. try {
  2449. var firstCode = color[0];
  2450. if (firstCode === 'l') {
  2451. return _parseLineGradient(color, shape, context);
  2452. } else if (firstCode === 'r') {
  2453. return _parseRadialGradient(color, shape, context);
  2454. }
  2455. } catch (ev) {
  2456. console.error('error in parsing gradient string, please check if there are any extra whitespaces.');
  2457. console.error(ev);
  2458. }
  2459. }
  2460. return color;
  2461. }
  2462. var ALIAS_ATTRS_MAP = {
  2463. stroke: 'strokeStyle',
  2464. fill: 'fillStyle',
  2465. opacity: 'globalAlpha'
  2466. };
  2467. var SHAPE_ATTRS = ['fillStyle', 'font', 'globalAlpha', 'lineCap', 'lineWidth', 'lineJoin', 'miterLimit', 'shadowBlur', 'shadowColor', 'shadowOffsetX', 'shadowOffsetY', 'strokeStyle', 'textAlign', 'textBaseline', 'lineDash', 'shadow' // 兼容支付宝小程序
  2468. ];
  2469. var CLIP_SHAPES = ['circle', 'sector', 'polygon', 'rect', 'polyline', 'custom'];
  2470. var Element = /*#__PURE__*/function () {
  2471. function Element(cfg) {
  2472. _classCallCheck$1(this, Element);
  2473. this._initProperties();
  2474. mix(this._attrs, cfg);
  2475. var attrs = this._attrs.attrs;
  2476. if (attrs) {
  2477. this.initAttrs(attrs);
  2478. }
  2479. this.initTransform();
  2480. }
  2481. _createClass$1(Element, [{
  2482. key: "_initProperties",
  2483. value: function _initProperties() {
  2484. this._attrs = _objectSpread2(_objectSpread2({}, this._attrs), {}, {
  2485. zIndex: 0,
  2486. visible: true,
  2487. destroyed: false
  2488. });
  2489. }
  2490. }, {
  2491. key: "get",
  2492. value: function get(name) {
  2493. return this._attrs[name];
  2494. }
  2495. }, {
  2496. key: "set",
  2497. value: function set(name, value) {
  2498. this._attrs[name] = value;
  2499. }
  2500. }, {
  2501. key: "isGroup",
  2502. value: function isGroup() {
  2503. return this.get('isGroup');
  2504. }
  2505. }, {
  2506. key: "isShape",
  2507. value: function isShape() {
  2508. return this.get('isShape');
  2509. }
  2510. }, {
  2511. key: "initAttrs",
  2512. value: function initAttrs(attrs) {
  2513. this.attr(mix(this.getDefaultAttrs(), attrs));
  2514. }
  2515. }, {
  2516. key: "getDefaultAttrs",
  2517. value: function getDefaultAttrs() {
  2518. return {};
  2519. }
  2520. }, {
  2521. key: "_setAttr",
  2522. value: function _setAttr(name, value) {
  2523. var attrs = this._attrs.attrs;
  2524. if (name === 'clip') {
  2525. value = this._setAttrClip(value);
  2526. } else {
  2527. var alias = ALIAS_ATTRS_MAP[name];
  2528. if (alias) {
  2529. attrs[alias] = value;
  2530. }
  2531. }
  2532. attrs[name] = value;
  2533. }
  2534. }, {
  2535. key: "_getAttr",
  2536. value: function _getAttr(name) {
  2537. var _this$_attrs, _this$_attrs$attrs;
  2538. 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];
  2539. }
  2540. }, {
  2541. key: "_afterAttrsSet",
  2542. value: function _afterAttrsSet() {}
  2543. }, {
  2544. key: "_setAttrClip",
  2545. value: function _setAttrClip(clip) {
  2546. if (clip && CLIP_SHAPES.indexOf(clip._attrs.type) > -1) {
  2547. if (clip.get('canvas') === null) {
  2548. clip = _objectSpread2({}, clip);
  2549. }
  2550. clip.set('parent', this.get('parent'));
  2551. clip.set('context', this.get('context'));
  2552. return clip;
  2553. }
  2554. return null;
  2555. }
  2556. }, {
  2557. key: "attr",
  2558. value: function attr(name, value) {
  2559. if (this.get('destroyed')) return null;
  2560. var argumentsLen = arguments.length;
  2561. if (argumentsLen === 0) {
  2562. return this._attrs.attrs;
  2563. }
  2564. if (isObject(name)) {
  2565. this._attrs.bbox = null;
  2566. for (var k in name) {
  2567. this._setAttr(k, name[k]);
  2568. }
  2569. if (this._afterAttrsSet) {
  2570. this._afterAttrsSet();
  2571. }
  2572. return this;
  2573. }
  2574. if (argumentsLen === 2) {
  2575. this._attrs.bbox = null;
  2576. this._setAttr(name, value);
  2577. if (this._afterAttrsSet) {
  2578. this._afterAttrsSet();
  2579. }
  2580. return this;
  2581. }
  2582. return this._getAttr(name);
  2583. }
  2584. }, {
  2585. key: "getParent",
  2586. value: function getParent() {
  2587. return this.get('parent');
  2588. }
  2589. }, {
  2590. key: "draw",
  2591. value: function draw(context) {
  2592. if (this.get('destroyed')) {
  2593. return;
  2594. }
  2595. if (this.get('visible')) {
  2596. this.setContext(context);
  2597. this.drawInner(context);
  2598. this.restoreContext(context);
  2599. }
  2600. }
  2601. }, {
  2602. key: "setContext",
  2603. value: function setContext(context) {
  2604. var clip = this._attrs.attrs.clip;
  2605. context.save();
  2606. if (clip && !clip._attrs.destroyed) {
  2607. clip.resetTransform(context);
  2608. clip.createPath(context);
  2609. context.clip();
  2610. }
  2611. this.resetContext(context);
  2612. this.resetTransform(context);
  2613. }
  2614. }, {
  2615. key: "restoreContext",
  2616. value: function restoreContext(context) {
  2617. context.restore();
  2618. }
  2619. }, {
  2620. key: "resetContext",
  2621. value: function resetContext(context) {
  2622. var elAttrs = this._attrs.attrs;
  2623. for (var k in elAttrs) {
  2624. if (SHAPE_ATTRS.indexOf(k) > -1) {
  2625. var v = elAttrs[k];
  2626. if ((k === 'fillStyle' || k === 'strokeStyle') && v) {
  2627. v = parseStyle(v, this, context);
  2628. }
  2629. if (k === 'lineDash' && context.setLineDash && isArray(v)) {
  2630. context.setLineDash(v);
  2631. } else {
  2632. context[k] = v;
  2633. }
  2634. }
  2635. }
  2636. }
  2637. }, {
  2638. key: "hasFill",
  2639. value: function hasFill() {
  2640. return this.get('canFill') && this._attrs.attrs.fillStyle;
  2641. }
  2642. }, {
  2643. key: "hasStroke",
  2644. value: function hasStroke() {
  2645. return this.get('canStroke') && this._attrs.attrs.strokeStyle;
  2646. }
  2647. }, {
  2648. key: "drawInner",
  2649. value: function drawInner(_context) {}
  2650. }, {
  2651. key: "show",
  2652. value: function show() {
  2653. this.set('visible', true);
  2654. return this;
  2655. }
  2656. }, {
  2657. key: "hide",
  2658. value: function hide() {
  2659. this.set('visible', false);
  2660. return this;
  2661. }
  2662. }, {
  2663. key: "isVisible",
  2664. value: function isVisible() {
  2665. return this.get('visible');
  2666. }
  2667. }, {
  2668. key: "getAriaLabel",
  2669. value: function getAriaLabel() {
  2670. var _this$_attrs2 = this._attrs,
  2671. destroyed = _this$_attrs2.destroyed,
  2672. visible = _this$_attrs2.visible,
  2673. isShape = _this$_attrs2.isShape,
  2674. aria = _this$_attrs2.aria;
  2675. if (destroyed || !visible || isShape && !aria) {
  2676. return;
  2677. }
  2678. return this._getAriaLabel();
  2679. }
  2680. }, {
  2681. key: "_getAriaLabel",
  2682. value: function _getAriaLabel() {
  2683. return this._attrs.ariaLabel;
  2684. }
  2685. }, {
  2686. key: "_removeFromParent",
  2687. value: function _removeFromParent() {
  2688. var parent = this.get('parent');
  2689. if (parent) {
  2690. var children = parent.get('children');
  2691. remove(children, this);
  2692. }
  2693. return this;
  2694. }
  2695. }, {
  2696. key: "remove",
  2697. value: function remove(destroy) {
  2698. if (destroy) {
  2699. this.destroy();
  2700. } else {
  2701. this._removeFromParent();
  2702. }
  2703. }
  2704. }, {
  2705. key: "destroy",
  2706. value: function destroy() {
  2707. var destroyed = this.get('destroyed');
  2708. if (destroyed) {
  2709. return null;
  2710. }
  2711. this._removeFromParent();
  2712. this._attrs = {};
  2713. this.set('destroyed', true);
  2714. }
  2715. }, {
  2716. key: "getBBox",
  2717. value: function getBBox() {
  2718. return {
  2719. minX: 0,
  2720. maxX: 0,
  2721. minY: 0,
  2722. maxY: 0,
  2723. width: 0,
  2724. height: 0
  2725. };
  2726. }
  2727. }, {
  2728. key: "initTransform",
  2729. value: function initTransform() {
  2730. var attrs = this._attrs.attrs;
  2731. if (!attrs) {
  2732. attrs = {};
  2733. }
  2734. if (!attrs.matrix) {
  2735. attrs.matrix = [1, 0, 0, 1, 0, 0];
  2736. }
  2737. this._attrs.attrs = attrs;
  2738. }
  2739. }, {
  2740. key: "getMatrix",
  2741. value: function getMatrix() {
  2742. return this._attrs.attrs.matrix;
  2743. }
  2744. }, {
  2745. key: "setMatrix",
  2746. value: function setMatrix(m) {
  2747. this._attrs.attrs.matrix = [m[0], m[1], m[2], m[3], m[4], m[5]];
  2748. }
  2749. }, {
  2750. key: "transform",
  2751. value: function transform(actions) {
  2752. var matrix = this._attrs.attrs.matrix;
  2753. this._attrs.attrs.matrix = Matrix.transform(matrix, actions);
  2754. return this;
  2755. }
  2756. }, {
  2757. key: "setTransform",
  2758. value: function setTransform(actions) {
  2759. this._attrs.attrs.matrix = [1, 0, 0, 1, 0, 0];
  2760. return this.transform(actions);
  2761. }
  2762. }, {
  2763. key: "translate",
  2764. value: function translate(x, y) {
  2765. var matrix = this._attrs.attrs.matrix;
  2766. Matrix.translate(matrix, matrix, [x, y]);
  2767. }
  2768. }, {
  2769. key: "rotate",
  2770. value: function rotate(rad) {
  2771. var matrix = this._attrs.attrs.matrix;
  2772. Matrix.rotate(matrix, matrix, rad);
  2773. }
  2774. }, {
  2775. key: "scale",
  2776. value: function scale(sx, sy) {
  2777. var matrix = this._attrs.attrs.matrix;
  2778. Matrix.scale(matrix, matrix, [sx, sy]);
  2779. }
  2780. }, {
  2781. key: "moveTo",
  2782. value: function moveTo(x, y) {
  2783. var cx = this._attrs.x || 0;
  2784. var cy = this._attrs.y || 0;
  2785. this.translate(x - cx, y - cy);
  2786. this.set('x', x);
  2787. this.set('y', y);
  2788. }
  2789. }, {
  2790. key: "apply",
  2791. value: function apply(v) {
  2792. var m = this._attrs.attrs.matrix;
  2793. Vector2.transformMat2d(v, v, m);
  2794. return this;
  2795. }
  2796. }, {
  2797. key: "resetTransform",
  2798. value: function resetTransform(context) {
  2799. var mo = this._attrs.attrs.matrix;
  2800. if (Matrix.isChanged(mo)) {
  2801. context.transform(mo[0], mo[1], mo[2], mo[3], mo[4], mo[5]);
  2802. }
  2803. }
  2804. }, {
  2805. key: "isDestroyed",
  2806. value: function isDestroyed() {
  2807. return this.get('destroyed');
  2808. }
  2809. }]);
  2810. return Element;
  2811. }();
  2812. var Shape = /*#__PURE__*/function (_Element) {
  2813. _inherits$1(Shape, _Element);
  2814. var _super = _createSuper$1(Shape);
  2815. function Shape() {
  2816. _classCallCheck$1(this, Shape);
  2817. return _super.apply(this, arguments);
  2818. }
  2819. _createClass$1(Shape, [{
  2820. key: "_initProperties",
  2821. value:
  2822. /* eslint-enable */
  2823. function _initProperties() {
  2824. this._attrs = _objectSpread2(_objectSpread2({}, this._attrs), {}, {
  2825. zIndex: 0,
  2826. visible: true,
  2827. destroyed: false,
  2828. isShape: true,
  2829. attrs: {}
  2830. });
  2831. }
  2832. }, {
  2833. key: "getType",
  2834. value: function getType() {
  2835. return this._attrs.type;
  2836. }
  2837. }, {
  2838. key: "drawInner",
  2839. value: function drawInner(context) {
  2840. var attrs = this.get('attrs');
  2841. this.createPath(context);
  2842. var originOpacity = context.globalAlpha;
  2843. if (this.hasFill()) {
  2844. var fillOpacity = attrs.fillOpacity;
  2845. if (!isNil(fillOpacity) && fillOpacity !== 1) {
  2846. context.globalAlpha = fillOpacity;
  2847. context.fill();
  2848. context.globalAlpha = originOpacity;
  2849. } else {
  2850. context.fill();
  2851. }
  2852. }
  2853. if (this.hasStroke()) {
  2854. var lineWidth = attrs.lineWidth;
  2855. if (lineWidth > 0) {
  2856. var strokeOpacity = attrs.strokeOpacity;
  2857. if (!isNil(strokeOpacity) && strokeOpacity !== 1) {
  2858. context.globalAlpha = strokeOpacity;
  2859. }
  2860. context.stroke();
  2861. }
  2862. }
  2863. }
  2864. }, {
  2865. key: "getBBox",
  2866. value: function getBBox() {
  2867. var bbox = this._attrs.bbox;
  2868. if (!bbox) {
  2869. bbox = this.calculateBox();
  2870. if (bbox) {
  2871. bbox.x = bbox.minX;
  2872. bbox.y = bbox.minY;
  2873. bbox.width = bbox.maxX - bbox.minX;
  2874. bbox.height = bbox.maxY - bbox.minY;
  2875. }
  2876. this._attrs.bbox = bbox;
  2877. }
  2878. return bbox;
  2879. }
  2880. }, {
  2881. key: "calculateBox",
  2882. value: function calculateBox() {
  2883. return null;
  2884. }
  2885. }, {
  2886. key: "createPath",
  2887. value: function createPath(_context) {}
  2888. }]);
  2889. return Shape;
  2890. }(Element);
  2891. function _superPropBase(object, property) {
  2892. while (!Object.prototype.hasOwnProperty.call(object, property)) {
  2893. object = _getPrototypeOf$1(object);
  2894. if (object === null) break;
  2895. }
  2896. return object;
  2897. }
  2898. function _get() {
  2899. if (typeof Reflect !== "undefined" && Reflect.get) {
  2900. _get = Reflect.get.bind();
  2901. } else {
  2902. _get = function _get(target, property, receiver) {
  2903. var base = _superPropBase(target, property);
  2904. if (!base) return;
  2905. var desc = Object.getOwnPropertyDescriptor(base, property);
  2906. if (desc.get) {
  2907. return desc.get.call(arguments.length < 3 ? target : receiver);
  2908. }
  2909. return desc.value;
  2910. };
  2911. }
  2912. return _get.apply(this, arguments);
  2913. }
  2914. function parsePadding(padding) {
  2915. var top = 0;
  2916. var right = 0;
  2917. var bottom = 0;
  2918. var left = 0;
  2919. if (isNumber(padding)) {
  2920. top = bottom = left = right = padding;
  2921. } else if (isArray(padding)) {
  2922. top = padding[0];
  2923. right = !isNil(padding[1]) ? padding[1] : padding[0];
  2924. bottom = !isNil(padding[2]) ? padding[2] : padding[0];
  2925. left = !isNil(padding[3]) ? padding[3] : right;
  2926. }
  2927. return [top, right, bottom, left];
  2928. } // 为了处理radius 大于 width 或 height 的场景
  2929. function parseRadius(radius, width, height) {
  2930. radius = parsePadding(radius); // 都为0
  2931. if (!radius[0] && !radius[1] && !radius[2] && !radius[3]) {
  2932. return radius;
  2933. }
  2934. var minWidth = Math.max(radius[0] + radius[1], radius[2] + radius[3]);
  2935. var minHeight = Math.max(radius[0] + radius[3], radius[1] + radius[2]);
  2936. var scale = Math.min(width / minWidth, height / minHeight);
  2937. if (scale < 1) {
  2938. return radius.map(function (r) {
  2939. return r * scale;
  2940. });
  2941. }
  2942. return radius;
  2943. }
  2944. var Rect = /*#__PURE__*/function (_Shape) {
  2945. _inherits$1(Rect, _Shape);
  2946. var _super = _createSuper$1(Rect);
  2947. function Rect() {
  2948. _classCallCheck$1(this, Rect);
  2949. return _super.apply(this, arguments);
  2950. }
  2951. _createClass$1(Rect, [{
  2952. key: "_initProperties",
  2953. value: function _initProperties() {
  2954. _get(_getPrototypeOf$1(Rect.prototype), "_initProperties", this).call(this);
  2955. this._attrs.canFill = true;
  2956. this._attrs.canStroke = true;
  2957. this._attrs.type = 'rect';
  2958. }
  2959. }, {
  2960. key: "getDefaultAttrs",
  2961. value: function getDefaultAttrs() {
  2962. return {
  2963. x: 0,
  2964. y: 0,
  2965. width: 0,
  2966. height: 0,
  2967. radius: 0,
  2968. lineWidth: 0
  2969. };
  2970. }
  2971. }, {
  2972. key: "createRadiusPath",
  2973. value: function createRadiusPath(context, x, y, width, height, radius) {
  2974. radius = parseRadius(radius, width, height);
  2975. context.moveTo(x + radius[0], y);
  2976. context.lineTo(x + width - radius[1], y);
  2977. context.arc(x + width - radius[1], y + radius[1], radius[1], -Math.PI / 2, 0, false);
  2978. context.lineTo(x + width, y + height - radius[2]);
  2979. context.arc(x + width - radius[2], y + height - radius[2], radius[2], 0, Math.PI / 2, false);
  2980. context.lineTo(x + radius[3], y + height);
  2981. context.arc(x + radius[3], y + height - radius[3], radius[3], Math.PI / 2, Math.PI, false);
  2982. context.lineTo(x, y + radius[0]);
  2983. context.arc(x + radius[0], y + radius[0], radius[0], Math.PI, Math.PI * 3 / 2, false);
  2984. context.closePath();
  2985. }
  2986. }, {
  2987. key: "createPath",
  2988. value: function createPath(context) {
  2989. var attrs = this.get('attrs');
  2990. var x = attrs.x,
  2991. y = attrs.y,
  2992. width = attrs.width,
  2993. height = attrs.height,
  2994. radius = attrs.radius;
  2995. context.beginPath();
  2996. if (!radius || !(width * height)) {
  2997. context.rect(x, y, width, height);
  2998. } else {
  2999. this.createRadiusPath(context, x, y, width, height, radius);
  3000. }
  3001. }
  3002. }, {
  3003. key: "calculateBox",
  3004. value: function calculateBox() {
  3005. var attrs = this.get('attrs');
  3006. var x = attrs.x,
  3007. y = attrs.y,
  3008. width = attrs.width,
  3009. height = attrs.height;
  3010. return {
  3011. minX: x,
  3012. minY: y,
  3013. maxX: x + width,
  3014. maxY: y + height
  3015. };
  3016. }
  3017. }]);
  3018. return Rect;
  3019. }(Shape);
  3020. var imageCaches = {};
  3021. var ImageShape = /*#__PURE__*/function (_Rect) {
  3022. _inherits$1(ImageShape, _Rect);
  3023. var _super = _createSuper$1(ImageShape);
  3024. function ImageShape() {
  3025. _classCallCheck$1(this, ImageShape);
  3026. return _super.apply(this, arguments);
  3027. }
  3028. _createClass$1(ImageShape, [{
  3029. key: "_initProperties",
  3030. value: function _initProperties() {
  3031. _get(_getPrototypeOf$1(ImageShape.prototype), "_initProperties", this).call(this);
  3032. this._attrs.canFill = false;
  3033. this._attrs.canStroke = false;
  3034. this._attrs.loading = false;
  3035. this._attrs.image = null;
  3036. this._attrs.type = 'image';
  3037. }
  3038. }, {
  3039. key: "draw",
  3040. value: function draw(context) {
  3041. var _this = this; // 如果图片还在loading中直接返回,等下次绘制
  3042. if (this.get('loading')) {
  3043. return;
  3044. } // 如果已经有image对象,直接绘制,会调用createPath绘制
  3045. var image = this.get('image');
  3046. if (image) {
  3047. _get(_getPrototypeOf$1(ImageShape.prototype), "draw", this).call(this, context);
  3048. return;
  3049. }
  3050. var attrs = this.get('attrs');
  3051. var src = attrs.src;
  3052. if (src) {
  3053. var cacheImage = this.get('cacheImage'); // 如果有缓存,则直接从缓存中拿
  3054. if (cacheImage && imageCaches[src]) {
  3055. this.set('image', imageCaches[src]);
  3056. this.draw(context);
  3057. return;
  3058. }
  3059. var _image = null;
  3060. var canvas = this.get('canvas');
  3061. if (canvas && canvas.get('createImage')) {
  3062. var createImage = canvas.get('createImage');
  3063. _image = createImage();
  3064. } else if (window.Image) {
  3065. _image = new Image();
  3066. }
  3067. if (_image) {
  3068. this.set('loading', true); // 设置跨域, 等同于 image.crossOrigin = 'anonymous'
  3069. _image.crossOrigin = '';
  3070. _image.onload = function () {
  3071. _this.set('loading', false);
  3072. _this.set('image', _image); // this.draw(context);
  3073. // 这里需要调用 canvas.draw 进行重新绘制,否则 image 会一直在最上层
  3074. canvas.draw();
  3075. }; // src 一定要在 crossOrigin 之后,否则 toDataURL 就会报 SecurityError
  3076. _image.src = src; // 设置全局缓存
  3077. if (cacheImage) {
  3078. imageCaches[src] = _image;
  3079. }
  3080. }
  3081. }
  3082. }
  3083. }, {
  3084. key: "createPath",
  3085. value: function createPath(context) {
  3086. var image = this.get('image');
  3087. this.drawImage(context, image);
  3088. }
  3089. }, {
  3090. key: "drawImage",
  3091. value: function drawImage(context, image) {
  3092. var _this$_attrs = this._attrs,
  3093. attrs = _this$_attrs.attrs,
  3094. destroyed = _this$_attrs.destroyed;
  3095. if (destroyed) {
  3096. return;
  3097. }
  3098. var x = attrs.x,
  3099. y = attrs.y,
  3100. width = attrs.width,
  3101. height = attrs.height,
  3102. sx = attrs.sx,
  3103. sy = attrs.sy,
  3104. swidth = attrs.swidth,
  3105. sheight = attrs.sheight,
  3106. radius = attrs.radius,
  3107. fillOpacity = attrs.fillOpacity;
  3108. if (radius) {
  3109. context.save();
  3110. this.createRadiusPath(context, x, y, width, height, radius);
  3111. context.clip();
  3112. } // 设置透明度
  3113. var originOpacity = context.globalAlpha;
  3114. if (!isNil(fillOpacity)) {
  3115. context.globalAlpha = fillOpacity;
  3116. }
  3117. if (!isNil(sx) && !isNil(sy) && !isNil(swidth) && !isNil(sheight)) {
  3118. context.drawImage(image, sx, sy, swidth, sheight, x, y, width, height);
  3119. } else {
  3120. context.drawImage(image, x, y, width, height);
  3121. }
  3122. context.globalAlpha = originOpacity;
  3123. if (radius) {
  3124. // 因为 save 和 restore 会一定程度上影响绘图性能,所以只在必要是调用
  3125. context.restore();
  3126. }
  3127. }
  3128. }]);
  3129. return ImageShape;
  3130. }(Rect);
  3131. var Circle = /*#__PURE__*/function (_Shape) {
  3132. _inherits$1(Circle, _Shape);
  3133. var _super = _createSuper$1(Circle);
  3134. function Circle() {
  3135. _classCallCheck$1(this, Circle);
  3136. return _super.apply(this, arguments);
  3137. }
  3138. _createClass$1(Circle, [{
  3139. key: "_initProperties",
  3140. value: function _initProperties() {
  3141. _get(_getPrototypeOf$1(Circle.prototype), "_initProperties", this).call(this);
  3142. this._attrs.canFill = true;
  3143. this._attrs.canStroke = true;
  3144. this._attrs.type = 'circle';
  3145. }
  3146. }, {
  3147. key: "getDefaultAttrs",
  3148. value: function getDefaultAttrs() {
  3149. return {
  3150. x: 0,
  3151. y: 0,
  3152. r: 0,
  3153. lineWidth: 0
  3154. };
  3155. }
  3156. }, {
  3157. key: "createPath",
  3158. value: function createPath(context) {
  3159. var attrs = this.get('attrs');
  3160. var x = attrs.x,
  3161. y = attrs.y,
  3162. r = attrs.r;
  3163. context.beginPath();
  3164. context.arc(x, y, r, 0, Math.PI * 2, false);
  3165. context.closePath();
  3166. }
  3167. }, {
  3168. key: "calculateBox",
  3169. value: function calculateBox() {
  3170. var attrs = this.get('attrs');
  3171. var x = attrs.x,
  3172. y = attrs.y,
  3173. r = attrs.r;
  3174. return {
  3175. minX: x - r,
  3176. maxX: x + r,
  3177. minY: y - r,
  3178. maxY: y + r
  3179. };
  3180. }
  3181. }]);
  3182. return Circle;
  3183. }(Shape);
  3184. var Line = /*#__PURE__*/function (_Shape) {
  3185. _inherits$1(Line, _Shape);
  3186. var _super = _createSuper$1(Line);
  3187. function Line() {
  3188. _classCallCheck$1(this, Line);
  3189. return _super.apply(this, arguments);
  3190. }
  3191. _createClass$1(Line, [{
  3192. key: "_initProperties",
  3193. value: function _initProperties() {
  3194. _get(_getPrototypeOf$1(Line.prototype), "_initProperties", this).call(this);
  3195. this._attrs.canStroke = true;
  3196. this._attrs.type = 'line';
  3197. }
  3198. }, {
  3199. key: "getDefaultAttrs",
  3200. value: function getDefaultAttrs() {
  3201. return {
  3202. x1: 0,
  3203. y1: 0,
  3204. x2: 0,
  3205. y2: 0,
  3206. lineWidth: 1
  3207. };
  3208. }
  3209. }, {
  3210. key: "createPath",
  3211. value: function createPath(context) {
  3212. var attrs = this.get('attrs');
  3213. var x1 = attrs.x1,
  3214. y1 = attrs.y1,
  3215. x2 = attrs.x2,
  3216. y2 = attrs.y2;
  3217. context.beginPath();
  3218. context.moveTo(x1, y1);
  3219. context.lineTo(x2, y2);
  3220. }
  3221. }, {
  3222. key: "calculateBox",
  3223. value: function calculateBox() {
  3224. var attrs = this.get('attrs');
  3225. var x1 = attrs.x1,
  3226. y1 = attrs.y1,
  3227. x2 = attrs.x2,
  3228. y2 = attrs.y2,
  3229. lineWidth = attrs.lineWidth;
  3230. return getBBoxFromLine(x1, y1, x2, y2, lineWidth);
  3231. }
  3232. }]);
  3233. return Line;
  3234. }(Shape);
  3235. var Polygon = /*#__PURE__*/function (_Shape) {
  3236. _inherits$1(Polygon, _Shape);
  3237. var _super = _createSuper$1(Polygon);
  3238. function Polygon() {
  3239. _classCallCheck$1(this, Polygon);
  3240. return _super.apply(this, arguments);
  3241. }
  3242. _createClass$1(Polygon, [{
  3243. key: "_initProperties",
  3244. value: function _initProperties() {
  3245. _get(_getPrototypeOf$1(Polygon.prototype), "_initProperties", this).call(this);
  3246. this._attrs.canFill = true;
  3247. this._attrs.canStroke = true;
  3248. this._attrs.type = 'polygon';
  3249. }
  3250. }, {
  3251. key: "getDefaultAttrs",
  3252. value: function getDefaultAttrs() {
  3253. return {
  3254. points: null,
  3255. lineWidth: 0
  3256. };
  3257. }
  3258. }, {
  3259. key: "createPath",
  3260. value: function createPath(context) {
  3261. var attrs = this.get('attrs');
  3262. var points = attrs.points;
  3263. context.beginPath();
  3264. for (var i = 0, len = points.length; i < len; i++) {
  3265. var point = points[i];
  3266. if (i === 0) {
  3267. context.moveTo(point.x, point.y);
  3268. } else {
  3269. context.lineTo(point.x, point.y);
  3270. }
  3271. }
  3272. context.closePath();
  3273. }
  3274. }, {
  3275. key: "calculateBox",
  3276. value: function calculateBox() {
  3277. var attrs = this.get('attrs');
  3278. var points = attrs.points;
  3279. return getBBoxFromPoints(points);
  3280. }
  3281. }]);
  3282. return Polygon;
  3283. }(Shape);
  3284. function _filterPoints(points) {
  3285. var filteredPoints = [];
  3286. for (var i = 0, len = points.length; i < len; i++) {
  3287. var point = points[i];
  3288. if (!isNaN(point.x) && !isNaN(point.y)) {
  3289. filteredPoints.push(point);
  3290. }
  3291. }
  3292. return filteredPoints;
  3293. }
  3294. var Polyline = /*#__PURE__*/function (_Shape) {
  3295. _inherits$1(Polyline, _Shape);
  3296. var _super = _createSuper$1(Polyline);
  3297. function Polyline() {
  3298. _classCallCheck$1(this, Polyline);
  3299. return _super.apply(this, arguments);
  3300. }
  3301. _createClass$1(Polyline, [{
  3302. key: "_initProperties",
  3303. value: function _initProperties() {
  3304. _get(_getPrototypeOf$1(Polyline.prototype), "_initProperties", this).call(this);
  3305. this._attrs.canFill = true;
  3306. this._attrs.canStroke = true;
  3307. this._attrs.type = 'polyline';
  3308. }
  3309. }, {
  3310. key: "getDefaultAttrs",
  3311. value: function getDefaultAttrs() {
  3312. return {
  3313. points: null,
  3314. lineWidth: 1,
  3315. smooth: false
  3316. };
  3317. }
  3318. }, {
  3319. key: "createPath",
  3320. value: function createPath(context) {
  3321. var attrs = this.get('attrs');
  3322. var points = attrs.points,
  3323. smooth = attrs.smooth;
  3324. var filteredPoints = _filterPoints(points);
  3325. context.beginPath();
  3326. if (filteredPoints.length) {
  3327. context.moveTo(filteredPoints[0].x, filteredPoints[0].y);
  3328. if (smooth) {
  3329. var constaint = [[0, 0], [1, 1]];
  3330. var sps = catmullRom2bezier(filteredPoints, false, constaint);
  3331. for (var i = 0, n = sps.length; i < n; i++) {
  3332. var sp = sps[i];
  3333. context.bezierCurveTo(sp[1], sp[2], sp[3], sp[4], sp[5], sp[6]);
  3334. }
  3335. } else {
  3336. var _i;
  3337. var l;
  3338. for (_i = 1, l = filteredPoints.length - 1; _i < l; _i++) {
  3339. context.lineTo(filteredPoints[_i].x, filteredPoints[_i].y);
  3340. }
  3341. context.lineTo(filteredPoints[l].x, filteredPoints[l].y);
  3342. }
  3343. }
  3344. }
  3345. }, {
  3346. key: "calculateBox",
  3347. value: function calculateBox() {
  3348. var attrs = this.get('attrs');
  3349. var points = attrs.points,
  3350. smooth = attrs.smooth,
  3351. lineWidth = attrs.lineWidth;
  3352. var filteredPoints = _filterPoints(points);
  3353. if (smooth) {
  3354. var newPoints = [];
  3355. var constaint = [[0, 0], [1, 1]];
  3356. var sps = catmullRom2bezier(filteredPoints, false, constaint);
  3357. for (var i = 0, n = sps.length; i < n; i++) {
  3358. var sp = sps[i];
  3359. if (i === 0) {
  3360. newPoints.push([filteredPoints[0].x, filteredPoints[0].y, sp[1], sp[2], sp[3], sp[4], sp[5], sp[6]]);
  3361. } else {
  3362. var lastPoint = sps[i - 1];
  3363. newPoints.push([lastPoint[5], lastPoint[6], sp[1], sp[2], sp[3], sp[4], sp[5], sp[6]]);
  3364. }
  3365. }
  3366. return getBBoxFromBezierGroup(newPoints, lineWidth);
  3367. }
  3368. return getBBoxFromPoints(filteredPoints, lineWidth);
  3369. }
  3370. }]);
  3371. return Polyline;
  3372. }(Shape);
  3373. var Arc = /*#__PURE__*/function (_Shape) {
  3374. _inherits$1(Arc, _Shape);
  3375. var _super = _createSuper$1(Arc);
  3376. function Arc() {
  3377. _classCallCheck$1(this, Arc);
  3378. return _super.apply(this, arguments);
  3379. }
  3380. _createClass$1(Arc, [{
  3381. key: "_initProperties",
  3382. value: function _initProperties() {
  3383. _get(_getPrototypeOf$1(Arc.prototype), "_initProperties", this).call(this);
  3384. this._attrs.canStroke = true;
  3385. this._attrs.canFill = true;
  3386. this._attrs.type = 'arc';
  3387. }
  3388. }, {
  3389. key: "getDefaultAttrs",
  3390. value: function getDefaultAttrs() {
  3391. return {
  3392. x: 0,
  3393. y: 0,
  3394. r: 0,
  3395. startAngle: 0,
  3396. endAngle: Math.PI * 2,
  3397. anticlockwise: false,
  3398. lineWidth: 1
  3399. };
  3400. }
  3401. }, {
  3402. key: "createPath",
  3403. value: function createPath(context) {
  3404. var attrs = this.get('attrs');
  3405. var x = attrs.x,
  3406. y = attrs.y,
  3407. r = attrs.r,
  3408. startAngle = attrs.startAngle,
  3409. endAngle = attrs.endAngle,
  3410. anticlockwise = attrs.anticlockwise;
  3411. context.beginPath();
  3412. if (startAngle !== endAngle) {
  3413. context.arc(x, y, r, startAngle, endAngle, anticlockwise);
  3414. }
  3415. }
  3416. }, {
  3417. key: "calculateBox",
  3418. value: function calculateBox() {
  3419. var attrs = this.get('attrs');
  3420. var x = attrs.x,
  3421. y = attrs.y,
  3422. r = attrs.r,
  3423. startAngle = attrs.startAngle,
  3424. endAngle = attrs.endAngle,
  3425. anticlockwise = attrs.anticlockwise;
  3426. return getBBoxFromArc(x, y, r, startAngle, endAngle, anticlockwise);
  3427. }
  3428. }]);
  3429. return Arc;
  3430. }(Shape);
  3431. var Sector = /*#__PURE__*/function (_Shape) {
  3432. _inherits$1(Sector, _Shape);
  3433. var _super = _createSuper$1(Sector);
  3434. function Sector() {
  3435. _classCallCheck$1(this, Sector);
  3436. return _super.apply(this, arguments);
  3437. }
  3438. _createClass$1(Sector, [{
  3439. key: "_initProperties",
  3440. value: function _initProperties() {
  3441. _get(_getPrototypeOf$1(Sector.prototype), "_initProperties", this).call(this);
  3442. this._attrs.canFill = true;
  3443. this._attrs.canStroke = true;
  3444. this._attrs.type = 'sector';
  3445. }
  3446. }, {
  3447. key: "getDefaultAttrs",
  3448. value: function getDefaultAttrs() {
  3449. return {
  3450. x: 0,
  3451. y: 0,
  3452. lineWidth: 0,
  3453. r: 0,
  3454. r0: 0,
  3455. startAngle: 0,
  3456. endAngle: Math.PI * 2,
  3457. anticlockwise: false
  3458. };
  3459. }
  3460. }, {
  3461. key: "createPath",
  3462. value: function createPath(context) {
  3463. var attrs = this.get('attrs');
  3464. var x = attrs.x,
  3465. y = attrs.y,
  3466. startAngle = attrs.startAngle,
  3467. r = attrs.r,
  3468. r0 = attrs.r0,
  3469. anticlockwise = attrs.anticlockwise; // 最大为整个圆
  3470. var endAngle = Math.min(attrs.endAngle, startAngle + Math.PI * 2);
  3471. context.beginPath();
  3472. var unitX = Math.cos(startAngle);
  3473. var unitY = Math.sin(startAngle);
  3474. context.moveTo(unitX * r0 + x, unitY * r0 + y);
  3475. context.lineTo(unitX * r + x, unitY * r + y); // 当扇形的角度非常小的时候,就不进行弧线的绘制;或者整个只有1个扇形时,会出现end<0的情况不绘制
  3476. if (Math.abs(endAngle - startAngle) > 0.0001 || startAngle === 0 && endAngle < 0) {
  3477. context.arc(x, y, r, startAngle, endAngle, anticlockwise);
  3478. context.lineTo(Math.cos(endAngle) * r0 + x, Math.sin(endAngle) * r0 + y);
  3479. if (r0 !== 0) {
  3480. context.arc(x, y, r0, endAngle, startAngle, !anticlockwise);
  3481. }
  3482. }
  3483. context.closePath();
  3484. }
  3485. }, {
  3486. key: "calculateBox",
  3487. value: function calculateBox() {
  3488. var attrs = this.get('attrs');
  3489. var x = attrs.x,
  3490. y = attrs.y,
  3491. r = attrs.r,
  3492. r0 = attrs.r0,
  3493. startAngle = attrs.startAngle,
  3494. endAngle = attrs.endAngle,
  3495. anticlockwise = attrs.anticlockwise;
  3496. var outerBBox = getBBoxFromArc(x, y, r, startAngle, endAngle, anticlockwise);
  3497. var innerBBox = getBBoxFromArc(x, y, r0, startAngle, endAngle, anticlockwise);
  3498. return {
  3499. minX: Math.min(outerBBox.minX, innerBBox.minX),
  3500. minY: Math.min(outerBBox.minY, innerBBox.minY),
  3501. maxX: Math.max(outerBBox.maxX, innerBBox.maxX),
  3502. maxY: Math.max(outerBBox.maxY, innerBBox.maxY)
  3503. };
  3504. }
  3505. }]);
  3506. return Sector;
  3507. }(Shape);
  3508. var Rect$1 = {
  3509. calcRotatedBox: function calcRotatedBox(_ref) {
  3510. var width = _ref.width,
  3511. height = _ref.height,
  3512. rotate = _ref.rotate;
  3513. var absRotate = Math.abs(rotate);
  3514. return {
  3515. width: Math.abs(width * Math.cos(absRotate) + height * Math.sin(absRotate)),
  3516. height: Math.abs(height * Math.cos(absRotate) + width * Math.sin(absRotate))
  3517. };
  3518. }
  3519. };
  3520. var measureText$1 = measureText;
  3521. var textWidthCacheCounter = 0;
  3522. var textWidthCache = {};
  3523. var TEXT_CACHE_MAX = 5000;
  3524. var Text = /*#__PURE__*/function (_Shape) {
  3525. _inherits$1(Text, _Shape);
  3526. var _super = _createSuper$1(Text);
  3527. function Text() {
  3528. _classCallCheck$1(this, Text);
  3529. return _super.apply(this, arguments);
  3530. }
  3531. _createClass$1(Text, [{
  3532. key: "_initProperties",
  3533. value: function _initProperties() {
  3534. _get(_getPrototypeOf$1(Text.prototype), "_initProperties", this).call(this);
  3535. this._attrs.canFill = true;
  3536. this._attrs.canStroke = true;
  3537. this._attrs.type = 'text';
  3538. }
  3539. }, {
  3540. key: "getDefaultAttrs",
  3541. value: function getDefaultAttrs() {
  3542. return {
  3543. lineWidth: 0,
  3544. lineCount: 1,
  3545. fontSize: 12,
  3546. fontFamily: '',
  3547. fontStyle: 'normal',
  3548. fontWeight: 'normal',
  3549. fontVariant: 'normal',
  3550. textAlign: 'start',
  3551. textBaseline: 'bottom',
  3552. lineHeight: null,
  3553. textArr: null
  3554. };
  3555. }
  3556. }, {
  3557. key: "_getFontStyle",
  3558. value: function _getFontStyle() {
  3559. var attrs = this._attrs.attrs;
  3560. var fontSize = attrs.fontSize,
  3561. fontFamily = attrs.fontFamily,
  3562. fontWeight = attrs.fontWeight,
  3563. fontStyle = attrs.fontStyle,
  3564. fontVariant = attrs.fontVariant;
  3565. return "".concat(fontStyle, " ").concat(fontVariant, " ").concat(fontWeight, " ").concat(fontSize, "px ").concat(fontFamily);
  3566. }
  3567. }, {
  3568. key: "_afterAttrsSet",
  3569. value: function _afterAttrsSet() {
  3570. var attrs = this._attrs.attrs;
  3571. attrs.font = this._getFontStyle();
  3572. if (attrs.text) {
  3573. var text = attrs.text;
  3574. var textArr = null;
  3575. var lineCount = 1;
  3576. if (isString(text) && text.indexOf('\n') !== -1) {
  3577. textArr = text.split('\n');
  3578. lineCount = textArr.length;
  3579. }
  3580. attrs.lineCount = lineCount;
  3581. attrs.textArr = textArr;
  3582. }
  3583. this.set('attrs', attrs);
  3584. }
  3585. }, {
  3586. key: "_getTextHeight",
  3587. value: function _getTextHeight() {
  3588. var attrs = this._attrs.attrs;
  3589. if (attrs.height) {
  3590. return attrs.height;
  3591. }
  3592. var lineCount = attrs.lineCount;
  3593. var fontSize = attrs.fontSize * 1;
  3594. if (lineCount > 1) {
  3595. var spaceingY = this._getSpaceingY();
  3596. return fontSize * lineCount + spaceingY * (lineCount - 1);
  3597. }
  3598. return fontSize;
  3599. }
  3600. }, {
  3601. key: "_getSpaceingY",
  3602. value: function _getSpaceingY() {
  3603. var attrs = this._attrs.attrs;
  3604. var lineHeight = attrs.lineHeight;
  3605. var fontSize = attrs.fontSize * 1;
  3606. return lineHeight ? lineHeight - fontSize : fontSize * 0.14;
  3607. }
  3608. }, {
  3609. key: "drawInner",
  3610. value: function drawInner(context) {
  3611. var attrs = this._attrs.attrs;
  3612. var text = attrs.text;
  3613. var x = attrs.x;
  3614. var y = attrs.y;
  3615. if (isNil(text) || isNaN(x) || isNaN(y)) {
  3616. // text will be 0
  3617. return;
  3618. }
  3619. var textArr = attrs.textArr;
  3620. var fontSize = attrs.fontSize * 1;
  3621. var spaceingY = this._getSpaceingY();
  3622. if (attrs.rotate) {
  3623. // do rotation
  3624. context.translate(x, y);
  3625. context.rotate(attrs.rotate);
  3626. x = 0;
  3627. y = 0;
  3628. }
  3629. var textBaseline = attrs.textBaseline;
  3630. var height;
  3631. if (textArr) {
  3632. height = this._getTextHeight();
  3633. }
  3634. var subY; // context.beginPath();
  3635. if (this.hasFill()) {
  3636. var fillOpacity = attrs.fillOpacity;
  3637. if (!isNil(fillOpacity) && fillOpacity !== 1) {
  3638. context.globalAlpha = fillOpacity;
  3639. }
  3640. if (textArr) {
  3641. for (var i = 0, len = textArr.length; i < len; i++) {
  3642. var subText = textArr[i];
  3643. subY = y + i * (spaceingY + fontSize) - height + fontSize; // bottom;
  3644. if (textBaseline === 'middle') {
  3645. subY += height - fontSize - (height - fontSize) / 2;
  3646. }
  3647. if (textBaseline === 'top') {
  3648. subY += height - fontSize;
  3649. }
  3650. context.fillText(subText, x, subY);
  3651. }
  3652. } else {
  3653. context.fillText(text, x, y);
  3654. }
  3655. }
  3656. if (this.hasStroke()) {
  3657. if (textArr) {
  3658. for (var _i = 0, _len = textArr.length; _i < _len; _i++) {
  3659. var _subText = textArr[_i];
  3660. subY = y + _i * (spaceingY + fontSize) - height + fontSize; // bottom;
  3661. if (textBaseline === 'middle') {
  3662. subY += height - fontSize - (height - fontSize) / 2;
  3663. }
  3664. if (textBaseline === 'top') {
  3665. subY += height - fontSize;
  3666. }
  3667. context.strokeText(_subText, x, subY);
  3668. }
  3669. } else {
  3670. context.strokeText(text, x, y);
  3671. }
  3672. }
  3673. }
  3674. }, {
  3675. key: "_getAriaLabel",
  3676. value: function _getAriaLabel() {
  3677. return this._attrs.attrs.text;
  3678. }
  3679. }, {
  3680. key: "calculateBox",
  3681. value: function calculateBox() {
  3682. var attrs = this._attrs.attrs;
  3683. var x = attrs.x,
  3684. y = attrs.y,
  3685. textAlign = attrs.textAlign,
  3686. textBaseline = attrs.textBaseline;
  3687. var width = this._getTextWidth(); // attrs.width
  3688. if (!width) {
  3689. return {
  3690. minX: x,
  3691. minY: y,
  3692. maxX: x,
  3693. maxY: y
  3694. };
  3695. }
  3696. var height = this._getTextHeight(); // attrs.height
  3697. if (attrs.rotate) {
  3698. var rotatedBox = Rect$1.calcRotatedBox({
  3699. width: width,
  3700. height: height,
  3701. rotate: attrs.rotate
  3702. });
  3703. width = rotatedBox.width;
  3704. height = rotatedBox.height;
  3705. }
  3706. var point = {
  3707. x: x,
  3708. y: y - height
  3709. }; // default textAlign: start, textBaseline: bottom
  3710. if (textAlign) {
  3711. if (textAlign === 'end' || textAlign === 'right') {
  3712. point.x -= width;
  3713. } else if (textAlign === 'center') {
  3714. point.x -= width / 2;
  3715. }
  3716. }
  3717. if (textBaseline) {
  3718. if (textBaseline === 'top') {
  3719. point.y += height;
  3720. } else if (textBaseline === 'middle') {
  3721. point.y += height / 2;
  3722. }
  3723. }
  3724. return {
  3725. minX: point.x,
  3726. minY: point.y,
  3727. maxX: point.x + width,
  3728. maxY: point.y + height
  3729. };
  3730. }
  3731. }, {
  3732. key: "_getTextWidth",
  3733. value: function _getTextWidth() {
  3734. var attrs = this._attrs.attrs;
  3735. if (attrs.width) {
  3736. return attrs.width;
  3737. }
  3738. var text = attrs.text;
  3739. var context = this.get('context');
  3740. if (isNil(text)) return undefined;
  3741. var font = attrs.font;
  3742. var textArr = attrs.textArr;
  3743. var key = text + '' + font;
  3744. if (textWidthCache[key]) {
  3745. return textWidthCache[key];
  3746. }
  3747. var width = 0;
  3748. if (textArr) {
  3749. for (var i = 0, length = textArr.length; i < length; i++) {
  3750. var subText = textArr[i];
  3751. width = Math.max(width, measureText$1(subText, font, context).width);
  3752. }
  3753. } else {
  3754. width = measureText$1(text, font, context).width;
  3755. }
  3756. if (textWidthCacheCounter > TEXT_CACHE_MAX) {
  3757. textWidthCacheCounter = 0;
  3758. textWidthCache = {};
  3759. }
  3760. textWidthCacheCounter++;
  3761. textWidthCache[key] = width;
  3762. return width;
  3763. }
  3764. }]);
  3765. return Text;
  3766. }(Shape);
  3767. var Custom = /*#__PURE__*/function (_Shape) {
  3768. _inherits$1(Custom, _Shape);
  3769. var _super = _createSuper$1(Custom);
  3770. function Custom() {
  3771. _classCallCheck$1(this, Custom);
  3772. return _super.apply(this, arguments);
  3773. }
  3774. _createClass$1(Custom, [{
  3775. key: "_initProperties",
  3776. value: function _initProperties() {
  3777. _get(_getPrototypeOf$1(Custom.prototype), "_initProperties", this).call(this);
  3778. this._attrs.canFill = true;
  3779. this._attrs.canStroke = true;
  3780. this._attrs.createPath = null;
  3781. this._attrs.type = 'custom';
  3782. }
  3783. }, {
  3784. key: "createPath",
  3785. value: function createPath(context) {
  3786. var createPath = this.get('createPath');
  3787. createPath && createPath.call(this, context);
  3788. }
  3789. }, {
  3790. key: "calculateBox",
  3791. value: function calculateBox() {
  3792. var calculateBox = this.get('calculateBox');
  3793. return calculateBox && calculateBox.call(this);
  3794. }
  3795. }]);
  3796. return Custom;
  3797. }(Shape);
  3798. var SYMBOLS = {
  3799. circle: function circle(x, y, r, ctx) {
  3800. ctx.arc(x, y, r, 0, Math.PI * 2, false);
  3801. },
  3802. square: function square(x, y, r, ctx) {
  3803. ctx.moveTo(x - r, y - r);
  3804. ctx.lineTo(x + r, y - r);
  3805. ctx.lineTo(x + r, y + r);
  3806. ctx.lineTo(x - r, y + r);
  3807. ctx.closePath();
  3808. }
  3809. };
  3810. var Marker = /*#__PURE__*/function (_Shape) {
  3811. _inherits$1(Marker, _Shape);
  3812. var _super = _createSuper$1(Marker);
  3813. function Marker() {
  3814. _classCallCheck$1(this, Marker);
  3815. return _super.apply(this, arguments);
  3816. }
  3817. _createClass$1(Marker, [{
  3818. key: "_initProperties",
  3819. value: function _initProperties() {
  3820. _get(_getPrototypeOf$1(Marker.prototype), "_initProperties", this).call(this);
  3821. this._attrs.canFill = true;
  3822. this._attrs.canStroke = true;
  3823. this._attrs.type = 'marker';
  3824. }
  3825. }, {
  3826. key: "getDefaultAttrs",
  3827. value: function getDefaultAttrs() {
  3828. return {
  3829. x: 0,
  3830. y: 0,
  3831. lineWidth: 0
  3832. };
  3833. }
  3834. }, {
  3835. key: "createPath",
  3836. value: function createPath(context) {
  3837. var attrs = this.get('attrs');
  3838. var x = attrs.x,
  3839. y = attrs.y,
  3840. radius = attrs.radius;
  3841. var symbol = attrs.symbol || 'circle';
  3842. var method;
  3843. if (isFunction(symbol)) {
  3844. method = symbol;
  3845. } else {
  3846. method = SYMBOLS[symbol];
  3847. }
  3848. context.beginPath();
  3849. method(x, y, radius, context, this);
  3850. }
  3851. }, {
  3852. key: "calculateBox",
  3853. value: function calculateBox() {
  3854. var attrs = this.get('attrs');
  3855. var x = attrs.x,
  3856. y = attrs.y,
  3857. radius = attrs.radius;
  3858. return {
  3859. minX: x - radius,
  3860. minY: y - radius,
  3861. maxX: x + radius,
  3862. maxY: y + radius
  3863. };
  3864. }
  3865. }]);
  3866. return Marker;
  3867. }(Shape);
  3868. Shape.Rect = Rect;
  3869. Shape.Image = ImageShape;
  3870. Shape.Circle = Circle;
  3871. Shape.Line = Line;
  3872. Shape.Polygon = Polygon;
  3873. Shape.Polyline = Polyline;
  3874. Shape.Arc = Arc;
  3875. Shape.Sector = Sector;
  3876. Shape.Text = Text;
  3877. Shape.Custom = Custom;
  3878. Shape.Marker = Marker;
  3879. var SHAPE_MAP = {};
  3880. var INDEX = '_INDEX';
  3881. function getComparer(compare) {
  3882. return function (left, right) {
  3883. var result = compare(left, right);
  3884. return result === 0 ? left[INDEX] - right[INDEX] : result;
  3885. };
  3886. }
  3887. var Container = {
  3888. getGroupClass: function getGroupClass() {},
  3889. getChildren: function getChildren() {
  3890. return this.get('children');
  3891. },
  3892. addShape: function addShape(type) {
  3893. var cfg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  3894. var shapeType = SHAPE_MAP[type];
  3895. if (!shapeType) {
  3896. shapeType = upperFirst(type);
  3897. SHAPE_MAP[type] = shapeType;
  3898. }
  3899. var shape = new Shape[shapeType](cfg);
  3900. this.add(shape);
  3901. return shape;
  3902. },
  3903. addGroup: function addGroup(cfg) {
  3904. var groupClass = this.getGroupClass();
  3905. var rst = new groupClass(cfg);
  3906. this.add(rst);
  3907. return rst;
  3908. },
  3909. contain: function contain(item) {
  3910. var children = this.get('children');
  3911. return children.indexOf(item) > -1;
  3912. },
  3913. sort: function sort() {
  3914. var children = this.get('children');
  3915. for (var i = 0, len = children.length; i < len; i++) {
  3916. var child = children[i];
  3917. child[INDEX] = i;
  3918. }
  3919. children.sort(getComparer(function (obj1, obj2) {
  3920. return obj1.get('zIndex') - obj2.get('zIndex');
  3921. }));
  3922. return this;
  3923. },
  3924. drawChildren: function drawChildren(context) {
  3925. this.sort();
  3926. var children = this.get('children');
  3927. for (var i = 0, len = children.length; i < len; i++) {
  3928. var child = children[i];
  3929. child.draw(context);
  3930. }
  3931. return this;
  3932. },
  3933. clear: function clear() {
  3934. var children = this.get('children') || [];
  3935. while (children.length !== 0) {
  3936. children[children.length - 1].remove(true);
  3937. }
  3938. return this;
  3939. },
  3940. add: function add(items) {
  3941. var children = this.get('children');
  3942. if (!children) {
  3943. children = [];
  3944. this.set('children', children);
  3945. }
  3946. if (!isArray(items)) {
  3947. items = [items];
  3948. }
  3949. for (var i = 0, len = items.length; i < len; i++) {
  3950. var item = items[i];
  3951. var parent = item.get('parent');
  3952. if (parent) {
  3953. var descendants = parent.get('children');
  3954. remove(descendants, item);
  3955. }
  3956. this._setEvn(item);
  3957. children.push(item);
  3958. }
  3959. return this;
  3960. },
  3961. _setEvn: function _setEvn(item) {
  3962. var _this$_attrs = this._attrs,
  3963. context = _this$_attrs.context,
  3964. canvas = _this$_attrs.canvas,
  3965. aria = _this$_attrs.aria;
  3966. var _item$_attrs = item._attrs,
  3967. isGroup = _item$_attrs.isGroup,
  3968. type = _item$_attrs.type;
  3969. item._attrs.parent = this;
  3970. item._attrs.context = context;
  3971. item._attrs.canvas = canvas; // 是否需要无障碍处理
  3972. if (aria && item._attrs.aria !== false) {
  3973. item._attrs.aria = aria;
  3974. }
  3975. if (type === 'text' && canvas && canvas.get('fontFamily') && !item._attrs.attrs.fontFamily) {
  3976. item.attr('fontFamily', canvas.get('fontFamily'));
  3977. }
  3978. var clip = item._attrs.attrs.clip;
  3979. if (clip) {
  3980. clip._attrs.parent = this;
  3981. clip._attrs.context = context;
  3982. clip._attrs.canvas = canvas;
  3983. }
  3984. if (isGroup) {
  3985. var children = item._attrs.children;
  3986. for (var i = 0, len = children.length; i < len; i++) {
  3987. item._setEvn(children[i]);
  3988. }
  3989. }
  3990. },
  3991. _getAriaLabel: function _getAriaLabel() {
  3992. var _this$_attrs2 = this._attrs,
  3993. aria = _this$_attrs2.aria,
  3994. ariaLabel = _this$_attrs2.ariaLabel,
  3995. children = _this$_attrs2.children; // 主动关闭
  3996. if (!aria) return;
  3997. var childAriaLabels = [];
  3998. if (children && children.length) {
  3999. for (var i = 0, len = children.length; i < len; i++) {
  4000. var _childAriaLabel = children[i].getAriaLabel();
  4001. if (_childAriaLabel) {
  4002. childAriaLabels.push(_childAriaLabel);
  4003. }
  4004. }
  4005. }
  4006. var childAriaLabel = childAriaLabels.join(' '); // 2个都有时拼接成完整句子
  4007. if (ariaLabel && childAriaLabel) {
  4008. return "".concat(ariaLabel, " ").concat(childAriaLabel, " ");
  4009. } // 只有1个,或者都没有
  4010. return ariaLabel || childAriaLabel;
  4011. }
  4012. };
  4013. var Group = /*#__PURE__*/function (_Rect) {
  4014. _inherits$1(Group, _Rect);
  4015. var _super = _createSuper$1(Group);
  4016. function Group() {
  4017. _classCallCheck$1(this, Group);
  4018. return _super.apply(this, arguments);
  4019. }
  4020. _createClass$1(Group, [{
  4021. key: "_initProperties",
  4022. value:
  4023. /* eslint-enable */
  4024. function _initProperties() {
  4025. this._attrs = {
  4026. type: 'group',
  4027. zIndex: 0,
  4028. visible: true,
  4029. destroyed: false,
  4030. isGroup: true,
  4031. canFill: true,
  4032. canStroke: true,
  4033. children: [],
  4034. attrs: {
  4035. x: 0,
  4036. y: 0,
  4037. width: 0,
  4038. height: 0,
  4039. radius: 0,
  4040. lineWidth: 0
  4041. }
  4042. };
  4043. }
  4044. }, {
  4045. key: "getBBox",
  4046. value: function getBBox() {
  4047. var minX = Infinity;
  4048. var maxX = -Infinity;
  4049. var minY = Infinity;
  4050. var maxY = -Infinity;
  4051. var children = this.get('children');
  4052. for (var i = 0, length = children.length; i < length; i++) {
  4053. var child = children[i];
  4054. if (child.get('visible')) {
  4055. var box = child.getBBox();
  4056. if (!box) {
  4057. continue;
  4058. }
  4059. var leftTop = [box.minX, box.minY];
  4060. var leftBottom = [box.minX, box.maxY];
  4061. var rightTop = [box.maxX, box.minY];
  4062. var rightBottom = [box.maxX, box.maxY];
  4063. var matrix = child.attr('matrix');
  4064. Vector2.transformMat2d(leftTop, leftTop, matrix);
  4065. Vector2.transformMat2d(leftBottom, leftBottom, matrix);
  4066. Vector2.transformMat2d(rightTop, rightTop, matrix);
  4067. Vector2.transformMat2d(rightBottom, rightBottom, matrix);
  4068. minX = Math.min(leftTop[0], leftBottom[0], rightTop[0], rightBottom[0], minX);
  4069. maxX = Math.max(leftTop[0], leftBottom[0], rightTop[0], rightBottom[0], maxX);
  4070. minY = Math.min(leftTop[1], leftBottom[1], rightTop[1], rightBottom[1], minY);
  4071. maxY = Math.max(leftTop[1], leftBottom[1], rightTop[1], rightBottom[1], maxY);
  4072. }
  4073. }
  4074. return {
  4075. minX: minX,
  4076. minY: minY,
  4077. maxX: maxX,
  4078. maxY: maxY,
  4079. x: minX,
  4080. y: minY,
  4081. width: maxX - minX,
  4082. height: maxY - minY
  4083. };
  4084. }
  4085. }, {
  4086. key: "createPath",
  4087. value: function createPath(context) {
  4088. var attrs = this.get('attrs'); // 只有在有fillStyle或strokeStyle 时才需要绘制
  4089. if (!attrs.fillStyle && !attrs.strokeStyle) {
  4090. return;
  4091. }
  4092. _get(_getPrototypeOf$1(Group.prototype), "createPath", this).call(this, context);
  4093. }
  4094. }, {
  4095. key: "drawInner",
  4096. value: function drawInner(context) {
  4097. _get(_getPrototypeOf$1(Group.prototype), "drawInner", this).call(this, context);
  4098. this.drawChildren(context);
  4099. }
  4100. }, {
  4101. key: "destroy",
  4102. value: function destroy() {
  4103. if (this.get('destroyed')) {
  4104. return;
  4105. }
  4106. this.clear();
  4107. _get(_getPrototypeOf$1(Group.prototype), "destroy", this).call(this);
  4108. }
  4109. }]);
  4110. return Group;
  4111. }(Rect); // @ts-ignore
  4112. mix(Group.prototype, Container, {
  4113. getGroupClass: function getGroupClass() {
  4114. return Group;
  4115. }
  4116. });
  4117. var requestAnimationFrame$1 = (typeof window === "undefined" ? "undefined" : _typeof$1(window)) === 'object' && window.requestAnimationFrame ? window.requestAnimationFrame : function (fn) {
  4118. return setTimeout(fn, 16);
  4119. };
  4120. var lang = {
  4121. general: {
  4122. title: '这是一个图表,',
  4123. withTitle: '这是一个关于“{title}”的图表。'
  4124. },
  4125. coord: {
  4126. cartesian: 'X轴是{xLabel}Y轴是{yLabel}' // polar: '弧度是{xLabel}半径是{yLabel}'
  4127. },
  4128. scale: {
  4129. linear: '数值型,数据最小值为{min},最大值为{max};',
  4130. cat: '分类型, 分类类型有:{values};',
  4131. timeCat: '时间型,时间范围从{start}到{end};'
  4132. },
  4133. geometry: {
  4134. prefix: '共有{count}种分类组成,',
  4135. oneData: '第{index}类是{name},数据是{values};',
  4136. partData: '第{index}类是{name},共有{count}项数据,前{part}项是{values};',
  4137. allData: '第{index}类是{name},有{count}项数据,分别是{values};'
  4138. },
  4139. legend: {
  4140. prefix: '图例分类有:'
  4141. }
  4142. };
  4143. var getPixelRatio$1 = getPixelRatio,
  4144. getDomById$1 = getDomById,
  4145. getWidth$1 = getWidth,
  4146. getHeight$1 = getHeight,
  4147. isCanvasElement$1 = isCanvasElement;
  4148. var Canvas = /*#__PURE__*/function (_EventEmit) {
  4149. _inherits$1(Canvas, _EventEmit);
  4150. var _super = _createSuper$1(Canvas);
  4151. function Canvas(cfg) {
  4152. var _this;
  4153. _classCallCheck$1(this, Canvas);
  4154. _this = _super.call(this);
  4155. var title = cfg.title;
  4156. var ariaLabel = title ? substitute(lang.general.withTitle, {
  4157. title: title
  4158. }) : lang.general.title;
  4159. _this._attrs = mix({
  4160. type: 'canvas',
  4161. children: [],
  4162. ariaLabel: ariaLabel
  4163. }, cfg);
  4164. _this._initPixelRatio();
  4165. _this._initCanvas();
  4166. return _this;
  4167. }
  4168. /* eslint-enable */
  4169. _createClass$1(Canvas, [{
  4170. key: "get",
  4171. value: function get(name) {
  4172. return this._attrs[name];
  4173. }
  4174. }, {
  4175. key: "set",
  4176. value: function set(name, value) {
  4177. this._attrs[name] = value;
  4178. }
  4179. }, {
  4180. key: "_initPixelRatio",
  4181. value: function _initPixelRatio() {
  4182. var pixelRatio = this.get('pixelRatio');
  4183. if (!pixelRatio) {
  4184. this.set('pixelRatio', getPixelRatio$1());
  4185. }
  4186. }
  4187. }, {
  4188. key: "beforeDraw",
  4189. value: function beforeDraw() {
  4190. var context = this._attrs.context;
  4191. var el = this._attrs.el;
  4192. context && context.clearRect && context.clearRect(0, 0, el.width, el.height);
  4193. }
  4194. }, {
  4195. key: "_initCanvas",
  4196. value: function _initCanvas() {
  4197. var el = this.get('el');
  4198. var context = this.get('context');
  4199. if (!el && !context) {
  4200. throw new Error('Please specify the id, el or context of the chart!');
  4201. }
  4202. var canvas;
  4203. if (el) {
  4204. // DOMElement or String
  4205. canvas = isString(el) ? getDomById$1(el) : el;
  4206. } else {
  4207. // 说明没有指定el
  4208. canvas = CanvasElement$1.create(context);
  4209. }
  4210. if (context && canvas && !canvas.getContext) {
  4211. canvas.getContext = function () {
  4212. return context;
  4213. };
  4214. }
  4215. var width = this.get('width') || getWidth$1(canvas) || canvas.width;
  4216. var height = this.get('height') || getHeight$1(canvas) || canvas.height;
  4217. this.set('canvas', this);
  4218. this.set('el', canvas);
  4219. this.set('context', context || canvas.getContext('2d'));
  4220. this.changeSize(width, height); // 初始化事件控制器
  4221. var eventController = new EventController({
  4222. canvas: this,
  4223. el: canvas
  4224. });
  4225. this.set('eventController', eventController);
  4226. }
  4227. }, {
  4228. key: "changeSize",
  4229. value: function changeSize(width, height) {
  4230. var pixelRatio = this.get('pixelRatio');
  4231. var canvasDOM = this.get('el'); // HTMLCanvasElement or canvasElement
  4232. // 浏览器环境设置style样式
  4233. if (canvasDOM.style) {
  4234. canvasDOM.style.width = width + 'px';
  4235. canvasDOM.style.height = height + 'px';
  4236. }
  4237. if (isCanvasElement$1(canvasDOM)) {
  4238. canvasDOM.width = width * pixelRatio;
  4239. canvasDOM.height = height * pixelRatio;
  4240. if (pixelRatio !== 1) {
  4241. var ctx = this.get('context');
  4242. ctx.scale(pixelRatio, pixelRatio);
  4243. }
  4244. }
  4245. this.set('width', width);
  4246. this.set('height', height);
  4247. }
  4248. }, {
  4249. key: "getWidth",
  4250. value: function getWidth() {
  4251. var pixelRatio = this.get('pixelRatio');
  4252. var width = this.get('width');
  4253. return width * pixelRatio;
  4254. }
  4255. }, {
  4256. key: "getHeight",
  4257. value: function getHeight() {
  4258. var pixelRatio = this.get('pixelRatio');
  4259. var height = this.get('height');
  4260. return height * pixelRatio;
  4261. }
  4262. }, {
  4263. key: "getPointByClient",
  4264. value: function getPointByClient(clientX, clientY) {
  4265. var el = this.get('el');
  4266. var bbox = el.getBoundingClientRect();
  4267. var width = bbox.right - bbox.left;
  4268. var height = bbox.bottom - bbox.top;
  4269. return {
  4270. x: (clientX - bbox.left) * (el.width / width),
  4271. y: (clientY - bbox.top) * (el.height / height)
  4272. };
  4273. }
  4274. }, {
  4275. key: "_beginDraw",
  4276. value: function _beginDraw() {
  4277. this._attrs.toDraw = true;
  4278. }
  4279. }, {
  4280. key: "_endDraw",
  4281. value: function _endDraw() {
  4282. this._attrs.toDraw = false;
  4283. }
  4284. }, {
  4285. key: "draw",
  4286. value: function draw() {
  4287. var _this2 = this;
  4288. var drawInner = function drawInner() {
  4289. _this2.set('animateHandler', requestAnimationFrame$1(function () {
  4290. _this2.set('animateHandler', undefined);
  4291. if (_this2.get('toDraw')) {
  4292. drawInner();
  4293. }
  4294. }));
  4295. _this2.beforeDraw();
  4296. try {
  4297. var context = _this2._attrs.context;
  4298. _this2.drawChildren(context); // 支付宝,微信小程序,需要调context.draw才能完成绘制, 所以这里直接判断是否有.draw方法
  4299. if (context.draw) {
  4300. context.draw();
  4301. } // 设置无障碍文本
  4302. _this2.setAriaLabel();
  4303. } catch (ev) {
  4304. console.warn('error in draw canvas, detail as:');
  4305. console.warn(ev);
  4306. _this2._endDraw();
  4307. }
  4308. _this2._endDraw();
  4309. };
  4310. if (this.get('destroyed')) {
  4311. return;
  4312. }
  4313. if (this.get('animateHandler')) {
  4314. this._beginDraw();
  4315. } else {
  4316. drawInner();
  4317. }
  4318. } // 设置无障碍文本
  4319. }, {
  4320. key: "setAriaLabel",
  4321. value: function setAriaLabel() {
  4322. var el = this._attrs.el;
  4323. var ariaLabel = this._getAriaLabel();
  4324. if (ariaLabel && el.setAttribute) {
  4325. el.setAttribute('aria-label', ariaLabel);
  4326. }
  4327. }
  4328. }, {
  4329. key: "destroy",
  4330. value: function destroy() {
  4331. if (this.get('destroyed')) {
  4332. return;
  4333. } // 需要清理 canvas 画布内容,否则会导致 spa 应用 ios 下 canvas 白屏
  4334. // https://stackoverflow.com/questions/52532614/total-canvas-memory-use-exceeds-the-maximum-limit-safari-12
  4335. // https://github.com/antvis/F2/issues/630
  4336. var el = this.get('el');
  4337. el.width = 0;
  4338. el.height = 0;
  4339. this.clear();
  4340. this._attrs = {};
  4341. this.set('destroyed', true);
  4342. }
  4343. }, {
  4344. key: "isDestroyed",
  4345. value: function isDestroyed() {
  4346. return this.get('destroyed');
  4347. }
  4348. }]);
  4349. return Canvas;
  4350. }(EventEmit); // @ts-ignore
  4351. mix(Canvas.prototype, Container, {
  4352. getGroupClass: function getGroupClass() {
  4353. return Group;
  4354. }
  4355. });
  4356. var engines = {};
  4357. function getEngine(name) {
  4358. var G = engines[name];
  4359. if (G) {
  4360. return G;
  4361. }
  4362. return {
  4363. Canvas: Canvas,
  4364. Group: Group,
  4365. Shape: Shape
  4366. };
  4367. }
  4368. function createCanvas(cfg) {
  4369. var renderer = cfg.renderer;
  4370. var G = getEngine(renderer);
  4371. return new G.Canvas(cfg);
  4372. }
  4373. var arrayWithHoles = createCommonjsModule(function (module) {
  4374. function _arrayWithHoles(arr) {
  4375. if (Array.isArray(arr)) return arr;
  4376. }
  4377. module.exports = _arrayWithHoles, module.exports.__esModule = true, module.exports["default"] = module.exports;
  4378. });
  4379. var iterableToArrayLimit = createCommonjsModule(function (module) {
  4380. function _iterableToArrayLimit(arr, i) {
  4381. var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
  4382. if (_i == null) return;
  4383. var _arr = [];
  4384. var _n = true;
  4385. var _d = false;
  4386. var _s, _e;
  4387. try {
  4388. for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
  4389. _arr.push(_s.value);
  4390. if (i && _arr.length === i) break;
  4391. }
  4392. } catch (err) {
  4393. _d = true;
  4394. _e = err;
  4395. } finally {
  4396. try {
  4397. if (!_n && _i["return"] != null) _i["return"]();
  4398. } finally {
  4399. if (_d) throw _e;
  4400. }
  4401. }
  4402. return _arr;
  4403. }
  4404. module.exports = _iterableToArrayLimit, module.exports.__esModule = true, module.exports["default"] = module.exports;
  4405. });
  4406. var arrayLikeToArray = createCommonjsModule(function (module) {
  4407. function _arrayLikeToArray(arr, len) {
  4408. if (len == null || len > arr.length) len = arr.length;
  4409. for (var i = 0, arr2 = new Array(len); i < len; i++) {
  4410. arr2[i] = arr[i];
  4411. }
  4412. return arr2;
  4413. }
  4414. module.exports = _arrayLikeToArray, module.exports.__esModule = true, module.exports["default"] = module.exports;
  4415. });
  4416. var unsupportedIterableToArray = createCommonjsModule(function (module) {
  4417. function _unsupportedIterableToArray(o, minLen) {
  4418. if (!o) return;
  4419. if (typeof o === "string") return arrayLikeToArray(o, minLen);
  4420. var n = Object.prototype.toString.call(o).slice(8, -1);
  4421. if (n === "Object" && o.constructor) n = o.constructor.name;
  4422. if (n === "Map" || n === "Set") return Array.from(o);
  4423. if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return arrayLikeToArray(o, minLen);
  4424. }
  4425. module.exports = _unsupportedIterableToArray, module.exports.__esModule = true, module.exports["default"] = module.exports;
  4426. });
  4427. var nonIterableRest = createCommonjsModule(function (module) {
  4428. function _nonIterableRest() {
  4429. throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
  4430. }
  4431. module.exports = _nonIterableRest, module.exports.__esModule = true, module.exports["default"] = module.exports;
  4432. });
  4433. var slicedToArray = createCommonjsModule(function (module) {
  4434. function _slicedToArray(arr, i) {
  4435. return arrayWithHoles(arr) || iterableToArrayLimit(arr, i) || unsupportedIterableToArray(arr, i) || nonIterableRest();
  4436. }
  4437. module.exports = _slicedToArray, module.exports.__esModule = true, module.exports["default"] = module.exports;
  4438. });
  4439. var _slicedToArray = /*@__PURE__*/getDefaultExportFromCjs(slicedToArray);
  4440. var Layout = /*#__PURE__*/function () {
  4441. function Layout(layout) {
  4442. _classCallCheck(this, Layout);
  4443. this.left = 0;
  4444. this.top = 0;
  4445. this.width = 0;
  4446. this.height = 0;
  4447. this.update(layout);
  4448. }
  4449. _createClass(Layout, [{
  4450. key: "update",
  4451. value: function update(layout) {
  4452. mix(this, layout);
  4453. var left = this.left,
  4454. top = this.top,
  4455. width = this.width,
  4456. height = this.height;
  4457. this.right = left + width;
  4458. this.bottom = top + height;
  4459. return this;
  4460. }
  4461. }, {
  4462. key: "padding",
  4463. value: function padding(style) {
  4464. if (!style) {
  4465. return this;
  4466. }
  4467. var _style$top = style.top,
  4468. paddingTop = _style$top === void 0 ? 0 : _style$top,
  4469. _style$right = style.right,
  4470. paddingRight = _style$right === void 0 ? 0 : _style$right,
  4471. _style$bottom = style.bottom,
  4472. paddingBottom = _style$bottom === void 0 ? 0 : _style$bottom,
  4473. _style$left = style.left,
  4474. paddingLeft = _style$left === void 0 ? 0 : _style$left;
  4475. var top = this.top,
  4476. right = this.right,
  4477. bottom = this.bottom,
  4478. left = this.left;
  4479. this.top = top + paddingTop;
  4480. this.right = right - paddingRight;
  4481. this.bottom = bottom - paddingBottom;
  4482. this.left = left + paddingLeft;
  4483. this.width = this.right - this.left;
  4484. this.height = this.bottom - this.top;
  4485. return this;
  4486. }
  4487. }, {
  4488. key: "clone",
  4489. value: function clone() {
  4490. var left = this.left,
  4491. top = this.top,
  4492. width = this.width,
  4493. height = this.height;
  4494. return new Layout({
  4495. left: left,
  4496. top: top,
  4497. width: width,
  4498. height: height
  4499. });
  4500. }
  4501. }], [{
  4502. key: "fromStyle",
  4503. value: function fromStyle(style) {
  4504. var left = style.left,
  4505. top = style.top,
  4506. width = style.width,
  4507. height = style.height,
  4508. padding = style.padding;
  4509. var _padding = _slicedToArray(padding, 4),
  4510. paddingTop = _padding[0],
  4511. paddingRight = _padding[1],
  4512. paddingBottom = _padding[2],
  4513. paddingLeft = _padding[3];
  4514. return new Layout({
  4515. left: left + paddingLeft,
  4516. top: top + paddingTop,
  4517. width: width - paddingLeft - paddingRight,
  4518. height: height - paddingTop - paddingBottom
  4519. });
  4520. }
  4521. }]);
  4522. return Layout;
  4523. }();
  4524. function objToString(obj) {
  4525. return Object.prototype.toString.call(obj);
  4526. }
  4527. function objectKeys(obj) {
  4528. return Object.keys(obj);
  4529. }
  4530. function equal(a, b) {
  4531. if (a === b) return true;
  4532. if (_typeof(a) !== _typeof(b)) {
  4533. return false;
  4534. } // null 和 undefined
  4535. if (a == null || b == null) {
  4536. return false;
  4537. } // 特殊处理NaN
  4538. if (Number.isNaN(a) && Number.isNaN(b)) {
  4539. return true;
  4540. }
  4541. if (objToString(a) !== objToString(b)) {
  4542. return false;
  4543. } // 如果是function, 则认为是相对
  4544. if (isFunction(a)) {
  4545. return true;
  4546. } // 值类型,Number String Boolean
  4547. if (_typeof(a) !== 'object') {
  4548. return false;
  4549. }
  4550. if (isArray(a)) {
  4551. if (a.length !== b.length) {
  4552. return false;
  4553. }
  4554. for (var i = a.length - 1; i >= 0; i--) {
  4555. if (!equal(a[i], b[i])) {
  4556. return false;
  4557. }
  4558. }
  4559. return true;
  4560. }
  4561. if (!isPlainObject(a)) {
  4562. return false;
  4563. }
  4564. var ka = objectKeys(a);
  4565. var kb = objectKeys(b); // having the same number of owned properties (keys incorporates hasOwnProperty)
  4566. if (ka.length !== kb.length) {
  4567. return false;
  4568. } // the same set of keys (although not necessarily the same order),
  4569. ka.sort();
  4570. kb.sort(); // ~~~cheap key test
  4571. for (var _i = ka.length - 1; _i >= 0; _i--) {
  4572. if (ka[_i] != kb[_i]) {
  4573. return false;
  4574. }
  4575. } // equivalent values for every corresponding key, and ~~~possibly expensive deep test
  4576. for (var _i2 = ka.length - 1; _i2 >= 0; _i2--) {
  4577. var key = ka[_i2];
  4578. if (!equal(a[key], b[key])) {
  4579. return false;
  4580. }
  4581. }
  4582. return true;
  4583. }
  4584. var requestAnimationFrame$2 = (typeof window === "undefined" ? "undefined" : _typeof(window)) === 'object' && window.requestAnimationFrame ? window.requestAnimationFrame : function (fn) {
  4585. return setTimeout(fn, 16);
  4586. };
  4587. var cancelAnimationFrame$1 = (typeof window === "undefined" ? "undefined" : _typeof(window)) === 'object' && window.cancelAnimationFrame ? window.cancelAnimationFrame : function (number) {
  4588. return clearTimeout(number);
  4589. };
  4590. var clock = (typeof performance === "undefined" ? "undefined" : _typeof(performance)) === 'object' && performance.now ? performance : Date;
  4591. var Timeline$1 = /*#__PURE__*/function () {
  4592. function Timeline() {
  4593. _classCallCheck(this, Timeline);
  4594. this.playing = false; // 暂停中
  4595. this.paused = false; // 暂停的时间点
  4596. this.pausedTime = 0;
  4597. }
  4598. _createClass(Timeline, [{
  4599. key: "play",
  4600. value: function play(duration, onUpdate, onEnd) {
  4601. var _this = this;
  4602. if (duration <= 0) {
  4603. onEnd();
  4604. return;
  4605. } // 上次动画未结束
  4606. if (this.playing) {
  4607. return;
  4608. } // 记录 duration、onUpdate、onEnd
  4609. this.duration = duration;
  4610. this.onUpdate = onUpdate;
  4611. this.onEnd = onEnd;
  4612. var paused = this.paused,
  4613. pausedTime = this.pausedTime;
  4614. this.playing = true;
  4615. var startTime = clock.now(); // 如果当前正在暂停状态, 从暂停态继续播放
  4616. if (paused && pausedTime) {
  4617. startTime = startTime - pausedTime;
  4618. this.paused = false;
  4619. this.pausedTime = 0;
  4620. }
  4621. var play = function play() {
  4622. var now = clock.now();
  4623. var time = now - startTime;
  4624. if (time >= duration) {
  4625. onUpdate(duration);
  4626. onEnd();
  4627. _this.playing = false;
  4628. return;
  4629. }
  4630. if (_this.paused) {
  4631. onUpdate(time);
  4632. _this.pausedTime = time;
  4633. _this.playing = false;
  4634. return;
  4635. }
  4636. onUpdate(time);
  4637. _this.animationFrameNumber = requestAnimationFrame$2(play);
  4638. };
  4639. this.animationFrameNumber = requestAnimationFrame$2(play);
  4640. }
  4641. }, {
  4642. key: "pause",
  4643. value: function pause() {
  4644. this.paused = true;
  4645. }
  4646. }, {
  4647. key: "stop",
  4648. value: function stop() {
  4649. this.playing = false;
  4650. }
  4651. }, {
  4652. key: "end",
  4653. value: function end() {
  4654. if (!this.playing) {
  4655. return;
  4656. } // 停掉动画
  4657. this.abort(); // 更新到最后一帧状态
  4658. this.onUpdate(this.duration);
  4659. this.onEnd();
  4660. }
  4661. }, {
  4662. key: "abort",
  4663. value: function abort() {
  4664. if (!this.animationFrameNumber) {
  4665. return;
  4666. }
  4667. cancelAnimationFrame$1(this.animationFrameNumber);
  4668. this.playing = false;
  4669. this.animationFrameNumber = null;
  4670. }
  4671. }]);
  4672. return Timeline;
  4673. }();
  4674. function define (constructor, factory, prototype) {
  4675. constructor.prototype = factory.prototype = prototype;
  4676. prototype.constructor = constructor;
  4677. }
  4678. function extend(parent, definition) {
  4679. var prototype = Object.create(parent.prototype);
  4680. for (var key in definition) {
  4681. prototype[key] = definition[key];
  4682. }
  4683. return prototype;
  4684. }
  4685. function Color() {}
  4686. var _darker = 0.7;
  4687. var _brighter = 1 / _darker;
  4688. var reI = "\\s*([+-]?\\d+)\\s*",
  4689. reN = "\\s*([+-]?\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)\\s*",
  4690. reP = "\\s*([+-]?\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)%\\s*",
  4691. reHex = /^#([0-9a-f]{3,8})$/,
  4692. reRgbInteger = new RegExp("^rgb\\(" + [reI, reI, reI] + "\\)$"),
  4693. reRgbPercent = new RegExp("^rgb\\(" + [reP, reP, reP] + "\\)$"),
  4694. reRgbaInteger = new RegExp("^rgba\\(" + [reI, reI, reI, reN] + "\\)$"),
  4695. reRgbaPercent = new RegExp("^rgba\\(" + [reP, reP, reP, reN] + "\\)$"),
  4696. reHslPercent = new RegExp("^hsl\\(" + [reN, reP, reP] + "\\)$"),
  4697. reHslaPercent = new RegExp("^hsla\\(" + [reN, reP, reP, reN] + "\\)$");
  4698. var named = {
  4699. aliceblue: 0xf0f8ff,
  4700. antiquewhite: 0xfaebd7,
  4701. aqua: 0x00ffff,
  4702. aquamarine: 0x7fffd4,
  4703. azure: 0xf0ffff,
  4704. beige: 0xf5f5dc,
  4705. bisque: 0xffe4c4,
  4706. black: 0x000000,
  4707. blanchedalmond: 0xffebcd,
  4708. blue: 0x0000ff,
  4709. blueviolet: 0x8a2be2,
  4710. brown: 0xa52a2a,
  4711. burlywood: 0xdeb887,
  4712. cadetblue: 0x5f9ea0,
  4713. chartreuse: 0x7fff00,
  4714. chocolate: 0xd2691e,
  4715. coral: 0xff7f50,
  4716. cornflowerblue: 0x6495ed,
  4717. cornsilk: 0xfff8dc,
  4718. crimson: 0xdc143c,
  4719. cyan: 0x00ffff,
  4720. darkblue: 0x00008b,
  4721. darkcyan: 0x008b8b,
  4722. darkgoldenrod: 0xb8860b,
  4723. darkgray: 0xa9a9a9,
  4724. darkgreen: 0x006400,
  4725. darkgrey: 0xa9a9a9,
  4726. darkkhaki: 0xbdb76b,
  4727. darkmagenta: 0x8b008b,
  4728. darkolivegreen: 0x556b2f,
  4729. darkorange: 0xff8c00,
  4730. darkorchid: 0x9932cc,
  4731. darkred: 0x8b0000,
  4732. darksalmon: 0xe9967a,
  4733. darkseagreen: 0x8fbc8f,
  4734. darkslateblue: 0x483d8b,
  4735. darkslategray: 0x2f4f4f,
  4736. darkslategrey: 0x2f4f4f,
  4737. darkturquoise: 0x00ced1,
  4738. darkviolet: 0x9400d3,
  4739. deeppink: 0xff1493,
  4740. deepskyblue: 0x00bfff,
  4741. dimgray: 0x696969,
  4742. dimgrey: 0x696969,
  4743. dodgerblue: 0x1e90ff,
  4744. firebrick: 0xb22222,
  4745. floralwhite: 0xfffaf0,
  4746. forestgreen: 0x228b22,
  4747. fuchsia: 0xff00ff,
  4748. gainsboro: 0xdcdcdc,
  4749. ghostwhite: 0xf8f8ff,
  4750. gold: 0xffd700,
  4751. goldenrod: 0xdaa520,
  4752. gray: 0x808080,
  4753. green: 0x008000,
  4754. greenyellow: 0xadff2f,
  4755. grey: 0x808080,
  4756. honeydew: 0xf0fff0,
  4757. hotpink: 0xff69b4,
  4758. indianred: 0xcd5c5c,
  4759. indigo: 0x4b0082,
  4760. ivory: 0xfffff0,
  4761. khaki: 0xf0e68c,
  4762. lavender: 0xe6e6fa,
  4763. lavenderblush: 0xfff0f5,
  4764. lawngreen: 0x7cfc00,
  4765. lemonchiffon: 0xfffacd,
  4766. lightblue: 0xadd8e6,
  4767. lightcoral: 0xf08080,
  4768. lightcyan: 0xe0ffff,
  4769. lightgoldenrodyellow: 0xfafad2,
  4770. lightgray: 0xd3d3d3,
  4771. lightgreen: 0x90ee90,
  4772. lightgrey: 0xd3d3d3,
  4773. lightpink: 0xffb6c1,
  4774. lightsalmon: 0xffa07a,
  4775. lightseagreen: 0x20b2aa,
  4776. lightskyblue: 0x87cefa,
  4777. lightslategray: 0x778899,
  4778. lightslategrey: 0x778899,
  4779. lightsteelblue: 0xb0c4de,
  4780. lightyellow: 0xffffe0,
  4781. lime: 0x00ff00,
  4782. limegreen: 0x32cd32,
  4783. linen: 0xfaf0e6,
  4784. magenta: 0xff00ff,
  4785. maroon: 0x800000,
  4786. mediumaquamarine: 0x66cdaa,
  4787. mediumblue: 0x0000cd,
  4788. mediumorchid: 0xba55d3,
  4789. mediumpurple: 0x9370db,
  4790. mediumseagreen: 0x3cb371,
  4791. mediumslateblue: 0x7b68ee,
  4792. mediumspringgreen: 0x00fa9a,
  4793. mediumturquoise: 0x48d1cc,
  4794. mediumvioletred: 0xc71585,
  4795. midnightblue: 0x191970,
  4796. mintcream: 0xf5fffa,
  4797. mistyrose: 0xffe4e1,
  4798. moccasin: 0xffe4b5,
  4799. navajowhite: 0xffdead,
  4800. navy: 0x000080,
  4801. oldlace: 0xfdf5e6,
  4802. olive: 0x808000,
  4803. olivedrab: 0x6b8e23,
  4804. orange: 0xffa500,
  4805. orangered: 0xff4500,
  4806. orchid: 0xda70d6,
  4807. palegoldenrod: 0xeee8aa,
  4808. palegreen: 0x98fb98,
  4809. paleturquoise: 0xafeeee,
  4810. palevioletred: 0xdb7093,
  4811. papayawhip: 0xffefd5,
  4812. peachpuff: 0xffdab9,
  4813. peru: 0xcd853f,
  4814. pink: 0xffc0cb,
  4815. plum: 0xdda0dd,
  4816. powderblue: 0xb0e0e6,
  4817. purple: 0x800080,
  4818. rebeccapurple: 0x663399,
  4819. red: 0xff0000,
  4820. rosybrown: 0xbc8f8f,
  4821. royalblue: 0x4169e1,
  4822. saddlebrown: 0x8b4513,
  4823. salmon: 0xfa8072,
  4824. sandybrown: 0xf4a460,
  4825. seagreen: 0x2e8b57,
  4826. seashell: 0xfff5ee,
  4827. sienna: 0xa0522d,
  4828. silver: 0xc0c0c0,
  4829. skyblue: 0x87ceeb,
  4830. slateblue: 0x6a5acd,
  4831. slategray: 0x708090,
  4832. slategrey: 0x708090,
  4833. snow: 0xfffafa,
  4834. springgreen: 0x00ff7f,
  4835. steelblue: 0x4682b4,
  4836. tan: 0xd2b48c,
  4837. teal: 0x008080,
  4838. thistle: 0xd8bfd8,
  4839. tomato: 0xff6347,
  4840. turquoise: 0x40e0d0,
  4841. violet: 0xee82ee,
  4842. wheat: 0xf5deb3,
  4843. white: 0xffffff,
  4844. whitesmoke: 0xf5f5f5,
  4845. yellow: 0xffff00,
  4846. yellowgreen: 0x9acd32
  4847. };
  4848. define(Color, color, {
  4849. copy: function copy(channels) {
  4850. return Object.assign(new this.constructor(), this, channels);
  4851. },
  4852. displayable: function displayable() {
  4853. return this.rgb().displayable();
  4854. },
  4855. hex: color_formatHex,
  4856. // Deprecated! Use color.formatHex.
  4857. formatHex: color_formatHex,
  4858. formatHsl: color_formatHsl,
  4859. formatRgb: color_formatRgb,
  4860. toString: color_formatRgb
  4861. });
  4862. function color_formatHex() {
  4863. return this.rgb().formatHex();
  4864. }
  4865. function color_formatHsl() {
  4866. return hslConvert(this).formatHsl();
  4867. }
  4868. function color_formatRgb() {
  4869. return this.rgb().formatRgb();
  4870. }
  4871. function color(format) {
  4872. var m, l;
  4873. format = (format + "").trim().toLowerCase();
  4874. return (m = reHex.exec(format)) ? (l = m[1].length, m = parseInt(m[1], 16), l === 6 ? rgbn(m) // #ff0000
  4875. : l === 3 ? new Rgb(m >> 8 & 0xf | m >> 4 & 0xf0, m >> 4 & 0xf | m & 0xf0, (m & 0xf) << 4 | m & 0xf, 1) // #f00
  4876. : l === 8 ? rgba(m >> 24 & 0xff, m >> 16 & 0xff, m >> 8 & 0xff, (m & 0xff) / 0xff) // #ff000000
  4877. : 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
  4878. : null // invalid hex
  4879. ) : (m = reRgbInteger.exec(format)) ? new Rgb(m[1], m[2], m[3], 1) // rgb(255, 0, 0)
  4880. : (m = reRgbPercent.exec(format)) ? new Rgb(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, 1) // rgb(100%, 0%, 0%)
  4881. : (m = reRgbaInteger.exec(format)) ? rgba(m[1], m[2], m[3], m[4]) // rgba(255, 0, 0, 1)
  4882. : (m = reRgbaPercent.exec(format)) ? rgba(m[1] * 255 / 100, m[2] * 255 / 100, m[3] * 255 / 100, m[4]) // rgb(100%, 0%, 0%, 1)
  4883. : (m = reHslPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, 1) // hsl(120, 50%, 50%)
  4884. : (m = reHslaPercent.exec(format)) ? hsla(m[1], m[2] / 100, m[3] / 100, m[4]) // hsla(120, 50%, 50%, 1)
  4885. : named.hasOwnProperty(format) ? rgbn(named[format]) // eslint-disable-line no-prototype-builtins
  4886. : format === "transparent" ? new Rgb(NaN, NaN, NaN, 0) : null;
  4887. }
  4888. function rgbn(n) {
  4889. return new Rgb(n >> 16 & 0xff, n >> 8 & 0xff, n & 0xff, 1);
  4890. }
  4891. function rgba(r, g, b, a) {
  4892. if (a <= 0) r = g = b = NaN;
  4893. return new Rgb(r, g, b, a);
  4894. }
  4895. function rgbConvert(o) {
  4896. if (!(o instanceof Color)) o = color(o);
  4897. if (!o) return new Rgb();
  4898. o = o.rgb();
  4899. return new Rgb(o.r, o.g, o.b, o.opacity);
  4900. }
  4901. function rgb(r, g, b, opacity) {
  4902. return arguments.length === 1 ? rgbConvert(r) : new Rgb(r, g, b, opacity == null ? 1 : opacity);
  4903. }
  4904. function Rgb(r, g, b, opacity) {
  4905. this.r = +r;
  4906. this.g = +g;
  4907. this.b = +b;
  4908. this.opacity = +opacity;
  4909. }
  4910. define(Rgb, rgb, extend(Color, {
  4911. brighter: function brighter(k) {
  4912. k = k == null ? _brighter : Math.pow(_brighter, k);
  4913. return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);
  4914. },
  4915. darker: function darker(k) {
  4916. k = k == null ? _darker : Math.pow(_darker, k);
  4917. return new Rgb(this.r * k, this.g * k, this.b * k, this.opacity);
  4918. },
  4919. rgb: function rgb() {
  4920. return this;
  4921. },
  4922. displayable: function displayable() {
  4923. 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;
  4924. },
  4925. hex: rgb_formatHex,
  4926. // Deprecated! Use color.formatHex.
  4927. formatHex: rgb_formatHex,
  4928. formatRgb: rgb_formatRgb,
  4929. toString: rgb_formatRgb
  4930. }));
  4931. function rgb_formatHex() {
  4932. return "#" + hex(this.r) + hex(this.g) + hex(this.b);
  4933. }
  4934. function rgb_formatRgb() {
  4935. var a = this.opacity;
  4936. a = isNaN(a) ? 1 : Math.max(0, Math.min(1, a));
  4937. 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 + ")");
  4938. }
  4939. function hex(value) {
  4940. value = Math.max(0, Math.min(255, Math.round(value) || 0));
  4941. return (value < 16 ? "0" : "") + value.toString(16);
  4942. }
  4943. function hsla(h, s, l, a) {
  4944. if (a <= 0) h = s = l = NaN;else if (l <= 0 || l >= 1) h = s = NaN;else if (s <= 0) h = NaN;
  4945. return new Hsl(h, s, l, a);
  4946. }
  4947. function hslConvert(o) {
  4948. if (o instanceof Hsl) return new Hsl(o.h, o.s, o.l, o.opacity);
  4949. if (!(o instanceof Color)) o = color(o);
  4950. if (!o) return new Hsl();
  4951. if (o instanceof Hsl) return o;
  4952. o = o.rgb();
  4953. var r = o.r / 255,
  4954. g = o.g / 255,
  4955. b = o.b / 255,
  4956. min = Math.min(r, g, b),
  4957. max = Math.max(r, g, b),
  4958. h = NaN,
  4959. s = max - min,
  4960. l = (max + min) / 2;
  4961. if (s) {
  4962. 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;
  4963. s /= l < 0.5 ? max + min : 2 - max - min;
  4964. h *= 60;
  4965. } else {
  4966. s = l > 0 && l < 1 ? 0 : h;
  4967. }
  4968. return new Hsl(h, s, l, o.opacity);
  4969. }
  4970. function hsl(h, s, l, opacity) {
  4971. return arguments.length === 1 ? hslConvert(h) : new Hsl(h, s, l, opacity == null ? 1 : opacity);
  4972. }
  4973. function Hsl(h, s, l, opacity) {
  4974. this.h = +h;
  4975. this.s = +s;
  4976. this.l = +l;
  4977. this.opacity = +opacity;
  4978. }
  4979. define(Hsl, hsl, extend(Color, {
  4980. brighter: function brighter(k) {
  4981. k = k == null ? _brighter : Math.pow(_brighter, k);
  4982. return new Hsl(this.h, this.s, this.l * k, this.opacity);
  4983. },
  4984. darker: function darker(k) {
  4985. k = k == null ? _darker : Math.pow(_darker, k);
  4986. return new Hsl(this.h, this.s, this.l * k, this.opacity);
  4987. },
  4988. rgb: function rgb() {
  4989. var h = this.h % 360 + (this.h < 0) * 360,
  4990. s = isNaN(h) || isNaN(this.s) ? 0 : this.s,
  4991. l = this.l,
  4992. m2 = l + (l < 0.5 ? l : 1 - l) * s,
  4993. m1 = 2 * l - m2;
  4994. 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);
  4995. },
  4996. displayable: function displayable() {
  4997. return (0 <= this.s && this.s <= 1 || isNaN(this.s)) && 0 <= this.l && this.l <= 1 && 0 <= this.opacity && this.opacity <= 1;
  4998. },
  4999. formatHsl: function formatHsl() {
  5000. var a = this.opacity;
  5001. a = isNaN(a) ? 1 : Math.max(0, Math.min(1, a));
  5002. return (a === 1 ? "hsl(" : "hsla(") + (this.h || 0) + ", " + (this.s || 0) * 100 + "%, " + (this.l || 0) * 100 + "%" + (a === 1 ? ")" : ", " + a + ")");
  5003. }
  5004. }));
  5005. /* From FvD 13.37, CSS Color Module Level 3 */
  5006. function hsl2rgb(h, m1, m2) {
  5007. return (h < 60 ? m1 + (m2 - m1) * h / 60 : h < 180 ? m2 : h < 240 ? m1 + (m2 - m1) * (240 - h) / 60 : m1) * 255;
  5008. }
  5009. var constant = (function (x) {
  5010. return function () {
  5011. return x;
  5012. };
  5013. });
  5014. function linear(a, d) {
  5015. return function (t) {
  5016. return a + t * d;
  5017. };
  5018. }
  5019. function exponential(a, b, y) {
  5020. return a = Math.pow(a, y), b = Math.pow(b, y) - a, y = 1 / y, function (t) {
  5021. return Math.pow(a + t * b, y);
  5022. };
  5023. }
  5024. function gamma(y) {
  5025. return (y = +y) === 1 ? nogamma : function (a, b) {
  5026. return b - a ? exponential(a, b, y) : constant(isNaN(a) ? b : a);
  5027. };
  5028. }
  5029. function nogamma(a, b) {
  5030. var d = b - a;
  5031. return d ? linear(a, d) : constant(isNaN(a) ? b : a);
  5032. }
  5033. var interpolateRgb = (function rgbGamma(y) {
  5034. var color = gamma(y);
  5035. function rgb$1(start, end) {
  5036. var r = color((start = rgb(start)).r, (end = rgb(end)).r),
  5037. g = color(start.g, end.g),
  5038. b = color(start.b, end.b),
  5039. opacity = nogamma(start.opacity, end.opacity);
  5040. return function (t) {
  5041. start.r = r(t);
  5042. start.g = g(t);
  5043. start.b = b(t);
  5044. start.opacity = opacity(t);
  5045. return start + '';
  5046. };
  5047. }
  5048. rgb$1.gamma = rgbGamma;
  5049. return rgb$1;
  5050. })(1);
  5051. function interpolateNumberArray (a, b) {
  5052. if (!b) b = [];
  5053. var n = a ? Math.min(b.length, a.length) : 0,
  5054. c = b.slice(),
  5055. i;
  5056. return function (t) {
  5057. for (i = 0; i < n; ++i) {
  5058. c[i] = a[i] * (1 - t) + b[i] * t;
  5059. }
  5060. return c;
  5061. };
  5062. }
  5063. function isNumberArray(x) {
  5064. return ArrayBuffer.isView(x) && !(x instanceof DataView);
  5065. }
  5066. function genericArray(a, b) {
  5067. var nb = b ? b.length : 0,
  5068. na = a ? Math.min(nb, a.length) : 0,
  5069. x = new Array(na),
  5070. c = new Array(nb),
  5071. i;
  5072. for (i = 0; i < na; ++i) {
  5073. x[i] = interpolate(a[i], b[i]);
  5074. }
  5075. for (; i < nb; ++i) {
  5076. c[i] = b[i];
  5077. }
  5078. return function (t) {
  5079. for (i = 0; i < na; ++i) {
  5080. c[i] = x[i](t);
  5081. }
  5082. return c;
  5083. };
  5084. }
  5085. function date (a, b) {
  5086. var d = new Date();
  5087. return a = +a, b = +b, function (t) {
  5088. return d.setTime(a * (1 - t) + b * t), d;
  5089. };
  5090. }
  5091. function interpolateNumber (a, b) {
  5092. return a = +a, b = +b, function (t) {
  5093. return a * (1 - t) + b * t;
  5094. };
  5095. }
  5096. function interpolateObject (a, b) {
  5097. var i = {},
  5098. c = {},
  5099. k;
  5100. if (a === null || _typeof(a) !== "object") a = {};
  5101. if (b === null || _typeof(b) !== "object") b = {};
  5102. for (k in b) {
  5103. if (k in a) {
  5104. i[k] = interpolate(a[k], b[k]);
  5105. } else {
  5106. c[k] = b[k];
  5107. }
  5108. }
  5109. return function (t) {
  5110. for (k in i) {
  5111. c[k] = i[k](t);
  5112. }
  5113. return c;
  5114. };
  5115. }
  5116. var reA = /[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,
  5117. reB = new RegExp(reA.source, "g");
  5118. function zero(b) {
  5119. return function () {
  5120. return b;
  5121. };
  5122. }
  5123. function one(b) {
  5124. return function (t) {
  5125. return b(t) + "";
  5126. };
  5127. }
  5128. function string (a, b) {
  5129. var bi = reA.lastIndex = reB.lastIndex = 0,
  5130. // scan index for next number in b
  5131. am,
  5132. // current match in a
  5133. bm,
  5134. // current match in b
  5135. bs,
  5136. // string preceding current number in b, if any
  5137. i = -1,
  5138. // index in s
  5139. s = [],
  5140. // string constants and placeholders
  5141. q = []; // number interpolators
  5142. // Coerce inputs to strings.
  5143. a = a + "", b = b + ""; // Interpolate pairs of numbers in a & b.
  5144. while ((am = reA.exec(a)) && (bm = reB.exec(b))) {
  5145. if ((bs = bm.index) > bi) {
  5146. // a string precedes the next number in b
  5147. bs = b.slice(bi, bs);
  5148. if (s[i]) s[i] += bs; // coalesce with previous string
  5149. else s[++i] = bs;
  5150. }
  5151. if ((am = am[0]) === (bm = bm[0])) {
  5152. // numbers in a & b match
  5153. if (s[i]) s[i] += bm; // coalesce with previous string
  5154. else s[++i] = bm;
  5155. } else {
  5156. // interpolate non-matching numbers
  5157. s[++i] = null;
  5158. q.push({
  5159. i: i,
  5160. x: interpolateNumber(am, bm)
  5161. });
  5162. }
  5163. bi = reB.lastIndex;
  5164. } // Add remains of b.
  5165. if (bi < b.length) {
  5166. bs = b.slice(bi);
  5167. if (s[i]) s[i] += bs; // coalesce with previous string
  5168. else s[++i] = bs;
  5169. } // Special optimization for only a single match.
  5170. // Otherwise, interpolate each of the numbers and rejoin the string.
  5171. return s.length < 2 ? q[0] ? one(q[0].x) : zero(b) : (b = q.length, function (t) {
  5172. for (var i = 0, o; i < b; ++i) {
  5173. s[(o = q[i]).i] = o.x(t);
  5174. }
  5175. return s.join("");
  5176. });
  5177. }
  5178. function interpolate (a, b) {
  5179. var t = _typeof(b),
  5180. c;
  5181. 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);
  5182. }
  5183. function interpolateObjectArray(a, b) {
  5184. var na = a ? a.length : 0;
  5185. var nb = b ? b.length : 0;
  5186. var maxLen = Math.max(nb, na);
  5187. var c = new Array(maxLen);
  5188. var x = new Array(maxLen);
  5189. var i; // 将a、b长度补齐后再进行插值计算
  5190. for (i = 0; i < maxLen; i++) {
  5191. var ia = i < na ? (a || [])[i] : (a || [])[na - 1];
  5192. var ib = i < nb ? (b || [])[i] : (b || [])[nb - 1];
  5193. x[i] = interpolateObject(ia, ib);
  5194. }
  5195. return function (t) {
  5196. // 清除补间的多余点
  5197. if (t >= 1) {
  5198. return b;
  5199. }
  5200. for (i = 0; i < maxLen; ++i) {
  5201. c[i] = x[i](t);
  5202. }
  5203. return c;
  5204. };
  5205. }
  5206. var interpolate$1 = (function (a, b) {
  5207. if (typeof b === 'string') {
  5208. return interpolateRgb(a, b);
  5209. }
  5210. if (Array.isArray(b)) {
  5211. if (typeof b[0] !== 'number') {
  5212. // if (hasNaN(a[0])) {
  5213. // return interpolateObjectArray(b, b);
  5214. // }
  5215. return interpolateObjectArray(a, b);
  5216. }
  5217. return interpolateNumberArray(a, b);
  5218. } // if (isNaN(a)) {
  5219. // return interpolateNumber(b, b);
  5220. // }
  5221. return interpolateNumber(a, b);
  5222. });
  5223. // https://github.com/tweenjs/tween.js
  5224. function linear$1(k) {
  5225. return k;
  5226. }
  5227. function quadraticIn(k) {
  5228. return k * k;
  5229. }
  5230. function quadraticOut(k) {
  5231. return k * (2 - k);
  5232. }
  5233. function quadraticInOut(k) {
  5234. if ((k *= 2) < 1) {
  5235. return 0.5 * k * k;
  5236. }
  5237. return -0.5 * (--k * (k - 2) - 1);
  5238. }
  5239. function cubicIn(k) {
  5240. return k * k * k;
  5241. }
  5242. function cubicOut(k) {
  5243. return --k * k * k + 1;
  5244. }
  5245. function cubicInOut(k) {
  5246. if ((k *= 2) < 1) {
  5247. return 0.5 * k * k * k;
  5248. }
  5249. return 0.5 * ((k -= 2) * k * k + 2);
  5250. }
  5251. function quarticIn(k) {
  5252. return k * k * k * k;
  5253. }
  5254. function quarticOut(k) {
  5255. return 1 - k * k * k * k;
  5256. }
  5257. function quarticInOut(k) {
  5258. if ((k *= 2) < 1) {
  5259. return 0.5 * k * k * k * k;
  5260. }
  5261. return -0.5 * ((k -= 2) * k * k * k - 2);
  5262. }
  5263. function quinticIn(k) {
  5264. return k * k * k * k * k;
  5265. }
  5266. function quinticOut(k) {
  5267. return --k * k * k * k * k + 1;
  5268. }
  5269. function quinticInOut(k) {
  5270. if ((k *= 2) < 1) {
  5271. return 0.5 * k * k * k * k * k;
  5272. }
  5273. return 0.5 * ((k -= 2) * k * k * k * k + 2);
  5274. }
  5275. function exponentialIn(k) {
  5276. return k === 0 ? 0 : Math.pow(1024, k - 1);
  5277. }
  5278. function exponentialOut(k) {
  5279. return k === 1 ? 1 : 1 - Math.pow(2, -10 * k);
  5280. }
  5281. function elasticIn(k) {
  5282. var s;
  5283. var a = 0.1;
  5284. var p = 0.4;
  5285. if (k === 0) return 0;
  5286. if (k === 1) return 1;
  5287. if (!a || a < 1) {
  5288. a = 1;
  5289. s = p / 4;
  5290. } else {
  5291. s = p / (2 * Math.PI) * Math.asin(1 / a);
  5292. }
  5293. return -(a * Math.pow(2, 10 * (k -= 1)) * Math.sin((k - s) * (2 * Math.PI) / p));
  5294. }
  5295. function elasticOut(k) {
  5296. var s;
  5297. var a = 0.1;
  5298. var p = 0.4;
  5299. if (k === 0) return 0;
  5300. if (k === 1) return 1;
  5301. if (!a || a < 1) {
  5302. a = 1;
  5303. s = p / 4;
  5304. } else {
  5305. s = p / (2 * Math.PI) * Math.asin(1 / a);
  5306. }
  5307. return a * Math.pow(2, -10 * k) * Math.sin((k - s) * (2 * Math.PI) / p) + 1;
  5308. }
  5309. function elasticInOut(k) {
  5310. var s;
  5311. var a = 0.1;
  5312. var p = 0.4;
  5313. if (k === 0) return 0;
  5314. if (k === 1) return 1;
  5315. if (!a || a < 1) {
  5316. a = 1;
  5317. s = p / 4;
  5318. } else {
  5319. s = p / (2 * Math.PI) * Math.asin(1 / a);
  5320. }
  5321. if ((k *= 2) < 1) {
  5322. return -0.5 * (a * Math.pow(2, 10 * (k -= 1)) * Math.sin((k - s) * (2 * Math.PI) / p));
  5323. }
  5324. return a * Math.pow(2, -10 * (k -= 1)) * Math.sin((k - s) * (2 * Math.PI) / p) * 0.5 + 1;
  5325. }
  5326. function backIn(k) {
  5327. var s = 1.70158;
  5328. return k * k * ((s + 1) * k - s);
  5329. }
  5330. function backOut(k) {
  5331. var s = 1.70158;
  5332. return (k = k - 1) * k * ((s + 1) * k + s) + 1;
  5333. }
  5334. function backInOut(k) {
  5335. var s = 1.70158 * 1.525;
  5336. if ((k *= 2) < 1) {
  5337. return 0.5 * (k * k * ((s + 1) * k - s));
  5338. }
  5339. return 0.5 * ((k -= 2) * k * ((s + 1) * k + s) + 2);
  5340. }
  5341. function bounceIn(k) {
  5342. return 1 - bounceOut(1 - k);
  5343. }
  5344. function bounceOut(k) {
  5345. if ((k /= 1) < 1 / 2.75) {
  5346. return 7.5625 * k * k;
  5347. } else if (k < 2 / 2.75) {
  5348. return 7.5625 * (k -= 1.5 / 2.75) * k + 0.75;
  5349. } else if (k < 2.5 / 2.75) {
  5350. return 7.5625 * (k -= 2.25 / 2.75) * k + 0.9375;
  5351. }
  5352. return 7.5625 * (k -= 2.625 / 2.75) * k + 0.984375;
  5353. }
  5354. function bounceInOut(k) {
  5355. if (k < 0.5) {
  5356. return bounceIn(k * 2) * 0.5;
  5357. }
  5358. return bounceOut(k * 2 - 1) * 0.5 + 0.5;
  5359. }
  5360. var Easing = /*#__PURE__*/Object.freeze({
  5361. __proto__: null,
  5362. linear: linear$1,
  5363. quadraticIn: quadraticIn,
  5364. quadraticOut: quadraticOut,
  5365. quadraticInOut: quadraticInOut,
  5366. cubicIn: cubicIn,
  5367. cubicOut: cubicOut,
  5368. cubicInOut: cubicInOut,
  5369. quarticIn: quarticIn,
  5370. quarticOut: quarticOut,
  5371. quarticInOut: quarticInOut,
  5372. elasticIn: elasticIn,
  5373. elasticOut: elasticOut,
  5374. elasticInOut: elasticInOut,
  5375. backIn: backIn,
  5376. backOut: backOut,
  5377. backInOut: backInOut,
  5378. bounceIn: bounceIn,
  5379. bounceOut: bounceOut,
  5380. bounceInOut: bounceInOut,
  5381. exponentialIn: exponentialIn,
  5382. exponentialOut: exponentialOut,
  5383. quinticIn: quinticIn,
  5384. quinticOut: quinticOut,
  5385. quinticInOut: quinticInOut
  5386. });
  5387. var objectWithoutPropertiesLoose = createCommonjsModule(function (module) {
  5388. function _objectWithoutPropertiesLoose(source, excluded) {
  5389. if (source == null) return {};
  5390. var target = {};
  5391. var sourceKeys = Object.keys(source);
  5392. var key, i;
  5393. for (i = 0; i < sourceKeys.length; i++) {
  5394. key = sourceKeys[i];
  5395. if (excluded.indexOf(key) >= 0) continue;
  5396. target[key] = source[key];
  5397. }
  5398. return target;
  5399. }
  5400. module.exports = _objectWithoutPropertiesLoose, module.exports.__esModule = true, module.exports["default"] = module.exports;
  5401. });
  5402. var objectWithoutProperties = createCommonjsModule(function (module) {
  5403. function _objectWithoutProperties(source, excluded) {
  5404. if (source == null) return {};
  5405. var target = objectWithoutPropertiesLoose(source, excluded);
  5406. var key, i;
  5407. if (Object.getOwnPropertySymbols) {
  5408. var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
  5409. for (i = 0; i < sourceSymbolKeys.length; i++) {
  5410. key = sourceSymbolKeys[i];
  5411. if (excluded.indexOf(key) >= 0) continue;
  5412. if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
  5413. target[key] = source[key];
  5414. }
  5415. }
  5416. return target;
  5417. }
  5418. module.exports = _objectWithoutProperties, module.exports.__esModule = true, module.exports["default"] = module.exports;
  5419. });
  5420. var _objectWithoutProperties = /*@__PURE__*/getDefaultExportFromCjs(objectWithoutProperties);
  5421. var _excluded = ["key", "ref"];
  5422. // 实现jsx-classic 入口
  5423. function jsx(type, config) {
  5424. var _ref = config || {},
  5425. key = _ref.key,
  5426. ref = _ref.ref,
  5427. props = _objectWithoutProperties(_ref, _excluded); // 保持和automatic模式一致
  5428. for (var _len = arguments.length, children = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
  5429. children[_key - 2] = arguments[_key];
  5430. }
  5431. if (children.length) {
  5432. props.children = children.length === 1 ? children[0] : children;
  5433. }
  5434. return {
  5435. key: key,
  5436. ref: ref,
  5437. type: type,
  5438. props: props,
  5439. // 存储一些过程中的cache值
  5440. _cache: {}
  5441. };
  5442. }
  5443. var fragment = (function (props) {
  5444. return props.children;
  5445. });
  5446. var ONE_REM;
  5447. try {
  5448. // xgraph下这段会抛错
  5449. ONE_REM = parseInt(document.documentElement.style.fontSize, 10) || 50;
  5450. } catch (e) {
  5451. ONE_REM = 50;
  5452. }
  5453. var SCALE = ONE_REM / 100;
  5454. /**
  5455. * 像素转换
  5456. * @param {Number} px - 750视觉稿像素
  5457. * @return {Number} 屏幕上实际像素
  5458. */
  5459. function defaultPx2hd(px) {
  5460. if (!px) {
  5461. return 0;
  5462. }
  5463. return Number((px * SCALE).toFixed(1));
  5464. }
  5465. function parsePadding$1(padding) {
  5466. if (isNumber(padding)) {
  5467. return [padding, padding, padding, padding];
  5468. }
  5469. var top = padding[0];
  5470. var right = isNumber(padding[1]) ? padding[1] : padding[0];
  5471. var bottom = isNumber(padding[2]) ? padding[2] : top;
  5472. var left = isNumber(padding[3]) ? padding[3] : right;
  5473. return [top, right, bottom, left];
  5474. }
  5475. function batch2hd(px2hd) {
  5476. var batchPx2hd = function batchPx2hd(value) {
  5477. // 处理带px的数据
  5478. if (isString(value) && /^-?\d+px$/.test(value)) {
  5479. var num = value.substr(0, value.length - 2);
  5480. return px2hd(Number(num));
  5481. }
  5482. if (isArray(value)) {
  5483. return value.map(function (v) {
  5484. return batchPx2hd(v);
  5485. });
  5486. }
  5487. if (isPlainObject(value)) {
  5488. var result = {};
  5489. for (var key in value) {
  5490. if (value.hasOwnProperty(key)) {
  5491. var rst = batchPx2hd(value[key]);
  5492. if (!rst) {
  5493. result[key] = rst;
  5494. continue;
  5495. }
  5496. if (key === 'padding' || key === 'margin') {
  5497. var paddingArray = parsePadding$1(rst);
  5498. result[key] = paddingArray;
  5499. result["".concat(key, "Top")] = paddingArray[0];
  5500. result["".concat(key, "Right")] = paddingArray[1];
  5501. result["".concat(key, "Bottom")] = paddingArray[2];
  5502. result["".concat(key, "Left")] = paddingArray[3];
  5503. continue;
  5504. }
  5505. result[key] = rst;
  5506. }
  5507. }
  5508. return result;
  5509. } // 默认直接返回
  5510. return value;
  5511. };
  5512. return batchPx2hd;
  5513. } // 展开数组
  5514. function extendMap(arr, fn) {
  5515. if (!arr) {
  5516. return arr;
  5517. }
  5518. if (!isArray(arr)) {
  5519. return [fn(arr)];
  5520. }
  5521. var newArray = [];
  5522. for (var i = 0; i < arr.length; i++) {
  5523. var element = arr[i];
  5524. if (isArray(element)) {
  5525. newArray = newArray.concat(extendMap(element, fn));
  5526. } else if (element) {
  5527. newArray.push(fn(element));
  5528. }
  5529. }
  5530. return newArray;
  5531. }
  5532. function toTimeStamp(value) {
  5533. if (isString(value)) {
  5534. if (value.indexOf('T') > 0) {
  5535. value = new Date(value).getTime();
  5536. } else {
  5537. // new Date('2010/01/10') 和 new Date('2010-01-10') 的差别在于:
  5538. // 如果仅有年月日时,前者是带有时区的: Fri Jan 10 2020 02:40:13 GMT+0800 (中国标准时间)
  5539. // 后者会格式化成 Sun Jan 10 2010 08:00:00 GMT+0800 (中国标准时间)
  5540. value = new Date(value.replace(/-/gi, '/')).getTime();
  5541. }
  5542. }
  5543. if (isDate(value)) {
  5544. value = value.getTime();
  5545. }
  5546. return value;
  5547. }
  5548. function isInBBox(bbox, point) {
  5549. var minX = bbox.minX,
  5550. maxX = bbox.maxX,
  5551. minY = bbox.minY,
  5552. maxY = bbox.maxY;
  5553. var x = point.x,
  5554. y = point.y;
  5555. return minX <= x && maxX >= x && minY <= y && maxY >= y;
  5556. }
  5557. function getElementsByClassName(className, element) {
  5558. if (!element || !className) return [];
  5559. var rst = [];
  5560. if (element.get('className') === className) {
  5561. rst.push(element);
  5562. }
  5563. var children = element.get('children');
  5564. if (children && children.length) {
  5565. for (var i = 0; i < children.length; i++) {
  5566. var child = children[i];
  5567. rst = rst.concat(getElementsByClassName(className, child));
  5568. }
  5569. }
  5570. return rst;
  5571. }
  5572. var px2hd = batch2hd(defaultPx2hd);
  5573. /* eslint-disable */
  5574. // @ts-nocheck
  5575. // from css-layout
  5576. var CSS_UNDEFINED;
  5577. var CSS_DIRECTION_INHERIT = 'inherit';
  5578. var CSS_DIRECTION_LTR = 'ltr';
  5579. var CSS_DIRECTION_RTL = 'rtl';
  5580. var CSS_FLEX_DIRECTION_ROW = 'row';
  5581. var CSS_FLEX_DIRECTION_ROW_REVERSE = 'row-reverse';
  5582. var CSS_FLEX_DIRECTION_COLUMN = 'column';
  5583. var CSS_FLEX_DIRECTION_COLUMN_REVERSE = 'column-reverse';
  5584. var CSS_JUSTIFY_FLEX_START = 'flex-start';
  5585. var CSS_JUSTIFY_CENTER = 'center';
  5586. var CSS_JUSTIFY_FLEX_END = 'flex-end';
  5587. var CSS_JUSTIFY_SPACE_BETWEEN = 'space-between';
  5588. var CSS_JUSTIFY_SPACE_AROUND = 'space-around';
  5589. var CSS_ALIGN_FLEX_START = 'flex-start';
  5590. var CSS_ALIGN_CENTER = 'center';
  5591. var CSS_ALIGN_FLEX_END = 'flex-end';
  5592. var CSS_ALIGN_STRETCH = 'stretch';
  5593. var CSS_POSITION_RELATIVE = 'relative';
  5594. var CSS_POSITION_ABSOLUTE = 'absolute';
  5595. var leading = {
  5596. row: 'left',
  5597. 'row-reverse': 'right',
  5598. column: 'top',
  5599. 'column-reverse': 'bottom'
  5600. };
  5601. var trailing = {
  5602. row: 'right',
  5603. 'row-reverse': 'left',
  5604. column: 'bottom',
  5605. 'column-reverse': 'top'
  5606. };
  5607. var pos = {
  5608. row: 'left',
  5609. 'row-reverse': 'right',
  5610. column: 'top',
  5611. 'column-reverse': 'bottom'
  5612. };
  5613. var dim = {
  5614. row: 'width',
  5615. 'row-reverse': 'width',
  5616. column: 'height',
  5617. 'column-reverse': 'height'
  5618. }; // When transpiled to Java / C the node type has layout, children and style
  5619. // properties. For the JavaScript version this function adds these properties
  5620. // if they don't already exist.
  5621. function fillNodes(node) {
  5622. if (!node.layout || node.isDirty) {
  5623. node.layout = {
  5624. width: undefined,
  5625. height: undefined,
  5626. top: 0,
  5627. left: 0,
  5628. right: 0,
  5629. bottom: 0
  5630. };
  5631. }
  5632. if (!node.style) {
  5633. node.style = {};
  5634. }
  5635. if (!node.children) {
  5636. node.children = [];
  5637. }
  5638. node.children.forEach(fillNodes);
  5639. return node;
  5640. }
  5641. function isUndefined$1(value) {
  5642. return value === undefined;
  5643. }
  5644. function isRowDirection(flexDirection) {
  5645. return flexDirection === CSS_FLEX_DIRECTION_ROW || flexDirection === CSS_FLEX_DIRECTION_ROW_REVERSE;
  5646. }
  5647. function isColumnDirection(flexDirection) {
  5648. return flexDirection === CSS_FLEX_DIRECTION_COLUMN || flexDirection === CSS_FLEX_DIRECTION_COLUMN_REVERSE;
  5649. }
  5650. function getLeadingMargin(node, axis) {
  5651. if (node.style.marginStart !== undefined && isRowDirection(axis)) {
  5652. return node.style.marginStart;
  5653. }
  5654. var value = null;
  5655. switch (axis) {
  5656. case 'row':
  5657. value = node.style.marginLeft;
  5658. break;
  5659. case 'row-reverse':
  5660. value = node.style.marginRight;
  5661. break;
  5662. case 'column':
  5663. value = node.style.marginTop;
  5664. break;
  5665. case 'column-reverse':
  5666. value = node.style.marginBottom;
  5667. break;
  5668. }
  5669. if (value !== undefined) {
  5670. return value;
  5671. }
  5672. if (node.style.margin !== undefined) {
  5673. return node.style.margin;
  5674. }
  5675. return 0;
  5676. }
  5677. function getTrailingMargin(node, axis) {
  5678. if (node.style.marginEnd !== undefined && isRowDirection(axis)) {
  5679. return node.style.marginEnd;
  5680. }
  5681. var value = null;
  5682. switch (axis) {
  5683. case 'row':
  5684. value = node.style.marginRight;
  5685. break;
  5686. case 'row-reverse':
  5687. value = node.style.marginLeft;
  5688. break;
  5689. case 'column':
  5690. value = node.style.marginBottom;
  5691. break;
  5692. case 'column-reverse':
  5693. value = node.style.marginTop;
  5694. break;
  5695. }
  5696. if (value != null) {
  5697. return value;
  5698. }
  5699. if (node.style.margin !== undefined) {
  5700. return node.style.margin;
  5701. }
  5702. return 0;
  5703. }
  5704. function getLeadingPadding(node, axis) {
  5705. if (node.style.paddingStart !== undefined && node.style.paddingStart >= 0 && isRowDirection(axis)) {
  5706. return node.style.paddingStart;
  5707. }
  5708. var value = null;
  5709. switch (axis) {
  5710. case 'row':
  5711. value = node.style.paddingLeft;
  5712. break;
  5713. case 'row-reverse':
  5714. value = node.style.paddingRight;
  5715. break;
  5716. case 'column':
  5717. value = node.style.paddingTop;
  5718. break;
  5719. case 'column-reverse':
  5720. value = node.style.paddingBottom;
  5721. break;
  5722. }
  5723. if (value != null && value >= 0) {
  5724. return value;
  5725. }
  5726. if (node.style.padding !== undefined && node.style.padding >= 0) {
  5727. return node.style.padding;
  5728. }
  5729. return 0;
  5730. }
  5731. function getTrailingPadding(node, axis) {
  5732. if (node.style.paddingEnd !== undefined && node.style.paddingEnd >= 0 && isRowDirection(axis)) {
  5733. return node.style.paddingEnd;
  5734. }
  5735. var value = null;
  5736. switch (axis) {
  5737. case 'row':
  5738. value = node.style.paddingRight;
  5739. break;
  5740. case 'row-reverse':
  5741. value = node.style.paddingLeft;
  5742. break;
  5743. case 'column':
  5744. value = node.style.paddingBottom;
  5745. break;
  5746. case 'column-reverse':
  5747. value = node.style.paddingTop;
  5748. break;
  5749. }
  5750. if (value != null && value >= 0) {
  5751. return value;
  5752. }
  5753. if (node.style.padding !== undefined && node.style.padding >= 0) {
  5754. return node.style.padding;
  5755. }
  5756. return 0;
  5757. }
  5758. function getLeadingBorder(node, axis) {
  5759. if (node.style.borderStartWidth !== undefined && node.style.borderStartWidth >= 0 && isRowDirection(axis)) {
  5760. return node.style.borderStartWidth;
  5761. }
  5762. var value = null;
  5763. switch (axis) {
  5764. case 'row':
  5765. value = node.style.borderLeftWidth;
  5766. break;
  5767. case 'row-reverse':
  5768. value = node.style.borderRightWidth;
  5769. break;
  5770. case 'column':
  5771. value = node.style.borderTopWidth;
  5772. break;
  5773. case 'column-reverse':
  5774. value = node.style.borderBottomWidth;
  5775. break;
  5776. }
  5777. if (value != null && value >= 0) {
  5778. return value;
  5779. }
  5780. if (node.style.borderWidth !== undefined && node.style.borderWidth >= 0) {
  5781. return node.style.borderWidth;
  5782. }
  5783. return 0;
  5784. }
  5785. function getTrailingBorder(node, axis) {
  5786. if (node.style.borderEndWidth !== undefined && node.style.borderEndWidth >= 0 && isRowDirection(axis)) {
  5787. return node.style.borderEndWidth;
  5788. }
  5789. var value = null;
  5790. switch (axis) {
  5791. case 'row':
  5792. value = node.style.borderRightWidth;
  5793. break;
  5794. case 'row-reverse':
  5795. value = node.style.borderLeftWidth;
  5796. break;
  5797. case 'column':
  5798. value = node.style.borderBottomWidth;
  5799. break;
  5800. case 'column-reverse':
  5801. value = node.style.borderTopWidth;
  5802. break;
  5803. }
  5804. if (value != null && value >= 0) {
  5805. return value;
  5806. }
  5807. if (node.style.borderWidth !== undefined && node.style.borderWidth >= 0) {
  5808. return node.style.borderWidth;
  5809. }
  5810. return 0;
  5811. }
  5812. function getLeadingPaddingAndBorder(node, axis) {
  5813. return getLeadingPadding(node, axis) + getLeadingBorder(node, axis);
  5814. }
  5815. function getTrailingPaddingAndBorder(node, axis) {
  5816. return getTrailingPadding(node, axis) + getTrailingBorder(node, axis);
  5817. }
  5818. function getBorderAxis(node, axis) {
  5819. return getLeadingBorder(node, axis) + getTrailingBorder(node, axis);
  5820. }
  5821. function getMarginAxis(node, axis) {
  5822. return getLeadingMargin(node, axis) + getTrailingMargin(node, axis);
  5823. }
  5824. function getPaddingAndBorderAxis(node, axis) {
  5825. return getLeadingPaddingAndBorder(node, axis) + getTrailingPaddingAndBorder(node, axis);
  5826. }
  5827. function getJustifyContent(node) {
  5828. if (node.style.justifyContent) {
  5829. return node.style.justifyContent;
  5830. }
  5831. return 'flex-start';
  5832. }
  5833. function getAlignContent(node) {
  5834. if (node.style.alignContent) {
  5835. return node.style.alignContent;
  5836. }
  5837. return 'flex-start';
  5838. }
  5839. function getAlignItem(node, child) {
  5840. if (child.style.alignSelf) {
  5841. return child.style.alignSelf;
  5842. }
  5843. if (node.style.alignItems) {
  5844. return node.style.alignItems;
  5845. }
  5846. return 'stretch';
  5847. }
  5848. function resolveAxis(axis, direction) {
  5849. if (direction === CSS_DIRECTION_RTL) {
  5850. if (axis === CSS_FLEX_DIRECTION_ROW) {
  5851. return CSS_FLEX_DIRECTION_ROW_REVERSE;
  5852. } else if (axis === CSS_FLEX_DIRECTION_ROW_REVERSE) {
  5853. return CSS_FLEX_DIRECTION_ROW;
  5854. }
  5855. }
  5856. return axis;
  5857. }
  5858. function resolveDirection(node, parentDirection) {
  5859. var direction;
  5860. if (node.style.direction) {
  5861. direction = node.style.direction;
  5862. } else {
  5863. direction = CSS_DIRECTION_INHERIT;
  5864. }
  5865. if (direction === CSS_DIRECTION_INHERIT) {
  5866. direction = parentDirection === undefined ? CSS_DIRECTION_LTR : parentDirection;
  5867. }
  5868. return direction;
  5869. }
  5870. function getFlexDirection(node) {
  5871. if (node.style.flexDirection) {
  5872. return node.style.flexDirection;
  5873. }
  5874. return CSS_FLEX_DIRECTION_COLUMN;
  5875. }
  5876. function getCrossFlexDirection(flexDirection, direction) {
  5877. if (isColumnDirection(flexDirection)) {
  5878. return resolveAxis(CSS_FLEX_DIRECTION_ROW, direction);
  5879. } else {
  5880. return CSS_FLEX_DIRECTION_COLUMN;
  5881. }
  5882. }
  5883. function getPositionType(node) {
  5884. if (node.style.position) {
  5885. return node.style.position;
  5886. }
  5887. return 'relative';
  5888. }
  5889. function isFlex(node) {
  5890. return getPositionType(node) === CSS_POSITION_RELATIVE && node.style.flex > 0;
  5891. }
  5892. function isFlexWrap(node) {
  5893. return node.style.flexWrap === 'wrap';
  5894. }
  5895. function getDimWithMargin(node, axis) {
  5896. return node.layout[dim[axis]] + getMarginAxis(node, axis);
  5897. }
  5898. function isDimDefined(node, axis) {
  5899. return node.style[dim[axis]] !== undefined && node.style[dim[axis]] >= 0;
  5900. }
  5901. function isPosDefined(node, pos) {
  5902. return node.style[pos] !== undefined;
  5903. }
  5904. function isMeasureDefined(node) {
  5905. return node.style.measure !== undefined;
  5906. }
  5907. function getPosition(node, pos) {
  5908. if (node.style[pos] !== undefined) {
  5909. return node.style[pos];
  5910. }
  5911. return 0;
  5912. }
  5913. function boundAxis(node, axis, value) {
  5914. var min = {
  5915. row: node.style.minWidth,
  5916. 'row-reverse': node.style.minWidth,
  5917. column: node.style.minHeight,
  5918. 'column-reverse': node.style.minHeight
  5919. }[axis];
  5920. var max = {
  5921. row: node.style.maxWidth,
  5922. 'row-reverse': node.style.maxWidth,
  5923. column: node.style.maxHeight,
  5924. 'column-reverse': node.style.maxHeight
  5925. }[axis];
  5926. var boundValue = value;
  5927. if (max !== undefined && max >= 0 && boundValue > max) {
  5928. boundValue = max;
  5929. }
  5930. if (min !== undefined && min >= 0 && boundValue < min) {
  5931. boundValue = min;
  5932. }
  5933. return boundValue;
  5934. }
  5935. function fmaxf(a, b) {
  5936. if (a > b) {
  5937. return a;
  5938. }
  5939. return b;
  5940. } // When the user specifically sets a value for width or height
  5941. function setDimensionFromStyle(node, axis) {
  5942. // The parent already computed us a width or height. We just skip it
  5943. if (node.layout[dim[axis]] !== undefined) {
  5944. return;
  5945. } // We only run if there's a width or height defined
  5946. if (!isDimDefined(node, axis)) {
  5947. return;
  5948. } // The dimensions can never be smaller than the padding and border
  5949. node.layout[dim[axis]] = fmaxf(boundAxis(node, axis, node.style[dim[axis]]), getPaddingAndBorderAxis(node, axis));
  5950. }
  5951. function setTrailingPosition(node, child, axis) {
  5952. child.layout[trailing[axis]] = node.layout[dim[axis]] - child.layout[dim[axis]] - child.layout[pos[axis]];
  5953. } // If both left and right are defined, then use left. Otherwise return
  5954. // +left or -right depending on which is defined.
  5955. function getRelativePosition$1(node, axis) {
  5956. if (node.style[leading[axis]] !== undefined) {
  5957. return getPosition(node, leading[axis]);
  5958. }
  5959. return -getPosition(node, trailing[axis]);
  5960. }
  5961. function layoutNodeImpl(node, parentMaxWidth,
  5962. /*css_direction_t*/
  5963. parentDirection) {
  5964. var
  5965. /*css_direction_t*/
  5966. direction = resolveDirection(node, parentDirection);
  5967. var
  5968. /*(c)!css_flex_direction_t*/
  5969. /*(java)!int*/
  5970. mainAxis = resolveAxis(getFlexDirection(node), direction);
  5971. var
  5972. /*(c)!css_flex_direction_t*/
  5973. /*(java)!int*/
  5974. crossAxis = getCrossFlexDirection(mainAxis, direction);
  5975. var
  5976. /*(c)!css_flex_direction_t*/
  5977. /*(java)!int*/
  5978. resolvedRowAxis = resolveAxis(CSS_FLEX_DIRECTION_ROW, direction); // Handle width and height style attributes
  5979. setDimensionFromStyle(node, mainAxis);
  5980. setDimensionFromStyle(node, crossAxis); // Set the resolved resolution in the node's layout
  5981. node.layout.direction = direction; // The position is set by the parent, but we need to complete it with a
  5982. // delta composed of the margin and left/top/right/bottom
  5983. node.layout[leading[mainAxis]] += getLeadingMargin(node, mainAxis) + getRelativePosition$1(node, mainAxis);
  5984. node.layout[trailing[mainAxis]] += getTrailingMargin(node, mainAxis) + getRelativePosition$1(node, mainAxis);
  5985. node.layout[leading[crossAxis]] += getLeadingMargin(node, crossAxis) + getRelativePosition$1(node, crossAxis);
  5986. node.layout[trailing[crossAxis]] += getTrailingMargin(node, crossAxis) + getRelativePosition$1(node, crossAxis); // Inline immutable values from the target node to avoid excessive method
  5987. // invocations during the layout calculation.
  5988. var
  5989. /*int*/
  5990. childCount = node.children.length;
  5991. var
  5992. /*float*/
  5993. paddingAndBorderAxisResolvedRow = getPaddingAndBorderAxis(node, resolvedRowAxis);
  5994. if (isMeasureDefined(node)) {
  5995. var
  5996. /*bool*/
  5997. isResolvedRowDimDefined = !isUndefined$1(node.layout[dim[resolvedRowAxis]]);
  5998. var
  5999. /*float*/
  6000. width = CSS_UNDEFINED;
  6001. if (isDimDefined(node, resolvedRowAxis)) {
  6002. width = node.style.width;
  6003. } else if (isResolvedRowDimDefined) {
  6004. width = node.layout[dim[resolvedRowAxis]];
  6005. } else {
  6006. width = parentMaxWidth - getMarginAxis(node, resolvedRowAxis);
  6007. }
  6008. width -= paddingAndBorderAxisResolvedRow; // We only need to give a dimension for the text if we haven't got any
  6009. // for it computed yet. It can either be from the style attribute or because
  6010. // the element is flexible.
  6011. var
  6012. /*bool*/
  6013. isRowUndefined = !isDimDefined(node, resolvedRowAxis) && !isResolvedRowDimDefined;
  6014. var
  6015. /*bool*/
  6016. isColumnUndefined = !isDimDefined(node, CSS_FLEX_DIRECTION_COLUMN) && isUndefined$1(node.layout[dim[CSS_FLEX_DIRECTION_COLUMN]]); // Let's not measure the text if we already know both dimensions
  6017. if (isRowUndefined || isColumnUndefined) {
  6018. var
  6019. /*css_dim_t*/
  6020. measureDim = node.style.measure(
  6021. /*(c)!node->context,*/
  6022. /*(java)!layoutContext.measureOutput,*/
  6023. width);
  6024. if (isRowUndefined) {
  6025. node.layout.width = measureDim.width + paddingAndBorderAxisResolvedRow;
  6026. }
  6027. if (isColumnUndefined) {
  6028. node.layout.height = measureDim.height + getPaddingAndBorderAxis(node, CSS_FLEX_DIRECTION_COLUMN);
  6029. }
  6030. }
  6031. if (childCount === 0) {
  6032. return;
  6033. }
  6034. }
  6035. var
  6036. /*bool*/
  6037. isNodeFlexWrap = isFlexWrap(node);
  6038. var
  6039. /*css_justify_t*/
  6040. justifyContent = getJustifyContent(node);
  6041. var
  6042. /*float*/
  6043. leadingPaddingAndBorderMain = getLeadingPaddingAndBorder(node, mainAxis);
  6044. var
  6045. /*float*/
  6046. leadingPaddingAndBorderCross = getLeadingPaddingAndBorder(node, crossAxis);
  6047. var
  6048. /*float*/
  6049. paddingAndBorderAxisMain = getPaddingAndBorderAxis(node, mainAxis);
  6050. var
  6051. /*float*/
  6052. paddingAndBorderAxisCross = getPaddingAndBorderAxis(node, crossAxis);
  6053. var
  6054. /*bool*/
  6055. isMainDimDefined = !isUndefined$1(node.layout[dim[mainAxis]]);
  6056. var
  6057. /*bool*/
  6058. isCrossDimDefined = !isUndefined$1(node.layout[dim[crossAxis]]);
  6059. var
  6060. /*bool*/
  6061. isMainRowDirection = isRowDirection(mainAxis);
  6062. var
  6063. /*int*/
  6064. i;
  6065. var
  6066. /*int*/
  6067. ii;
  6068. var
  6069. /*css_node_t**/
  6070. child;
  6071. var
  6072. /*(c)!css_flex_direction_t*/
  6073. /*(java)!int*/
  6074. axis;
  6075. var
  6076. /*css_node_t**/
  6077. firstAbsoluteChild = null;
  6078. var
  6079. /*css_node_t**/
  6080. currentAbsoluteChild = null;
  6081. var
  6082. /*float*/
  6083. definedMainDim = CSS_UNDEFINED;
  6084. if (isMainDimDefined) {
  6085. definedMainDim = node.layout[dim[mainAxis]] - paddingAndBorderAxisMain;
  6086. } // We want to execute the next two loops one per line with flex-wrap
  6087. var
  6088. /*int*/
  6089. startLine = 0;
  6090. var
  6091. /*int*/
  6092. endLine = 0; // var/*int*/ nextOffset = 0;
  6093. var
  6094. /*int*/
  6095. alreadyComputedNextLayout = 0; // We aggregate the total dimensions of the container in those two variables
  6096. var
  6097. /*float*/
  6098. linesCrossDim = 0;
  6099. var
  6100. /*float*/
  6101. linesMainDim = 0;
  6102. var
  6103. /*int*/
  6104. linesCount = 0;
  6105. while (endLine < childCount) {
  6106. // <Loop A> Layout non flexible children and count children by type
  6107. // mainContentDim is accumulation of the dimensions and margin of all the
  6108. // non flexible children. This will be used in order to either set the
  6109. // dimensions of the node if none already exist, or to compute the
  6110. // remaining space left for the flexible children.
  6111. var
  6112. /*float*/
  6113. mainContentDim = 0; // There are three kind of children, non flexible, flexible and absolute.
  6114. // We need to know how many there are in order to distribute the space.
  6115. var
  6116. /*int*/
  6117. flexibleChildrenCount = 0;
  6118. var
  6119. /*float*/
  6120. totalFlexible = 0;
  6121. var
  6122. /*int*/
  6123. nonFlexibleChildrenCount = 0; // Use the line loop to position children in the main axis for as long
  6124. // as they are using a simple stacking behaviour. Children that are
  6125. // immediately stacked in the initial loop will not be touched again
  6126. // in <Loop C>.
  6127. var
  6128. /*bool*/
  6129. isSimpleStackMain = isMainDimDefined && justifyContent === CSS_JUSTIFY_FLEX_START || !isMainDimDefined && justifyContent !== CSS_JUSTIFY_CENTER;
  6130. var
  6131. /*int*/
  6132. firstComplexMain = isSimpleStackMain ? childCount : startLine; // Use the initial line loop to position children in the cross axis for
  6133. // as long as they are relatively positioned with alignment STRETCH or
  6134. // FLEX_START. Children that are immediately stacked in the initial loop
  6135. // will not be touched again in <Loop D>.
  6136. var
  6137. /*bool*/
  6138. isSimpleStackCross = true;
  6139. var
  6140. /*int*/
  6141. firstComplexCross = childCount;
  6142. var
  6143. /*css_node_t**/
  6144. firstFlexChild = null;
  6145. var
  6146. /*css_node_t**/
  6147. currentFlexChild = null;
  6148. var
  6149. /*float*/
  6150. mainDim = leadingPaddingAndBorderMain;
  6151. var
  6152. /*float*/
  6153. crossDim = 0;
  6154. var
  6155. /*float*/
  6156. maxWidth;
  6157. for (i = startLine; i < childCount; ++i) {
  6158. child = node.children[i];
  6159. child.lineIndex = linesCount;
  6160. child.nextAbsoluteChild = null;
  6161. child.nextFlexChild = null;
  6162. var
  6163. /*css_align_t*/
  6164. alignItem = getAlignItem(node, child); // Pre-fill cross axis dimensions when the child is using stretch before
  6165. // we call the recursive layout pass
  6166. if (alignItem === CSS_ALIGN_STRETCH && getPositionType(child) === CSS_POSITION_RELATIVE && isCrossDimDefined && !isDimDefined(child, crossAxis)) {
  6167. child.layout[dim[crossAxis]] = fmaxf(boundAxis(child, crossAxis, node.layout[dim[crossAxis]] - paddingAndBorderAxisCross - getMarginAxis(child, crossAxis)), // You never want to go smaller than padding
  6168. getPaddingAndBorderAxis(child, crossAxis));
  6169. } else if (getPositionType(child) === CSS_POSITION_ABSOLUTE) {
  6170. // Store a private linked list of absolutely positioned children
  6171. // so that we can efficiently traverse them later.
  6172. if (firstAbsoluteChild === null) {
  6173. firstAbsoluteChild = child;
  6174. }
  6175. if (currentAbsoluteChild !== null) {
  6176. currentAbsoluteChild.nextAbsoluteChild = child;
  6177. }
  6178. currentAbsoluteChild = child; // Pre-fill dimensions when using absolute position and both offsets for the axis are defined (either both
  6179. // left and right or top and bottom).
  6180. for (ii = 0; ii < 2; ii++) {
  6181. axis = ii !== 0 ? CSS_FLEX_DIRECTION_ROW : CSS_FLEX_DIRECTION_COLUMN;
  6182. if (!isUndefined$1(node.layout[dim[axis]]) && !isDimDefined(child, axis) && isPosDefined(child, leading[axis]) && isPosDefined(child, trailing[axis])) {
  6183. 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])), // You never want to go smaller than padding
  6184. getPaddingAndBorderAxis(child, axis));
  6185. }
  6186. }
  6187. }
  6188. var
  6189. /*float*/
  6190. nextContentDim = 0; // It only makes sense to consider a child flexible if we have a computed
  6191. // dimension for the node.
  6192. if (isMainDimDefined && isFlex(child)) {
  6193. flexibleChildrenCount++;
  6194. totalFlexible += child.style.flex; // Store a private linked list of flexible children so that we can
  6195. // efficiently traverse them later.
  6196. if (firstFlexChild === null) {
  6197. firstFlexChild = child;
  6198. }
  6199. if (currentFlexChild !== null) {
  6200. currentFlexChild.nextFlexChild = child;
  6201. }
  6202. currentFlexChild = child; // Even if we don't know its exact size yet, we already know the padding,
  6203. // border and margin. We'll use this partial information, which represents
  6204. // the smallest possible size for the child, to compute the remaining
  6205. // available space.
  6206. nextContentDim = getPaddingAndBorderAxis(child, mainAxis) + getMarginAxis(child, mainAxis);
  6207. } else {
  6208. maxWidth = CSS_UNDEFINED;
  6209. if (!isMainRowDirection) {
  6210. if (isDimDefined(node, resolvedRowAxis)) {
  6211. maxWidth = node.layout[dim[resolvedRowAxis]] - paddingAndBorderAxisResolvedRow;
  6212. } else {
  6213. maxWidth = parentMaxWidth - getMarginAxis(node, resolvedRowAxis) - paddingAndBorderAxisResolvedRow;
  6214. }
  6215. } // This is the main recursive call. We layout non flexible children.
  6216. if (alreadyComputedNextLayout === 0) {
  6217. layoutNode(
  6218. /*(java)!layoutContext, */
  6219. child, maxWidth, direction);
  6220. } // Absolute positioned elements do not take part of the layout, so we
  6221. // don't use them to compute mainContentDim
  6222. if (getPositionType(child) === CSS_POSITION_RELATIVE) {
  6223. nonFlexibleChildrenCount++; // At this point we know the final size and margin of the element.
  6224. nextContentDim = getDimWithMargin(child, mainAxis);
  6225. }
  6226. } // The element we are about to add would make us go to the next line
  6227. if (isNodeFlexWrap && isMainDimDefined && mainContentDim + nextContentDim > definedMainDim && // If there's only one element, then it's bigger than the content
  6228. // and needs its own line
  6229. i !== startLine) {
  6230. nonFlexibleChildrenCount--;
  6231. alreadyComputedNextLayout = 1;
  6232. break;
  6233. } // Disable simple stacking in the main axis for the current line as
  6234. // we found a non-trivial child. The remaining children will be laid out
  6235. // in <Loop C>.
  6236. if (isSimpleStackMain && (getPositionType(child) !== CSS_POSITION_RELATIVE || isFlex(child))) {
  6237. isSimpleStackMain = false;
  6238. firstComplexMain = i;
  6239. } // Disable simple stacking in the cross axis for the current line as
  6240. // we found a non-trivial child. The remaining children will be laid out
  6241. // in <Loop D>.
  6242. if (isSimpleStackCross && (getPositionType(child) !== CSS_POSITION_RELATIVE || alignItem !== CSS_ALIGN_STRETCH && alignItem !== CSS_ALIGN_FLEX_START || isUndefined$1(child.layout[dim[crossAxis]]))) {
  6243. isSimpleStackCross = false;
  6244. firstComplexCross = i;
  6245. }
  6246. if (isSimpleStackMain) {
  6247. child.layout[pos[mainAxis]] += mainDim;
  6248. if (isMainDimDefined) {
  6249. setTrailingPosition(node, child, mainAxis);
  6250. }
  6251. mainDim += getDimWithMargin(child, mainAxis);
  6252. crossDim = fmaxf(crossDim, boundAxis(child, crossAxis, getDimWithMargin(child, crossAxis)));
  6253. }
  6254. if (isSimpleStackCross) {
  6255. child.layout[pos[crossAxis]] += linesCrossDim + leadingPaddingAndBorderCross;
  6256. if (isCrossDimDefined) {
  6257. setTrailingPosition(node, child, crossAxis);
  6258. }
  6259. }
  6260. alreadyComputedNextLayout = 0;
  6261. mainContentDim += nextContentDim;
  6262. endLine = i + 1;
  6263. } // <Loop B> Layout flexible children and allocate empty space
  6264. // In order to position the elements in the main axis, we have two
  6265. // controls. The space between the beginning and the first element
  6266. // and the space between each two elements.
  6267. var
  6268. /*float*/
  6269. leadingMainDim = 0;
  6270. var
  6271. /*float*/
  6272. betweenMainDim = 0; // The remaining available space that needs to be allocated
  6273. var
  6274. /*float*/
  6275. remainingMainDim = 0;
  6276. if (isMainDimDefined) {
  6277. remainingMainDim = definedMainDim - mainContentDim;
  6278. } else {
  6279. remainingMainDim = fmaxf(mainContentDim, 0) - mainContentDim;
  6280. } // If there are flexible children in the mix, they are going to fill the
  6281. // remaining space
  6282. if (flexibleChildrenCount !== 0) {
  6283. var
  6284. /*float*/
  6285. flexibleMainDim = remainingMainDim / totalFlexible;
  6286. var
  6287. /*float*/
  6288. baseMainDim;
  6289. var
  6290. /*float*/
  6291. boundMainDim; // If the flex share of remaining space doesn't meet min/max bounds,
  6292. // remove this child from flex calculations.
  6293. currentFlexChild = firstFlexChild;
  6294. while (currentFlexChild !== null) {
  6295. baseMainDim = flexibleMainDim * currentFlexChild.style.flex + getPaddingAndBorderAxis(currentFlexChild, mainAxis);
  6296. boundMainDim = boundAxis(currentFlexChild, mainAxis, baseMainDim);
  6297. if (baseMainDim !== boundMainDim) {
  6298. remainingMainDim -= boundMainDim;
  6299. totalFlexible -= currentFlexChild.style.flex;
  6300. }
  6301. currentFlexChild = currentFlexChild.nextFlexChild;
  6302. }
  6303. flexibleMainDim = remainingMainDim / totalFlexible; // The non flexible children can overflow the container, in this case
  6304. // we should just assume that there is no space available.
  6305. if (flexibleMainDim < 0) {
  6306. flexibleMainDim = 0;
  6307. }
  6308. currentFlexChild = firstFlexChild;
  6309. while (currentFlexChild !== null) {
  6310. // At this point we know the final size of the element in the main
  6311. // dimension
  6312. currentFlexChild.layout[dim[mainAxis]] = boundAxis(currentFlexChild, mainAxis, flexibleMainDim * currentFlexChild.style.flex + getPaddingAndBorderAxis(currentFlexChild, mainAxis));
  6313. maxWidth = CSS_UNDEFINED;
  6314. if (isDimDefined(node, resolvedRowAxis)) {
  6315. maxWidth = node.layout[dim[resolvedRowAxis]] - paddingAndBorderAxisResolvedRow;
  6316. } else if (!isMainRowDirection) {
  6317. maxWidth = parentMaxWidth - getMarginAxis(node, resolvedRowAxis) - paddingAndBorderAxisResolvedRow;
  6318. } // And we recursively call the layout algorithm for this child
  6319. layoutNode(
  6320. /*(java)!layoutContext, */
  6321. currentFlexChild, maxWidth, direction);
  6322. child = currentFlexChild;
  6323. currentFlexChild = currentFlexChild.nextFlexChild;
  6324. child.nextFlexChild = null;
  6325. } // We use justifyContent to figure out how to allocate the remaining
  6326. // space available
  6327. } else if (justifyContent !== CSS_JUSTIFY_FLEX_START) {
  6328. if (justifyContent === CSS_JUSTIFY_CENTER) {
  6329. leadingMainDim = remainingMainDim / 2;
  6330. } else if (justifyContent === CSS_JUSTIFY_FLEX_END) {
  6331. leadingMainDim = remainingMainDim;
  6332. } else if (justifyContent === CSS_JUSTIFY_SPACE_BETWEEN) {
  6333. remainingMainDim = fmaxf(remainingMainDim, 0);
  6334. if (flexibleChildrenCount + nonFlexibleChildrenCount - 1 !== 0) {
  6335. betweenMainDim = remainingMainDim / (flexibleChildrenCount + nonFlexibleChildrenCount - 1);
  6336. } else {
  6337. betweenMainDim = 0;
  6338. }
  6339. } else if (justifyContent === CSS_JUSTIFY_SPACE_AROUND) {
  6340. // Space on the edges is half of the space between elements
  6341. betweenMainDim = remainingMainDim / (flexibleChildrenCount + nonFlexibleChildrenCount);
  6342. leadingMainDim = betweenMainDim / 2;
  6343. }
  6344. } // <Loop C> Position elements in the main axis and compute dimensions
  6345. // At this point, all the children have their dimensions set. We need to
  6346. // find their position. In order to do that, we accumulate data in
  6347. // variables that are also useful to compute the total dimensions of the
  6348. // container!
  6349. mainDim += leadingMainDim;
  6350. for (i = firstComplexMain; i < endLine; ++i) {
  6351. child = node.children[i];
  6352. if (getPositionType(child) === CSS_POSITION_ABSOLUTE && isPosDefined(child, leading[mainAxis])) {
  6353. // In case the child is position absolute and has left/top being
  6354. // defined, we override the position to whatever the user said
  6355. // (and margin/border).
  6356. child.layout[pos[mainAxis]] = getPosition(child, leading[mainAxis]) + getLeadingBorder(node, mainAxis) + getLeadingMargin(child, mainAxis);
  6357. } else {
  6358. // If the child is position absolute (without top/left) or relative,
  6359. // we put it at the current accumulated offset.
  6360. child.layout[pos[mainAxis]] += mainDim; // Define the trailing position accordingly.
  6361. if (isMainDimDefined) {
  6362. setTrailingPosition(node, child, mainAxis);
  6363. } // Now that we placed the element, we need to update the variables
  6364. // We only need to do that for relative elements. Absolute elements
  6365. // do not take part in that phase.
  6366. if (getPositionType(child) === CSS_POSITION_RELATIVE) {
  6367. // The main dimension is the sum of all the elements dimension plus
  6368. // the spacing.
  6369. mainDim += betweenMainDim + getDimWithMargin(child, mainAxis); // The cross dimension is the max of the elements dimension since there
  6370. // can only be one element in that cross dimension.
  6371. crossDim = fmaxf(crossDim, boundAxis(child, crossAxis, getDimWithMargin(child, crossAxis)));
  6372. }
  6373. }
  6374. }
  6375. var
  6376. /*float*/
  6377. containerCrossAxis = node.layout[dim[crossAxis]];
  6378. if (!isCrossDimDefined) {
  6379. containerCrossAxis = fmaxf( // For the cross dim, we add both sides at the end because the value
  6380. // is aggregate via a max function. Intermediate negative values
  6381. // can mess this computation otherwise
  6382. boundAxis(node, crossAxis, crossDim + paddingAndBorderAxisCross), paddingAndBorderAxisCross);
  6383. } // <Loop D> Position elements in the cross axis
  6384. for (i = firstComplexCross; i < endLine; ++i) {
  6385. child = node.children[i];
  6386. if (getPositionType(child) === CSS_POSITION_ABSOLUTE && isPosDefined(child, leading[crossAxis])) {
  6387. // In case the child is absolutely positionned and has a
  6388. // top/left/bottom/right being set, we override all the previously
  6389. // computed positions to set it correctly.
  6390. child.layout[pos[crossAxis]] = getPosition(child, leading[crossAxis]) + getLeadingBorder(node, crossAxis) + getLeadingMargin(child, crossAxis);
  6391. } else {
  6392. var
  6393. /*float*/
  6394. leadingCrossDim = leadingPaddingAndBorderCross; // For a relative children, we're either using alignItems (parent) or
  6395. // alignSelf (child) in order to determine the position in the cross axis
  6396. if (getPositionType(child) === CSS_POSITION_RELATIVE) {
  6397. // This variable is intentionally re-defined as the code is transpiled to a block scope language
  6398. var
  6399. /*css_align_t*/
  6400. alignItem = getAlignItem(node, child);
  6401. if (alignItem === CSS_ALIGN_STRETCH) {
  6402. // You can only stretch if the dimension has not already been set
  6403. // previously.
  6404. if (isUndefined$1(child.layout[dim[crossAxis]])) {
  6405. child.layout[dim[crossAxis]] = fmaxf(boundAxis(child, crossAxis, containerCrossAxis - paddingAndBorderAxisCross - getMarginAxis(child, crossAxis)), // You never want to go smaller than padding
  6406. getPaddingAndBorderAxis(child, crossAxis));
  6407. }
  6408. } else if (alignItem !== CSS_ALIGN_FLEX_START) {
  6409. // The remaining space between the parent dimensions+padding and child
  6410. // dimensions+margin.
  6411. var
  6412. /*float*/
  6413. remainingCrossDim = containerCrossAxis - paddingAndBorderAxisCross - getDimWithMargin(child, crossAxis);
  6414. if (alignItem === CSS_ALIGN_CENTER) {
  6415. leadingCrossDim += remainingCrossDim / 2;
  6416. } else {
  6417. // CSS_ALIGN_FLEX_END
  6418. leadingCrossDim += remainingCrossDim;
  6419. }
  6420. }
  6421. } // And we apply the position
  6422. child.layout[pos[crossAxis]] += linesCrossDim + leadingCrossDim; // Define the trailing position accordingly.
  6423. if (isCrossDimDefined) {
  6424. setTrailingPosition(node, child, crossAxis);
  6425. }
  6426. }
  6427. }
  6428. linesCrossDim += crossDim;
  6429. linesMainDim = fmaxf(linesMainDim, mainDim);
  6430. linesCount += 1;
  6431. startLine = endLine;
  6432. } // <Loop E>
  6433. //
  6434. // Note(prenaux): More than one line, we need to layout the crossAxis
  6435. // according to alignContent.
  6436. //
  6437. // Note that we could probably remove <Loop D> and handle the one line case
  6438. // here too, but for the moment this is safer since it won't interfere with
  6439. // previously working code.
  6440. //
  6441. // See specs:
  6442. // http://www.w3.org/TR/2012/CR-css3-flexbox-20120918/#layout-algorithm
  6443. // section 9.4
  6444. //
  6445. if (linesCount > 1 && isCrossDimDefined) {
  6446. var
  6447. /*float*/
  6448. nodeCrossAxisInnerSize = node.layout[dim[crossAxis]] - paddingAndBorderAxisCross;
  6449. var
  6450. /*float*/
  6451. remainingAlignContentDim = nodeCrossAxisInnerSize - linesCrossDim;
  6452. var
  6453. /*float*/
  6454. crossDimLead = 0;
  6455. var
  6456. /*float*/
  6457. currentLead = leadingPaddingAndBorderCross;
  6458. var
  6459. /*css_align_t*/
  6460. alignContent = getAlignContent(node);
  6461. if (alignContent === CSS_ALIGN_FLEX_END) {
  6462. currentLead += remainingAlignContentDim;
  6463. } else if (alignContent === CSS_ALIGN_CENTER) {
  6464. currentLead += remainingAlignContentDim / 2;
  6465. } else if (alignContent === CSS_ALIGN_STRETCH) {
  6466. if (nodeCrossAxisInnerSize > linesCrossDim) {
  6467. crossDimLead = remainingAlignContentDim / linesCount;
  6468. }
  6469. }
  6470. var
  6471. /*int*/
  6472. endIndex = 0;
  6473. for (i = 0; i < linesCount; ++i) {
  6474. var
  6475. /*int*/
  6476. startIndex = endIndex; // compute the line's height and find the endIndex
  6477. var
  6478. /*float*/
  6479. lineHeight = 0;
  6480. for (ii = startIndex; ii < childCount; ++ii) {
  6481. child = node.children[ii];
  6482. if (getPositionType(child) !== CSS_POSITION_RELATIVE) {
  6483. continue;
  6484. }
  6485. if (child.lineIndex !== i) {
  6486. break;
  6487. }
  6488. if (!isUndefined$1(child.layout[dim[crossAxis]])) {
  6489. lineHeight = fmaxf(lineHeight, child.layout[dim[crossAxis]] + getMarginAxis(child, crossAxis));
  6490. }
  6491. }
  6492. endIndex = ii;
  6493. lineHeight += crossDimLead;
  6494. for (ii = startIndex; ii < endIndex; ++ii) {
  6495. child = node.children[ii];
  6496. if (getPositionType(child) !== CSS_POSITION_RELATIVE) {
  6497. continue;
  6498. }
  6499. var
  6500. /*css_align_t*/
  6501. alignContentAlignItem = getAlignItem(node, child);
  6502. if (alignContentAlignItem === CSS_ALIGN_FLEX_START) {
  6503. child.layout[pos[crossAxis]] = currentLead + getLeadingMargin(child, crossAxis);
  6504. } else if (alignContentAlignItem === CSS_ALIGN_FLEX_END) {
  6505. child.layout[pos[crossAxis]] = currentLead + lineHeight - getTrailingMargin(child, crossAxis) - child.layout[dim[crossAxis]];
  6506. } else if (alignContentAlignItem === CSS_ALIGN_CENTER) {
  6507. var
  6508. /*float*/
  6509. childHeight = child.layout[dim[crossAxis]];
  6510. child.layout[pos[crossAxis]] = currentLead + (lineHeight - childHeight) / 2;
  6511. } else if (alignContentAlignItem === CSS_ALIGN_STRETCH) {
  6512. child.layout[pos[crossAxis]] = currentLead + getLeadingMargin(child, crossAxis); // TODO(prenaux): Correctly set the height of items with undefined
  6513. // (auto) crossAxis dimension.
  6514. }
  6515. }
  6516. currentLead += lineHeight;
  6517. }
  6518. }
  6519. var
  6520. /*bool*/
  6521. needsMainTrailingPos = false;
  6522. var
  6523. /*bool*/
  6524. needsCrossTrailingPos = false; // If the user didn't specify a width or height, and it has not been set
  6525. // by the container, then we set it via the children.
  6526. if (!isMainDimDefined) {
  6527. node.layout[dim[mainAxis]] = fmaxf( // We're missing the last padding at this point to get the final
  6528. // dimension
  6529. boundAxis(node, mainAxis, linesMainDim + getTrailingPaddingAndBorder(node, mainAxis)), // We can never assign a width smaller than the padding and borders
  6530. paddingAndBorderAxisMain);
  6531. if (mainAxis === CSS_FLEX_DIRECTION_ROW_REVERSE || mainAxis === CSS_FLEX_DIRECTION_COLUMN_REVERSE) {
  6532. needsMainTrailingPos = true;
  6533. }
  6534. }
  6535. if (!isCrossDimDefined) {
  6536. node.layout[dim[crossAxis]] = fmaxf( // For the cross dim, we add both sides at the end because the value
  6537. // is aggregate via a max function. Intermediate negative values
  6538. // can mess this computation otherwise
  6539. boundAxis(node, crossAxis, linesCrossDim + paddingAndBorderAxisCross), paddingAndBorderAxisCross);
  6540. if (crossAxis === CSS_FLEX_DIRECTION_ROW_REVERSE || crossAxis === CSS_FLEX_DIRECTION_COLUMN_REVERSE) {
  6541. needsCrossTrailingPos = true;
  6542. }
  6543. } // <Loop F> Set trailing position if necessary
  6544. if (needsMainTrailingPos || needsCrossTrailingPos) {
  6545. for (i = 0; i < childCount; ++i) {
  6546. child = node.children[i];
  6547. if (needsMainTrailingPos) {
  6548. setTrailingPosition(node, child, mainAxis);
  6549. }
  6550. if (needsCrossTrailingPos) {
  6551. setTrailingPosition(node, child, crossAxis);
  6552. }
  6553. }
  6554. } // <Loop G> Calculate dimensions for absolutely positioned elements
  6555. currentAbsoluteChild = firstAbsoluteChild;
  6556. while (currentAbsoluteChild !== null) {
  6557. // Pre-fill dimensions when using absolute position and both offsets for
  6558. // the axis are defined (either both left and right or top and bottom).
  6559. for (ii = 0; ii < 2; ii++) {
  6560. axis = ii !== 0 ? CSS_FLEX_DIRECTION_ROW : CSS_FLEX_DIRECTION_COLUMN;
  6561. if (!isUndefined$1(node.layout[dim[axis]]) && !isDimDefined(currentAbsoluteChild, axis) && isPosDefined(currentAbsoluteChild, leading[axis]) && isPosDefined(currentAbsoluteChild, trailing[axis])) {
  6562. 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])), // You never want to go smaller than padding
  6563. getPaddingAndBorderAxis(currentAbsoluteChild, axis));
  6564. }
  6565. if (isPosDefined(currentAbsoluteChild, trailing[axis]) && !isPosDefined(currentAbsoluteChild, leading[axis])) {
  6566. currentAbsoluteChild.layout[leading[axis]] = node.layout[dim[axis]] - currentAbsoluteChild.layout[dim[axis]] - getPosition(currentAbsoluteChild, trailing[axis]);
  6567. }
  6568. }
  6569. child = currentAbsoluteChild;
  6570. currentAbsoluteChild = currentAbsoluteChild.nextAbsoluteChild;
  6571. child.nextAbsoluteChild = null;
  6572. }
  6573. } // 在外层做的margin补丁
  6574. function saveMargin(node) {
  6575. var style = node.style;
  6576. var margin = {};
  6577. ['marginTop', 'marginRight', 'marginBottom', 'marginLeft' // 只支持marginLeft
  6578. ].forEach(function (key) {
  6579. // 只处理百分号
  6580. var value = style[key];
  6581. if (value && /^-?\d+%$/.test(value)) {
  6582. margin[key] = value;
  6583. style[key] = 0;
  6584. }
  6585. });
  6586. node.margin = margin;
  6587. }
  6588. function percent2Num(value) {
  6589. var percent = Number(value.substr(0, value.length - 1));
  6590. return percent / 100;
  6591. }
  6592. function layoutMargin(node) {
  6593. var margin = node.margin,
  6594. layout = node.layout;
  6595. Object.keys(margin).forEach(function (key) {
  6596. var percent = percent2Num(margin[key]);
  6597. if ((key === 'marginLeft' || key === 'marginRight') && layout.width) {
  6598. layout.left += layout.width * percent;
  6599. } else if ((key === 'marginTop' || key === 'marginBottom') && layout.height) {
  6600. layout.top += layout.height * percent;
  6601. }
  6602. });
  6603. }
  6604. function layoutNode(node, parentMaxWidth, parentDirection) {
  6605. node.shouldUpdate = true; // hack
  6606. saveMargin(node);
  6607. var direction = node.style.direction || CSS_DIRECTION_LTR;
  6608. 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;
  6609. if (skipLayout) {
  6610. node.layout.width = node.lastLayout.width;
  6611. node.layout.height = node.lastLayout.height;
  6612. node.layout.top = node.lastLayout.top;
  6613. node.layout.left = node.lastLayout.left;
  6614. } else {
  6615. if (!node.lastLayout) {
  6616. node.lastLayout = {};
  6617. }
  6618. node.lastLayout.requestedWidth = node.layout.width;
  6619. node.lastLayout.requestedHeight = node.layout.height;
  6620. node.lastLayout.parentMaxWidth = parentMaxWidth;
  6621. node.lastLayout.direction = direction; // Reset child layouts
  6622. node.children.forEach(function (child) {
  6623. child.layout.width = undefined;
  6624. child.layout.height = undefined;
  6625. child.layout.top = 0;
  6626. child.layout.left = 0;
  6627. });
  6628. layoutNodeImpl(node, parentMaxWidth, parentDirection);
  6629. node.lastLayout.width = node.layout.width;
  6630. node.lastLayout.height = node.layout.height;
  6631. node.lastLayout.top = node.layout.top;
  6632. node.lastLayout.left = node.layout.left;
  6633. } // hack
  6634. layoutMargin(node);
  6635. }
  6636. /* eslint-enable */
  6637. function computeLayout(node) {
  6638. if (!node) return node;
  6639. var style = node.style,
  6640. children = node.children;
  6641. if (style) {
  6642. fillNodes(node);
  6643. layoutNode(node, null, null);
  6644. return node;
  6645. }
  6646. if (children && children.length) {
  6647. for (var i = 0, len = children.length; i < len; i++) {
  6648. computeLayout(children[i]);
  6649. }
  6650. }
  6651. return node;
  6652. }
  6653. var rect = (function (layout) {
  6654. var left = layout.left,
  6655. top = layout.top,
  6656. width = layout.width,
  6657. height = layout.height;
  6658. return {
  6659. x: left,
  6660. y: top,
  6661. width: width,
  6662. height: height
  6663. };
  6664. });
  6665. var line = (function (layout) {
  6666. var left = layout.left,
  6667. top = layout.top,
  6668. width = layout.width,
  6669. height = layout.height;
  6670. return {
  6671. x1: left,
  6672. y1: top,
  6673. x2: left + width,
  6674. y2: top + height
  6675. };
  6676. });
  6677. var text = (function (layout) {
  6678. var height = layout.height,
  6679. left = layout.left,
  6680. top = layout.top;
  6681. return {
  6682. x: left,
  6683. y: top + height / 2,
  6684. // 通过middle + top 才能比较好的实现文本对齐
  6685. textBaseline: 'middle'
  6686. };
  6687. });
  6688. var circle = (function (layout) {
  6689. var left = layout.left,
  6690. top = layout.top,
  6691. width = layout.width;
  6692. var r = width / 2;
  6693. return {
  6694. x: left + r,
  6695. y: top + r,
  6696. r: r
  6697. };
  6698. });
  6699. var marker = (function (layout) {
  6700. var left = layout.left,
  6701. top = layout.top,
  6702. width = layout.width;
  6703. var r = width / 2;
  6704. return {
  6705. x: left + r,
  6706. y: top,
  6707. radius: r
  6708. };
  6709. });
  6710. var map$2 = {
  6711. rect: rect,
  6712. line: line,
  6713. text: text,
  6714. circle: circle,
  6715. marker: marker,
  6716. group: rect
  6717. };
  6718. var getShapeAttrs = (function (type, layout) {
  6719. if (!layout) return null;
  6720. var fn = map$2[type] || rect;
  6721. return fn(layout);
  6722. });
  6723. var ELEMENT_APPEAR = 'appear'; // 标识元素更新
  6724. var ELEMENT_UPDATE = 'update'; // 标识是删除的元素
  6725. var ELEMENT_DELETE = 'delete';
  6726. function createClipElement(type, config) {
  6727. return new Shape[upperFirst(type)](config);
  6728. }
  6729. var getAnimation = (function (element, animation, nextAttrs, lastAttrs) {
  6730. if (!animation) return null; // 获取shape的默认属性
  6731. var status = element.get('status');
  6732. var clip = animation.clip,
  6733. start = animation.start,
  6734. end = animation.end,
  6735. easing = animation.easing,
  6736. delay = animation.delay,
  6737. duration = animation.duration;
  6738. var clipConfig = isFunction(clip) ? clip(element._attrs.attrs) : clip; // 裁剪动画
  6739. if (clipConfig) {
  6740. var type = clipConfig.type,
  6741. attrs = clipConfig.attrs,
  6742. clipStart = clipConfig.start;
  6743. var clipElement = createClipElement(type, {
  6744. attrs: _objectSpread(_objectSpread({}, attrs), clipStart)
  6745. }); // 默认用 animation 配置里的 easing 和 duration
  6746. clipConfig.easing = clipConfig.easing || easing;
  6747. clipConfig.delay = typeof clipConfig.delay === 'number' ? clipConfig.delay : delay;
  6748. clipConfig.duration = clipConfig.duration || duration;
  6749. clipConfig.element = clipElement;
  6750. }
  6751. var defaultAttrs = element.getDefaultAttrs();
  6752. return _objectSpread(_objectSpread({}, animation), {}, {
  6753. clip: clipConfig,
  6754. start: _objectSpread(_objectSpread(_objectSpread({}, defaultAttrs), lastAttrs), start),
  6755. end: _objectSpread(_objectSpread({}, status === ELEMENT_DELETE ? null : nextAttrs), end)
  6756. });
  6757. });
  6758. function createNodeTree(element, container, px2hd) {
  6759. var key = element.key,
  6760. ref = element.ref,
  6761. _cache = element._cache,
  6762. type = element.type,
  6763. props = element.props,
  6764. status = element.status,
  6765. animation = element.animation;
  6766. var children = extendMap(props.children, function (child) {
  6767. return createNodeTree(child, container, px2hd);
  6768. }); // const { style, attrs } = props;
  6769. var style = px2hd(props.style);
  6770. var attrs = px2hd(props.attrs); // 文本要自动计算文本的宽高, TODO, 后面再优化
  6771. if (type === 'text') {
  6772. var shape = container.addShape(type, {
  6773. attrs: _objectSpread({
  6774. x: 0,
  6775. y: 0
  6776. }, attrs)
  6777. });
  6778. var _shape$getBBox = shape.getBBox(),
  6779. width = _shape$getBBox.width,
  6780. height = _shape$getBBox.height;
  6781. style = _objectSpread({
  6782. width: width,
  6783. height: height
  6784. }, style); // 无用,销毁掉
  6785. shape.remove(true);
  6786. }
  6787. return {
  6788. key: key,
  6789. ref: ref,
  6790. _cache: _cache,
  6791. type: type,
  6792. props: props,
  6793. children: children,
  6794. status: status,
  6795. animation: animation,
  6796. // 处理px2hd之后的配置
  6797. style: style,
  6798. attrs: attrs
  6799. };
  6800. }
  6801. function mergeLayout(parent, layout) {
  6802. if (!parent || !layout) return layout;
  6803. var parentLeft = parent.left,
  6804. parentTop = parent.top;
  6805. var left = layout.left,
  6806. top = layout.top;
  6807. return _objectSpread(_objectSpread({}, layout), {}, {
  6808. left: parentLeft + left,
  6809. top: parentTop + top
  6810. });
  6811. }
  6812. function createElement(node, container, parentLayout, animate) {
  6813. var _node$_cache = node._cache,
  6814. _cache = _node$_cache === void 0 ? {} : _node$_cache,
  6815. ref = node.ref,
  6816. type = node.type,
  6817. props = node.props,
  6818. attrs = node.attrs,
  6819. originLayout = node.layout,
  6820. renderChildren = node.renderChildren,
  6821. nodeChildren = node.children,
  6822. status = node.status,
  6823. animation = node.animation;
  6824. var layout = mergeLayout(parentLayout, originLayout); // 该元素上一次的attrs
  6825. var lastAttrs = _cache.attrs;
  6826. var elementAttrs = _objectSpread(_objectSpread(_objectSpread({}, getShapeAttrs(type, layout)), status === ELEMENT_DELETE ? lastAttrs : null), attrs); // 缓存这次新的attrs
  6827. _cache.attrs = elementAttrs;
  6828. if (elementAttrs.clip) {
  6829. var clip = elementAttrs.clip;
  6830. var clipConfig = isFunction(clip) ? clip(elementAttrs) : clip;
  6831. elementAttrs.clip = createClipElement(clipConfig.type, clipConfig);
  6832. }
  6833. var element;
  6834. if (type === 'group') {
  6835. element = container.addGroup(_objectSpread(_objectSpread({}, omit(props, ['children'])), {}, {
  6836. status: status,
  6837. attrs: elementAttrs
  6838. })); // 如果元素被删除了,就不会有renderChildren, 直接拿node.children渲染
  6839. var children = renderChildren ? renderChildren : nodeChildren; // 只有group才需要处理children
  6840. if (children && children.length) {
  6841. for (var i = 0, len = children.length; i < len; i++) {
  6842. createElement(children[i], element, layout, animate);
  6843. }
  6844. }
  6845. } else {
  6846. element = container.addShape(type, _objectSpread(_objectSpread({}, props), {}, {
  6847. status: status,
  6848. attrs: elementAttrs
  6849. }));
  6850. }
  6851. if (animate !== false) {
  6852. element.set('animation', getAnimation(element, animation, elementAttrs, lastAttrs));
  6853. }
  6854. if (ref) {
  6855. ref.current = element;
  6856. }
  6857. return element;
  6858. } // 过滤删除的元素,让其不参与布局计算
  6859. function filterDeleteElement(node) {
  6860. var status = node.status,
  6861. children = node.children;
  6862. if (status === ELEMENT_DELETE) {
  6863. return null;
  6864. }
  6865. if (!children || !children.length) {
  6866. return node;
  6867. }
  6868. var newChildren = children.filter(function (child) {
  6869. return !!filterDeleteElement(child);
  6870. }); // 要保留引用
  6871. node.children = newChildren;
  6872. node.renderChildren = children;
  6873. return node;
  6874. }
  6875. function render(element, container, animate) {
  6876. var px2hd$1 = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : px2hd;
  6877. if (!element) {
  6878. return;
  6879. }
  6880. var nodeTree = createNodeTree(element, container, px2hd$1);
  6881. var computeLayoutTree = filterDeleteElement(nodeTree);
  6882. computeLayout(computeLayoutTree);
  6883. return createElement(nodeTree, container, null, animate);
  6884. }
  6885. var render$1 = (function (element, container, animate) {
  6886. return render(element, container, animate);
  6887. });
  6888. function renderJSXElement(element, context, updater) {
  6889. if (!element) return element;
  6890. var _element = element,
  6891. type = _element.type,
  6892. key = _element.key,
  6893. ref = _element.ref,
  6894. props = _element.props,
  6895. _element$_cache = _element._cache,
  6896. _cache = _element$_cache === void 0 ? {} : _element$_cache; // render children first
  6897. var children = Children.map(props.children, function (child) {
  6898. return renderJSXElement(child, context, updater);
  6899. });
  6900. element = {
  6901. type: type,
  6902. key: key,
  6903. ref: ref,
  6904. _cache: _cache,
  6905. props: _objectSpread(_objectSpread({}, props), {}, {
  6906. children: children
  6907. })
  6908. };
  6909. if (typeof type === 'function') {
  6910. // @ts-ignore
  6911. var newElement = type(element.props, context, updater);
  6912. if (!newElement) return newElement; // recursive render until type is string
  6913. return renderJSXElement(_objectSpread(_objectSpread({}, newElement), {}, {
  6914. // 保留原始的key和ref
  6915. key: key !== undefined ? key : newElement.key,
  6916. ref: ref !== undefined ? ref : newElement.ref
  6917. }), context, updater);
  6918. } // return element if type is string
  6919. return element;
  6920. }
  6921. var renderJSXElement$1 = (function (element, context, updater) {
  6922. return renderJSXElement(element, context, updater);
  6923. });
  6924. var _excluded$1 = ["children", "animation"],
  6925. _excluded2 = ["children", "animation"],
  6926. _excluded3 = ["children", "animation"],
  6927. _excluded4 = ["animation"],
  6928. _excluded5 = ["animation"];
  6929. function deleteElement(element) {
  6930. // 是否有非空的子元素
  6931. var hasElement = false;
  6932. var receiveElement = Children.map(element, function (item) {
  6933. if (!item) return item;
  6934. var ref = item.ref,
  6935. key = item.key,
  6936. type = item.type,
  6937. props = item.props,
  6938. _cache = item._cache;
  6939. var children = props.children,
  6940. animation = props.animation,
  6941. receiveProps = _objectWithoutProperties(props, _excluded$1);
  6942. var status = ELEMENT_DELETE;
  6943. var receiveAnimation = animation && animation.leave;
  6944. var receiveChildren = deleteElement(children); // 没有子元素,且自身也不需要动画,则直接删除
  6945. if (!receiveChildren && !receiveAnimation) {
  6946. return null;
  6947. }
  6948. hasElement = true;
  6949. return {
  6950. ref: ref,
  6951. key: key,
  6952. type: type,
  6953. props: _objectSpread(_objectSpread({}, receiveProps), {}, {
  6954. children: receiveChildren
  6955. }),
  6956. _cache: _cache,
  6957. animation: receiveAnimation,
  6958. status: status
  6959. };
  6960. }); // 如果没有非空的子元素,都删除
  6961. if (!hasElement) {
  6962. return null;
  6963. }
  6964. return receiveElement;
  6965. }
  6966. function appearElement(element) {
  6967. return Children.map(element, function (item) {
  6968. if (!item) return item;
  6969. var ref = item.ref,
  6970. key = item.key,
  6971. type = item.type,
  6972. props = item.props,
  6973. _cache = item._cache;
  6974. var children = props.children,
  6975. animation = props.animation,
  6976. receiveProps = _objectWithoutProperties(props, _excluded2);
  6977. var status = ELEMENT_APPEAR;
  6978. var receiveAnimation = animation && animation.appear;
  6979. var receiveChildren = appearElement(children);
  6980. return {
  6981. ref: ref,
  6982. key: key,
  6983. type: type,
  6984. props: _objectSpread(_objectSpread({}, receiveProps), {}, {
  6985. children: receiveChildren
  6986. }),
  6987. _cache: _cache,
  6988. animation: receiveAnimation,
  6989. status: status
  6990. };
  6991. });
  6992. }
  6993. function updateElement(nextElement, lastElement) {
  6994. var ref = nextElement.ref,
  6995. key = nextElement.key,
  6996. type = nextElement.type,
  6997. _nextCache = nextElement._cache,
  6998. nextProps = nextElement.props;
  6999. var _lastCache = lastElement._cache,
  7000. lastProps = lastElement.props;
  7001. var nextChildren = nextProps.children,
  7002. nextAnimation = nextProps.animation,
  7003. nextReceiveProps = _objectWithoutProperties(nextProps, _excluded3);
  7004. var lastChildren = lastProps.children; // 继续比较子元素
  7005. var children = compareElement(nextChildren, lastChildren); // 保留缓存值
  7006. var _cache = mix(_nextCache, _lastCache); // 动画
  7007. var animation = nextAnimation && nextAnimation.update; // 生成新对象
  7008. return {
  7009. ref: ref,
  7010. key: key,
  7011. type: type,
  7012. props: _objectSpread(_objectSpread({}, nextReceiveProps), {}, {
  7013. children: children
  7014. }),
  7015. _cache: _cache,
  7016. animation: animation,
  7017. status: ELEMENT_UPDATE
  7018. };
  7019. } // 形变动画, TODO
  7020. function morphElement(nextElement, lastElement) {
  7021. return [deleteElement(lastElement), appearElement(nextElement)];
  7022. }
  7023. function changeTypeToGroup(nextGroupElement, lastShapeElement) {
  7024. var key = nextGroupElement.key,
  7025. type = nextGroupElement.type,
  7026. ref = nextGroupElement.ref,
  7027. groupProps = nextGroupElement.props,
  7028. _groupCache = nextGroupElement._cache;
  7029. var lastType = lastShapeElement.type,
  7030. _lastCache = lastShapeElement._cache;
  7031. var groupChildren = groupProps.children; // let existTransform = false;
  7032. var children = Children.map(groupChildren, function (nextElement) {
  7033. if (!nextElement) return nextElement;
  7034. var key = nextElement.key,
  7035. ref = nextElement.ref,
  7036. nextType = nextElement.type,
  7037. nextProps = nextElement.props,
  7038. _nextCache = nextElement._cache; // if (nextType === 'group') {
  7039. // return changeTypeToGroup(nextElement, lastShapeElement);
  7040. // }
  7041. if (nextType !== lastType) {
  7042. return morphElement(nextElement, lastShapeElement);
  7043. } // existTransform = true;
  7044. var nextAnimation = nextProps.animation,
  7045. nextReceiveProps = _objectWithoutProperties(nextProps, _excluded4);
  7046. var animation = nextAnimation && nextAnimation.update;
  7047. return {
  7048. ref: ref,
  7049. key: key,
  7050. type: nextType,
  7051. props: nextReceiveProps,
  7052. _cache: mix(_nextCache, _lastCache),
  7053. animation: animation,
  7054. status: ELEMENT_UPDATE
  7055. };
  7056. });
  7057. return {
  7058. key: key,
  7059. type: type,
  7060. ref: ref,
  7061. props: _objectSpread(_objectSpread({}, groupProps), {}, {
  7062. children: children
  7063. }),
  7064. _cache: _groupCache,
  7065. status: ELEMENT_UPDATE
  7066. };
  7067. }
  7068. function changeTypeFromGroup(nextShapeElement, lastGroupElement) {
  7069. var nextRef = nextShapeElement.ref,
  7070. nextKey = nextShapeElement.key,
  7071. nextType = nextShapeElement.type,
  7072. nextShapeProps = nextShapeElement.props,
  7073. _nextCache = nextShapeElement._cache;
  7074. var lastType = lastGroupElement.type,
  7075. lastProps = lastGroupElement.props;
  7076. var nextAnimation = nextShapeProps.animation,
  7077. nextReceiveProps = _objectWithoutProperties(nextShapeProps, _excluded5);
  7078. var groupChildren = lastProps.children;
  7079. var animation = nextAnimation && nextAnimation.update;
  7080. if (!animation) {
  7081. return [deleteElement(lastGroupElement), appearElement[nextShapeElement]];
  7082. }
  7083. var transformChild = null;
  7084. var children = Children.map(groupChildren, function (child) {
  7085. if (!child) return child;
  7086. var childType = child.type,
  7087. _childCache = child._cache;
  7088. if (childType !== nextType) {
  7089. // TODO: child 形变
  7090. return deleteElement(child);
  7091. }
  7092. if (!transformChild) {
  7093. transformChild = child;
  7094. }
  7095. return {
  7096. type: nextType,
  7097. props: nextShapeProps,
  7098. _cache: _childCache,
  7099. animation: animation,
  7100. status: ELEMENT_UPDATE
  7101. };
  7102. });
  7103. if (!transformChild) {
  7104. return [deleteElement(lastGroupElement), appearElement(nextShapeElement)];
  7105. }
  7106. var nextElement = {
  7107. ref: nextRef,
  7108. key: nextKey,
  7109. type: nextType,
  7110. props: nextReceiveProps,
  7111. _cache: mix(_nextCache, transformChild._cache),
  7112. animation: animation,
  7113. status: ELEMENT_UPDATE
  7114. }; // 保留group 结构
  7115. return [{
  7116. type: lastType,
  7117. props: _objectSpread(_objectSpread({}, lastProps), {}, {
  7118. children: children
  7119. }),
  7120. status: ELEMENT_DELETE
  7121. }, nextElement];
  7122. }
  7123. function changeElementType(nextElement, lastElement) {
  7124. var nextType = nextElement.type;
  7125. var lastType = lastElement.type;
  7126. if (nextType === 'group') {
  7127. return changeTypeToGroup(nextElement, lastElement);
  7128. }
  7129. if (lastType === 'group') {
  7130. return changeTypeFromGroup(nextElement, lastElement);
  7131. } // 都不是group, 形变动画 TODO
  7132. return morphElement(nextElement, lastElement);
  7133. } // 对比2个数组
  7134. function compareArray$1(nextElements, lastElements) {
  7135. var keyed = {};
  7136. var nextLength = nextElements.length;
  7137. var lastLength = lastElements.length;
  7138. for (var i = 0; i < lastLength; i++) {
  7139. var element = lastElements[i];
  7140. if (element && !isNil(element.key)) {
  7141. var key = element.key;
  7142. keyed[key] = element;
  7143. }
  7144. } // 比较元素
  7145. var maxLength = Math.max(nextLength, lastLength);
  7146. var returnElements = [];
  7147. for (var _i = 0; _i < maxLength; _i++) {
  7148. var nextElement = nextElements[_i];
  7149. if (!nextElement) {
  7150. returnElements.push(compareElement(nextElement, lastElements[_i]));
  7151. continue;
  7152. }
  7153. var _key = nextElement.key; // 有key值定义
  7154. if (!isNil(_key)) {
  7155. var lastElement = keyed[_key];
  7156. if (lastElement) delete keyed[_key];
  7157. returnElements.push(compareElement(nextElement, lastElement));
  7158. continue;
  7159. }
  7160. returnElements.push(compareElement(nextElement, lastElements[_i]));
  7161. } // 说明是删除的元素
  7162. Object.keys(keyed).forEach(function (key) {
  7163. returnElements.push(compareElement(null, keyed[key]));
  7164. });
  7165. return returnElements;
  7166. } // 比较2个元素,会被递归执行
  7167. function compareElement(nextElement, lastElement) {
  7168. // 都为空
  7169. if (!nextElement && !lastElement) {
  7170. return null;
  7171. } // 新增
  7172. if (!lastElement) {
  7173. return appearElement(nextElement);
  7174. } // 删除
  7175. if (!nextElement) {
  7176. return deleteElement(lastElement);
  7177. } // nextElement & lastElement 都不为空了
  7178. // 如果有数组,比较数组
  7179. if (isArray(nextElement) || isArray(lastElement)) {
  7180. var nextElementArray = isArray(nextElement) ? nextElement : [nextElement];
  7181. var lastElementArray = isArray(lastElement) ? lastElement : [lastElement];
  7182. return compareArray$1(nextElementArray, lastElementArray);
  7183. } // 普通的jsx元素, 且都非空
  7184. var nextKey = nextElement.key,
  7185. nextType = nextElement.type;
  7186. var lastKey = lastElement.key,
  7187. lastType = lastElement.type; // key 值不相等
  7188. if (!isNil(nextKey) && nextKey !== lastKey) {
  7189. return [deleteElement(lastElement), appearElement(nextElement)];
  7190. } // shape 类型的变化
  7191. if (nextType !== lastType) {
  7192. // return [deleteElement(lastElement), nextElement];
  7193. return changeElementType(nextElement, lastElement);
  7194. }
  7195. return updateElement(nextElement, lastElement);
  7196. } // 因为要实现删除元素的动画,所以需要保留删除的元素,diff 后需要创建一颗新树, 实际渲染也需要拿这颗树来进行
  7197. var Animator = /*#__PURE__*/function () {
  7198. function Animator(element, animation) {
  7199. _classCallCheck(this, Animator);
  7200. // 是否是裁剪动画
  7201. this.isClip = false;
  7202. this.end = false;
  7203. this.element = element;
  7204. this.animation = animation;
  7205. var _animation$property = animation.property,
  7206. property = _animation$property === void 0 ? [] : _animation$property,
  7207. easing = animation.easing,
  7208. duration = animation.duration,
  7209. _animation$delay = animation.delay,
  7210. delay = _animation$delay === void 0 ? 0 : _animation$delay,
  7211. start = animation.start,
  7212. end = animation.end,
  7213. onFrame = animation.onFrame,
  7214. isClip = animation.isClip;
  7215. var interpolates = property.map(function (name) {
  7216. if (isString(name)) {
  7217. return interpolate$1(start[name], end[name]);
  7218. } // @ts-ignore
  7219. if (name.interpolate) {
  7220. // @ts-ignore
  7221. return name.interpolate(start, end);
  7222. }
  7223. });
  7224. this.easing = typeof easing === 'function' ? easing : Easing[easing] || linear$1;
  7225. this.property = property;
  7226. this.interpolates = interpolates;
  7227. this.duration = duration;
  7228. this.delay = delay;
  7229. this.onFrame = onFrame;
  7230. this.totalDuration = duration + delay;
  7231. this.isClip = isClip; // 更新到初始状态
  7232. this.update(0, 0);
  7233. }
  7234. _createClass(Animator, [{
  7235. key: "to",
  7236. value: function to(time) {
  7237. var duration = this.duration,
  7238. delay = this.delay,
  7239. totalDuration = this.totalDuration,
  7240. easing = this.easing,
  7241. end = this.end; // 已结束
  7242. if (end) {
  7243. return;
  7244. } // 未开始
  7245. if (time <= delay || !duration) {
  7246. return;
  7247. } // 最大为1
  7248. var t = time >= totalDuration ? 1 : (time - delay) / duration;
  7249. this.update(easing(t), time); // 最后一帧
  7250. if (t === 1) {
  7251. this.onEnd();
  7252. }
  7253. }
  7254. }, {
  7255. key: "update",
  7256. value: function update(t, time) {
  7257. var element = this.element,
  7258. interpolates = this.interpolates,
  7259. property = this.property,
  7260. onFrame = this.onFrame;
  7261. var attrs = {};
  7262. for (var i = property.length - 1; i >= 0; i--) {
  7263. var name = property[i];
  7264. if (isString(name)) {
  7265. attrs[name] = interpolates[i](t);
  7266. } else {
  7267. // @ts-ignore
  7268. attrs[name.name] = interpolates[i](t);
  7269. }
  7270. }
  7271. if (onFrame) {
  7272. attrs = _objectSpread(_objectSpread({}, attrs), this.onFrame(t, time));
  7273. }
  7274. element.attr(attrs);
  7275. }
  7276. }, {
  7277. key: "onEnd",
  7278. value: function onEnd() {
  7279. var animation = this.animation,
  7280. isClip = this.isClip,
  7281. element = this.element;
  7282. var onEnd = animation.onEnd;
  7283. onEnd && onEnd.call(this);
  7284. if (isClip) {
  7285. // 如果是裁剪区动画,要移除裁剪区
  7286. element.remove(true);
  7287. } // 如果当前元素状态被标记为删除,等动画结束后直接删除
  7288. if (element._attrs.status === ELEMENT_DELETE) {
  7289. element.remove(true);
  7290. } // 清空 不需要重复执行
  7291. element.set('animation', null);
  7292. this.end = true;
  7293. }
  7294. }]);
  7295. return Animator;
  7296. }();
  7297. function eachElement(element, fn) {
  7298. fn(element);
  7299. var children = element.get('children');
  7300. if (children && children.length) {
  7301. for (var i = 0, len = children.length; i < len; i++) {
  7302. var child = children[i];
  7303. eachElement(child, fn);
  7304. }
  7305. }
  7306. }
  7307. var Animation = /*#__PURE__*/function () {
  7308. function Animation(canvas) {
  7309. _classCallCheck(this, Animation);
  7310. this.timeline = new Timeline$1();
  7311. this.canvas = canvas;
  7312. }
  7313. _createClass(Animation, [{
  7314. key: "createAnimator",
  7315. value: function createAnimator(element, animation) {
  7316. var duration = animation.duration,
  7317. property = animation.property,
  7318. onFrame = animation.onFrame; // 校验关键参数
  7319. if (!duration || (!property || !property.length) && !onFrame) {
  7320. return;
  7321. }
  7322. return new Animator(element, animation);
  7323. }
  7324. }, {
  7325. key: "play",
  7326. value: function play(container, onAnimationEnd) {
  7327. var _this = this;
  7328. var canvas = this.canvas;
  7329. var animators = [];
  7330. var maxDuration = 0;
  7331. var deleteElements = []; // 遍历整个树,找到全部需要动画的元素
  7332. eachElement(container, function (element) {
  7333. // TODO: status 需要提取状态
  7334. var _element$_attrs = element._attrs,
  7335. animation = _element$_attrs.animation,
  7336. status = _element$_attrs.status;
  7337. if (!animation) {
  7338. if (status === ELEMENT_DELETE) {
  7339. // element.remove(true);
  7340. deleteElements.push(element);
  7341. }
  7342. return;
  7343. }
  7344. var animator = _this.createAnimator(element, animation);
  7345. if (animator) {
  7346. maxDuration = Math.max(maxDuration, animator.totalDuration);
  7347. animators.push(animator);
  7348. }
  7349. var clip = animation.clip; // 如果有裁剪区动画,处理裁剪区动画
  7350. if (clip) {
  7351. clip.isClip = true;
  7352. var clipElement = clip.element;
  7353. var _animator = _this.createAnimator(clipElement, clip);
  7354. if (_animator) {
  7355. maxDuration = Math.max(maxDuration, _animator.totalDuration);
  7356. element.attr('clip', clipElement);
  7357. animators.push(_animator);
  7358. }
  7359. }
  7360. });
  7361. for (var i = 0, len = deleteElements.length; i < len; i++) {
  7362. var element = deleteElements[i];
  7363. var children = element._attrs.children; // 因为group的子元素也有可能有动画,所以这里先把叶子节点删除掉,等动画结束后,再把所有删除的元素删除掉
  7364. if (!children || !children.length) {
  7365. element.remove(true);
  7366. }
  7367. } // 开始播放动画
  7368. this.timeline.play(maxDuration, function (time) {
  7369. for (var _i = 0, _len = animators.length; _i < _len; _i++) {
  7370. var animator = animators[_i];
  7371. animator.to(time);
  7372. } // 最后一帧放在end里统一draw, 避免重复draw
  7373. if (time < maxDuration) {
  7374. canvas.draw();
  7375. }
  7376. }, function () {
  7377. for (var _i2 = 0, _len2 = deleteElements.length; _i2 < _len2; _i2++) {
  7378. var _element = deleteElements[_i2];
  7379. _element.remove(true);
  7380. }
  7381. canvas.draw();
  7382. onAnimationEnd && onAnimationEnd();
  7383. });
  7384. } // 直接跳到动画最终态
  7385. }, {
  7386. key: "end",
  7387. value: function end() {
  7388. this.timeline.end();
  7389. }
  7390. }, {
  7391. key: "abort",
  7392. value: function abort() {
  7393. this.timeline.abort();
  7394. }
  7395. }]);
  7396. return Animation;
  7397. }();
  7398. function createUpdater(canvas) {
  7399. var setStateQueue = [];
  7400. var renderQueue = [];
  7401. var callbackQueue = [];
  7402. function process() {
  7403. var item; // let component;
  7404. while (item = setStateQueue.shift()) {
  7405. var _item = item,
  7406. state = _item.state,
  7407. component = _item.component,
  7408. callback = _item.callback;
  7409. if (component.destroyed) {
  7410. continue;
  7411. } // 如果没有prevState,则将当前的state作为初始的prevState
  7412. if (!component.prevState) {
  7413. component.prevState = Object.assign({}, component.state);
  7414. } // 如果stateChange是一个方法,也就是setState的第二种形式
  7415. if (typeof state === 'function') {
  7416. Object.assign(component.state, state(component.prevState, component.props));
  7417. } else {
  7418. // 如果stateChange是一个对象,则直接合并到setState中
  7419. Object.assign(component.state, state);
  7420. }
  7421. component.prevState = component.state;
  7422. if (typeof callback === 'function') {
  7423. callbackQueue.push({
  7424. callback: callback,
  7425. component: component
  7426. });
  7427. }
  7428. }
  7429. var renderComponents = [].concat(renderQueue);
  7430. canvas.renderComponents(renderComponents); // callback queue
  7431. commitRenderQueue(); // 清空
  7432. renderQueue.length = 0;
  7433. callbackQueue.length = 0;
  7434. }
  7435. function enqueueSetState(component, state, callback) {
  7436. if (setStateQueue.length === 0) {
  7437. setTimeout(process, 0);
  7438. }
  7439. setStateQueue.push({
  7440. component: component,
  7441. state: state,
  7442. callback: callback
  7443. });
  7444. if (renderQueue.indexOf(component) < 0) {
  7445. renderQueue.push(component);
  7446. }
  7447. }
  7448. function commitRenderQueue() {
  7449. for (var i = 0; i < callbackQueue.length; i++) {
  7450. var _callbackQueue$i = callbackQueue[i],
  7451. callback = _callbackQueue$i.callback,
  7452. component = _callbackQueue$i.component;
  7453. callback.call(component);
  7454. }
  7455. }
  7456. var updater = {
  7457. // isMounted: function(publicInstance) {
  7458. // return false;
  7459. // },
  7460. enqueueForceUpdate: enqueueSetState,
  7461. // enqueueReplaceState: function(publicInstance, completeState) {
  7462. // },
  7463. enqueueSetState: enqueueSetState
  7464. };
  7465. return updater;
  7466. }
  7467. var axis = {
  7468. labelOffset: '15px',
  7469. line: {
  7470. stroke: '#E8E8E8',
  7471. lineWidth: '1px'
  7472. },
  7473. label: {
  7474. fill: '#808080',
  7475. fontSize: '20px'
  7476. },
  7477. grid: {
  7478. stroke: '#E8E8E8',
  7479. lineWidth: '1px',
  7480. lineDash: ['4px']
  7481. }
  7482. };
  7483. var guide = {
  7484. line: {
  7485. style: {
  7486. stroke: '#a3a3a3',
  7487. lineWidth: 1
  7488. },
  7489. offsetX: 0,
  7490. offsetY: 0
  7491. },
  7492. text: {
  7493. style: {
  7494. fill: '#787878',
  7495. // textAlign: 'center',
  7496. textBaseline: 'middle'
  7497. },
  7498. offsetX: 0,
  7499. offsetY: 0
  7500. },
  7501. rect: {
  7502. style: {
  7503. fill: '#fafafa'
  7504. }
  7505. },
  7506. arc: {
  7507. style: {
  7508. stroke: '#a3a3a3'
  7509. }
  7510. },
  7511. html: {
  7512. offsetX: 0,
  7513. offsetY: 0,
  7514. alignX: 'center',
  7515. alignY: 'middle'
  7516. },
  7517. tag: {
  7518. offsetX: 0,
  7519. offsetY: 0,
  7520. side: 4,
  7521. background: {
  7522. padding: 5,
  7523. radius: 2,
  7524. fill: '#1890FF'
  7525. },
  7526. textStyle: {
  7527. fontSize: 12,
  7528. fill: '#fff',
  7529. textAlign: 'center',
  7530. textBaseline: 'middle'
  7531. }
  7532. },
  7533. point: {
  7534. offsetX: 0,
  7535. offsetY: 0,
  7536. style: {
  7537. fill: '#fff',
  7538. r: 3,
  7539. lineWidth: 2,
  7540. stroke: '#1890ff'
  7541. }
  7542. }
  7543. };
  7544. var chart = {
  7545. padding: ['30px', '30px', '30px', '30px']
  7546. };
  7547. var Theme = {
  7548. fontFamily: '"Helvetica Neue", Helvetica, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", Arial, sans-serif',
  7549. pixelRatio: 1,
  7550. padding: [0, 0, 0, 0],
  7551. chart: chart,
  7552. colors: ['#1890FF', '#2FC25B', '#FACC14', '#223273', '#8543E0', '#13C2C2', '#3436C7', '#F04864'],
  7553. shapes: {
  7554. line: ['line', 'dash', 'smooth'],
  7555. point: ['circle', 'hollowCircle', 'rect'],
  7556. area: ['area', 'smooth'],
  7557. interval: ['rect', 'pyramid', 'funnel']
  7558. },
  7559. sizes: ['4px', '6px', '8px', '10px', '12px'],
  7560. shape: {
  7561. line: {
  7562. default: {
  7563. lineWidth: '4px',
  7564. lineJoin: 'round',
  7565. lineCap: 'round'
  7566. },
  7567. smooth: {
  7568. smooth: true
  7569. },
  7570. dash: {
  7571. lineDash: ['8px', '8px']
  7572. }
  7573. },
  7574. point: {
  7575. default: {
  7576. size: '6px'
  7577. },
  7578. hollowCircle: {
  7579. lineWidth: '2px'
  7580. }
  7581. },
  7582. area: {
  7583. default: {
  7584. fillOpacity: 0.1
  7585. }
  7586. },
  7587. interval: {
  7588. default: {}
  7589. }
  7590. },
  7591. axis: axis,
  7592. guide: guide
  7593. };
  7594. var _excluded$2 = ["transformFrom"];
  7595. function pickElement(element) {
  7596. if (!element) return element;
  7597. return Children.map(element, function (item) {
  7598. if (!item) return item; // 只需要这几个元素就可以了
  7599. return pick(item, ['key', 'ref', 'type', 'props']);
  7600. });
  7601. }
  7602. function renderShape(component, children, animate) {
  7603. var container = component.container,
  7604. context = component.context,
  7605. updater = component.updater,
  7606. __lastElement = component.__lastElement,
  7607. transformFrom = component.transformFrom,
  7608. componentAnimate = component.animate; // 先清空绘制内容
  7609. container.clear();
  7610. animate = isBoolean(animate) ? animate : componentAnimate;
  7611. var px2hd = context.px2hd;
  7612. var lastElement = __lastElement || transformFrom && transformFrom.__lastElement; // children 是 shape 的 jsx 结构, component.render() 返回的结构
  7613. var shapeElement = renderJSXElement$1(children, context, updater); // @ts-ignore
  7614. component.__lastElement = shapeElement;
  7615. var renderElement = animate !== false ? compareElement(shapeElement, lastElement) : shapeElement;
  7616. if (!renderElement) return null; // 生成G的节点树, 存在数组的情况是根节点有变化,之前的树删除,新的树创建
  7617. if (isArray(renderElement)) {
  7618. return renderElement.map(function (element) {
  7619. return render(element, container, animate, px2hd);
  7620. });
  7621. } else {
  7622. return render(renderElement, container, animate, px2hd);
  7623. }
  7624. }
  7625. function setComponentAnimate(child, parent) {
  7626. var parentAnimate = parent.animate; // 如果父组件不需要动画,子组件全不不执行动画
  7627. if (parentAnimate === false) {
  7628. child.animate = false;
  7629. return;
  7630. }
  7631. var childProps = child.props;
  7632. var childAnimate = childProps.animate;
  7633. child.animate = isBoolean(childAnimate) ? childAnimate : parentAnimate;
  7634. }
  7635. function getTransformComponent(component) {
  7636. if (!component) return null; // @ts-ignore
  7637. var __lastElement = component.__lastElement,
  7638. children = component.children;
  7639. if (__lastElement) {
  7640. return component;
  7641. }
  7642. if (!children) {
  7643. return null;
  7644. }
  7645. var componentFromChildren = null;
  7646. Children.map(children, function (item) {
  7647. if (componentFromChildren) return;
  7648. if (!item) return;
  7649. var component = getTransformComponent(item.component);
  7650. if (component) {
  7651. componentFromChildren = component;
  7652. }
  7653. });
  7654. return componentFromChildren;
  7655. }
  7656. function getTransformFromComponentRef(transformFromRef) {
  7657. if (!transformFromRef || !transformFromRef.current) {
  7658. return null;
  7659. }
  7660. var transformFromComponent = transformFromRef.current;
  7661. return getTransformComponent(transformFromComponent);
  7662. }
  7663. function createComponent(parent, element) {
  7664. var type = element.type,
  7665. props = element.props,
  7666. ref = element.ref;
  7667. var container = parent.container,
  7668. context = parent.context,
  7669. updater = parent.updater,
  7670. transformFrom = parent.transformFrom;
  7671. var transformFromRef = props.transformFrom,
  7672. receiveProps = _objectWithoutProperties(props, _excluded$2);
  7673. var component; // @ts-ignore
  7674. if (type.prototype && type.prototype.isF2Component) {
  7675. // @ts-ignore
  7676. component = new type(receiveProps, context, updater);
  7677. } else {
  7678. component = new Component(receiveProps, context, updater);
  7679. component.render = function () {
  7680. // @ts-ignore
  7681. return type(this.props, context, updater);
  7682. };
  7683. } // 设置ref
  7684. if (ref) {
  7685. ref.current = component;
  7686. } // 因为view 可能在子组件,所以这里要透传到子组件
  7687. if (transformFrom) {
  7688. // @ts-ignore
  7689. component.transformFrom = transformFrom;
  7690. }
  7691. if (transformFromRef) {
  7692. var transformFromComponent = transformFromRef ? getTransformFromComponentRef(transformFromRef) : null; // @ts-ignore
  7693. component.transformFrom = transformFromComponent;
  7694. }
  7695. var zIndex = props.zIndex; // 每个组件都新建一个独立容器
  7696. component.container = container.addGroup({
  7697. zIndex: zIndex
  7698. });
  7699. component.context = context;
  7700. component.updater = updater;
  7701. return component;
  7702. }
  7703. function renderComponent(component) {
  7704. Children.map(component, function (item) {
  7705. var lastChildren = item.children;
  7706. var mount = isUndefined(lastChildren);
  7707. if (mount) {
  7708. if (item.willMount) item.willMount();
  7709. } else if (item.willUpdate) {
  7710. item.willUpdate();
  7711. }
  7712. });
  7713. Children.map(component, function (item) {
  7714. var lastChildren = item.children;
  7715. var mount = isUndefined(lastChildren);
  7716. var newChildren = item.render();
  7717. renderChildren(item, newChildren, lastChildren);
  7718. if (mount) {
  7719. if (item.didMount) item.didMount();
  7720. } else if (item.didUpdate) {
  7721. item.didUpdate();
  7722. }
  7723. });
  7724. }
  7725. function destroyElement(elements) {
  7726. Children.map(elements, function (element) {
  7727. if (!element) return;
  7728. var component = element.component;
  7729. if (!component) {
  7730. return;
  7731. }
  7732. if (component.willUnmount) {
  7733. component.willUnmount();
  7734. }
  7735. destroyElement(component.children);
  7736. var container = component.container;
  7737. container.remove(true);
  7738. if (component.didUnmount) {
  7739. component.didUnmount();
  7740. }
  7741. component.destroy();
  7742. });
  7743. }
  7744. function diffElement(parent, nextElement, lastElement) {
  7745. if (!nextElement && !lastElement) {
  7746. return null;
  7747. } // 删除
  7748. if (!nextElement && lastElement) {
  7749. destroyElement(lastElement);
  7750. return null;
  7751. } // 新建
  7752. if (nextElement && !lastElement) {
  7753. return nextElement;
  7754. } // diff
  7755. var nextType = nextElement.type,
  7756. nextProps = nextElement.props;
  7757. var lastType = lastElement.type,
  7758. lastProps = lastElement.props,
  7759. lastComponent = lastElement.component;
  7760. if (nextType !== lastType) {
  7761. destroyElement(lastElement);
  7762. return nextElement;
  7763. } // 保留component, 等下一阶段处理
  7764. nextElement.component = lastComponent;
  7765. if (equal(nextProps, lastProps) && lastComponent.context === parent.context) {
  7766. return null;
  7767. }
  7768. return nextElement;
  7769. }
  7770. function diff(parent, nextChildren, lastChildren) {
  7771. // destroy
  7772. // 生命周期的几个阶段
  7773. // should create / update
  7774. // create / Receive props
  7775. // willMount / willUpdate
  7776. // render
  7777. // didMount / didUpdate
  7778. var childrenArray = []; // 1. 第一轮比较, 直接destroy的元素处理掉,destroy 的元素不需要进入下一阶段
  7779. Children.compare(nextChildren, lastChildren, function (next, last) {
  7780. var element = diffElement(parent, next, last);
  7781. if (element) {
  7782. childrenArray = childrenArray.concat(Children.toArray(element).filter(Boolean));
  7783. }
  7784. }); // 2. 处理 shouldCreate 和 shouldUpdate
  7785. var shouldProcessChildren = childrenArray.filter(function (element) {
  7786. var component = element.component,
  7787. props = element.props; // 说明是新增的元素,需要新建
  7788. if (!component) return true; // 不需要更新
  7789. if (component.shouldUpdate && component.shouldUpdate(props) === false) {
  7790. return false;
  7791. }
  7792. return true;
  7793. }); // 3. 处理 create 和 Receive props
  7794. var shouldRenderComponent = shouldProcessChildren.map(function (element) {
  7795. var component = element.component;
  7796. if (!component) {
  7797. component = createComponent(parent, element);
  7798. } else {
  7799. var props = element.props;
  7800. if (component.willReceiveProps) {
  7801. component.willReceiveProps(props, parent.context);
  7802. }
  7803. var zIndex = props.zIndex;
  7804. component.container.set('zIndex', zIndex);
  7805. component.props = props;
  7806. component.context = parent.context;
  7807. }
  7808. element.component = component;
  7809. setComponentAnimate(component, parent);
  7810. return component;
  7811. }); // 4. 处理 render
  7812. renderComponent(shouldRenderComponent); // 按子组件顺序渲染内容
  7813. childrenArray.forEach(function (element) {
  7814. var component = element.component;
  7815. var parentGroup = parent.container;
  7816. parentGroup.add(component.container);
  7817. });
  7818. return nextChildren;
  7819. }
  7820. function isContainer(children) {
  7821. if (!children) return false;
  7822. if (!isArray(children)) {
  7823. var type = children.type;
  7824. return typeof type === 'function';
  7825. }
  7826. for (var i = 0, len = children.length; i < len; i++) {
  7827. if (isContainer(children[i])) {
  7828. return true;
  7829. }
  7830. }
  7831. return false;
  7832. }
  7833. function renderChildren(parent, nextChildren, lastChildren) {
  7834. // react 生成的 element 是 not extensible 的,这里新建一个新对象,并把需要的内容pick 出来
  7835. nextChildren = pickElement(nextChildren);
  7836. parent.children = nextChildren;
  7837. if (isContainer(nextChildren)) {
  7838. nextChildren = diff(parent, nextChildren, lastChildren);
  7839. } else {
  7840. renderShape(parent, nextChildren);
  7841. }
  7842. return nextChildren;
  7843. }
  7844. var WILDCARD = '*';
  7845. /* event-emitter */
  7846. var EventEmitter = /** @class */ (function () {
  7847. function EventEmitter() {
  7848. this._events = {};
  7849. }
  7850. /**
  7851. * 监听一个事件
  7852. * @param evt
  7853. * @param callback
  7854. * @param once
  7855. */
  7856. EventEmitter.prototype.on = function (evt, callback, once) {
  7857. if (!this._events[evt]) {
  7858. this._events[evt] = [];
  7859. }
  7860. this._events[evt].push({
  7861. callback: callback,
  7862. once: !!once,
  7863. });
  7864. return this;
  7865. };
  7866. /**
  7867. * 监听一个事件一次
  7868. * @param evt
  7869. * @param callback
  7870. */
  7871. EventEmitter.prototype.once = function (evt, callback) {
  7872. return this.on(evt, callback, true);
  7873. };
  7874. /**
  7875. * 触发一个事件
  7876. * @param evt
  7877. * @param args
  7878. */
  7879. EventEmitter.prototype.emit = function (evt) {
  7880. var _this = this;
  7881. var args = [];
  7882. for (var _i = 1; _i < arguments.length; _i++) {
  7883. args[_i - 1] = arguments[_i];
  7884. }
  7885. var events = this._events[evt] || [];
  7886. var wildcardEvents = this._events[WILDCARD] || [];
  7887. // 实际的处理 emit 方法
  7888. var doEmit = function (es) {
  7889. var length = es.length;
  7890. for (var i = 0; i < length; i++) {
  7891. if (!es[i]) {
  7892. continue;
  7893. }
  7894. var _a = es[i], callback = _a.callback, once = _a.once;
  7895. if (once) {
  7896. es.splice(i, 1);
  7897. if (es.length === 0) {
  7898. delete _this._events[evt];
  7899. }
  7900. length--;
  7901. i--;
  7902. }
  7903. callback.apply(_this, args);
  7904. }
  7905. };
  7906. doEmit(events);
  7907. doEmit(wildcardEvents);
  7908. };
  7909. /**
  7910. * 取消监听一个事件,或者一个channel
  7911. * @param evt
  7912. * @param callback
  7913. */
  7914. EventEmitter.prototype.off = function (evt, callback) {
  7915. if (!evt) {
  7916. // evt 为空全部清除
  7917. this._events = {};
  7918. }
  7919. else {
  7920. if (!callback) {
  7921. // evt 存在,callback 为空,清除事件所有方法
  7922. delete this._events[evt];
  7923. }
  7924. else {
  7925. // evt 存在,callback 存在,清除匹配的
  7926. var events = this._events[evt] || [];
  7927. var length_1 = events.length;
  7928. for (var i = 0; i < length_1; i++) {
  7929. if (events[i].callback === callback) {
  7930. events.splice(i, 1);
  7931. length_1--;
  7932. i--;
  7933. }
  7934. }
  7935. if (events.length === 0) {
  7936. delete this._events[evt];
  7937. }
  7938. }
  7939. }
  7940. return this;
  7941. };
  7942. /* 当前所有的事件 */
  7943. EventEmitter.prototype.getEvents = function () {
  7944. return this._events;
  7945. };
  7946. return EventEmitter;
  7947. }());
  7948. function measureText$2(canvas, px2hd) {
  7949. return function (text, font) {
  7950. var _ref = font || {},
  7951. fontSize = _ref.fontSize,
  7952. fontFamily = _ref.fontFamily,
  7953. fontStyle = _ref.fontStyle,
  7954. fontWeight = _ref.fontWeight,
  7955. fontVariant = _ref.fontVariant;
  7956. var shape = canvas.addShape('text', {
  7957. attrs: {
  7958. x: 0,
  7959. y: 0,
  7960. fontSize: px2hd(fontSize),
  7961. fontFamily: fontFamily,
  7962. fontStyle: fontStyle,
  7963. fontWeight: fontWeight,
  7964. fontVariant: fontVariant,
  7965. text: text
  7966. }
  7967. });
  7968. var _shape$getBBox = shape.getBBox(),
  7969. width = _shape$getBBox.width,
  7970. height = _shape$getBBox.height;
  7971. shape.remove(true);
  7972. return {
  7973. width: width,
  7974. height: height
  7975. };
  7976. };
  7977. } // 顶层Canvas标签
  7978. var Canvas$1 = /*#__PURE__*/function (_Component) {
  7979. _inherits(Canvas, _Component);
  7980. var _super = _createSuper(Canvas);
  7981. function Canvas(props) {
  7982. var _this;
  7983. _classCallCheck(this, Canvas);
  7984. _this = _super.call(this, props);
  7985. var context = props.context,
  7986. pixelRatio = props.pixelRatio,
  7987. width = props.width,
  7988. height = props.height,
  7989. _props$animate = props.animate,
  7990. animate = _props$animate === void 0 ? true : _props$animate,
  7991. customPx2hd = props.px2hd,
  7992. customTheme = props.theme,
  7993. customStyle = props.style,
  7994. createImage = props.createImage,
  7995. landscape = props.landscape;
  7996. var px2hd$1 = isFunction(customPx2hd) ? batch2hd(customPx2hd) : px2hd;
  7997. var theme = px2hd$1(deepMix({}, Theme, customTheme)); // 创建G的canvas
  7998. var canvas = createCanvas({
  7999. context: context,
  8000. pixelRatio: pixelRatio,
  8001. fontFamily: theme.fontFamily,
  8002. width: width,
  8003. height: height,
  8004. createImage: createImage,
  8005. landscape: landscape
  8006. }); // 组件更新器
  8007. var updater = createUpdater(_assertThisInitialized(_this)); // 供全局使用的一些变量
  8008. var componentContext = {
  8009. root: _assertThisInitialized(_this),
  8010. canvas: canvas,
  8011. theme: theme,
  8012. px2hd: px2hd$1,
  8013. measureText: measureText$2(canvas, px2hd$1)
  8014. }; // 动画模块
  8015. var animation = new Animation(canvas);
  8016. _this.canvas = canvas;
  8017. _this.container = canvas;
  8018. _this.context = componentContext;
  8019. _this.updater = updater;
  8020. _this.animate = animate;
  8021. _this.animation = animation;
  8022. _this.theme = theme;
  8023. _this._ee = new EventEmitter();
  8024. _this.updateLayout(props);
  8025. return _this;
  8026. }
  8027. _createClass(Canvas, [{
  8028. key: "renderComponents",
  8029. value: function renderComponents(components) {
  8030. if (!components || !components.length) {
  8031. return;
  8032. }
  8033. renderComponent(components);
  8034. this.draw();
  8035. }
  8036. }, {
  8037. key: "update",
  8038. value: function update(nextProps) {
  8039. var props = this.props;
  8040. if (equal(nextProps, props)) {
  8041. return;
  8042. }
  8043. this.props = nextProps;
  8044. this.render();
  8045. }
  8046. }, {
  8047. key: "resize",
  8048. value: function resize(width, height) {
  8049. var _this$canvas$_attrs = this.canvas._attrs,
  8050. canvasWidth = _this$canvas$_attrs.width,
  8051. canvasHeight = _this$canvas$_attrs.height;
  8052. this.canvas.changeSize(width || canvasWidth, height || canvasHeight); // this.canvas.clear();
  8053. // this.children = null;
  8054. this.updateLayout(_objectSpread(_objectSpread({}, this.props), {}, {
  8055. width: width,
  8056. height: height
  8057. }));
  8058. this.render();
  8059. }
  8060. }, {
  8061. key: "updateLayout",
  8062. value: function updateLayout(props) {
  8063. var _this$canvas$_attrs2 = this.canvas._attrs,
  8064. canvasWidth = _this$canvas$_attrs2.width,
  8065. canvasHeight = _this$canvas$_attrs2.height;
  8066. var style = this.context.px2hd(_objectSpread({
  8067. left: 0,
  8068. top: 0,
  8069. width: (props === null || props === void 0 ? void 0 : props.width) || canvasWidth,
  8070. height: (props === null || props === void 0 ? void 0 : props.height) || canvasHeight,
  8071. padding: this.theme.padding
  8072. }, props.style));
  8073. this.layout = Layout.fromStyle(style);
  8074. this.context = _objectSpread(_objectSpread({}, this.context), {}, {
  8075. left: this.layout.left,
  8076. top: this.layout.top,
  8077. width: this.layout.width,
  8078. height: this.layout.height
  8079. });
  8080. }
  8081. }, {
  8082. key: "draw",
  8083. value: function draw() {
  8084. var canvas = this.canvas,
  8085. animate = this.animate;
  8086. if (animate === false) {
  8087. canvas.draw();
  8088. return;
  8089. }
  8090. this.play();
  8091. }
  8092. }, {
  8093. key: "play",
  8094. value: function play() {
  8095. var _this2 = this;
  8096. var canvas = this.canvas,
  8097. animation = this.animation; // 执行动画
  8098. animation.abort();
  8099. animation.play(canvas, function () {
  8100. _this2.emit('animationEnd');
  8101. });
  8102. }
  8103. }, {
  8104. key: "render",
  8105. value: function render() {
  8106. var lastChildren = this.children,
  8107. props = this.props;
  8108. var nextChildren = props.children;
  8109. renderChildren(this, nextChildren, lastChildren);
  8110. this.draw();
  8111. return null;
  8112. }
  8113. }, {
  8114. key: "destroy",
  8115. value: function destroy() {
  8116. var canvas = this.canvas;
  8117. canvas.destroy();
  8118. }
  8119. }, {
  8120. key: "on",
  8121. value: function on(type, listener) {
  8122. this._ee.on(type, listener);
  8123. }
  8124. }, {
  8125. key: "emit",
  8126. value: function emit(type, event) {
  8127. this._ee.emit(type, event);
  8128. }
  8129. }, {
  8130. key: "off",
  8131. value: function off(type, listener) {
  8132. this._ee.off(type, listener);
  8133. }
  8134. }]);
  8135. return Canvas;
  8136. }(Component);
  8137. var LayoutController = /*#__PURE__*/function () {
  8138. function LayoutController() {
  8139. _classCallCheck(this, LayoutController);
  8140. }
  8141. _createClass(LayoutController, [{
  8142. key: "getRectRange",
  8143. value: function getRectRange(style) {
  8144. var left = style.left,
  8145. top = style.top,
  8146. width = style.width,
  8147. height = style.height,
  8148. padding = style.padding;
  8149. var _padding = _slicedToArray(padding, 4),
  8150. paddingTop = _padding[0],
  8151. paddingRight = _padding[1],
  8152. paddingBottom = _padding[2],
  8153. paddingLeft = _padding[3];
  8154. return {
  8155. left: left + paddingLeft,
  8156. top: top + paddingTop,
  8157. width: width - paddingLeft - paddingRight,
  8158. height: height - paddingTop - paddingBottom
  8159. };
  8160. }
  8161. }, {
  8162. key: "create",
  8163. value: function create(style) {
  8164. var rectRange = this.getRectRange(style);
  8165. var layout = new Layout(rectRange);
  8166. this.layout = layout;
  8167. return layout;
  8168. }
  8169. }, {
  8170. key: "update",
  8171. value: function update(style) {
  8172. var rectRange = this.getRectRange(style);
  8173. var layout = this.layout;
  8174. layout.update(rectRange);
  8175. return layout;
  8176. }
  8177. }]);
  8178. return LayoutController;
  8179. }();
  8180. var superPropBase = createCommonjsModule(function (module) {
  8181. function _superPropBase(object, property) {
  8182. while (!Object.prototype.hasOwnProperty.call(object, property)) {
  8183. object = getPrototypeOf(object);
  8184. if (object === null) break;
  8185. }
  8186. return object;
  8187. }
  8188. module.exports = _superPropBase, module.exports.__esModule = true, module.exports["default"] = module.exports;
  8189. });
  8190. var get$1 = createCommonjsModule(function (module) {
  8191. function _get() {
  8192. if (typeof Reflect !== "undefined" && Reflect.get) {
  8193. module.exports = _get = Reflect.get.bind(), module.exports.__esModule = true, module.exports["default"] = module.exports;
  8194. } else {
  8195. module.exports = _get = function _get(target, property, receiver) {
  8196. var base = superPropBase(target, property);
  8197. if (!base) return;
  8198. var desc = Object.getOwnPropertyDescriptor(base, property);
  8199. if (desc.get) {
  8200. return desc.get.call(arguments.length < 3 ? target : receiver);
  8201. }
  8202. return desc.value;
  8203. }, module.exports.__esModule = true, module.exports["default"] = module.exports;
  8204. }
  8205. return _get.apply(this, arguments);
  8206. }
  8207. module.exports = _get, module.exports.__esModule = true, module.exports["default"] = module.exports;
  8208. });
  8209. var _get$1 = /*@__PURE__*/getDefaultExportFromCjs(get$1);
  8210. function transposedRect(_ref) {
  8211. var xMin = _ref.xMin,
  8212. xMax = _ref.xMax,
  8213. yMin = _ref.yMin,
  8214. yMax = _ref.yMax;
  8215. return {
  8216. xMin: yMin,
  8217. xMax: yMax,
  8218. yMin: xMin,
  8219. yMax: xMax
  8220. };
  8221. }
  8222. function _convertRect(_ref2) {
  8223. var x = _ref2.x,
  8224. y = _ref2.y,
  8225. size = _ref2.size,
  8226. y0 = _ref2.y0;
  8227. var xMin;
  8228. var xMax;
  8229. if (isArray(x)) {
  8230. xMin = x[0];
  8231. xMax = x[1];
  8232. } else {
  8233. xMin = x - size / 2;
  8234. xMax = x + size / 2;
  8235. }
  8236. var yMin;
  8237. var yMax;
  8238. if (isArray(y)) {
  8239. yMin = y[0];
  8240. yMax = y[1];
  8241. } else {
  8242. yMin = Math.min(y0, y);
  8243. yMax = Math.max(y0, y);
  8244. }
  8245. return {
  8246. xMin: xMin,
  8247. xMax: xMax,
  8248. yMin: yMin,
  8249. yMax: yMax
  8250. };
  8251. }
  8252. /**
  8253. * 直角坐标系
  8254. * convert相关的方法,涉及将标准坐标系映射到实际坐标系内
  8255. * transform相关的方法,是仅将某一种关键点转换成另一种关键点 (比如将x/y/size/y0转换成yMin/yMax/..)
  8256. */
  8257. var Base = /*#__PURE__*/function (_Layout) {
  8258. _inherits(Base, _Layout);
  8259. var _super = _createSuper(Base);
  8260. function Base(option) {
  8261. var _this;
  8262. _classCallCheck(this, Base);
  8263. _this = _super.call(this, option); // x y 调换
  8264. _this.transposed = false; // x,y 的值域,在极坐标中对应的就是弧度和半径
  8265. _this.x = [0, 1];
  8266. _this.y = [0, 1];
  8267. _this.update(option);
  8268. return _this;
  8269. }
  8270. _createClass(Base, [{
  8271. key: "update",
  8272. value: function update(option) {
  8273. _get$1(_getPrototypeOf(Base.prototype), "update", this).call(this, option);
  8274. var left = this.left,
  8275. top = this.top,
  8276. width = this.width,
  8277. height = this.height;
  8278. this.center = {
  8279. x: left + width / 2,
  8280. y: top + height / 2
  8281. };
  8282. return this;
  8283. } // 是循环, 比如极坐标是以 2π 循环的
  8284. }, {
  8285. key: "isCyclic",
  8286. value: function isCyclic() {
  8287. return false;
  8288. }
  8289. }, {
  8290. key: "_zoomVal",
  8291. value: function _zoomVal(val, func) {
  8292. return isArray(val) ? val.map(function (v) {
  8293. return func(v);
  8294. }) : func(val);
  8295. }
  8296. /**
  8297. * 把归一后的值映射到对应的定义域
  8298. * @param point
  8299. */
  8300. }, {
  8301. key: "convert",
  8302. value: function convert(point) {
  8303. var transposed = this.transposed,
  8304. x = this.x,
  8305. y = this.y;
  8306. var xDim = transposed ? 'y' : 'x';
  8307. var yDim = transposed ? 'x' : 'y';
  8308. var pointX = point[xDim];
  8309. var pointY = point[yDim]; // 超出边界不绘制
  8310. if (pointX < 0 || pointX > 1 || pointY < 0 || pointY > 1) {
  8311. return {
  8312. x: NaN,
  8313. y: NaN
  8314. };
  8315. }
  8316. return {
  8317. x: this._zoomVal(point[xDim], function (v) {
  8318. return x[0] + (x[1] - x[0]) * v;
  8319. }),
  8320. y: this._zoomVal(point[yDim], function (v) {
  8321. return y[0] + (y[1] - y[0]) * v;
  8322. })
  8323. };
  8324. }
  8325. /**
  8326. * convert 的反处理,把定义域的值,反处理到归一的值
  8327. */
  8328. }, {
  8329. key: "invert",
  8330. value: function invert(point) {
  8331. var _ref3;
  8332. var transposed = this.transposed,
  8333. x = this.x,
  8334. y = this.y;
  8335. var xDim = transposed ? 'y' : 'x';
  8336. var yDim = transposed ? 'x' : 'y';
  8337. return _ref3 = {}, _defineProperty(_ref3, xDim, this._zoomVal(point.x, function (v) {
  8338. return (v - x[0]) / (x[1] - x[0]);
  8339. })), _defineProperty(_ref3, yDim, this._zoomVal(point.y, function (v) {
  8340. return (v - y[0]) / (y[1] - y[0]);
  8341. })), _ref3;
  8342. }
  8343. /**
  8344. * 把归一化的值映射到 canvas 的坐标点
  8345. * @param point
  8346. * @returns
  8347. */
  8348. }, {
  8349. key: "convertPoint",
  8350. value: function convertPoint(point) {
  8351. return this.convert(point);
  8352. }
  8353. /**
  8354. * 把canvas坐标的点位映射回归一的值
  8355. */
  8356. }, {
  8357. key: "invertPoint",
  8358. value: function invertPoint(point) {
  8359. return this.invert(point);
  8360. } // 将标准坐标系下的矩形绘制关键点映射成实际绘制的坐标点
  8361. }, {
  8362. key: "convertRect",
  8363. value: function convertRect(rectPoint) {
  8364. var xRange = this.x,
  8365. yRange = this.y,
  8366. transposed = this.transposed;
  8367. var _xRange = _slicedToArray(xRange, 2),
  8368. xStart = _xRange[0],
  8369. xEnd = _xRange[1];
  8370. var _yRange = _slicedToArray(yRange, 2),
  8371. yStart = _yRange[0],
  8372. yEnd = _yRange[1];
  8373. var rect = _convertRect(rectPoint);
  8374. var _ref4 = transposed ? transposedRect(rect) : rect,
  8375. xMin = _ref4.xMin,
  8376. xMax = _ref4.xMax,
  8377. yMin = _ref4.yMin,
  8378. yMax = _ref4.yMax;
  8379. var x0 = xStart + (xEnd - xStart) * xMin;
  8380. var x1 = xStart + (xEnd - xStart) * xMax;
  8381. var y0 = yStart + (yEnd - yStart) * yMin;
  8382. var y1 = yStart + (yEnd - yStart) * yMax;
  8383. return {
  8384. xMin: Math.min(x0, x1),
  8385. xMax: Math.max(x0, x1),
  8386. yMin: Math.min(y0, y1),
  8387. yMax: Math.max(y0, y1)
  8388. };
  8389. } // 将已经映射好的矩形绘制关键点转换成实际绘制的坐标点
  8390. }, {
  8391. key: "transformToRect",
  8392. value: function transformToRect(rectPoint) {
  8393. var x = rectPoint.x,
  8394. y = rectPoint.y,
  8395. y0 = rectPoint.y0,
  8396. size = rectPoint.size;
  8397. var coordOrigin = this.convertPoint({
  8398. x: 0,
  8399. y: y0
  8400. });
  8401. var transposed = this.transposed;
  8402. var _rectPoint = {
  8403. size: size,
  8404. x: transposed ? y : x,
  8405. y: transposed ? x : y,
  8406. y0: transposed ? coordOrigin.x : coordOrigin.y
  8407. };
  8408. var rect = _convertRect(_rectPoint);
  8409. var _ref5 = transposed ? transposedRect(rect) : rect,
  8410. xMin = _ref5.xMin,
  8411. xMax = _ref5.xMax,
  8412. yMin = _ref5.yMin,
  8413. yMax = _ref5.yMax;
  8414. return {
  8415. xMin: xMin,
  8416. xMax: xMax,
  8417. yMin: yMin,
  8418. yMax: yMax
  8419. };
  8420. }
  8421. }]);
  8422. return Base;
  8423. }(Layout);
  8424. var Rect$2 = /*#__PURE__*/function (_Base) {
  8425. _inherits(Rect, _Base);
  8426. var _super = _createSuper(Rect);
  8427. function Rect() {
  8428. var _this;
  8429. _classCallCheck(this, Rect);
  8430. _this = _super.apply(this, arguments);
  8431. _this.type = 'rect';
  8432. return _this;
  8433. }
  8434. _createClass(Rect, [{
  8435. key: "update",
  8436. value: function update(option) {
  8437. _get$1(_getPrototypeOf(Rect.prototype), "update", this).call(this, option);
  8438. var left = this.left,
  8439. top = this.top,
  8440. right = this.right,
  8441. bottom = this.bottom;
  8442. var x = [left, right];
  8443. var y = [bottom, top];
  8444. this.x = x;
  8445. this.y = y;
  8446. return this;
  8447. }
  8448. }]);
  8449. return Rect;
  8450. }(Base);
  8451. var Polar = /*#__PURE__*/function (_Base) {
  8452. _inherits(Polar, _Base);
  8453. var _super = _createSuper(Polar);
  8454. function Polar() {
  8455. var _this;
  8456. _classCallCheck(this, Polar);
  8457. _this = _super.apply(this, arguments);
  8458. _this.type = 'polar';
  8459. _this.isPolar = true;
  8460. return _this;
  8461. }
  8462. _createClass(Polar, [{
  8463. key: "update",
  8464. value: function update(option) {
  8465. _get$1(_getPrototypeOf(Polar.prototype), "update", this).call(this, option);
  8466. if (!this.option) {
  8467. this.option = option;
  8468. }
  8469. var _this$option = this.option,
  8470. _this$option$radius = _this$option.radius,
  8471. radiusRatio = _this$option$radius === void 0 ? 1 : _this$option$radius,
  8472. _this$option$innerRad = _this$option.innerRadius,
  8473. innerRadiusRatio = _this$option$innerRad === void 0 ? 0 : _this$option$innerRad;
  8474. var width = this.width,
  8475. height = this.height,
  8476. _this$startAngle = this.startAngle,
  8477. startAngle = _this$startAngle === void 0 ? -Math.PI / 2 : _this$startAngle,
  8478. _this$endAngle = this.endAngle,
  8479. endAngle = _this$endAngle === void 0 ? Math.PI * 3 / 2 : _this$endAngle; // 半径取宽高的最小值
  8480. var radius = radiusRatio * (Math.min(width, height) / 2); // 极坐标下 x 表示弧度, y 代表 半径
  8481. var x = [startAngle, endAngle];
  8482. var y = [innerRadiusRatio * radius, radius];
  8483. this.x = x;
  8484. this.y = y;
  8485. this.startAngle = startAngle;
  8486. this.endAngle = endAngle;
  8487. this.radius = radius;
  8488. this.innnerRadius = innerRadiusRatio * radius;
  8489. return this;
  8490. }
  8491. }, {
  8492. key: "isCyclic",
  8493. value: function isCyclic() {
  8494. var startAngle = this.startAngle,
  8495. endAngle = this.endAngle;
  8496. if (endAngle - startAngle < Math.PI * 2) {
  8497. return false;
  8498. }
  8499. return true;
  8500. }
  8501. }, {
  8502. key: "convertPoint",
  8503. value: function convertPoint(point) {
  8504. var center = this.center,
  8505. transposed = this.transposed,
  8506. x = this.x,
  8507. y = this.y;
  8508. var xDim = transposed ? 'y' : 'x';
  8509. var yDim = transposed ? 'x' : 'y';
  8510. var _x = _slicedToArray(x, 2),
  8511. xStart = _x[0],
  8512. xEnd = _x[1];
  8513. var _y = _slicedToArray(y, 2),
  8514. yStart = _y[0],
  8515. yEnd = _y[1];
  8516. var angle = xStart + (xEnd - xStart) * point[xDim];
  8517. var radius = yStart + (yEnd - yStart) * point[yDim];
  8518. return {
  8519. x: center.x + Math.cos(angle) * radius,
  8520. y: center.y + Math.sin(angle) * radius
  8521. };
  8522. }
  8523. }, {
  8524. key: "invertPoint",
  8525. value: function invertPoint(point) {
  8526. var center = this.center,
  8527. transposed = this.transposed,
  8528. x = this.x,
  8529. y = this.y;
  8530. var xDim = transposed ? 'y' : 'x';
  8531. var yDim = transposed ? 'x' : 'y';
  8532. var _x2 = _slicedToArray(x, 2),
  8533. xStart = _x2[0],
  8534. xEnd = _x2[1];
  8535. var _y2 = _slicedToArray(y, 2),
  8536. yStart = _y2[0],
  8537. yEnd = _y2[1];
  8538. var m = [1, 0, 0, 1, 0, 0];
  8539. Matrix.rotate(m, m, xStart);
  8540. var startV = [1, 0];
  8541. Vector2.transformMat2d(startV, startV, m);
  8542. startV = [startV[0], startV[1]];
  8543. var pointV = [point.x - center.x, point.y - center.y];
  8544. if (Vector2.zero(pointV)) {
  8545. return {
  8546. x: 0,
  8547. y: 0
  8548. };
  8549. }
  8550. var theta = Vector2.angleTo(startV, pointV, xEnd < xStart);
  8551. if (Math.abs(theta - Math.PI * 2) < 0.001) {
  8552. theta = 0;
  8553. }
  8554. var l = Vector2.length(pointV);
  8555. var percentX = theta / (xEnd - xStart);
  8556. percentX = xEnd - xStart > 0 ? percentX : -percentX;
  8557. var percentY = (l - yStart) / (yEnd - yStart);
  8558. var rst = {};
  8559. rst[xDim] = percentX;
  8560. rst[yDim] = percentY;
  8561. return rst;
  8562. }
  8563. }]);
  8564. return Polar;
  8565. }(Base);
  8566. var coordMap = {
  8567. rect: Rect$2,
  8568. polar: Polar
  8569. };
  8570. var coordController = /*#__PURE__*/function () {
  8571. function coordController() {
  8572. _classCallCheck(this, coordController);
  8573. }
  8574. _createClass(coordController, [{
  8575. key: "getOption",
  8576. value: function getOption(cfg) {
  8577. if (isString(cfg)) {
  8578. return {
  8579. type: coordMap[cfg] || Rect$2
  8580. };
  8581. }
  8582. if (isFunction(cfg)) {
  8583. return {
  8584. type: cfg
  8585. };
  8586. }
  8587. var _ref = cfg || {},
  8588. type = _ref.type;
  8589. return _objectSpread(_objectSpread({}, cfg), {}, {
  8590. // 默认直角坐标系
  8591. type: isFunction(type) ? type : coordMap[type] || Rect$2
  8592. });
  8593. }
  8594. }, {
  8595. key: "create",
  8596. value: function create(cfg, layout) {
  8597. var option = this.getOption(cfg);
  8598. var type = option.type;
  8599. var coord = new type(_objectSpread(_objectSpread({}, option), layout));
  8600. this.coord = coord;
  8601. return coord;
  8602. }
  8603. }, {
  8604. key: "updateLayout",
  8605. value: function updateLayout(layout) {
  8606. this.coord.update(layout);
  8607. }
  8608. }, {
  8609. key: "update",
  8610. value: function update() {}
  8611. }]);
  8612. return coordController;
  8613. }();
  8614. var methodCache = {};
  8615. /**
  8616. * 获取计算 ticks 的方法
  8617. * @param key 键值
  8618. * @returns 计算 ticks 的方法
  8619. */
  8620. function getTickMethod(key) {
  8621. return methodCache[key];
  8622. }
  8623. /**
  8624. * 注册计算 ticks 的方法
  8625. * @param key 键值
  8626. * @param method 方法
  8627. */
  8628. function registerTickMethod(key, method) {
  8629. methodCache[key] = method;
  8630. }
  8631. var Scale = /** @class */ (function () {
  8632. function Scale(cfg) {
  8633. /**
  8634. * 度量的类型
  8635. */
  8636. this.type = 'base';
  8637. /**
  8638. * 是否分类类型的度量
  8639. */
  8640. this.isCategory = false;
  8641. /**
  8642. * 是否线性度量,有linear, time 度量
  8643. */
  8644. this.isLinear = false;
  8645. /**
  8646. * 是否连续类型的度量,linear,time,log, pow, quantile, quantize 都支持
  8647. */
  8648. this.isContinuous = false;
  8649. /**
  8650. * 是否是常量的度量,传入和传出一致
  8651. */
  8652. this.isIdentity = false;
  8653. this.values = [];
  8654. this.range = [0, 1];
  8655. this.ticks = [];
  8656. this.__cfg__ = cfg;
  8657. this.initCfg();
  8658. this.init();
  8659. }
  8660. // 对于原始值的必要转换,如分类、时间字段需转换成数值,用transform/map命名可能更好
  8661. Scale.prototype.translate = function (v) {
  8662. return v;
  8663. };
  8664. /** 重新初始化 */
  8665. Scale.prototype.change = function (cfg) {
  8666. // 覆盖配置项,而不替代
  8667. mix(this.__cfg__, cfg);
  8668. this.init();
  8669. };
  8670. Scale.prototype.clone = function () {
  8671. return this.constructor(this.__cfg__);
  8672. };
  8673. /** 获取坐标轴需要的ticks */
  8674. Scale.prototype.getTicks = function () {
  8675. var _this = this;
  8676. return map(this.ticks, function (tick, idx) {
  8677. if (isObject(tick)) {
  8678. // 仅当符合Tick类型时才有意义
  8679. return tick;
  8680. }
  8681. return {
  8682. text: _this.getText(tick, idx),
  8683. tickValue: tick,
  8684. value: _this.scale(tick),
  8685. };
  8686. });
  8687. };
  8688. /** 获取Tick的格式化结果 */
  8689. Scale.prototype.getText = function (value, key) {
  8690. var formatter = this.formatter;
  8691. var res = formatter ? formatter(value, key) : value;
  8692. if (isNil(res) || !isFunction(res.toString)) {
  8693. return '';
  8694. }
  8695. return res.toString();
  8696. };
  8697. // 获取配置项中的值,当前 scale 上的值可能会被修改
  8698. Scale.prototype.getConfig = function (key) {
  8699. return this.__cfg__[key];
  8700. };
  8701. // scale初始化
  8702. Scale.prototype.init = function () {
  8703. mix(this, this.__cfg__);
  8704. this.setDomain();
  8705. if (isEmpty(this.getConfig('ticks'))) {
  8706. this.ticks = this.calculateTicks();
  8707. }
  8708. };
  8709. // 子类上覆盖某些属性,不能直接在类上声明,否则会被覆盖
  8710. Scale.prototype.initCfg = function () { };
  8711. Scale.prototype.setDomain = function () { };
  8712. Scale.prototype.calculateTicks = function () {
  8713. var tickMethod = this.tickMethod;
  8714. var ticks = [];
  8715. if (isString(tickMethod)) {
  8716. var method = getTickMethod(tickMethod);
  8717. if (!method) {
  8718. throw new Error('There is no method to to calculate ticks!');
  8719. }
  8720. ticks = method(this);
  8721. }
  8722. else if (isFunction(tickMethod)) {
  8723. ticks = tickMethod(this);
  8724. }
  8725. return ticks;
  8726. };
  8727. // range 的最小值
  8728. Scale.prototype.rangeMin = function () {
  8729. return this.range[0];
  8730. };
  8731. // range 的最大值
  8732. Scale.prototype.rangeMax = function () {
  8733. return this.range[1];
  8734. };
  8735. /** 定义域转 0~1 */
  8736. Scale.prototype.calcPercent = function (value, min, max) {
  8737. if (isNumber(value)) {
  8738. return (value - min) / (max - min);
  8739. }
  8740. return NaN;
  8741. };
  8742. /** 0~1转定义域 */
  8743. Scale.prototype.calcValue = function (percent, min, max) {
  8744. return min + percent * (max - min);
  8745. };
  8746. return Scale;
  8747. }());
  8748. /**
  8749. * 分类度量
  8750. * @class
  8751. */
  8752. var Category = /** @class */ (function (_super) {
  8753. __extends(Category, _super);
  8754. function Category() {
  8755. var _this = _super !== null && _super.apply(this, arguments) || this;
  8756. _this.type = 'cat';
  8757. _this.isCategory = true;
  8758. return _this;
  8759. }
  8760. Category.prototype.buildIndexMap = function () {
  8761. if (!this.translateIndexMap) {
  8762. this.translateIndexMap = new Map();
  8763. // 重新构建缓存
  8764. for (var i = 0; i < this.values.length; i++) {
  8765. this.translateIndexMap.set(this.values[i], i);
  8766. }
  8767. }
  8768. };
  8769. Category.prototype.translate = function (value) {
  8770. // 按需构建 map
  8771. this.buildIndexMap();
  8772. // 找得到
  8773. var idx = this.translateIndexMap.get(value);
  8774. if (idx === undefined) {
  8775. idx = isNumber(value) ? value : NaN;
  8776. }
  8777. return idx;
  8778. };
  8779. Category.prototype.scale = function (value) {
  8780. var order = this.translate(value);
  8781. // 分类数据允许 0.5 范围内调整
  8782. // if (order < this.min - 0.5 || order > this.max + 0.5) {
  8783. // return NaN;
  8784. // }
  8785. var percent = this.calcPercent(order, this.min, this.max);
  8786. return this.calcValue(percent, this.rangeMin(), this.rangeMax());
  8787. };
  8788. Category.prototype.invert = function (scaledValue) {
  8789. var domainRange = this.max - this.min;
  8790. var percent = this.calcPercent(scaledValue, this.rangeMin(), this.rangeMax());
  8791. var idx = Math.round(domainRange * percent) + this.min;
  8792. if (idx < this.min || idx > this.max) {
  8793. return NaN;
  8794. }
  8795. return this.values[idx];
  8796. };
  8797. Category.prototype.getText = function (value) {
  8798. var args = [];
  8799. for (var _i = 1; _i < arguments.length; _i++) {
  8800. args[_i - 1] = arguments[_i];
  8801. }
  8802. var v = value;
  8803. // value为index
  8804. if (isNumber(value) && !this.values.includes(value)) {
  8805. v = this.values[v];
  8806. }
  8807. return _super.prototype.getText.apply(this, __spreadArrays([v], args));
  8808. };
  8809. // 复写属性
  8810. Category.prototype.initCfg = function () {
  8811. this.tickMethod = 'cat';
  8812. };
  8813. // 设置 min, max
  8814. Category.prototype.setDomain = function () {
  8815. // 用户有可能设置 min
  8816. if (isNil(this.getConfig('min'))) {
  8817. this.min = 0;
  8818. }
  8819. if (isNil(this.getConfig('max'))) {
  8820. var size = this.values.length;
  8821. this.max = size > 1 ? size - 1 : size;
  8822. }
  8823. // scale.init 的时候清除缓存
  8824. if (this.translateIndexMap) {
  8825. this.translateIndexMap = undefined;
  8826. }
  8827. };
  8828. return Category;
  8829. }(Scale));
  8830. var token = /d{1,4}|M{1,4}|YY(?:YY)?|S{1,3}|Do|ZZ|Z|([HhMsDm])\1?|[aA]|"[^"]*"|'[^']*'/g;
  8831. var twoDigitsOptional = "\\d\\d?";
  8832. var twoDigits = "\\d\\d";
  8833. var threeDigits = "\\d{3}";
  8834. var fourDigits = "\\d{4}";
  8835. var word = "[^\\s]+";
  8836. var literal = /\[([^]*?)\]/gm;
  8837. function shorten(arr, sLen) {
  8838. var newArr = [];
  8839. for (var i = 0, len = arr.length; i < len; i++) {
  8840. newArr.push(arr[i].substr(0, sLen));
  8841. }
  8842. return newArr;
  8843. }
  8844. var monthUpdate = function (arrName) { return function (v, i18n) {
  8845. var lowerCaseArr = i18n[arrName].map(function (v) { return v.toLowerCase(); });
  8846. var index = lowerCaseArr.indexOf(v.toLowerCase());
  8847. if (index > -1) {
  8848. return index;
  8849. }
  8850. return null;
  8851. }; };
  8852. function assign(origObj) {
  8853. var args = [];
  8854. for (var _i = 1; _i < arguments.length; _i++) {
  8855. args[_i - 1] = arguments[_i];
  8856. }
  8857. for (var _a = 0, args_1 = args; _a < args_1.length; _a++) {
  8858. var obj = args_1[_a];
  8859. for (var key in obj) {
  8860. // @ts-ignore ex
  8861. origObj[key] = obj[key];
  8862. }
  8863. }
  8864. return origObj;
  8865. }
  8866. var dayNames = [
  8867. "Sunday",
  8868. "Monday",
  8869. "Tuesday",
  8870. "Wednesday",
  8871. "Thursday",
  8872. "Friday",
  8873. "Saturday"
  8874. ];
  8875. var monthNames = [
  8876. "January",
  8877. "February",
  8878. "March",
  8879. "April",
  8880. "May",
  8881. "June",
  8882. "July",
  8883. "August",
  8884. "September",
  8885. "October",
  8886. "November",
  8887. "December"
  8888. ];
  8889. var monthNamesShort = shorten(monthNames, 3);
  8890. var dayNamesShort = shorten(dayNames, 3);
  8891. var defaultI18n = {
  8892. dayNamesShort: dayNamesShort,
  8893. dayNames: dayNames,
  8894. monthNamesShort: monthNamesShort,
  8895. monthNames: monthNames,
  8896. amPm: ["am", "pm"],
  8897. DoFn: function (dayOfMonth) {
  8898. return (dayOfMonth +
  8899. ["th", "st", "nd", "rd"][dayOfMonth % 10 > 3
  8900. ? 0
  8901. : ((dayOfMonth - (dayOfMonth % 10) !== 10 ? 1 : 0) * dayOfMonth) % 10]);
  8902. }
  8903. };
  8904. var globalI18n = assign({}, defaultI18n);
  8905. var setGlobalDateI18n = function (i18n) {
  8906. return (globalI18n = assign(globalI18n, i18n));
  8907. };
  8908. var regexEscape = function (str) {
  8909. return str.replace(/[|\\{()[^$+*?.-]/g, "\\$&");
  8910. };
  8911. var pad = function (val, len) {
  8912. if (len === void 0) { len = 2; }
  8913. val = String(val);
  8914. while (val.length < len) {
  8915. val = "0" + val;
  8916. }
  8917. return val;
  8918. };
  8919. var formatFlags = {
  8920. D: function (dateObj) { return String(dateObj.getDate()); },
  8921. DD: function (dateObj) { return pad(dateObj.getDate()); },
  8922. Do: function (dateObj, i18n) {
  8923. return i18n.DoFn(dateObj.getDate());
  8924. },
  8925. d: function (dateObj) { return String(dateObj.getDay()); },
  8926. dd: function (dateObj) { return pad(dateObj.getDay()); },
  8927. ddd: function (dateObj, i18n) {
  8928. return i18n.dayNamesShort[dateObj.getDay()];
  8929. },
  8930. dddd: function (dateObj, i18n) {
  8931. return i18n.dayNames[dateObj.getDay()];
  8932. },
  8933. M: function (dateObj) { return String(dateObj.getMonth() + 1); },
  8934. MM: function (dateObj) { return pad(dateObj.getMonth() + 1); },
  8935. MMM: function (dateObj, i18n) {
  8936. return i18n.monthNamesShort[dateObj.getMonth()];
  8937. },
  8938. MMMM: function (dateObj, i18n) {
  8939. return i18n.monthNames[dateObj.getMonth()];
  8940. },
  8941. YY: function (dateObj) {
  8942. return pad(String(dateObj.getFullYear()), 4).substr(2);
  8943. },
  8944. YYYY: function (dateObj) { return pad(dateObj.getFullYear(), 4); },
  8945. h: function (dateObj) { return String(dateObj.getHours() % 12 || 12); },
  8946. hh: function (dateObj) { return pad(dateObj.getHours() % 12 || 12); },
  8947. H: function (dateObj) { return String(dateObj.getHours()); },
  8948. HH: function (dateObj) { return pad(dateObj.getHours()); },
  8949. m: function (dateObj) { return String(dateObj.getMinutes()); },
  8950. mm: function (dateObj) { return pad(dateObj.getMinutes()); },
  8951. s: function (dateObj) { return String(dateObj.getSeconds()); },
  8952. ss: function (dateObj) { return pad(dateObj.getSeconds()); },
  8953. S: function (dateObj) {
  8954. return String(Math.round(dateObj.getMilliseconds() / 100));
  8955. },
  8956. SS: function (dateObj) {
  8957. return pad(Math.round(dateObj.getMilliseconds() / 10), 2);
  8958. },
  8959. SSS: function (dateObj) { return pad(dateObj.getMilliseconds(), 3); },
  8960. a: function (dateObj, i18n) {
  8961. return dateObj.getHours() < 12 ? i18n.amPm[0] : i18n.amPm[1];
  8962. },
  8963. A: function (dateObj, i18n) {
  8964. return dateObj.getHours() < 12
  8965. ? i18n.amPm[0].toUpperCase()
  8966. : i18n.amPm[1].toUpperCase();
  8967. },
  8968. ZZ: function (dateObj) {
  8969. var offset = dateObj.getTimezoneOffset();
  8970. return ((offset > 0 ? "-" : "+") +
  8971. pad(Math.floor(Math.abs(offset) / 60) * 100 + (Math.abs(offset) % 60), 4));
  8972. },
  8973. Z: function (dateObj) {
  8974. var offset = dateObj.getTimezoneOffset();
  8975. return ((offset > 0 ? "-" : "+") +
  8976. pad(Math.floor(Math.abs(offset) / 60), 2) +
  8977. ":" +
  8978. pad(Math.abs(offset) % 60, 2));
  8979. }
  8980. };
  8981. var monthParse = function (v) { return +v - 1; };
  8982. var emptyDigits = [null, twoDigitsOptional];
  8983. var emptyWord = [null, word];
  8984. var amPm = [
  8985. "isPm",
  8986. word,
  8987. function (v, i18n) {
  8988. var val = v.toLowerCase();
  8989. if (val === i18n.amPm[0]) {
  8990. return 0;
  8991. }
  8992. else if (val === i18n.amPm[1]) {
  8993. return 1;
  8994. }
  8995. return null;
  8996. }
  8997. ];
  8998. var timezoneOffset = [
  8999. "timezoneOffset",
  9000. "[^\\s]*?[\\+\\-]\\d\\d:?\\d\\d|[^\\s]*?Z?",
  9001. function (v) {
  9002. var parts = (v + "").match(/([+-]|\d\d)/gi);
  9003. if (parts) {
  9004. var minutes = +parts[1] * 60 + parseInt(parts[2], 10);
  9005. return parts[0] === "+" ? minutes : -minutes;
  9006. }
  9007. return 0;
  9008. }
  9009. ];
  9010. var parseFlags = {
  9011. D: ["day", twoDigitsOptional],
  9012. DD: ["day", twoDigits],
  9013. Do: ["day", twoDigitsOptional + word, function (v) { return parseInt(v, 10); }],
  9014. M: ["month", twoDigitsOptional, monthParse],
  9015. MM: ["month", twoDigits, monthParse],
  9016. YY: [
  9017. "year",
  9018. twoDigits,
  9019. function (v) {
  9020. var now = new Date();
  9021. var cent = +("" + now.getFullYear()).substr(0, 2);
  9022. return +("" + (+v > 68 ? cent - 1 : cent) + v);
  9023. }
  9024. ],
  9025. h: ["hour", twoDigitsOptional, undefined, "isPm"],
  9026. hh: ["hour", twoDigits, undefined, "isPm"],
  9027. H: ["hour", twoDigitsOptional],
  9028. HH: ["hour", twoDigits],
  9029. m: ["minute", twoDigitsOptional],
  9030. mm: ["minute", twoDigits],
  9031. s: ["second", twoDigitsOptional],
  9032. ss: ["second", twoDigits],
  9033. YYYY: ["year", fourDigits],
  9034. S: ["millisecond", "\\d", function (v) { return +v * 100; }],
  9035. SS: ["millisecond", twoDigits, function (v) { return +v * 10; }],
  9036. SSS: ["millisecond", threeDigits],
  9037. d: emptyDigits,
  9038. dd: emptyDigits,
  9039. ddd: emptyWord,
  9040. dddd: emptyWord,
  9041. MMM: ["month", word, monthUpdate("monthNamesShort")],
  9042. MMMM: ["month", word, monthUpdate("monthNames")],
  9043. a: amPm,
  9044. A: amPm,
  9045. ZZ: timezoneOffset,
  9046. Z: timezoneOffset
  9047. };
  9048. // Some common format strings
  9049. var globalMasks = {
  9050. default: "ddd MMM DD YYYY HH:mm:ss",
  9051. shortDate: "M/D/YY",
  9052. mediumDate: "MMM D, YYYY",
  9053. longDate: "MMMM D, YYYY",
  9054. fullDate: "dddd, MMMM D, YYYY",
  9055. isoDate: "YYYY-MM-DD",
  9056. isoDateTime: "YYYY-MM-DDTHH:mm:ssZ",
  9057. shortTime: "HH:mm",
  9058. mediumTime: "HH:mm:ss",
  9059. longTime: "HH:mm:ss.SSS"
  9060. };
  9061. var setGlobalDateMasks = function (masks) { return assign(globalMasks, masks); };
  9062. /***
  9063. * Format a date
  9064. * @method format
  9065. * @param {Date|number} dateObj
  9066. * @param {string} mask Format of the date, i.e. 'mm-dd-yy' or 'shortDate'
  9067. * @returns {string} Formatted date string
  9068. */
  9069. var format = function (dateObj, mask, i18n) {
  9070. if (mask === void 0) { mask = globalMasks["default"]; }
  9071. if (i18n === void 0) { i18n = {}; }
  9072. if (typeof dateObj === "number") {
  9073. dateObj = new Date(dateObj);
  9074. }
  9075. if (Object.prototype.toString.call(dateObj) !== "[object Date]" ||
  9076. isNaN(dateObj.getTime())) {
  9077. throw new Error("Invalid Date pass to format");
  9078. }
  9079. mask = globalMasks[mask] || mask;
  9080. var literals = [];
  9081. // Make literals inactive by replacing them with @@@
  9082. mask = mask.replace(literal, function ($0, $1) {
  9083. literals.push($1);
  9084. return "@@@";
  9085. });
  9086. var combinedI18nSettings = assign(assign({}, globalI18n), i18n);
  9087. // Apply formatting rules
  9088. mask = mask.replace(token, function ($0) {
  9089. return formatFlags[$0](dateObj, combinedI18nSettings);
  9090. });
  9091. // Inline literal values back into the formatted value
  9092. return mask.replace(/@@@/g, function () { return literals.shift(); });
  9093. };
  9094. /**
  9095. * Parse a date string into a Javascript Date object /
  9096. * @method parse
  9097. * @param {string} dateStr Date string
  9098. * @param {string} format Date parse format
  9099. * @param {i18n} I18nSettingsOptional Full or subset of I18N settings
  9100. * @returns {Date|null} Returns Date object. Returns null what date string is invalid or doesn't match format
  9101. */
  9102. function parse(dateStr, format, i18n) {
  9103. if (i18n === void 0) { i18n = {}; }
  9104. if (typeof format !== "string") {
  9105. throw new Error("Invalid format in fecha parse");
  9106. }
  9107. // Check to see if the format is actually a mask
  9108. format = globalMasks[format] || format;
  9109. // Avoid regular expression denial of service, fail early for really long strings
  9110. // https://www.owasp.org/index.php/Regular_expression_Denial_of_Service_-_ReDoS
  9111. if (dateStr.length > 1000) {
  9112. return null;
  9113. }
  9114. // Default to the beginning of the year.
  9115. var today = new Date();
  9116. var dateInfo = {
  9117. year: today.getFullYear(),
  9118. month: 0,
  9119. day: 1,
  9120. hour: 0,
  9121. minute: 0,
  9122. second: 0,
  9123. millisecond: 0,
  9124. isPm: null,
  9125. timezoneOffset: null
  9126. };
  9127. var parseInfo = [];
  9128. var literals = [];
  9129. // Replace all the literals with @@@. Hopefully a string that won't exist in the format
  9130. var newFormat = format.replace(literal, function ($0, $1) {
  9131. literals.push(regexEscape($1));
  9132. return "@@@";
  9133. });
  9134. var specifiedFields = {};
  9135. var requiredFields = {};
  9136. // Change every token that we find into the correct regex
  9137. newFormat = regexEscape(newFormat).replace(token, function ($0) {
  9138. var info = parseFlags[$0];
  9139. var field = info[0], regex = info[1], requiredField = info[3];
  9140. // Check if the person has specified the same field twice. This will lead to confusing results.
  9141. if (specifiedFields[field]) {
  9142. throw new Error("Invalid format. " + field + " specified twice in format");
  9143. }
  9144. specifiedFields[field] = true;
  9145. // Check if there are any required fields. For instance, 12 hour time requires AM/PM specified
  9146. if (requiredField) {
  9147. requiredFields[requiredField] = true;
  9148. }
  9149. parseInfo.push(info);
  9150. return "(" + regex + ")";
  9151. });
  9152. // Check all the required fields are present
  9153. Object.keys(requiredFields).forEach(function (field) {
  9154. if (!specifiedFields[field]) {
  9155. throw new Error("Invalid format. " + field + " is required in specified format");
  9156. }
  9157. });
  9158. // Add back all the literals after
  9159. newFormat = newFormat.replace(/@@@/g, function () { return literals.shift(); });
  9160. // Check if the date string matches the format. If it doesn't return null
  9161. var matches = dateStr.match(new RegExp(newFormat, "i"));
  9162. if (!matches) {
  9163. return null;
  9164. }
  9165. var combinedI18nSettings = assign(assign({}, globalI18n), i18n);
  9166. // For each match, call the parser function for that date part
  9167. for (var i = 1; i < matches.length; i++) {
  9168. var _a = parseInfo[i - 1], field = _a[0], parser = _a[2];
  9169. var value = parser
  9170. ? parser(matches[i], combinedI18nSettings)
  9171. : +matches[i];
  9172. // If the parser can't make sense of the value, return null
  9173. if (value == null) {
  9174. return null;
  9175. }
  9176. dateInfo[field] = value;
  9177. }
  9178. if (dateInfo.isPm === 1 && dateInfo.hour != null && +dateInfo.hour !== 12) {
  9179. dateInfo.hour = +dateInfo.hour + 12;
  9180. }
  9181. else if (dateInfo.isPm === 0 && +dateInfo.hour === 12) {
  9182. dateInfo.hour = 0;
  9183. }
  9184. var dateTZ;
  9185. if (dateInfo.timezoneOffset == null) {
  9186. dateTZ = new Date(dateInfo.year, dateInfo.month, dateInfo.day, dateInfo.hour, dateInfo.minute, dateInfo.second, dateInfo.millisecond);
  9187. var validateFields = [
  9188. ["month", "getMonth"],
  9189. ["day", "getDate"],
  9190. ["hour", "getHours"],
  9191. ["minute", "getMinutes"],
  9192. ["second", "getSeconds"]
  9193. ];
  9194. for (var i = 0, len = validateFields.length; i < len; i++) {
  9195. // Check to make sure the date field is within the allowed range. Javascript dates allows values
  9196. // outside the allowed range. If the values don't match the value was invalid
  9197. if (specifiedFields[validateFields[i][0]] &&
  9198. dateInfo[validateFields[i][0]] !== dateTZ[validateFields[i][1]]()) {
  9199. return null;
  9200. }
  9201. }
  9202. }
  9203. else {
  9204. dateTZ = new Date(Date.UTC(dateInfo.year, dateInfo.month, dateInfo.day, dateInfo.hour, dateInfo.minute - dateInfo.timezoneOffset, dateInfo.second, dateInfo.millisecond));
  9205. // We can't validate dates in another timezone unfortunately. Do a basic check instead
  9206. if (dateInfo.month > 11 ||
  9207. dateInfo.month < 0 ||
  9208. dateInfo.day > 31 ||
  9209. dateInfo.day < 1 ||
  9210. dateInfo.hour > 23 ||
  9211. dateInfo.hour < 0 ||
  9212. dateInfo.minute > 59 ||
  9213. dateInfo.minute < 0 ||
  9214. dateInfo.second > 59 ||
  9215. dateInfo.second < 0) {
  9216. return null;
  9217. }
  9218. }
  9219. // Don't allow invalid dates
  9220. return dateTZ;
  9221. }
  9222. var fecha = {
  9223. format: format,
  9224. parse: parse,
  9225. defaultI18n: defaultI18n,
  9226. setGlobalDateI18n: setGlobalDateI18n,
  9227. setGlobalDateMasks: setGlobalDateMasks
  9228. };
  9229. var fecha1 = /*#__PURE__*/Object.freeze({
  9230. __proto__: null,
  9231. 'default': fecha,
  9232. assign: assign,
  9233. format: format,
  9234. parse: parse,
  9235. defaultI18n: defaultI18n,
  9236. setGlobalDateI18n: setGlobalDateI18n,
  9237. setGlobalDateMasks: setGlobalDateMasks
  9238. });
  9239. /**
  9240. * 二分右侧查找
  9241. * https://github.com/d3/d3-array/blob/master/src/bisector.js
  9242. */
  9243. function bisector (getter) {
  9244. /**
  9245. * x: 目标值
  9246. * lo: 起始位置
  9247. * hi: 结束位置
  9248. */
  9249. return function (a, x, _lo, _hi) {
  9250. var lo = isNil(_lo) ? 0 : _lo;
  9251. var hi = isNil(_hi) ? a.length : _hi;
  9252. while (lo < hi) {
  9253. var mid = (lo + hi) >>> 1;
  9254. if (getter(a[mid]) > x) {
  9255. hi = mid;
  9256. }
  9257. else {
  9258. lo = mid + 1;
  9259. }
  9260. }
  9261. return lo;
  9262. };
  9263. }
  9264. var FORMAT_METHOD = 'format';
  9265. function timeFormat(time, mask) {
  9266. var method = fecha1[FORMAT_METHOD] || fecha[FORMAT_METHOD];
  9267. return method(time, mask);
  9268. }
  9269. /**
  9270. * 转换成时间戳
  9271. * @param value 时间值
  9272. */
  9273. function toTimeStamp$1(value) {
  9274. if (isString(value)) {
  9275. if (value.indexOf('T') > 0) {
  9276. value = new Date(value).getTime();
  9277. }
  9278. else {
  9279. // new Date('2010/01/10') 和 new Date('2010-01-10') 的差别在于:
  9280. // 如果仅有年月日时,前者是带有时区的: Fri Jan 10 2020 02:40:13 GMT+0800 (中国标准时间)
  9281. // 后者会格式化成 Sun Jan 10 2010 08:00:00 GMT+0800 (中国标准时间)
  9282. value = new Date(value.replace(/-/gi, '/')).getTime();
  9283. }
  9284. }
  9285. if (isDate(value)) {
  9286. value = value.getTime();
  9287. }
  9288. return value;
  9289. }
  9290. var SECOND = 1000;
  9291. var MINUTE = 60 * SECOND;
  9292. var HOUR = 60 * MINUTE;
  9293. var DAY = 24 * HOUR;
  9294. var MONTH = DAY * 31;
  9295. var YEAR = DAY * 365;
  9296. var intervals = [
  9297. ['HH:mm:ss', SECOND],
  9298. ['HH:mm:ss', SECOND * 10],
  9299. ['HH:mm:ss', SECOND * 30],
  9300. ['HH:mm', MINUTE],
  9301. ['HH:mm', MINUTE * 10],
  9302. ['HH:mm', MINUTE * 30],
  9303. ['HH', HOUR],
  9304. ['HH', HOUR * 6],
  9305. ['HH', HOUR * 12],
  9306. ['YYYY-MM-DD', DAY],
  9307. ['YYYY-MM-DD', DAY * 4],
  9308. ['YYYY-WW', DAY * 7],
  9309. ['YYYY-MM', MONTH],
  9310. ['YYYY-MM', MONTH * 4],
  9311. ['YYYY-MM', MONTH * 6],
  9312. ['YYYY', DAY * 380],
  9313. ];
  9314. function getTickInterval(min, max, tickCount) {
  9315. var target = (max - min) / tickCount;
  9316. var idx = bisector(function (o) { return o[1]; })(intervals, target) - 1;
  9317. var interval = intervals[idx];
  9318. if (idx < 0) {
  9319. interval = intervals[0];
  9320. }
  9321. else if (idx >= intervals.length) {
  9322. interval = last(intervals);
  9323. }
  9324. return interval;
  9325. }
  9326. /**
  9327. * 时间分类度量
  9328. * @class
  9329. */
  9330. var TimeCat = /** @class */ (function (_super) {
  9331. __extends(TimeCat, _super);
  9332. function TimeCat() {
  9333. var _this = _super !== null && _super.apply(this, arguments) || this;
  9334. _this.type = 'timeCat';
  9335. return _this;
  9336. }
  9337. /**
  9338. * @override
  9339. */
  9340. TimeCat.prototype.translate = function (value) {
  9341. value = toTimeStamp$1(value);
  9342. var index = this.values.indexOf(value);
  9343. if (index === -1) {
  9344. if (isNumber(value) && value < this.values.length) {
  9345. index = value;
  9346. }
  9347. else {
  9348. index = NaN;
  9349. }
  9350. }
  9351. return index;
  9352. };
  9353. /**
  9354. * 由于时间类型数据需要转换一下,所以复写 getText
  9355. * @override
  9356. */
  9357. TimeCat.prototype.getText = function (value, tickIndex) {
  9358. var index = this.translate(value);
  9359. if (index > -1) {
  9360. var result = this.values[index];
  9361. var formatter = this.formatter;
  9362. result = formatter ? formatter(result, tickIndex) : timeFormat(result, this.mask);
  9363. return result;
  9364. }
  9365. return value;
  9366. };
  9367. TimeCat.prototype.initCfg = function () {
  9368. this.tickMethod = 'time-cat';
  9369. this.mask = 'YYYY-MM-DD';
  9370. this.tickCount = 7; // 一般时间数据会显示 7, 14, 30 天的数字
  9371. };
  9372. TimeCat.prototype.setDomain = function () {
  9373. var values = this.values;
  9374. // 针对时间分类类型,会将时间统一转换为时间戳
  9375. each(values, function (v, i) {
  9376. values[i] = toTimeStamp$1(v);
  9377. });
  9378. values.sort(function (v1, v2) {
  9379. return v1 - v2;
  9380. });
  9381. _super.prototype.setDomain.call(this);
  9382. };
  9383. return TimeCat;
  9384. }(Category));
  9385. /**
  9386. * 连续度量的基类
  9387. * @class
  9388. */
  9389. var Continuous = /** @class */ (function (_super) {
  9390. __extends(Continuous, _super);
  9391. function Continuous() {
  9392. var _this = _super !== null && _super.apply(this, arguments) || this;
  9393. _this.isContinuous = true;
  9394. return _this;
  9395. }
  9396. Continuous.prototype.scale = function (value) {
  9397. if (isNil(value)) {
  9398. return NaN;
  9399. }
  9400. var rangeMin = this.rangeMin();
  9401. var rangeMax = this.rangeMax();
  9402. var max = this.max;
  9403. var min = this.min;
  9404. if (max === min) {
  9405. return rangeMin;
  9406. }
  9407. var percent = this.getScalePercent(value);
  9408. return rangeMin + percent * (rangeMax - rangeMin);
  9409. };
  9410. Continuous.prototype.init = function () {
  9411. _super.prototype.init.call(this);
  9412. // init 完成后保证 min, max 包含 ticks 的范围
  9413. var ticks = this.ticks;
  9414. var firstTick = head(ticks);
  9415. var lastTick = last(ticks);
  9416. if (firstTick < this.min) {
  9417. this.min = firstTick;
  9418. }
  9419. if (lastTick > this.max) {
  9420. this.max = lastTick;
  9421. }
  9422. // strict-limit 方式
  9423. if (!isNil(this.minLimit)) {
  9424. this.min = firstTick;
  9425. }
  9426. if (!isNil(this.maxLimit)) {
  9427. this.max = lastTick;
  9428. }
  9429. };
  9430. Continuous.prototype.setDomain = function () {
  9431. var _a = getRange(this.values), min = _a.min, max = _a.max;
  9432. if (isNil(this.min)) {
  9433. this.min = min;
  9434. }
  9435. if (isNil(this.max)) {
  9436. this.max = max;
  9437. }
  9438. if (this.min > this.max) {
  9439. this.min = min;
  9440. this.max = max;
  9441. }
  9442. };
  9443. Continuous.prototype.calculateTicks = function () {
  9444. var _this = this;
  9445. var ticks = _super.prototype.calculateTicks.call(this);
  9446. if (!this.nice) {
  9447. ticks = filter(ticks, function (tick) {
  9448. return tick >= _this.min && tick <= _this.max;
  9449. });
  9450. }
  9451. return ticks;
  9452. };
  9453. // 计算原始值值占的百分比
  9454. Continuous.prototype.getScalePercent = function (value) {
  9455. var max = this.max;
  9456. var min = this.min;
  9457. return (value - min) / (max - min);
  9458. };
  9459. Continuous.prototype.getInvertPercent = function (value) {
  9460. return (value - this.rangeMin()) / (this.rangeMax() - this.rangeMin());
  9461. };
  9462. return Continuous;
  9463. }(Scale));
  9464. /**
  9465. * 线性度量
  9466. * @class
  9467. */
  9468. var Linear = /** @class */ (function (_super) {
  9469. __extends(Linear, _super);
  9470. function Linear() {
  9471. var _this = _super !== null && _super.apply(this, arguments) || this;
  9472. _this.type = 'linear';
  9473. _this.isLinear = true;
  9474. return _this;
  9475. }
  9476. Linear.prototype.invert = function (value) {
  9477. var percent = this.getInvertPercent(value);
  9478. return this.min + percent * (this.max - this.min);
  9479. };
  9480. Linear.prototype.initCfg = function () {
  9481. this.tickMethod = 'wilkinson-extended';
  9482. this.nice = false;
  9483. };
  9484. return Linear;
  9485. }(Continuous));
  9486. // 求以a为次幂,结果为b的基数,如 x^^a = b;求x
  9487. // 虽然数学上 b 不支持负数,但是这里需要支持 负数
  9488. function calBase(a, b) {
  9489. var e = Math.E;
  9490. var value;
  9491. if (b >= 0) {
  9492. value = Math.pow(e, Math.log(b) / a); // 使用换底公式求底
  9493. }
  9494. else {
  9495. value = Math.pow(e, Math.log(-b) / a) * -1; // 使用换底公式求底
  9496. }
  9497. return value;
  9498. }
  9499. function log(a, b) {
  9500. if (a === 1) {
  9501. return 1;
  9502. }
  9503. return Math.log(b) / Math.log(a);
  9504. }
  9505. function getLogPositiveMin(values, base, max) {
  9506. if (isNil(max)) {
  9507. max = Math.max.apply(null, values);
  9508. }
  9509. var positiveMin = max;
  9510. each(values, function (value) {
  9511. if (value > 0 && value < positiveMin) {
  9512. positiveMin = value;
  9513. }
  9514. });
  9515. if (positiveMin === max) {
  9516. positiveMin = max / base;
  9517. }
  9518. if (positiveMin > 1) {
  9519. positiveMin = 1;
  9520. }
  9521. return positiveMin;
  9522. }
  9523. /**
  9524. * Log 度量,处理非均匀分布
  9525. */
  9526. var Log = /** @class */ (function (_super) {
  9527. __extends(Log, _super);
  9528. function Log() {
  9529. var _this = _super !== null && _super.apply(this, arguments) || this;
  9530. _this.type = 'log';
  9531. return _this;
  9532. }
  9533. /**
  9534. * @override
  9535. */
  9536. Log.prototype.invert = function (value) {
  9537. var base = this.base;
  9538. var max = log(base, this.max);
  9539. var rangeMin = this.rangeMin();
  9540. var range = this.rangeMax() - rangeMin;
  9541. var min;
  9542. var positiveMin = this.positiveMin;
  9543. if (positiveMin) {
  9544. if (value === 0) {
  9545. return 0;
  9546. }
  9547. min = log(base, positiveMin / base);
  9548. var appendPercent = (1 / (max - min)) * range; // 0 到 positiveMin的占比
  9549. if (value < appendPercent) {
  9550. // 落到 0 - positiveMin 之间
  9551. return (value / appendPercent) * positiveMin;
  9552. }
  9553. }
  9554. else {
  9555. min = log(base, this.min);
  9556. }
  9557. var percent = (value - rangeMin) / range;
  9558. var tmp = percent * (max - min) + min;
  9559. return Math.pow(base, tmp);
  9560. };
  9561. Log.prototype.initCfg = function () {
  9562. this.tickMethod = 'log';
  9563. this.base = 10;
  9564. this.tickCount = 6;
  9565. this.nice = true;
  9566. };
  9567. // 设置
  9568. Log.prototype.setDomain = function () {
  9569. _super.prototype.setDomain.call(this);
  9570. var min = this.min;
  9571. if (min < 0) {
  9572. throw new Error('When you use log scale, the minimum value must be greater than zero!');
  9573. }
  9574. if (min === 0) {
  9575. this.positiveMin = getLogPositiveMin(this.values, this.base, this.max);
  9576. }
  9577. };
  9578. // 根据当前值获取占比
  9579. Log.prototype.getScalePercent = function (value) {
  9580. var max = this.max;
  9581. var min = this.min;
  9582. if (max === min) {
  9583. return 0;
  9584. }
  9585. // 如果值小于等于0,则按照0处理
  9586. if (value <= 0) {
  9587. return 0;
  9588. }
  9589. var base = this.base;
  9590. var positiveMin = this.positiveMin;
  9591. // 如果min == 0, 则根据比0大的最小值,计算比例关系。这个最小值作为坐标轴上的第二个tick,第一个是0但是不显示
  9592. if (positiveMin) {
  9593. min = (positiveMin * 1) / base;
  9594. }
  9595. var percent;
  9596. // 如果数值小于次小值,那么就计算 value / 次小值 占整体的比例
  9597. if (value < positiveMin) {
  9598. percent = value / positiveMin / (log(base, max) - log(base, min));
  9599. }
  9600. else {
  9601. percent = (log(base, value) - log(base, min)) / (log(base, max) - log(base, min));
  9602. }
  9603. return percent;
  9604. };
  9605. return Log;
  9606. }(Continuous));
  9607. /**
  9608. * Pow 度量,处理非均匀分布
  9609. */
  9610. var Pow = /** @class */ (function (_super) {
  9611. __extends(Pow, _super);
  9612. function Pow() {
  9613. var _this = _super !== null && _super.apply(this, arguments) || this;
  9614. _this.type = 'pow';
  9615. return _this;
  9616. }
  9617. /**
  9618. * @override
  9619. */
  9620. Pow.prototype.invert = function (value) {
  9621. var percent = this.getInvertPercent(value);
  9622. var exponent = this.exponent;
  9623. var max = calBase(exponent, this.max);
  9624. var min = calBase(exponent, this.min);
  9625. var tmp = percent * (max - min) + min;
  9626. var factor = tmp >= 0 ? 1 : -1;
  9627. return Math.pow(tmp, exponent) * factor;
  9628. };
  9629. Pow.prototype.initCfg = function () {
  9630. this.tickMethod = 'pow';
  9631. this.exponent = 2;
  9632. this.tickCount = 5;
  9633. this.nice = true;
  9634. };
  9635. // 获取度量计算时,value占的定义域百分比
  9636. Pow.prototype.getScalePercent = function (value) {
  9637. var max = this.max;
  9638. var min = this.min;
  9639. if (max === min) {
  9640. return 0;
  9641. }
  9642. var exponent = this.exponent;
  9643. var percent = (calBase(exponent, value) - calBase(exponent, min)) / (calBase(exponent, max) - calBase(exponent, min));
  9644. return percent;
  9645. };
  9646. return Pow;
  9647. }(Continuous));
  9648. /**
  9649. * 时间度量
  9650. * @class
  9651. */
  9652. var Time = /** @class */ (function (_super) {
  9653. __extends(Time, _super);
  9654. function Time() {
  9655. var _this = _super !== null && _super.apply(this, arguments) || this;
  9656. _this.type = 'time';
  9657. return _this;
  9658. }
  9659. /**
  9660. * @override
  9661. */
  9662. Time.prototype.getText = function (value, index) {
  9663. var numberValue = this.translate(value);
  9664. var formatter = this.formatter;
  9665. return formatter ? formatter(numberValue, index) : timeFormat(numberValue, this.mask);
  9666. };
  9667. /**
  9668. * @override
  9669. */
  9670. Time.prototype.scale = function (value) {
  9671. var v = value;
  9672. if (isString(v) || isDate(v)) {
  9673. v = this.translate(v);
  9674. }
  9675. return _super.prototype.scale.call(this, v);
  9676. };
  9677. /**
  9678. * 将时间转换成数字
  9679. * @override
  9680. */
  9681. Time.prototype.translate = function (v) {
  9682. return toTimeStamp$1(v);
  9683. };
  9684. Time.prototype.initCfg = function () {
  9685. this.tickMethod = 'time-pretty';
  9686. this.mask = 'YYYY-MM-DD';
  9687. this.tickCount = 7;
  9688. this.nice = false;
  9689. };
  9690. Time.prototype.setDomain = function () {
  9691. var values = this.values;
  9692. // 是否设置了 min, max,而不是直接取 this.min, this.max
  9693. var minConfig = this.getConfig('min');
  9694. var maxConfig = this.getConfig('max');
  9695. // 如果设置了 min,max 则转换成时间戳
  9696. if (!isNil(minConfig) || !isNumber(minConfig)) {
  9697. this.min = this.translate(this.min);
  9698. }
  9699. if (!isNil(maxConfig) || !isNumber(maxConfig)) {
  9700. this.max = this.translate(this.max);
  9701. }
  9702. // 没有设置 min, max 时
  9703. if (values && values.length) {
  9704. // 重新计算最大最小值
  9705. var timeStamps_1 = [];
  9706. var min_1 = Infinity; // 最小值
  9707. var secondMin_1 = min_1; // 次小值
  9708. var max_1 = 0;
  9709. // 使用一个循环,计算min,max,secondMin
  9710. each(values, function (v) {
  9711. var timeStamp = toTimeStamp$1(v);
  9712. if (isNaN(timeStamp)) {
  9713. throw new TypeError("Invalid Time: " + v + " in time scale!");
  9714. }
  9715. if (min_1 > timeStamp) {
  9716. secondMin_1 = min_1;
  9717. min_1 = timeStamp;
  9718. }
  9719. else if (secondMin_1 > timeStamp) {
  9720. secondMin_1 = timeStamp;
  9721. }
  9722. if (max_1 < timeStamp) {
  9723. max_1 = timeStamp;
  9724. }
  9725. timeStamps_1.push(timeStamp);
  9726. });
  9727. // 存在多个值时,设置最小间距
  9728. if (values.length > 1) {
  9729. this.minTickInterval = secondMin_1 - min_1;
  9730. }
  9731. if (isNil(minConfig)) {
  9732. this.min = min_1;
  9733. }
  9734. if (isNil(maxConfig)) {
  9735. this.max = max_1;
  9736. }
  9737. }
  9738. };
  9739. return Time;
  9740. }(Linear));
  9741. /**
  9742. * 分段度量
  9743. */
  9744. var Quantize = /** @class */ (function (_super) {
  9745. __extends(Quantize, _super);
  9746. function Quantize() {
  9747. var _this = _super !== null && _super.apply(this, arguments) || this;
  9748. _this.type = 'quantize';
  9749. return _this;
  9750. }
  9751. Quantize.prototype.invert = function (value) {
  9752. var ticks = this.ticks;
  9753. var length = ticks.length;
  9754. var percent = this.getInvertPercent(value);
  9755. var minIndex = Math.floor(percent * (length - 1));
  9756. // 最后一个
  9757. if (minIndex >= length - 1) {
  9758. return last(ticks);
  9759. }
  9760. // 超出左边界, 则取第一个
  9761. if (minIndex < 0) {
  9762. return head(ticks);
  9763. }
  9764. var minTick = ticks[minIndex];
  9765. var nextTick = ticks[minIndex + 1];
  9766. // 比当前值小的 tick 在度量上的占比
  9767. var minIndexPercent = minIndex / (length - 1);
  9768. var maxIndexPercent = (minIndex + 1) / (length - 1);
  9769. return minTick + (percent - minIndexPercent) / (maxIndexPercent - minIndexPercent) * (nextTick - minTick);
  9770. };
  9771. Quantize.prototype.initCfg = function () {
  9772. this.tickMethod = 'r-pretty';
  9773. this.tickCount = 5;
  9774. this.nice = true;
  9775. };
  9776. Quantize.prototype.calculateTicks = function () {
  9777. var ticks = _super.prototype.calculateTicks.call(this);
  9778. if (!this.nice) { // 如果 nice = false ,补充 min, max
  9779. if (last(ticks) !== this.max) {
  9780. ticks.push(this.max);
  9781. }
  9782. if (head(ticks) !== this.min) {
  9783. ticks.unshift(this.min);
  9784. }
  9785. }
  9786. return ticks;
  9787. };
  9788. // 计算当前值在刻度中的占比
  9789. Quantize.prototype.getScalePercent = function (value) {
  9790. var ticks = this.ticks;
  9791. // 超出左边界
  9792. if (value < head(ticks)) {
  9793. return 0;
  9794. }
  9795. // 超出右边界
  9796. if (value > last(ticks)) {
  9797. return 1;
  9798. }
  9799. var minIndex = 0;
  9800. each(ticks, function (tick, index) {
  9801. if (value >= tick) {
  9802. minIndex = index;
  9803. }
  9804. else {
  9805. return false;
  9806. }
  9807. });
  9808. return minIndex / (ticks.length - 1);
  9809. };
  9810. return Quantize;
  9811. }(Continuous));
  9812. var Quantile = /** @class */ (function (_super) {
  9813. __extends(Quantile, _super);
  9814. function Quantile() {
  9815. var _this = _super !== null && _super.apply(this, arguments) || this;
  9816. _this.type = 'quantile';
  9817. return _this;
  9818. }
  9819. Quantile.prototype.initCfg = function () {
  9820. this.tickMethod = 'quantile';
  9821. this.tickCount = 5;
  9822. this.nice = true;
  9823. };
  9824. return Quantile;
  9825. }(Quantize));
  9826. var map$3 = {};
  9827. function getClass(key) {
  9828. return map$3[key];
  9829. }
  9830. function registerClass(key, cls) {
  9831. if (getClass(key)) {
  9832. throw new Error("type '" + key + "' existed.");
  9833. }
  9834. map$3[key] = cls;
  9835. }
  9836. /**
  9837. * identity scale原则上是定义域和值域一致,scale/invert方法也是一致的
  9838. * 参考R的实现:https://github.com/r-lib/scales/blob/master/R/pal-identity.r
  9839. * 参考d3的实现(做了下转型):https://github.com/d3/d3-scale/blob/master/src/identity.js
  9840. */
  9841. var Identity = /** @class */ (function (_super) {
  9842. __extends(Identity, _super);
  9843. function Identity() {
  9844. var _this = _super !== null && _super.apply(this, arguments) || this;
  9845. _this.type = 'identity';
  9846. _this.isIdentity = true;
  9847. return _this;
  9848. }
  9849. Identity.prototype.calculateTicks = function () {
  9850. return this.values;
  9851. };
  9852. Identity.prototype.scale = function (value) {
  9853. // 如果传入的值不等于 identity 的值,则直接返回,用于一维图时的 dodge
  9854. if (this.values[0] !== value && isNumber(value)) {
  9855. return value;
  9856. }
  9857. return this.range[0];
  9858. };
  9859. Identity.prototype.invert = function (value) {
  9860. var range = this.range;
  9861. if (value < range[0] || value > range[1]) {
  9862. return NaN;
  9863. }
  9864. return this.values[0];
  9865. };
  9866. return Identity;
  9867. }(Scale));
  9868. /**
  9869. * 计算分类 ticks
  9870. * @param cfg 度量的配置项
  9871. * @returns 计算后的 ticks
  9872. */
  9873. function calculateCatTicks(cfg) {
  9874. var values = cfg.values, tickInterval = cfg.tickInterval, tickCount = cfg.tickCount, showLast = cfg.showLast;
  9875. if (isNumber(tickInterval)) {
  9876. var ticks_1 = filter(values, function (__, i) { return i % tickInterval === 0; });
  9877. var lastValue = last(values);
  9878. if (showLast && last(ticks_1) !== lastValue) {
  9879. ticks_1.push(lastValue);
  9880. }
  9881. return ticks_1;
  9882. }
  9883. var len = values.length;
  9884. var min = cfg.min, max = cfg.max;
  9885. if (isNil(min)) {
  9886. min = 0;
  9887. }
  9888. if (isNil(max)) {
  9889. max = values.length - 1;
  9890. }
  9891. if (!isNumber(tickCount) || tickCount >= len)
  9892. return values.slice(min, max + 1);
  9893. if (tickCount <= 0 || max <= 0)
  9894. return [];
  9895. var interval = tickCount === 1 ? len : Math.floor(len / (tickCount - 1));
  9896. var ticks = [];
  9897. var idx = min;
  9898. for (var i = 0; i < tickCount; i++) {
  9899. if (idx >= max)
  9900. break;
  9901. idx = Math.min(min + i * interval, max);
  9902. if (i === tickCount - 1 && showLast)
  9903. ticks.push(values[max]);
  9904. else
  9905. ticks.push(values[idx]);
  9906. }
  9907. return ticks;
  9908. }
  9909. function d3Linear(cfg) {
  9910. var min = cfg.min, max = cfg.max, nice = cfg.nice, tickCount = cfg.tickCount;
  9911. var linear = new D3Linear();
  9912. linear.domain([min, max]);
  9913. if (nice) {
  9914. linear.nice(tickCount);
  9915. }
  9916. return linear.ticks(tickCount);
  9917. }
  9918. var DEFAULT_COUNT = 5;
  9919. var e10 = Math.sqrt(50);
  9920. var e5 = Math.sqrt(10);
  9921. var e2 = Math.sqrt(2);
  9922. // https://github.com/d3/d3-scale
  9923. var D3Linear = /** @class */ (function () {
  9924. function D3Linear() {
  9925. this._domain = [0, 1];
  9926. }
  9927. D3Linear.prototype.domain = function (domain) {
  9928. if (domain) {
  9929. this._domain = Array.from(domain, Number);
  9930. return this;
  9931. }
  9932. return this._domain.slice();
  9933. };
  9934. D3Linear.prototype.nice = function (count) {
  9935. var _a, _b;
  9936. if (count === void 0) { count = DEFAULT_COUNT; }
  9937. var d = this._domain.slice();
  9938. var i0 = 0;
  9939. var i1 = this._domain.length - 1;
  9940. var start = this._domain[i0];
  9941. var stop = this._domain[i1];
  9942. var step;
  9943. if (stop < start) {
  9944. _a = [stop, start], start = _a[0], stop = _a[1];
  9945. _b = [i1, i0], i0 = _b[0], i1 = _b[1];
  9946. }
  9947. step = tickIncrement(start, stop, count);
  9948. if (step > 0) {
  9949. start = Math.floor(start / step) * step;
  9950. stop = Math.ceil(stop / step) * step;
  9951. step = tickIncrement(start, stop, count);
  9952. }
  9953. else if (step < 0) {
  9954. start = Math.ceil(start * step) / step;
  9955. stop = Math.floor(stop * step) / step;
  9956. step = tickIncrement(start, stop, count);
  9957. }
  9958. if (step > 0) {
  9959. d[i0] = Math.floor(start / step) * step;
  9960. d[i1] = Math.ceil(stop / step) * step;
  9961. this.domain(d);
  9962. }
  9963. else if (step < 0) {
  9964. d[i0] = Math.ceil(start * step) / step;
  9965. d[i1] = Math.floor(stop * step) / step;
  9966. this.domain(d);
  9967. }
  9968. return this;
  9969. };
  9970. D3Linear.prototype.ticks = function (count) {
  9971. if (count === void 0) { count = DEFAULT_COUNT; }
  9972. return d3ArrayTicks(this._domain[0], this._domain[this._domain.length - 1], count || DEFAULT_COUNT);
  9973. };
  9974. return D3Linear;
  9975. }());
  9976. function d3ArrayTicks(start, stop, count) {
  9977. var reverse;
  9978. var i = -1;
  9979. var n;
  9980. var ticks;
  9981. var step;
  9982. (stop = +stop), (start = +start), (count = +count);
  9983. if (start === stop && count > 0) {
  9984. return [start];
  9985. }
  9986. // tslint:disable-next-line
  9987. if ((reverse = stop < start)) {
  9988. (n = start), (start = stop), (stop = n);
  9989. }
  9990. // tslint:disable-next-line
  9991. if ((step = tickIncrement(start, stop, count)) === 0 || !isFinite(step)) {
  9992. return [];
  9993. }
  9994. if (step > 0) {
  9995. start = Math.ceil(start / step);
  9996. stop = Math.floor(stop / step);
  9997. ticks = new Array((n = Math.ceil(stop - start + 1)));
  9998. while (++i < n) {
  9999. ticks[i] = (start + i) * step;
  10000. }
  10001. }
  10002. else {
  10003. start = Math.floor(start * step);
  10004. stop = Math.ceil(stop * step);
  10005. ticks = new Array((n = Math.ceil(start - stop + 1)));
  10006. while (++i < n) {
  10007. ticks[i] = (start - i) / step;
  10008. }
  10009. }
  10010. if (reverse) {
  10011. ticks.reverse();
  10012. }
  10013. return ticks;
  10014. }
  10015. function tickIncrement(start, stop, count) {
  10016. var step = (stop - start) / Math.max(0, count);
  10017. var power = Math.floor(Math.log(step) / Math.LN10);
  10018. var error = step / Math.pow(10, power);
  10019. return power >= 0
  10020. ? (error >= e10 ? 10 : error >= e5 ? 5 : error >= e2 ? 2 : 1) * Math.pow(10, power)
  10021. : -Math.pow(10, -power) / (error >= e10 ? 10 : error >= e5 ? 5 : error >= e2 ? 2 : 1);
  10022. }
  10023. function snapMultiple(v, base, snapType) {
  10024. var div;
  10025. if (snapType === 'ceil') {
  10026. div = Math.ceil(v / base);
  10027. }
  10028. else if (snapType === 'floor') {
  10029. div = Math.floor(v / base);
  10030. }
  10031. else {
  10032. div = Math.round(v / base);
  10033. }
  10034. return div * base;
  10035. }
  10036. function intervalTicks(min, max, interval) {
  10037. // 变成 interval 的倍数
  10038. var minTick = snapMultiple(min, interval, 'floor');
  10039. var maxTick = snapMultiple(max, interval, 'ceil');
  10040. // 统一小数位数
  10041. minTick = fixedBase(minTick, interval);
  10042. maxTick = fixedBase(maxTick, interval);
  10043. var ticks = [];
  10044. // https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Errors/Invalid_array_length
  10045. var availableInterval = Math.max((maxTick - minTick) / (Math.pow(2, 12) - 1), interval);
  10046. for (var i = minTick; i <= maxTick; i = i + availableInterval) {
  10047. var tickValue = fixedBase(i, availableInterval); // 防止浮点数加法出现问题
  10048. ticks.push(tickValue);
  10049. }
  10050. return {
  10051. min: minTick,
  10052. max: maxTick,
  10053. ticks: ticks
  10054. };
  10055. }
  10056. /**
  10057. * 按照给定的 minLimit/maxLimit/tickCount 均匀计算出刻度 ticks
  10058. *
  10059. * @param cfg Scale 配置项
  10060. * @return ticks
  10061. */
  10062. function strictLimit(cfg, defaultMin, defaultMax) {
  10063. var _a;
  10064. var minLimit = cfg.minLimit, maxLimit = cfg.maxLimit, min = cfg.min, max = cfg.max, _b = cfg.tickCount, tickCount = _b === void 0 ? 5 : _b;
  10065. var tickMin = isNil(minLimit) ? (isNil(defaultMin) ? min : defaultMin) : minLimit;
  10066. var tickMax = isNil(maxLimit) ? (isNil(defaultMax) ? max : defaultMax) : maxLimit;
  10067. if (tickMin > tickMax) {
  10068. _a = [tickMin, tickMax], tickMax = _a[0], tickMin = _a[1];
  10069. }
  10070. if (tickCount <= 2) {
  10071. return [tickMin, tickMax];
  10072. }
  10073. var step = (tickMax - tickMin) / (tickCount - 1);
  10074. var ticks = [];
  10075. for (var i = 0; i < tickCount; i++) {
  10076. ticks.push(tickMin + step * i);
  10077. }
  10078. return ticks;
  10079. }
  10080. function d3LinearTickMethod(cfg) {
  10081. var min = cfg.min, max = cfg.max, tickInterval = cfg.tickInterval, minLimit = cfg.minLimit, maxLimit = cfg.maxLimit;
  10082. var ticks = d3Linear(cfg);
  10083. if (!isNil(minLimit) || !isNil(maxLimit)) {
  10084. return strictLimit(cfg, head(ticks), last(ticks));
  10085. }
  10086. if (tickInterval) {
  10087. return intervalTicks(min, max, tickInterval).ticks;
  10088. }
  10089. return ticks;
  10090. }
  10091. // 为了解决 js 运算的精度问题
  10092. function prettyNumber(n) {
  10093. return Math.abs(n) < 1e-15 ? n : parseFloat(n.toFixed(15));
  10094. }
  10095. var DEFAULT_Q = [1, 5, 2, 2.5, 4, 3];
  10096. var eps = Number.EPSILON * 100;
  10097. function mod(n, m) {
  10098. return ((n % m) + m) % m;
  10099. }
  10100. function round(n) {
  10101. return Math.round(n * 1e12) / 1e12;
  10102. }
  10103. function simplicity(q, Q, j, lmin, lmax, lstep) {
  10104. var n = size(Q);
  10105. var i = indexOf(Q, q);
  10106. var v = 0;
  10107. var m = mod(lmin, lstep);
  10108. if ((m < eps || lstep - m < eps) && lmin <= 0 && lmax >= 0) {
  10109. v = 1;
  10110. }
  10111. return 1 - i / (n - 1) - j + v;
  10112. }
  10113. function simplicityMax(q, Q, j) {
  10114. var n = size(Q);
  10115. var i = indexOf(Q, q);
  10116. var v = 1;
  10117. return 1 - i / (n - 1) - j + v;
  10118. }
  10119. function density(k, m, dMin, dMax, lMin, lMax) {
  10120. var r = (k - 1) / (lMax - lMin);
  10121. var rt = (m - 1) / (Math.max(lMax, dMax) - Math.min(dMin, lMin));
  10122. return 2 - Math.max(r / rt, rt / r);
  10123. }
  10124. function densityMax(k, m) {
  10125. if (k >= m) {
  10126. return 2 - (k - 1) / (m - 1);
  10127. }
  10128. return 1;
  10129. }
  10130. function coverage(dMin, dMax, lMin, lMax) {
  10131. var range = dMax - dMin;
  10132. return 1 - (0.5 * (Math.pow((dMax - lMax), 2) + Math.pow((dMin - lMin), 2))) / Math.pow((0.1 * range), 2);
  10133. }
  10134. function coverageMax(dMin, dMax, span) {
  10135. var range = dMax - dMin;
  10136. if (span > range) {
  10137. var half = (span - range) / 2;
  10138. return 1 - Math.pow(half, 2) / Math.pow((0.1 * range), 2);
  10139. }
  10140. return 1;
  10141. }
  10142. function legibility() {
  10143. return 1;
  10144. }
  10145. /**
  10146. * An Extension of Wilkinson's Algorithm for Position Tick Labels on Axes
  10147. * https://www.yuque.com/preview/yuque/0/2019/pdf/185317/1546999150858-45c3b9c2-4e86-4223-bf1a-8a732e8195ed.pdf
  10148. * @param dMin 最小值
  10149. * @param dMax 最大值
  10150. * @param m tick个数
  10151. * @param onlyLoose 是否允许扩展min、max,不绝对强制,例如[3, 97]
  10152. * @param Q nice numbers集合
  10153. * @param w 四个优化组件的权重
  10154. */
  10155. function extended(dMin, dMax, n, onlyLoose, Q, w) {
  10156. if (n === void 0) { n = 5; }
  10157. if (onlyLoose === void 0) { onlyLoose = true; }
  10158. if (Q === void 0) { Q = DEFAULT_Q; }
  10159. if (w === void 0) { w = [0.25, 0.2, 0.5, 0.05]; }
  10160. // 处理小于 0 和小数的 tickCount
  10161. var m = n < 0 ? 0 : Math.round(n);
  10162. // nan 也会导致异常
  10163. if (Number.isNaN(dMin) || Number.isNaN(dMax) || typeof dMin !== 'number' || typeof dMax !== 'number' || !m) {
  10164. return {
  10165. min: 0,
  10166. max: 0,
  10167. ticks: [],
  10168. };
  10169. }
  10170. // js 极大值极小值问题,差值小于 1e-15 会导致计算出错
  10171. if (dMax - dMin < 1e-15 || m === 1) {
  10172. return {
  10173. min: dMin,
  10174. max: dMax,
  10175. ticks: [dMin],
  10176. };
  10177. }
  10178. // js 超大值问题
  10179. if (dMax - dMin > 1e148) {
  10180. var count = n || 5;
  10181. var step_1 = (dMax - dMin) / count;
  10182. return {
  10183. min: dMin,
  10184. max: dMax,
  10185. ticks: Array(count).fill(null).map(function (_, idx) {
  10186. return prettyNumber(dMin + step_1 * idx);
  10187. }),
  10188. };
  10189. }
  10190. var best = {
  10191. score: -2,
  10192. lmin: 0,
  10193. lmax: 0,
  10194. lstep: 0,
  10195. };
  10196. var j = 1;
  10197. while (j < Infinity) {
  10198. for (var i = 0; i < Q.length; i += 1) {
  10199. var q = Q[i];
  10200. var sm = simplicityMax(q, Q, j);
  10201. if (w[0] * sm + w[1] + w[2] + w[3] < best.score) {
  10202. j = Infinity;
  10203. break;
  10204. }
  10205. var k = 2;
  10206. while (k < Infinity) {
  10207. var dm = densityMax(k, m);
  10208. if (w[0] * sm + w[1] + w[2] * dm + w[3] < best.score) {
  10209. break;
  10210. }
  10211. var delta = (dMax - dMin) / (k + 1) / j / q;
  10212. var z = Math.ceil(Math.log10(delta));
  10213. while (z < Infinity) {
  10214. var step = j * q * Math.pow(10, z);
  10215. var cm = coverageMax(dMin, dMax, step * (k - 1));
  10216. if (w[0] * sm + w[1] * cm + w[2] * dm + w[3] < best.score) {
  10217. break;
  10218. }
  10219. var minStart = Math.floor(dMax / step) * j - (k - 1) * j;
  10220. var maxStart = Math.ceil(dMin / step) * j;
  10221. if (minStart <= maxStart) {
  10222. var count = maxStart - minStart;
  10223. for (var i_1 = 0; i_1 <= count; i_1 += 1) {
  10224. var start = minStart + i_1;
  10225. var lMin = start * (step / j);
  10226. var lMax = lMin + step * (k - 1);
  10227. var lStep = step;
  10228. var s = simplicity(q, Q, j, lMin, lMax, lStep);
  10229. var c = coverage(dMin, dMax, lMin, lMax);
  10230. var g = density(k, m, dMin, dMax, lMin, lMax);
  10231. var l = legibility();
  10232. var score = w[0] * s + w[1] * c + w[2] * g + w[3] * l;
  10233. if (score > best.score && (!onlyLoose || (lMin <= dMin && lMax >= dMax))) {
  10234. best.lmin = lMin;
  10235. best.lmax = lMax;
  10236. best.lstep = lStep;
  10237. best.score = score;
  10238. }
  10239. }
  10240. }
  10241. z += 1;
  10242. }
  10243. k += 1;
  10244. }
  10245. }
  10246. j += 1;
  10247. }
  10248. // 处理精度问题,保证这三个数没有精度问题
  10249. var lmax = prettyNumber(best.lmax);
  10250. var lmin = prettyNumber(best.lmin);
  10251. var lstep = prettyNumber(best.lstep);
  10252. // 加 round 是为处理 extended(0.94, 1, 5)
  10253. // 保证生成的 tickCount 没有精度问题
  10254. var tickCount = Math.floor(round((lmax - lmin) / lstep)) + 1;
  10255. var ticks = new Array(tickCount);
  10256. // 少用乘法:防止出现 -1.2 + 1.2 * 3 = 2.3999999999999995 的情况
  10257. ticks[0] = prettyNumber(lmin);
  10258. for (var i = 1; i < tickCount; i++) {
  10259. ticks[i] = prettyNumber(ticks[i - 1] + lstep);
  10260. }
  10261. return {
  10262. min: Math.min(dMin, head(ticks)),
  10263. max: Math.max(dMax, last(ticks)),
  10264. ticks: ticks,
  10265. };
  10266. }
  10267. /**
  10268. * 计算线性的 ticks,使用 wilkinson extended 方法
  10269. * @param cfg 度量的配置项
  10270. * @returns 计算后的 ticks
  10271. */
  10272. function linear$2(cfg) {
  10273. var min = cfg.min, max = cfg.max, tickCount = cfg.tickCount, nice = cfg.nice, tickInterval = cfg.tickInterval, minLimit = cfg.minLimit, maxLimit = cfg.maxLimit;
  10274. var ticks = extended(min, max, tickCount, nice).ticks;
  10275. if (!isNil(minLimit) || !isNil(maxLimit)) {
  10276. return strictLimit(cfg, head(ticks), last(ticks));
  10277. }
  10278. if (tickInterval) {
  10279. return intervalTicks(min, max, tickInterval).ticks;
  10280. }
  10281. return ticks;
  10282. }
  10283. /**
  10284. * 计算 log 的 ticks,考虑 min = 0 的场景
  10285. * @param cfg 度量的配置项
  10286. * @returns 计算后的 ticks
  10287. */
  10288. function calculateLogTicks(cfg) {
  10289. var base = cfg.base, tickCount = cfg.tickCount, min = cfg.min, max = cfg.max, values = cfg.values;
  10290. var minTick;
  10291. var maxTick = log(base, max);
  10292. if (min > 0) {
  10293. minTick = Math.floor(log(base, min));
  10294. }
  10295. else {
  10296. var positiveMin = getLogPositiveMin(values, base, max);
  10297. minTick = Math.floor(log(base, positiveMin));
  10298. }
  10299. var count = maxTick - minTick;
  10300. var avg = Math.ceil(count / tickCount);
  10301. var ticks = [];
  10302. for (var i = minTick; i < maxTick + avg; i = i + avg) {
  10303. ticks.push(Math.pow(base, i));
  10304. }
  10305. if (min <= 0) {
  10306. // 最小值 <= 0 时显示 0
  10307. ticks.unshift(0);
  10308. }
  10309. return ticks;
  10310. }
  10311. function pretty(min, max, m) {
  10312. if (m === void 0) { m = 5; }
  10313. if (min === max) {
  10314. return {
  10315. max: max,
  10316. min: min,
  10317. ticks: [min],
  10318. };
  10319. }
  10320. var n = m < 0 ? 0 : Math.round(m);
  10321. if (n === 0)
  10322. return { max: max, min: min, ticks: [] };
  10323. /*
  10324. R pretty:
  10325. https://svn.r-project.org/R/trunk/src/appl/pretty.c
  10326. https://www.rdocumentation.org/packages/base/versions/3.5.2/topics/pretty
  10327. */
  10328. var h = 1.5; // high.u.bias
  10329. var h5 = 0.5 + 1.5 * h; // u5.bias
  10330. // 反正我也不会调参,跳过所有判断步骤
  10331. var d = max - min;
  10332. var c = d / n;
  10333. // 当d非常小的时候触发,但似乎没什么用
  10334. // const min_n = Math.floor(n / 3);
  10335. // const shrink_sml = Math.pow(2, 5);
  10336. // if (Math.log10(d) < -2) {
  10337. // c = (_.max([ Math.abs(max), Math.abs(min) ]) * shrink_sml) / min_n;
  10338. // }
  10339. var base = Math.pow(10, Math.floor(Math.log10(c)));
  10340. var unit = base;
  10341. if (2 * base - c < h * (c - unit)) {
  10342. unit = 2 * base;
  10343. if (5 * base - c < h5 * (c - unit)) {
  10344. unit = 5 * base;
  10345. if (10 * base - c < h * (c - unit)) {
  10346. unit = 10 * base;
  10347. }
  10348. }
  10349. }
  10350. var nu = Math.ceil(max / unit);
  10351. var ns = Math.floor(min / unit);
  10352. var hi = Math.max(nu * unit, max);
  10353. var lo = Math.min(ns * unit, min);
  10354. var size = Math.floor((hi - lo) / unit) + 1;
  10355. var ticks = new Array(size);
  10356. for (var i = 0; i < size; i++) {
  10357. ticks[i] = prettyNumber(lo + i * unit);
  10358. }
  10359. return {
  10360. min: lo,
  10361. max: hi,
  10362. ticks: ticks,
  10363. };
  10364. }
  10365. /**
  10366. * 计算 Pow 的 ticks
  10367. * @param cfg 度量的配置项
  10368. * @returns 计算后的 ticks
  10369. */
  10370. function calculatePowTicks(cfg) {
  10371. var exponent = cfg.exponent, tickCount = cfg.tickCount;
  10372. var max = Math.ceil(calBase(exponent, cfg.max));
  10373. var min = Math.floor(calBase(exponent, cfg.min));
  10374. var ticks = pretty(min, max, tickCount).ticks;
  10375. return ticks.map(function (tick) {
  10376. var factor = tick >= 0 ? 1 : -1;
  10377. return Math.pow(tick, exponent) * factor;
  10378. });
  10379. }
  10380. /**
  10381. * 计算几分位 https://github.com/simple-statistics/simple-statistics/blob/master/src/quantile_sorted.js
  10382. * @param x 数组
  10383. * @param p 百分比
  10384. */
  10385. function quantileSorted(x, p) {
  10386. var idx = x.length * p;
  10387. /*if (x.length === 0) { // 当前场景这些条件不可能命中
  10388. throw new Error('quantile requires at least one value.');
  10389. } else if (p < 0 || p > 1) {
  10390. throw new Error('quantiles must be between 0 and 1');
  10391. } else */
  10392. if (p === 1) {
  10393. // If p is 1, directly return the last element
  10394. return x[x.length - 1];
  10395. }
  10396. else if (p === 0) {
  10397. // If p is 0, directly return the first element
  10398. return x[0];
  10399. }
  10400. else if (idx % 1 !== 0) {
  10401. // If p is not integer, return the next element in array
  10402. return x[Math.ceil(idx) - 1];
  10403. }
  10404. else if (x.length % 2 === 0) {
  10405. // If the list has even-length, we'll take the average of this number
  10406. // and the next value, if there is one
  10407. return (x[idx - 1] + x[idx]) / 2;
  10408. }
  10409. else {
  10410. // Finally, in the simple case of an integer value
  10411. // with an odd-length list, return the x value at the index.
  10412. return x[idx];
  10413. }
  10414. }
  10415. function calculateTicks(cfg) {
  10416. var tickCount = cfg.tickCount, values = cfg.values;
  10417. if (!values || !values.length) {
  10418. return [];
  10419. }
  10420. var sorted = values.slice().sort(function (a, b) {
  10421. return a - b;
  10422. });
  10423. var ticks = [];
  10424. for (var i = 0; i < tickCount; i++) {
  10425. var p = i / (tickCount - 1);
  10426. ticks.push(quantileSorted(sorted, p));
  10427. }
  10428. return ticks;
  10429. }
  10430. /**
  10431. * 计算线性的 ticks,使用 R's pretty 方法
  10432. * @param cfg 度量的配置项
  10433. * @returns 计算后的 ticks
  10434. */
  10435. function linearPretty(cfg) {
  10436. var min = cfg.min, max = cfg.max, tickCount = cfg.tickCount, tickInterval = cfg.tickInterval, minLimit = cfg.minLimit, maxLimit = cfg.maxLimit;
  10437. var ticks = pretty(min, max, tickCount).ticks;
  10438. if (!isNil(minLimit) || !isNil(maxLimit)) {
  10439. return strictLimit(cfg, head(ticks), last(ticks));
  10440. }
  10441. if (tickInterval) {
  10442. return intervalTicks(min, max, tickInterval).ticks;
  10443. }
  10444. return ticks;
  10445. }
  10446. function calculateTimeTicks(cfg) {
  10447. var min = cfg.min, max = cfg.max, minTickInterval = cfg.minTickInterval;
  10448. var tickInterval = cfg.tickInterval;
  10449. var tickCount = cfg.tickCount;
  10450. // 指定 tickInterval 后 tickCount 不生效,需要重新计算
  10451. if (tickInterval) {
  10452. tickCount = Math.ceil((max - min) / tickInterval);
  10453. }
  10454. else {
  10455. tickInterval = getTickInterval(min, max, tickCount)[1];
  10456. var count = (max - min) / tickInterval;
  10457. var ratio = count / tickCount;
  10458. if (ratio > 1) {
  10459. tickInterval = tickInterval * Math.ceil(ratio);
  10460. }
  10461. // 如果设置了最小间距,则使用最小间距
  10462. if (minTickInterval && tickInterval < minTickInterval) {
  10463. tickInterval = minTickInterval;
  10464. }
  10465. }
  10466. tickInterval = Math.max(Math.floor((max - min) / (Math.pow(2, 12) - 1)), tickInterval);
  10467. var ticks = [];
  10468. for (var i = min; i < max + tickInterval; i += tickInterval) {
  10469. ticks.push(i);
  10470. }
  10471. return ticks;
  10472. }
  10473. /**
  10474. * 计算时间分类的 ticks, 保头,保尾
  10475. * @param cfg 度量的配置项
  10476. * @returns 计算后的 ticks
  10477. */
  10478. function timeCat(cfg) {
  10479. // 默认保留最后一条
  10480. var ticks = calculateCatTicks(__assign({ showLast: true }, cfg));
  10481. return ticks;
  10482. }
  10483. function getYear(date) {
  10484. return new Date(date).getFullYear();
  10485. }
  10486. function createYear(year) {
  10487. return new Date(year, 0, 1).getTime();
  10488. }
  10489. function getMonth(date) {
  10490. return new Date(date).getMonth();
  10491. }
  10492. function diffMonth(min, max) {
  10493. var minYear = getYear(min);
  10494. var maxYear = getYear(max);
  10495. var minMonth = getMonth(min);
  10496. var maxMonth = getMonth(max);
  10497. return (maxYear - minYear) * 12 + ((maxMonth - minMonth) % 12);
  10498. }
  10499. function creatMonth(year, month) {
  10500. return new Date(year, month, 1).getTime();
  10501. }
  10502. function diffDay(min, max) {
  10503. return Math.ceil((max - min) / DAY);
  10504. }
  10505. function diffHour(min, max) {
  10506. return Math.ceil((max - min) / HOUR);
  10507. }
  10508. function diffMinus(min, max) {
  10509. return Math.ceil((max - min) / (60 * 1000));
  10510. }
  10511. /**
  10512. * 计算 time 的 ticks,对 month, year 进行 pretty 处理
  10513. * @param cfg 度量的配置项
  10514. * @returns 计算后的 ticks
  10515. */
  10516. function timePretty(cfg) {
  10517. var min = cfg.min, max = cfg.max, minTickInterval = cfg.minTickInterval, tickCount = cfg.tickCount;
  10518. var tickInterval = cfg.tickInterval;
  10519. var ticks = [];
  10520. // 指定 tickInterval 后 tickCount 不生效,需要重新计算
  10521. if (!tickInterval) {
  10522. tickInterval = (max - min) / tickCount;
  10523. // 如果设置了最小间距,则使用最小间距
  10524. if (minTickInterval && tickInterval < minTickInterval) {
  10525. tickInterval = minTickInterval;
  10526. }
  10527. }
  10528. tickInterval = Math.max(Math.floor((max - min) / (Math.pow(2, 12) - 1)), tickInterval);
  10529. var minYear = getYear(min);
  10530. // 如果间距大于 1 年,则将开始日期从整年开始
  10531. if (tickInterval > YEAR) {
  10532. var maxYear = getYear(max);
  10533. var yearInterval = Math.ceil(tickInterval / YEAR);
  10534. for (var i = minYear; i <= maxYear + yearInterval; i = i + yearInterval) {
  10535. ticks.push(createYear(i));
  10536. }
  10537. }
  10538. else if (tickInterval > MONTH) {
  10539. // 大于月时
  10540. var monthInterval = Math.ceil(tickInterval / MONTH);
  10541. var mmMoth = getMonth(min);
  10542. var dMonths = diffMonth(min, max);
  10543. for (var i = 0; i <= dMonths + monthInterval; i = i + monthInterval) {
  10544. ticks.push(creatMonth(minYear, i + mmMoth));
  10545. }
  10546. }
  10547. else if (tickInterval > DAY) {
  10548. // 大于天
  10549. var date = new Date(min);
  10550. var year = date.getFullYear();
  10551. var month = date.getMonth();
  10552. var mday = date.getDate();
  10553. var day = Math.ceil(tickInterval / DAY);
  10554. var ddays = diffDay(min, max);
  10555. for (var i = 0; i < ddays + day; i = i + day) {
  10556. ticks.push(new Date(year, month, mday + i).getTime());
  10557. }
  10558. }
  10559. else if (tickInterval > HOUR) {
  10560. // 大于小时
  10561. var date = new Date(min);
  10562. var year = date.getFullYear();
  10563. var month = date.getMonth();
  10564. var day = date.getDate();
  10565. var hour = date.getHours();
  10566. var hours = Math.ceil(tickInterval / HOUR);
  10567. var dHours = diffHour(min, max);
  10568. for (var i = 0; i <= dHours + hours; i = i + hours) {
  10569. ticks.push(new Date(year, month, day, hour + i).getTime());
  10570. }
  10571. }
  10572. else if (tickInterval > MINUTE) {
  10573. // 大于分钟
  10574. var dMinus = diffMinus(min, max);
  10575. var minutes = Math.ceil(tickInterval / MINUTE);
  10576. for (var i = 0; i <= dMinus + minutes; i = i + minutes) {
  10577. ticks.push(min + i * MINUTE);
  10578. }
  10579. }
  10580. else {
  10581. // 小于分钟
  10582. var interval = tickInterval;
  10583. if (interval < SECOND) {
  10584. interval = SECOND;
  10585. }
  10586. var minSecond = Math.floor(min / SECOND) * SECOND;
  10587. var dSeconds = Math.ceil((max - min) / SECOND);
  10588. var seconds = Math.ceil(interval / SECOND);
  10589. for (var i = 0; i < dSeconds + seconds; i = i + seconds) {
  10590. ticks.push(minSecond + i * SECOND);
  10591. }
  10592. }
  10593. // 最好是能从算法能解决这个问题,但是如果指定了 tickInterval,计算 ticks,也只能这么算,所以
  10594. // 打印警告提示
  10595. if (ticks.length >= 512) {
  10596. 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!");
  10597. }
  10598. return ticks;
  10599. }
  10600. registerTickMethod('cat', calculateCatTicks);
  10601. registerTickMethod('time-cat', timeCat);
  10602. registerTickMethod('wilkinson-extended', linear$2);
  10603. registerTickMethod('r-pretty', linearPretty);
  10604. registerTickMethod('time', calculateTimeTicks);
  10605. registerTickMethod('time-pretty', timePretty);
  10606. registerTickMethod('log', calculateLogTicks);
  10607. registerTickMethod('pow', calculatePowTicks);
  10608. registerTickMethod('quantile', calculateTicks);
  10609. registerTickMethod('d3-linear', d3LinearTickMethod);
  10610. registerClass('cat', Category);
  10611. registerClass('category', Category);
  10612. registerClass('identity', Identity);
  10613. registerClass('linear', Linear);
  10614. registerClass('log', Log);
  10615. registerClass('pow', Pow);
  10616. registerClass('time', Time);
  10617. registerClass('timeCat', TimeCat);
  10618. registerClass('quantize', Quantize);
  10619. registerClass('quantile', Quantile);
  10620. // cat平均算法,保头保尾
  10621. var CatTick = (function (cfg) {
  10622. var values = cfg.values,
  10623. tickCount = cfg.tickCount;
  10624. if (!tickCount) {
  10625. return values;
  10626. }
  10627. if (values.length <= 1) {
  10628. return values;
  10629. } // 获取间隔步长, 最小是1
  10630. var step = Math.floor(values.length / (tickCount - 1)) || 1;
  10631. var ticks = []; // 按间隔数取对应节点
  10632. for (var index = 0; index < values.length; index = index + step) {
  10633. ticks.push(values[index]);
  10634. }
  10635. var last = values[values.length - 1]; // 如果最后一个tick不等于原数据的最后一个
  10636. if (ticks[ticks.length - 1] !== last) {
  10637. if (ticks.length >= tickCount) {
  10638. // 如果当前的tick个数满足要求
  10639. ticks[ticks.length - 1] = last;
  10640. } else {
  10641. // 不满足tickCount则直接加入最后一个
  10642. ticks.push(last);
  10643. }
  10644. }
  10645. return ticks;
  10646. });
  10647. // 认为是nice的刻度
  10648. var SNAP_COUNT_ARRAY = [1, 1.2, 1.5, 2, 2.2, 2.4, 2.5, 3, 4, 5, 6, 7.5, 8, 10];
  10649. var DEFAULT_COUNT$1 = 5; // 默认刻度值
  10650. var LinearTick = (function (cfg) {
  10651. var _ref = cfg || {},
  10652. tickCount = _ref.tickCount,
  10653. tickInterval = _ref.tickInterval;
  10654. var _ref2 = cfg || {},
  10655. min = _ref2.min,
  10656. max = _ref2.max;
  10657. min = isNaN(min) ? 0 : min;
  10658. max = isNaN(max) ? 0 : max;
  10659. var count = tickCount && tickCount >= 2 ? tickCount : DEFAULT_COUNT$1; // 计算interval, 优先取tickInterval
  10660. var interval = tickInterval || getBestInterval({
  10661. tickCount: count,
  10662. max: max,
  10663. min: min
  10664. }); // 通过interval计算最小tick
  10665. var minTick = Math.floor(min / interval) * interval; // 如果指定了tickInterval, count 需要根据指定的tickInterval来算计
  10666. if (tickInterval) {
  10667. var intervalCount = Math.abs(Math.ceil((max - minTick) / tickInterval)) + 1; // tickCount 作为最小 count 处理
  10668. count = Math.max(count, intervalCount);
  10669. }
  10670. var ticks = [];
  10671. var tickLength = 0;
  10672. var fixedLength = getFixedLength(interval);
  10673. while (tickLength < count) {
  10674. ticks.push(toFixed(minTick + tickLength * interval, fixedLength));
  10675. tickLength++;
  10676. }
  10677. return ticks;
  10678. });
  10679. var DECIMAL_LENGTH = 12;
  10680. function getFactor(number) {
  10681. // 取正数
  10682. number = Math.abs(number);
  10683. var factor = 1;
  10684. if (number === 0) {
  10685. return factor;
  10686. } // 小于1,逐渐放大
  10687. if (number < 1) {
  10688. var count = 0;
  10689. while (number < 1) {
  10690. factor = factor / 10;
  10691. number = number * 10;
  10692. count++;
  10693. } // 浮点数计算出现问题
  10694. if (factor.toString().length > DECIMAL_LENGTH) {
  10695. factor = parseFloat(factor.toFixed(count));
  10696. }
  10697. return factor;
  10698. } // 大于10逐渐缩小
  10699. while (number > 10) {
  10700. factor = factor * 10;
  10701. number = number / 10;
  10702. }
  10703. return factor;
  10704. } // 获取最佳匹配刻度
  10705. function getBestInterval(_ref3) {
  10706. var tickCount = _ref3.tickCount,
  10707. min = _ref3.min,
  10708. max = _ref3.max;
  10709. // 如果最大最小相等,则直接按1处理
  10710. if (min === max) {
  10711. return 1 * getFactor(max);
  10712. } // 1.计算平均刻度间隔
  10713. var avgInterval = (max - min) / (tickCount - 1); // 2.数据标准归一化 映射到[1-10]区间
  10714. var factor = getFactor(avgInterval);
  10715. var calInterval = avgInterval / factor;
  10716. var calMax = max / factor;
  10717. var calMin = min / factor; // 根据平均值推算最逼近刻度值
  10718. var similarityIndex = 0;
  10719. for (var index = 0; index < SNAP_COUNT_ARRAY.length; index++) {
  10720. var item = SNAP_COUNT_ARRAY[index];
  10721. if (calInterval <= item) {
  10722. similarityIndex = index;
  10723. break;
  10724. }
  10725. }
  10726. var similarityInterval = getInterval(similarityIndex, tickCount, calMin, calMax); // 小数点位数还原到数据的位数, 因为similarityIndex有可能是小数,所以需要保留similarityIndex自己的小数位数
  10727. var fixedLength = getFixedLength(similarityInterval) + getFixedLength(factor);
  10728. return toFixed(similarityInterval * factor, fixedLength);
  10729. }
  10730. function getInterval(startIndex, tickCount, min, max) {
  10731. var verify = false;
  10732. var interval = SNAP_COUNT_ARRAY[startIndex]; // 刻度值校验,如果不满足,循环下去
  10733. for (var i = startIndex; i < SNAP_COUNT_ARRAY.length; i++) {
  10734. if (intervalIsVerify({
  10735. interval: SNAP_COUNT_ARRAY[i],
  10736. tickCount: tickCount,
  10737. max: max,
  10738. min: min
  10739. })) {
  10740. // 有符合条件的interval
  10741. interval = SNAP_COUNT_ARRAY[i];
  10742. verify = true;
  10743. break;
  10744. }
  10745. } // 如果不满足, 依次缩小10倍,再计算
  10746. if (!verify) {
  10747. return 10 * getInterval(0, tickCount, min / 10, max / 10);
  10748. }
  10749. return interval;
  10750. } // 刻度是否满足展示需求
  10751. function intervalIsVerify(_ref4) {
  10752. var interval = _ref4.interval,
  10753. tickCount = _ref4.tickCount,
  10754. max = _ref4.max,
  10755. min = _ref4.min;
  10756. var minTick = Math.floor(min / interval) * interval;
  10757. if (minTick + (tickCount - 1) * interval >= max) {
  10758. return true;
  10759. }
  10760. return false;
  10761. } // 计算小数点应该保留的位数
  10762. function getFixedLength(num) {
  10763. var str = num.toString();
  10764. var index = str.indexOf('.');
  10765. var indexOfExp = str.indexOf('e-');
  10766. var length = indexOfExp >= 0 ? parseInt(str.substr(indexOfExp + 2), 10) : str.substr(index + 1).length;
  10767. if (length > 20) {
  10768. // 最多保留20位小数
  10769. length = 20;
  10770. }
  10771. return length;
  10772. } // @antv/util fixedbase不支持科学计数法的判断,需要提mr
  10773. function toFixed(v, length) {
  10774. return parseFloat(v.toFixed(length));
  10775. }
  10776. registerTickMethod('cat', CatTick);
  10777. registerTickMethod('time-cat', CatTick); // 覆盖linear 度量的tick算法
  10778. registerTickMethod('wilkinson-extended', LinearTick);
  10779. var ScaleController = /*#__PURE__*/function () {
  10780. function ScaleController(data) {
  10781. _classCallCheck(this, ScaleController);
  10782. this.data = data;
  10783. this.options = {};
  10784. this.scales = {};
  10785. }
  10786. _createClass(ScaleController, [{
  10787. key: "_getType",
  10788. value: function _getType(option) {
  10789. var type = option.type,
  10790. values = option.values,
  10791. field = option.field;
  10792. if (type) {
  10793. return type;
  10794. }
  10795. if (isNumber(field) || isNil(values[0]) && field) {
  10796. return 'identity';
  10797. }
  10798. if (typeof values[0] === 'number') {
  10799. return 'linear';
  10800. }
  10801. return 'cat';
  10802. }
  10803. }, {
  10804. key: "_getOption",
  10805. value: function _getOption(option) {
  10806. var values = option.values,
  10807. field = option.field,
  10808. justifyContent = option.justifyContent;
  10809. var type = this._getType(option);
  10810. option.type = type; // identity
  10811. if (type === 'identity') {
  10812. option.field = field.toString();
  10813. option.values = [field];
  10814. return option;
  10815. } // linear 类型
  10816. if (type === 'linear') {
  10817. // 设置默认nice
  10818. if (typeof option.nice !== 'boolean') {
  10819. option.nice = true;
  10820. } // 重置最大最小
  10821. var _getRange = getRange(values),
  10822. min = _getRange.min,
  10823. max = _getRange.max;
  10824. if (isNil(option.min)) {
  10825. option.min = min;
  10826. }
  10827. if (isNil(option.max)) {
  10828. option.max = max;
  10829. }
  10830. option.values = values.sort(function (a, b) {
  10831. return a - b;
  10832. });
  10833. return option;
  10834. } // 分类类型和 timeCat 类型,调整 range
  10835. if (type === 'cat' || type === 'timeCat') {
  10836. if (option.range) {
  10837. return option;
  10838. }
  10839. var count = values.length;
  10840. var range = [0, 1]; // 如果只有一项,显示在中间
  10841. if (count === 1) {
  10842. range = [0.5, 1];
  10843. } else if (justifyContent) {
  10844. // 居中
  10845. var offset = 1 / count * 0.5;
  10846. range = [offset, 1 - offset];
  10847. } else {
  10848. // 最后留 1 / count
  10849. var _offset = 1 / count;
  10850. range = [0, 1 - _offset];
  10851. }
  10852. option.range = range;
  10853. }
  10854. return option;
  10855. }
  10856. }, {
  10857. key: "createScale",
  10858. value: function createScale(option) {
  10859. var type = option.type;
  10860. if (isFunction(type)) {
  10861. return new type(option);
  10862. }
  10863. var ScaleClass = getClass(type);
  10864. return new ScaleClass(option);
  10865. } // 更新或创建scale
  10866. }, {
  10867. key: "setScale",
  10868. value: function setScale(field, option) {
  10869. var options = this.options,
  10870. scales = this.scales;
  10871. options[field] = mix({}, options[field], option); // 如果scale有更新,scale 也需要重新创建
  10872. if (scales[field]) {
  10873. delete scales[field];
  10874. }
  10875. }
  10876. }, {
  10877. key: "create",
  10878. value: function create(options) {
  10879. this.update(options);
  10880. }
  10881. }, {
  10882. key: "update",
  10883. value: function update(options) {
  10884. var _this = this;
  10885. if (!options) return;
  10886. each(options, function (option, field) {
  10887. _this.setScale(field, option);
  10888. }); // 为了让外部感知到scale有变化
  10889. this.scales = _objectSpread({}, this.scales);
  10890. }
  10891. }, {
  10892. key: "changeData",
  10893. value: function changeData(data) {
  10894. this.data = data;
  10895. this.scales = {};
  10896. }
  10897. }, {
  10898. key: "getData",
  10899. value: function getData() {
  10900. return this.data;
  10901. }
  10902. }, {
  10903. key: "getScale",
  10904. value: function getScale(field) {
  10905. var scales = this.scales,
  10906. options = this.options,
  10907. data = this.data;
  10908. var scale = scales[field];
  10909. if (scale) {
  10910. return scale;
  10911. }
  10912. var option = options[field];
  10913. if (!option) {
  10914. return null;
  10915. }
  10916. var values = option.values ? option.values : data ? valuesOfKey(data, field) : [];
  10917. var scaleOption = this._getOption(_objectSpread(_objectSpread({}, option), {}, {
  10918. field: field,
  10919. values: values
  10920. }));
  10921. var newScale = this.createScale(scaleOption);
  10922. scales[field] = newScale;
  10923. return newScale;
  10924. }
  10925. }, {
  10926. key: "getScales",
  10927. value: function getScales() {
  10928. var _this2 = this;
  10929. var options = this.options,
  10930. scales = this.scales;
  10931. each(options, function (option, field) {
  10932. _this2.getScale(field);
  10933. });
  10934. return scales;
  10935. }
  10936. }, {
  10937. key: "adjustStartZero",
  10938. value: function adjustStartZero(scale) {
  10939. var options = this.options;
  10940. var field = scale.field,
  10941. min = scale.min,
  10942. max = scale.max;
  10943. var option = options[field]; // 如果有定义,则不处理
  10944. if (option && option.min) {
  10945. return;
  10946. }
  10947. if (min > 0) {
  10948. scale.change({
  10949. min: 0
  10950. });
  10951. } else if (max < 0) {
  10952. scale.change({
  10953. max: 0
  10954. });
  10955. }
  10956. } // 饼图下的scale调整
  10957. }, {
  10958. key: "adjustPieScale",
  10959. value: function adjustPieScale(scale) {
  10960. var options = this.options;
  10961. var field = scale.field;
  10962. var option = options[field];
  10963. if (option && !isNil(option.nice)) {
  10964. return null;
  10965. }
  10966. scale.change({
  10967. nice: false
  10968. });
  10969. } // 获取scale 在 0点对位置的值
  10970. }, {
  10971. key: "getZeroValue",
  10972. value: function getZeroValue(scale) {
  10973. var min = scale.min,
  10974. max = scale.max;
  10975. var value;
  10976. if (min >= 0) {
  10977. value = min;
  10978. } else if (max <= 0) {
  10979. value = max;
  10980. } else {
  10981. value = 0;
  10982. }
  10983. return scale.scale(value);
  10984. }
  10985. }]);
  10986. return ScaleController;
  10987. }();
  10988. var Chart = /*#__PURE__*/function (_Component) {
  10989. _inherits(Chart, _Component);
  10990. var _super = _createSuper(Chart);
  10991. function Chart(props, context, updater) {
  10992. var _this;
  10993. _classCallCheck(this, Chart);
  10994. _this = _super.call(this, props, context, updater);
  10995. _this.componentsPosition = [];
  10996. var data = props.data,
  10997. coordOption = props.coord,
  10998. _props$scale = props.scale,
  10999. scale = _props$scale === void 0 ? [] : _props$scale;
  11000. _this.layoutController = new LayoutController();
  11001. _this.coordController = new coordController();
  11002. _this.scaleController = new ScaleController(data);
  11003. _this.scale = _this.scaleController;
  11004. var _assertThisInitialize = _assertThisInitialized(_this),
  11005. layoutController = _assertThisInitialize.layoutController,
  11006. coordController$1 = _assertThisInitialize.coordController,
  11007. scaleController = _assertThisInitialize.scaleController; // 布局
  11008. var style = _this.getStyle(props, context);
  11009. _this.layout = layoutController.create(style); // 坐标系
  11010. _this.coord = coordController$1.create(coordOption, _this.layout); // scale
  11011. scaleController.create(scale);
  11012. _this.data = data; // state
  11013. _this.state = {
  11014. filters: {}
  11015. };
  11016. return _this;
  11017. } // props 更新
  11018. _createClass(Chart, [{
  11019. key: "willReceiveProps",
  11020. value: function willReceiveProps(nextProps, context) {
  11021. var layoutController = this.layoutController,
  11022. coordController = this.coordController,
  11023. scaleController = this.scaleController,
  11024. lastProps = this.props;
  11025. var nextStyle = nextProps.style,
  11026. nextData = nextProps.data,
  11027. nextScale = nextProps.scale;
  11028. var lastStyle = lastProps.style,
  11029. lastData = lastProps.data,
  11030. lastScale = lastProps.scale; // 布局
  11031. if (!equal(nextStyle, lastStyle) || context !== this.context) {
  11032. var style = this.getStyle(nextProps, context);
  11033. this.layout = layoutController.create(style);
  11034. coordController.updateLayout(this.layout);
  11035. }
  11036. if (nextData !== lastData) {
  11037. scaleController.changeData(nextData);
  11038. } // scale
  11039. if (!equal(nextScale, lastScale)) {
  11040. scaleController.update(nextScale);
  11041. }
  11042. }
  11043. }, {
  11044. key: "willUpdate",
  11045. value: function willUpdate() {
  11046. var coordController = this.coordController,
  11047. props = this.props; // render 时要重置 coord 范围,重置后需要让所有子组件都重新render
  11048. // 所以这里不比较是否有差异,每次都新建,让所有子组件重新render
  11049. this.coord = coordController.create(props.coord, this.layout);
  11050. }
  11051. }, {
  11052. key: "getStyle",
  11053. value: function getStyle(props, context) {
  11054. var theme = context.theme,
  11055. px2hd = context.px2hd,
  11056. left = context.left,
  11057. top = context.top,
  11058. width = context.width,
  11059. height = context.height;
  11060. var style = props.style;
  11061. return px2hd(_objectSpread(_objectSpread({
  11062. left: left,
  11063. top: top,
  11064. width: width,
  11065. height: height
  11066. }, theme.chart), style));
  11067. } // 给需要显示的组件留空
  11068. }, {
  11069. key: "layoutCoord",
  11070. value: function layoutCoord(layout) {
  11071. var coord = this.coord;
  11072. var position = layout.position,
  11073. boxWidth = layout.width,
  11074. boxHeight = layout.height;
  11075. var left = coord.left,
  11076. top = coord.top,
  11077. width = coord.width,
  11078. height = coord.height;
  11079. switch (position) {
  11080. case 'left':
  11081. left += boxWidth;
  11082. width = Math.max(0, width - boxWidth);
  11083. break;
  11084. case 'right':
  11085. width = Math.max(0, width - boxWidth);
  11086. break;
  11087. case 'top':
  11088. top += boxHeight;
  11089. height = Math.max(0, height - boxHeight);
  11090. break;
  11091. case 'bottom':
  11092. height = Math.max(0, height - boxHeight);
  11093. break;
  11094. }
  11095. coord.update({
  11096. left: left,
  11097. top: top,
  11098. width: width,
  11099. height: height
  11100. });
  11101. }
  11102. }, {
  11103. key: "resetCoordLayout",
  11104. value: function resetCoordLayout() {
  11105. var coord = this.coord,
  11106. layout = this.layout;
  11107. coord.update(layout);
  11108. }
  11109. }, {
  11110. key: "updateCoordLayout",
  11111. value: function updateCoordLayout(layout) {
  11112. var _this2 = this;
  11113. if (isArray(layout)) {
  11114. layout.forEach(function (item) {
  11115. _this2.layoutCoord(item);
  11116. });
  11117. return;
  11118. }
  11119. this.layoutCoord(layout);
  11120. }
  11121. }, {
  11122. key: "updateCoordFor",
  11123. value: function updateCoordFor(component, layout) {
  11124. var _this3 = this;
  11125. if (!layout) return;
  11126. var componentsPosition = this.componentsPosition;
  11127. var componentPosition = {
  11128. component: component,
  11129. layout: layout
  11130. };
  11131. var existIndex = findIndex(componentsPosition, function (item) {
  11132. return item.component === component;
  11133. }); // 说明是已经存在的组件
  11134. if (existIndex > -1) {
  11135. componentsPosition.splice(existIndex, 1, componentPosition); // 先重置,然后整体重新算一次
  11136. this.resetCoordLayout();
  11137. componentsPosition.forEach(function (componentPosition) {
  11138. var layout = componentPosition.layout;
  11139. _this3.updateCoordLayout(layout);
  11140. });
  11141. return;
  11142. } // 是新组件,直接添加
  11143. componentsPosition.push(componentPosition);
  11144. this.updateCoordLayout(layout);
  11145. }
  11146. }, {
  11147. key: "getGeometrys",
  11148. value: function getGeometrys() {
  11149. var children = this.children;
  11150. var geometrys = []; // @ts-ignore
  11151. Children.toArray(children).forEach(function (element) {
  11152. if (!element) return false;
  11153. var component = element.component;
  11154. if (component && component.isGeometry) {
  11155. geometrys.push(component);
  11156. }
  11157. });
  11158. return geometrys;
  11159. }
  11160. /**
  11161. * calculate dataset's position on canvas
  11162. * @param {Object} record the dataset
  11163. * @return {Object} return the position
  11164. */
  11165. }, {
  11166. key: "getPosition",
  11167. value: function getPosition(record) {
  11168. var coord = this.getCoord();
  11169. var xScale = this.getXScales()[0];
  11170. var xField = xScale.field;
  11171. var yScales = this.getYScales(); // default first
  11172. var yScale = yScales[0];
  11173. var yField = yScale.field;
  11174. for (var i = 0, len = yScales.length; i < len; i++) {
  11175. var scale = yScales[i];
  11176. var field = scale.field;
  11177. if (record[field]) {
  11178. yScale = scale;
  11179. yField = field;
  11180. break;
  11181. }
  11182. }
  11183. var x = xScale.scale(record[xField]);
  11184. var y = yScale.scale(record[yField]);
  11185. return coord.convertPoint({
  11186. x: x,
  11187. y: y
  11188. });
  11189. }
  11190. }, {
  11191. key: "getSnapRecords",
  11192. value: function getSnapRecords(point, inCoordRange) {
  11193. var geometrys = this.getGeometrys();
  11194. if (!geometrys.length) return; // @ts-ignore
  11195. return geometrys[0].getSnapRecords(point, inCoordRange);
  11196. }
  11197. }, {
  11198. key: "getLegendItems",
  11199. value: function getLegendItems(point) {
  11200. var geometrys = this.getGeometrys();
  11201. if (!geometrys.length) return; // @ts-ignore
  11202. return geometrys[0].getLegendItems(point);
  11203. }
  11204. }, {
  11205. key: "setScale",
  11206. value: function setScale(field, option) {
  11207. this.scaleController.setScale(field, option);
  11208. }
  11209. }, {
  11210. key: "getScale",
  11211. value: function getScale(field) {
  11212. return this.scaleController.getScale(field);
  11213. }
  11214. }, {
  11215. key: "getScales",
  11216. value: function getScales() {
  11217. return this.scaleController.getScales();
  11218. }
  11219. }, {
  11220. key: "getXScales",
  11221. value: function getXScales() {
  11222. var geometrys = this.getGeometrys();
  11223. return geometrys.map(function (component) {
  11224. // @ts-ignore
  11225. return component.getXScale();
  11226. });
  11227. }
  11228. }, {
  11229. key: "getYScales",
  11230. value: function getYScales() {
  11231. var geometrys = this.getGeometrys();
  11232. return geometrys.map(function (component) {
  11233. // @ts-ignore
  11234. return component.getYScale();
  11235. });
  11236. }
  11237. }, {
  11238. key: "getCoord",
  11239. value: function getCoord() {
  11240. return this.coord;
  11241. }
  11242. }, {
  11243. key: "filter",
  11244. value: function filter(field, condition) {
  11245. var filters = this.state.filters;
  11246. this.setState({
  11247. filters: _objectSpread(_objectSpread({}, filters), {}, _defineProperty({}, field, condition))
  11248. });
  11249. }
  11250. }, {
  11251. key: "_getRenderData",
  11252. value: function _getRenderData() {
  11253. var props = this.props,
  11254. state = this.state;
  11255. var data = props.data;
  11256. var filters = state.filters;
  11257. if (!filters || !Object.keys(filters).length) {
  11258. return data;
  11259. }
  11260. var filteredData = data;
  11261. each(filters, function (condition, field) {
  11262. if (!condition) return;
  11263. filteredData = filteredData.filter(function (record) {
  11264. return condition(record[field], record);
  11265. });
  11266. });
  11267. return filteredData;
  11268. }
  11269. }, {
  11270. key: "render",
  11271. value: function render() {
  11272. var _this4 = this;
  11273. var props = this.props,
  11274. layout = this.layout,
  11275. coord = this.coord;
  11276. var children = props.children,
  11277. originData = props.data;
  11278. if (!originData) return null;
  11279. var data = this._getRenderData();
  11280. return Children.map(children, function (child) {
  11281. return Children.cloneElement(child, {
  11282. chart: _this4,
  11283. coord: coord,
  11284. data: data,
  11285. layout: layout
  11286. });
  11287. });
  11288. }
  11289. }]);
  11290. return Chart;
  11291. }(Component);
  11292. function isEqual(origin1, origin2, fields) {
  11293. if (origin1 === origin2) {
  11294. return true;
  11295. }
  11296. for (var i = 0, len = fields.length; i < len; i++) {
  11297. var field = fields[i];
  11298. if (origin1[field] !== origin2[field]) {
  11299. return false;
  11300. }
  11301. }
  11302. return true;
  11303. }
  11304. var Selection = /*#__PURE__*/function (_Component) {
  11305. _inherits(Selection, _Component);
  11306. var _super = _createSuper(Selection);
  11307. function Selection(props, context) {
  11308. var _this;
  11309. _classCallCheck(this, Selection);
  11310. _this = _super.call(this, props, context);
  11311. var selection = props.selection;
  11312. if (!selection) return _possibleConstructorReturn(_this);
  11313. var defaultSelected = selection.defaultSelected;
  11314. _this.state.selected = defaultSelected;
  11315. return _this;
  11316. }
  11317. _createClass(Selection, [{
  11318. key: "didMount",
  11319. value: function didMount() {
  11320. var _this2 = this;
  11321. var props = this.props,
  11322. state = this.state,
  11323. container = this.container;
  11324. var canvas = container.get('canvas');
  11325. var selection = props.selection,
  11326. chart = props.chart;
  11327. if (!selection) return; // 默认为 click
  11328. var _selection$triggerOn = selection.triggerOn,
  11329. triggerOn = _selection$triggerOn === void 0 ? 'click' : _selection$triggerOn;
  11330. canvas.on(triggerOn, function (ev) {
  11331. var points = ev.points;
  11332. var records = _this2.getSnapRecords(points[0]);
  11333. var _selection$type = selection.type,
  11334. type = _selection$type === void 0 ? 'single' : _selection$type,
  11335. _selection$cancelable = selection.cancelable,
  11336. cancelable = _selection$cancelable === void 0 ? true : _selection$cancelable;
  11337. if (!records || !records.length) {
  11338. if (cancelable) {
  11339. _this2.setState({
  11340. selected: null
  11341. });
  11342. }
  11343. return;
  11344. }
  11345. var selected = state.selected;
  11346. var origins = records.map(function (record) {
  11347. return record.origin;
  11348. });
  11349. if (!selected || !selected.length) {
  11350. _this2.setState({
  11351. selected: origins
  11352. });
  11353. }
  11354. if (type === 'single') {
  11355. if (!cancelable) {
  11356. _this2.setState({
  11357. selected: origins
  11358. });
  11359. return;
  11360. }
  11361. var _newSelected = [];
  11362. records.forEach(function (record) {
  11363. if (!_this2.isSelected(record)) {
  11364. _newSelected.push(record.origin);
  11365. }
  11366. });
  11367. _this2.setState({
  11368. selected: _newSelected
  11369. });
  11370. return;
  11371. } // 多选
  11372. var scales = chart.getScales();
  11373. var fields = Object.keys(scales);
  11374. var selectedMap = {};
  11375. selected.forEach(function (item) {
  11376. var key = fields.map(function (field) {
  11377. return item[field];
  11378. }).join('-');
  11379. selectedMap[key] = item;
  11380. });
  11381. records.forEach(function (record) {
  11382. var origin = record.origin;
  11383. var key = fields.map(function (field) {
  11384. return origin[field];
  11385. }).join('-');
  11386. selectedMap[key] = selectedMap[key] ? null : origin;
  11387. });
  11388. var newSelected = Object.keys(selectedMap).map(function (key) {
  11389. return selectedMap[key];
  11390. }).filter(Boolean);
  11391. _this2.setState({
  11392. selected: newSelected
  11393. });
  11394. });
  11395. }
  11396. }, {
  11397. key: "willReceiveProps",
  11398. value: function willReceiveProps(nextProps) {
  11399. var nextSelection = nextProps.selection;
  11400. var lastSelection = this.props.selection;
  11401. if (!nextSelection || !lastSelection) {
  11402. return;
  11403. }
  11404. var nextDefaultSelected = nextSelection.defaultSelected;
  11405. var lastDefaultSelected = lastSelection.defaultSelected;
  11406. if (!equal(nextDefaultSelected, lastDefaultSelected)) {
  11407. this.state.selected = nextDefaultSelected;
  11408. }
  11409. }
  11410. }, {
  11411. key: "getSnapRecords",
  11412. value: function getSnapRecords(_point) {
  11413. return null;
  11414. }
  11415. }, {
  11416. key: "isSelected",
  11417. value: function isSelected(record) {
  11418. var state = this.state,
  11419. props = this.props;
  11420. var selected = state.selected;
  11421. if (!selected || !selected.length) {
  11422. return false;
  11423. }
  11424. var chart = props.chart;
  11425. var scales = chart.getScales();
  11426. var fields = Object.keys(scales);
  11427. for (var i = 0, len = selected.length; i < len; i++) {
  11428. var item = selected[i];
  11429. if (isEqual(record.origin, item, fields)) {
  11430. return true;
  11431. }
  11432. }
  11433. return false;
  11434. }
  11435. }, {
  11436. key: "getSelectionStyle",
  11437. value: function getSelectionStyle(record) {
  11438. var state = this.state,
  11439. props = this.props;
  11440. var selected = state.selected;
  11441. if (!selected || !selected.length) {
  11442. return null;
  11443. }
  11444. var selection = props.selection;
  11445. var selectedStyle = selection.selectedStyle,
  11446. unSelectedStyle = selection.unSelectedStyle;
  11447. var isSelected = this.isSelected(record);
  11448. if (isSelected) {
  11449. return isFunction(selectedStyle) ? selectedStyle(record) : selectedStyle;
  11450. }
  11451. return isFunction(unSelectedStyle) ? unSelectedStyle(record) : unSelectedStyle;
  11452. }
  11453. }]);
  11454. return Selection;
  11455. }(Component);
  11456. var DEFAULT_Y = 0; // 默认的 y 的值
  11457. // 偏移之后,间距
  11458. var MARGIN_RATIO = 1 / 2;
  11459. var DODGE_RATIO = 1 / 2;
  11460. // 散点分开之后,距离边界的距离
  11461. var GAP = 0.05;
  11462. var Adjust = /** @class */ (function () {
  11463. function Adjust(cfg) {
  11464. var xField = cfg.xField, yField = cfg.yField, _a = cfg.adjustNames, adjustNames = _a === void 0 ? ['x', 'y'] : _a, dimValuesMap = cfg.dimValuesMap;
  11465. this.adjustNames = adjustNames;
  11466. this.xField = xField;
  11467. this.yField = yField;
  11468. this.dimValuesMap = dimValuesMap;
  11469. }
  11470. /**
  11471. * 查看维度是否是 adjust 字段
  11472. * @param dim
  11473. */
  11474. Adjust.prototype.isAdjust = function (dim) {
  11475. return this.adjustNames.indexOf(dim) >= 0;
  11476. };
  11477. Adjust.prototype.getAdjustRange = function (dim, dimValue, values) {
  11478. var yField = this.yField;
  11479. var index = values.indexOf(dimValue);
  11480. var length = values.length;
  11481. var pre;
  11482. var next;
  11483. // 没有 y 字段,但是需要根据 y 调整
  11484. if (!yField && this.isAdjust('y')) {
  11485. pre = 0;
  11486. next = 1;
  11487. }
  11488. else if (length > 1) {
  11489. // 如果以其开头,则取之,否则取他前面一个
  11490. pre = values[index === 0 ? 0 : index - 1];
  11491. // 如果以其结尾,则取之,否则取他后面一个
  11492. next = values[index === length - 1 ? length - 1 : index + 1];
  11493. if (index !== 0) {
  11494. pre += (dimValue - pre) / 2;
  11495. }
  11496. else {
  11497. pre -= (next - dimValue) / 2;
  11498. }
  11499. if (index !== length - 1) {
  11500. next -= (next - dimValue) / 2;
  11501. }
  11502. else {
  11503. next += (dimValue - values[length - 2]) / 2;
  11504. }
  11505. }
  11506. else {
  11507. pre = dimValue === 0 ? 0 : dimValue - 0.5;
  11508. next = dimValue === 0 ? 1 : dimValue + 0.5;
  11509. }
  11510. return {
  11511. pre: pre,
  11512. next: next,
  11513. };
  11514. };
  11515. Adjust.prototype.adjustData = function (groupedDataArray, mergedData) {
  11516. var _this = this;
  11517. // 所有调整维度的值数组
  11518. var dimValuesMap = this.getDimValues(mergedData);
  11519. // 按照每一个分组来进行调整
  11520. each(groupedDataArray, function (dataArray, index) {
  11521. // 遍历所有数据集合
  11522. // 每个分组中,分别按照不同的 dim 进行调整
  11523. each(dimValuesMap, function (values, dim) {
  11524. // 根据不同的度量分别调整位置
  11525. _this.adjustDim(dim, values, dataArray, index);
  11526. });
  11527. });
  11528. };
  11529. /**
  11530. * 对数据进行分组adjustData
  11531. * @param data 数据
  11532. * @param dim 分组的字段
  11533. * @return 分组结果
  11534. */
  11535. Adjust.prototype.groupData = function (data, dim) {
  11536. // 补齐数据空数据为默认值
  11537. each(data, function (record) {
  11538. if (record[dim] === undefined) {
  11539. record[dim] = DEFAULT_Y;
  11540. }
  11541. });
  11542. // 按照 dim 维度分组
  11543. return groupBy(data, dim);
  11544. };
  11545. /** @override */
  11546. Adjust.prototype.adjustDim = function (dim, values, data, index) { };
  11547. /**
  11548. * 获取可调整度量对应的值
  11549. * @param mergedData 数据
  11550. * @return 值的映射
  11551. */
  11552. Adjust.prototype.getDimValues = function (mergedData) {
  11553. var _a = this, xField = _a.xField, yField = _a.yField;
  11554. var dimValuesMap = mix({}, this.dimValuesMap);
  11555. // 所有的维度
  11556. var dims = [];
  11557. if (xField && this.isAdjust('x')) {
  11558. dims.push(xField);
  11559. }
  11560. if (yField && this.isAdjust('y')) {
  11561. dims.push(yField);
  11562. }
  11563. dims.forEach(function (dim) {
  11564. if (dimValuesMap && dimValuesMap[dim]) {
  11565. return;
  11566. }
  11567. // 在每个维度上,所有的值
  11568. dimValuesMap[dim] = valuesOfKey(mergedData, dim).sort(function (v1, v2) { return v1 - v2; });
  11569. });
  11570. // 只有一维的情况下,同时调整 y,赋予默认值
  11571. if (!yField && this.isAdjust('y')) {
  11572. var dim = 'y';
  11573. dimValuesMap[dim] = [DEFAULT_Y, 1]; // 默认分布在 y 轴的 0 与 1 之间
  11574. }
  11575. return dimValuesMap;
  11576. };
  11577. return Adjust;
  11578. }());
  11579. var ADJUST_MAP = {};
  11580. /**
  11581. * 根据类型获取 Adjust 类
  11582. * @param type
  11583. */
  11584. var getAdjust = function (type) {
  11585. return ADJUST_MAP[type.toLowerCase()];
  11586. };
  11587. /**
  11588. * 注册自定义 Adjust
  11589. * @param type
  11590. * @param ctor
  11591. */
  11592. var registerAdjust = function (type, ctor) {
  11593. // 注册的时候,需要校验 type 重名,不区分大小写
  11594. if (getAdjust(type)) {
  11595. throw new Error("Adjust type '" + type + "' existed.");
  11596. }
  11597. // 存储到 map 中
  11598. ADJUST_MAP[type.toLowerCase()] = ctor;
  11599. };
  11600. /*! *****************************************************************************
  11601. Copyright (c) Microsoft Corporation.
  11602. Permission to use, copy, modify, and/or distribute this software for any
  11603. purpose with or without fee is hereby granted.
  11604. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
  11605. REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  11606. AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
  11607. INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11608. LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  11609. OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  11610. PERFORMANCE OF THIS SOFTWARE.
  11611. ***************************************************************************** */
  11612. /* global Reflect, Promise */
  11613. var _extendStatics = function extendStatics(d, b) {
  11614. _extendStatics = Object.setPrototypeOf || {
  11615. __proto__: []
  11616. } instanceof Array && function (d, b) {
  11617. d.__proto__ = b;
  11618. } || function (d, b) {
  11619. for (var p in b) {
  11620. if (b.hasOwnProperty(p)) d[p] = b[p];
  11621. }
  11622. };
  11623. return _extendStatics(d, b);
  11624. };
  11625. function __extends$1(d, b) {
  11626. _extendStatics(d, b);
  11627. function __() {
  11628. this.constructor = d;
  11629. }
  11630. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  11631. }
  11632. var _assign = function __assign() {
  11633. _assign = Object.assign || function __assign(t) {
  11634. for (var s, i = 1, n = arguments.length; i < n; i++) {
  11635. s = arguments[i];
  11636. for (var p in s) {
  11637. if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
  11638. }
  11639. }
  11640. return t;
  11641. };
  11642. return _assign.apply(this, arguments);
  11643. };
  11644. var Dodge = /** @class */ (function (_super) {
  11645. __extends$1(Dodge, _super);
  11646. function Dodge(cfg) {
  11647. var _this = _super.call(this, cfg) || this;
  11648. _this.cacheMap = {};
  11649. _this.adjustDataArray = [];
  11650. _this.mergeData = [];
  11651. 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;
  11652. _this.marginRatio = marginRatio;
  11653. _this.dodgeRatio = dodgeRatio;
  11654. _this.dodgeBy = dodgeBy;
  11655. _this.intervalPadding = intervalPadding;
  11656. _this.dodgePadding = dodgePadding;
  11657. _this.xDimensionLegenth = xDimensionLength;
  11658. _this.groupNum = groupNum;
  11659. _this.defaultSize = defaultSize;
  11660. _this.maxColumnWidth = maxColumnWidth;
  11661. _this.minColumnWidth = minColumnWidth;
  11662. _this.columnWidthRatio = columnWidthRatio;
  11663. _this.customOffset = customOffset;
  11664. return _this;
  11665. }
  11666. Dodge.prototype.process = function (groupDataArray) {
  11667. var groupedDataArray = clone(groupDataArray);
  11668. // 将数据数组展开一层
  11669. var mergeData = flatten(groupedDataArray);
  11670. var dodgeBy = this.dodgeBy;
  11671. // 如果指定了分组 dim 的字段
  11672. var adjustDataArray = dodgeBy ? group(mergeData, dodgeBy) : groupedDataArray;
  11673. this.cacheMap = {};
  11674. this.adjustDataArray = adjustDataArray;
  11675. this.mergeData = mergeData;
  11676. this.adjustData(adjustDataArray, mergeData);
  11677. this.adjustDataArray = [];
  11678. this.mergeData = [];
  11679. return groupedDataArray;
  11680. };
  11681. Dodge.prototype.adjustDim = function (dim, values, data, frameIndex) {
  11682. var _this = this;
  11683. var customOffset = this.customOffset;
  11684. var map = this.getDistribution(dim);
  11685. var groupData = this.groupData(data, dim); // 根据值分组
  11686. each(groupData, function (group, key) {
  11687. var range;
  11688. // xField 中只有一个值,不需要做 dodge
  11689. if (values.length === 1) {
  11690. range = {
  11691. pre: values[0] - 1,
  11692. next: values[0] + 1,
  11693. };
  11694. }
  11695. else {
  11696. // 如果有多个,则需要获取调整的范围
  11697. range = _this.getAdjustRange(dim, parseFloat(key), values);
  11698. }
  11699. each(group, function (d) {
  11700. var value = d[dim];
  11701. var valueArr = map[value];
  11702. var valIndex = valueArr.indexOf(frameIndex);
  11703. if (!isNil(customOffset)) {
  11704. var pre = range.pre, next = range.next;
  11705. d[dim] = isFunction(customOffset) ? customOffset(d, range) : (pre + next) / 2 + customOffset;
  11706. }
  11707. else {
  11708. d[dim] = _this.getDodgeOffset(range, valIndex, valueArr.length);
  11709. }
  11710. });
  11711. });
  11712. return [];
  11713. };
  11714. Dodge.prototype.getDodgeOffset = function (range, idx, len) {
  11715. var _a = this, dodgeRatio = _a.dodgeRatio, marginRatio = _a.marginRatio, intervalPadding = _a.intervalPadding, dodgePadding = _a.dodgePadding;
  11716. var pre = range.pre, next = range.next;
  11717. var tickLength = next - pre;
  11718. var position;
  11719. // 分多种输入情况
  11720. if (!isNil(intervalPadding) && isNil(dodgePadding) && intervalPadding >= 0) {
  11721. // 仅配置intervalPadding
  11722. var offset = this.getIntervalOnlyOffset(len, idx);
  11723. position = pre + offset;
  11724. }
  11725. else if (!isNil(dodgePadding) && isNil(intervalPadding) && dodgePadding >= 0) {
  11726. // 仅配置dodgePadding
  11727. var offset = this.getDodgeOnlyOffset(len, idx);
  11728. position = pre + offset;
  11729. }
  11730. else if (!isNil(intervalPadding) &&
  11731. !isNil(dodgePadding) &&
  11732. intervalPadding >= 0 &&
  11733. dodgePadding >= 0) {
  11734. // 同时配置intervalPadding和dodgePadding
  11735. var offset = this.getIntervalAndDodgeOffset(len, idx);
  11736. position = pre + offset;
  11737. }
  11738. else {
  11739. // 默认情况
  11740. var width = (tickLength * dodgeRatio) / len;
  11741. var margin = marginRatio * width;
  11742. var offset = (1 / 2) * (tickLength - len * width - (len - 1) * margin) +
  11743. ((idx + 1) * width + idx * margin) -
  11744. (1 / 2) * width -
  11745. (1 / 2) * tickLength;
  11746. position = (pre + next) / 2 + offset;
  11747. }
  11748. return position;
  11749. };
  11750. Dodge.prototype.getIntervalOnlyOffset = function (len, idx) {
  11751. 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;
  11752. var normalizedIntervalPadding = intervalPadding / xDimensionLegenth;
  11753. var normalizedDodgePadding = (1 - (groupNum - 1) * normalizedIntervalPadding) / groupNum * dodgeRatio / (len - 1);
  11754. var geomWidth = ((1 - normalizedIntervalPadding * (groupNum - 1)) / groupNum - normalizedDodgePadding * (len - 1)) / len;
  11755. // 根据columnWidthRatio/defaultSize/maxColumnWidth/minColumnWidth调整宽度
  11756. geomWidth = (!isNil(columnWidthRatio)) ? 1 / groupNum / len * columnWidthRatio : geomWidth;
  11757. if (!isNil(maxColumnWidth)) {
  11758. var normalizedMaxWidht = maxColumnWidth / xDimensionLegenth;
  11759. geomWidth = Math.min(geomWidth, normalizedMaxWidht);
  11760. }
  11761. if (!isNil(minColumnWidth)) {
  11762. var normalizedMinWidht = minColumnWidth / xDimensionLegenth;
  11763. geomWidth = Math.max(geomWidth, normalizedMinWidht);
  11764. }
  11765. geomWidth = defaultSize ? (defaultSize / xDimensionLegenth) : geomWidth;
  11766. // 调整组内间隔
  11767. normalizedDodgePadding = ((1 - (groupNum - 1) * normalizedIntervalPadding) / groupNum - len * geomWidth) / (len - 1);
  11768. var offset = ((1 / 2 + idx) * geomWidth + idx * normalizedDodgePadding +
  11769. (1 / 2) * normalizedIntervalPadding) * groupNum -
  11770. normalizedIntervalPadding / 2;
  11771. return offset;
  11772. };
  11773. Dodge.prototype.getDodgeOnlyOffset = function (len, idx) {
  11774. 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;
  11775. var normalizedDodgePadding = dodgePadding / xDimensionLegenth;
  11776. var normalizedIntervalPadding = 1 * marginRatio / (groupNum - 1);
  11777. var geomWidth = ((1 - normalizedIntervalPadding * (groupNum - 1)) / groupNum - normalizedDodgePadding * (len - 1)) / len;
  11778. // 根据columnWidthRatio/defaultSize/maxColumnWidth/minColumnWidth调整宽度
  11779. geomWidth = columnWidthRatio ? 1 / groupNum / len * columnWidthRatio : geomWidth;
  11780. if (!isNil(maxColumnWidth)) {
  11781. var normalizedMaxWidht = maxColumnWidth / xDimensionLegenth;
  11782. geomWidth = Math.min(geomWidth, normalizedMaxWidht);
  11783. }
  11784. if (!isNil(minColumnWidth)) {
  11785. var normalizedMinWidht = minColumnWidth / xDimensionLegenth;
  11786. geomWidth = Math.max(geomWidth, normalizedMinWidht);
  11787. }
  11788. geomWidth = defaultSize ? (defaultSize / xDimensionLegenth) : geomWidth;
  11789. // 调整组间距
  11790. normalizedIntervalPadding = (1 - (geomWidth * len + normalizedDodgePadding * (len - 1)) * groupNum) / (groupNum - 1);
  11791. var offset = ((1 / 2 + idx) * geomWidth + idx * normalizedDodgePadding +
  11792. (1 / 2) * normalizedIntervalPadding) * groupNum -
  11793. normalizedIntervalPadding / 2;
  11794. return offset;
  11795. };
  11796. Dodge.prototype.getIntervalAndDodgeOffset = function (len, idx) {
  11797. var _a = this, intervalPadding = _a.intervalPadding, dodgePadding = _a.dodgePadding, xDimensionLegenth = _a.xDimensionLegenth, groupNum = _a.groupNum;
  11798. var normalizedIntervalPadding = intervalPadding / xDimensionLegenth;
  11799. var normalizedDodgePadding = dodgePadding / xDimensionLegenth;
  11800. var geomWidth = ((1 - normalizedIntervalPadding * (groupNum - 1)) / groupNum - normalizedDodgePadding * (len - 1)) / len;
  11801. var offset = ((1 / 2 + idx) * geomWidth + idx * normalizedDodgePadding +
  11802. (1 / 2) * normalizedIntervalPadding) * groupNum -
  11803. normalizedIntervalPadding / 2;
  11804. return offset;
  11805. };
  11806. Dodge.prototype.getDistribution = function (dim) {
  11807. var groupedDataArray = this.adjustDataArray;
  11808. var cacheMap = this.cacheMap;
  11809. var map = cacheMap[dim];
  11810. if (!map) {
  11811. map = {};
  11812. each(groupedDataArray, function (data, index) {
  11813. var values = valuesOfKey(data, dim);
  11814. if (!values.length) {
  11815. values.push(0);
  11816. }
  11817. each(values, function (val) {
  11818. if (!map[val]) {
  11819. map[val] = [];
  11820. }
  11821. map[val].push(index);
  11822. });
  11823. });
  11824. cacheMap[dim] = map;
  11825. }
  11826. return map;
  11827. };
  11828. return Dodge;
  11829. }(Adjust));
  11830. function randomNumber(min, max) {
  11831. return (max - min) * Math.random() + min;
  11832. }
  11833. var Jitter = /** @class */ (function (_super) {
  11834. __extends$1(Jitter, _super);
  11835. function Jitter() {
  11836. return _super !== null && _super.apply(this, arguments) || this;
  11837. }
  11838. Jitter.prototype.process = function (groupDataArray) {
  11839. var groupedDataArray = clone(groupDataArray);
  11840. // 之前分组之后的数据,然后有合并回去(和分组前可以理解成是一样的)
  11841. var mergeData = flatten(groupedDataArray);
  11842. // 返回值
  11843. this.adjustData(groupedDataArray, mergeData);
  11844. return groupedDataArray;
  11845. };
  11846. /**
  11847. * 当前数据分组(index)中,按照维度 dim 进行 jitter 调整
  11848. * @param dim
  11849. * @param values
  11850. * @param dataArray
  11851. */
  11852. Jitter.prototype.adjustDim = function (dim, values, dataArray) {
  11853. var _this = this;
  11854. // 在每一个分组中,将数据再按照 dim 分组,用于散列
  11855. var groupDataArray = this.groupData(dataArray, dim);
  11856. return each(groupDataArray, function (data, dimValue) {
  11857. return _this.adjustGroup(data, dim, parseFloat(dimValue), values);
  11858. });
  11859. };
  11860. // 随机出来的字段值
  11861. Jitter.prototype.getAdjustOffset = function (range) {
  11862. var pre = range.pre, next = range.next;
  11863. // 随机的范围
  11864. var margin = (next - pre) * GAP;
  11865. return randomNumber(pre + margin, next - margin);
  11866. };
  11867. // adjust group data
  11868. Jitter.prototype.adjustGroup = function (group, dim, dimValue, values) {
  11869. var _this = this;
  11870. // 调整范围
  11871. var range = this.getAdjustRange(dim, dimValue, values);
  11872. each(group, function (data) {
  11873. data[dim] = _this.getAdjustOffset(range); // 获取调整的位置
  11874. });
  11875. return group;
  11876. };
  11877. return Jitter;
  11878. }(Adjust));
  11879. var Cache = default_1;
  11880. var Stack = /** @class */ (function (_super) {
  11881. __extends$1(Stack, _super);
  11882. function Stack(cfg) {
  11883. var _this = _super.call(this, cfg) || this;
  11884. 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;
  11885. _this.adjustNames = adjustNames;
  11886. _this.height = height;
  11887. _this.size = size;
  11888. _this.reverseOrder = reverseOrder;
  11889. return _this;
  11890. }
  11891. /**
  11892. * 方法入参是经过数据分组、数据数字化之后的二维数组
  11893. * @param groupDataArray 分组之后的数据
  11894. */
  11895. Stack.prototype.process = function (groupDataArray) {
  11896. var _a = this, yField = _a.yField, reverseOrder = _a.reverseOrder;
  11897. // 如果有指定 y 字段,那么按照 y 字段来 stack
  11898. // 否则,按照高度均分
  11899. var d = yField ? this.processStack(groupDataArray) : this.processOneDimStack(groupDataArray);
  11900. return reverseOrder ? this.reverse(d) : d;
  11901. };
  11902. Stack.prototype.reverse = function (groupedDataArray) {
  11903. return groupedDataArray.slice(0).reverse();
  11904. };
  11905. Stack.prototype.processStack = function (groupDataArray) {
  11906. var _a = this, xField = _a.xField, yField = _a.yField, reverseOrder = _a.reverseOrder;
  11907. // 层叠顺序翻转
  11908. var groupedDataArray = reverseOrder ? this.reverse(groupDataArray) : groupDataArray;
  11909. // 用来缓存,正数和负数的堆叠问题
  11910. var positive = new Cache();
  11911. var negative = new Cache();
  11912. return groupedDataArray.map(function (dataArray) {
  11913. return dataArray.map(function (data) {
  11914. var _a;
  11915. var x = get(data, xField, 0);
  11916. var y = get(data, [yField]);
  11917. var xKey = x.toString();
  11918. // todo 是否应该取 _origin?因为 y 可能取到的值不正确,比如先 symmetric,再 stack!
  11919. y = isArray(y) ? y[1] : y;
  11920. if (!isNil(y)) {
  11921. var cache = y >= 0 ? positive : negative;
  11922. if (!cache.has(xKey)) {
  11923. cache.set(xKey, 0);
  11924. }
  11925. var xValue = cache.get(xKey);
  11926. var newXValue = y + xValue;
  11927. // 存起来
  11928. cache.set(xKey, newXValue);
  11929. return _assign(_assign({}, data), (_a = {}, _a[yField] = [xValue, newXValue], _a));
  11930. }
  11931. // 没有修改,则直接返回
  11932. return data;
  11933. });
  11934. });
  11935. };
  11936. Stack.prototype.processOneDimStack = function (groupDataArray) {
  11937. var _this = this;
  11938. var _a = this, xField = _a.xField, height = _a.height, reverseOrder = _a.reverseOrder;
  11939. var yField = 'y';
  11940. // 如果层叠的顺序翻转
  11941. var groupedDataArray = reverseOrder ? this.reverse(groupDataArray) : groupDataArray;
  11942. // 缓存累加数据
  11943. var cache = new Cache();
  11944. return groupedDataArray.map(function (dataArray) {
  11945. return dataArray.map(function (data) {
  11946. var _a;
  11947. var size = _this.size;
  11948. var xValue = data[xField];
  11949. // todo 没有看到这个 stack 计算原理
  11950. var stackHeight = (size * 2) / height;
  11951. if (!cache.has(xValue)) {
  11952. cache.set(xValue, stackHeight / 2); // 初始值大小
  11953. }
  11954. var stackValue = cache.get(xValue);
  11955. // 增加一层 stackHeight
  11956. cache.set(xValue, stackValue + stackHeight);
  11957. return _assign(_assign({}, data), (_a = {}, _a[yField] = stackValue, _a));
  11958. });
  11959. });
  11960. };
  11961. return Stack;
  11962. }(Adjust));
  11963. var Symmetric = /** @class */ (function (_super) {
  11964. __extends$1(Symmetric, _super);
  11965. function Symmetric() {
  11966. return _super !== null && _super.apply(this, arguments) || this;
  11967. }
  11968. Symmetric.prototype.process = function (groupDataArray) {
  11969. var mergeData = flatten(groupDataArray);
  11970. var _a = this, xField = _a.xField, yField = _a.yField;
  11971. // 每个 x 值对应的 最大值
  11972. var cache = this.getXValuesMaxMap(mergeData);
  11973. // 所有数据的最大的值
  11974. var max = Math.max.apply(Math, Object.keys(cache).map(function (key) { return cache[key]; }));
  11975. return map(groupDataArray, function (dataArray) {
  11976. return map(dataArray, function (data) {
  11977. var _a, _b;
  11978. var yValue = data[yField];
  11979. var xValue = data[xField];
  11980. // 数组处理逻辑
  11981. if (isArray(yValue)) {
  11982. var off_1 = (max - cache[xValue]) / 2;
  11983. return _assign(_assign({}, data), (_a = {}, _a[yField] = map(yValue, function (y) { return off_1 + y; }), _a));
  11984. }
  11985. // 非数组处理逻辑
  11986. var offset = (max - yValue) / 2;
  11987. return _assign(_assign({}, data), (_b = {}, _b[yField] = [offset, yValue + offset], _b));
  11988. });
  11989. });
  11990. };
  11991. // 获取每个 x 对应的最大的值
  11992. Symmetric.prototype.getXValuesMaxMap = function (mergeData) {
  11993. var _this = this;
  11994. var _a = this, xField = _a.xField, yField = _a.yField;
  11995. // 根据 xField 的值进行分组
  11996. var groupDataArray = groupBy(mergeData, function (data) { return data[xField]; });
  11997. // 获取每个 xField 值中的最大值
  11998. return mapValues(groupDataArray, function (dataArray) { return _this.getDimMaxValue(dataArray, yField); });
  11999. };
  12000. Symmetric.prototype.getDimMaxValue = function (mergeData, dim) {
  12001. // 所有的 value 值
  12002. var dimValues = map(mergeData, function (data) { return get(data, dim, []); });
  12003. // 将数组打平(dim value 有可能是数组,比如 stack 之后的)
  12004. var flattenValues = flatten(dimValues);
  12005. // 求出数组的最大值
  12006. return Math.max.apply(Math, flattenValues);
  12007. };
  12008. return Symmetric;
  12009. }(Adjust));
  12010. // 注册内置的 adjust
  12011. registerAdjust('Dodge', Dodge);
  12012. registerAdjust('Jitter', Jitter);
  12013. registerAdjust('Stack', Stack);
  12014. registerAdjust('Symmetric', Symmetric);
  12015. var Base$1 = /*#__PURE__*/function () {
  12016. function Base(options) {
  12017. _classCallCheck(this, Base);
  12018. mix(this, options);
  12019. var scale = this.scale,
  12020. field = this.field,
  12021. data = this.data;
  12022. if (!scale && data) {
  12023. var values = valuesOfKey(data, field);
  12024. this.scale = this.createScale({
  12025. values: values,
  12026. field: field
  12027. });
  12028. }
  12029. }
  12030. _createClass(Base, [{
  12031. key: "createScale",
  12032. value: function createScale(_scaleConfig) {
  12033. return null;
  12034. } // 数据映射方法
  12035. }, {
  12036. key: "_mapping",
  12037. value: function _mapping(value) {
  12038. return value;
  12039. }
  12040. }, {
  12041. key: "update",
  12042. value: function update(options) {
  12043. mix(this, options);
  12044. }
  12045. }, {
  12046. key: "setRange",
  12047. value: function setRange(range) {
  12048. this.range = range;
  12049. } // 归一化,参数是原始数据,返回是归一化的数据
  12050. }, {
  12051. key: "normalize",
  12052. value: function normalize(value) {
  12053. var scale = this.scale;
  12054. if (isArray(value)) {
  12055. return value.map(function (v) {
  12056. return scale.scale(v);
  12057. });
  12058. }
  12059. return scale.scale(value);
  12060. } // convert 参数是归一化的数据,返回定义域的值
  12061. }, {
  12062. key: "convert",
  12063. value: function convert(value) {
  12064. return value;
  12065. } // 等于 normalize + convert, 参数是原始数据,返回是定义域的值
  12066. }, {
  12067. key: "mapping",
  12068. value: function mapping(value) {
  12069. var child = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
  12070. var rst = isFunction(this.callback) ? this.callback(value, child) : null;
  12071. if (!isNil(rst)) {
  12072. return rst;
  12073. }
  12074. return this._mapping(value);
  12075. }
  12076. }]);
  12077. return Base;
  12078. }();
  12079. var Linear$1 = /*#__PURE__*/function (_Base) {
  12080. _inherits(Linear$1, _Base);
  12081. var _super = _createSuper(Linear$1);
  12082. function Linear$1(options) {
  12083. var _this;
  12084. _classCallCheck(this, Linear$1);
  12085. _this = _super.call(this, options);
  12086. _this._updateInterpolate();
  12087. return _this;
  12088. }
  12089. _createClass(Linear$1, [{
  12090. key: "createScale",
  12091. value: function createScale(scaleConfig) {
  12092. return new Linear(scaleConfig);
  12093. }
  12094. }, {
  12095. key: "_updateInterpolate",
  12096. value: function _updateInterpolate() {
  12097. var _this$range = _slicedToArray(this.range, 2),
  12098. min = _this$range[0],
  12099. max = _this$range[1];
  12100. this.interpolate = interpolate(min, max);
  12101. }
  12102. }, {
  12103. key: "update",
  12104. value: function update(options) {
  12105. _get$1(_getPrototypeOf(Linear$1.prototype), "update", this).call(this, options);
  12106. this._updateInterpolate();
  12107. }
  12108. }, {
  12109. key: "_mapping",
  12110. value: function _mapping(value) {
  12111. var scale = this.scale,
  12112. interpolate = this.interpolate;
  12113. if (isArray(value)) {
  12114. return value.map(function (v) {
  12115. return interpolate(scale.scale(v));
  12116. });
  12117. }
  12118. return interpolate(scale.scale(value));
  12119. }
  12120. }, {
  12121. key: "normalize",
  12122. value: function normalize(value) {
  12123. var scale = this.scale;
  12124. if (isArray(value)) {
  12125. return value.map(function (v) {
  12126. return scale.scale(v);
  12127. });
  12128. }
  12129. return scale.scale(value);
  12130. }
  12131. }, {
  12132. key: "convert",
  12133. value: function convert(value) {
  12134. var range = this.range;
  12135. var _range = _slicedToArray(range, 2),
  12136. min = _range[0],
  12137. max = _range[1];
  12138. if (isArray(value)) {
  12139. return value.map(function (v) {
  12140. return min + (max - min) * v;
  12141. });
  12142. }
  12143. return min + (max - min) * value;
  12144. }
  12145. }]);
  12146. return Linear$1;
  12147. }(Base$1);
  12148. var Category$1 = /*#__PURE__*/function (_Base) {
  12149. _inherits(Category$1, _Base);
  12150. var _super = _createSuper(Category$1);
  12151. function Category$1() {
  12152. _classCallCheck(this, Category$1);
  12153. return _super.apply(this, arguments);
  12154. }
  12155. _createClass(Category$1, [{
  12156. key: "createScale",
  12157. value: function createScale(scaleConfig) {
  12158. return new Category(scaleConfig);
  12159. }
  12160. }, {
  12161. key: "_mapping",
  12162. value: function _mapping(value) {
  12163. var scale = this.scale,
  12164. range = this.range;
  12165. if (scale.type === 'cat') {
  12166. var _index = scale.translate(value);
  12167. return range[_index % range.length];
  12168. }
  12169. var normalizeValue = scale.scale(value);
  12170. var index = Math.round(normalizeValue * (range.length - 1));
  12171. return range[index];
  12172. }
  12173. }]);
  12174. return Category$1;
  12175. }(Base$1);
  12176. var Identity$1 = /*#__PURE__*/function (_Base) {
  12177. _inherits(Identity$1, _Base);
  12178. var _super = _createSuper(Identity$1);
  12179. function Identity$1() {
  12180. _classCallCheck(this, Identity$1);
  12181. return _super.apply(this, arguments);
  12182. }
  12183. _createClass(Identity$1, [{
  12184. key: "createScale",
  12185. value: function createScale(scaleConfig) {
  12186. return new Identity(scaleConfig);
  12187. }
  12188. }, {
  12189. key: "_mapping",
  12190. value: function _mapping() {
  12191. var field = this.field,
  12192. range = this.range;
  12193. return field || range && range[0];
  12194. }
  12195. }]);
  12196. return Identity$1;
  12197. }(Base$1);
  12198. var Attrs = /*#__PURE__*/Object.freeze({
  12199. __proto__: null,
  12200. Attr: Base$1,
  12201. Linear: Linear$1,
  12202. Category: Category$1,
  12203. Identity: Identity$1
  12204. });
  12205. var Identity$2 = Identity$1,
  12206. Linear$2 = Linear$1,
  12207. Category$2 = Category$1; // 需要映射的属性名
  12208. var ATTRS = ['x', 'y', 'color', 'size', 'shape']; // 分组处理的属性
  12209. var GROUP_ATTRS = ['color', 'size', 'shape'];
  12210. function cloneScale(scale, scaleConfig) {
  12211. // @ts-ignore
  12212. return new scale.constructor(_objectSpread(_objectSpread({}, scale.__cfg__), scaleConfig));
  12213. }
  12214. var AttrController = /*#__PURE__*/function () {
  12215. function AttrController(scaleController, attrsRange) {
  12216. _classCallCheck(this, AttrController);
  12217. this.scaleController = scaleController;
  12218. this.attrsRange = attrsRange;
  12219. this.options = {};
  12220. this.attrs = {};
  12221. }
  12222. _createClass(AttrController, [{
  12223. key: "parseOption",
  12224. value: function parseOption(option, attrName) {
  12225. if (!option) {
  12226. return {
  12227. type: 'identity'
  12228. };
  12229. }
  12230. if (isString(option)) {
  12231. return {
  12232. field: option,
  12233. type: 'category'
  12234. };
  12235. }
  12236. if (isNumber(option)) {
  12237. if (attrName === 'size') {
  12238. return {
  12239. type: 'identity',
  12240. field: option
  12241. };
  12242. }
  12243. }
  12244. if (isArray(option)) {
  12245. return {
  12246. field: option[0],
  12247. range: option[1]
  12248. };
  12249. }
  12250. return option;
  12251. }
  12252. }, {
  12253. key: "getAttrOptions",
  12254. value: function getAttrOptions(props, justifyContentCenter) {
  12255. var _this = this;
  12256. if (!props.x || !props.y) {
  12257. throw new Error('x, y are required !');
  12258. }
  12259. var options = {};
  12260. var ranges = this.attrsRange;
  12261. ATTRS.forEach(function (attrName) {
  12262. if (!props[attrName]) return;
  12263. var option = _this.parseOption(props[attrName], attrName);
  12264. if (!option.range) {
  12265. option.range = ranges[attrName];
  12266. }
  12267. options[attrName] = option;
  12268. }); // @ts-ignore
  12269. var x = options.x,
  12270. y = options.y;
  12271. x.justifyContent = justifyContentCenter; // x, y 都是固定Linear 映射
  12272. x.type = Linear$2;
  12273. y.type = Linear$2;
  12274. return options;
  12275. }
  12276. }, {
  12277. key: "getDefaultAttrValues",
  12278. value: function getDefaultAttrValues() {
  12279. var _this$attrsRange = this.attrsRange,
  12280. color = _this$attrsRange.color,
  12281. shape = _this$attrsRange.shape;
  12282. return {
  12283. color: color[0],
  12284. shape: shape && shape[0]
  12285. };
  12286. }
  12287. }, {
  12288. key: "getGroupScales",
  12289. value: function getGroupScales() {
  12290. var attrs = this.attrs;
  12291. var scales = [];
  12292. each(GROUP_ATTRS, function (attrName) {
  12293. var attr = attrs[attrName];
  12294. if (!attr) {
  12295. return;
  12296. }
  12297. var scale = attr.scale;
  12298. if (scale && scale.isCategory && scales.indexOf(scale) === -1) {
  12299. scales.push(scale);
  12300. }
  12301. });
  12302. return scales;
  12303. }
  12304. }, {
  12305. key: "createAttr",
  12306. value: function createAttr(option) {
  12307. var type = option.type,
  12308. field = option.field,
  12309. scaleConfig = option.scale;
  12310. if (isNil(field) || type === Identity$2) {
  12311. return new Identity$2(option);
  12312. }
  12313. var scale = this.scaleController.getScale(field);
  12314. var attrOption = _objectSpread(_objectSpread({}, option), {}, {
  12315. data: this.scaleController.getData(),
  12316. // scaleConfig 只在属性映射中生效
  12317. scale: scaleConfig ? cloneScale(scale, scaleConfig) : scale
  12318. }); // identity
  12319. if (scale && scale.type === 'identity') {
  12320. return new Identity$2(attrOption);
  12321. } // Attr的默认类型和scale类型保持一致
  12322. var AttrConstructor = scale.isLinear ? Linear$2 : Category$2; // custom Attr Constructor
  12323. if (isFunction(type)) {
  12324. AttrConstructor = type;
  12325. }
  12326. if (isString(type) && Attrs[upperFirst(type)]) {
  12327. AttrConstructor = Attrs[upperFirst(type)];
  12328. }
  12329. return new AttrConstructor(attrOption);
  12330. }
  12331. }, {
  12332. key: "create",
  12333. value: function create(options) {
  12334. this.update(options);
  12335. }
  12336. }, {
  12337. key: "update",
  12338. value: function update(nextOptions) {
  12339. var scaleController = this.scaleController,
  12340. lastOptions = this.options,
  12341. lastAttrs = this.attrs;
  12342. var nextAttrs = {};
  12343. each(nextOptions, function (nextOption, attrName) {
  12344. var lastOption = lastOptions[attrName];
  12345. if (equal(nextOption, lastOption)) {
  12346. nextAttrs[attrName] = lastAttrs[attrName];
  12347. }
  12348. var field = nextOption.field,
  12349. justifyContent = nextOption.justifyContent;
  12350. if (field) {
  12351. scaleController.setScale(field, {
  12352. justifyContent: justifyContent
  12353. });
  12354. }
  12355. });
  12356. this.options = nextOptions;
  12357. this.attrs = nextAttrs;
  12358. }
  12359. }, {
  12360. key: "getAttr",
  12361. value: function getAttr(attrName) {
  12362. var attrs = this.attrs,
  12363. options = this.options;
  12364. var attr = attrs[attrName];
  12365. if (attr) {
  12366. return attr;
  12367. }
  12368. var option = options[attrName];
  12369. if (!option) {
  12370. return null;
  12371. }
  12372. var newAttr = this.createAttr(option);
  12373. attrs[attrName] = newAttr;
  12374. return newAttr;
  12375. }
  12376. }, {
  12377. key: "getAttrs",
  12378. value: function getAttrs() {
  12379. var _this2 = this;
  12380. var options = this.options,
  12381. attrs = this.attrs;
  12382. each(options, function (option, attrName) {
  12383. _this2.getAttr(attrName);
  12384. });
  12385. return attrs;
  12386. }
  12387. }, {
  12388. key: "isGroupAttr",
  12389. value: function isGroupAttr(attrName) {
  12390. return GROUP_ATTRS.indexOf(attrName) !== -1;
  12391. }
  12392. }, {
  12393. key: "getAttrsByLinear",
  12394. value: function getAttrsByLinear() {
  12395. var attrs = this.attrs;
  12396. var attrNames = Object.keys(attrs);
  12397. var linearAttrs = [];
  12398. var nonlinearAttrs = [];
  12399. attrNames.forEach(function (attrName) {
  12400. if (attrName === 'x' || attrName === 'y') {
  12401. linearAttrs.push(attrName);
  12402. return;
  12403. }
  12404. var scale = attrs[attrName].scale;
  12405. if (scale && scale.type === 'linear') {
  12406. linearAttrs.push(attrName);
  12407. } else {
  12408. nonlinearAttrs.push(attrName);
  12409. }
  12410. });
  12411. return {
  12412. linearAttrs: linearAttrs,
  12413. nonlinearAttrs: nonlinearAttrs
  12414. };
  12415. }
  12416. }]);
  12417. return AttrController;
  12418. }();
  12419. var _excluded$3 = ["field"];
  12420. var FIELD_ORIGIN = 'origin';
  12421. var Geometry = /*#__PURE__*/function (_Selection) {
  12422. _inherits(Geometry, _Selection);
  12423. var _super = _createSuper(Geometry);
  12424. function Geometry(props, context) {
  12425. var _this;
  12426. _classCallCheck(this, Geometry);
  12427. _this = _super.call(this, props, context);
  12428. _this.isGeometry = true; // x 轴居中
  12429. _this.justifyContent = false; // y 轴是否从0开始
  12430. _this.startOnZero = false; // 是否连接空值
  12431. _this.connectNulls = false; // 是否需要排序
  12432. _this.sortable = false;
  12433. mix(_assertThisInitialized(_this), _this.getDefaultCfg());
  12434. var chart = props.chart,
  12435. coord = props.coord;
  12436. var attrsRange = _this._getThemeAttrsRange();
  12437. _this.attrController = new AttrController(chart.scale, attrsRange);
  12438. var _assertThisInitialize = _assertThisInitialized(_this),
  12439. attrController = _assertThisInitialize.attrController,
  12440. justifyContent = _assertThisInitialize.justifyContent;
  12441. var attrOptions = attrController.getAttrOptions(props, !coord.isCyclic() || justifyContent);
  12442. attrController.create(attrOptions);
  12443. return _this;
  12444. }
  12445. _createClass(Geometry, [{
  12446. key: "getDefaultCfg",
  12447. value: function getDefaultCfg() {
  12448. return {};
  12449. }
  12450. }, {
  12451. key: "willReceiveProps",
  12452. value: function willReceiveProps(nextProps) {
  12453. _get$1(_getPrototypeOf(Geometry.prototype), "willReceiveProps", this).call(this, nextProps);
  12454. var lastProps = this.props,
  12455. attrController = this.attrController,
  12456. justifyContent = this.justifyContent;
  12457. var nextData = nextProps.data,
  12458. nextAdjust = nextProps.adjust,
  12459. nextZoomRange = nextProps.zoomRange,
  12460. coord = nextProps.coord;
  12461. var lastData = lastProps.data,
  12462. lastAdjust = lastProps.adjust,
  12463. lastZoomRange = lastProps.zoomRange;
  12464. var justifyContentCenter = !coord.isCyclic() || justifyContent;
  12465. var nextAttrOptions = attrController.getAttrOptions(nextProps, justifyContentCenter);
  12466. var lastAttrOptions = attrController.getAttrOptions(lastProps, justifyContentCenter);
  12467. if (!equal(nextAttrOptions, lastAttrOptions)) {
  12468. attrController.update(nextAttrOptions);
  12469. this.records = null;
  12470. } // 重新处理数据
  12471. if (nextData !== lastData) {
  12472. this.records = null;
  12473. } // 重新处理数据
  12474. if (nextAdjust !== lastAdjust) {
  12475. this.records = null;
  12476. } // zoomRange发生变化,records也需要重新计算
  12477. if (!equal(nextZoomRange, lastZoomRange)) {
  12478. this.records = null;
  12479. }
  12480. }
  12481. }, {
  12482. key: "willMount",
  12483. value: function willMount() {
  12484. this._createAttrs();
  12485. if (!this.records) {
  12486. this._processData();
  12487. }
  12488. }
  12489. }, {
  12490. key: "willUpdate",
  12491. value: function willUpdate() {
  12492. this._createAttrs();
  12493. if (!this.records) {
  12494. this._processData();
  12495. }
  12496. }
  12497. }, {
  12498. key: "didMount",
  12499. value: function didMount() {
  12500. _get$1(_getPrototypeOf(Geometry.prototype), "didMount", this).call(this);
  12501. this._initEvent();
  12502. }
  12503. }, {
  12504. key: "_createAttrs",
  12505. value: function _createAttrs() {
  12506. var attrController = this.attrController;
  12507. attrController.attrs = {};
  12508. this.attrs = attrController.getAttrs();
  12509. }
  12510. }, {
  12511. key: "_getThemeAttrsRange",
  12512. value: function _getThemeAttrsRange() {
  12513. var context = this.context,
  12514. props = this.props,
  12515. geomType = this.geomType;
  12516. var coord = props.coord;
  12517. var theme = context.theme;
  12518. var colors = theme.colors,
  12519. sizes = theme.sizes,
  12520. shapes = theme.shapes;
  12521. return {
  12522. x: coord.x,
  12523. y: coord.y,
  12524. color: colors,
  12525. size: sizes,
  12526. shape: shapes[geomType]
  12527. };
  12528. }
  12529. }, {
  12530. key: "_adjustScales",
  12531. value: function _adjustScales() {
  12532. var attrs = this.attrs,
  12533. props = this.props,
  12534. defaultStartOnZero = this.startOnZero;
  12535. var chart = props.chart,
  12536. _props$startOnZero = props.startOnZero,
  12537. startOnZero = _props$startOnZero === void 0 ? defaultStartOnZero : _props$startOnZero,
  12538. coord = props.coord,
  12539. adjust = props.adjust;
  12540. var isPolar = coord.isPolar,
  12541. transposed = coord.transposed;
  12542. var y = attrs.y;
  12543. var yField = y.field; // 如果从 0 开始,只调整 y 轴 scale
  12544. if (startOnZero) {
  12545. var _y = attrs.y;
  12546. chart.scale.adjustStartZero(_y.scale);
  12547. } // 饼图的scale调整,关闭nice
  12548. if (isPolar && transposed && (adjust === 'stack' || (adjust === null || adjust === void 0 ? void 0 : adjust.type) === 'stack')) {
  12549. var _y2 = attrs.y;
  12550. chart.scale.adjustPieScale(_y2.scale);
  12551. }
  12552. if (adjust === 'stack' || (adjust === null || adjust === void 0 ? void 0 : adjust.type) === 'stack') {
  12553. this._updateStackRange(yField, y.scale, this.dataArray);
  12554. }
  12555. }
  12556. }, {
  12557. key: "_groupData",
  12558. value: function _groupData(data) {
  12559. var attrController = this.attrController;
  12560. var groupScales = attrController.getGroupScales();
  12561. if (!groupScales.length) {
  12562. return [{
  12563. children: data
  12564. }];
  12565. }
  12566. var names = [];
  12567. groupScales.forEach(function (scale) {
  12568. var field = scale.field;
  12569. names.push(field);
  12570. });
  12571. var groups = groupToMap(data, names);
  12572. var records = [];
  12573. for (var key in groups) {
  12574. records.push({
  12575. key: key.replace(/^_/, ''),
  12576. children: groups[key]
  12577. });
  12578. }
  12579. return records;
  12580. }
  12581. }, {
  12582. key: "_saveOrigin",
  12583. value: function _saveOrigin(originData) {
  12584. var len = originData.length;
  12585. var data = new Array(len);
  12586. for (var i = 0; i < len; i++) {
  12587. var record = originData[i];
  12588. data[i] = _objectSpread(_objectSpread({}, record), {}, _defineProperty({}, FIELD_ORIGIN, record));
  12589. }
  12590. return data;
  12591. }
  12592. }, {
  12593. key: "_numberic",
  12594. value: function _numberic(data) {
  12595. var attrs = this.attrs;
  12596. var scales = [attrs.x.scale, attrs.y.scale];
  12597. for (var j = 0, len = data.length; j < len; j++) {
  12598. var obj = data[j];
  12599. var count = scales.length;
  12600. for (var i = 0; i < count; i++) {
  12601. var scale = scales[i];
  12602. if (scale.isCategory) {
  12603. var field = scale.field;
  12604. obj[field] = scale.translate(obj[field]);
  12605. }
  12606. }
  12607. }
  12608. }
  12609. }, {
  12610. key: "_adjustData",
  12611. value: function _adjustData(records) {
  12612. var attrs = this.attrs,
  12613. props = this.props;
  12614. var adjust = props.adjust; // groupedArray 是二维数组
  12615. var groupedArray = records.map(function (record) {
  12616. return record.children;
  12617. });
  12618. if (!adjust) {
  12619. return groupedArray;
  12620. }
  12621. var adjustCfg = typeof adjust === 'string' ? {
  12622. type: adjust
  12623. } : adjust;
  12624. var adjustType = upperFirst(adjustCfg.type);
  12625. var AdjustConstructor = getAdjust(adjustType);
  12626. if (!AdjustConstructor) {
  12627. throw new Error('not support such adjust : ' + adjust);
  12628. }
  12629. if (adjustType === 'Dodge') {
  12630. for (var i = 0, len = groupedArray.length; i < len; i++) {
  12631. // 如果是dodge, 需要处理数字再处理
  12632. this._numberic(groupedArray[i]);
  12633. }
  12634. adjustCfg.adjustNames = ['x'];
  12635. }
  12636. var x = attrs.x,
  12637. y = attrs.y;
  12638. adjustCfg.xField = x.field;
  12639. adjustCfg.yField = y.field;
  12640. var adjustInstance = new AdjustConstructor(adjustCfg);
  12641. var adjustData = adjustInstance.process(groupedArray);
  12642. this.adjust = {
  12643. type: adjustCfg.type,
  12644. adjust: adjustInstance
  12645. }; // process 返回的是新数组,所以要修改 records
  12646. records.forEach(function (record, index) {
  12647. record.children = adjustData[index];
  12648. });
  12649. return adjustData;
  12650. }
  12651. }, {
  12652. key: "_updateStackRange",
  12653. value: function _updateStackRange(field, scale, dataArray) {
  12654. var flattenArray = flatten(dataArray);
  12655. var min = Infinity;
  12656. var max = -Infinity;
  12657. for (var i = 0, len = flattenArray.length; i < len; i++) {
  12658. var obj = flattenArray[i];
  12659. var tmpMin = Math.min.apply(null, obj[field]);
  12660. var tmpMax = Math.max.apply(null, obj[field]);
  12661. if (tmpMin < min) {
  12662. min = tmpMin;
  12663. }
  12664. if (tmpMax > max) {
  12665. max = tmpMax;
  12666. }
  12667. }
  12668. if (min !== scale.min || max !== scale.max) {
  12669. scale.change({
  12670. min: min,
  12671. max: max
  12672. });
  12673. }
  12674. }
  12675. }, {
  12676. key: "_processData",
  12677. value: function _processData() {
  12678. var props = this.props;
  12679. var originData = props.data;
  12680. var data = this._saveOrigin(originData); // 根据分类度量进行数据分组
  12681. var records = this._groupData(data); // 根据adjust分组
  12682. var dataArray = this._adjustData(records);
  12683. this.dataArray = dataArray; // scale适配调整,主要是调整 y 轴是否从 0 开始 以及 饼图
  12684. this._adjustScales(); // 数据排序(非必须)
  12685. if (this.sortable) {
  12686. this._sortData(records);
  12687. }
  12688. this.records = records;
  12689. }
  12690. }, {
  12691. key: "_sortData",
  12692. value: function _sortData(records) {
  12693. var xScale = this.getXScale();
  12694. var field = xScale.field,
  12695. type = xScale.type;
  12696. if (type !== 'identity' && xScale.values.length > 1) {
  12697. each(records, function (_ref) {
  12698. var children = _ref.children;
  12699. children.sort(function (record1, record2) {
  12700. if (type === 'timeCat') {
  12701. return toTimeStamp(record1[FIELD_ORIGIN][field]) - toTimeStamp(record2[FIELD_ORIGIN][field]);
  12702. }
  12703. return xScale.translate(record1[FIELD_ORIGIN][field]) - xScale.translate(record2[FIELD_ORIGIN][field]);
  12704. });
  12705. });
  12706. }
  12707. }
  12708. }, {
  12709. key: "_initEvent",
  12710. value: function _initEvent() {
  12711. var _this2 = this;
  12712. var container = this.container,
  12713. props = this.props;
  12714. var canvas = container.get('canvas');
  12715. ['onPressStart', 'onPress', 'onPressEnd', 'onPan', 'onPanStart', 'onPanEnd'].forEach(function (eventName) {
  12716. if (props[eventName]) {
  12717. canvas.on(eventName.substr(2).toLowerCase(), function (ev) {
  12718. ev.geometry = _this2;
  12719. props[eventName](ev);
  12720. });
  12721. }
  12722. });
  12723. }
  12724. }, {
  12725. key: "getY0Value",
  12726. value: function getY0Value() {
  12727. var attrs = this.attrs,
  12728. props = this.props;
  12729. var chart = props.chart;
  12730. var field = attrs.y.field;
  12731. var scale = chart.getScale(field);
  12732. return chart.scale.getZeroValue(scale);
  12733. } // 根据各属性映射的值域来获取真正的绘图属性
  12734. }, {
  12735. key: "_getShapeStyle",
  12736. value: function _getShapeStyle(shape, origin) {
  12737. var context = this.context,
  12738. props = this.props,
  12739. geomType = this.geomType;
  12740. var theme = context.theme;
  12741. var shapeTheme = theme.shape[geomType] || {};
  12742. var defaultShapeStyle = shapeTheme.default;
  12743. var shapeThemeStyle = shapeTheme[shape];
  12744. var style = props.style;
  12745. var shapeStyle = _objectSpread(_objectSpread({}, defaultShapeStyle), shapeThemeStyle);
  12746. if (!style || !isObject(style)) {
  12747. return shapeStyle;
  12748. } // @ts-ignore
  12749. var field = style.field,
  12750. styles = _objectWithoutProperties(style, _excluded$3);
  12751. var value = field ? origin[field] : origin;
  12752. each(styles, function (attr, key) {
  12753. if (isFunction(attr)) {
  12754. shapeStyle[key] = attr(value);
  12755. } else {
  12756. shapeStyle[key] = attr;
  12757. }
  12758. });
  12759. return shapeStyle;
  12760. }
  12761. /**
  12762. * 数据映射到视图属性核心逻辑
  12763. * x、y 每个元素走 normalize 然后 convertPoint
  12764. * color、size、shape
  12765. * 如果是Linear,则每个元素 走 mapping
  12766. * 如果是Category/Identity 则第一个元素走 mapping
  12767. */
  12768. }, {
  12769. key: "_mapping",
  12770. value: function _mapping(records) {
  12771. var attrs = this.attrs,
  12772. props = this.props,
  12773. attrController = this.attrController;
  12774. var coord = props.coord;
  12775. var _attrController$getAt = attrController.getAttrsByLinear(),
  12776. linearAttrs = _attrController$getAt.linearAttrs,
  12777. nonlinearAttrs = _attrController$getAt.nonlinearAttrs;
  12778. var defaultAttrValues = attrController.getDefaultAttrValues();
  12779. for (var i = 0, len = records.length; i < len; i++) {
  12780. var record = records[i];
  12781. var children = record.children;
  12782. var attrValues = _objectSpread({}, defaultAttrValues);
  12783. var firstChild = children[0];
  12784. if (children.length === 0) {
  12785. continue;
  12786. } // 非线性映射
  12787. for (var k = 0, _len = nonlinearAttrs.length; k < _len; k++) {
  12788. var attrName = nonlinearAttrs[k];
  12789. var attr = attrs[attrName]; // 非线性映射只用映射第一项就可以了
  12790. attrValues[attrName] = attr.mapping(firstChild[attr.field]);
  12791. } // 线性属性映射
  12792. for (var j = 0, childrenLen = children.length; j < childrenLen; j++) {
  12793. var child = children[j];
  12794. var normalized = {};
  12795. for (var _k = 0; _k < linearAttrs.length; _k++) {
  12796. var _attrName = linearAttrs[_k];
  12797. var _attr = attrs[_attrName]; // 分类属性的线性映射
  12798. if (attrController.isGroupAttr(_attrName)) {
  12799. attrValues[_attrName] = _attr.mapping(child[_attr.field], child);
  12800. } else {
  12801. normalized[_attrName] = _attr.normalize(child[_attr.field]);
  12802. }
  12803. }
  12804. var _coord$convertPoint = coord.convertPoint({
  12805. x: normalized.x,
  12806. y: normalized.y
  12807. }),
  12808. x = _coord$convertPoint.x,
  12809. y = _coord$convertPoint.y; // 获取 shape 的 style
  12810. var shapeName = attrValues.shape;
  12811. var shape = this._getShapeStyle(shapeName, child.origin);
  12812. var selected = this.isSelected(child);
  12813. mix(child, attrValues, {
  12814. normalized: normalized,
  12815. x: x,
  12816. y: y,
  12817. shapeName: shapeName,
  12818. shape: shape,
  12819. selected: selected
  12820. });
  12821. }
  12822. }
  12823. return records;
  12824. } // 数据映射
  12825. }, {
  12826. key: "mapping",
  12827. value: function mapping() {
  12828. var records = this.records; // 数据映射
  12829. this._mapping(records);
  12830. return records;
  12831. }
  12832. }, {
  12833. key: "getClip",
  12834. value: function getClip() {
  12835. var _this$props = this.props,
  12836. coord = _this$props.coord,
  12837. viewClip = _this$props.viewClip;
  12838. var contentWidth = coord.width,
  12839. contentHeight = coord.height,
  12840. left = coord.left,
  12841. top = coord.top;
  12842. if (viewClip) {
  12843. return {
  12844. type: 'rect',
  12845. attrs: {
  12846. x: left,
  12847. y: top,
  12848. width: contentWidth,
  12849. height: contentHeight
  12850. }
  12851. };
  12852. }
  12853. return null;
  12854. }
  12855. }, {
  12856. key: "getAttr",
  12857. value: function getAttr(attrName) {
  12858. return this.attrController.getAttr(attrName);
  12859. }
  12860. }, {
  12861. key: "getXScale",
  12862. value: function getXScale() {
  12863. return this.getAttr('x').scale;
  12864. }
  12865. }, {
  12866. key: "getYScale",
  12867. value: function getYScale() {
  12868. return this.getAttr('y').scale;
  12869. }
  12870. }, {
  12871. key: "_getXSnap",
  12872. value: function _getXSnap(invertPointX) {
  12873. var xScale = this.getXScale();
  12874. if (xScale.isCategory) {
  12875. return xScale.invert(invertPointX);
  12876. } // linear 类型
  12877. var invertValue = xScale.invert(invertPointX);
  12878. var values = xScale.values;
  12879. var len = values.length; // 如果只有1个点直接返回第1个点
  12880. if (len === 1) {
  12881. return values[0];
  12882. } // 第1个点和第2个点之间
  12883. if ((values[0] + values[1]) / 2 > invertValue) {
  12884. return values[0];
  12885. } // 最后2个点
  12886. if ((values[len - 2] + values[len - 1]) / 2 <= invertValue) {
  12887. return values[len - 1];
  12888. }
  12889. for (var i = 1; i < len; i++) {
  12890. // 中间的点
  12891. if ((values[i - 1] + values[i]) / 2 <= invertValue && (values[i + 1] + values[i]) / 2 > invertValue) {
  12892. return values[i];
  12893. }
  12894. }
  12895. return null;
  12896. }
  12897. }, {
  12898. key: "_getYSnapRecords",
  12899. value: function _getYSnapRecords(invertPointY, records) {
  12900. var yScale = this.getYScale();
  12901. var yField = yScale.field;
  12902. var yValue = yScale.invert(invertPointY); // category
  12903. if (yScale.isCategory) {
  12904. return records.filter(function (record) {
  12905. return record[FIELD_ORIGIN][yField] === yValue;
  12906. });
  12907. } // linear
  12908. return records.filter(function (record) {
  12909. var rangeY = record[yField];
  12910. if (rangeY[0] <= yValue && rangeY[1] >= yValue) {
  12911. return true;
  12912. }
  12913. return false;
  12914. });
  12915. } // 把 records 拍平
  12916. }, {
  12917. key: "flatRecords",
  12918. value: function flatRecords() {
  12919. var records = this.records;
  12920. return records.reduce(function (prevRecords, record) {
  12921. return prevRecords.concat(record.children);
  12922. }, []);
  12923. }
  12924. }, {
  12925. key: "getSnapRecords",
  12926. value: function getSnapRecords(point, inCoordRange) {
  12927. var props = this.props;
  12928. var coord = props.coord,
  12929. adjust = props.adjust;
  12930. var invertPoint = coord.invertPoint(point);
  12931. var xScale = this.getXScale();
  12932. var yScale = this.getYScale(); // 如果不在coord坐标范围内,直接返回空
  12933. // if (invertPoint.x < 0 || invertPoint.y < 0) {
  12934. // return [];
  12935. // }
  12936. // 是否调整 point,默认为不调整
  12937. if (inCoordRange) {
  12938. var xRange = xScale.range;
  12939. var yRange = yScale.range; // 如果 inCoordRange=true,当 point 不在 coord 坐标范围内时,调整到 range 内
  12940. invertPoint.x = Math.min(Math.max(invertPoint.x, xRange[0]), xRange[1]);
  12941. invertPoint.y = Math.min(Math.max(invertPoint.y, yRange[0]), yRange[1]);
  12942. }
  12943. var records = this.flatRecords(); // 处理饼图
  12944. if (adjust === 'stack' && coord.isPolar && coord.transposed) {
  12945. // 弧度在半径范围内
  12946. if (invertPoint.x >= 0 && invertPoint.x <= 1) {
  12947. var snapRecords = this._getYSnapRecords(invertPoint.y, records);
  12948. return snapRecords;
  12949. }
  12950. }
  12951. var rst = [];
  12952. var value = this._getXSnap(invertPoint.x);
  12953. if (!value) {
  12954. return rst;
  12955. }
  12956. var xField = xScale.field;
  12957. var yField = yScale.field;
  12958. for (var i = 0, len = records.length; i < len; i++) {
  12959. var record = _objectSpread(_objectSpread({}, records[i]), {}, {
  12960. xField: xField,
  12961. yField: yField
  12962. });
  12963. var originValue = record[FIELD_ORIGIN][xField];
  12964. if (xScale.type === 'timeCat' && toTimeStamp(originValue) === value) {
  12965. rst.push(record);
  12966. } else if (originValue === value) {
  12967. rst.push(record);
  12968. }
  12969. }
  12970. return rst;
  12971. }
  12972. }, {
  12973. key: "getLegendItems",
  12974. value: function getLegendItems() {
  12975. var attrController = this.attrController;
  12976. var colorAttr = attrController.getAttr('color');
  12977. if (!colorAttr) return null;
  12978. var scale = colorAttr.scale;
  12979. if (!scale.isCategory) return null;
  12980. var ticks = scale.getTicks();
  12981. var items = ticks.map(function (tick) {
  12982. var text = tick.text,
  12983. tickValue = tick.tickValue;
  12984. var color = colorAttr.mapping(tickValue);
  12985. return {
  12986. field: scale.field,
  12987. color: color,
  12988. name: text,
  12989. tickValue: tickValue
  12990. };
  12991. });
  12992. return items;
  12993. }
  12994. }]);
  12995. return Geometry;
  12996. }(Selection);
  12997. var arrayWithoutHoles = createCommonjsModule(function (module) {
  12998. function _arrayWithoutHoles(arr) {
  12999. if (Array.isArray(arr)) return arrayLikeToArray(arr);
  13000. }
  13001. module.exports = _arrayWithoutHoles, module.exports.__esModule = true, module.exports["default"] = module.exports;
  13002. });
  13003. var iterableToArray = createCommonjsModule(function (module) {
  13004. function _iterableToArray(iter) {
  13005. if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
  13006. }
  13007. module.exports = _iterableToArray, module.exports.__esModule = true, module.exports["default"] = module.exports;
  13008. });
  13009. var nonIterableSpread = createCommonjsModule(function (module) {
  13010. function _nonIterableSpread() {
  13011. throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
  13012. }
  13013. module.exports = _nonIterableSpread, module.exports.__esModule = true, module.exports["default"] = module.exports;
  13014. });
  13015. var toConsumableArray = createCommonjsModule(function (module) {
  13016. function _toConsumableArray(arr) {
  13017. return arrayWithoutHoles(arr) || iterableToArray(arr) || unsupportedIterableToArray(arr) || nonIterableSpread();
  13018. }
  13019. module.exports = _toConsumableArray, module.exports.__esModule = true, module.exports["default"] = module.exports;
  13020. });
  13021. var _toConsumableArray = /*@__PURE__*/getDefaultExportFromCjs(toConsumableArray);
  13022. var withLine = (function (View) {
  13023. return /*#__PURE__*/function (_Geometry) {
  13024. _inherits(Line, _Geometry);
  13025. var _super = _createSuper(Line);
  13026. function Line() {
  13027. _classCallCheck(this, Line);
  13028. return _super.apply(this, arguments);
  13029. }
  13030. _createClass(Line, [{
  13031. key: "getDefaultCfg",
  13032. value: function getDefaultCfg() {
  13033. return {
  13034. geomType: 'line',
  13035. sortable: true
  13036. };
  13037. }
  13038. }, {
  13039. key: "splitPoints",
  13040. value: function splitPoints(points) {
  13041. var topPoints = [];
  13042. var bottomPoints = [];
  13043. for (var i = 0, len = points.length; i < len; i++) {
  13044. var point = points[i];
  13045. var x = point.x,
  13046. y = point.y;
  13047. topPoints.push(_objectSpread(_objectSpread({}, point), {}, {
  13048. x: x,
  13049. y: y[1]
  13050. }));
  13051. bottomPoints.push(_objectSpread(_objectSpread({}, point), {}, {
  13052. x: x,
  13053. y: y[0]
  13054. }));
  13055. }
  13056. return [topPoints, bottomPoints];
  13057. }
  13058. }, {
  13059. key: "splitNulls",
  13060. value: function splitNulls(points, connectNulls) {
  13061. if (connectNulls) {
  13062. var _tmpPoints = [];
  13063. for (var i = 0, len = points.length; i < len; i++) {
  13064. var point = points[i];
  13065. var y = point.y;
  13066. if (isArray(y)) {
  13067. if (isNaN(y[0])) {
  13068. continue;
  13069. }
  13070. _tmpPoints.push(point);
  13071. continue;
  13072. }
  13073. if (isNaN(y)) {
  13074. continue;
  13075. }
  13076. _tmpPoints.push(point);
  13077. }
  13078. if (_tmpPoints.length) {
  13079. return [_tmpPoints];
  13080. }
  13081. return [];
  13082. }
  13083. var result = [];
  13084. var tmpPoints = [];
  13085. for (var _i = 0, _len = points.length; _i < _len; _i++) {
  13086. var _point = points[_i];
  13087. var _y = _point.y;
  13088. if (isArray(_y)) {
  13089. if (isNaN(_y[0])) {
  13090. if (tmpPoints.length) {
  13091. result.push(tmpPoints);
  13092. tmpPoints = [];
  13093. }
  13094. continue;
  13095. }
  13096. tmpPoints.push(_point);
  13097. continue;
  13098. }
  13099. if (isNaN(_y)) {
  13100. if (tmpPoints.length) {
  13101. result.push(tmpPoints);
  13102. tmpPoints = [];
  13103. }
  13104. continue;
  13105. }
  13106. tmpPoints.push(_point);
  13107. }
  13108. if (tmpPoints.length) {
  13109. result.push(tmpPoints);
  13110. }
  13111. return result;
  13112. }
  13113. }, {
  13114. key: "mapping",
  13115. value: function mapping() {
  13116. var _this = this;
  13117. var records = _get$1(_getPrototypeOf(Line.prototype), "mapping", this).call(this);
  13118. var props = this.props,
  13119. defaultConnectNulls = this.connectNulls;
  13120. var coord = props.coord,
  13121. _props$connectNulls = props.connectNulls,
  13122. connectNulls = _props$connectNulls === void 0 ? defaultConnectNulls : _props$connectNulls;
  13123. return records.map(function (record) {
  13124. var children = record.children; // children 有可能为空
  13125. var _ref = children[0] || {},
  13126. size = _ref.size,
  13127. color = _ref.color,
  13128. shape = _ref.shape,
  13129. y = _ref.y; // 极坐标时,需加入起点,从而闭合所绘图形
  13130. var points = coord.isPolar ? [].concat(_toConsumableArray(children), [children[0]]) : children;
  13131. var splitPoints = _this.splitNulls(points, connectNulls);
  13132. var newChildren = splitPoints.map(function (points) {
  13133. var _ref2 = isArray(y) ? _this.splitPoints(points) : [points, undefined],
  13134. _ref3 = _slicedToArray(_ref2, 2),
  13135. topPoints = _ref3[0],
  13136. bottomPoints = _ref3[1];
  13137. return {
  13138. size: size,
  13139. color: color,
  13140. shape: shape,
  13141. points: topPoints,
  13142. bottomPoints: bottomPoints
  13143. };
  13144. });
  13145. return _objectSpread(_objectSpread({}, record), {}, {
  13146. children: newChildren
  13147. });
  13148. });
  13149. }
  13150. }, {
  13151. key: "render",
  13152. value: function render() {
  13153. var props = this.props;
  13154. var coord = props.coord;
  13155. var records = this.mapping();
  13156. var clip = this.getClip();
  13157. return jsx(View, _objectSpread(_objectSpread({}, props), {}, {
  13158. coord: coord,
  13159. records: records,
  13160. clip: clip
  13161. }));
  13162. }
  13163. }]);
  13164. return Line;
  13165. }(Geometry);
  13166. });
  13167. function concatPoints(children) {
  13168. var result = [];
  13169. for (var i = 0; i < children.length; i++) {
  13170. var child = children[i];
  13171. result = result.concat(child.points);
  13172. }
  13173. return result;
  13174. }
  13175. function formatPoint(point) {
  13176. var y = point.y;
  13177. return {
  13178. x: point.x,
  13179. y: isArray(y) ? y[1] : y
  13180. };
  13181. }
  13182. function getPoint$1(points, t) {
  13183. var formatedPoints = points.map(function (p) {
  13184. return formatPoint(p);
  13185. });
  13186. var firstPoint = formatedPoints[0];
  13187. var lastPoint = formatedPoints[formatedPoints.length - 1];
  13188. var xOffset = lastPoint.x - firstPoint.x;
  13189. var x = firstPoint.x + xOffset * t;
  13190. for (var i = 1; i < formatedPoints.length; i++) {
  13191. var point = formatedPoints[i];
  13192. var prevPoint = formatedPoints[i - 1];
  13193. if (x >= prevPoint.x && x <= point.x) {
  13194. // x 在 2 点之间的比例,根据比例再算出 y 的值
  13195. var ratio = (x - prevPoint.x) / (point.x - prevPoint.x);
  13196. return {
  13197. x: x,
  13198. y: prevPoint.y + (point.y - prevPoint.y) * ratio
  13199. };
  13200. }
  13201. }
  13202. }
  13203. function AnimationEndView(props) {
  13204. var record = props.record,
  13205. appear = props.appear,
  13206. EndView = props.EndView;
  13207. var children = record.children;
  13208. var points = concatPoints(children);
  13209. var origin = points[0].origin;
  13210. return jsx("group", {
  13211. animation: {
  13212. appear: {
  13213. easing: appear.easing,
  13214. duration: appear.duration,
  13215. onFrame: function onFrame(t) {
  13216. // 这段逻辑有点恶心。。
  13217. var element = this.element;
  13218. var children = element.get('children');
  13219. var point = getPoint$1(points, t);
  13220. children.forEach(function (child) {
  13221. child.moveTo(point.x, point.y);
  13222. });
  13223. }
  13224. }
  13225. }
  13226. }, jsx(EndView, {
  13227. origin: origin
  13228. }));
  13229. }
  13230. var LineView = (function (props) {
  13231. var records = props.records,
  13232. coord = props.coord,
  13233. animation = props.animation,
  13234. EndView = props.endView,
  13235. clip = props.clip;
  13236. var left = coord.left,
  13237. top = coord.top,
  13238. width = coord.width,
  13239. height = coord.height,
  13240. center = coord.center,
  13241. startAngle = coord.startAngle,
  13242. endAngle = coord.endAngle,
  13243. radius = coord.radius;
  13244. var appear = coord.isPolar ? {
  13245. easing: 'quadraticOut',
  13246. duration: 450,
  13247. clip: {
  13248. type: 'sector',
  13249. property: ['endAngle'],
  13250. attrs: {
  13251. x: center.x,
  13252. y: center.y,
  13253. startAngle: startAngle,
  13254. r: radius
  13255. },
  13256. start: {
  13257. endAngle: startAngle
  13258. },
  13259. end: {
  13260. endAngle: endAngle
  13261. }
  13262. }
  13263. } : {
  13264. easing: 'quadraticOut',
  13265. duration: 450,
  13266. clip: {
  13267. type: 'rect',
  13268. property: ['width'],
  13269. attrs: {
  13270. x: left,
  13271. y: top,
  13272. height: height
  13273. },
  13274. start: {
  13275. width: 0
  13276. },
  13277. end: {
  13278. width: width
  13279. }
  13280. }
  13281. };
  13282. return jsx("group", {
  13283. attrs: {
  13284. clip: clip
  13285. }
  13286. }, records.map(function (record) {
  13287. var key = record.key,
  13288. children = record.children;
  13289. return jsx("group", {
  13290. key: key
  13291. }, children.map(function (child) {
  13292. var points = child.points,
  13293. color = child.color,
  13294. size = child.size,
  13295. shape = child.shape;
  13296. return jsx("polyline", {
  13297. attrs: _objectSpread(_objectSpread({
  13298. points: points.map(function (point) {
  13299. return {
  13300. x: point.x,
  13301. y: point.y
  13302. };
  13303. }),
  13304. stroke: color
  13305. }, shape), {}, {
  13306. lineWidth: size || shape.lineWidth
  13307. }),
  13308. animation: deepMix({
  13309. update: {
  13310. easing: 'linear',
  13311. duration: 450,
  13312. property: ['points']
  13313. },
  13314. appear: appear
  13315. }, animation)
  13316. });
  13317. }), EndView ? jsx(AnimationEndView, {
  13318. record: record,
  13319. EndView: EndView,
  13320. appear: appear
  13321. }) : null);
  13322. }));
  13323. });
  13324. var index = withLine(LineView);
  13325. var withArea = (function (View) {
  13326. return /*#__PURE__*/function (_withLine) {
  13327. _inherits(Area, _withLine);
  13328. var _super = _createSuper(Area);
  13329. function Area() {
  13330. _classCallCheck(this, Area);
  13331. return _super.apply(this, arguments);
  13332. }
  13333. _createClass(Area, [{
  13334. key: "getDefaultCfg",
  13335. value: function getDefaultCfg() {
  13336. return {
  13337. geomType: 'area',
  13338. // 面积图默认设为从0开始
  13339. startOnZero: true,
  13340. // 点需要排序
  13341. sortable: true
  13342. };
  13343. }
  13344. }, {
  13345. key: "mapping",
  13346. value: function mapping() {
  13347. var records = _get$1(_getPrototypeOf(Area.prototype), "mapping", this).call(this); // 坐标轴 y0
  13348. var y0 = this.getY0Value();
  13349. var props = this.props,
  13350. defaultStartOnZero = this.startOnZero;
  13351. var coord = props.coord,
  13352. _props$startOnZero = props.startOnZero,
  13353. startOnZero = _props$startOnZero === void 0 ? defaultStartOnZero : _props$startOnZero;
  13354. var baseY = coord.y[0];
  13355. if (startOnZero) {
  13356. // 零点映射到绝对坐标
  13357. var originCoord = coord.convertPoint({
  13358. x: 0,
  13359. y: y0
  13360. });
  13361. baseY = originCoord.y;
  13362. }
  13363. for (var i = 0, len = records.length; i < len; i++) {
  13364. var record = records[i];
  13365. var children = record.children;
  13366. for (var j = 0, _len = children.length; j < _len; j++) {
  13367. var child = children[j];
  13368. var points = child.points,
  13369. bottomPoints = child.bottomPoints;
  13370. if (bottomPoints && bottomPoints.length) {
  13371. bottomPoints.reverse();
  13372. child.points = points.concat(bottomPoints);
  13373. } else {
  13374. points.push({
  13375. x: points[points.length - 1].x,
  13376. y: baseY
  13377. });
  13378. points.push({
  13379. x: points[0].x,
  13380. y: baseY
  13381. });
  13382. }
  13383. }
  13384. }
  13385. return records;
  13386. }
  13387. }]);
  13388. return Area;
  13389. }(withLine(View));
  13390. });
  13391. var AreaView = (function (props) {
  13392. var coord = props.coord,
  13393. records = props.records,
  13394. shape = props.shape,
  13395. animation = props.animation;
  13396. var isSmooth = shape === 'smooth';
  13397. var left = coord.left,
  13398. top = coord.top,
  13399. width = coord.width,
  13400. height = coord.height,
  13401. center = coord.center,
  13402. startAngle = coord.startAngle,
  13403. endAngle = coord.endAngle,
  13404. radius = coord.radius;
  13405. var appear = coord.isPolar ? {
  13406. easing: 'quadraticOut',
  13407. duration: 450,
  13408. clip: {
  13409. type: 'sector',
  13410. property: ['endAngle'],
  13411. attrs: {
  13412. x: center.x,
  13413. y: center.y,
  13414. startAngle: startAngle,
  13415. r: radius
  13416. },
  13417. start: {
  13418. endAngle: startAngle
  13419. },
  13420. end: {
  13421. endAngle: endAngle
  13422. }
  13423. }
  13424. } : {
  13425. easing: 'quadraticOut',
  13426. duration: 450,
  13427. clip: {
  13428. type: 'rect',
  13429. property: ['width'],
  13430. attrs: {
  13431. x: left,
  13432. y: top,
  13433. height: height
  13434. },
  13435. start: {
  13436. width: 0
  13437. },
  13438. end: {
  13439. width: width
  13440. }
  13441. }
  13442. };
  13443. return jsx("group", null, records.map(function (record) {
  13444. var key = record.key,
  13445. children = record.children;
  13446. return jsx("group", {
  13447. key: key
  13448. }, children.map(function (child) {
  13449. var points = child.points,
  13450. bottomPoints = child.bottomPoints,
  13451. color = child.color,
  13452. shape = child.shape;
  13453. if (isSmooth) {
  13454. return jsx("custom", {
  13455. attrs: _objectSpread({
  13456. points: points,
  13457. lineWidth: '2px',
  13458. fill: color
  13459. }, shape),
  13460. createPath: function createPath(context) {
  13461. var constaint = [[0, 0], [1, 1]];
  13462. var bottomPointsLen = (bottomPoints === null || bottomPoints === void 0 ? void 0 : bottomPoints.length) || 0;
  13463. var topPoints = points.slice(0, points.length - bottomPointsLen);
  13464. var topSps = catmullRom2bezier(topPoints, false, constaint);
  13465. context.beginPath();
  13466. context.moveTo(topPoints[0].x, topPoints[0].y);
  13467. for (var i = 0, n = topSps.length; i < n; i++) {
  13468. var sp = topSps[i];
  13469. context.bezierCurveTo(sp[1], sp[2], sp[3], sp[4], sp[5], sp[6]);
  13470. }
  13471. if (bottomPointsLen) {
  13472. var bottomSps = catmullRom2bezier(bottomPoints, false, constaint);
  13473. context.lineTo(bottomPoints[0].x, bottomPoints[0].y);
  13474. for (var _i = 0, _n = bottomSps.length; _i < _n; _i++) {
  13475. var _sp = bottomSps[_i];
  13476. context.bezierCurveTo(_sp[1], _sp[2], _sp[3], _sp[4], _sp[5], _sp[6]);
  13477. }
  13478. }
  13479. context.closePath();
  13480. },
  13481. calculateBox: function calculateBox() {
  13482. return getBBoxFromPoints(points);
  13483. }
  13484. });
  13485. }
  13486. return jsx("polygon", {
  13487. attrs: _objectSpread({
  13488. points: points,
  13489. lineWidth: '2px',
  13490. fill: color
  13491. }, shape),
  13492. animation: deepMix({
  13493. appear: appear,
  13494. update: {
  13495. easing: 'linear',
  13496. duration: 450,
  13497. property: ['points']
  13498. }
  13499. }, animation)
  13500. });
  13501. }));
  13502. }));
  13503. });
  13504. var index$1 = withArea(AreaView);
  13505. /**
  13506. * 计算两个坐标的中点坐标
  13507. * @param start 起始点{x:number, y:number}
  13508. * @param end 结束点{x:number, y:number}
  13509. * @returns 中点坐标{x:number, y:number}
  13510. */
  13511. function getMiddlePoint(start, end) {
  13512. var x = (end.x - start.x) / 2 + start.x;
  13513. var y = (end.y - start.y) / 2 + start.y;
  13514. return {
  13515. x: x,
  13516. y: y
  13517. };
  13518. }
  13519. var DEFAULT_LABEL_CFG = {
  13520. textBaseline: 'middle',
  13521. fill: '#808080'
  13522. };
  13523. function LabelView(props) {
  13524. var record = props.record,
  13525. offsetX = props.offsetX,
  13526. offsetY = props.offsetY,
  13527. points = props.points,
  13528. label = props.label,
  13529. guide = props.guide;
  13530. var origin = record.origin,
  13531. color = record.color;
  13532. var labelAttrs, guideAttrs;
  13533. if (isFunction(label)) {
  13534. var point = points.length === 4 // 如果是金字塔图,顶部只有 3 个点
  13535. ? getMiddlePoint(points[1], points[2]) : getMiddlePoint(points[0], points[1]);
  13536. labelAttrs = mix({
  13537. x: point.x + offsetX,
  13538. y: point.y + offsetY
  13539. }, DEFAULT_LABEL_CFG, label(origin, color));
  13540. }
  13541. if (isFunction(guide)) {
  13542. var _points$;
  13543. 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]));
  13544. guideAttrs = mix({
  13545. x: _point.x,
  13546. y: _point.y,
  13547. textBaseline: 'middle',
  13548. textAlign: 'center'
  13549. }, DEFAULT_LABEL_CFG, guide(origin, color));
  13550. }
  13551. return jsx("group", null, labelAttrs && jsx("text", {
  13552. attrs: labelAttrs
  13553. }), guideAttrs && jsx("text", {
  13554. attrs: guideAttrs
  13555. }));
  13556. }
  13557. var LabelViews = /*#__PURE__*/Object.freeze({
  13558. __proto__: null,
  13559. pyramid: LabelView,
  13560. funnel: LabelView
  13561. });
  13562. var withInterval = (function (Views) {
  13563. return /*#__PURE__*/function (_Geometry) {
  13564. _inherits(Interval, _Geometry);
  13565. var _super = _createSuper(Interval);
  13566. function Interval() {
  13567. _classCallCheck(this, Interval);
  13568. return _super.apply(this, arguments);
  13569. }
  13570. _createClass(Interval, [{
  13571. key: "getDefaultCfg",
  13572. value: function getDefaultCfg() {
  13573. return {
  13574. geomType: 'interval',
  13575. justifyContent: true,
  13576. startOnZero: true
  13577. };
  13578. }
  13579. }, {
  13580. key: "getDefaultSize",
  13581. value: function getDefaultSize() {
  13582. var attrs = this.attrs,
  13583. props = this.props,
  13584. adjust = this.adjust,
  13585. records = this.records;
  13586. var coord = props.coord,
  13587. sizeRatio = props.sizeRatio;
  13588. var x = attrs.x;
  13589. var scale = x.scale;
  13590. var values = scale.values;
  13591. if (sizeRatio) {
  13592. return 1 / values.length * sizeRatio;
  13593. }
  13594. var defaultWithRatio = {
  13595. column: 1 / 2,
  13596. rose: 0.999999,
  13597. multiplePie: 3 / 4 // 多饼图
  13598. };
  13599. var count = values.length;
  13600. var ratio;
  13601. if (coord.isPolar) {
  13602. if (coord.transposed && count > 1) {
  13603. ratio = defaultWithRatio.multiplePie;
  13604. } else {
  13605. ratio = defaultWithRatio.rose;
  13606. }
  13607. } else {
  13608. ratio = defaultWithRatio.column;
  13609. }
  13610. var size = 1 / values.length * ratio; // 分组时size要除以类别个数
  13611. if (adjust && adjust.type === 'dodge') {
  13612. return size / records.length;
  13613. }
  13614. return size;
  13615. }
  13616. }, {
  13617. key: "mapping",
  13618. value: function mapping() {
  13619. var records = _get$1(_getPrototypeOf(Interval.prototype), "mapping", this).call(this);
  13620. var props = this.props;
  13621. var coord = props.coord;
  13622. var y0 = this.getY0Value();
  13623. var defaultSize = this.getDefaultSize();
  13624. for (var i = 0, len = records.length; i < len; i++) {
  13625. var record = records[i];
  13626. var children = record.children;
  13627. for (var j = 0, _len = children.length; j < _len; j++) {
  13628. var child = children[j];
  13629. var normalized = child.normalized,
  13630. mappedSize = child.size; // 没有指定size,则根据数据来计算默认size
  13631. if (isNil(mappedSize)) {
  13632. var x = normalized.x,
  13633. y = normalized.y,
  13634. _normalized$size = normalized.size,
  13635. size = _normalized$size === void 0 ? defaultSize : _normalized$size;
  13636. mix(child, coord.convertRect({
  13637. x: x,
  13638. y: y,
  13639. y0: y0,
  13640. size: size
  13641. }));
  13642. } else {
  13643. var _x = child.x,
  13644. _y = child.y;
  13645. var rect = {
  13646. size: mappedSize,
  13647. x: _x,
  13648. y: _y,
  13649. y0: y0
  13650. };
  13651. mix(child, coord.transformToRect(rect));
  13652. }
  13653. mix(child.shape, this.getSelectionStyle(child));
  13654. }
  13655. }
  13656. return records;
  13657. } // 获取Y轴坐标零点的画布位置
  13658. }, {
  13659. key: "getPointY0",
  13660. value: function getPointY0() {
  13661. var props = this.props;
  13662. var coord = props.coord;
  13663. var y0 = this.getY0Value();
  13664. var y0Point = coord.convertPoint({
  13665. y: y0,
  13666. x: 0
  13667. });
  13668. return y0Point === null || y0Point === void 0 ? void 0 : y0Point.y;
  13669. }
  13670. }, {
  13671. key: "render",
  13672. value: function render() {
  13673. var props = this.props,
  13674. state = this.state,
  13675. container = this.container;
  13676. var coord = props.coord,
  13677. _props$shape = props.shape,
  13678. shape = _props$shape === void 0 ? 'rect' : _props$shape,
  13679. animation = props.animation,
  13680. showLabel = props.showLabel,
  13681. customLabelCfg = props.labelCfg;
  13682. var View = isFunction(Views) ? Views : Views[shape];
  13683. var LabelView = LabelViews[shape];
  13684. var labelCfg = deepMix({
  13685. label: null,
  13686. offsetX: 0,
  13687. offsetY: 0
  13688. }, customLabelCfg);
  13689. if (!View) return null;
  13690. var selected = state.selected;
  13691. var records = this.mapping();
  13692. var pointY0 = this.getPointY0();
  13693. var clip = this.getClip();
  13694. return jsx(View, {
  13695. coord: coord,
  13696. records: records,
  13697. selected: selected,
  13698. shape: shape,
  13699. animation: animation,
  13700. showLabel: showLabel,
  13701. labelCfg: labelCfg,
  13702. LabelView: LabelView,
  13703. y0: pointY0,
  13704. clip: clip
  13705. });
  13706. }
  13707. }]);
  13708. return Interval;
  13709. }(Geometry);
  13710. });
  13711. var Rect$3 = (function (props) {
  13712. var records = props.records,
  13713. animation = props.animation,
  13714. y0 = props.y0,
  13715. clip = props.clip;
  13716. return jsx("group", {
  13717. attrs: {
  13718. clip: clip
  13719. }
  13720. }, records.map(function (record) {
  13721. var key = record.key,
  13722. children = record.children;
  13723. return jsx("group", {
  13724. key: key
  13725. }, children.map(function (item) {
  13726. var key = item.key,
  13727. xMin = item.xMin,
  13728. xMax = item.xMax,
  13729. yMin = item.yMin,
  13730. yMax = item.yMax,
  13731. color = item.color,
  13732. shape = item.shape;
  13733. if (isNaN(xMin) || isNaN(xMax) || isNaN(yMin) || isNaN(yMax)) {
  13734. return null;
  13735. }
  13736. return jsx("rect", {
  13737. key: key,
  13738. attrs: _objectSpread({
  13739. x: xMin,
  13740. y: yMin,
  13741. width: xMax - xMin,
  13742. height: yMax - yMin,
  13743. fill: color
  13744. }, shape),
  13745. animation: deepMix({
  13746. appear: {
  13747. easing: 'linear',
  13748. duration: 450,
  13749. property: ['y', 'height'],
  13750. start: {
  13751. y: y0,
  13752. height: 0
  13753. }
  13754. },
  13755. update: {
  13756. easing: 'linear',
  13757. duration: 450,
  13758. property: ['x', 'y', 'width', 'height']
  13759. }
  13760. }, animation)
  13761. });
  13762. }));
  13763. }));
  13764. });
  13765. var Polar$1 = (function (props) {
  13766. var coord = props.coord,
  13767. records = props.records,
  13768. animation = props.animation;
  13769. var center = coord.center,
  13770. startAngle = coord.startAngle,
  13771. endAngle = coord.endAngle,
  13772. radius = coord.radius;
  13773. return jsx("group", {
  13774. animation: {
  13775. appear: _objectSpread(_objectSpread({
  13776. easing: 'quadraticOut',
  13777. duration: 450
  13778. }, animation && animation.appear), {}, {
  13779. clip: {
  13780. type: 'sector',
  13781. property: ['endAngle'],
  13782. attrs: {
  13783. x: center.x,
  13784. y: center.y,
  13785. startAngle: startAngle,
  13786. r: radius
  13787. },
  13788. start: {
  13789. endAngle: startAngle
  13790. },
  13791. end: {
  13792. endAngle: endAngle
  13793. }
  13794. }
  13795. })
  13796. }
  13797. }, records.map(function (record) {
  13798. var key = record.key,
  13799. children = record.children;
  13800. return jsx("group", {
  13801. key: key
  13802. }, children.map(function (item) {
  13803. var key = item.key,
  13804. xMin = item.xMin,
  13805. xMax = item.xMax,
  13806. yMin = item.yMin,
  13807. yMax = item.yMax,
  13808. color = item.color,
  13809. shape = item.shape;
  13810. return jsx("sector", {
  13811. key: key,
  13812. attrs: _objectSpread({
  13813. x: center.x,
  13814. y: center.y,
  13815. fill: color,
  13816. startAngle: xMin,
  13817. endAngle: xMax,
  13818. r0: yMin,
  13819. r: yMax
  13820. }, shape),
  13821. animation: deepMix({
  13822. update: {
  13823. easing: 'linear',
  13824. duration: 450,
  13825. property: ['x', 'y', 'startAngle', 'endAngle', 'r0', 'r']
  13826. }
  13827. }, animation)
  13828. });
  13829. }));
  13830. }));
  13831. });
  13832. var intervalView = (function (props) {
  13833. var coord = props.coord;
  13834. var coordType = coord.type; // 直角坐标系
  13835. if (coordType === 'rect') {
  13836. return jsx(Rect$3, _objectSpread({}, props));
  13837. } // 极坐标系
  13838. return jsx(Polar$1, _objectSpread({}, props));
  13839. });
  13840. function convertToPoints(_ref) {
  13841. var xMin = _ref.xMin,
  13842. xMax = _ref.xMax,
  13843. yMin = _ref.yMin,
  13844. yMax = _ref.yMax;
  13845. return [{
  13846. x: xMin,
  13847. y: yMin
  13848. }, {
  13849. x: xMax,
  13850. y: yMin
  13851. }, {
  13852. x: xMax,
  13853. y: yMax
  13854. }, {
  13855. x: xMin,
  13856. y: yMax
  13857. } // bl
  13858. ];
  13859. }
  13860. var polygonView = (function (props) {
  13861. var records = props.records,
  13862. shape = props.shape,
  13863. showLabel = props.showLabel,
  13864. labelCfg = props.labelCfg,
  13865. LabelView = props.LabelView; // 是否倒置
  13866. var overturn = false;
  13867. return jsx("group", null, records.map(function (record, index) {
  13868. var key = record.key,
  13869. children = record.children;
  13870. var isLastRecord = index === records.length - 1;
  13871. var nextRecord = isLastRecord ? record : records[index + 1];
  13872. var nextChildren = nextRecord.children;
  13873. var nextFirstPoint = convertToPoints(nextChildren[0]);
  13874. var nextLastPoints = convertToPoints(nextChildren[nextChildren.length - 1]);
  13875. if (!overturn) {
  13876. overturn = nextChildren[0].yMax > children[0].yMax;
  13877. }
  13878. if (overturn) {
  13879. nextFirstPoint.reverse();
  13880. nextLastPoints.reverse();
  13881. }
  13882. var polygonPoints = children.map(function (child, childIndex) {
  13883. var points = convertToPoints(child);
  13884. if (overturn) {
  13885. points.reverse();
  13886. }
  13887. if (isLastRecord) {
  13888. if (shape === 'pyramid') {
  13889. points = [getMiddlePoint(points[0], points[1]), points[2], points[3]];
  13890. }
  13891. } else {
  13892. if (childIndex === 0) {
  13893. points[0] = nextFirstPoint[3];
  13894. }
  13895. if (childIndex === children.length - 1) {
  13896. points[1] = nextLastPoints[2];
  13897. }
  13898. }
  13899. return _objectSpread(_objectSpread({}, child), {}, {
  13900. points: points
  13901. });
  13902. });
  13903. return jsx("group", {
  13904. key: key
  13905. }, polygonPoints.map(function (child) {
  13906. var points = child.points,
  13907. color = child.color,
  13908. shape = child.shape;
  13909. return jsx("group", null, jsx("polygon", {
  13910. attrs: _objectSpread({
  13911. points: points,
  13912. fill: color
  13913. }, shape)
  13914. }), showLabel && LabelView ? jsx(LabelView, _objectSpread({
  13915. record: child,
  13916. points: points
  13917. }, labelCfg)) : null);
  13918. }));
  13919. }));
  13920. });
  13921. // 柱图/条图
  13922. var Views = /*#__PURE__*/Object.freeze({
  13923. __proto__: null,
  13924. rect: intervalView,
  13925. pyramid: polygonView,
  13926. funnel: polygonView
  13927. });
  13928. var index$2 = withInterval(Views);
  13929. var withPoint = (function (View) {
  13930. return /*#__PURE__*/function (_Geometry) {
  13931. _inherits(Point, _Geometry);
  13932. var _super = _createSuper(Point);
  13933. function Point() {
  13934. _classCallCheck(this, Point);
  13935. return _super.apply(this, arguments);
  13936. }
  13937. _createClass(Point, [{
  13938. key: "getDefaultCfg",
  13939. value: function getDefaultCfg() {
  13940. return {
  13941. geomType: 'point'
  13942. };
  13943. }
  13944. }, {
  13945. key: "render",
  13946. value: function render() {
  13947. var props = this.props,
  13948. container = this.container;
  13949. var coord = props.coord;
  13950. var records = this.mapping();
  13951. var clip = this.getClip();
  13952. return jsx(View, _objectSpread(_objectSpread({}, props), {}, {
  13953. coord: coord,
  13954. records: records,
  13955. clip: clip
  13956. }));
  13957. }
  13958. }]);
  13959. return Point;
  13960. }(Geometry);
  13961. });
  13962. var PointView = (function (props) {
  13963. var records = props.records,
  13964. animation = props.animation,
  13965. clip = props.clip;
  13966. return jsx("group", {
  13967. attrs: {
  13968. clip: clip
  13969. }
  13970. }, records.map(function (record) {
  13971. var key = record.key,
  13972. children = record.children;
  13973. return jsx("group", {
  13974. key: key
  13975. }, children.map(function (item) {
  13976. var x = item.x,
  13977. y = item.y,
  13978. size = item.size,
  13979. color = item.color,
  13980. shapeName = item.shapeName,
  13981. shape = item.shape;
  13982. if (isNaN(x) || isNaN(y)) {
  13983. return null;
  13984. }
  13985. if (shapeName === 'rect') {
  13986. var rectSize = isNil(size) ? shape.size : size;
  13987. return jsx("rect", {
  13988. attrs: _objectSpread(_objectSpread({
  13989. x: x - rectSize,
  13990. y: y - rectSize,
  13991. fill: color,
  13992. stroke: color
  13993. }, shape), {}, {
  13994. width: rectSize * 2,
  13995. height: rectSize * 2
  13996. }),
  13997. animation: deepMix({
  13998. appear: {
  13999. easing: 'linear',
  14000. duration: 450
  14001. },
  14002. update: {
  14003. easing: 'linear',
  14004. duration: 450,
  14005. property: ['x', 'y', 'width', 'height', 'fill']
  14006. }
  14007. }, animation)
  14008. });
  14009. }
  14010. return jsx("circle", {
  14011. attrs: _objectSpread(_objectSpread({
  14012. x: x,
  14013. y: y,
  14014. fill: shapeName === 'circle' ? color : null,
  14015. stroke: shapeName === 'hollowCircle' ? color : null
  14016. }, shape), {}, {
  14017. r: isNil(size) ? shape.size : size
  14018. }),
  14019. animation: deepMix({
  14020. appear: {
  14021. easing: 'linear',
  14022. duration: 450
  14023. },
  14024. update: {
  14025. easing: 'linear',
  14026. duration: 450,
  14027. property: ['x', 'y', 'r', 'fill']
  14028. }
  14029. }, animation)
  14030. });
  14031. }));
  14032. }));
  14033. });
  14034. var index$3 = withPoint(PointView);
  14035. var withAxis = (function (View) {
  14036. return /*#__PURE__*/function (_Component) {
  14037. _inherits(Axis, _Component);
  14038. var _super = _createSuper(Axis);
  14039. function Axis(props) {
  14040. var _this;
  14041. _classCallCheck(this, Axis);
  14042. _this = _super.call(this, props);
  14043. _this.style = {};
  14044. var _this$props = _this.props,
  14045. chart = _this$props.chart,
  14046. field = _this$props.field;
  14047. var scaleOption = _this.getScaleOption(props);
  14048. chart.setScale(field, scaleOption);
  14049. return _this;
  14050. }
  14051. _createClass(Axis, [{
  14052. key: "willReceiveProps",
  14053. value: function willReceiveProps(nextProps) {
  14054. var lastProps = this.props;
  14055. var chart = nextProps.chart,
  14056. field = nextProps.field;
  14057. var nextScaleOption = this.getScaleOption(nextProps);
  14058. var lastScaleOption = this.getScaleOption(lastProps);
  14059. if (!equal(nextScaleOption, lastScaleOption)) {
  14060. chart.setScale(field, nextScaleOption);
  14061. }
  14062. }
  14063. }, {
  14064. key: "willMount",
  14065. value: function willMount() {
  14066. this.updateCoord();
  14067. }
  14068. }, {
  14069. key: "willUpdate",
  14070. value: function willUpdate() {
  14071. this.updateCoord();
  14072. }
  14073. }, {
  14074. key: "getScaleOption",
  14075. value: function getScaleOption(props) {
  14076. var type = props.type,
  14077. tickCount = props.tickCount,
  14078. range = props.range,
  14079. mask = props.mask,
  14080. formatter = props.formatter,
  14081. min = props.min,
  14082. max = props.max,
  14083. nice = props.nice;
  14084. return {
  14085. type: type,
  14086. tickCount: tickCount,
  14087. range: range,
  14088. mask: mask,
  14089. formatter: formatter,
  14090. min: min,
  14091. max: max,
  14092. nice: nice
  14093. };
  14094. }
  14095. }, {
  14096. key: "_getDimType",
  14097. value: function _getDimType() {
  14098. var props = this.props;
  14099. var field = props.field,
  14100. chart = props.chart;
  14101. var xScales = chart.getXScales();
  14102. var scales = xScales.filter(function (scale) {
  14103. return scale.field === field;
  14104. });
  14105. return scales.length > 0 ? 'x' : 'y';
  14106. } // 获取ticks最大的宽高
  14107. }, {
  14108. key: "getMaxBBox",
  14109. value: function getMaxBBox(ticks, style) {
  14110. var context = this.context;
  14111. var measureText = context.measureText;
  14112. var label = style.label,
  14113. labelOffset = style.labelOffset;
  14114. var width = 0;
  14115. var height = 0;
  14116. ticks.forEach(function (tick) {
  14117. if (!label) return;
  14118. var labelStyle = tick.labelStyle,
  14119. text = tick.text;
  14120. var bbox = measureText(text, _objectSpread(_objectSpread({}, label), labelStyle));
  14121. width = Math.max(width, bbox.width);
  14122. height = Math.max(height, bbox.height);
  14123. });
  14124. if (!width && !height) {
  14125. return {
  14126. width: width,
  14127. height: height
  14128. };
  14129. }
  14130. var bbox = {
  14131. width: width + labelOffset,
  14132. height: height + labelOffset
  14133. };
  14134. return bbox;
  14135. }
  14136. }, {
  14137. key: "_getPosition",
  14138. value: function _getPosition() {
  14139. var props = this.props;
  14140. var position = props.position,
  14141. coord = props.coord;
  14142. if (position) {
  14143. return position;
  14144. }
  14145. var dimType = this._getDimType();
  14146. if (coord.transposed) {
  14147. return dimType === 'x' ? 'left' : 'bottom';
  14148. }
  14149. return dimType === 'x' ? 'bottom' : 'left';
  14150. }
  14151. }, {
  14152. key: "getTicks",
  14153. value: function getTicks() {
  14154. var props = this.props;
  14155. var field = props.field,
  14156. chart = props.chart;
  14157. var scale = chart.getScale(field);
  14158. var ticks = scale.getTicks(); // 设置tick的样式
  14159. ticks = this._setTicksStyle(ticks);
  14160. ticks = this._generateGridPoints(ticks);
  14161. return ticks;
  14162. }
  14163. /**
  14164. * 生成极坐标下网格线的交叉点
  14165. * @param ticks
  14166. * @returns
  14167. */
  14168. }, {
  14169. key: "_generateGridPoints",
  14170. value: function _generateGridPoints(ticks) {
  14171. var props = this.props;
  14172. var chart = props.chart,
  14173. coord = props.coord;
  14174. if (!coord.isPolar) {
  14175. return ticks;
  14176. }
  14177. var dimType = this._getDimType(); // 只需要在 y 的时候生成
  14178. if (dimType !== 'y') {
  14179. return ticks;
  14180. }
  14181. var xScale = chart.getXScales()[0];
  14182. var xTicks = xScale.getTicks();
  14183. ticks.forEach(function (tick) {
  14184. var gridPoints = xTicks.map(function (xTick) {
  14185. return coord.convertPoint({
  14186. x: xTick.value,
  14187. y: tick.value
  14188. });
  14189. }); // 添加第 1 个点,形成环状
  14190. gridPoints.push(gridPoints[0]);
  14191. tick.gridPoints = gridPoints;
  14192. });
  14193. return ticks;
  14194. }
  14195. }, {
  14196. key: "_setTicksStyle",
  14197. value: function _setTicksStyle(ticks) {
  14198. var _this2 = this;
  14199. var props = this.props,
  14200. context = this.context;
  14201. var theme = context.theme,
  14202. px2hd = context.px2hd;
  14203. var _props$style = props.style,
  14204. style = _props$style === void 0 ? {} : _props$style;
  14205. var themeAxis = theme.axis;
  14206. each(themeAxis, function (value, key) {
  14207. // 关闭tick的样式
  14208. if (style[key] === null) {
  14209. return;
  14210. }
  14211. var styleValue = isFunction(style[key]) ? undefined : style[key];
  14212. if (isString(value) || isNumber(value)) {
  14213. _this2.style[key] = px2hd(styleValue) || value;
  14214. } else {
  14215. _this2.style[key] = px2hd(deepMix(clone(value), styleValue));
  14216. }
  14217. });
  14218. return ticks.map(function (tick, index) {
  14219. var label = style.label,
  14220. grid = style.grid;
  14221. var defaultLabelStyle = themeAxis.label,
  14222. defaultGridStyle = themeAxis.grid;
  14223. if (isFunction(label)) {
  14224. tick.labelStyle = px2hd(mix({}, defaultLabelStyle, label(tick.text, index, ticks)));
  14225. }
  14226. if (isFunction(grid)) {
  14227. tick.gridStyle = px2hd(mix({}, defaultGridStyle, grid(tick.text, index, ticks.length)));
  14228. }
  14229. return tick;
  14230. });
  14231. }
  14232. }, {
  14233. key: "convertTicks",
  14234. value: function convertTicks(ticks) {
  14235. var props = this.props;
  14236. var coord = props.coord;
  14237. var dimType = this._getDimType();
  14238. var otherDim = dimType === 'x' ? 'y' : 'x';
  14239. return ticks.map(function (tick) {
  14240. var _coord$convertPoint, _coord$convertPoint2;
  14241. var start = coord.convertPoint((_coord$convertPoint = {}, _defineProperty(_coord$convertPoint, dimType, tick.value), _defineProperty(_coord$convertPoint, otherDim, 0), _coord$convertPoint));
  14242. var end = coord.convertPoint((_coord$convertPoint2 = {}, _defineProperty(_coord$convertPoint2, dimType, tick.value), _defineProperty(_coord$convertPoint2, otherDim, 1), _coord$convertPoint2));
  14243. return _objectSpread(_objectSpread({}, tick), {}, {
  14244. points: [start, end]
  14245. });
  14246. });
  14247. }
  14248. }, {
  14249. key: "measureLayout",
  14250. value: function measureLayout() {
  14251. var props = this.props;
  14252. var visible = props.visible,
  14253. coord = props.coord;
  14254. if (visible === false) {
  14255. return null;
  14256. }
  14257. var ticks = this.getTicks();
  14258. var bbox = this.getMaxBBox(ticks, this.style);
  14259. var isPolar = coord.isPolar;
  14260. var dimType = this._getDimType();
  14261. var width = bbox.width,
  14262. height = bbox.height;
  14263. if (isPolar) {
  14264. // 机坐标系的 y 不占位置
  14265. if (dimType === 'y') {
  14266. return null;
  14267. } // 4 个方向都需要留空
  14268. return ['top', 'right', 'bottom', 'left'].map(function (position) {
  14269. return {
  14270. position: position,
  14271. width: width,
  14272. height: height
  14273. };
  14274. });
  14275. } // 直角坐标系下
  14276. var position = this._getPosition();
  14277. return {
  14278. position: position,
  14279. width: width,
  14280. height: height
  14281. };
  14282. } // 主要是计算coord的布局
  14283. }, {
  14284. key: "updateCoord",
  14285. value: function updateCoord() {
  14286. var props = this.props;
  14287. var chart = props.chart;
  14288. var layout = this.measureLayout();
  14289. chart.updateCoordFor(this, layout);
  14290. }
  14291. }, {
  14292. key: "render",
  14293. value: function render() {
  14294. var props = this.props,
  14295. style = this.style;
  14296. var visible = props.visible,
  14297. coord = props.coord;
  14298. if (visible === false) {
  14299. return null;
  14300. }
  14301. var ticks = this.getTicks();
  14302. var position = this._getPosition();
  14303. var dimType = this._getDimType();
  14304. return jsx(View, _objectSpread(_objectSpread({}, props), {}, {
  14305. style: style,
  14306. ticks: this.convertTicks(ticks),
  14307. coord: coord,
  14308. position: position,
  14309. dimType: dimType
  14310. }));
  14311. }
  14312. }]);
  14313. return Axis;
  14314. }(Component);
  14315. });
  14316. // 相对圆心偏移量的点
  14317. function getOffsetPoint(center, point, offset) {
  14318. var vectorX = point.x - center.x;
  14319. var vectorY = point.y - center.y;
  14320. var vector = [vectorX, vectorY];
  14321. var vectorLength = Vector2.length(vector);
  14322. var offsetLength = vectorLength + offset;
  14323. var x = vectorX / vectorLength * offsetLength;
  14324. var y = vectorY / vectorLength * offsetLength;
  14325. return {
  14326. x: center.x + x,
  14327. y: center.y + y
  14328. };
  14329. } // 获取文本的对齐方式
  14330. function getTextAlignInfo(center, point) {
  14331. // 文本点向量
  14332. var vector = [point.x - center.x, point.y - center.y];
  14333. var align;
  14334. var baseLine; // 水平对齐
  14335. if (vector[0] > 0) {
  14336. align = 'left';
  14337. } else if (vector[0] < 0) {
  14338. align = 'right';
  14339. } else {
  14340. align = 'center';
  14341. } // 垂直对齐
  14342. if (vector[1] > 0) {
  14343. baseLine = 'top';
  14344. } else if (vector[1] < 0) {
  14345. baseLine = 'bottom';
  14346. } else {
  14347. baseLine = 'middle';
  14348. }
  14349. return {
  14350. textAlign: align,
  14351. textBaseline: baseLine
  14352. };
  14353. }
  14354. var Line$1 = function Line(props) {
  14355. var line = props.line,
  14356. gridType = props.gridType,
  14357. center = props.center,
  14358. radius = props.radius,
  14359. ticks = props.ticks;
  14360. if (!line) return null;
  14361. if (gridType !== 'line') {
  14362. return jsx("arc", {
  14363. attrs: _objectSpread({
  14364. x: center.x,
  14365. y: center.y,
  14366. r: radius
  14367. }, line)
  14368. });
  14369. }
  14370. var points = ticks.map(function (tick) {
  14371. var points = tick.points;
  14372. return points[points.length - 1];
  14373. }); // 头尾相连
  14374. points.push(points[0]);
  14375. return jsx("polyline", {
  14376. attrs: _objectSpread({
  14377. points: points
  14378. }, line)
  14379. });
  14380. };
  14381. var PolarX = (function (props) {
  14382. var ticks = props.ticks,
  14383. coord = props.coord,
  14384. style = props.style,
  14385. gridType = props.grid;
  14386. var center = coord.center;
  14387. var grid = style.grid,
  14388. tickLine = style.tickLine,
  14389. line = style.line,
  14390. labelOffset = style.labelOffset,
  14391. label = style.label;
  14392. var firstTicks = ticks[0];
  14393. var points = firstTicks.points;
  14394. var end = points[points.length - 1];
  14395. var radius = Vector2.length([end.x - center.x, end.y - center.y]);
  14396. return jsx("group", null, grid ? ticks.map(function (tick) {
  14397. var points = tick.points,
  14398. gridStyle = tick.gridStyle;
  14399. var end = points[points.length - 1];
  14400. return jsx("line", {
  14401. attrs: _objectSpread(_objectSpread({
  14402. x1: center.x,
  14403. y1: center.y,
  14404. x2: end.x,
  14405. y2: end.y
  14406. }, grid), gridStyle)
  14407. });
  14408. }) : null, tickLine && tickLine.length ? ticks.map(function (tick) {
  14409. var points = tick.points;
  14410. var end = points[points.length - 1];
  14411. var offsetPoint = getOffsetPoint(center, end, tickLine.length);
  14412. return jsx("line", {
  14413. attrs: _objectSpread({
  14414. x1: end.x,
  14415. y1: end.y,
  14416. x2: offsetPoint.x,
  14417. y2: offsetPoint.y
  14418. }, tickLine)
  14419. });
  14420. }) : null, jsx(Line$1, {
  14421. line: line,
  14422. gridType: gridType,
  14423. center: center,
  14424. radius: radius,
  14425. ticks: ticks
  14426. }), label ? ticks.map(function (tick) {
  14427. var points = tick.points,
  14428. text = tick.text,
  14429. labelStyle = tick.labelStyle;
  14430. var end = points[points.length - 1];
  14431. var offsetPoint = getOffsetPoint(center, end, labelOffset);
  14432. return jsx("text", {
  14433. attrs: _objectSpread(_objectSpread(_objectSpread({
  14434. x: offsetPoint.x,
  14435. y: offsetPoint.y,
  14436. text: text
  14437. }, getTextAlignInfo(center, end)), label), labelStyle)
  14438. });
  14439. }) : null);
  14440. });
  14441. var PolarY = (function (props) {
  14442. var ticks = props.ticks,
  14443. coord = props.coord,
  14444. style = props.style,
  14445. gridType = props.grid;
  14446. var center = coord.center;
  14447. var grid = style.grid,
  14448. tickLine = style.tickLine,
  14449. line = style.line,
  14450. labelOffset = style.labelOffset,
  14451. label = style.label;
  14452. return jsx("group", null, grid ? ticks.map(function (tick) {
  14453. var points = tick.points,
  14454. gridStyle = tick.gridStyle,
  14455. gridPoints = tick.gridPoints;
  14456. var end = points[points.length - 1];
  14457. if (gridType !== 'line') {
  14458. return jsx("arc", {
  14459. attrs: _objectSpread(_objectSpread({
  14460. x: center.x,
  14461. y: center.y,
  14462. r: Vector2.length([end.x - center.x, end.y - center.y])
  14463. }, grid), gridStyle)
  14464. });
  14465. }
  14466. return jsx("polyline", {
  14467. attrs: _objectSpread(_objectSpread({
  14468. points: gridPoints
  14469. }, grid), gridStyle)
  14470. });
  14471. }) : null, tickLine && tickLine.length ? ticks.map(function (tick) {
  14472. var points = tick.points;
  14473. var end = points[points.length - 1];
  14474. return jsx("line", {
  14475. attrs: _objectSpread({
  14476. x1: end.x,
  14477. y1: end.y,
  14478. x2: end.x - tickLine.length,
  14479. y2: end.y
  14480. }, tickLine)
  14481. });
  14482. }) : null, line ? jsx("line", {
  14483. attrs: _objectSpread({
  14484. x1: ticks[0].points[0].x,
  14485. y1: ticks[0].points[0].y,
  14486. x2: ticks[ticks.length - 1].points[0].x,
  14487. y2: ticks[ticks.length - 1].points[0].y
  14488. }, line)
  14489. }) : null, label ? ticks.map(function (tick) {
  14490. var points = tick.points,
  14491. text = tick.text,
  14492. labelStyle = tick.labelStyle;
  14493. var end = points[points.length - 1];
  14494. return jsx("text", {
  14495. attrs: _objectSpread(_objectSpread({
  14496. x: end.x - labelOffset,
  14497. y: end.y,
  14498. text: text,
  14499. textAlign: 'right',
  14500. textBaseline: 'middle'
  14501. }, label), labelStyle)
  14502. });
  14503. }) : null);
  14504. });
  14505. var Top = (function (props) {
  14506. var ticks = props.ticks,
  14507. coord = props.coord,
  14508. style = props.style;
  14509. var left = coord.left,
  14510. top = coord.top,
  14511. right = coord.right;
  14512. var grid = style.grid,
  14513. tickLine = style.tickLine,
  14514. line = style.line,
  14515. labelOffset = style.labelOffset,
  14516. label = style.label;
  14517. return jsx("group", null, grid ? ticks.map(function (tick) {
  14518. var points = tick.points,
  14519. gridStyle = tick.gridStyle;
  14520. var start = points[0];
  14521. var end = points[points.length - 1];
  14522. return jsx("line", {
  14523. attrs: _objectSpread(_objectSpread({
  14524. x1: start.x,
  14525. y1: start.y,
  14526. x2: end.x,
  14527. y2: end.y
  14528. }, grid), gridStyle)
  14529. });
  14530. }) : null, tickLine && tickLine.length ? ticks.map(function (tick) {
  14531. var points = tick.points;
  14532. var end = points[points.length - 1];
  14533. return jsx("line", {
  14534. attrs: _objectSpread({
  14535. x1: end.x,
  14536. y1: end.y,
  14537. x2: end.x,
  14538. y2: end.y - tickLine.length
  14539. }, tickLine)
  14540. });
  14541. }) : null, line ? jsx("line", {
  14542. attrs: _objectSpread({
  14543. x1: left,
  14544. y1: top,
  14545. x2: right,
  14546. y2: top
  14547. }, line)
  14548. }) : null, label ? ticks.map(function (tick, _index) {
  14549. var points = tick.points,
  14550. text = tick.text,
  14551. labelStyle = tick.labelStyle;
  14552. var end = points[points.length - 1];
  14553. return jsx("text", {
  14554. attrs: _objectSpread(_objectSpread({
  14555. x: end.x,
  14556. y: end.y - labelOffset,
  14557. textAlign: 'center',
  14558. textBaseline: 'bottom',
  14559. text: text
  14560. }, label), labelStyle)
  14561. });
  14562. }) : null);
  14563. });
  14564. var Bottom = (function (props, context) {
  14565. var ticks = props.ticks,
  14566. coord = props.coord,
  14567. style = props.style,
  14568. animation = props.animation;
  14569. var px2hd = context.px2hd;
  14570. var left = coord.left,
  14571. right = coord.right,
  14572. bottom = coord.bottom;
  14573. var grid = style.grid,
  14574. tickLine = style.tickLine,
  14575. line = style.line,
  14576. labelOffset = style.labelOffset,
  14577. label = style.label;
  14578. return jsx("group", null, grid ? ticks.map(function (tick) {
  14579. var points = tick.points,
  14580. tickValue = tick.tickValue,
  14581. gridStyle = tick.gridStyle;
  14582. var start = points[0];
  14583. var end = points[points.length - 1];
  14584. return jsx("line", {
  14585. key: tickValue,
  14586. attrs: _objectSpread(_objectSpread({
  14587. x1: start.x,
  14588. y1: start.y,
  14589. x2: end.x,
  14590. y2: end.y
  14591. }, grid), gridStyle)
  14592. });
  14593. }) : null, tickLine && tickLine.length ? ticks.map(function (tick) {
  14594. var points = tick.points,
  14595. tickValue = tick.tickValue;
  14596. var start = points[0];
  14597. return jsx("line", {
  14598. key: tickValue,
  14599. attrs: _objectSpread({
  14600. x1: start.x,
  14601. y1: start.y,
  14602. x2: start.x,
  14603. y2: start.y + px2hd(tickLine.length)
  14604. }, tickLine)
  14605. });
  14606. }) : null, line ? jsx("line", {
  14607. attrs: _objectSpread({
  14608. x1: left,
  14609. y1: bottom,
  14610. x2: right,
  14611. y2: bottom
  14612. }, line)
  14613. }) : null, label ? ticks.map(function (tick, index) {
  14614. var points = tick.points,
  14615. text = tick.text,
  14616. tickValue = tick.tickValue,
  14617. labelStyle = tick.labelStyle;
  14618. var start = points[0];
  14619. var _ref = labelStyle || label || {},
  14620. _ref$align = _ref.align,
  14621. align = _ref$align === void 0 ? 'center' : _ref$align;
  14622. var textAttrs = _objectSpread(_objectSpread({
  14623. x: start.x,
  14624. y: start.y + labelOffset,
  14625. textBaseline: 'top',
  14626. text: text
  14627. }, label), labelStyle);
  14628. if (align === 'between') {
  14629. if (index === 0) {
  14630. textAttrs.textAlign = 'start';
  14631. } else if (index === ticks.length - 1) {
  14632. textAttrs.textAlign = 'end';
  14633. } else {
  14634. textAttrs.textAlign = 'center';
  14635. }
  14636. } else {
  14637. textAttrs.textAlign = align;
  14638. }
  14639. return jsx("text", {
  14640. key: tickValue,
  14641. attrs: textAttrs,
  14642. animation: animation || {
  14643. appear: {
  14644. easing: 'linear',
  14645. duration: 300,
  14646. delay: 0,
  14647. property: ['fillOpacity'],
  14648. start: {
  14649. fillOpacity: 0
  14650. },
  14651. end: {
  14652. fillOpacity: 1
  14653. }
  14654. },
  14655. update: {
  14656. easing: 'linear',
  14657. duration: 450,
  14658. delay: 0,
  14659. property: ['x', 'y']
  14660. },
  14661. leave: {
  14662. easing: 'linear',
  14663. duration: 450,
  14664. delay: 0,
  14665. property: ['fillOpacity'],
  14666. start: {
  14667. fillOpacity: 1
  14668. },
  14669. end: {
  14670. fillOpacity: 0
  14671. }
  14672. }
  14673. }
  14674. });
  14675. }) : null);
  14676. });
  14677. var Right = (function (props) {
  14678. var ticks = props.ticks,
  14679. coord = props.coord,
  14680. style = props.style;
  14681. var top = coord.top,
  14682. right = coord.right,
  14683. bottom = coord.bottom;
  14684. var grid = style.grid,
  14685. tickLine = style.tickLine,
  14686. line = style.line,
  14687. labelOffset = style.labelOffset,
  14688. label = style.label;
  14689. return jsx("group", null, grid ? ticks.map(function (tick) {
  14690. var points = tick.points,
  14691. gridStyle = tick.gridStyle;
  14692. var start = points[0];
  14693. var end = points[points.length - 1];
  14694. return jsx("line", {
  14695. attrs: _objectSpread(_objectSpread({
  14696. x1: start.x,
  14697. y1: start.y,
  14698. x2: end.x,
  14699. y2: end.y
  14700. }, grid), gridStyle)
  14701. });
  14702. }) : null, tickLine && tickLine.length ? ticks.map(function (tick) {
  14703. var points = tick.points;
  14704. var end = points[points.length - 1];
  14705. return jsx("line", {
  14706. attrs: _objectSpread({
  14707. x1: end.x,
  14708. y1: end.y,
  14709. x2: end.x + tickLine.length,
  14710. y2: end.y
  14711. }, tickLine)
  14712. });
  14713. }) : null, line ? jsx("line", {
  14714. attrs: _objectSpread({
  14715. x1: right,
  14716. y1: top,
  14717. x2: right,
  14718. y2: bottom
  14719. }, line)
  14720. }) : null, label ? ticks.map(function (tick, _index) {
  14721. var points = tick.points,
  14722. text = tick.text,
  14723. labelStyle = tick.labelStyle;
  14724. var end = points[points.length - 1];
  14725. return jsx("text", {
  14726. attrs: _objectSpread(_objectSpread({
  14727. x: end.x + labelOffset,
  14728. y: end.y,
  14729. textAlign: 'left',
  14730. textBaseline: 'middle',
  14731. text: text
  14732. }, label), labelStyle)
  14733. });
  14734. }) : null);
  14735. });
  14736. var Left = (function (props) {
  14737. var ticks = props.ticks,
  14738. coord = props.coord,
  14739. style = props.style,
  14740. animation = props.animation;
  14741. var left = coord.left,
  14742. top = coord.top,
  14743. bottom = coord.bottom;
  14744. var grid = style.grid,
  14745. tickLine = style.tickLine,
  14746. line = style.line,
  14747. labelOffset = style.labelOffset,
  14748. label = style.label;
  14749. return jsx("group", null, grid ? ticks.map(function (tick) {
  14750. var points = tick.points,
  14751. tickValue = tick.tickValue,
  14752. gridStyle = tick.gridStyle;
  14753. var start = points[0];
  14754. var end = points[points.length - 1];
  14755. return jsx("line", {
  14756. key: tickValue,
  14757. attrs: _objectSpread(_objectSpread({
  14758. x1: start.x,
  14759. y1: start.y,
  14760. x2: end.x,
  14761. y2: end.y
  14762. }, grid), gridStyle)
  14763. });
  14764. }) : null, tickLine && tickLine.length ? ticks.map(function (tick) {
  14765. var points = tick.points,
  14766. tickValue = tick.tickValue;
  14767. var start = points[0];
  14768. return jsx("line", {
  14769. key: tickValue,
  14770. attrs: _objectSpread({
  14771. x1: start.x,
  14772. y1: start.y,
  14773. x2: start.x - tickLine.length,
  14774. y2: start.y
  14775. }, tickLine)
  14776. });
  14777. }) : null, line ? jsx("line", {
  14778. attrs: _objectSpread({
  14779. x1: left,
  14780. y1: top,
  14781. x2: left,
  14782. y2: bottom
  14783. }, line)
  14784. }) : null, label ? ticks.map(function (tick, _index) {
  14785. var tickValue = tick.tickValue,
  14786. points = tick.points,
  14787. text = tick.text,
  14788. labelStyle = tick.labelStyle;
  14789. var start = points[0];
  14790. return jsx("text", {
  14791. key: tickValue,
  14792. attrs: _objectSpread(_objectSpread({
  14793. x: start.x - labelOffset,
  14794. y: start.y,
  14795. textAlign: 'right',
  14796. textBaseline: 'middle',
  14797. text: text
  14798. }, label), labelStyle),
  14799. animation: animation || {
  14800. appear: {
  14801. easing: 'linear',
  14802. duration: 300,
  14803. delay: 0,
  14804. property: ['fillOpacity'],
  14805. start: {
  14806. fillOpacity: 0
  14807. },
  14808. end: {
  14809. fillOpacity: 1
  14810. }
  14811. },
  14812. update: {
  14813. easing: 'linear',
  14814. duration: 450,
  14815. delay: 0,
  14816. property: ['x', 'y']
  14817. },
  14818. leave: {
  14819. easing: 'linear',
  14820. duration: 450,
  14821. delay: 0,
  14822. property: ['fillOpacity'],
  14823. start: {
  14824. fillOpacity: 1
  14825. },
  14826. end: {
  14827. fillOpacity: 0
  14828. }
  14829. }
  14830. }
  14831. });
  14832. }) : null);
  14833. });
  14834. function isPolar(props) {
  14835. return props.coord.isPolar;
  14836. }
  14837. var AxisView = (function (props) {
  14838. // 极坐标
  14839. if (isPolar(props)) {
  14840. var dimType = props.dimType;
  14841. if (dimType === 'x') {
  14842. return jsx(PolarX, _objectSpread({}, props));
  14843. }
  14844. return jsx(PolarY, _objectSpread({}, props));
  14845. }
  14846. var position = props.position; // 直角坐标
  14847. if (position === 'right') {
  14848. return jsx(Right, _objectSpread({}, props));
  14849. }
  14850. if (position === 'left') {
  14851. return jsx(Left, _objectSpread({}, props));
  14852. }
  14853. if (position === 'top') {
  14854. return jsx(Top, _objectSpread({}, props));
  14855. }
  14856. return jsx(Bottom, _objectSpread({}, props));
  14857. });
  14858. var index$4 = withAxis(AxisView);
  14859. var withLegend = (function (View) {
  14860. return /*#__PURE__*/function (_Component) {
  14861. _inherits(Legend, _Component);
  14862. var _super = _createSuper(Legend);
  14863. function Legend(props) {
  14864. var _this;
  14865. _classCallCheck(this, Legend);
  14866. _this = _super.call(this, props);
  14867. _this.state = {
  14868. filtered: {},
  14869. items: []
  14870. };
  14871. return _this;
  14872. }
  14873. _createClass(Legend, [{
  14874. key: "getOriginItems",
  14875. value: function getOriginItems() {
  14876. var chart = this.props.chart;
  14877. return chart.getLegendItems();
  14878. }
  14879. }, {
  14880. key: "getItems",
  14881. value: function getItems() {
  14882. var _props$items;
  14883. var props = this.props,
  14884. state = this.state;
  14885. var filtered = state.filtered;
  14886. var renderItems = ((_props$items = props.items) === null || _props$items === void 0 ? void 0 : _props$items.length) ? props.items : this.getOriginItems();
  14887. if (!renderItems) return null;
  14888. return renderItems.map(function (item) {
  14889. var tickValue = item.tickValue;
  14890. return _objectSpread(_objectSpread({}, item), {}, {
  14891. filtered: filtered[tickValue]
  14892. });
  14893. });
  14894. }
  14895. }, {
  14896. key: "setItems",
  14897. value: function setItems(items) {
  14898. this.setState({
  14899. items: items
  14900. });
  14901. }
  14902. }, {
  14903. key: "getMaxItemBox",
  14904. value: function getMaxItemBox(legendShape) {
  14905. var maxItemWidth = 0;
  14906. var maxItemHeight = 0;
  14907. (legendShape.get('children') || []).forEach(function (child) {
  14908. var _child$get = child.get('attrs'),
  14909. width = _child$get.width,
  14910. height = _child$get.height;
  14911. maxItemWidth = Math.max(maxItemWidth, width);
  14912. maxItemHeight = Math.max(maxItemHeight, height);
  14913. });
  14914. return {
  14915. width: maxItemWidth,
  14916. height: maxItemHeight
  14917. };
  14918. } // 计算 legend 的位置
  14919. }, {
  14920. key: "_init",
  14921. value: function _init() {
  14922. var props = this.props,
  14923. context = this.context;
  14924. var parentLayout = props.layout,
  14925. customWidth = props.width,
  14926. customHeight = props.height,
  14927. _props$position = props.position,
  14928. position = _props$position === void 0 ? 'top' : _props$position;
  14929. var items = this.getItems();
  14930. if (!items || !items.length) return;
  14931. var left = parentLayout.left,
  14932. top = parentLayout.top,
  14933. right = parentLayout.right,
  14934. bottom = parentLayout.bottom,
  14935. layoutWidth = parentLayout.width,
  14936. layoutHeight = parentLayout.height;
  14937. var width = context.px2hd(customWidth) || layoutWidth;
  14938. var shape = renderShape(this, this.render(), false);
  14939. var _this$getMaxItemBox = this.getMaxItemBox(shape),
  14940. itemMaxWidth = _this$getMaxItemBox.width,
  14941. itemMaxHeight = _this$getMaxItemBox.height; // 每行最多的个数
  14942. var lineMaxCount = Math.floor(width / itemMaxWidth);
  14943. var itemCount = items.length; // legend item 的行数
  14944. var lineCount = Math.ceil(itemCount / lineMaxCount);
  14945. var itemWidth = width / lineMaxCount;
  14946. var autoHeight = itemMaxHeight * lineCount;
  14947. var style = {
  14948. left: left,
  14949. top: top,
  14950. width: width,
  14951. // height 默认自适应
  14952. height: undefined,
  14953. flexDirection: 'row',
  14954. flexWrap: 'wrap',
  14955. alignItems: 'center',
  14956. justifyContent: 'flex-start'
  14957. }; // 如果只有一行,2端对齐
  14958. if (lineCount === 1) {
  14959. style.justifyContent = 'space-between';
  14960. }
  14961. if (position === 'top') {
  14962. style.height = customHeight ? customHeight : autoHeight;
  14963. }
  14964. if (position === 'left') {
  14965. style.flexDirection = 'column';
  14966. style.justifyContent = 'center';
  14967. style.width = itemMaxWidth;
  14968. style.height = customHeight ? customHeight : layoutHeight;
  14969. }
  14970. if (position === 'right') {
  14971. style.flexDirection = 'column';
  14972. style.alignItems = 'flex-start';
  14973. style.justifyContent = 'center';
  14974. style.width = itemMaxWidth;
  14975. style.height = customHeight ? customHeight : layoutHeight;
  14976. style.left = right - itemMaxWidth;
  14977. }
  14978. if (position === 'bottom') {
  14979. style.top = bottom - autoHeight;
  14980. style.height = customHeight ? customHeight : autoHeight;
  14981. }
  14982. this.itemWidth = itemWidth;
  14983. this.style = style;
  14984. shape.remove();
  14985. }
  14986. }, {
  14987. key: "updateCoord",
  14988. value: function updateCoord() {
  14989. var context = this.context,
  14990. props = this.props,
  14991. style = this.style;
  14992. var _props$position2 = props.position,
  14993. position = _props$position2 === void 0 ? 'top' : _props$position2,
  14994. _props$margin = props.margin,
  14995. margin = _props$margin === void 0 ? '30px' : _props$margin,
  14996. chart = props.chart;
  14997. var width = style.width,
  14998. height = style.height;
  14999. var marginNumber = context.px2hd(margin);
  15000. chart.updateCoordFor(this, {
  15001. position: position,
  15002. width: width + marginNumber,
  15003. height: height + marginNumber
  15004. });
  15005. }
  15006. }, {
  15007. key: "willMount",
  15008. value: function willMount() {
  15009. var items = this.getItems();
  15010. if (!items || !items.length) return;
  15011. this._init();
  15012. this.updateCoord();
  15013. }
  15014. }, {
  15015. key: "didMount",
  15016. value: function didMount() {
  15017. this._initEvent();
  15018. }
  15019. }, {
  15020. key: "willUpdate",
  15021. value: function willUpdate() {
  15022. var items = this.getItems();
  15023. if (!items || !items.length) return;
  15024. this.updateCoord();
  15025. }
  15026. }, {
  15027. key: "_initEvent",
  15028. value: function _initEvent() {
  15029. var _this2 = this;
  15030. var context = this.context,
  15031. props = this.props,
  15032. container = this.container;
  15033. var canvas = context.canvas;
  15034. var chart = props.chart,
  15035. _props$clickable = props.clickable,
  15036. clickable = _props$clickable === void 0 ? true : _props$clickable,
  15037. onClick = props.onClick;
  15038. if (!clickable) return; // item 点击事件
  15039. canvas.on('click', function (ev) {
  15040. var points = ev.points;
  15041. var point = points[0];
  15042. var bbox = container.getBBox();
  15043. if (!isInBBox(bbox, point)) {
  15044. return;
  15045. }
  15046. var legendItems = getElementsByClassName('legend-item', container);
  15047. if (!legendItems.length) {
  15048. return;
  15049. }
  15050. var clickItem = find(legendItems, function (item) {
  15051. var itemBBox = item.getBBox();
  15052. return isInBBox(itemBBox, point);
  15053. });
  15054. if (!clickItem) {
  15055. return;
  15056. }
  15057. var dataItem = clickItem.get('data-item');
  15058. if (!dataItem) {
  15059. return;
  15060. }
  15061. if (isFunction(onClick)) {
  15062. onClick(dataItem);
  15063. }
  15064. var field = dataItem.field,
  15065. tickValue = dataItem.tickValue;
  15066. var prevFiltered = _this2.state.filtered;
  15067. var filtered = _objectSpread(_objectSpread({}, prevFiltered), {}, _defineProperty({}, tickValue, !prevFiltered[tickValue]));
  15068. _this2.setState({
  15069. filtered: filtered
  15070. });
  15071. chart.filter(field, function (value) {
  15072. return !filtered[value];
  15073. });
  15074. });
  15075. }
  15076. }, {
  15077. key: "render",
  15078. value: function render() {
  15079. var props = this.props,
  15080. itemWidth = this.itemWidth,
  15081. style = this.style;
  15082. var items = this.getItems();
  15083. if (!items || !items.length) {
  15084. return null;
  15085. }
  15086. return jsx(View, _objectSpread(_objectSpread({}, props), {}, {
  15087. items: items,
  15088. itemWidth: itemWidth,
  15089. style: _objectSpread(_objectSpread({}, style), props.style)
  15090. }));
  15091. }
  15092. }]);
  15093. return Legend;
  15094. }(Component);
  15095. });
  15096. var Marker$1 = function Marker(_ref) {
  15097. var type = _ref.type,
  15098. color = _ref.color;
  15099. if (type === 'square') {
  15100. return jsx("rect", {
  15101. style: {
  15102. width: '12px',
  15103. height: '12px',
  15104. marginRight: '10px'
  15105. },
  15106. attrs: {
  15107. fill: color
  15108. }
  15109. });
  15110. }
  15111. return jsx("circle", {
  15112. style: {
  15113. width: '12px',
  15114. height: '12px',
  15115. marginRight: '10px'
  15116. },
  15117. attrs: {
  15118. fill: color
  15119. }
  15120. });
  15121. };
  15122. var LegendView = (function (props) {
  15123. var items = props.items,
  15124. itemWidth = props.itemWidth,
  15125. itemFormatter = props.itemFormatter,
  15126. style = props.style,
  15127. _props$marker = props.marker,
  15128. marker = _props$marker === void 0 ? 'circle' : _props$marker,
  15129. nameStyle = props.nameStyle,
  15130. valueStyle = props.valueStyle,
  15131. valuePrefix = props.valuePrefix;
  15132. var formatValue = function formatValue(value) {
  15133. var valuePrefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ": ";
  15134. return "".concat(valuePrefix).concat(value);
  15135. };
  15136. return jsx("group", {
  15137. style: style
  15138. }, items.map(function (item) {
  15139. var color = item.color,
  15140. name = item.name,
  15141. value = item.value,
  15142. filtered = item.filtered,
  15143. tickValue = item.tickValue;
  15144. var valueText = isFunction(itemFormatter) ? itemFormatter(value, tickValue) : value;
  15145. return jsx("group", {
  15146. className: "legend-item",
  15147. style: {
  15148. width: itemWidth,
  15149. display: 'flex',
  15150. flexDirection: 'row',
  15151. alignItems: 'center',
  15152. justifyContent: 'flex-start',
  15153. padding: ['6px', '6px', '6px', 0]
  15154. },
  15155. "data-item": item
  15156. }, jsx(Marker$1, {
  15157. color: filtered ? '#bfbfbf' : color,
  15158. type: marker
  15159. }), jsx("text", {
  15160. attrs: _objectSpread({
  15161. fill: filtered ? '#bfbfbf' : '#808080',
  15162. text: name
  15163. }, nameStyle)
  15164. }), valueText ? jsx("text", {
  15165. attrs: _objectSpread({
  15166. fill: '#808080',
  15167. text: formatValue(valueText, valuePrefix)
  15168. }, valueStyle)
  15169. }) : null);
  15170. }));
  15171. });
  15172. var index$5 = withLegend(LegendView);
  15173. function isInBBox$1(bbox, point) {
  15174. var minX = bbox.minX,
  15175. maxX = bbox.maxX,
  15176. minY = bbox.minY,
  15177. maxY = bbox.maxY;
  15178. var x = point.x,
  15179. y = point.y;
  15180. return minX <= x && maxX >= x && minY <= y && maxY >= y;
  15181. }
  15182. var withGuide = (function (View) {
  15183. return /*#__PURE__*/function (_Component) {
  15184. _inherits(Guide, _Component);
  15185. var _super = _createSuper(Guide);
  15186. function Guide(props) {
  15187. var _this;
  15188. _classCallCheck(this, Guide);
  15189. _this = _super.call(this, props); // 创建ref
  15190. _this.triggerRef = {};
  15191. _this.state = {};
  15192. return _this;
  15193. }
  15194. _createClass(Guide, [{
  15195. key: "willMount",
  15196. value: function willMount() {
  15197. _get$1(_getPrototypeOf(Guide.prototype), "willMount", this).call(this);
  15198. this.getGuideBBox();
  15199. }
  15200. }, {
  15201. key: "didMount",
  15202. value: function didMount() {
  15203. var _this2 = this;
  15204. var context = this.context,
  15205. props = this.props;
  15206. var canvas = context.canvas;
  15207. var onClick = props.onClick;
  15208. canvas.on('click', function (ev) {
  15209. var points = ev.points;
  15210. var shape = _this2.triggerRef.current;
  15211. if (!shape || shape.isDestroyed()) return;
  15212. var bbox = shape.getBBox();
  15213. if (isInBBox$1(bbox, points[0])) {
  15214. ev.shape = shape;
  15215. onClick && onClick(ev);
  15216. }
  15217. });
  15218. }
  15219. }, {
  15220. key: "didUpdate",
  15221. value: function didUpdate() {
  15222. _get$1(_getPrototypeOf(Guide.prototype), "didUpdate", this).call(this);
  15223. var shape = this.triggerRef.current;
  15224. if (!shape || shape.isDestroyed()) return;
  15225. var _shape$get = shape.get('attrs'),
  15226. x = _shape$get.x,
  15227. y = _shape$get.y,
  15228. width = _shape$get.width,
  15229. height = _shape$get.height;
  15230. var bbox = {
  15231. minX: x,
  15232. minY: y,
  15233. maxX: x + width,
  15234. maxY: y + height,
  15235. width: width,
  15236. height: height
  15237. };
  15238. this.setState({
  15239. guideBBox: bbox
  15240. });
  15241. }
  15242. }, {
  15243. key: "getGuideBBox",
  15244. value: function getGuideBBox() {
  15245. var shape = renderShape(this, this.render(), false);
  15246. var _shape$get2 = shape.get('attrs'),
  15247. x = _shape$get2.x,
  15248. y = _shape$get2.y,
  15249. width = _shape$get2.width,
  15250. height = _shape$get2.height; // getBBox 没有包含 padding 所以这里手动计算 bbox
  15251. var bbox = {
  15252. minX: x,
  15253. minY: y,
  15254. maxX: x + width,
  15255. maxY: y + height,
  15256. width: width,
  15257. height: height
  15258. };
  15259. this.setState({
  15260. guideBBox: bbox
  15261. });
  15262. shape.destroy();
  15263. } // 解析record里的模板字符串,如min、max、50%...
  15264. }, {
  15265. key: "parseReplaceStr",
  15266. value: function parseReplaceStr(value, scale) {
  15267. var replaceMap = {
  15268. min: 0,
  15269. max: 1,
  15270. median: 0.5
  15271. }; // 传入的是 min、max、median 的
  15272. if (!isNil(replaceMap[value])) {
  15273. return replaceMap[value];
  15274. } // 传入的是 xx%
  15275. if (isString(value) && value.indexOf('%') != -1 && !isNaN(Number(value.slice(0, -1)))) {
  15276. var rateValue = Number(value.slice(0, -1));
  15277. var percent = rateValue / 100;
  15278. return percent;
  15279. }
  15280. return scale.scale(value);
  15281. }
  15282. }, {
  15283. key: "parsePoint",
  15284. value: function parsePoint(record) {
  15285. var props = this.props;
  15286. var chart = props.chart,
  15287. coord = props.coord;
  15288. var xScale = chart.getXScales()[0]; // 只取第一个yScale
  15289. var yScale = chart.getYScales()[0]; // 解析 record 为归一化后的坐标
  15290. var x = this.parseReplaceStr(record[xScale.field], xScale);
  15291. var y = this.parseReplaceStr(record[yScale.field], yScale);
  15292. return coord.convertPoint({
  15293. x: x,
  15294. y: y
  15295. });
  15296. }
  15297. }, {
  15298. key: "convertPoints",
  15299. value: function convertPoints(records) {
  15300. var _this3 = this;
  15301. return records.map(function (record) {
  15302. return _this3.parsePoint(record);
  15303. });
  15304. }
  15305. }, {
  15306. key: "getGuideTheme",
  15307. value: function getGuideTheme() {
  15308. var context = this.context;
  15309. var theme = context.theme;
  15310. return theme.guide;
  15311. }
  15312. }, {
  15313. key: "render",
  15314. value: function render() {
  15315. var props = this.props,
  15316. context = this.context;
  15317. var coord = props.coord,
  15318. _props$records = props.records,
  15319. records = _props$records === void 0 ? [] : _props$records,
  15320. animation = props.animation,
  15321. chart = props.chart;
  15322. var width = context.width,
  15323. height = context.height;
  15324. var points = this.convertPoints(records);
  15325. var theme = this.getGuideTheme();
  15326. var guideBBox = this.state.guideBBox;
  15327. var animationCfg = animation;
  15328. if (isFunction(animation)) {
  15329. // 透传绘制关键点和chart实例
  15330. animationCfg = animation(points, chart);
  15331. }
  15332. return jsx(View, _objectSpread(_objectSpread({
  15333. triggerRef: this.triggerRef,
  15334. points: points,
  15335. theme: theme,
  15336. coord: coord
  15337. }, props), {}, {
  15338. canvasWidth: width,
  15339. canvasHeight: height,
  15340. guideBBox: guideBBox,
  15341. animation: animationCfg
  15342. }));
  15343. }
  15344. }]);
  15345. return Guide;
  15346. }(Component);
  15347. });
  15348. var TextGuideView = (function (props, context) {
  15349. var _props$theme = props.theme,
  15350. theme = _props$theme === void 0 ? {} : _props$theme;
  15351. var _deepMix = deepMix(_objectSpread({}, theme.text), props),
  15352. points = _deepMix.points,
  15353. style = _deepMix.style,
  15354. offsetX = _deepMix.offsetX,
  15355. offsetY = _deepMix.offsetY,
  15356. content = _deepMix.content,
  15357. animation = _deepMix.animation;
  15358. var _ref = points[0] || {},
  15359. x = _ref.x,
  15360. y = _ref.y;
  15361. var offsetXNum = context.px2hd(offsetX);
  15362. var offsetYNum = context.px2hd(offsetY);
  15363. var posX = x + (offsetXNum || 0);
  15364. var posY = y + (offsetYNum || 0);
  15365. return jsx("text", {
  15366. attrs: _objectSpread({
  15367. text: content,
  15368. x: posX,
  15369. y: posY
  15370. }, style),
  15371. animation: deepMix({
  15372. update: {
  15373. easing: 'linear',
  15374. duration: 450,
  15375. property: ['x', 'y']
  15376. }
  15377. }, animation)
  15378. });
  15379. });
  15380. var PointGuideView = (function (props, context) {
  15381. var theme = props.theme;
  15382. var _deepMix = deepMix(_objectSpread({}, theme.point), props),
  15383. points = _deepMix.points,
  15384. style = _deepMix.style,
  15385. offsetX = _deepMix.offsetX,
  15386. offsetY = _deepMix.offsetY,
  15387. animation = _deepMix.animation;
  15388. var _ref = points[0] || {},
  15389. x = _ref.x,
  15390. y = _ref.y;
  15391. var offsetXNum = context.px2hd(offsetX);
  15392. var offsetYNum = context.px2hd(offsetY);
  15393. var posX = x + (offsetXNum || 0);
  15394. var posY = y + (offsetYNum || 0);
  15395. return jsx("group", null, jsx("circle", {
  15396. attrs: _objectSpread({
  15397. x: posX,
  15398. y: posY
  15399. }, style),
  15400. animation: animation
  15401. }));
  15402. });
  15403. var LineGuideView = (function (props, context) {
  15404. var _props$theme = props.theme,
  15405. theme = _props$theme === void 0 ? {} : _props$theme;
  15406. var _deepMix = deepMix(_objectSpread({}, theme.line), props),
  15407. points = _deepMix.points,
  15408. style = _deepMix.style,
  15409. offsetX = _deepMix.offsetX,
  15410. offsetY = _deepMix.offsetY,
  15411. animation = _deepMix.animation;
  15412. var _ref = points[0] || {},
  15413. x1 = _ref.x,
  15414. y1 = _ref.y;
  15415. var _ref2 = points[1] || {},
  15416. x2 = _ref2.x,
  15417. y2 = _ref2.y;
  15418. var offsetXNum = context.px2hd(offsetX);
  15419. var offsetYNum = context.px2hd(offsetY);
  15420. var posX1 = x1 + (isArray(offsetXNum) ? offsetXNum[0] || 0 : offsetXNum || 0);
  15421. var posY1 = y1 + (isArray(offsetYNum) ? offsetYNum[0] || 0 : offsetYNum || 0);
  15422. var posX2 = x2 + (isArray(offsetXNum) ? offsetXNum[1] || 0 : offsetXNum || 0);
  15423. var posY2 = y2 + (isArray(offsetYNum) ? offsetYNum[1] || 0 : offsetYNum || 0);
  15424. return jsx("group", null, jsx("line", {
  15425. attrs: _objectSpread({
  15426. x1: posX1,
  15427. y1: posY1,
  15428. x2: posX2,
  15429. y2: posY2
  15430. }, style),
  15431. animation: animation
  15432. }));
  15433. });
  15434. var ArcGuideView = (function (props) {
  15435. var _props$theme = props.theme,
  15436. theme = _props$theme === void 0 ? {} : _props$theme;
  15437. var _deepMix = deepMix(_objectSpread({}, theme.line), props),
  15438. coord = _deepMix.coord,
  15439. points = _deepMix.points,
  15440. style = _deepMix.style,
  15441. animation = _deepMix.animation;
  15442. var start = points[0] || {};
  15443. var end = points[1] || {};
  15444. var coordCenter = coord.center;
  15445. var radius = Math.sqrt((start.x - coordCenter.x) * (start.x - coordCenter.x) + (start.y - coordCenter.y) * (start.y - coordCenter.y));
  15446. var startAngle = Math.atan2(start.y - coordCenter.y, start.x - coordCenter.x);
  15447. var endAngle = Math.atan2(end.y - coordCenter.y, end.x - coordCenter.x);
  15448. return jsx("group", null, jsx("arc", {
  15449. attrs: _objectSpread({
  15450. x: coordCenter.x,
  15451. y: coordCenter.y,
  15452. r: radius,
  15453. startAngle: startAngle,
  15454. endAngle: endAngle
  15455. }, style),
  15456. animation: animation
  15457. }));
  15458. });
  15459. var RectGuideView = (function (props) {
  15460. var _props$theme = props.theme,
  15461. theme = _props$theme === void 0 ? {} : _props$theme;
  15462. var _deepMix = deepMix(_objectSpread({}, theme.rect), props),
  15463. points = _deepMix.points,
  15464. style = _deepMix.style,
  15465. animation = _deepMix.animation;
  15466. var start = points[0] || {};
  15467. var end = points[1] || {};
  15468. return jsx("group", null, jsx("rect", {
  15469. attrs: _objectSpread({
  15470. x: Math.min(start.x, end.x),
  15471. y: Math.min(start.y, end.y),
  15472. width: Math.abs(end.x - start.x),
  15473. height: Math.abs(start.y - end.y)
  15474. }, style),
  15475. animation: animation
  15476. }));
  15477. });
  15478. var defaultProps = {
  15479. offsetX: 0,
  15480. offsetY: 0,
  15481. points: [],
  15482. src: ''
  15483. };
  15484. var baseAttrs = {
  15485. height: '20px',
  15486. width: '20px'
  15487. };
  15488. var ImageGuideView = (function (props, context) {
  15489. var cfg = deepMix({}, defaultProps, props);
  15490. var points = cfg.points,
  15491. style = cfg.style,
  15492. attrs = cfg.attrs,
  15493. offsetX = cfg.offsetX,
  15494. offsetY = cfg.offsetY,
  15495. src = cfg.src,
  15496. animation = cfg.animation;
  15497. var _ref = points[0] || {},
  15498. x = _ref.x,
  15499. y = _ref.y;
  15500. var _attrs$height = attrs.height,
  15501. height = _attrs$height === void 0 ? 0 : _attrs$height,
  15502. _attrs$width = attrs.width,
  15503. width = _attrs$width === void 0 ? 0 : _attrs$width;
  15504. var offsetXNum = context.px2hd(offsetX);
  15505. var offsetYNum = context.px2hd(offsetY);
  15506. var posX = x + (offsetXNum || 0) - height / 2;
  15507. var posY = y + (offsetYNum || 0) - width / 2;
  15508. return jsx("group", {
  15509. style: style
  15510. }, jsx("image", {
  15511. attrs: _objectSpread(_objectSpread(_objectSpread({}, baseAttrs), attrs), {}, {
  15512. height: height + 'px',
  15513. width: width + 'px',
  15514. x: posX,
  15515. y: posY,
  15516. src: src
  15517. }),
  15518. animation: deepMix({
  15519. update: {
  15520. easing: 'linear',
  15521. duration: 450,
  15522. property: ['x', 'y']
  15523. }
  15524. }, animation)
  15525. }));
  15526. });
  15527. var defaultProps$1 = {
  15528. offsetX: 0,
  15529. offsetY: 0,
  15530. points: [],
  15531. direct: 'tl',
  15532. side: 6,
  15533. autoAdjust: true
  15534. };
  15535. var defaultStyle = {
  15536. container: {
  15537. fill: '#1677FF',
  15538. radius: 2,
  15539. padding: [3, 5]
  15540. },
  15541. text: {
  15542. fontSize: '22px',
  15543. fill: '#fff'
  15544. },
  15545. arrow: {
  15546. fill: '#1677FF'
  15547. }
  15548. };
  15549. var TagGuideView = (function (props, context) {
  15550. var cfg = _objectSpread(_objectSpread({}, defaultProps$1), props);
  15551. var points = cfg.points,
  15552. content = cfg.content,
  15553. offsetX = cfg.offsetX,
  15554. offsetY = cfg.offsetY,
  15555. direct = cfg.direct,
  15556. side = cfg.side,
  15557. autoAdjust = cfg.autoAdjust,
  15558. canvasWidth = cfg.canvasWidth,
  15559. canvasHeight = cfg.canvasHeight,
  15560. guideBBox = cfg.guideBBox,
  15561. background = cfg.background,
  15562. textStyle = cfg.textStyle,
  15563. triggerRef = cfg.triggerRef;
  15564. var _ref = points[0] || {},
  15565. x = _ref.x,
  15566. y = _ref.y;
  15567. var _ref2 = guideBBox || {},
  15568. guideWidth = _ref2.width,
  15569. guideHeight = _ref2.height;
  15570. var offsetXNum = context.px2hd(offsetX);
  15571. var offsetYNum = context.px2hd(offsetY);
  15572. var posX = x + (offsetXNum || 0);
  15573. var posY = y + (offsetYNum || 0);
  15574. var _getDirect = function _getDirect(point) {
  15575. var newDirect = direct;
  15576. var x = point.x,
  15577. y = point.y;
  15578. var vertical = newDirect[0];
  15579. var horizontal = newDirect[1]; // adjust for vertical direction
  15580. if (vertical === 't' && y - side - guideHeight < 0) {
  15581. vertical = 'b';
  15582. } else if (vertical === 'b' && y + side + guideHeight > canvasHeight) {
  15583. vertical = 't';
  15584. } // adjust for horizontal direction
  15585. var diff = vertical === 'c' ? side : 0;
  15586. if (horizontal === 'l' && x - diff - guideWidth < 0) {
  15587. horizontal = 'r';
  15588. } else if (horizontal === 'r' && x + diff + guideWidth > canvasWidth) {
  15589. horizontal = 'l';
  15590. } else if (horizontal === 'c') {
  15591. if (guideWidth / 2 + x + diff > canvasWidth) {
  15592. horizontal = 'l';
  15593. } else if (x - guideWidth / 2 - diff < 0) {
  15594. horizontal = 'r';
  15595. }
  15596. }
  15597. newDirect = vertical + horizontal;
  15598. return newDirect;
  15599. };
  15600. var _getArrowPoints = function _getArrowPoints(direct) {
  15601. var arrowPoints = []; // const { minX, minY } = guideBBox || {};
  15602. if (direct === 'tl') {
  15603. arrowPoints = [{
  15604. x: posX,
  15605. y: posY - side - 1
  15606. }, {
  15607. x: posX,
  15608. y: posY
  15609. }, {
  15610. x: posX - side,
  15611. y: posY - side - 1
  15612. }];
  15613. posX -= guideWidth || 0;
  15614. posY = posY - (guideHeight || 0) - side;
  15615. } else if (direct === 'cl') {
  15616. arrowPoints = [{
  15617. x: posX - side - 1,
  15618. y: posY - side
  15619. }, {
  15620. x: posX - side - 1,
  15621. y: posY + side
  15622. }, {
  15623. x: posX,
  15624. y: posY
  15625. }];
  15626. posX = posX - (guideWidth || 0) - side;
  15627. posY -= guideHeight / 2 || 0;
  15628. } else if (direct === 'bl') {
  15629. arrowPoints = [{
  15630. x: posX,
  15631. y: posY
  15632. }, {
  15633. x: posX,
  15634. y: posY + side + 1
  15635. }, {
  15636. x: posX - side,
  15637. y: posY + side + 1
  15638. }];
  15639. posX = posX - (guideWidth || 0);
  15640. posY += side;
  15641. } else if (direct === 'bc') {
  15642. // 有问题
  15643. arrowPoints = [{
  15644. x: posX,
  15645. y: posY
  15646. }, {
  15647. x: posX - side,
  15648. y: posY + side + 1
  15649. }, {
  15650. x: posX + side,
  15651. y: posY + side + 1
  15652. }];
  15653. posX = posX - (guideWidth / 2 || 0);
  15654. posY = posY + side;
  15655. } else if (direct === 'br') {
  15656. arrowPoints = [{
  15657. x: posX,
  15658. y: posY
  15659. }, {
  15660. x: posX,
  15661. y: posY + side + 1
  15662. }, {
  15663. x: posX + side,
  15664. y: posY + side + 1
  15665. }];
  15666. posY += side;
  15667. } else if (direct === 'cr') {
  15668. arrowPoints = [{
  15669. x: posX,
  15670. y: posY
  15671. }, {
  15672. x: posX + side,
  15673. y: posY - side
  15674. }, {
  15675. x: posX + side,
  15676. y: posY + side
  15677. }];
  15678. posX += side;
  15679. posY -= guideHeight / 2 || 0;
  15680. } else if (direct === 'tr') {
  15681. arrowPoints = [{
  15682. x: posX,
  15683. y: posY
  15684. }, {
  15685. x: posX,
  15686. y: posY - side - 1
  15687. }, {
  15688. x: posX + side,
  15689. y: posY - side - 1
  15690. }];
  15691. posY = posY - (guideHeight || 0) - side;
  15692. } else if (direct === 'tc') {
  15693. arrowPoints = [{
  15694. x: posX,
  15695. y: posY
  15696. }, {
  15697. x: posX - side,
  15698. y: posY - side - 1
  15699. }, {
  15700. x: posX + side,
  15701. y: posY - side - 1
  15702. }];
  15703. posX -= guideWidth / 2 || 0;
  15704. posY = posY - (guideHeight || 0) - side;
  15705. }
  15706. return arrowPoints;
  15707. };
  15708. var dr = autoAdjust ? _getDirect(points[0]) : direct;
  15709. var arrowPoints = _getArrowPoints(dr);
  15710. return jsx("group", {
  15711. attrs: _objectSpread({
  15712. fill: defaultStyle.container.fill,
  15713. radius: defaultStyle.container.radius
  15714. }, background),
  15715. style: _objectSpread({
  15716. left: posX,
  15717. top: posY,
  15718. padding: defaultStyle.container.padding
  15719. }, background),
  15720. ref: triggerRef
  15721. }, jsx("text", {
  15722. attrs: _objectSpread({
  15723. text: content,
  15724. fontSize: defaultStyle.text.fontSize,
  15725. fill: defaultStyle.text.fill
  15726. }, textStyle)
  15727. }), guideBBox && jsx("polygon", {
  15728. attrs: {
  15729. points: arrowPoints,
  15730. fill: (background === null || background === void 0 ? void 0 : background.fill) || defaultStyle.arrow.fill
  15731. }
  15732. }));
  15733. });
  15734. var DefaultGuideView = function DefaultGuideView() {
  15735. return null;
  15736. };
  15737. var TextGuide = withGuide(TextGuideView);
  15738. var PointGuide = withGuide(PointGuideView);
  15739. var LineGuide = withGuide(LineGuideView);
  15740. var ArcGuide = withGuide(ArcGuideView);
  15741. var RectGuide = withGuide(RectGuideView);
  15742. var ImageGuide = withGuide(ImageGuideView);
  15743. var TagGuide = withGuide(TagGuideView);
  15744. var index$6 = withGuide(DefaultGuideView);
  15745. var withTooltip = (function (View) {
  15746. return /*#__PURE__*/function (_Component) {
  15747. _inherits(Tooltip, _Component);
  15748. var _super = _createSuper(Tooltip);
  15749. function Tooltip(props) {
  15750. var _this;
  15751. _classCallCheck(this, Tooltip);
  15752. _this = _super.call(this, props);
  15753. _this._triggerOn = function (ev) {
  15754. var points = ev.points;
  15755. _this.show(points[0], ev);
  15756. };
  15757. _this._triggerOff = function () {
  15758. var _assertThisInitialize = _assertThisInitialized(_this),
  15759. _assertThisInitialize2 = _assertThisInitialize.props.alwaysShow,
  15760. alwaysShow = _assertThisInitialize2 === void 0 ? false : _assertThisInitialize2;
  15761. if (!alwaysShow) {
  15762. _this.hide();
  15763. }
  15764. };
  15765. _this.state = {
  15766. records: null
  15767. };
  15768. return _this;
  15769. }
  15770. _createClass(Tooltip, [{
  15771. key: "updateCoord",
  15772. value: function updateCoord() {
  15773. var props = this.props,
  15774. context = this.context;
  15775. var _props$padding = props.padding,
  15776. padding = _props$padding === void 0 ? '10px' : _props$padding,
  15777. chart = props.chart;
  15778. chart.updateCoordFor(this, {
  15779. position: 'top',
  15780. width: 0,
  15781. height: context.px2hd(padding)
  15782. });
  15783. }
  15784. }, {
  15785. key: "willMount",
  15786. value: function willMount() {
  15787. this.updateCoord();
  15788. }
  15789. }, {
  15790. key: "didMount",
  15791. value: function didMount() {
  15792. this._initShow();
  15793. this._initEvent();
  15794. }
  15795. }, {
  15796. key: "willReceiveProps",
  15797. value: function willReceiveProps(nextProps) {
  15798. var nextDefaultItem = nextProps.defaultItem,
  15799. nextCoord = nextProps.coord;
  15800. var _this$props = this.props,
  15801. lastDefaultItem = _this$props.defaultItem,
  15802. lastCoord = _this$props.coord; // 默认元素或坐标有变动,均需重新渲染
  15803. if (!equal(nextDefaultItem, lastDefaultItem) || !equal(nextCoord, lastCoord)) {
  15804. this._showByData(nextDefaultItem);
  15805. }
  15806. }
  15807. }, {
  15808. key: "_initShow",
  15809. value: function _initShow() {
  15810. var props = this.props;
  15811. var defaultItem = props.defaultItem;
  15812. this._showByData(defaultItem);
  15813. }
  15814. }, {
  15815. key: "_showByData",
  15816. value: function _showByData(dataItem) {
  15817. var _this2 = this;
  15818. if (!dataItem) return;
  15819. var props = this.props;
  15820. var chart = props.chart; // 因为 tooltip 有可能在 geometry 之前,所以需要等 geometry render 完后再执行
  15821. setTimeout(function () {
  15822. var point = chart.getPosition(dataItem);
  15823. _this2.show(point);
  15824. }, 0);
  15825. }
  15826. }, {
  15827. key: "_initEvent",
  15828. value: function _initEvent() {
  15829. var context = this.context,
  15830. props = this.props;
  15831. var canvas = context.canvas;
  15832. var _props$triggerOn = props.triggerOn,
  15833. triggerOn = _props$triggerOn === void 0 ? 'press' : _props$triggerOn,
  15834. _props$triggerOff = props.triggerOff,
  15835. triggerOff = _props$triggerOff === void 0 ? 'pressend' : _props$triggerOff;
  15836. canvas.on(triggerOn, this._triggerOn);
  15837. canvas.on(triggerOff, this._triggerOff);
  15838. }
  15839. }, {
  15840. key: "didUnmount",
  15841. value: function didUnmount() {
  15842. this._clearEvents();
  15843. }
  15844. }, {
  15845. key: "_clearEvents",
  15846. value: function _clearEvents() {
  15847. var context = this.context,
  15848. props = this.props;
  15849. var canvas = context.canvas;
  15850. var _props$triggerOn2 = props.triggerOn,
  15851. triggerOn = _props$triggerOn2 === void 0 ? 'press' : _props$triggerOn2,
  15852. _props$triggerOff2 = props.triggerOff,
  15853. triggerOff = _props$triggerOff2 === void 0 ? 'pressend' : _props$triggerOff2; // 解绑事件
  15854. canvas.off(triggerOn, this._triggerOn);
  15855. canvas.off(triggerOff, this._triggerOff);
  15856. }
  15857. }, {
  15858. key: "show",
  15859. value: function show(point, _ev) {
  15860. var props = this.props;
  15861. var chart = props.chart,
  15862. onChange = props.onChange;
  15863. var snapRecords = chart.getSnapRecords(point, true); // 超出边界会自动调整
  15864. if (!snapRecords || !snapRecords.length) return;
  15865. var legendItems = chart.getLegendItems();
  15866. var _snapRecords$ = snapRecords[0],
  15867. xField = _snapRecords$.xField,
  15868. yField = _snapRecords$.yField;
  15869. var xScale = chart.getScale(xField);
  15870. var yScale = chart.getScale(yField);
  15871. var records = snapRecords.map(function (record) {
  15872. var origin = record.origin,
  15873. xField = record.xField,
  15874. yField = record.yField;
  15875. var value = yScale.getText(origin[yField]); // 默认取 alias 的配置
  15876. var name = yScale.alias;
  15877. if (!name) {
  15878. name = xScale.getText(origin[xField]);
  15879. if (legendItems && legendItems.length) {
  15880. var item = find(legendItems, function (item) {
  15881. var field = item.field,
  15882. tickValue = item.tickValue;
  15883. return origin[field] === tickValue;
  15884. });
  15885. if (item && item.name) {
  15886. name = item.name;
  15887. }
  15888. }
  15889. }
  15890. return _objectSpread(_objectSpread({}, record), {}, {
  15891. name: name,
  15892. value: value
  15893. });
  15894. });
  15895. if (!isArray(records) || !records.length) {
  15896. return;
  15897. }
  15898. this.setState({
  15899. records: records
  15900. });
  15901. if (isFunction(onChange)) {
  15902. onChange(records);
  15903. }
  15904. }
  15905. }, {
  15906. key: "hide",
  15907. value: function hide() {
  15908. this.setState({
  15909. records: null
  15910. });
  15911. }
  15912. }, {
  15913. key: "render",
  15914. value: function render() {
  15915. var props = this.props,
  15916. state = this.state;
  15917. var visible = props.visible;
  15918. if (visible === false) {
  15919. return null;
  15920. }
  15921. var records = state.records;
  15922. if (!records || !records.length) return null;
  15923. return jsx(View, _objectSpread(_objectSpread({}, props), {}, {
  15924. records: records
  15925. }));
  15926. }
  15927. }]);
  15928. return Tooltip;
  15929. }(Component);
  15930. });
  15931. function createRef() {
  15932. var ref = {
  15933. current: null
  15934. };
  15935. return ref;
  15936. }
  15937. var defaultStyle$1 = {
  15938. showTitle: false,
  15939. showCrosshairs: false,
  15940. crosshairsType: 'y',
  15941. crosshairsStyle: {
  15942. stroke: 'rgba(0, 0, 0, 0.25)',
  15943. lineWidth: '2px'
  15944. },
  15945. showTooltipMarker: false,
  15946. markerBackgroundStyle: {
  15947. fill: '#CCD6EC',
  15948. opacity: 0.3,
  15949. padding: '6px'
  15950. },
  15951. tooltipMarkerStyle: {
  15952. fill: '#fff',
  15953. lineWidth: '3px'
  15954. },
  15955. background: {
  15956. radius: '4px',
  15957. fill: 'rgba(0, 0, 0, 0.65)',
  15958. padding: ['6px', '10px']
  15959. },
  15960. titleStyle: {
  15961. fontSize: '24px',
  15962. fill: '#fff',
  15963. textAlign: 'start',
  15964. textBaseline: 'top'
  15965. },
  15966. nameStyle: {
  15967. fontSize: '24px',
  15968. fill: 'rgba(255, 255, 255, 0.65)',
  15969. textAlign: 'start',
  15970. textBaseline: 'middle'
  15971. },
  15972. valueStyle: {
  15973. fontSize: '24px',
  15974. fill: '#fff',
  15975. textAlign: 'start',
  15976. textBaseline: 'middle'
  15977. },
  15978. joinString: ': ',
  15979. showItemMarker: true,
  15980. itemMarkerStyle: {
  15981. width: '12px',
  15982. radius: '6px',
  15983. symbol: 'circle',
  15984. lineWidth: '2px',
  15985. stroke: '#fff'
  15986. },
  15987. layout: 'horizontal',
  15988. snap: false,
  15989. xTipTextStyle: {
  15990. fontSize: '24px',
  15991. fill: '#fff'
  15992. },
  15993. yTipTextStyle: {
  15994. fontSize: '24px',
  15995. fill: '#fff'
  15996. },
  15997. xTipBackground: {
  15998. radius: '4px',
  15999. fill: 'rgba(0, 0, 0, 0.65)',
  16000. padding: ['6px', '10px'],
  16001. marginLeft: '-50%',
  16002. marginTop: '6px'
  16003. },
  16004. yTipBackground: {
  16005. radius: '4px',
  16006. fill: 'rgba(0, 0, 0, 0.65)',
  16007. padding: ['6px', '10px'],
  16008. marginLeft: '-100%',
  16009. marginTop: '-50%'
  16010. }
  16011. };
  16012. function directionEnabled(mode, dir) {
  16013. if (mode === undefined) {
  16014. return true;
  16015. } else if (typeof mode === 'string') {
  16016. return mode.indexOf(dir) !== -1;
  16017. }
  16018. return false;
  16019. }
  16020. var RenderItemMarker = function RenderItemMarker(props) {
  16021. var records = props.records,
  16022. coord = props.coord,
  16023. context = props.context,
  16024. markerBackgroundStyle = props.markerBackgroundStyle;
  16025. var point = coord.convertPoint({
  16026. x: 1,
  16027. y: 1
  16028. });
  16029. var padding = context.px2hd(markerBackgroundStyle.padding || '6px');
  16030. var xPoints = [].concat(_toConsumableArray(records.map(function (record) {
  16031. return record.xMin;
  16032. })), _toConsumableArray(records.map(function (record) {
  16033. return record.xMax;
  16034. })));
  16035. var yPoints = [].concat(_toConsumableArray(records.map(function (record) {
  16036. return record.yMin;
  16037. })), _toConsumableArray(records.map(function (record) {
  16038. return record.yMax;
  16039. })));
  16040. if (coord.transposed) {
  16041. xPoints.push(point.x);
  16042. } else {
  16043. yPoints.push(point.y);
  16044. }
  16045. var xMin = Math.min.apply(null, xPoints);
  16046. var xMax = Math.max.apply(null, xPoints);
  16047. var yMin = Math.min.apply(null, yPoints);
  16048. var yMax = Math.max.apply(null, yPoints);
  16049. var x = coord.transposed ? xMin : xMin - padding;
  16050. var y = coord.transposed ? yMin - padding : yMin;
  16051. var width = coord.transposed ? xMax - xMin : xMax - xMin + 2 * padding;
  16052. var height = coord.transposed ? yMax - yMin + 2 * padding : yMax - yMin;
  16053. return jsx("rect", {
  16054. attrs: _objectSpread({
  16055. x: x,
  16056. y: y,
  16057. width: width,
  16058. height: height
  16059. }, markerBackgroundStyle)
  16060. });
  16061. };
  16062. var RenderCrosshairs = function RenderCrosshairs(props) {
  16063. var records = props.records,
  16064. coord = props.coord,
  16065. chart = props.chart,
  16066. crosshairsType = props.crosshairsType,
  16067. crosshairsStyle = props.crosshairsStyle;
  16068. var coordLeft = coord.left,
  16069. coordTop = coord.top,
  16070. coordRight = coord.right,
  16071. coordBottom = coord.bottom,
  16072. center = coord.center;
  16073. var firstRecord = records[0];
  16074. var x = firstRecord.x,
  16075. y = firstRecord.y,
  16076. origin = firstRecord.origin,
  16077. xField = firstRecord.xField;
  16078. if (coord.isPolar) {
  16079. // 极坐标下的辅助线
  16080. var xScale = chart.getScale(xField);
  16081. var ticks = xScale.getTicks();
  16082. var tick = find(ticks, function (tick) {
  16083. return origin[xField] === tick.tickValue;
  16084. });
  16085. var end = coord.convertPoint({
  16086. x: tick.value,
  16087. y: 1
  16088. });
  16089. return jsx("line", {
  16090. attrs: _objectSpread({
  16091. x1: center.x,
  16092. y1: center.y,
  16093. x2: end.x,
  16094. y2: end.y
  16095. }, crosshairsStyle)
  16096. });
  16097. }
  16098. return jsx("group", null, directionEnabled(crosshairsType, 'x') ? jsx("line", {
  16099. attrs: _objectSpread({
  16100. x1: coordLeft,
  16101. y1: y,
  16102. x2: coordRight,
  16103. y2: y
  16104. }, crosshairsStyle)
  16105. }) : null, directionEnabled(crosshairsType, 'y') ? jsx("line", {
  16106. attrs: _objectSpread({
  16107. x1: x,
  16108. y1: coordTop,
  16109. x2: x,
  16110. y2: coordBottom
  16111. }, crosshairsStyle)
  16112. }) : null);
  16113. };
  16114. var TooltipView = /*#__PURE__*/function (_Component) {
  16115. _inherits(TooltipView, _Component);
  16116. var _super = _createSuper(TooltipView);
  16117. function TooltipView(props) {
  16118. var _this;
  16119. _classCallCheck(this, TooltipView);
  16120. _this = _super.call(this, props);
  16121. _this.rootRef = createRef();
  16122. _this.arrowRef = createRef();
  16123. return _this;
  16124. } // 调整 显示的位置
  16125. _createClass(TooltipView, [{
  16126. key: "_position",
  16127. value: function _position() {
  16128. var props = this.props,
  16129. context = this.context,
  16130. rootRef = this.rootRef,
  16131. arrowRef = this.arrowRef;
  16132. var group = rootRef.current;
  16133. if (!group) {
  16134. return;
  16135. }
  16136. var records = props.records,
  16137. coord = props.coord;
  16138. var arrowWidth = context.px2hd('6px');
  16139. var record = records[0]; // 中心点
  16140. var x = record.x;
  16141. var coordLeft = coord.left,
  16142. coordWidth = coord.width;
  16143. var _group$get = group.get('attrs'),
  16144. y = _group$get.y,
  16145. width = _group$get.width,
  16146. height = _group$get.height,
  16147. radius = _group$get.radius;
  16148. var halfWidth = width / 2; // 让 tooltip 限制在 coord 的显示范围内
  16149. var offsetX = Math.min(Math.max(x - coordLeft - halfWidth, -arrowWidth - radius), coordWidth - width + arrowWidth + radius); // 因为默认是从 coord 的范围内显示的,所以要往上移,移出 coord,避免挡住 geometry
  16150. var offset = Math.min(y, height + arrowWidth); // 因为不能超出 canvas 画布区域,所以最大只能是 y
  16151. group.moveTo(offsetX, -offset);
  16152. arrowRef.current.moveTo(0, height - offset);
  16153. }
  16154. }, {
  16155. key: "didMount",
  16156. value: function didMount() {
  16157. this._position();
  16158. }
  16159. }, {
  16160. key: "didUpdate",
  16161. value: function didUpdate() {
  16162. this._position();
  16163. }
  16164. }, {
  16165. key: "render",
  16166. value: function render() {
  16167. var props = this.props,
  16168. context = this.context;
  16169. var records = props.records,
  16170. coord = props.coord;
  16171. var coordLeft = coord.left,
  16172. coordTop = coord.top,
  16173. coordBottom = coord.bottom;
  16174. var firstRecord = records[0];
  16175. var x = firstRecord.x,
  16176. y = firstRecord.y;
  16177. var xFirstText = firstRecord.name,
  16178. yFirstText = firstRecord.value;
  16179. var chart = props.chart,
  16180. customBackground = props.background,
  16181. _props$showTooltipMar = props.showTooltipMarker,
  16182. showTooltipMarker = _props$showTooltipMar === void 0 ? defaultStyle$1.showTooltipMarker : _props$showTooltipMar,
  16183. _props$markerBackgrou = props.markerBackgroundStyle,
  16184. markerBackgroundStyle = _props$markerBackgrou === void 0 ? defaultStyle$1.markerBackgroundStyle : _props$markerBackgrou,
  16185. _props$showItemMarker = props.showItemMarker,
  16186. showItemMarker = _props$showItemMarker === void 0 ? defaultStyle$1.showItemMarker : _props$showItemMarker,
  16187. customItemMarkerStyle = props.itemMarkerStyle,
  16188. nameStyle = props.nameStyle,
  16189. valueStyle = props.valueStyle,
  16190. _props$joinString = props.joinString,
  16191. joinString = _props$joinString === void 0 ? defaultStyle$1.joinString : _props$joinString,
  16192. _props$showCrosshairs = props.showCrosshairs,
  16193. showCrosshairs = _props$showCrosshairs === void 0 ? defaultStyle$1.showCrosshairs : _props$showCrosshairs,
  16194. crosshairsStyle = props.crosshairsStyle,
  16195. _props$crosshairsType = props.crosshairsType,
  16196. crosshairsType = _props$crosshairsType === void 0 ? defaultStyle$1.crosshairsType : _props$crosshairsType,
  16197. _props$snap = props.snap,
  16198. snap = _props$snap === void 0 ? defaultStyle$1.snap : _props$snap,
  16199. _props$tooltipMarkerS = props.tooltipMarkerStyle,
  16200. tooltipMarkerStyle = _props$tooltipMarkerS === void 0 ? defaultStyle$1.tooltipMarkerStyle : _props$tooltipMarkerS,
  16201. showXTip = props.showXTip,
  16202. showYTip = props.showYTip,
  16203. xTip = props.xTip,
  16204. yTip = props.yTip,
  16205. _props$xTipTextStyle = props.xTipTextStyle,
  16206. xTipTextStyle = _props$xTipTextStyle === void 0 ? defaultStyle$1.xTipTextStyle : _props$xTipTextStyle,
  16207. _props$yTipTextStyle = props.yTipTextStyle,
  16208. yTipTextStyle = _props$yTipTextStyle === void 0 ? defaultStyle$1.yTipTextStyle : _props$yTipTextStyle,
  16209. _props$xTipBackground = props.xTipBackground,
  16210. xTipBackground = _props$xTipBackground === void 0 ? defaultStyle$1.xTipBackground : _props$xTipBackground,
  16211. _props$yTipBackground = props.yTipBackground,
  16212. yTipBackground = _props$yTipBackground === void 0 ? defaultStyle$1.yTipBackground : _props$yTipBackground,
  16213. _props$custom = props.custom,
  16214. custom = _props$custom === void 0 ? false : _props$custom,
  16215. customText = props.customText;
  16216. var itemMarkerStyle = _objectSpread(_objectSpread({}, customItemMarkerStyle), defaultStyle$1.itemMarkerStyle);
  16217. var background = _objectSpread(_objectSpread({}, defaultStyle$1.background), customBackground);
  16218. var arrowWidth = context.px2hd('6px');
  16219. return jsx("group", null, jsx("group", {
  16220. style: {
  16221. left: coordLeft,
  16222. top: coordTop
  16223. }
  16224. }, !custom && jsx("group", null, jsx("group", {
  16225. ref: this.rootRef,
  16226. style: background,
  16227. attrs: background
  16228. }, jsx("group", {
  16229. style: {
  16230. display: 'flex',
  16231. flexDirection: 'row',
  16232. flexWrap: 'wrap',
  16233. padding: [0, 0, 0, '6px']
  16234. }
  16235. }, records.map(function (record) {
  16236. var name = record.name,
  16237. value = record.value;
  16238. return jsx("group", {
  16239. style: {
  16240. display: 'flex',
  16241. flexDirection: 'row',
  16242. alignItems: 'center',
  16243. padding: [0, '6px', 0, 0]
  16244. }
  16245. }, showItemMarker ? jsx("marker", {
  16246. style: {
  16247. width: itemMarkerStyle.width,
  16248. marginRight: '6px'
  16249. },
  16250. attrs: _objectSpread(_objectSpread({}, itemMarkerStyle), {}, {
  16251. fill: record.color
  16252. })
  16253. }) : null, customText && isFunction(customText) ? customText(record) : jsx("group", {
  16254. style: {
  16255. display: 'flex',
  16256. flexDirection: 'row'
  16257. }
  16258. }, jsx("text", {
  16259. attrs: _objectSpread(_objectSpread(_objectSpread({}, defaultStyle$1.nameStyle), nameStyle), {}, {
  16260. text: value ? "".concat(name).concat(joinString) : name
  16261. })
  16262. }), jsx("text", {
  16263. attrs: _objectSpread(_objectSpread(_objectSpread({}, defaultStyle$1.valueStyle), valueStyle), {}, {
  16264. text: value
  16265. })
  16266. })));
  16267. }))), jsx("polygon", {
  16268. ref: this.arrowRef,
  16269. attrs: {
  16270. points: [{
  16271. x: x - arrowWidth,
  16272. y: coordTop
  16273. }, {
  16274. x: x + arrowWidth,
  16275. y: coordTop
  16276. }, {
  16277. x: x,
  16278. y: coordTop + arrowWidth
  16279. }],
  16280. fill: background.fill
  16281. }
  16282. })), showTooltipMarker ? jsx(RenderItemMarker, {
  16283. coord: coord,
  16284. context: context,
  16285. records: records,
  16286. markerBackgroundStyle: markerBackgroundStyle
  16287. }) : null, showCrosshairs ? jsx(RenderCrosshairs, {
  16288. chart: chart,
  16289. coord: coord,
  16290. records: records,
  16291. crosshairsType: crosshairsType,
  16292. crosshairsStyle: _objectSpread(_objectSpread({}, defaultStyle$1.crosshairsStyle), crosshairsStyle)
  16293. }) : null, snap ? records.map(function (item) {
  16294. var x = item.x,
  16295. y = item.y,
  16296. color = item.color,
  16297. shape = item.shape;
  16298. return jsx("circle", {
  16299. attrs: _objectSpread(_objectSpread({
  16300. x: x,
  16301. y: y,
  16302. r: '6px',
  16303. stroke: color,
  16304. fill: color
  16305. }, shape), tooltipMarkerStyle)
  16306. });
  16307. }) : null), showXTip && jsx("group", {
  16308. style: _objectSpread(_objectSpread({
  16309. left: x,
  16310. top: coordBottom
  16311. }, defaultStyle$1.xTipBackground), xTipBackground),
  16312. attrs: _objectSpread(_objectSpread({}, defaultStyle$1.xTipBackground), xTipBackground)
  16313. }, jsx("text", {
  16314. attrs: _objectSpread(_objectSpread(_objectSpread({}, defaultStyle$1.xTipTextStyle), xTipTextStyle), {}, {
  16315. text: isFunction(xTip) ? xTip(xFirstText) : xFirstText
  16316. })
  16317. })), showYTip && jsx("group", {
  16318. style: _objectSpread(_objectSpread({
  16319. left: coordLeft,
  16320. top: y
  16321. }, defaultStyle$1.yTipBackground), yTipBackground),
  16322. attrs: _objectSpread(_objectSpread({}, defaultStyle$1.yTipBackground), yTipBackground)
  16323. }, jsx("text", {
  16324. attrs: _objectSpread(_objectSpread(_objectSpread({}, defaultStyle$1.yTipTextStyle), yTipTextStyle), {}, {
  16325. text: isFunction(yTip) ? yTip(yFirstText) : yFirstText
  16326. })
  16327. })));
  16328. }
  16329. }]);
  16330. return TooltipView;
  16331. }(Component);
  16332. var index$7 = withTooltip(TooltipView);
  16333. function count(node) {
  16334. var sum = 0,
  16335. children = node.children,
  16336. i = children && children.length;
  16337. if (!i) sum = 1;else while (--i >= 0) {
  16338. sum += children[i].value;
  16339. }
  16340. node.value = sum;
  16341. }
  16342. function node_count () {
  16343. return this.eachAfter(count);
  16344. }
  16345. var createForOfIteratorHelper = createCommonjsModule(function (module) {
  16346. function _createForOfIteratorHelper(o, allowArrayLike) {
  16347. var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
  16348. if (!it) {
  16349. if (Array.isArray(o) || (it = unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
  16350. if (it) o = it;
  16351. var i = 0;
  16352. var F = function F() {};
  16353. return {
  16354. s: F,
  16355. n: function n() {
  16356. if (i >= o.length) return {
  16357. done: true
  16358. };
  16359. return {
  16360. done: false,
  16361. value: o[i++]
  16362. };
  16363. },
  16364. e: function e(_e) {
  16365. throw _e;
  16366. },
  16367. f: F
  16368. };
  16369. }
  16370. throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
  16371. }
  16372. var normalCompletion = true,
  16373. didErr = false,
  16374. err;
  16375. return {
  16376. s: function s() {
  16377. it = it.call(o);
  16378. },
  16379. n: function n() {
  16380. var step = it.next();
  16381. normalCompletion = step.done;
  16382. return step;
  16383. },
  16384. e: function e(_e2) {
  16385. didErr = true;
  16386. err = _e2;
  16387. },
  16388. f: function f() {
  16389. try {
  16390. if (!normalCompletion && it["return"] != null) it["return"]();
  16391. } finally {
  16392. if (didErr) throw err;
  16393. }
  16394. }
  16395. };
  16396. }
  16397. module.exports = _createForOfIteratorHelper, module.exports.__esModule = true, module.exports["default"] = module.exports;
  16398. });
  16399. var _createForOfIteratorHelper = /*@__PURE__*/getDefaultExportFromCjs(createForOfIteratorHelper);
  16400. function node_each (callback, that) {
  16401. var index = -1;
  16402. var _iterator = _createForOfIteratorHelper(this),
  16403. _step;
  16404. try {
  16405. for (_iterator.s(); !(_step = _iterator.n()).done;) {
  16406. var node = _step.value;
  16407. callback.call(that, node, ++index, this);
  16408. }
  16409. } catch (err) {
  16410. _iterator.e(err);
  16411. } finally {
  16412. _iterator.f();
  16413. }
  16414. return this;
  16415. }
  16416. function node_eachBefore (callback, that) {
  16417. var node = this,
  16418. nodes = [node],
  16419. children,
  16420. i,
  16421. index = -1;
  16422. while (node = nodes.pop()) {
  16423. callback.call(that, node, ++index, this);
  16424. if (children = node.children) {
  16425. for (i = children.length - 1; i >= 0; --i) {
  16426. nodes.push(children[i]);
  16427. }
  16428. }
  16429. }
  16430. return this;
  16431. }
  16432. function node_eachAfter (callback, that) {
  16433. var node = this,
  16434. nodes = [node],
  16435. next = [],
  16436. children,
  16437. i,
  16438. n,
  16439. index = -1;
  16440. while (node = nodes.pop()) {
  16441. next.push(node);
  16442. if (children = node.children) {
  16443. for (i = 0, n = children.length; i < n; ++i) {
  16444. nodes.push(children[i]);
  16445. }
  16446. }
  16447. }
  16448. while (node = next.pop()) {
  16449. callback.call(that, node, ++index, this);
  16450. }
  16451. return this;
  16452. }
  16453. function node_find (callback, that) {
  16454. var index = -1;
  16455. var _iterator = _createForOfIteratorHelper(this),
  16456. _step;
  16457. try {
  16458. for (_iterator.s(); !(_step = _iterator.n()).done;) {
  16459. var node = _step.value;
  16460. if (callback.call(that, node, ++index, this)) {
  16461. return node;
  16462. }
  16463. }
  16464. } catch (err) {
  16465. _iterator.e(err);
  16466. } finally {
  16467. _iterator.f();
  16468. }
  16469. }
  16470. function node_sum (value) {
  16471. return this.eachAfter(function (node) {
  16472. var sum = +value(node.data) || 0,
  16473. children = node.children,
  16474. i = children && children.length;
  16475. while (--i >= 0) {
  16476. sum += children[i].value;
  16477. }
  16478. node.value = sum;
  16479. });
  16480. }
  16481. function node_sort (compare) {
  16482. return this.eachBefore(function (node) {
  16483. if (node.children) {
  16484. node.children.sort(compare);
  16485. }
  16486. });
  16487. }
  16488. function node_path (end) {
  16489. var start = this,
  16490. ancestor = leastCommonAncestor(start, end),
  16491. nodes = [start];
  16492. while (start !== ancestor) {
  16493. start = start.parent;
  16494. nodes.push(start);
  16495. }
  16496. var k = nodes.length;
  16497. while (end !== ancestor) {
  16498. nodes.splice(k, 0, end);
  16499. end = end.parent;
  16500. }
  16501. return nodes;
  16502. }
  16503. function leastCommonAncestor(a, b) {
  16504. if (a === b) return a;
  16505. var aNodes = a.ancestors(),
  16506. bNodes = b.ancestors(),
  16507. c = null;
  16508. a = aNodes.pop();
  16509. b = bNodes.pop();
  16510. while (a === b) {
  16511. c = a;
  16512. a = aNodes.pop();
  16513. b = bNodes.pop();
  16514. }
  16515. return c;
  16516. }
  16517. function node_ancestors () {
  16518. var node = this,
  16519. nodes = [node];
  16520. while (node = node.parent) {
  16521. nodes.push(node);
  16522. }
  16523. return nodes;
  16524. }
  16525. function node_descendants () {
  16526. return Array.from(this);
  16527. }
  16528. function node_leaves () {
  16529. var leaves = [];
  16530. this.eachBefore(function (node) {
  16531. if (!node.children) {
  16532. leaves.push(node);
  16533. }
  16534. });
  16535. return leaves;
  16536. }
  16537. function node_links () {
  16538. var root = this,
  16539. links = [];
  16540. root.each(function (node) {
  16541. if (node !== root) {
  16542. // Don’t include the root’s parent, if any.
  16543. links.push({
  16544. source: node.parent,
  16545. target: node
  16546. });
  16547. }
  16548. });
  16549. return links;
  16550. }
  16551. var regeneratorRuntime$1 = createCommonjsModule(function (module) {
  16552. var _typeof = _typeof_1["default"];
  16553. function _regeneratorRuntime() {
  16554. /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
  16555. module.exports = _regeneratorRuntime = function _regeneratorRuntime() {
  16556. return exports;
  16557. }, module.exports.__esModule = true, module.exports["default"] = module.exports;
  16558. var exports = {},
  16559. Op = Object.prototype,
  16560. hasOwn = Op.hasOwnProperty,
  16561. $Symbol = "function" == typeof Symbol ? Symbol : {},
  16562. iteratorSymbol = $Symbol.iterator || "@@iterator",
  16563. asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator",
  16564. toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
  16565. function define(obj, key, value) {
  16566. return Object.defineProperty(obj, key, {
  16567. value: value,
  16568. enumerable: !0,
  16569. configurable: !0,
  16570. writable: !0
  16571. }), obj[key];
  16572. }
  16573. try {
  16574. define({}, "");
  16575. } catch (err) {
  16576. define = function define(obj, key, value) {
  16577. return obj[key] = value;
  16578. };
  16579. }
  16580. function wrap(innerFn, outerFn, self, tryLocsList) {
  16581. var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator,
  16582. generator = Object.create(protoGenerator.prototype),
  16583. context = new Context(tryLocsList || []);
  16584. return generator._invoke = function (innerFn, self, context) {
  16585. var state = "suspendedStart";
  16586. return function (method, arg) {
  16587. if ("executing" === state) throw new Error("Generator is already running");
  16588. if ("completed" === state) {
  16589. if ("throw" === method) throw arg;
  16590. return doneResult();
  16591. }
  16592. for (context.method = method, context.arg = arg;;) {
  16593. var delegate = context.delegate;
  16594. if (delegate) {
  16595. var delegateResult = maybeInvokeDelegate(delegate, context);
  16596. if (delegateResult) {
  16597. if (delegateResult === ContinueSentinel) continue;
  16598. return delegateResult;
  16599. }
  16600. }
  16601. if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) {
  16602. if ("suspendedStart" === state) throw state = "completed", context.arg;
  16603. context.dispatchException(context.arg);
  16604. } else "return" === context.method && context.abrupt("return", context.arg);
  16605. state = "executing";
  16606. var record = tryCatch(innerFn, self, context);
  16607. if ("normal" === record.type) {
  16608. if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue;
  16609. return {
  16610. value: record.arg,
  16611. done: context.done
  16612. };
  16613. }
  16614. "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg);
  16615. }
  16616. };
  16617. }(innerFn, self, context), generator;
  16618. }
  16619. function tryCatch(fn, obj, arg) {
  16620. try {
  16621. return {
  16622. type: "normal",
  16623. arg: fn.call(obj, arg)
  16624. };
  16625. } catch (err) {
  16626. return {
  16627. type: "throw",
  16628. arg: err
  16629. };
  16630. }
  16631. }
  16632. exports.wrap = wrap;
  16633. var ContinueSentinel = {};
  16634. function Generator() {}
  16635. function GeneratorFunction() {}
  16636. function GeneratorFunctionPrototype() {}
  16637. var IteratorPrototype = {};
  16638. define(IteratorPrototype, iteratorSymbol, function () {
  16639. return this;
  16640. });
  16641. var getProto = Object.getPrototypeOf,
  16642. NativeIteratorPrototype = getProto && getProto(getProto(values([])));
  16643. NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype);
  16644. var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
  16645. function defineIteratorMethods(prototype) {
  16646. ["next", "throw", "return"].forEach(function (method) {
  16647. define(prototype, method, function (arg) {
  16648. return this._invoke(method, arg);
  16649. });
  16650. });
  16651. }
  16652. function AsyncIterator(generator, PromiseImpl) {
  16653. function invoke(method, arg, resolve, reject) {
  16654. var record = tryCatch(generator[method], generator, arg);
  16655. if ("throw" !== record.type) {
  16656. var result = record.arg,
  16657. value = result.value;
  16658. return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
  16659. invoke("next", value, resolve, reject);
  16660. }, function (err) {
  16661. invoke("throw", err, resolve, reject);
  16662. }) : PromiseImpl.resolve(value).then(function (unwrapped) {
  16663. result.value = unwrapped, resolve(result);
  16664. }, function (error) {
  16665. return invoke("throw", error, resolve, reject);
  16666. });
  16667. }
  16668. reject(record.arg);
  16669. }
  16670. var previousPromise;
  16671. this._invoke = function (method, arg) {
  16672. function callInvokeWithMethodAndArg() {
  16673. return new PromiseImpl(function (resolve, reject) {
  16674. invoke(method, arg, resolve, reject);
  16675. });
  16676. }
  16677. return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
  16678. };
  16679. }
  16680. function maybeInvokeDelegate(delegate, context) {
  16681. var method = delegate.iterator[context.method];
  16682. if (undefined === method) {
  16683. if (context.delegate = null, "throw" === context.method) {
  16684. if (delegate.iterator["return"] && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method)) return ContinueSentinel;
  16685. context.method = "throw", context.arg = new TypeError("The iterator does not provide a 'throw' method");
  16686. }
  16687. return ContinueSentinel;
  16688. }
  16689. var record = tryCatch(method, delegate.iterator, context.arg);
  16690. if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel;
  16691. var info = record.arg;
  16692. 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);
  16693. }
  16694. function pushTryEntry(locs) {
  16695. var entry = {
  16696. tryLoc: locs[0]
  16697. };
  16698. 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry);
  16699. }
  16700. function resetTryEntry(entry) {
  16701. var record = entry.completion || {};
  16702. record.type = "normal", delete record.arg, entry.completion = record;
  16703. }
  16704. function Context(tryLocsList) {
  16705. this.tryEntries = [{
  16706. tryLoc: "root"
  16707. }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0);
  16708. }
  16709. function values(iterable) {
  16710. if (iterable) {
  16711. var iteratorMethod = iterable[iteratorSymbol];
  16712. if (iteratorMethod) return iteratorMethod.call(iterable);
  16713. if ("function" == typeof iterable.next) return iterable;
  16714. if (!isNaN(iterable.length)) {
  16715. var i = -1,
  16716. next = function next() {
  16717. for (; ++i < iterable.length;) {
  16718. if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next;
  16719. }
  16720. return next.value = undefined, next.done = !0, next;
  16721. };
  16722. return next.next = next;
  16723. }
  16724. }
  16725. return {
  16726. next: doneResult
  16727. };
  16728. }
  16729. function doneResult() {
  16730. return {
  16731. value: undefined,
  16732. done: !0
  16733. };
  16734. }
  16735. return GeneratorFunction.prototype = GeneratorFunctionPrototype, define(Gp, "constructor", GeneratorFunctionPrototype), define(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) {
  16736. var ctor = "function" == typeof genFun && genFun.constructor;
  16737. return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name));
  16738. }, exports.mark = function (genFun) {
  16739. return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun;
  16740. }, exports.awrap = function (arg) {
  16741. return {
  16742. __await: arg
  16743. };
  16744. }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
  16745. return this;
  16746. }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
  16747. void 0 === PromiseImpl && (PromiseImpl = Promise);
  16748. var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
  16749. return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) {
  16750. return result.done ? result.value : iter.next();
  16751. });
  16752. }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () {
  16753. return this;
  16754. }), define(Gp, "toString", function () {
  16755. return "[object Generator]";
  16756. }), exports.keys = function (object) {
  16757. var keys = [];
  16758. for (var key in object) {
  16759. keys.push(key);
  16760. }
  16761. return keys.reverse(), function next() {
  16762. for (; keys.length;) {
  16763. var key = keys.pop();
  16764. if (key in object) return next.value = key, next.done = !1, next;
  16765. }
  16766. return next.done = !0, next;
  16767. };
  16768. }, exports.values = values, Context.prototype = {
  16769. constructor: Context,
  16770. reset: function reset(skipTempReset) {
  16771. 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) {
  16772. "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined);
  16773. }
  16774. },
  16775. stop: function stop() {
  16776. this.done = !0;
  16777. var rootRecord = this.tryEntries[0].completion;
  16778. if ("throw" === rootRecord.type) throw rootRecord.arg;
  16779. return this.rval;
  16780. },
  16781. dispatchException: function dispatchException(exception) {
  16782. if (this.done) throw exception;
  16783. var context = this;
  16784. function handle(loc, caught) {
  16785. return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught;
  16786. }
  16787. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  16788. var entry = this.tryEntries[i],
  16789. record = entry.completion;
  16790. if ("root" === entry.tryLoc) return handle("end");
  16791. if (entry.tryLoc <= this.prev) {
  16792. var hasCatch = hasOwn.call(entry, "catchLoc"),
  16793. hasFinally = hasOwn.call(entry, "finallyLoc");
  16794. if (hasCatch && hasFinally) {
  16795. if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
  16796. if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
  16797. } else if (hasCatch) {
  16798. if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
  16799. } else {
  16800. if (!hasFinally) throw new Error("try statement without catch or finally");
  16801. if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
  16802. }
  16803. }
  16804. }
  16805. },
  16806. abrupt: function abrupt(type, arg) {
  16807. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  16808. var entry = this.tryEntries[i];
  16809. if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
  16810. var finallyEntry = entry;
  16811. break;
  16812. }
  16813. }
  16814. finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null);
  16815. var record = finallyEntry ? finallyEntry.completion : {};
  16816. return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record);
  16817. },
  16818. complete: function complete(record, afterLoc) {
  16819. if ("throw" === record.type) throw record.arg;
  16820. 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;
  16821. },
  16822. finish: function finish(finallyLoc) {
  16823. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  16824. var entry = this.tryEntries[i];
  16825. if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel;
  16826. }
  16827. },
  16828. "catch": function _catch(tryLoc) {
  16829. for (var i = this.tryEntries.length - 1; i >= 0; --i) {
  16830. var entry = this.tryEntries[i];
  16831. if (entry.tryLoc === tryLoc) {
  16832. var record = entry.completion;
  16833. if ("throw" === record.type) {
  16834. var thrown = record.arg;
  16835. resetTryEntry(entry);
  16836. }
  16837. return thrown;
  16838. }
  16839. }
  16840. throw new Error("illegal catch attempt");
  16841. },
  16842. delegateYield: function delegateYield(iterable, resultName, nextLoc) {
  16843. return this.delegate = {
  16844. iterator: values(iterable),
  16845. resultName: resultName,
  16846. nextLoc: nextLoc
  16847. }, "next" === this.method && (this.arg = undefined), ContinueSentinel;
  16848. }
  16849. }, exports;
  16850. }
  16851. module.exports = _regeneratorRuntime, module.exports.__esModule = true, module.exports["default"] = module.exports;
  16852. });
  16853. // TODO(Babel 8): Remove this file.
  16854. var runtime = regeneratorRuntime$1();
  16855. var regenerator = runtime;
  16856. // Copied from https://github.com/facebook/regenerator/blob/main/packages/runtime/runtime.js#L736=
  16857. try {
  16858. regeneratorRuntime = runtime;
  16859. } catch (accidentalStrictMode) {
  16860. if (typeof globalThis === "object") {
  16861. globalThis.regeneratorRuntime = runtime;
  16862. } else {
  16863. Function("r", "regeneratorRuntime = r")(runtime);
  16864. }
  16865. }
  16866. var _marked = /*#__PURE__*/regenerator.mark(_callee);
  16867. function _callee() {
  16868. var node, current, next, children, i, n;
  16869. return regenerator.wrap(function _callee$(_context) {
  16870. while (1) {
  16871. switch (_context.prev = _context.next) {
  16872. case 0:
  16873. node = this, next = [node];
  16874. case 1:
  16875. current = next.reverse(), next = [];
  16876. case 2:
  16877. if (!(node = current.pop())) {
  16878. _context.next = 8;
  16879. break;
  16880. }
  16881. _context.next = 5;
  16882. return node;
  16883. case 5:
  16884. if (children = node.children) {
  16885. for (i = 0, n = children.length; i < n; ++i) {
  16886. next.push(children[i]);
  16887. }
  16888. }
  16889. _context.next = 2;
  16890. break;
  16891. case 8:
  16892. if (next.length) {
  16893. _context.next = 1;
  16894. break;
  16895. }
  16896. case 9:
  16897. case "end":
  16898. return _context.stop();
  16899. }
  16900. }
  16901. }, _marked, this);
  16902. }
  16903. function hierarchy(data, children) {
  16904. if (data instanceof Map) {
  16905. data = [undefined, data];
  16906. if (children === undefined) children = mapChildren;
  16907. } else if (children === undefined) {
  16908. children = objectChildren;
  16909. }
  16910. var root = new Node(data),
  16911. node,
  16912. nodes = [root],
  16913. child,
  16914. childs,
  16915. i,
  16916. n;
  16917. while (node = nodes.pop()) {
  16918. if ((childs = children(node.data)) && (n = (childs = Array.from(childs)).length)) {
  16919. node.children = childs;
  16920. for (i = n - 1; i >= 0; --i) {
  16921. nodes.push(child = childs[i] = new Node(childs[i]));
  16922. child.parent = node;
  16923. child.depth = node.depth + 1;
  16924. }
  16925. }
  16926. }
  16927. return root.eachBefore(computeHeight);
  16928. }
  16929. function node_copy() {
  16930. return hierarchy(this).eachBefore(copyData);
  16931. }
  16932. function objectChildren(d) {
  16933. return d.children;
  16934. }
  16935. function mapChildren(d) {
  16936. return Array.isArray(d) ? d[1] : null;
  16937. }
  16938. function copyData(node) {
  16939. if (node.data.value !== undefined) node.value = node.data.value;
  16940. node.data = node.data.data;
  16941. }
  16942. function computeHeight(node) {
  16943. var height = 0;
  16944. do {
  16945. node.height = height;
  16946. } while ((node = node.parent) && node.height < ++height);
  16947. }
  16948. function Node(data) {
  16949. this.data = data;
  16950. this.depth = this.height = 0;
  16951. this.parent = null;
  16952. }
  16953. Node.prototype = hierarchy.prototype = _defineProperty({
  16954. constructor: Node,
  16955. count: node_count,
  16956. each: node_each,
  16957. eachAfter: node_eachAfter,
  16958. eachBefore: node_eachBefore,
  16959. find: node_find,
  16960. sum: node_sum,
  16961. sort: node_sort,
  16962. path: node_path,
  16963. ancestors: node_ancestors,
  16964. descendants: node_descendants,
  16965. leaves: node_leaves,
  16966. links: node_links,
  16967. copy: node_copy
  16968. }, Symbol.iterator, _callee);
  16969. function required(f) {
  16970. if (typeof f !== "function") throw new Error();
  16971. return f;
  16972. }
  16973. function constantZero() {
  16974. return 0;
  16975. }
  16976. function constant$1 (x) {
  16977. return function () {
  16978. return x;
  16979. };
  16980. }
  16981. function roundNode (node) {
  16982. node.x0 = Math.round(node.x0);
  16983. node.y0 = Math.round(node.y0);
  16984. node.x1 = Math.round(node.x1);
  16985. node.y1 = Math.round(node.y1);
  16986. }
  16987. function treemapDice (parent, x0, y0, x1, y1) {
  16988. var nodes = parent.children,
  16989. node,
  16990. i = -1,
  16991. n = nodes.length,
  16992. k = parent.value && (x1 - x0) / parent.value;
  16993. while (++i < n) {
  16994. node = nodes[i], node.y0 = y0, node.y1 = y1;
  16995. node.x0 = x0, node.x1 = x0 += node.value * k;
  16996. }
  16997. }
  16998. function partition () {
  16999. var dx = 1,
  17000. dy = 1,
  17001. padding = 0,
  17002. round = false;
  17003. function partition(root) {
  17004. var n = root.height + 1;
  17005. root.x0 = root.y0 = padding;
  17006. root.x1 = dx;
  17007. root.y1 = dy / n;
  17008. root.eachBefore(positionNode(dy, n));
  17009. if (round) root.eachBefore(roundNode);
  17010. return root;
  17011. }
  17012. function positionNode(dy, n) {
  17013. return function (node) {
  17014. if (node.children) {
  17015. treemapDice(node, node.x0, dy * (node.depth + 1) / n, node.x1, dy * (node.depth + 2) / n);
  17016. }
  17017. var x0 = node.x0,
  17018. y0 = node.y0,
  17019. x1 = node.x1 - padding,
  17020. y1 = node.y1 - padding;
  17021. if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
  17022. if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
  17023. node.x0 = x0;
  17024. node.y0 = y0;
  17025. node.x1 = x1;
  17026. node.y1 = y1;
  17027. };
  17028. }
  17029. partition.round = function (x) {
  17030. return arguments.length ? (round = !!x, partition) : round;
  17031. };
  17032. partition.size = function (x) {
  17033. return arguments.length ? (dx = +x[0], dy = +x[1], partition) : [dx, dy];
  17034. };
  17035. partition.padding = function (x) {
  17036. return arguments.length ? (padding = +x, partition) : padding;
  17037. };
  17038. return partition;
  17039. }
  17040. function treemapSlice (parent, x0, y0, x1, y1) {
  17041. var nodes = parent.children,
  17042. node,
  17043. i = -1,
  17044. n = nodes.length,
  17045. k = parent.value && (y1 - y0) / parent.value;
  17046. while (++i < n) {
  17047. node = nodes[i], node.x0 = x0, node.x1 = x1;
  17048. node.y0 = y0, node.y1 = y0 += node.value * k;
  17049. }
  17050. }
  17051. var phi = (1 + Math.sqrt(5)) / 2;
  17052. function squarifyRatio(ratio, parent, x0, y0, x1, y1) {
  17053. var rows = [],
  17054. nodes = parent.children,
  17055. row,
  17056. nodeValue,
  17057. i0 = 0,
  17058. i1 = 0,
  17059. n = nodes.length,
  17060. dx,
  17061. dy,
  17062. value = parent.value,
  17063. sumValue,
  17064. minValue,
  17065. maxValue,
  17066. newRatio,
  17067. minRatio,
  17068. alpha,
  17069. beta;
  17070. while (i0 < n) {
  17071. dx = x1 - x0, dy = y1 - y0; // Find the next non-empty node.
  17072. do {
  17073. sumValue = nodes[i1++].value;
  17074. } while (!sumValue && i1 < n);
  17075. minValue = maxValue = sumValue;
  17076. alpha = Math.max(dy / dx, dx / dy) / (value * ratio);
  17077. beta = sumValue * sumValue * alpha;
  17078. minRatio = Math.max(maxValue / beta, beta / minValue); // Keep adding nodes while the aspect ratio maintains or improves.
  17079. for (; i1 < n; ++i1) {
  17080. sumValue += nodeValue = nodes[i1].value;
  17081. if (nodeValue < minValue) minValue = nodeValue;
  17082. if (nodeValue > maxValue) maxValue = nodeValue;
  17083. beta = sumValue * sumValue * alpha;
  17084. newRatio = Math.max(maxValue / beta, beta / minValue);
  17085. if (newRatio > minRatio) {
  17086. sumValue -= nodeValue;
  17087. break;
  17088. }
  17089. minRatio = newRatio;
  17090. } // Position and record the row orientation.
  17091. rows.push(row = {
  17092. value: sumValue,
  17093. dice: dx < dy,
  17094. children: nodes.slice(i0, i1)
  17095. });
  17096. 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);
  17097. value -= sumValue, i0 = i1;
  17098. }
  17099. return rows;
  17100. }
  17101. var squarify = (function custom(ratio) {
  17102. function squarify(parent, x0, y0, x1, y1) {
  17103. squarifyRatio(ratio, parent, x0, y0, x1, y1);
  17104. }
  17105. squarify.ratio = function (x) {
  17106. return custom((x = +x) > 1 ? x : 1);
  17107. };
  17108. return squarify;
  17109. })(phi);
  17110. function treemap () {
  17111. var tile = squarify,
  17112. round = false,
  17113. dx = 1,
  17114. dy = 1,
  17115. paddingStack = [0],
  17116. paddingInner = constantZero,
  17117. paddingTop = constantZero,
  17118. paddingRight = constantZero,
  17119. paddingBottom = constantZero,
  17120. paddingLeft = constantZero;
  17121. function treemap(root) {
  17122. root.x0 = root.y0 = 0;
  17123. root.x1 = dx;
  17124. root.y1 = dy;
  17125. root.eachBefore(positionNode);
  17126. paddingStack = [0];
  17127. if (round) root.eachBefore(roundNode);
  17128. return root;
  17129. }
  17130. function positionNode(node) {
  17131. var p = paddingStack[node.depth],
  17132. x0 = node.x0 + p,
  17133. y0 = node.y0 + p,
  17134. x1 = node.x1 - p,
  17135. y1 = node.y1 - p;
  17136. if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
  17137. if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
  17138. node.x0 = x0;
  17139. node.y0 = y0;
  17140. node.x1 = x1;
  17141. node.y1 = y1;
  17142. if (node.children) {
  17143. p = paddingStack[node.depth + 1] = paddingInner(node) / 2;
  17144. x0 += paddingLeft(node) - p;
  17145. y0 += paddingTop(node) - p;
  17146. x1 -= paddingRight(node) - p;
  17147. y1 -= paddingBottom(node) - p;
  17148. if (x1 < x0) x0 = x1 = (x0 + x1) / 2;
  17149. if (y1 < y0) y0 = y1 = (y0 + y1) / 2;
  17150. tile(node, x0, y0, x1, y1);
  17151. }
  17152. }
  17153. treemap.round = function (x) {
  17154. return arguments.length ? (round = !!x, treemap) : round;
  17155. };
  17156. treemap.size = function (x) {
  17157. return arguments.length ? (dx = +x[0], dy = +x[1], treemap) : [dx, dy];
  17158. };
  17159. treemap.tile = function (x) {
  17160. return arguments.length ? (tile = required(x), treemap) : tile;
  17161. };
  17162. treemap.padding = function (x) {
  17163. return arguments.length ? treemap.paddingInner(x).paddingOuter(x) : treemap.paddingInner();
  17164. };
  17165. treemap.paddingInner = function (x) {
  17166. return arguments.length ? (paddingInner = typeof x === "function" ? x : constant$1(+x), treemap) : paddingInner;
  17167. };
  17168. treemap.paddingOuter = function (x) {
  17169. return arguments.length ? treemap.paddingTop(x).paddingRight(x).paddingBottom(x).paddingLeft(x) : treemap.paddingTop();
  17170. };
  17171. treemap.paddingTop = function (x) {
  17172. return arguments.length ? (paddingTop = typeof x === "function" ? x : constant$1(+x), treemap) : paddingTop;
  17173. };
  17174. treemap.paddingRight = function (x) {
  17175. return arguments.length ? (paddingRight = typeof x === "function" ? x : constant$1(+x), treemap) : paddingRight;
  17176. };
  17177. treemap.paddingBottom = function (x) {
  17178. return arguments.length ? (paddingBottom = typeof x === "function" ? x : constant$1(+x), treemap) : paddingBottom;
  17179. };
  17180. treemap.paddingLeft = function (x) {
  17181. return arguments.length ? (paddingLeft = typeof x === "function" ? x : constant$1(+x), treemap) : paddingLeft;
  17182. };
  17183. return treemap;
  17184. }
  17185. function treemapBinary (parent, x0, y0, x1, y1) {
  17186. var nodes = parent.children,
  17187. i,
  17188. n = nodes.length,
  17189. sum,
  17190. sums = new Array(n + 1);
  17191. for (sums[0] = sum = i = 0; i < n; ++i) {
  17192. sums[i + 1] = sum += nodes[i].value;
  17193. }
  17194. partition(0, n, parent.value, x0, y0, x1, y1);
  17195. function partition(i, j, value, x0, y0, x1, y1) {
  17196. if (i >= j - 1) {
  17197. var node = nodes[i];
  17198. node.x0 = x0, node.y0 = y0;
  17199. node.x1 = x1, node.y1 = y1;
  17200. return;
  17201. }
  17202. var valueOffset = sums[i],
  17203. valueTarget = value / 2 + valueOffset,
  17204. k = i + 1,
  17205. hi = j - 1;
  17206. while (k < hi) {
  17207. var mid = k + hi >>> 1;
  17208. if (sums[mid] < valueTarget) k = mid + 1;else hi = mid;
  17209. }
  17210. if (valueTarget - sums[k - 1] < sums[k] - valueTarget && i + 1 < k) --k;
  17211. var valueLeft = sums[k] - valueOffset,
  17212. valueRight = value - valueLeft;
  17213. if (x1 - x0 > y1 - y0) {
  17214. var xk = value ? (x0 * valueRight + x1 * valueLeft) / value : x1;
  17215. partition(i, k, valueLeft, x0, y0, xk, y1);
  17216. partition(k, j, valueRight, xk, y0, x1, y1);
  17217. } else {
  17218. var yk = value ? (y0 * valueRight + y1 * valueLeft) / value : y1;
  17219. partition(i, k, valueLeft, x0, y0, x1, yk);
  17220. partition(k, j, valueRight, x0, yk, x1, y1);
  17221. }
  17222. }
  17223. }
  17224. var withTreemap = (function (View) {
  17225. return /*#__PURE__*/function (_Component) {
  17226. _inherits(Treemap, _Component);
  17227. var _super = _createSuper(Treemap);
  17228. function Treemap(props, context, updater) {
  17229. var _this;
  17230. _classCallCheck(this, Treemap);
  17231. _this = _super.call(this, props, context, updater);
  17232. var coord = props.coord,
  17233. color = props.color,
  17234. data = props.data;
  17235. var width = context.width,
  17236. height = context.height,
  17237. theme = context.theme;
  17238. _this.coordController = new coordController();
  17239. var _assertThisInitialize = _assertThisInitialized(_this),
  17240. coordController$1 = _assertThisInitialize.coordController;
  17241. _this.coord = coordController$1.create(coord, {
  17242. width: width,
  17243. height: height
  17244. });
  17245. _this.color = new Category$1(_objectSpread(_objectSpread({
  17246. range: theme.colors
  17247. }, color), {}, {
  17248. data: data
  17249. }));
  17250. return _this;
  17251. }
  17252. _createClass(Treemap, [{
  17253. key: "treemapLayout",
  17254. value: function treemapLayout() {
  17255. var props = this.props,
  17256. coord = this.coord,
  17257. colorAttr = this.color;
  17258. var data = props.data,
  17259. value = props.value;
  17260. var root = hierarchy({
  17261. children: data
  17262. }).sum(function (d) {
  17263. return d[value];
  17264. }).sort(function (a, b) {
  17265. return b[value] - a[value];
  17266. });
  17267. var treemapLayout = treemap() // 默认treemapSquarify
  17268. .tile(treemapBinary) // .size([1, 1])
  17269. // @ts-ignore
  17270. .round(false); // .padding(space)
  17271. // .paddingInner(space);
  17272. // .paddingOuter(options.paddingOuter)
  17273. // .paddingTop(options.paddingTop)
  17274. // .paddingRight(options.paddingRight)
  17275. // .paddingBottom(options.paddingBottom)
  17276. // .paddingLeft(options.paddingLeft);
  17277. var nodes = treemapLayout(root);
  17278. return nodes.children.map(function (item) {
  17279. var data = item.data,
  17280. x0 = item.x0,
  17281. y0 = item.y0,
  17282. x1 = item.x1,
  17283. y1 = item.y1;
  17284. var color = colorAttr.mapping(data[colorAttr.field]);
  17285. var rect = coord.convertRect({
  17286. x: [x0, x1],
  17287. y: [y0, y1]
  17288. });
  17289. return _objectSpread({
  17290. key: data.key,
  17291. origin: data,
  17292. color: color
  17293. }, rect);
  17294. });
  17295. }
  17296. }, {
  17297. key: "render",
  17298. value: function render() {
  17299. var nodes = this.treemapLayout();
  17300. var props = this.props,
  17301. coord = this.coord;
  17302. return jsx(View, _objectSpread(_objectSpread({
  17303. nodes: nodes
  17304. }, props), {}, {
  17305. coord: coord
  17306. }));
  17307. }
  17308. }]);
  17309. return Treemap;
  17310. }(Component);
  17311. });
  17312. var TreemapView = (function (props) {
  17313. var nodes = props.nodes,
  17314. coord = props.coord;
  17315. if (coord.isPolar) {
  17316. var center = coord.center;
  17317. var x = center.x,
  17318. y = center.y;
  17319. return jsx("group", null, nodes.map(function (node) {
  17320. var xMin = node.xMin,
  17321. xMax = node.xMax,
  17322. yMin = node.yMin,
  17323. yMax = node.yMax,
  17324. color = node.color;
  17325. return jsx("sector", {
  17326. attrs: {
  17327. x: x,
  17328. y: y,
  17329. lineWidth: '1px',
  17330. stroke: '#fff',
  17331. startAngle: xMin,
  17332. endAngle: xMax,
  17333. r0: yMin,
  17334. r: yMax,
  17335. anticlockwise: false,
  17336. fill: color
  17337. }
  17338. });
  17339. }));
  17340. }
  17341. return jsx("group", null, nodes.map(function (node) {
  17342. var key = node.key,
  17343. xMin = node.xMin,
  17344. xMax = node.xMax,
  17345. yMin = node.yMin,
  17346. yMax = node.yMax,
  17347. color = node.color;
  17348. return jsx("rect", {
  17349. key: key,
  17350. attrs: {
  17351. x: xMin,
  17352. y: yMin,
  17353. width: xMax - xMin,
  17354. height: yMax - yMin,
  17355. fill: color,
  17356. lineWidth: '4px',
  17357. stroke: '#fff',
  17358. radius: '8px'
  17359. },
  17360. animation: {
  17361. appear: {
  17362. easing: 'linear',
  17363. duration: 450,
  17364. property: ['fillOpacity', 'strokeOpacity'],
  17365. start: {
  17366. fillOpacity: 0,
  17367. strokeOpacity: 0
  17368. },
  17369. end: {
  17370. fillOpacity: 1,
  17371. strokeOpacity: 1
  17372. }
  17373. },
  17374. update: {
  17375. easing: 'linear',
  17376. duration: 450,
  17377. property: ['x', 'y', 'width', 'height', 'radius', 'lineWidth']
  17378. }
  17379. }
  17380. });
  17381. }));
  17382. });
  17383. var index$8 = withTreemap(TreemapView);
  17384. function rootParent(data) {
  17385. var d = data;
  17386. while (d.depth > 1) {
  17387. d = d.parent;
  17388. }
  17389. return d;
  17390. }
  17391. var withSunburst = (function (View) {
  17392. return /*#__PURE__*/function (_Component) {
  17393. _inherits(Sunburst, _Component);
  17394. var _super = _createSuper(Sunburst);
  17395. function Sunburst(props, context) {
  17396. var _this;
  17397. _classCallCheck(this, Sunburst);
  17398. _this = _super.call(this, props, context);
  17399. var coord = props.coord,
  17400. color = props.color,
  17401. data = props.data;
  17402. var width = context.width,
  17403. height = context.height,
  17404. theme = context.theme;
  17405. _this.coordController = new coordController();
  17406. var _assertThisInitialize = _assertThisInitialized(_this),
  17407. coordController$1 = _assertThisInitialize.coordController;
  17408. _this.coord = coordController$1.create(coord, {
  17409. width: width,
  17410. height: height
  17411. });
  17412. _this.color = new Category$1(_objectSpread(_objectSpread({
  17413. range: theme.colors
  17414. }, color), {}, {
  17415. data: data
  17416. }));
  17417. return _this;
  17418. }
  17419. _createClass(Sunburst, [{
  17420. key: "didMount",
  17421. value: function didMount() {
  17422. var _this2 = this;
  17423. var props = this.props,
  17424. container = this.container;
  17425. var onClick = props.onClick;
  17426. var canvas = container.get('canvas');
  17427. this.triggerRef = [];
  17428. canvas.on('click', function (ev) {
  17429. var points = ev.points;
  17430. var shape = _this2.triggerRef.find(function (ref) {
  17431. return isInBBox(ref.current.getBBox(), points[0]);
  17432. });
  17433. if (shape) {
  17434. ev.shape = shape; // @ts-ignore
  17435. ev.payload = shape.payload;
  17436. onClick && onClick(ev);
  17437. }
  17438. });
  17439. }
  17440. }, {
  17441. key: "_mapping",
  17442. value: function _mapping(children) {
  17443. var colorAttr = this.color,
  17444. coord = this.coord;
  17445. for (var i = 0, len = children.length; i < len; i++) {
  17446. var node = children[i];
  17447. var root = rootParent(node);
  17448. var color = colorAttr.mapping(root.data[colorAttr.field]);
  17449. node.color = color;
  17450. var x0 = node.x0,
  17451. x1 = node.x1,
  17452. y0 = node.y0,
  17453. y1 = node.y1;
  17454. var rect = coord.convertRect({
  17455. x: [x0, x1],
  17456. y: [y0, y1]
  17457. });
  17458. mix(node, rect); // 递归处理
  17459. if (node.children && node.children.length) {
  17460. this._mapping(node.children);
  17461. }
  17462. }
  17463. }
  17464. }, {
  17465. key: "sunburst",
  17466. value: function sunburst() {
  17467. var props = this.props;
  17468. var data = props.data,
  17469. value = props.value,
  17470. _props$sort = props.sort,
  17471. sort = _props$sort === void 0 ? true : _props$sort;
  17472. var root = hierarchy({
  17473. children: data
  17474. }).sum(function (d) {
  17475. return d[value];
  17476. }); // 内置按value大小顺序排序,支持传入sort函数
  17477. if (sort === true || isFunction(sort)) {
  17478. var sortFn = isFunction(sort) ? sort : function (a, b) {
  17479. return b[value] - a[value];
  17480. };
  17481. root.sort(sortFn);
  17482. }
  17483. var nodes = partition()(root);
  17484. var children = nodes.children;
  17485. this._mapping(children);
  17486. return nodes;
  17487. }
  17488. }, {
  17489. key: "render",
  17490. value: function render() {
  17491. var node = this.sunburst();
  17492. var coord = this.coord,
  17493. props = this.props;
  17494. return jsx(View, _objectSpread(_objectSpread({}, props), {}, {
  17495. coord: coord,
  17496. node: node,
  17497. triggerRef: this.triggerRef
  17498. }));
  17499. }
  17500. }]);
  17501. return Sunburst;
  17502. }(Component);
  17503. });
  17504. var SunburstView = (function (props) {
  17505. var coord = props.coord,
  17506. node = props.node;
  17507. var children = node.children;
  17508. var _coord$center = coord.center,
  17509. x = _coord$center.x,
  17510. y = _coord$center.y;
  17511. var renderNodes = function renderNodes(nodes) {
  17512. return jsx("group", null, nodes.map(function (node) {
  17513. var xMin = node.xMin,
  17514. xMax = node.xMax,
  17515. yMin = node.yMin,
  17516. yMax = node.yMax,
  17517. color = node.color,
  17518. children = node.children;
  17519. return jsx("group", null, jsx("sector", {
  17520. attrs: {
  17521. x: x,
  17522. y: y,
  17523. lineWidth: '1px',
  17524. stroke: '#fff',
  17525. startAngle: xMin,
  17526. endAngle: xMax,
  17527. r0: yMin,
  17528. r: yMax,
  17529. anticlockwise: false,
  17530. fill: color
  17531. }
  17532. }), children && children.length ? renderNodes(children) : null);
  17533. }));
  17534. };
  17535. return renderNodes(children);
  17536. });
  17537. var IcicleView = (function (props) {
  17538. var node = props.node;
  17539. var children = node.children;
  17540. var renderNodes = function renderNodes(nodes) {
  17541. return jsx("group", null, nodes.map(function (node) {
  17542. var xMin = node.xMin,
  17543. xMax = node.xMax,
  17544. yMin = node.yMin,
  17545. yMax = node.yMax,
  17546. color = node.color,
  17547. children = node.children;
  17548. return jsx("group", null, jsx("rect", {
  17549. attrs: {
  17550. x: xMin,
  17551. y: yMin,
  17552. width: xMax - xMin,
  17553. height: yMax - yMin,
  17554. lineWidth: '1px',
  17555. stroke: '#fff',
  17556. fill: color
  17557. }
  17558. }), children && children.length ? renderNodes(children) : null);
  17559. }));
  17560. };
  17561. return renderNodes(children);
  17562. });
  17563. var View = (function (props) {
  17564. var coord = props.coord;
  17565. if (coord.type === 'polar') {
  17566. return jsx(SunburstView, _objectSpread({}, props));
  17567. }
  17568. return jsx(IcicleView, _objectSpread({}, props));
  17569. });
  17570. var index$9 = withSunburst(View);
  17571. var DEFAULT_CONFIG = {
  17572. anchorOffset: '10px',
  17573. inflectionOffset: '30px',
  17574. sidePadding: '15px',
  17575. height: '64px',
  17576. adjustOffset: '30',
  17577. triggerOn: 'click',
  17578. // activeShape: false, // 当有图形被选中的时候,是否激活图形
  17579. // activeStyle: {
  17580. // offset: '1px',
  17581. // appendRadius: '8px',
  17582. // fillOpacity: 0.5,
  17583. // },
  17584. label1OffsetY: '-4px',
  17585. label2OffsetY: '4px'
  17586. };
  17587. function getEndPoint(center, angle, r) {
  17588. return {
  17589. x: center.x + r * Math.cos(angle),
  17590. y: center.y + r * Math.sin(angle)
  17591. };
  17592. } // 计算中间角度
  17593. function getMiddleAngle(startAngle, endAngle) {
  17594. if (endAngle < startAngle) {
  17595. endAngle += Math.PI * 2;
  17596. }
  17597. return (endAngle + startAngle) / 2;
  17598. }
  17599. function move(from, to, count, center) {
  17600. var x = center.x;
  17601. var sort = from.sort(function (a, b) {
  17602. var aDistance = Math.abs(a.x - x);
  17603. var bDistance = Math.abs(b.x - x);
  17604. return bDistance - aDistance;
  17605. });
  17606. return [sort.slice(0, sort.length - count), sort.slice(sort.length - count).concat(to)];
  17607. } // 第一象限
  17608. function isFirstQuadrant(angle) {
  17609. return angle >= -Math.PI / 2 && angle < 0;
  17610. } // 第二象限
  17611. function isSecondQuadrant(angle) {
  17612. return angle >= 0 && angle < Math.PI / 2;
  17613. }
  17614. function isThirdQuadrant(angle) {
  17615. return angle >= Math.PI / 2 && angle < Math.PI;
  17616. }
  17617. function isFourthQuadrant(angle) {
  17618. return angle >= Math.PI && angle < Math.PI * 3 / 2;
  17619. }
  17620. function findShapeByClassName(shape, point, className) {
  17621. var targetShapes = getElementsByClassName(className, shape);
  17622. for (var i = 0, len = targetShapes.length; i < len; i++) {
  17623. var _shape = targetShapes[i];
  17624. if (isInBBox(_shape.getBBox(), point)) {
  17625. return _shape;
  17626. }
  17627. }
  17628. }
  17629. var withPieLabel = (function (View) {
  17630. return /*#__PURE__*/function (_Component) {
  17631. _inherits(PieLabel, _Component);
  17632. var _super = _createSuper(PieLabel);
  17633. function PieLabel(props) {
  17634. var _this;
  17635. _classCallCheck(this, PieLabel);
  17636. _this = _super.call(this, props);
  17637. _this._handleEvent = function (ev) {
  17638. var _this$props = _this.props,
  17639. chart = _this$props.chart,
  17640. onClick = _this$props.onClick;
  17641. var ele = _this.triggerRef.current;
  17642. var point = ev.points[0];
  17643. var shape = findShapeByClassName(ele, point, 'click');
  17644. var pieData = chart.getSnapRecords(point);
  17645. if (typeof onClick === 'function') {
  17646. // 点击label
  17647. if (shape) {
  17648. onClick(shape.get('data'));
  17649. } // 点击饼图
  17650. else if (isArray(pieData) && pieData.length > 0) {
  17651. onClick(pieData);
  17652. }
  17653. }
  17654. };
  17655. _this.triggerRef = {};
  17656. return _this;
  17657. }
  17658. _createClass(PieLabel, [{
  17659. key: "willMount",
  17660. value: function willMount() {}
  17661. /**
  17662. * 绑定事件
  17663. */
  17664. }, {
  17665. key: "didMount",
  17666. value: function didMount() {
  17667. this._initEvent();
  17668. }
  17669. }, {
  17670. key: "getLabels",
  17671. value: function getLabels(props) {
  17672. var chart = props.chart,
  17673. coord = props.coord,
  17674. anchorOffset = props.anchorOffset,
  17675. inflectionOffset = props.inflectionOffset,
  17676. label1 = props.label1,
  17677. label2 = props.label2,
  17678. itemHeight = props.height,
  17679. sidePadding = props.sidePadding;
  17680. var center = coord.center,
  17681. radius = coord.radius,
  17682. coordWidth = coord.width,
  17683. coordHeight = coord.height,
  17684. coordLeft = coord.left,
  17685. coordRight = coord.right,
  17686. coordTop = coord.top;
  17687. var maxCountForOneSide = Math.floor(coordHeight / itemHeight);
  17688. var maxCount = maxCountForOneSide * 2;
  17689. var geometry = chart.getGeometrys()[0];
  17690. var records = geometry.flatRecords() // 按角度大到小排序
  17691. .sort(function (a, b) {
  17692. var angle1 = a.xMax - a.xMin;
  17693. var angle2 = b.xMax - b.xMin;
  17694. return angle2 - angle1;
  17695. }) // 只取前 maxCount 个显示
  17696. .slice(0, maxCount); // 存储左右 labels
  17697. var halves = [[], [] // right
  17698. ];
  17699. records.forEach(function (record) {
  17700. var xMin = record.xMin,
  17701. xMax = record.xMax,
  17702. color = record.color,
  17703. origin = record.origin; // 锚点角度
  17704. var anchorAngle = getMiddleAngle(xMin, xMax); // 锚点坐标
  17705. var anchorPoint = getEndPoint(center, anchorAngle, radius + anchorOffset); // 拐点坐标
  17706. var inflectionPoint = getEndPoint(center, anchorAngle, radius + inflectionOffset); // 锚点方向
  17707. var side = anchorPoint.x < center.x ? 'left' : 'right';
  17708. var label = {
  17709. origin: origin,
  17710. angle: anchorAngle,
  17711. anchor: anchorPoint,
  17712. inflection: inflectionPoint,
  17713. side: side,
  17714. x: inflectionPoint.x,
  17715. y: inflectionPoint.y,
  17716. r: radius + inflectionOffset,
  17717. color: color,
  17718. label1: isFunction(label1) ? label1(origin, record) : label1,
  17719. label2: isFunction(label2) ? label2(origin, record) : label2
  17720. }; // 判断文本的方向
  17721. if (side === 'left') {
  17722. halves[0].push(label);
  17723. } else {
  17724. halves[1].push(label);
  17725. }
  17726. }); // 判断是有一边超过了显示的最大
  17727. if (halves[0].length > maxCountForOneSide) {
  17728. halves = move(halves[0], halves[1], halves[0].length - maxCountForOneSide, center);
  17729. } else if (halves[1].length > maxCountForOneSide) {
  17730. var _move = move(halves[1], halves[0], halves[1].length - maxCountForOneSide, center),
  17731. _move2 = _slicedToArray(_move, 2),
  17732. right = _move2[0],
  17733. left = _move2[1];
  17734. halves = [left, right];
  17735. } // label 的最大宽度
  17736. var labelWidth = coordWidth / 2 - radius - anchorOffset - inflectionOffset - 2 * sidePadding;
  17737. var labels = [];
  17738. halves.forEach(function (half, index) {
  17739. var showSide = index === 0 ? 'left' : 'right'; // 顺时针方向排序
  17740. half.sort(function (a, b) {
  17741. var aAngle = a.angle;
  17742. var bAngle = b.angle;
  17743. if (showSide === 'left') {
  17744. // 是否在第一象限
  17745. aAngle = isFirstQuadrant(aAngle) ? aAngle + Math.PI * 2 : aAngle;
  17746. bAngle = isFirstQuadrant(bAngle) ? bAngle + Math.PI * 2 : bAngle;
  17747. return bAngle - aAngle;
  17748. } else {
  17749. // 是否在第四象限
  17750. aAngle = isFourthQuadrant(aAngle) ? aAngle - Math.PI * 2 : aAngle;
  17751. bAngle = isFourthQuadrant(bAngle) ? bAngle - Math.PI * 2 : bAngle;
  17752. return aAngle - bAngle;
  17753. }
  17754. });
  17755. var pointsY = half.map(function (label) {
  17756. return label.y;
  17757. });
  17758. var maxY = Math.max.apply(null, pointsY);
  17759. var minY = Math.min.apply(null, pointsY); // 每个 label 占用的高度
  17760. var labelCount = half.length;
  17761. var labelHeight = coordHeight / labelCount;
  17762. var halfLabelHeight = labelHeight / 2; // 线之间的间隔
  17763. var lineInterval = 2;
  17764. if (showSide === 'left') {
  17765. half.forEach(function (label, index) {
  17766. var anchor = label.anchor,
  17767. inflection = label.inflection,
  17768. angle = label.angle,
  17769. x = label.x,
  17770. y = label.y;
  17771. var points = [anchor, inflection];
  17772. var endX = coordLeft + sidePadding;
  17773. var endY = coordTop + halfLabelHeight + labelHeight * index; // 文本开始点
  17774. var labelStart = {
  17775. x: endX + labelWidth + lineInterval * index,
  17776. y: endY
  17777. }; // 文本结束点
  17778. var labelEnd = {
  17779. x: endX,
  17780. y: endY
  17781. }; // 第四象限
  17782. if (isFirstQuadrant(angle)) {
  17783. var pointY = minY - lineInterval * (labelCount - index);
  17784. points.push({
  17785. x: x,
  17786. y: pointY
  17787. });
  17788. points.push({
  17789. x: labelStart.x,
  17790. y: pointY
  17791. });
  17792. } else if (isThirdQuadrant(angle) || isFourthQuadrant(angle)) {
  17793. points.push({
  17794. x: labelStart.x,
  17795. y: y
  17796. });
  17797. } else if (isSecondQuadrant(angle)) {
  17798. var _pointY = maxY + lineInterval * index;
  17799. points.push({
  17800. x: x,
  17801. y: _pointY
  17802. });
  17803. points.push({
  17804. x: labelStart.x,
  17805. y: _pointY
  17806. });
  17807. }
  17808. points.push(labelStart);
  17809. points.push(labelEnd);
  17810. label.points = points;
  17811. label.side = showSide;
  17812. labels.push(label);
  17813. });
  17814. } else {
  17815. half.forEach(function (label, index) {
  17816. var anchor = label.anchor,
  17817. inflection = label.inflection,
  17818. angle = label.angle,
  17819. x = label.x,
  17820. y = label.y; // 折线的点
  17821. var points = [anchor, inflection];
  17822. var endX = coordRight - sidePadding;
  17823. var endY = coordTop + halfLabelHeight + labelHeight * index; // 文本开始点
  17824. var labelStart = {
  17825. x: endX - labelWidth - lineInterval * index,
  17826. y: endY
  17827. }; // 文本结束点
  17828. var labelEnd = {
  17829. x: endX,
  17830. y: endY
  17831. }; // 第四象限
  17832. if (isFourthQuadrant(angle)) {
  17833. var pointY = minY - lineInterval * (labelCount - index);
  17834. points.push({
  17835. x: x,
  17836. y: pointY
  17837. });
  17838. points.push({
  17839. x: labelStart.x,
  17840. y: pointY
  17841. });
  17842. } else if (isFirstQuadrant(angle) || isSecondQuadrant(angle)) {
  17843. points.push({
  17844. x: labelStart.x,
  17845. y: y
  17846. });
  17847. } else if (isThirdQuadrant(angle)) {
  17848. var _pointY2 = maxY + lineInterval * index;
  17849. points.push({
  17850. x: x,
  17851. y: _pointY2
  17852. });
  17853. points.push({
  17854. x: labelStart.x,
  17855. y: _pointY2
  17856. });
  17857. }
  17858. points.push(labelStart);
  17859. points.push(labelEnd);
  17860. label.points = points;
  17861. label.side = showSide;
  17862. labels.push(label);
  17863. });
  17864. }
  17865. });
  17866. return labels;
  17867. }
  17868. }, {
  17869. key: "_initEvent",
  17870. value: function _initEvent() {
  17871. var context = this.context,
  17872. props = this.props;
  17873. var canvas = context.canvas;
  17874. var _props$triggerOn = props.triggerOn,
  17875. triggerOn = _props$triggerOn === void 0 ? DEFAULT_CONFIG.triggerOn : _props$triggerOn;
  17876. canvas.on(triggerOn, this._handleEvent);
  17877. }
  17878. }, {
  17879. key: "render",
  17880. value: function render() {
  17881. var context = this.context;
  17882. var props = context.px2hd(deepMix({}, DEFAULT_CONFIG, this.props));
  17883. var labels = this.getLabels(props);
  17884. return jsx(View, _objectSpread(_objectSpread({
  17885. labels: labels
  17886. }, props), {}, {
  17887. triggerRef: this.triggerRef
  17888. }));
  17889. }
  17890. }]);
  17891. return PieLabel;
  17892. }(Component);
  17893. });
  17894. var PieLabelView = (function (props) {
  17895. var lineStyle = props.lineStyle,
  17896. anchorStyle = props.anchorStyle,
  17897. labels = props.labels,
  17898. label1OffsetY = props.label1OffsetY,
  17899. label2OffsetY = props.label2OffsetY,
  17900. triggerRef = props.triggerRef;
  17901. return jsx("group", {
  17902. ref: triggerRef
  17903. }, labels.map(function (label) {
  17904. var origin = label.origin,
  17905. anchor = label.anchor,
  17906. side = label.side,
  17907. color = label.color,
  17908. label1 = label.label1,
  17909. label2 = label.label2,
  17910. points = label.points;
  17911. var end = points[points.length - 1];
  17912. return jsx("group", null, jsx("circle", {
  17913. attrs: _objectSpread({
  17914. r: '4px',
  17915. x: anchor.x,
  17916. y: anchor.y,
  17917. fill: color
  17918. }, anchorStyle)
  17919. }), jsx("polyline", {
  17920. attrs: _objectSpread({
  17921. points: points,
  17922. lineWidth: '2px',
  17923. stroke: color
  17924. }, lineStyle)
  17925. }), jsx("text", {
  17926. className: "click",
  17927. attrs: _objectSpread({
  17928. x: end.x,
  17929. y: end.y + label1OffsetY,
  17930. fontSize: '24px',
  17931. lineHeight: '24px',
  17932. fill: color,
  17933. textBaseline: 'bottom',
  17934. textAlign: side === 'left' ? 'left' : 'right'
  17935. }, label1),
  17936. data: origin
  17937. }), jsx("text", {
  17938. className: "click",
  17939. attrs: _objectSpread({
  17940. x: end.x,
  17941. y: end.y + label2OffsetY,
  17942. fontSize: '24px',
  17943. lineHeight: '24px',
  17944. fill: '#808080',
  17945. textBaseline: 'top',
  17946. textAlign: side === 'left' ? 'left' : 'right'
  17947. }, label2),
  17948. data: origin
  17949. }));
  17950. }));
  17951. });
  17952. var index$a = withPieLabel(PieLabelView);
  17953. var getPoint$2 = function getPoint(cener, angle, r) {
  17954. var x = cener.x + Math.cos(angle) * r;
  17955. var y = cener.y + Math.sin(angle) * r;
  17956. return {
  17957. x: x,
  17958. y: y
  17959. };
  17960. };
  17961. var getTicks = function getTicks(start, end, tickCount, center, r, tickOffset, tickLength) {
  17962. var ticks = [];
  17963. var diff = end - start;
  17964. for (var i = 0; i <= tickCount; i++) {
  17965. var tickValue = start + diff * i / tickCount;
  17966. var startPoint = getPoint$2(center, tickValue, r + tickOffset - tickLength);
  17967. var endPoint = getPoint$2(center, tickValue, r + tickOffset);
  17968. ticks.push({
  17969. tickValue: tickValue,
  17970. start: startPoint,
  17971. end: endPoint
  17972. });
  17973. }
  17974. return ticks;
  17975. };
  17976. var withGauge = (function (View) {
  17977. return /*#__PURE__*/function (_Component) {
  17978. _inherits(Guage, _Component);
  17979. var _super = _createSuper(Guage);
  17980. function Guage() {
  17981. _classCallCheck(this, Guage);
  17982. return _super.apply(this, arguments);
  17983. }
  17984. _createClass(Guage, [{
  17985. key: "render",
  17986. value: function render() {
  17987. var props = this.props,
  17988. context = this.context;
  17989. var startAngle = props.startAngle,
  17990. endAngle = props.endAngle,
  17991. tickCount = props.tickCount,
  17992. center = props.center,
  17993. r = props.r,
  17994. tickOffset = props.tickOffset,
  17995. tickLength = props.tickLength;
  17996. var ticks = getTicks(startAngle, endAngle, tickCount, center, context.px2hd(r), context.px2hd(tickOffset), context.px2hd(tickLength));
  17997. return jsx(View, _objectSpread(_objectSpread({}, props), {}, {
  17998. ticks: ticks
  17999. }));
  18000. }
  18001. }]);
  18002. return Guage;
  18003. }(Component);
  18004. });
  18005. var GaugeView = (function (props) {
  18006. var center = props.center,
  18007. startAngle = props.startAngle,
  18008. endAngle = props.endAngle,
  18009. r = props.r,
  18010. percent = props.percent,
  18011. ticks = props.ticks;
  18012. var x = center.x,
  18013. y = center.y;
  18014. var diff = endAngle - startAngle;
  18015. return jsx("group", null, jsx("arc", {
  18016. attrs: {
  18017. x: x,
  18018. y: y,
  18019. r: r,
  18020. startAngle: startAngle,
  18021. endAngle: endAngle,
  18022. lineWidth: '20px',
  18023. lineCap: 'round',
  18024. stroke: '#e7e7e7'
  18025. }
  18026. }), jsx("arc", {
  18027. attrs: {
  18028. x: x,
  18029. y: y,
  18030. r: r,
  18031. startAngle: startAngle,
  18032. endAngle: startAngle,
  18033. lineWidth: '40px',
  18034. lineCap: 'round',
  18035. stroke: '#0075ff'
  18036. },
  18037. animation: {
  18038. appear: {
  18039. easing: 'linear',
  18040. duration: 500,
  18041. property: ['endAngle'],
  18042. start: {
  18043. endAngle: startAngle
  18044. },
  18045. end: {
  18046. endAngle: startAngle + diff * percent
  18047. }
  18048. }
  18049. }
  18050. }), ticks.map(function (tick) {
  18051. var start = tick.start,
  18052. end = tick.end;
  18053. return jsx("line", {
  18054. attrs: {
  18055. x1: start.x,
  18056. y1: start.y,
  18057. x2: end.x,
  18058. y2: end.y,
  18059. lineWidth: '6px',
  18060. lineCap: 'round',
  18061. stroke: '#e7e7e7'
  18062. }
  18063. });
  18064. }));
  18065. });
  18066. var index$b = withGauge(GaugeView);
  18067. function isValuesEqual(values, newValues) {
  18068. if (values.length !== newValues.length) {
  18069. return false;
  18070. }
  18071. var lastIndex = values.length - 1;
  18072. return values[0] === newValues[0] && values[lastIndex] === newValues[lastIndex];
  18073. }
  18074. function updateCategoryRange(scale, originScale, range) {
  18075. var currentValues = scale.values,
  18076. currentTicks = scale.ticks,
  18077. tickMethod = scale.tickMethod,
  18078. tickCount = scale.tickCount;
  18079. var originValues = originScale.values;
  18080. var _range = _slicedToArray(range, 2),
  18081. start = _range[0],
  18082. end = _range[1];
  18083. var len = originValues.length;
  18084. var valueStart = start * len;
  18085. var valueEnd = end * len; // 保持滑动时个数的稳定
  18086. var count = Math.round(valueEnd - valueStart);
  18087. var sliceSatrt = Math.round(valueStart); // 从原始数据里截取需要显示的数据
  18088. var newValues = originValues.slice(sliceSatrt, sliceSatrt + count); // 根据当前数据的比例,和定义的tickCount计算应该需要多少个ticks
  18089. var newTickCount = Math.round(tickCount * originValues.length / newValues.length); // 计算新的ticks
  18090. var catTicks = getTickMethod(tickMethod);
  18091. var newTicks = catTicks({
  18092. tickCount: newTickCount,
  18093. values: originValues
  18094. }); // 如果新数组和当前显示的数组相同,则不更新
  18095. if (isValuesEqual(currentValues, newValues) && isValuesEqual(currentTicks, newTicks)) {
  18096. return;
  18097. }
  18098. scale.change({
  18099. values: newValues,
  18100. ticks: newTicks
  18101. });
  18102. return scale;
  18103. }
  18104. function updateLinearRange(scale, originScale, range) {
  18105. var min = originScale.min,
  18106. max = originScale.max;
  18107. var _range2 = _slicedToArray(range, 2),
  18108. start = _range2[0],
  18109. end = _range2[1];
  18110. var newMin = min + (max - min) * start;
  18111. var newMax = min + (max - min) * end;
  18112. scale.change({
  18113. min: newMin,
  18114. max: newMax,
  18115. nice: false
  18116. });
  18117. }
  18118. function updateScale(scale, values) {
  18119. var isLinear = scale.isLinear;
  18120. if (isLinear) {
  18121. var _getRange = getRange(values),
  18122. min = _getRange.min,
  18123. max = _getRange.max;
  18124. return scale.change({
  18125. min: min,
  18126. max: max,
  18127. nice: true
  18128. });
  18129. }
  18130. }
  18131. function updateRange(scale, originScale, range) {
  18132. var isCategory = scale.isCategory,
  18133. isLinear = scale.isLinear;
  18134. if (isCategory) {
  18135. return updateCategoryRange(scale, originScale, range);
  18136. }
  18137. if (isLinear) {
  18138. return updateLinearRange(scale, originScale, range);
  18139. }
  18140. }
  18141. function updateFollow(scales, mainScale, data) {
  18142. var mainField = mainScale.field,
  18143. mainType = mainScale.type,
  18144. mainValues = mainScale.values; // 转成 map 提高查询性能
  18145. var mainValuesMap = {};
  18146. mainValues.forEach(function (item) {
  18147. mainValuesMap[item] = true;
  18148. });
  18149. return scales.map(function (scale) {
  18150. var followField = scale.field;
  18151. var values = [];
  18152. data.forEach(function (item) {
  18153. var value = mainType === 'timeCat' ? toTimeStamp(item[mainField]) : item[mainField];
  18154. if (mainValuesMap[value]) {
  18155. values.push(item[followField]);
  18156. }
  18157. });
  18158. return updateScale(scale, values);
  18159. });
  18160. }
  18161. function lerp(min, max, fraction) {
  18162. return (max - min) * fraction + min;
  18163. }
  18164. function isEqual$1(aRange, bRange) {
  18165. for (var i in aRange) {
  18166. if (!isNumberEqual(aRange[i], bRange[i])) return false;
  18167. }
  18168. return true;
  18169. }
  18170. function cloneScale$1(scale, scaleConfig) {
  18171. // @ts-ignore
  18172. return new scale.constructor(_objectSpread(_objectSpread({}, scale.__cfg__), scaleConfig));
  18173. } // 缩放
  18174. var Zoom = /*#__PURE__*/function (_Component) {
  18175. _inherits(Zoom, _Component);
  18176. var _super = _createSuper(Zoom);
  18177. function Zoom(props) {
  18178. var _this;
  18179. _classCallCheck(this, Zoom);
  18180. var defaultProps = {
  18181. onPanStart: function onPanStart() {},
  18182. onPinchStart: function onPinchStart() {},
  18183. onPan: function onPan() {},
  18184. onPinch: function onPinch() {},
  18185. onInit: function onInit() {},
  18186. onPanEnd: function onPanEnd() {},
  18187. onPinchEnd: function onPinchEnd() {},
  18188. minCount: 10
  18189. };
  18190. _this = _super.call(this, _objectSpread(_objectSpread({}, defaultProps), props));
  18191. _this.scale = {};
  18192. _this.originScale = {}; //swipe end x y
  18193. _this.swipeEnd = {
  18194. startX: 0,
  18195. startY: 0,
  18196. endX: 0,
  18197. endY: 0
  18198. };
  18199. _this.onStart = function () {
  18200. var _assertThisInitialize = _assertThisInitialized(_this),
  18201. state = _assertThisInitialize.state;
  18202. var range = state.range;
  18203. _this.startRange = range;
  18204. _this.loop && cancelAnimationFrame(_this.loop);
  18205. };
  18206. _this.onPan = function (ev) {
  18207. var _assertThisInitialize2 = _assertThisInitialized(_this),
  18208. dims = _assertThisInitialize2.dims;
  18209. var range = {};
  18210. each(dims, function (dim) {
  18211. if (dim === 'x') {
  18212. range['x'] = _this._doXPan(ev);
  18213. return;
  18214. }
  18215. if (dim === 'y') {
  18216. range['y'] = _this._doYPan(ev);
  18217. return;
  18218. }
  18219. });
  18220. if (isEqual$1(range, _this.state.range)) return;
  18221. _this.setState({
  18222. range: range
  18223. }); // console.log('pan range', range);
  18224. };
  18225. _this.onSwipe = function (ev) {
  18226. var swipe = _this.props.swipe;
  18227. if (_this.props.mode.length < 2 || !swipe) return;
  18228. var _ev$velocityX = ev.velocityX,
  18229. velocityX = _ev$velocityX === void 0 ? 0 : _ev$velocityX,
  18230. _ev$velocityY = ev.velocityY,
  18231. velocityY = _ev$velocityY === void 0 ? 0 : _ev$velocityY,
  18232. points = ev.points;
  18233. var range = _this.state.range;
  18234. var _points$ = points[0],
  18235. x = _points$.x,
  18236. y = _points$.y; // 边界处理
  18237. if (Math.abs((range === null || range === void 0 ? void 0 : range.x[0]) - 0) < 0.0005 && velocityX > 0) return;
  18238. if (Math.abs((range === null || range === void 0 ? void 0 : range.x[1]) - 1) < 0.0005 && velocityX < 0) return;
  18239. if (Math.abs((range === null || range === void 0 ? void 0 : range.y[0]) - 0) < 0.0005 && velocityY < 0) return;
  18240. if (Math.abs((range === null || range === void 0 ? void 0 : range.x[1]) - 1) < 0.0005 && velocityY > 0) return;
  18241. _this.swipeEnd = {
  18242. startX: x,
  18243. startY: y,
  18244. endX: x + velocityX * 50,
  18245. endY: y - velocityY * 50
  18246. };
  18247. _this.onStart();
  18248. _this.update();
  18249. };
  18250. _this.onPinch = function (ev) {
  18251. var _assertThisInitialize3 = _assertThisInitialized(_this),
  18252. dims = _assertThisInitialize3.dims;
  18253. var range = {};
  18254. each(dims, function (dim) {
  18255. if (dim === 'x') {
  18256. range['x'] = _this._doXPinch(ev);
  18257. return;
  18258. }
  18259. if (dim === 'y') {
  18260. range['y'] = _this._doYPinch(ev);
  18261. return;
  18262. }
  18263. });
  18264. if (isEqual$1(range, _this.state.range)) return;
  18265. _this.setState({
  18266. range: range
  18267. });
  18268. };
  18269. _this.onEnd = function () {
  18270. _this.startRange = null;
  18271. };
  18272. var _props$range = props.range,
  18273. mode = props.mode;
  18274. _this.dims = mode instanceof Array ? mode : [mode];
  18275. return _this;
  18276. }
  18277. _createClass(Zoom, [{
  18278. key: "didMount",
  18279. value: function didMount() {
  18280. this._bindEvents();
  18281. }
  18282. }, {
  18283. key: "willReceiveProps",
  18284. value: function willReceiveProps(nextProps) {
  18285. var nextRange = nextProps.range;
  18286. var lastRange = this.props.range;
  18287. if (!equal(nextRange, lastRange)) {
  18288. var cacheRange = {};
  18289. each(this.dims, function (dim) {
  18290. cacheRange[dim] = nextRange;
  18291. });
  18292. this.state = {
  18293. range: cacheRange
  18294. };
  18295. }
  18296. }
  18297. }, {
  18298. key: "willMount",
  18299. value: function willMount() {
  18300. var _this2 = this;
  18301. var props = this.props,
  18302. dims = this.dims,
  18303. state = this.state;
  18304. var minCount = props.minCount,
  18305. range = props.range; // const { range } = state;
  18306. var valueLength = Number.MIN_VALUE;
  18307. var cacheRange = {};
  18308. each(dims, function (dim) {
  18309. var scale = _this2._getScale(dim);
  18310. var values = scale.values;
  18311. valueLength = values.length > valueLength ? values.length : valueLength;
  18312. _this2.scale[dim] = scale;
  18313. _this2.originScale[dim] = cloneScale$1(scale);
  18314. _this2.updateRange(range, dim);
  18315. cacheRange[dim] = range;
  18316. }); // 图表上最少显示 MIN_COUNT 个数据
  18317. this.minScale = minCount / valueLength;
  18318. this.state = {
  18319. range: cacheRange
  18320. };
  18321. }
  18322. }, {
  18323. key: "didUnmount",
  18324. value: function didUnmount() {
  18325. this._clearEvents();
  18326. }
  18327. }, {
  18328. key: "update",
  18329. value: function update() {
  18330. var _this3 = this;
  18331. var _this$swipeEnd = this.swipeEnd,
  18332. startX = _this$swipeEnd.startX,
  18333. startY = _this$swipeEnd.startY,
  18334. endX = _this$swipeEnd.endX,
  18335. endY = _this$swipeEnd.endY;
  18336. var x = lerp(startX, endX, 0.05);
  18337. var y = lerp(startY, endY, 0.05);
  18338. this.swipeEnd = {
  18339. startX: x,
  18340. startY: y,
  18341. endX: endX,
  18342. endY: endY
  18343. };
  18344. var props = this.props;
  18345. var coord = props.coord;
  18346. var coordWidth = coord.width,
  18347. coordHeight = coord.height;
  18348. var range = {};
  18349. range['x'] = this._doPan((x - startX) / coordWidth, 'x');
  18350. range['y'] = this._doPan((y - startY) / coordHeight, 'y');
  18351. this.setState({
  18352. range: range
  18353. });
  18354. this.startRange = range;
  18355. this.loop = requestAnimationFrame(function () {
  18356. return _this3.update();
  18357. });
  18358. if (Math.abs(x - endX) < 0.0005 && Math.abs(y - endY) < 0.0005) {
  18359. this.onEnd();
  18360. cancelAnimationFrame(this.loop);
  18361. }
  18362. }
  18363. }, {
  18364. key: "_doXPan",
  18365. value: function _doXPan(ev) {
  18366. var direction = ev.direction,
  18367. deltaX = ev.deltaX;
  18368. if (this.props.mode.length === 1 && (direction === 'up' || direction === 'down')) {
  18369. return this.state.range['x'];
  18370. }
  18371. ev.preventDefault && ev.preventDefault();
  18372. var props = this.props;
  18373. var coord = props.coord,
  18374. _props$panSensitive = props.panSensitive,
  18375. panSensitive = _props$panSensitive === void 0 ? 1 : _props$panSensitive;
  18376. var coordWidth = coord.width;
  18377. var ratio = deltaX / coordWidth * panSensitive;
  18378. var newRange = this._doPan(ratio, 'x');
  18379. return newRange;
  18380. }
  18381. }, {
  18382. key: "_doYPan",
  18383. value: function _doYPan(ev) {
  18384. var direction = ev.direction,
  18385. deltaY = ev.deltaY;
  18386. if (this.props.mode.length === 1 && (direction === 'left' || direction === 'right')) {
  18387. return this.state.range['y'];
  18388. }
  18389. ev.preventDefault && ev.preventDefault();
  18390. var props = this.props;
  18391. var coord = props.coord,
  18392. _props$panSensitive2 = props.panSensitive,
  18393. panSensitive = _props$panSensitive2 === void 0 ? 1 : _props$panSensitive2;
  18394. var coordHeight = coord.height;
  18395. var ratio = -deltaY / coordHeight * panSensitive;
  18396. var newRange = this._doPan(ratio, 'y');
  18397. return newRange;
  18398. }
  18399. }, {
  18400. key: "_doPan",
  18401. value: function _doPan(ratio, dim) {
  18402. var startRange = this.startRange;
  18403. var _startRange$dim = _slicedToArray(startRange[dim], 2),
  18404. start = _startRange$dim[0],
  18405. end = _startRange$dim[1];
  18406. var rangeLen = end - start;
  18407. var rangeOffset = rangeLen * ratio;
  18408. var newStart = start - rangeOffset;
  18409. var newEnd = end - rangeOffset;
  18410. var newRange = this.updateRange([newStart, newEnd], dim);
  18411. return newRange;
  18412. }
  18413. }, {
  18414. key: "_doXPinch",
  18415. value: function _doXPinch(ev) {
  18416. ev.preventDefault && ev.preventDefault();
  18417. var zoom = ev.zoom,
  18418. center = ev.center;
  18419. var props = this.props;
  18420. var coord = props.coord;
  18421. var coordWidth = coord.width,
  18422. left = coord.left,
  18423. right = coord.right;
  18424. var leftLen = Math.abs(center.x - left);
  18425. var rightLen = Math.abs(right - center.x); // 计算左右缩放的比例
  18426. var leftZoom = leftLen / coordWidth;
  18427. var rightZoom = rightLen / coordWidth;
  18428. var newRange = this._doPinch(leftZoom, rightZoom, zoom, 'x');
  18429. return newRange;
  18430. }
  18431. }, {
  18432. key: "_doYPinch",
  18433. value: function _doYPinch(ev) {
  18434. ev.preventDefault && ev.preventDefault();
  18435. var zoom = ev.zoom,
  18436. center = ev.center;
  18437. var props = this.props;
  18438. var coord = props.coord;
  18439. var coordHeight = coord.height,
  18440. top = coord.top,
  18441. bottom = coord.bottom;
  18442. var topLen = Math.abs(center.y - top);
  18443. var bottomLen = Math.abs(bottom - center.y); // 计算左右缩放的比例
  18444. var topZoom = topLen / coordHeight;
  18445. var bottomZoom = bottomLen / coordHeight;
  18446. var newRange = this._doPinch(topZoom, bottomZoom, zoom, 'y');
  18447. return newRange;
  18448. }
  18449. }, {
  18450. key: "_doPinch",
  18451. value: function _doPinch(startRatio, endRatio, zoom, dim) {
  18452. var startRange = this.startRange,
  18453. minScale = this.minScale,
  18454. props = this.props;
  18455. var _props$pinchSensitive = props.pinchSensitive,
  18456. pinchSensitive = _props$pinchSensitive === void 0 ? 1 : _props$pinchSensitive;
  18457. var _startRange$dim2 = _slicedToArray(startRange[dim], 2),
  18458. start = _startRange$dim2[0],
  18459. end = _startRange$dim2[1];
  18460. var zoomOffset = zoom < 1 ? (1 / zoom - 1) * pinchSensitive : (1 - zoom) * pinchSensitive;
  18461. var rangeLen = end - start;
  18462. var rangeOffset = rangeLen * zoomOffset;
  18463. var startOffset = rangeOffset * startRatio;
  18464. var endOffset = rangeOffset * endRatio;
  18465. var newStart = Math.max(0, start - startOffset);
  18466. var newEnd = Math.min(1, end + endOffset);
  18467. var newRange = [newStart, newEnd]; // 如果已经到了最小比例,则不能再继续再放大
  18468. if (newEnd - newStart < minScale) {
  18469. return this.state.range[dim];
  18470. }
  18471. return this.updateRange(newRange, dim);
  18472. }
  18473. }, {
  18474. key: "updateRange",
  18475. value: function updateRange$1(originalRange, dim) {
  18476. if (!originalRange) return;
  18477. var _originalRange = _slicedToArray(originalRange, 2),
  18478. start = _originalRange[0],
  18479. end = _originalRange[1];
  18480. var rangeLength = end - start; // 处理边界值
  18481. var newRange;
  18482. if (start < 0) {
  18483. newRange = [0, rangeLength];
  18484. } else if (end > 1) {
  18485. newRange = [1 - rangeLength, 1];
  18486. } else {
  18487. newRange = originalRange;
  18488. }
  18489. var props = this.props,
  18490. scale = this.scale,
  18491. originScale = this.originScale,
  18492. state = this.state;
  18493. var chart = props.chart,
  18494. data = props.data,
  18495. autoFit = props.autoFit;
  18496. var range = state.range;
  18497. if (range && isEqual$1(newRange, range[dim])) return newRange; // 更新主 scale
  18498. updateRange(scale[dim], originScale[dim], newRange);
  18499. if (autoFit) {
  18500. var followScale = this._getFollowScales(dim);
  18501. this.updateFollow(followScale, scale[dim], data);
  18502. } // 手势变化不执行动画
  18503. var animate = chart.animate;
  18504. chart.setAnimate(false);
  18505. chart.forceUpdate(function () {
  18506. chart.setAnimate(animate);
  18507. });
  18508. return newRange;
  18509. }
  18510. }, {
  18511. key: "updateFollow",
  18512. value: function updateFollow$1(scales, mainScale, data) {
  18513. updateFollow(scales, mainScale, data);
  18514. }
  18515. }, {
  18516. key: "_getScale",
  18517. value: function _getScale(dim) {
  18518. var _this$props = this.props,
  18519. coord = _this$props.coord,
  18520. chart = _this$props.chart;
  18521. if (dim === 'x') {
  18522. return coord.transposed ? chart.getYScales()[0] : chart.getXScales()[0];
  18523. } else {
  18524. return coord.transposed ? chart.getXScales()[0] : chart.getYScales()[0];
  18525. }
  18526. }
  18527. }, {
  18528. key: "_getFollowScales",
  18529. value: function _getFollowScales(dim) {
  18530. var _this$props2 = this.props,
  18531. coord = _this$props2.coord,
  18532. chart = _this$props2.chart;
  18533. if (dim === 'x') {
  18534. return coord.transposed ? chart.getXScales() : chart.getYScales();
  18535. }
  18536. if (dim === 'y') {
  18537. return coord.transposed ? chart.getYScales() : chart.getXScales();
  18538. }
  18539. }
  18540. }, {
  18541. key: "_bindEvents",
  18542. value: function _bindEvents() {
  18543. var _this4 = this;
  18544. var context = this.context,
  18545. props = this.props,
  18546. scale = this.scale;
  18547. var canvas = context.canvas;
  18548. var onPinchStart = props.onPinchStart,
  18549. onPanStart = props.onPanStart,
  18550. onPanEnd = props.onPanEnd,
  18551. pan = props.pan,
  18552. pinch = props.pinch,
  18553. swipe = props.swipe,
  18554. onInit = props.onInit,
  18555. onPan = props.onPan,
  18556. onPinch = props.onPinch; // 统一绑定事件
  18557. if (pan !== false) {
  18558. canvas.on('panstart', function () {
  18559. _this4.onStart();
  18560. onPanStart({
  18561. scale: scale
  18562. });
  18563. });
  18564. canvas.on('pan', function (ev) {
  18565. _this4.onPan(ev);
  18566. onPan(ev);
  18567. });
  18568. canvas.on('panend', function () {
  18569. _this4.onEnd();
  18570. onPanEnd({
  18571. scale: scale
  18572. });
  18573. });
  18574. }
  18575. if (pinch !== false) {
  18576. canvas.on('pinchstart', function () {
  18577. _this4.onStart();
  18578. onPinchStart();
  18579. });
  18580. canvas.on('pinch', function (ev) {
  18581. _this4.onPinch(ev);
  18582. onPinch(ev);
  18583. });
  18584. canvas.on('pinchend', function () {
  18585. _this4.onEnd();
  18586. onPanEnd({
  18587. scale: scale
  18588. });
  18589. });
  18590. }
  18591. if (swipe !== false) {
  18592. canvas.on('swipe', this.onSwipe);
  18593. }
  18594. onInit({
  18595. scale: scale
  18596. });
  18597. }
  18598. }, {
  18599. key: "_clearEvents",
  18600. value: function _clearEvents() {
  18601. var _this5 = this;
  18602. var context = this.context,
  18603. props = this.props,
  18604. scale = this.scale;
  18605. var canvas = context.canvas;
  18606. var onPinchEnd = props.onPinchEnd,
  18607. onPanEnd = props.onPanEnd,
  18608. onPinchStart = props.onPinchStart,
  18609. pan = props.pan,
  18610. pinch = props.pinch,
  18611. onPan = props.onPan,
  18612. onPinch = props.onPinch,
  18613. swipe = props.swipe; // 统一解绑事件
  18614. if (pan !== false) {
  18615. canvas.off('panstart', function () {
  18616. _this5.onStart();
  18617. onPinchStart();
  18618. });
  18619. canvas.off('pan', function (ev) {
  18620. _this5.onPan(ev);
  18621. onPan(ev);
  18622. });
  18623. canvas.off('panend', function () {
  18624. _this5.onEnd();
  18625. onPanEnd({
  18626. scale: scale
  18627. });
  18628. });
  18629. }
  18630. if (pinch !== false) {
  18631. canvas.off('pinchstart', function () {
  18632. _this5.onStart();
  18633. onPinchStart();
  18634. });
  18635. canvas.off('pinch', function (ev) {
  18636. _this5.onPinch(ev);
  18637. onPinch(ev);
  18638. });
  18639. canvas.off('pinchend', function () {
  18640. _this5.onEnd();
  18641. onPinchEnd({
  18642. scale: scale
  18643. });
  18644. });
  18645. }
  18646. if (swipe !== false) {
  18647. canvas.off('swipe', this.onSwipe);
  18648. }
  18649. }
  18650. }]);
  18651. return Zoom;
  18652. }(Component);
  18653. var withScrollBar = (function (View) {
  18654. return /*#__PURE__*/function (_Zoom) {
  18655. _inherits(ScrollBar, _Zoom);
  18656. var _super = _createSuper(ScrollBar);
  18657. function ScrollBar() {
  18658. _classCallCheck(this, ScrollBar);
  18659. return _super.apply(this, arguments);
  18660. }
  18661. _createClass(ScrollBar, [{
  18662. key: "willMount",
  18663. value: function willMount() {
  18664. _get$1(_getPrototypeOf(ScrollBar.prototype), "willMount", this).call(this);
  18665. var context = this.context,
  18666. props = this.props;
  18667. var visible = props.visible,
  18668. _props$position = props.position,
  18669. position = _props$position === void 0 ? 'bottom' : _props$position,
  18670. _props$margin = props.margin,
  18671. margin = _props$margin === void 0 ? '16px' : _props$margin,
  18672. chart = props.chart;
  18673. var marginNumber = context.px2hd(margin);
  18674. if (visible === false) {
  18675. return null;
  18676. }
  18677. chart.updateCoordFor(this, {
  18678. position: position,
  18679. width: position === 'left' || position === 'right' ? marginNumber : 0,
  18680. height: position === 'bottom' || position === 'top' ? marginNumber : 0
  18681. });
  18682. }
  18683. }, {
  18684. key: "render",
  18685. value: function render() {
  18686. var props = this.props,
  18687. state = this.state;
  18688. var visible = props.visible;
  18689. if (visible === false) {
  18690. return null;
  18691. }
  18692. return jsx(View, _objectSpread(_objectSpread({
  18693. position: "bottom"
  18694. }, props), state));
  18695. }
  18696. }]);
  18697. return ScrollBar;
  18698. }(Zoom);
  18699. });
  18700. var Horizontal = (function (props, context) {
  18701. var coord = props.coord,
  18702. range = props.range,
  18703. position = props.position,
  18704. layout = props.layout;
  18705. var left = coord.left,
  18706. width = coord.width;
  18707. var top = layout.top,
  18708. height = layout.height;
  18709. var _ref = (range === null || range === void 0 ? void 0 : range.x) || (range === null || range === void 0 ? void 0 : range.y),
  18710. _ref2 = _slicedToArray(_ref, 2),
  18711. start = _ref2[0],
  18712. end = _ref2[1];
  18713. var barLeft = width * start;
  18714. var barWidth = width * (end - start);
  18715. return jsx("group", {
  18716. style: {
  18717. left: left,
  18718. top: position === 'top' ? top - context.px2hd('8px') : top + height
  18719. }
  18720. }, jsx("line", {
  18721. style: {
  18722. position: 'absolute',
  18723. left: 0,
  18724. width: width,
  18725. height: 0
  18726. },
  18727. attrs: {
  18728. stroke: 'rgba(202, 215, 239, .2)',
  18729. lineCap: 'round',
  18730. lineWidth: '8px'
  18731. }
  18732. }), jsx("line", {
  18733. style: {
  18734. position: 'absolute',
  18735. left: barLeft,
  18736. width: barWidth,
  18737. height: 0
  18738. },
  18739. attrs: {
  18740. stroke: 'rgba(202, 215, 239, .5)',
  18741. lineCap: 'round',
  18742. lineWidth: '8px'
  18743. }
  18744. }));
  18745. });
  18746. var Vertical = (function (props, context) {
  18747. var coord = props.coord,
  18748. range = props.range,
  18749. position = props.position,
  18750. layout = props.layout;
  18751. var top = coord.top,
  18752. height = coord.height;
  18753. var left = layout.left,
  18754. width = layout.width;
  18755. var _ref = (range === null || range === void 0 ? void 0 : range.y) || (range === null || range === void 0 ? void 0 : range.x),
  18756. _ref2 = _slicedToArray(_ref, 2),
  18757. start = _ref2[0],
  18758. end = _ref2[1];
  18759. var barTop = height * start;
  18760. var barHeight = height * (end - start);
  18761. return jsx("group", {
  18762. style: {
  18763. top: top,
  18764. left: position === 'left' ? left - context.px2hd('8px') : left + width
  18765. }
  18766. }, jsx("line", {
  18767. style: {
  18768. position: 'absolute',
  18769. top: 0,
  18770. left: 0,
  18771. width: 0,
  18772. height: height
  18773. },
  18774. attrs: {
  18775. stroke: 'rgba(202, 215, 239, .2)',
  18776. lineCap: 'round',
  18777. lineWidth: '8px'
  18778. }
  18779. }), jsx("line", {
  18780. style: {
  18781. position: 'absolute',
  18782. top: barTop,
  18783. width: 0,
  18784. height: barHeight
  18785. },
  18786. attrs: {
  18787. stroke: 'rgba(202, 215, 239, .5)',
  18788. lineCap: 'round',
  18789. lineWidth: '8px'
  18790. }
  18791. }));
  18792. });
  18793. var ScrollBarView = (function (props) {
  18794. var position = props.position,
  18795. mode = props.mode;
  18796. if (mode.length > 1) {
  18797. return jsx("group", null, jsx(Vertical, _objectSpread({}, props)), jsx(Horizontal, _objectSpread({}, props)));
  18798. }
  18799. if (position === 'left' || position === 'right') {
  18800. return jsx(Vertical, _objectSpread({}, props));
  18801. }
  18802. return jsx(Horizontal, _objectSpread({}, props));
  18803. });
  18804. var index$c = withScrollBar(ScrollBarView);
  18805. exports.ArcGuide = ArcGuide;
  18806. exports.Area = index$1;
  18807. exports.AreaView = AreaView;
  18808. exports.Axis = index$4;
  18809. exports.AxisView = AxisView;
  18810. exports.Canvas = Canvas$1;
  18811. exports.Chart = Chart;
  18812. exports.Children = Children;
  18813. exports.Component = Component;
  18814. exports.Fragment = fragment;
  18815. exports.Gauge = index$b;
  18816. exports.GaugeView = GaugeView;
  18817. exports.Geometry = Geometry;
  18818. exports.Guide = index$6;
  18819. exports.ImageGuide = ImageGuide;
  18820. exports.Interval = index$2;
  18821. exports.IntervalView = intervalView;
  18822. exports.Legend = index$5;
  18823. exports.LegendView = LegendView;
  18824. exports.Line = index;
  18825. exports.LineGuide = LineGuide;
  18826. exports.LineView = LineView;
  18827. exports.PieLabel = index$a;
  18828. exports.PieLabelView = PieLabelView;
  18829. exports.Point = index$3;
  18830. exports.PointGuide = PointGuide;
  18831. exports.PointView = PointView;
  18832. exports.RectGuide = RectGuide;
  18833. exports.ScrollBar = index$c;
  18834. exports.ScrollBarView = ScrollBarView;
  18835. exports.Sunburst = index$9;
  18836. exports.SunburstView = SunburstView;
  18837. exports.TagGuide = TagGuide;
  18838. exports.TextGuide = TextGuide;
  18839. exports.Timeline = Timeline;
  18840. exports.Tooltip = index$7;
  18841. exports.TooltipView = TooltipView;
  18842. exports.Treemap = index$8;
  18843. exports.TreemapView = TreemapView;
  18844. exports.Zoom = Zoom;
  18845. exports.createElement = jsx;
  18846. exports.createRef = createRef;
  18847. exports.jsx = jsx;
  18848. exports.render = render$1;
  18849. exports.renderShape = renderShape;
  18850. exports.withArea = withArea;
  18851. exports.withAxis = withAxis;
  18852. exports.withGauge = withGauge;
  18853. exports.withGuide = withGuide;
  18854. exports.withInterval = withInterval;
  18855. exports.withLegend = withLegend;
  18856. exports.withLine = withLine;
  18857. exports.withPieLabel = withPieLabel;
  18858. exports.withPoint = withPoint;
  18859. exports.withScrollBar = withScrollBar;
  18860. exports.withSunburst = withSunburst;
  18861. exports.withTooltip = withTooltip;
  18862. exports.withTreemap = withTreemap;
  18863. Object.defineProperty(exports, '__esModule', { value: true });
  18864. })));