f2.js 479 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219
  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. var isArrayLike = function (value) {
  7. /**
  8. * isArrayLike([1, 2, 3]) => true
  9. * isArrayLike(document.body.children) => true
  10. * isArrayLike('abc') => true
  11. * isArrayLike(Function) => false
  12. */
  13. return value !== null && typeof value !== 'function' && isFinite(value.length);
  14. };
  15. var filter = function (arr, func) {
  16. if (!isArrayLike(arr)) {
  17. return arr;
  18. }
  19. var result = [];
  20. for (var index = 0; index < arr.length; index++) {
  21. var value = arr[index];
  22. if (func(value, index)) {
  23. result.push(value);
  24. }
  25. }
  26. return result;
  27. };
  28. var toString$3 = {}.toString;
  29. var isType$1 = function (value, type) {
  30. return toString$3.call(value) === '[object ' + type + ']';
  31. };
  32. /**
  33. * 是否为函数
  34. * @param {*} fn 对象
  35. * @return {Boolean} 是否函数
  36. */
  37. var isFunction$1 = (function (value) {
  38. return isType$1(value, 'Function');
  39. });
  40. // isFinite,
  41. var isNil$1 = function (value) {
  42. /**
  43. * isNil(null) => true
  44. * isNil() => true
  45. */
  46. return value === null || value === undefined;
  47. };
  48. var isArray$1 = (function (value) {
  49. return Array.isArray ? Array.isArray(value) : isType$1(value, 'Array');
  50. });
  51. var isObject$1 = (function (value) {
  52. /**
  53. * isObject({}) => true
  54. * isObject([1, 2, 3]) => true
  55. * isObject(Function) => true
  56. * isObject(null) => false
  57. */
  58. var type = typeof value;
  59. return value !== null && type === 'object' || type === 'function';
  60. });
  61. function each$1(elements, func) {
  62. if (!elements) {
  63. return;
  64. }
  65. var rst;
  66. if (isArray$1(elements)) {
  67. for (var i = 0, len = elements.length; i < len; i++) {
  68. rst = func(elements[i], i);
  69. if (rst === false) {
  70. break;
  71. }
  72. }
  73. } else if (isObject$1(elements)) {
  74. for (var k in elements) {
  75. if (elements.hasOwnProperty(k)) {
  76. rst = func(elements[k], k);
  77. if (rst === false) {
  78. break;
  79. }
  80. }
  81. }
  82. }
  83. }
  84. var keys = Object.keys ? function (obj) {
  85. return Object.keys(obj);
  86. } : function (obj) {
  87. var result = [];
  88. each$1(obj, function (value, key) {
  89. if (!(isFunction$1(obj) && key === 'prototype')) {
  90. result.push(key);
  91. }
  92. });
  93. return result;
  94. };
  95. function isMatch(obj, attrs) {
  96. var _keys = keys(attrs);
  97. var length = _keys.length;
  98. if (isNil$1(obj)) return !length;
  99. for (var i = 0; i < length; i += 1) {
  100. var key = _keys[i];
  101. if (attrs[key] !== obj[key] || !(key in obj)) {
  102. return false;
  103. }
  104. }
  105. return true;
  106. }
  107. var isObjectLike = function (value) {
  108. /**
  109. * isObjectLike({}) => true
  110. * isObjectLike([1, 2, 3]) => true
  111. * isObjectLike(Function) => false
  112. * isObjectLike(null) => false
  113. */
  114. return typeof value === 'object' && value !== null;
  115. };
  116. var isPlainObject = function (value) {
  117. /**
  118. * isObjectLike(new Foo) => false
  119. * isObjectLike([1, 2, 3]) => false
  120. * isObjectLike({ x: 0, y: 0 }) => true
  121. * isObjectLike(Object.create(null)) => true
  122. */
  123. if (!isObjectLike(value) || !isType$1(value, 'Object')) {
  124. return false;
  125. }
  126. if (Object.getPrototypeOf(value) === null) {
  127. return true;
  128. }
  129. var proto = value;
  130. while (Object.getPrototypeOf(proto) !== null) {
  131. proto = Object.getPrototypeOf(proto);
  132. }
  133. return Object.getPrototypeOf(value) === proto;
  134. };
  135. function find(arr, predicate) {
  136. if (!isArray$1(arr)) return null;
  137. var _predicate;
  138. if (isFunction$1(predicate)) {
  139. _predicate = predicate;
  140. }
  141. if (isPlainObject(predicate)) {
  142. _predicate = function (a) {
  143. return isMatch(a, predicate);
  144. };
  145. }
  146. if (_predicate) {
  147. for (var i = 0; i < arr.length; i += 1) {
  148. if (_predicate(arr[i])) {
  149. return arr[i];
  150. }
  151. }
  152. }
  153. return null;
  154. }
  155. /**
  156. * @param {Array} arr The array to iterate over.
  157. * @return {*} Returns the maximum value.
  158. * @example
  159. *
  160. * max([1, 2]);
  161. * // => 2
  162. *
  163. * max([]);
  164. * // => undefined
  165. *
  166. * const data = new Array(1250010).fill(1).map((d,idx) => idx);
  167. *
  168. * max(data);
  169. * // => 1250010
  170. * // Math.max(...data) will encounter "Maximum call stack size exceeded" error
  171. */
  172. var getMax = (function (arr) {
  173. if (!isArray$1(arr)) {
  174. return undefined;
  175. }
  176. return arr.reduce(function (prev, curr) {
  177. return Math.max(prev, curr);
  178. }, arr[0]);
  179. });
  180. /**
  181. * @param {Array} arr The array to iterate over.
  182. * @return {*} Returns the minimum value.
  183. * @example
  184. *
  185. * min([1, 2]);
  186. * // => 1
  187. *
  188. * min([]);
  189. * // => undefined
  190. *
  191. * const data = new Array(1250010).fill(1).map((d,idx) => idx);
  192. *
  193. * min(data);
  194. * // => 1250010
  195. * // Math.min(...data) will encounter "Maximum call stack size exceeded" error
  196. */
  197. var getMin = (function (arr) {
  198. if (!isArray$1(arr)) {
  199. return undefined;
  200. }
  201. return arr.reduce(function (prev, curr) {
  202. return Math.min(prev, curr);
  203. }, arr[0]);
  204. });
  205. var getRange$1 = function (values) {
  206. // 存在 NaN 时,min,max 判定会出问题
  207. var filterValues = values.filter(function (v) {
  208. return !isNaN(v);
  209. });
  210. if (!filterValues.length) {
  211. // 如果没有数值则直接返回0
  212. return {
  213. min: 0,
  214. max: 0
  215. };
  216. }
  217. if (isArray$1(values[0])) {
  218. var tmp = [];
  219. for (var i = 0; i < values.length; i++) {
  220. tmp = tmp.concat(values[i]);
  221. }
  222. filterValues = tmp;
  223. }
  224. var max = getMax(filterValues);
  225. var min = getMin(filterValues);
  226. return {
  227. min: min,
  228. max: max
  229. };
  230. };
  231. var isString = (function (str) {
  232. return isType$1(str, 'String');
  233. });
  234. function uniq(arr, cache) {
  235. if (cache === void 0) {
  236. cache = new Map();
  237. }
  238. var r = [];
  239. if (Array.isArray(arr)) {
  240. for (var i = 0, len = arr.length; i < len; i++) {
  241. var item = arr[i]; // 加一个 cache,提升性能
  242. if (!cache.has(item)) {
  243. r.push(item);
  244. cache.set(item, true);
  245. }
  246. }
  247. }
  248. return r;
  249. }
  250. function head(o) {
  251. if (isArrayLike(o)) {
  252. return o[0];
  253. }
  254. return undefined;
  255. }
  256. function last(o) {
  257. if (isArrayLike(o)) {
  258. var arr = o;
  259. return arr[arr.length - 1];
  260. }
  261. return undefined;
  262. }
  263. var fixedBase = function (v, base) {
  264. var str = base.toString();
  265. var index = str.indexOf('.');
  266. if (index === -1) {
  267. return Math.round(v);
  268. }
  269. var length = str.substr(index + 1).length;
  270. if (length > 20) {
  271. length = 20;
  272. }
  273. return parseFloat(v.toFixed(length));
  274. };
  275. /**
  276. * 判断是否数字
  277. * @return {Boolean} 是否数字
  278. */
  279. var isNumber = function (value) {
  280. return isType$1(value, 'Number');
  281. };
  282. var values$1 = Object.values ? function (obj) {
  283. return Object.values(obj);
  284. } : function (obj) {
  285. var result = [];
  286. each$1(obj, function (value, key) {
  287. if (!(isFunction$1(obj) && key === 'prototype')) {
  288. result.push(value);
  289. }
  290. });
  291. return result;
  292. };
  293. var toString$2 = (function (value) {
  294. if (isNil$1(value)) return '';
  295. return value.toString();
  296. });
  297. var lowerFirst = function (value) {
  298. var str = toString$2(value);
  299. return str.charAt(0).toLowerCase() + str.substring(1);
  300. };
  301. function substitute(str, o) {
  302. if (!str || !o) {
  303. return str;
  304. }
  305. return str.replace(/\\?\{([^{}]+)\}/g, function (match, name) {
  306. if (match.charAt(0) === '\\') {
  307. return match.slice(1);
  308. }
  309. return o[name] === undefined ? '' : o[name];
  310. });
  311. }
  312. var upperFirst = function (value) {
  313. var str = toString$2(value);
  314. return str.charAt(0).toUpperCase() + str.substring(1);
  315. };
  316. var toString$1 = {}.toString;
  317. var getType = function (value) {
  318. return toString$1.call(value).replace(/^\[object /, '').replace(/]$/, '');
  319. };
  320. /**
  321. * 是否是布尔类型
  322. *
  323. * @param {Object} value 测试的值
  324. * @return {Boolean}
  325. */
  326. var isBoolean = function (value) {
  327. return isType$1(value, 'Boolean');
  328. };
  329. var isDate = function (value) {
  330. return isType$1(value, 'Date');
  331. };
  332. var objectProto = Object.prototype;
  333. var isPrototype = function (value) {
  334. var Ctor = value && value.constructor;
  335. var proto = typeof Ctor === 'function' && Ctor.prototype || objectProto;
  336. return value === proto;
  337. };
  338. // FIXME: Mutable param should be forbidden in static lang.
  339. function _mix$1(dist, obj) {
  340. for (var key in obj) {
  341. if (obj.hasOwnProperty(key) && key !== 'constructor' && obj[key] !== undefined) {
  342. dist[key] = obj[key];
  343. }
  344. }
  345. }
  346. function mix$1(dist, src1, src2, src3) {
  347. if (src1) _mix$1(dist, src1);
  348. if (src2) _mix$1(dist, src2);
  349. if (src3) _mix$1(dist, src3);
  350. return dist;
  351. }
  352. /**
  353. * _.memoize(calColor);
  354. * _.memoize(calColor, (...args) => args[0]);
  355. * @param f
  356. * @param resolver
  357. */
  358. var memoize = (function (f, resolver) {
  359. if (!isFunction$1(f)) {
  360. throw new TypeError('Expected a function');
  361. }
  362. var memoized = function () {
  363. var args = [];
  364. for (var _i = 0; _i < arguments.length; _i++) {
  365. args[_i] = arguments[_i];
  366. } // 使用方法构造 key,如果不存在 resolver,则直接取第一个参数作为 key
  367. var key = resolver ? resolver.apply(this, args) : args[0];
  368. var cache = memoized.cache;
  369. if (cache.has(key)) {
  370. return cache.get(key);
  371. }
  372. var result = f.apply(this, args); // 缓存起来
  373. cache.set(key, result);
  374. return result;
  375. };
  376. memoized.cache = new Map();
  377. return memoized;
  378. });
  379. var MAX_MIX_LEVEL = 5;
  380. function _deepMix(dist, src, level, maxLevel) {
  381. level = level || 0;
  382. maxLevel = maxLevel || MAX_MIX_LEVEL;
  383. for (var key in src) {
  384. if (src.hasOwnProperty(key)) {
  385. var value = src[key];
  386. if (value !== null && isPlainObject(value)) {
  387. if (!isPlainObject(dist[key])) {
  388. dist[key] = {};
  389. }
  390. if (level < maxLevel) {
  391. _deepMix(dist[key], value, level + 1, maxLevel);
  392. } else {
  393. dist[key] = src[key];
  394. }
  395. } else if (isArray$1(value)) {
  396. dist[key] = [];
  397. dist[key] = dist[key].concat(value);
  398. } else if (value !== undefined) {
  399. dist[key] = value;
  400. }
  401. }
  402. }
  403. } // todo 重写
  404. var deepMix = function (rst) {
  405. var args = [];
  406. for (var _i = 1; _i < arguments.length; _i++) {
  407. args[_i - 1] = arguments[_i];
  408. }
  409. for (var i = 0; i < args.length; i += 1) {
  410. _deepMix(rst, args[i]);
  411. }
  412. return rst;
  413. };
  414. var indexOf = function (arr, obj) {
  415. if (!isArrayLike(arr)) {
  416. return -1;
  417. }
  418. var m = Array.prototype.indexOf;
  419. if (m) {
  420. return m.call(arr, obj);
  421. }
  422. var index = -1;
  423. for (var i = 0; i < arr.length; i++) {
  424. if (arr[i] === obj) {
  425. index = i;
  426. break;
  427. }
  428. }
  429. return index;
  430. };
  431. var hasOwnProperty = Object.prototype.hasOwnProperty;
  432. function isEmpty(value) {
  433. /**
  434. * isEmpty(null) => true
  435. * isEmpty() => true
  436. * isEmpty(true) => true
  437. * isEmpty(1) => true
  438. * isEmpty([1, 2, 3]) => false
  439. * isEmpty('abc') => false
  440. * isEmpty({ a: 1 }) => false
  441. */
  442. if (isNil$1(value)) {
  443. return true;
  444. }
  445. if (isArrayLike(value)) {
  446. return !value.length;
  447. }
  448. var type = getType(value);
  449. if (type === 'Map' || type === 'Set') {
  450. return !value.size;
  451. }
  452. if (isPrototype(value)) {
  453. return !Object.keys(value).length;
  454. }
  455. for (var key in value) {
  456. if (hasOwnProperty.call(value, key)) {
  457. return false;
  458. }
  459. }
  460. return true;
  461. }
  462. var isEqual$1 = function (value, other) {
  463. if (value === other) {
  464. return true;
  465. }
  466. if (!value || !other) {
  467. return false;
  468. }
  469. if (isString(value) || isString(other)) {
  470. return false;
  471. }
  472. if (isArrayLike(value) || isArrayLike(other)) {
  473. if (value.length !== other.length) {
  474. return false;
  475. }
  476. var rst = true;
  477. for (var i = 0; i < value.length; i++) {
  478. rst = isEqual$1(value[i], other[i]);
  479. if (!rst) {
  480. break;
  481. }
  482. }
  483. return rst;
  484. }
  485. if (isObjectLike(value) || isObjectLike(other)) {
  486. var valueKeys = Object.keys(value);
  487. var otherKeys = Object.keys(other);
  488. if (valueKeys.length !== otherKeys.length) {
  489. return false;
  490. }
  491. var rst = true;
  492. for (var i = 0; i < valueKeys.length; i++) {
  493. rst = isEqual$1(value[valueKeys[i]], other[valueKeys[i]]);
  494. if (!rst) {
  495. break;
  496. }
  497. }
  498. return rst;
  499. }
  500. return false;
  501. };
  502. var map$1 = function (arr, func) {
  503. if (!isArrayLike(arr)) {
  504. // @ts-ignore
  505. return arr;
  506. }
  507. var result = [];
  508. for (var index = 0; index < arr.length; index++) {
  509. var value = arr[index];
  510. result.push(func(value, index));
  511. }
  512. return result;
  513. };
  514. function size(o) {
  515. if (isNil$1(o)) {
  516. return 0;
  517. }
  518. if (isArrayLike(o)) {
  519. return o.length;
  520. }
  521. return Object.keys(o).length;
  522. }
  523. /*! *****************************************************************************
  524. Copyright (c) Microsoft Corporation.
  525. Permission to use, copy, modify, and/or distribute this software for any
  526. purpose with or without fee is hereby granted.
  527. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
  528. REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  529. AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
  530. INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  531. LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  532. OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  533. PERFORMANCE OF THIS SOFTWARE.
  534. ***************************************************************************** */
  535. /* global Reflect, Promise */
  536. var extendStatics = function (d, b) {
  537. extendStatics = Object.setPrototypeOf || {
  538. __proto__: []
  539. } instanceof Array && function (d, b) {
  540. d.__proto__ = b;
  541. } || function (d, b) {
  542. for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
  543. };
  544. return extendStatics(d, b);
  545. };
  546. function __extends(d, b) {
  547. if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
  548. extendStatics(d, b);
  549. function __() {
  550. this.constructor = d;
  551. }
  552. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  553. }
  554. /** @deprecated */
  555. function __spreadArrays() {
  556. for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
  557. for (var r = Array(s), k = 0, i = 0; i < il; i++) for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) r[k] = a[j];
  558. return r;
  559. }
  560. var ctx;
  561. /**
  562. * 计算文本的宽度
  563. */
  564. memoize(function (text, font) {
  565. if (font === void 0) {
  566. font = {};
  567. }
  568. var fontSize = font.fontSize,
  569. fontFamily = font.fontFamily,
  570. fontWeight = font.fontWeight,
  571. fontStyle = font.fontStyle,
  572. fontVariant = font.fontVariant;
  573. if (!ctx) {
  574. ctx = document.createElement('canvas').getContext('2d');
  575. }
  576. ctx.font = [fontStyle, fontVariant, fontWeight, fontSize + "px", fontFamily].join(' ');
  577. return ctx.measureText(isString(text) ? text : '').width;
  578. }, function (text, font) {
  579. if (font === void 0) {
  580. font = {};
  581. }
  582. return __spreadArrays([text], values$1(font)).join('');
  583. });
  584. function merge$1(dataArray) {
  585. var rst = [];
  586. for (var i = 0, len = dataArray.length; i < len; i++) {
  587. rst = rst.concat(dataArray[i]);
  588. }
  589. return rst;
  590. }
  591. function values(data, name) {
  592. var rst = [];
  593. var tmpMap = {};
  594. for (var i = 0, len = data.length; i < len; i++) {
  595. var obj = data[i];
  596. var value = obj[name];
  597. if (!isNil$1(value)) {
  598. if (!isArray$1(value)) {
  599. if (!tmpMap[value]) {
  600. rst.push(value);
  601. tmpMap[value] = true;
  602. }
  603. } else {
  604. each$1(value, function (val) {
  605. if (!tmpMap[val]) {
  606. rst.push(val);
  607. tmpMap[val] = true;
  608. }
  609. });
  610. }
  611. }
  612. }
  613. return rst;
  614. }
  615. function firstValue(data, name) {
  616. var rst = null;
  617. for (var i = 0, len = data.length; i < len; i++) {
  618. var obj = data[i];
  619. var value = obj[name];
  620. if (!isNil$1(value)) {
  621. if (isArray$1(value)) {
  622. rst = value[0];
  623. } else {
  624. rst = value;
  625. }
  626. break;
  627. }
  628. }
  629. return rst;
  630. }
  631. function groupToMap(data, fields) {
  632. if (!fields) {
  633. return {
  634. 0: data
  635. };
  636. }
  637. var callback = function callback(row) {
  638. var unique = '_';
  639. for (var i = 0, l = fields.length; i < l; i++) {
  640. unique += row[fields[i]] && row[fields[i]].toString();
  641. }
  642. return unique;
  643. };
  644. var groups = {};
  645. for (var i = 0, len = data.length; i < len; i++) {
  646. var row = data[i];
  647. var key = callback(row);
  648. if (groups[key]) {
  649. groups[key].push(row);
  650. } else {
  651. groups[key] = [row];
  652. }
  653. }
  654. return groups;
  655. }
  656. function group(data, fields, appendConditions) {
  657. if (appendConditions === void 0) {
  658. appendConditions = {};
  659. }
  660. if (!fields) {
  661. return [data];
  662. }
  663. var groups = groupToMap(data, fields);
  664. var array = [];
  665. if (fields.length === 1 && appendConditions[fields[0]]) {
  666. var _values = appendConditions[fields[0]];
  667. each$1(_values, function (value) {
  668. value = '_' + value;
  669. array.push(groups[value]);
  670. });
  671. } else {
  672. for (var i in groups) {
  673. array.push(groups[i]);
  674. }
  675. }
  676. return array;
  677. }
  678. function remove(arr, obj) {
  679. if (!arr) {
  680. return;
  681. }
  682. var index = arr.indexOf(obj);
  683. if (index !== -1) {
  684. arr.splice(index, 1);
  685. }
  686. }
  687. function getRange(values) {
  688. if (!values.length) {
  689. return {
  690. min: 0,
  691. max: 0
  692. };
  693. }
  694. var max = Math.max.apply(null, values);
  695. var min = Math.min.apply(null, values);
  696. return {
  697. min: min,
  698. max: max
  699. };
  700. }
  701. var array = /*#__PURE__*/Object.freeze({
  702. __proto__: null,
  703. merge: merge$1,
  704. values: values,
  705. firstValue: firstValue,
  706. group: group,
  707. groupToMap: groupToMap,
  708. remove: remove,
  709. getRange: getRange
  710. });
  711. /**
  712. * Detects support for options object argument in addEventListener.
  713. * https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#Safely_detecting_option_support
  714. * @private
  715. */
  716. var supportsEventListenerOptions = function () {
  717. var supports = false;
  718. try {
  719. var options = Object.defineProperty({}, 'passive', {
  720. get: function get() {
  721. supports = true;
  722. }
  723. });
  724. window.addEventListener('e', null, options);
  725. } catch (e) {// continue regardless of error
  726. }
  727. return supports;
  728. }(); // Default passive to true as expected by Chrome for 'touchstart' and 'touchend' events.
  729. // https://github.com/chartjs/Chart.js/issues/4287
  730. var eventListenerOptions = supportsEventListenerOptions ? {
  731. passive: true
  732. } : false;
  733. /* global wx, my */
  734. // weixin miniprogram
  735. var isWx = typeof wx === 'object' && typeof wx.getSystemInfoSync === 'function'; // ant miniprogram
  736. var isMy = typeof my === 'object' && typeof my.getSystemInfoSync === 'function'; // in node
  737. var isNode = typeof global && !typeof window; // in browser
  738. var isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.sessionStorage !== 'undefined';
  739. function isCanvasElement(el) {
  740. if (!el || typeof el !== 'object') return false;
  741. if (el.nodeType === 1 && el.nodeName) {
  742. // HTMLCanvasElement
  743. return true;
  744. } // CanvasElement
  745. return !!el.isCanvasElement;
  746. }
  747. function getPixelRatio() {
  748. return window && window.devicePixelRatio || 1;
  749. }
  750. function getStyle$1(el, property) {
  751. return el.currentStyle ? el.currentStyle[property] : document.defaultView.getComputedStyle(el, null).getPropertyValue(property);
  752. }
  753. function getWidth(el) {
  754. var width = getStyle$1(el, 'width');
  755. if (width === 'auto') {
  756. width = el.offsetWidth;
  757. }
  758. return parseFloat(width);
  759. }
  760. function getHeight(el) {
  761. var height = getStyle$1(el, 'height');
  762. if (height === 'auto') {
  763. height = el.offsetHeight;
  764. }
  765. return parseFloat(height);
  766. }
  767. function getDomById(id) {
  768. if (!id) {
  769. return null;
  770. }
  771. return document.getElementById(id);
  772. }
  773. function getRelativePosition(point, canvas) {
  774. var canvasDom = canvas.get('el');
  775. if (!canvasDom) return point;
  776. var _canvasDom$getBoundin = canvasDom.getBoundingClientRect(),
  777. top = _canvasDom$getBoundin.top,
  778. left = _canvasDom$getBoundin.left;
  779. var paddingLeft = parseFloat(getStyle$1(canvasDom, 'padding-left'));
  780. var paddingTop = parseFloat(getStyle$1(canvasDom, 'padding-top'));
  781. var mouseX = point.x - left - paddingLeft;
  782. var mouseY = point.y - top - paddingTop;
  783. return {
  784. x: mouseX,
  785. y: mouseY
  786. };
  787. }
  788. function addEventListener(source, type, listener) {
  789. source.addEventListener(type, listener, eventListenerOptions);
  790. }
  791. function removeEventListener(source, type, listener) {
  792. source.removeEventListener(type, listener, eventListenerOptions);
  793. }
  794. function landscapePoint(point, canvas) {
  795. var landscape = canvas.get('landscape');
  796. if (!landscape) {
  797. return point;
  798. }
  799. if (isFunction$1(landscape)) {
  800. return landscape(point, canvas);
  801. } // 默认顺时针旋转90度
  802. var height = canvas.get('height');
  803. var x = point.y;
  804. var y = height - point.x;
  805. return {
  806. x: x,
  807. y: y
  808. };
  809. }
  810. function convertPoints(ev, canvas) {
  811. var touches = ev.touches; // 认为是mouse事件
  812. if (!touches) {
  813. var point = getRelativePosition({
  814. x: ev.clientX,
  815. y: ev.clientY
  816. }, canvas);
  817. return [landscapePoint(point, canvas)];
  818. } // 单指 touchend 后,touchs 会变空,最后的触点要从changedTouches里拿
  819. if (!touches.length) {
  820. // 为了防止万一,加个空逻辑
  821. touches = ev.changedTouches || [];
  822. }
  823. var points = [];
  824. for (var i = 0, len = touches.length; i < len; i++) {
  825. var touch = touches[i]; // x, y: 相对canvas原点的位置,clientX, clientY 相对于可视窗口的位置
  826. var x = touch.x,
  827. y = touch.y,
  828. clientX = touch.clientX,
  829. clientY = touch.clientY;
  830. var _point = void 0; // 小程序环境会有x,y
  831. if (isNumber(x) || isNumber(y)) {
  832. _point = {
  833. x: x,
  834. y: y
  835. };
  836. } else {
  837. // 浏览器环境再计算下canvas的相对位置
  838. _point = getRelativePosition({
  839. x: clientX,
  840. y: clientY
  841. }, canvas);
  842. }
  843. points.push(landscapePoint(_point, canvas));
  844. }
  845. return points;
  846. }
  847. function createEvent(event, chart) {
  848. var canvas = chart.get('canvas');
  849. var points = convertPoints(event, canvas); // touchend会没有points
  850. var point = points[0] || {};
  851. return {
  852. type: event.type,
  853. chart: chart,
  854. "native": event,
  855. x: point.x,
  856. y: point.y
  857. };
  858. }
  859. function measureText(text, font, ctx) {
  860. if (!ctx) {
  861. ctx = document.createElement('canvas').getContext('2d');
  862. }
  863. ctx.font = font || '12px sans-serif';
  864. return ctx.measureText(text);
  865. }
  866. /**
  867. * @fileOverview Utility for F2
  868. * @author dxq613 @gmail.com
  869. * @author sima.zhang1990@gmail.com
  870. */
  871. function isObjectValueEqual(a, b) {
  872. // for vue.js
  873. a = Object.assign({}, a);
  874. b = Object.assign({}, b);
  875. var aProps = Object.getOwnPropertyNames(a);
  876. var bProps = Object.getOwnPropertyNames(b);
  877. if (aProps.length !== bProps.length) {
  878. return false;
  879. }
  880. for (var i = 0, len = aProps.length; i < len; i++) {
  881. var propName = aProps[i];
  882. if (a[propName] !== b[propName]) {
  883. return false;
  884. }
  885. }
  886. return true;
  887. }
  888. function parsePadding(padding) {
  889. var top;
  890. var right;
  891. var bottom;
  892. var left;
  893. if (isNumber(padding) || isString(padding)) {
  894. top = bottom = left = right = padding;
  895. } else if (isArray$1(padding)) {
  896. top = padding[0];
  897. right = !isNil$1(padding[1]) ? padding[1] : padding[0];
  898. bottom = !isNil$1(padding[2]) ? padding[2] : padding[0];
  899. left = !isNil$1(padding[3]) ? padding[3] : right;
  900. }
  901. return [top, right, bottom, left];
  902. }
  903. function directionEnabled(mode, dir) {
  904. if (mode === undefined) {
  905. return true;
  906. } else if (typeof mode === 'string') {
  907. return mode.indexOf(dir) !== -1;
  908. }
  909. return false;
  910. }
  911. function toTimeStamp$1(value) {
  912. if (isString(value)) {
  913. if (value.indexOf('T') > 0) {
  914. value = new Date(value).getTime();
  915. } else {
  916. // new Date('2010/01/10') 和 new Date('2010-01-10') 的差别在于:
  917. // 如果仅有年月日时,前者是带有时区的: Fri Jan 10 2020 02:40:13 GMT+0800 (中国标准时间)
  918. // 后者会格式化成 Sun Jan 10 2010 08:00:00 GMT+0800 (中国标准时间)
  919. value = new Date(value.replace(/-/gi, '/')).getTime();
  920. }
  921. }
  922. if (isDate(value)) {
  923. value = value.getTime();
  924. }
  925. return value;
  926. }
  927. var Util = /*#__PURE__*/Object.freeze({
  928. __proto__: null,
  929. Array: array,
  930. upperFirst: upperFirst,
  931. lowerFirst: lowerFirst,
  932. isString: isString,
  933. isNumber: isNumber,
  934. isBoolean: isBoolean,
  935. isFunction: isFunction$1,
  936. isDate: isDate,
  937. isArray: isArray$1,
  938. isNil: isNil$1,
  939. isObject: isObject$1,
  940. isPlainObject: isPlainObject,
  941. isEqual: isEqual$1,
  942. deepMix: deepMix,
  943. mix: mix$1,
  944. each: each$1,
  945. uniq: uniq,
  946. find: find,
  947. isObjectValueEqual: isObjectValueEqual,
  948. parsePadding: parsePadding,
  949. directionEnabled: directionEnabled,
  950. toTimeStamp: toTimeStamp$1,
  951. substitute: substitute,
  952. isWx: isWx,
  953. isMy: isMy,
  954. isNode: isNode,
  955. isBrowser: isBrowser,
  956. isCanvasElement: isCanvasElement,
  957. getPixelRatio: getPixelRatio,
  958. getStyle: getStyle$1,
  959. getWidth: getWidth,
  960. getHeight: getHeight,
  961. getDomById: getDomById,
  962. getRelativePosition: getRelativePosition,
  963. addEventListener: addEventListener,
  964. removeEventListener: removeEventListener,
  965. createEvent: createEvent,
  966. convertPoints: convertPoints,
  967. measureText: measureText
  968. });
  969. /**
  970. * @fileOverview default theme
  971. * @author dxq613@gail.com
  972. */
  973. var color1 = '#E8E8E8'; // color of axis-line and axis-grid
  974. var color2 = '#808080'; // color of axis label
  975. var defaultAxis = {
  976. label: {
  977. fill: color2,
  978. fontSize: 10
  979. },
  980. line: {
  981. stroke: color1,
  982. lineWidth: 1
  983. },
  984. grid: {
  985. type: 'line',
  986. stroke: color1,
  987. lineWidth: 1,
  988. lineDash: [2]
  989. },
  990. tickLine: null,
  991. labelOffset: 7.5
  992. };
  993. var Theme = {
  994. fontFamily: '"Helvetica Neue", "San Francisco", Helvetica, Tahoma, Arial, "PingFang SC", "Hiragino Sans GB", "Heiti SC", "Microsoft YaHei", sans-serif',
  995. defaultColor: '#1890FF',
  996. pixelRatio: 1,
  997. padding: 'auto',
  998. appendPadding: 15,
  999. colors: ['#1890FF', '#2FC25B', '#FACC14', '#223273', '#8543E0', '#13C2C2', '#3436C7', '#F04864'],
  1000. shapes: {
  1001. line: ['line', 'dash'],
  1002. point: ['circle', 'hollowCircle']
  1003. },
  1004. sizes: [4, 10],
  1005. axis: {
  1006. common: defaultAxis,
  1007. // common axis configuration
  1008. bottom: mix$1({}, defaultAxis, {
  1009. grid: null
  1010. }),
  1011. left: mix$1({}, defaultAxis, {
  1012. line: null
  1013. }),
  1014. right: mix$1({}, defaultAxis, {
  1015. line: null
  1016. }),
  1017. circle: mix$1({}, defaultAxis, {
  1018. line: null
  1019. }),
  1020. radius: mix$1({}, defaultAxis, {
  1021. labelOffset: 4
  1022. })
  1023. },
  1024. shape: {
  1025. line: {
  1026. lineWidth: 2,
  1027. lineJoin: 'round',
  1028. lineCap: 'round'
  1029. },
  1030. point: {
  1031. lineWidth: 0,
  1032. size: 3
  1033. },
  1034. area: {
  1035. fillOpacity: 0.1
  1036. }
  1037. },
  1038. _defaultAxis: defaultAxis
  1039. };
  1040. var lang = {
  1041. general: {
  1042. title: '这是一个图表,',
  1043. withTitle: '这是一个关于“{title}”的图表。'
  1044. },
  1045. coord: {
  1046. cartesian: 'X轴是{xLabel}Y轴是{yLabel}' // polar: '弧度是{xLabel}半径是{yLabel}'
  1047. },
  1048. scale: {
  1049. linear: '数值型,数据最小值为{min},最大值为{max};',
  1050. cat: '分类型, 分类类型有:{values};',
  1051. timeCat: '时间型,时间范围从{start}到{end};'
  1052. },
  1053. geometry: {
  1054. prefix: '共有{count}种分类组成,',
  1055. oneData: '第{index}类是{name},数据是{values};',
  1056. partData: '第{index}类是{name},共有{count}项数据,前{part}项是{values};',
  1057. allData: '第{index}类是{name},有{count}项数据,分别是{values};'
  1058. },
  1059. legend: {
  1060. prefix: '图例分类有:'
  1061. }
  1062. };
  1063. var Global = {
  1064. version: '3.8.10-beta.1',
  1065. scales: {},
  1066. widthRatio: {
  1067. column: 1 / 2,
  1068. rose: 0.999999,
  1069. multiplePie: 3 / 4
  1070. },
  1071. lineDash: [4, 4],
  1072. lang: lang
  1073. };
  1074. Global.setTheme = function (theme) {
  1075. deepMix(Global, theme);
  1076. };
  1077. Global.setTheme(Theme);
  1078. function _defineProperty(obj, key, value) {
  1079. if (key in obj) {
  1080. Object.defineProperty(obj, key, {
  1081. value: value,
  1082. enumerable: true,
  1083. configurable: true,
  1084. writable: true
  1085. });
  1086. } else {
  1087. obj[key] = value;
  1088. }
  1089. return obj;
  1090. }
  1091. function _extends() {
  1092. _extends = Object.assign || function (target) {
  1093. for (var i = 1; i < arguments.length; i++) {
  1094. var source = arguments[i];
  1095. for (var key in source) {
  1096. if (Object.prototype.hasOwnProperty.call(source, key)) {
  1097. target[key] = source[key];
  1098. }
  1099. }
  1100. }
  1101. return target;
  1102. };
  1103. return _extends.apply(this, arguments);
  1104. }
  1105. function _inheritsLoose$3(subClass, superClass) {
  1106. subClass.prototype = Object.create(superClass.prototype);
  1107. subClass.prototype.constructor = subClass;
  1108. _setPrototypeOf(subClass, superClass);
  1109. }
  1110. function _setPrototypeOf(o, p) {
  1111. _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
  1112. o.__proto__ = p;
  1113. return o;
  1114. };
  1115. return _setPrototypeOf(o, p);
  1116. }
  1117. function _assertThisInitialized(self) {
  1118. if (self === void 0) {
  1119. throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  1120. }
  1121. return self;
  1122. }
  1123. var EVENT_AFTER_INIT = 'afterinit';
  1124. var EVENT_BEFORE_RENDER = 'beforerender';
  1125. var EVENT_AFTER_RENDER = 'afterrender';
  1126. var EVENT_BEFORE_DATA_CHANGE = 'beforedatachange';
  1127. var EVENT_AFTER_DATA_CHANGE = 'afterdatachange';
  1128. var EVENT_AFTER_SIZE_CHANGE = '_aftersizechange';
  1129. var EVENT_AFTER_GEOM_INIT = '_aftergeominit';
  1130. var EVENT_BEFORE_GEOM_DRAW = 'beforegeomdraw';
  1131. var EVENT_AFTER_GEOM_DRAW = 'aftergeomdraw';
  1132. var EVENT_CLEAR = 'clear';
  1133. var EVENT_CLEAR_INNER = 'clearinner';
  1134. var EVENT_REPAINT = 'repaint';
  1135. // 实现简单的事件机制
  1136. var EventEmit = /*#__PURE__*/function () {
  1137. function EventEmit() {
  1138. this.__events = {};
  1139. }
  1140. var _proto = EventEmit.prototype;
  1141. _proto.on = function on(type, listener) {
  1142. if (!type || !listener) {
  1143. return;
  1144. }
  1145. var events = this.__events[type] || [];
  1146. events.push(listener);
  1147. this.__events[type] = events;
  1148. };
  1149. _proto.emit = function emit(type, e) {
  1150. var _this = this;
  1151. if (isObject$1(type)) {
  1152. e = type;
  1153. type = e && e.type;
  1154. }
  1155. if (!type) {
  1156. return;
  1157. }
  1158. var events = this.__events[type];
  1159. if (!events || !events.length) {
  1160. return;
  1161. }
  1162. events.forEach(function (listener) {
  1163. listener.call(_this, e);
  1164. });
  1165. };
  1166. _proto.off = function off(type, listener) {
  1167. var __events = this.__events;
  1168. var events = __events[type];
  1169. if (!events || !events.length) {
  1170. return;
  1171. } // 如果没有指定方法,则删除所有项
  1172. if (!listener) {
  1173. delete __events[type];
  1174. return;
  1175. } // 删除指定的 listener
  1176. for (var i = 0, len = events.length; i < len; i++) {
  1177. if (events[i] === listener) {
  1178. events.splice(i, 1);
  1179. i--;
  1180. }
  1181. }
  1182. };
  1183. return EventEmit;
  1184. }();
  1185. var Base$2 = /*#__PURE__*/function (_Emit) {
  1186. _inheritsLoose$3(Base, _Emit);
  1187. var _proto = Base.prototype;
  1188. _proto.getDefaultCfg = function getDefaultCfg() {
  1189. return {};
  1190. };
  1191. function Base(cfg) {
  1192. var _this;
  1193. _this = _Emit.call(this) || this;
  1194. var attrs = {};
  1195. var defaultCfg = _this.getDefaultCfg();
  1196. _this._attrs = attrs;
  1197. mix$1(attrs, defaultCfg, cfg);
  1198. return _this;
  1199. }
  1200. _proto.get = function get(name) {
  1201. return this._attrs[name];
  1202. };
  1203. _proto.set = function set(name, value) {
  1204. this._attrs[name] = value;
  1205. };
  1206. _proto.destroy = function destroy() {
  1207. this._attrs = {};
  1208. this.destroyed = true;
  1209. };
  1210. return Base;
  1211. }(EventEmit);
  1212. var Plot = /*#__PURE__*/function () {
  1213. function Plot(cfg) {
  1214. mix$1(this, cfg);
  1215. this._init();
  1216. }
  1217. var _proto = Plot.prototype;
  1218. _proto._init = function _init() {
  1219. var self = this;
  1220. var start = self.start;
  1221. var end = self.end;
  1222. var xMin = Math.min(start.x, end.x);
  1223. var xMax = Math.max(start.x, end.x);
  1224. var yMin = Math.min(start.y, end.y);
  1225. var yMax = Math.max(start.y, end.y);
  1226. this.tl = {
  1227. x: xMin,
  1228. y: yMin
  1229. };
  1230. this.tr = {
  1231. x: xMax,
  1232. y: yMin
  1233. };
  1234. this.bl = {
  1235. x: xMin,
  1236. y: yMax
  1237. };
  1238. this.br = {
  1239. x: xMax,
  1240. y: yMax
  1241. };
  1242. this.width = xMax - xMin;
  1243. this.height = yMax - yMin;
  1244. }
  1245. /**
  1246. * reset
  1247. * @param {Object} start start point
  1248. * @param {Object} end end point
  1249. */
  1250. ;
  1251. _proto.reset = function reset(start, end) {
  1252. this.start = start;
  1253. this.end = end;
  1254. this._init();
  1255. }
  1256. /**
  1257. * check the point is in the range of plot
  1258. * @param {Number} x x value
  1259. * @param {[type]} y y value
  1260. * @return {Boolean} return the result
  1261. */
  1262. ;
  1263. _proto.isInRange = function isInRange(x, y) {
  1264. if (isObject$1(x)) {
  1265. y = x.y;
  1266. x = x.x;
  1267. }
  1268. var tl = this.tl;
  1269. var br = this.br;
  1270. return tl.x <= x && x <= br.x && tl.y <= y && y <= br.y;
  1271. };
  1272. return Plot;
  1273. }();
  1274. var Matrix = {
  1275. generateDefault: function generateDefault() {
  1276. return [1, 0, 0, 1, 0, 0];
  1277. },
  1278. isChanged: function isChanged(m) {
  1279. return m[0] !== 1 || m[1] !== 0 || m[2] !== 0 || m[3] !== 1 || m[4] !== 0 || m[5] !== 0;
  1280. },
  1281. multiply: function multiply(m1, m2) {
  1282. var m11 = m1[0] * m2[0] + m1[2] * m2[1];
  1283. var m12 = m1[1] * m2[0] + m1[3] * m2[1];
  1284. var m21 = m1[0] * m2[2] + m1[2] * m2[3];
  1285. var m22 = m1[1] * m2[2] + m1[3] * m2[3];
  1286. var dx = m1[0] * m2[4] + m1[2] * m2[5] + m1[4];
  1287. var dy = m1[1] * m2[4] + m1[3] * m2[5] + m1[5];
  1288. return [m11, m12, m21, m22, dx, dy];
  1289. },
  1290. scale: function scale(out, m, v) {
  1291. out[0] = m[0] * v[0];
  1292. out[1] = m[1] * v[0];
  1293. out[2] = m[2] * v[1];
  1294. out[3] = m[3] * v[1];
  1295. out[4] = m[4];
  1296. out[5] = m[5];
  1297. return out;
  1298. },
  1299. rotate: function rotate(out, m, radian) {
  1300. var c = Math.cos(radian);
  1301. var s = Math.sin(radian);
  1302. var m11 = m[0] * c + m[2] * s;
  1303. var m12 = m[1] * c + m[3] * s;
  1304. var m21 = m[0] * -s + m[2] * c;
  1305. var m22 = m[1] * -s + m[3] * c;
  1306. out[0] = m11;
  1307. out[1] = m12;
  1308. out[2] = m21;
  1309. out[3] = m22;
  1310. out[4] = m[4];
  1311. out[5] = m[5];
  1312. return out;
  1313. },
  1314. translate: function translate(out, m, v) {
  1315. out[0] = m[0];
  1316. out[1] = m[1];
  1317. out[2] = m[2];
  1318. out[3] = m[3];
  1319. out[4] = m[4] + m[0] * v[0] + m[2] * v[1];
  1320. out[5] = m[5] + m[1] * v[0] + m[3] * v[1];
  1321. return out;
  1322. },
  1323. transform: function transform(m, actions) {
  1324. var out = [].concat(m);
  1325. for (var i = 0, len = actions.length; i < len; i++) {
  1326. var action = actions[i];
  1327. switch (action[0]) {
  1328. case 't':
  1329. Matrix.translate(out, out, [action[1], action[2]]);
  1330. break;
  1331. case 's':
  1332. Matrix.scale(out, out, [action[1], action[2]]);
  1333. break;
  1334. case 'r':
  1335. Matrix.rotate(out, out, action[1]);
  1336. break;
  1337. }
  1338. }
  1339. return out;
  1340. }
  1341. };
  1342. /**
  1343. * 2 Dimensional Vector
  1344. * @module vector2
  1345. */
  1346. var Vector2 = {
  1347. /**
  1348. * Creates a new, empty vector2
  1349. *
  1350. * @return {vector2} a new 2D vector
  1351. */
  1352. create: function create() {
  1353. return [0, 0];
  1354. },
  1355. /**
  1356. * Calculates the length of a vector2
  1357. *
  1358. * @param {vector2} v vector to calculate length of
  1359. * @return {Number} length of v
  1360. */
  1361. length: function length(v) {
  1362. var x = v[0];
  1363. var y = v[1];
  1364. return Math.sqrt(x * x + y * y);
  1365. },
  1366. /**
  1367. * Normalize a vector2
  1368. *
  1369. * @param {vector2} out the receiving vector
  1370. * @param {vector2} v vector to normalize
  1371. * @return {vector2} out
  1372. */
  1373. normalize: function normalize(out, v) {
  1374. var len = this.length(v);
  1375. if (len === 0) {
  1376. out[0] = 0;
  1377. out[1] = 0;
  1378. } else {
  1379. out[0] = v[0] / len;
  1380. out[1] = v[1] / len;
  1381. }
  1382. return out;
  1383. },
  1384. /**
  1385. * Adds two vector2's
  1386. *
  1387. * @param {vector2} out the receiving vector
  1388. * @param {vector2} v1 the first operand
  1389. * @param {vector2} v2 the second operand
  1390. * @return {vector2} out
  1391. */
  1392. add: function add(out, v1, v2) {
  1393. out[0] = v1[0] + v2[0];
  1394. out[1] = v1[1] + v2[1];
  1395. return out;
  1396. },
  1397. /**
  1398. * Subtracts vector v2 from vector v1
  1399. *
  1400. * @param {vector2} out the receiving vector
  1401. * @param {vector2} v1 the first operand
  1402. * @param {vector2} v2 the second operand
  1403. * @return {vector2} out
  1404. */
  1405. sub: function sub(out, v1, v2) {
  1406. out[0] = v1[0] - v2[0];
  1407. out[1] = v1[1] - v2[1];
  1408. return out;
  1409. },
  1410. /**
  1411. * Scales a vector2 by a scalar number
  1412. *
  1413. * @param {vector2} out the receiving vector
  1414. * @param {vector2} v the vector to scale
  1415. * @param {Number} s amount to scale the vector by
  1416. * @return {vector2} out
  1417. */
  1418. scale: function scale(out, v, s) {
  1419. out[0] = v[0] * s;
  1420. out[1] = v[1] * s;
  1421. return out;
  1422. },
  1423. /**
  1424. * Calculates the dot product of two vector2's
  1425. *
  1426. * @param {vector2} v1 the first operand
  1427. * @param {vector2} v2 the second operand
  1428. * @return {Number} dot product of v1 and v2
  1429. */
  1430. dot: function dot(v1, v2) {
  1431. return v1[0] * v2[0] + v1[1] * v2[1];
  1432. },
  1433. /**
  1434. * Calculates the direction of two vector2's
  1435. *
  1436. * @param {vector2} v1 the first operand
  1437. * @param {vector2} v2 the second operand
  1438. * @return {Boolean} the direction of v1 and v2
  1439. */
  1440. direction: function direction(v1, v2) {
  1441. return v1[0] * v2[1] - v2[0] * v1[1];
  1442. },
  1443. /**
  1444. * Calculates the angle of two vector2's
  1445. *
  1446. * @param {vector2} v1 the first operand
  1447. * @param {vector2} v2 the second operand
  1448. * @return {Number} angle of v1 and v2
  1449. */
  1450. angle: function angle(v1, v2) {
  1451. var theta = this.dot(v1, v2) / (this.length(v1) * this.length(v2));
  1452. return Math.acos(theta);
  1453. },
  1454. /**
  1455. * Calculates the angle of two vector2's with direction
  1456. *
  1457. * @param {vector2} v1 the first operand
  1458. * @param {vector2} v2 the second operand
  1459. * @param {Boolean} direction the direction of two vector2's
  1460. * @return {Number} angle of v1 and v2
  1461. */
  1462. angleTo: function angleTo(v1, v2, direction) {
  1463. var angle = this.angle(v1, v2);
  1464. var angleLargeThanPI = this.direction(v1, v2) >= 0;
  1465. if (direction) {
  1466. if (angleLargeThanPI) {
  1467. return Math.PI * 2 - angle;
  1468. }
  1469. return angle;
  1470. }
  1471. if (angleLargeThanPI) {
  1472. return angle;
  1473. }
  1474. return Math.PI * 2 - angle;
  1475. },
  1476. /**
  1477. * whether a vector2 is zero vector
  1478. *
  1479. * @param {vector2} v vector to calculate
  1480. * @return {Boolean} is or not a zero vector
  1481. */
  1482. zero: function zero(v) {
  1483. return v[0] === 0 && v[1] === 0;
  1484. },
  1485. /**
  1486. * Calculates the euclidian distance between two vector2's
  1487. *
  1488. * @param {vector2} v1 the first operand
  1489. * @param {vector2} v2 the second operand
  1490. * @return {Number} distance between a and b
  1491. */
  1492. distance: function distance(v1, v2) {
  1493. var x = v2[0] - v1[0];
  1494. var y = v2[1] - v1[1];
  1495. return Math.sqrt(x * x + y * y);
  1496. },
  1497. /**
  1498. * Creates a new vector2 initialized with values from an existing vector
  1499. *
  1500. * @param {vector2} v vector to clone
  1501. * @return {Array} a new 2D vector
  1502. */
  1503. clone: function clone(v) {
  1504. return [v[0], v[1]];
  1505. },
  1506. /**
  1507. * Return the minimum of two vector2's
  1508. *
  1509. * @param {vector2} out the receiving vector
  1510. * @param {vector2} v1 the first operand
  1511. * @param {vector2} v2 the second operand
  1512. * @return {vector2} out
  1513. */
  1514. min: function min(out, v1, v2) {
  1515. out[0] = Math.min(v1[0], v2[0]);
  1516. out[1] = Math.min(v1[1], v2[1]);
  1517. return out;
  1518. },
  1519. /**
  1520. * Return the maximum of two vector2's
  1521. *
  1522. * @param {vector2} out the receiving vector
  1523. * @param {vector2} v1 the first operand
  1524. * @param {vector2} v2 the second operand
  1525. * @return {vector2} out
  1526. */
  1527. max: function max(out, v1, v2) {
  1528. out[0] = Math.max(v1[0], v2[0]);
  1529. out[1] = Math.max(v1[1], v2[1]);
  1530. return out;
  1531. },
  1532. /**
  1533. * Transforms the vector2 with a mat2d
  1534. *
  1535. * @param {vector2} out the receiving vector
  1536. * @param {vector2} v the vector to transform
  1537. * @param {mat2d} m matrix to transform with
  1538. * @return {vector2} out
  1539. */
  1540. transformMat2d: function transformMat2d(out, v, m) {
  1541. var x = v[0];
  1542. var y = v[1];
  1543. out[0] = m[0] * x + m[2] * y + m[4];
  1544. out[1] = m[1] * x + m[3] * y + m[5];
  1545. return out;
  1546. }
  1547. };
  1548. var defaultMatrix = [1, 0, 0, 1, 0, 0];
  1549. var Base$1 = /*#__PURE__*/function () {
  1550. var _proto = Base.prototype;
  1551. _proto._initDefaultCfg = function _initDefaultCfg() {};
  1552. function Base(cfg) {
  1553. this._initDefaultCfg();
  1554. mix$1(this, cfg);
  1555. var start;
  1556. var end;
  1557. if (this.plot) {
  1558. start = this.plot.bl;
  1559. end = this.plot.tr;
  1560. this.start = start;
  1561. this.end = end;
  1562. } else {
  1563. start = this.start;
  1564. end = this.end;
  1565. }
  1566. this.init(start, end);
  1567. }
  1568. _proto._scale = function _scale(s1, s2) {
  1569. var matrix = this.matrix;
  1570. var center = this.center;
  1571. Matrix.translate(matrix, matrix, [center.x, center.y]);
  1572. Matrix.scale(matrix, matrix, [s1, s2]);
  1573. Matrix.translate(matrix, matrix, [-center.x, -center.y]);
  1574. };
  1575. _proto.init = function init(start, end) {
  1576. this.matrix = [].concat(defaultMatrix); // 设置中心点
  1577. this.center = {
  1578. x: (end.x - start.x) / 2 + start.x,
  1579. y: (end.y - start.y) / 2 + start.y
  1580. };
  1581. if (this.scale) {
  1582. this._scale(this.scale[0], this.scale[1]);
  1583. }
  1584. };
  1585. _proto.convertPoint = function convertPoint(point) {
  1586. var _this$_convertPoint = this._convertPoint(point),
  1587. x = _this$_convertPoint.x,
  1588. y = _this$_convertPoint.y;
  1589. if (!Matrix.isChanged(this.matrix)) {
  1590. return {
  1591. x: x,
  1592. y: y
  1593. };
  1594. }
  1595. var vector = [x, y];
  1596. Vector2.transformMat2d(vector, vector, this.matrix);
  1597. return {
  1598. x: vector[0],
  1599. y: vector[1]
  1600. };
  1601. };
  1602. _proto.invertPoint = function invertPoint(point) {
  1603. return this._invertPoint(point);
  1604. };
  1605. _proto._convertPoint = function _convertPoint(point) {
  1606. return point;
  1607. };
  1608. _proto._invertPoint = function _invertPoint(point) {
  1609. return point;
  1610. };
  1611. _proto.reset = function reset(plot) {
  1612. this.plot = plot;
  1613. var bl = plot.bl,
  1614. tr = plot.tr;
  1615. this.start = bl;
  1616. this.end = tr;
  1617. this.init(bl, tr);
  1618. };
  1619. return Base;
  1620. }();
  1621. var Cartesian = /*#__PURE__*/function (_Base) {
  1622. _inheritsLoose$3(Cartesian, _Base);
  1623. function Cartesian() {
  1624. return _Base.apply(this, arguments) || this;
  1625. }
  1626. var _proto = Cartesian.prototype;
  1627. _proto._initDefaultCfg = function _initDefaultCfg() {
  1628. this.type = 'cartesian';
  1629. this.transposed = false;
  1630. this.isRect = true;
  1631. };
  1632. _proto.init = function init(start, end) {
  1633. _Base.prototype.init.call(this, start, end);
  1634. this.x = {
  1635. start: start.x,
  1636. end: end.x
  1637. };
  1638. this.y = {
  1639. start: start.y,
  1640. end: end.y
  1641. };
  1642. };
  1643. _proto._convertPoint = function _convertPoint(point) {
  1644. var self = this;
  1645. var transposed = self.transposed;
  1646. var xDim = transposed ? 'y' : 'x';
  1647. var yDim = transposed ? 'x' : 'y';
  1648. var x = self.x;
  1649. var y = self.y;
  1650. return {
  1651. x: x.start + (x.end - x.start) * point[xDim],
  1652. y: y.start + (y.end - y.start) * point[yDim]
  1653. };
  1654. };
  1655. _proto._invertPoint = function _invertPoint(point) {
  1656. var self = this;
  1657. var transposed = self.transposed;
  1658. var xDim = transposed ? 'y' : 'x';
  1659. var yDim = transposed ? 'x' : 'y';
  1660. var x = self.x;
  1661. var y = self.y;
  1662. var rst = {};
  1663. rst[xDim] = (point.x - x.start) / (x.end - x.start);
  1664. rst[yDim] = (point.y - y.start) / (y.end - y.start);
  1665. return rst;
  1666. };
  1667. return Cartesian;
  1668. }(Base$1);
  1669. Base$1.Cartesian = Cartesian;
  1670. Base$1.Rect = Cartesian;
  1671. /**
  1672. * @fileOverview the Attribute base class
  1673. */
  1674. function toScaleString(scale, value) {
  1675. if (isString(value)) {
  1676. return value;
  1677. }
  1678. return scale.invert(scale.scale(value));
  1679. }
  1680. /**
  1681. * 所有视觉通道属性的基类
  1682. * @class Attr
  1683. */
  1684. var AttributeBase = /*#__PURE__*/function () {
  1685. function AttributeBase(cfg) {
  1686. var _this = this;
  1687. /**
  1688. * 属性的类型
  1689. * @type {String}
  1690. */
  1691. this.type = 'base';
  1692. /**
  1693. * 属性的名称
  1694. * @type {String}
  1695. */
  1696. this.name = null;
  1697. /**
  1698. * 回调函数
  1699. * @type {Function}
  1700. */
  1701. this.method = null;
  1702. /**
  1703. * 备选的值数组
  1704. * @type {Array}
  1705. */
  1706. this.values = [];
  1707. /**
  1708. * 属性内部的度量
  1709. * @type {Array}
  1710. */
  1711. this.scales = [];
  1712. /**
  1713. * 是否通过线性取值, 如果未指定,则根据数值的类型判定
  1714. * @type {Boolean}
  1715. */
  1716. this.linear = null;
  1717. /**
  1718. * 当用户设置的 callback 返回 null 时, 应该返回默认 callback 中的值
  1719. */
  1720. var mixedCallback = null;
  1721. var defaultCallback = this.callback;
  1722. if (cfg.callback) {
  1723. var userCallback = cfg.callback;
  1724. mixedCallback = function mixedCallback() {
  1725. for (var _len = arguments.length, params = new Array(_len), _key = 0; _key < _len; _key++) {
  1726. params[_key] = arguments[_key];
  1727. }
  1728. var ret = userCallback.apply(void 0, params);
  1729. if (isNil$1(ret)) {
  1730. ret = defaultCallback.apply(_this, params);
  1731. }
  1732. return ret;
  1733. };
  1734. }
  1735. mix$1(this, cfg);
  1736. if (mixedCallback) {
  1737. mix$1(this, {
  1738. callback: mixedCallback
  1739. });
  1740. }
  1741. } // 获取属性值,将值映射到视觉通道
  1742. var _proto = AttributeBase.prototype;
  1743. _proto._getAttrValue = function _getAttrValue(scale, value) {
  1744. var values = this.values;
  1745. if (scale.isCategory && !this.linear) {
  1746. var index = scale.translate(value);
  1747. return values[index % values.length];
  1748. }
  1749. var percent = scale.scale(value);
  1750. return this.getLinearValue(percent);
  1751. }
  1752. /**
  1753. * 如果进行线性映射,返回对应的映射值
  1754. * @protected
  1755. * @param {Number} percent 百分比
  1756. * @return {*} 颜色值、形状、大小等
  1757. */
  1758. ;
  1759. _proto.getLinearValue = function getLinearValue(percent) {
  1760. var values = this.values;
  1761. var steps = values.length - 1;
  1762. var step = Math.floor(steps * percent);
  1763. var leftPercent = steps * percent - step;
  1764. var start = values[step];
  1765. var end = step === steps ? start : values[step + 1];
  1766. var rstValue = start + (end - start) * leftPercent;
  1767. return rstValue;
  1768. }
  1769. /**
  1770. * 默认的回调函数
  1771. * @param {*} value 回调函数的值
  1772. * @type {Function}
  1773. * @return {Array} 返回映射后的值
  1774. */
  1775. ;
  1776. _proto.callback = function callback(value) {
  1777. var self = this;
  1778. var scale = self.scales[0];
  1779. var rstValue = null;
  1780. if (scale.type === 'identity') {
  1781. rstValue = scale.value;
  1782. } else {
  1783. rstValue = self._getAttrValue(scale, value);
  1784. }
  1785. return rstValue;
  1786. }
  1787. /**
  1788. * 根据度量获取属性名
  1789. * @return {Array} dims of this Attribute
  1790. */
  1791. ;
  1792. _proto.getNames = function getNames() {
  1793. var scales = this.scales;
  1794. var names = this.names;
  1795. var length = Math.min(scales.length, names.length);
  1796. var rst = [];
  1797. for (var i = 0; i < length; i++) {
  1798. rst.push(names[i]);
  1799. }
  1800. return rst;
  1801. }
  1802. /**
  1803. * 根据度量获取维度名
  1804. * @return {Array} dims of this Attribute
  1805. */
  1806. ;
  1807. _proto.getFields = function getFields() {
  1808. var scales = this.scales;
  1809. var rst = [];
  1810. each$1(scales, function (scale) {
  1811. rst.push(scale.field);
  1812. });
  1813. return rst;
  1814. }
  1815. /**
  1816. * 根据名称获取度量
  1817. * @param {String} name the name of scale
  1818. * @return {Scale} scale
  1819. */
  1820. ;
  1821. _proto.getScale = function getScale(name) {
  1822. var scales = this.scales;
  1823. var names = this.names;
  1824. var index = names.indexOf(name);
  1825. return scales[index];
  1826. }
  1827. /**
  1828. * 映射数据
  1829. * @param {*} param1...paramn 多个数值
  1830. * @return {Array} 映射的值组成的数组
  1831. */
  1832. ;
  1833. _proto.mapping = function mapping() {
  1834. var scales = this.scales;
  1835. var callback = this.callback;
  1836. for (var _len2 = arguments.length, params = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
  1837. params[_key2] = arguments[_key2];
  1838. }
  1839. var values = params;
  1840. if (callback) {
  1841. for (var i = 0, len = params.length; i < len; i++) {
  1842. params[i] = this._toOriginParam(params[i], scales[i]);
  1843. }
  1844. values = callback.apply(this, params);
  1845. }
  1846. values = [].concat(values);
  1847. return values;
  1848. } // 原始的参数
  1849. ;
  1850. _proto._toOriginParam = function _toOriginParam(param, scale) {
  1851. var rst = param;
  1852. if (!scale.isLinear) {
  1853. if (isArray$1(param)) {
  1854. rst = [];
  1855. for (var i = 0, len = param.length; i < len; i++) {
  1856. rst.push(toScaleString(scale, param[i]));
  1857. }
  1858. } else {
  1859. rst = toScaleString(scale, param);
  1860. }
  1861. }
  1862. return rst;
  1863. };
  1864. return AttributeBase;
  1865. }();
  1866. var Position = /*#__PURE__*/function (_Base) {
  1867. _inheritsLoose$3(Position, _Base);
  1868. function Position(cfg) {
  1869. var _this;
  1870. _this = _Base.call(this, cfg) || this;
  1871. _this.names = ['x', 'y'];
  1872. _this.type = 'position';
  1873. return _this;
  1874. }
  1875. var _proto = Position.prototype;
  1876. _proto.mapping = function mapping(x, y) {
  1877. var scales = this.scales;
  1878. var coord = this.coord;
  1879. var scaleX = scales[0];
  1880. var scaleY = scales[1];
  1881. var rstX;
  1882. var rstY;
  1883. var obj;
  1884. if (isNil$1(x) || isNil$1(y)) {
  1885. return [];
  1886. }
  1887. if (isArray$1(y) && isArray$1(x)) {
  1888. rstX = [];
  1889. rstY = [];
  1890. for (var i = 0, j = 0, xLen = x.length, yLen = y.length; i < xLen && j < yLen; i++, j++) {
  1891. obj = coord.convertPoint({
  1892. x: scaleX.scale(x[i]),
  1893. y: scaleY.scale(y[j])
  1894. });
  1895. rstX.push(obj.x);
  1896. rstY.push(obj.y);
  1897. }
  1898. } else if (isArray$1(y)) {
  1899. x = scaleX.scale(x);
  1900. rstY = [];
  1901. each$1(y, function (yVal) {
  1902. yVal = scaleY.scale(yVal);
  1903. obj = coord.convertPoint({
  1904. x: x,
  1905. y: yVal
  1906. });
  1907. if (rstX && rstX !== obj.x) {
  1908. if (!isArray$1(rstX)) {
  1909. rstX = [rstX];
  1910. }
  1911. rstX.push(obj.x);
  1912. } else {
  1913. rstX = obj.x;
  1914. }
  1915. rstY.push(obj.y);
  1916. });
  1917. } else if (isArray$1(x)) {
  1918. y = scaleY.scale(y);
  1919. rstX = [];
  1920. each$1(x, function (xVal) {
  1921. xVal = scaleX.scale(xVal);
  1922. obj = coord.convertPoint({
  1923. x: xVal,
  1924. y: y
  1925. });
  1926. if (rstY && rstY !== obj.y) {
  1927. if (!isArray$1(rstY)) {
  1928. rstY = [rstY];
  1929. }
  1930. rstY.push(obj.y);
  1931. } else {
  1932. rstY = obj.y;
  1933. }
  1934. rstX.push(obj.x);
  1935. });
  1936. } else {
  1937. x = scaleX.scale(x);
  1938. y = scaleY.scale(y);
  1939. var point = coord.convertPoint({
  1940. x: x,
  1941. y: y
  1942. });
  1943. rstX = point.x;
  1944. rstY = point.y;
  1945. }
  1946. return [rstX, rstY];
  1947. };
  1948. return Position;
  1949. }(AttributeBase);
  1950. var Shape$2 = /*#__PURE__*/function (_Base) {
  1951. _inheritsLoose$3(Shape, _Base);
  1952. function Shape(cfg) {
  1953. var _this;
  1954. _this = _Base.call(this, cfg) || this;
  1955. _this.names = ['shape'];
  1956. _this.type = 'shape';
  1957. _this.gradient = null;
  1958. return _this;
  1959. }
  1960. /**
  1961. * @override
  1962. */
  1963. var _proto = Shape.prototype;
  1964. _proto.getLinearValue = function getLinearValue(percent) {
  1965. var values = this.values;
  1966. var index = Math.round((values.length - 1) * percent);
  1967. return values[index];
  1968. };
  1969. return Shape;
  1970. }(AttributeBase);
  1971. var Size = /*#__PURE__*/function (_Base) {
  1972. _inheritsLoose$3(Size, _Base);
  1973. function Size(cfg) {
  1974. var _this;
  1975. _this = _Base.call(this, cfg) || this;
  1976. _this.names = ['size'];
  1977. _this.type = 'size';
  1978. _this.gradient = null;
  1979. return _this;
  1980. }
  1981. return Size;
  1982. }(AttributeBase);
  1983. function getValue(start, end, percent, index) {
  1984. var value = start[index] + (end[index] - start[index]) * percent;
  1985. return value;
  1986. } // convert to hex
  1987. function arr2hex(arr) {
  1988. return '#' + toRGBValue(arr[0]) + toRGBValue(arr[1]) + toRGBValue(arr[2]);
  1989. }
  1990. function toRGBValue(value) {
  1991. value = Math.round(value);
  1992. value = value.toString(16);
  1993. if (value.length === 1) {
  1994. value = '0' + value;
  1995. }
  1996. return value;
  1997. }
  1998. function calColor(colors, percent) {
  1999. var steps = colors.length - 1;
  2000. var step = Math.floor(steps * percent);
  2001. var left = steps * percent - step;
  2002. var start = colors[step];
  2003. var end = step === steps ? start : colors[step + 1];
  2004. var rgb = arr2hex([getValue(start, end, left, 0), getValue(start, end, left, 1), getValue(start, end, left, 2)]);
  2005. return rgb;
  2006. }
  2007. function hex2arr(str) {
  2008. var arr = [];
  2009. arr.push(parseInt(str.substr(1, 2), 16));
  2010. arr.push(parseInt(str.substr(3, 2), 16));
  2011. arr.push(parseInt(str.substr(5, 2), 16));
  2012. return arr;
  2013. }
  2014. var colorCache = {
  2015. black: '#000000',
  2016. blue: '#0000ff',
  2017. grey: '#808080',
  2018. green: '#008000',
  2019. orange: '#ffa500',
  2020. pink: '#ffc0cb',
  2021. purple: '#800080',
  2022. red: '#ff0000',
  2023. white: '#ffffff',
  2024. yellow: '#ffff00'
  2025. };
  2026. /**
  2027. * Returns a hexadecimal string representing this color in RGB space, such as #f7eaba.
  2028. * @param {String} color color value
  2029. * @return {String} Returns a hexadecimal string
  2030. */
  2031. function toHex(color) {
  2032. if (colorCache[color]) {
  2033. return colorCache[color];
  2034. }
  2035. if (color[0] === '#') {
  2036. if (color.length === 7) {
  2037. return color;
  2038. }
  2039. var hex = color.replace(/^#?([a-f\d])([a-f\d])([a-f\d])$/i, function (m, r, g, b) {
  2040. return '#' + r + r + g + g + b + b;
  2041. }); // hex3 to hex6
  2042. colorCache[color] = hex;
  2043. return hex;
  2044. } // rgb/rgba to hex
  2045. var rst = color.match(/^rgba?[\s+]?\([\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?/i);
  2046. rst.shift();
  2047. rst = arr2hex(rst);
  2048. colorCache[color] = rst;
  2049. return rst;
  2050. }
  2051. /**
  2052. * handle the gradient color
  2053. * @param {Array} colors the colors
  2054. * @return {String} return the color value
  2055. */
  2056. function gradient(colors) {
  2057. var points = [];
  2058. if (isString(colors)) {
  2059. colors = colors.split('-');
  2060. }
  2061. each$1(colors, function (color) {
  2062. if (color.indexOf('#') === -1) {
  2063. color = toHex(color);
  2064. }
  2065. points.push(hex2arr(color));
  2066. });
  2067. return function (percent) {
  2068. return calColor(points, percent);
  2069. };
  2070. }
  2071. var Color = /*#__PURE__*/function (_Base) {
  2072. _inheritsLoose$3(Color, _Base);
  2073. function Color(cfg) {
  2074. var _this;
  2075. _this = _Base.call(this, cfg) || this;
  2076. _this.names = ['color'];
  2077. _this.type = 'color';
  2078. _this.gradient = null;
  2079. if (isString(_this.values)) {
  2080. _this.linear = true;
  2081. }
  2082. return _this;
  2083. }
  2084. /**
  2085. * @override
  2086. */
  2087. var _proto = Color.prototype;
  2088. _proto.getLinearValue = function getLinearValue(percent) {
  2089. var gradient$1 = this.gradient;
  2090. if (!gradient$1) {
  2091. var values = this.values;
  2092. gradient$1 = gradient(values);
  2093. this.gradient = gradient$1;
  2094. }
  2095. return gradient$1(percent);
  2096. };
  2097. return Color;
  2098. }(AttributeBase);
  2099. var Attr = /*#__PURE__*/Object.freeze({
  2100. __proto__: null,
  2101. Position: Position,
  2102. Shape: Shape$2,
  2103. Size: Size,
  2104. Color: Color
  2105. });
  2106. var Shape$1 = {};
  2107. var ShapeBase = {
  2108. _coord: null,
  2109. /**
  2110. * draw the shape
  2111. * @param {Object} cfg options
  2112. * @param {Object} container container to store the shapes
  2113. */
  2114. draw: function draw(cfg, container) {
  2115. if (this.drawShape) {
  2116. this.drawShape(cfg, container);
  2117. }
  2118. },
  2119. /**
  2120. * set the coordinate instance
  2121. * @param {Coord} coord coordinate instance
  2122. */
  2123. setCoord: function setCoord(coord) {
  2124. this._coord = coord;
  2125. },
  2126. /**
  2127. * convert the normalized value to the canvas position
  2128. * @param {point} point the point to convert
  2129. * @return {point} point return the result
  2130. */
  2131. parsePoint: function parsePoint(point) {
  2132. var coord = this._coord;
  2133. if (coord.isPolar) {
  2134. if (point.x === 1) point.x = 0.9999999;
  2135. if (point.y === 1) point.y = 0.9999999;
  2136. }
  2137. return coord.convertPoint(point);
  2138. },
  2139. /**
  2140. * convert the normalized value to the canvas position
  2141. * @param {points} points the array that store the points
  2142. * @return {points} points return the result
  2143. */
  2144. parsePoints: function parsePoints(points) {
  2145. if (!points) return false;
  2146. var self = this;
  2147. var rst = [];
  2148. points.forEach(function (point) {
  2149. rst.push(self.parsePoint(point));
  2150. });
  2151. return rst;
  2152. }
  2153. };
  2154. var ShapeFactoryBase = {
  2155. defaultShapeType: null,
  2156. setCoord: function setCoord(coord) {
  2157. this._coord = coord;
  2158. },
  2159. getShape: function getShape(type) {
  2160. var self = this;
  2161. if (isArray$1(type)) {
  2162. type = type[0];
  2163. }
  2164. var shape = self[type] || self[self.defaultShapeType];
  2165. shape._coord = self._coord;
  2166. return shape;
  2167. },
  2168. getShapePoints: function getShapePoints(type, cfg) {
  2169. var shape = this.getShape(type);
  2170. var fn = shape.getPoints || shape.getShapePoints || this.getDefaultPoints;
  2171. var points = fn(cfg);
  2172. return points;
  2173. },
  2174. getDefaultPoints: function getDefaultPoints() {
  2175. return [];
  2176. },
  2177. drawShape: function drawShape(type, cfg, container) {
  2178. var shape = this.getShape(type);
  2179. if (!cfg.color) {
  2180. cfg.color = Global.colors[0];
  2181. }
  2182. return shape.draw(cfg, container);
  2183. }
  2184. };
  2185. Shape$1.registerFactory = function (factoryName, cfg) {
  2186. var className = upperFirst(factoryName);
  2187. var geomObj = mix$1({}, ShapeFactoryBase, cfg);
  2188. Shape$1[className] = geomObj;
  2189. geomObj.name = factoryName;
  2190. return geomObj;
  2191. };
  2192. Shape$1.registerShape = function (factoryName, shapeType, cfg) {
  2193. var className = upperFirst(factoryName);
  2194. var factory = Shape$1[className];
  2195. var shapeObj = mix$1({}, ShapeBase, cfg);
  2196. factory[shapeType] = shapeObj;
  2197. return shapeObj;
  2198. };
  2199. Shape$1.registShape = Shape$1.registerShape;
  2200. Shape$1.getShapeFactory = function (factoryName) {
  2201. var self = this;
  2202. factoryName = factoryName || 'point';
  2203. var className = upperFirst(factoryName);
  2204. return self[className];
  2205. };
  2206. function _mix(dist, obj) {
  2207. for (var key in obj) {
  2208. if (obj.hasOwnProperty(key) && key !== 'constructor' && obj[key] !== undefined) {
  2209. dist[key] = obj[key];
  2210. }
  2211. }
  2212. }
  2213. var mix = function mix(dist, src1, src2, src3) {
  2214. if (src1) _mix(dist, src1);
  2215. if (src2) _mix(dist, src2);
  2216. if (src3) _mix(dist, src3);
  2217. return dist;
  2218. };
  2219. var mix_1 = mix;
  2220. var Adjust = /*#__PURE__*/function () {
  2221. var _proto = Adjust.prototype;
  2222. _proto._initDefaultCfg = function _initDefaultCfg() {
  2223. this.adjustNames = ['x', 'y']; // 调整的维度,默认,x,y都做调整
  2224. };
  2225. function Adjust(cfg) {
  2226. this._initDefaultCfg();
  2227. mix_1(this, cfg);
  2228. }
  2229. /**
  2230. * @override
  2231. */
  2232. _proto.processAdjust = function processAdjust()
  2233. /* dataArray */
  2234. {};
  2235. return Adjust;
  2236. }();
  2237. var base = Adjust;
  2238. function generateScaleAria(scale) {
  2239. var type = scale.type,
  2240. values = scale.values;
  2241. if (type === 'linear') {
  2242. return substitute(lang.scale.linear, scale);
  2243. }
  2244. if (type === 'cat') {
  2245. return substitute(lang.scale.cat, {
  2246. values: values.slice(0, 10).join(' ')
  2247. });
  2248. }
  2249. if (type === 'timeCat') {
  2250. var start = scale.getText(values[0]);
  2251. var end = scale.getText(values[values.length - 1]);
  2252. return substitute(lang.scale.timeCat, {
  2253. start: start,
  2254. end: end
  2255. });
  2256. }
  2257. return '';
  2258. }
  2259. function generateCoordAria(coord, xScale, yScale) {
  2260. var type = coord.type;
  2261. if (!lang.coord[type]) {
  2262. return '';
  2263. }
  2264. return substitute(lang.coord[type], {
  2265. xLabel: generateScaleAria(xScale),
  2266. yLabel: generateScaleAria(yScale)
  2267. });
  2268. }
  2269. var GROUP_ATTRS = ['color', 'size', 'shape'];
  2270. var FIELD_ORIGIN = '_origin';
  2271. var FIELD_ORIGIN_Y = '_originY';
  2272. function parseFields(field) {
  2273. if (isArray$1(field)) {
  2274. return field;
  2275. }
  2276. if (isString(field)) {
  2277. return field.split('*');
  2278. }
  2279. return [field];
  2280. }
  2281. /**
  2282. * The parent class for Geometry
  2283. * @class Geom
  2284. */
  2285. var Geom = /*#__PURE__*/function (_Base) {
  2286. _inheritsLoose$3(Geom, _Base);
  2287. function Geom() {
  2288. return _Base.apply(this, arguments) || this;
  2289. }
  2290. var _proto = Geom.prototype;
  2291. _proto.getDefaultCfg = function getDefaultCfg() {
  2292. return {
  2293. /**
  2294. * geometry type
  2295. * @type {String}
  2296. */
  2297. type: null,
  2298. /**
  2299. * the data of geometry
  2300. * @type {Array}
  2301. */
  2302. data: null,
  2303. /**
  2304. * the attrs of geo,etry
  2305. * @type {Object}
  2306. */
  2307. attrs: {},
  2308. scales: {},
  2309. /**
  2310. * group for storing the shapes
  2311. * @type {Canvas}
  2312. */
  2313. container: null,
  2314. /**
  2315. * style options
  2316. * @type {Object}
  2317. */
  2318. styleOptions: null,
  2319. chart: null,
  2320. shapeType: '',
  2321. /**
  2322. * wether to generate key points for each shape
  2323. * @protected
  2324. * @type {Boolean}
  2325. */
  2326. generatePoints: false,
  2327. attrOptions: {},
  2328. sortable: false,
  2329. startOnZero: true,
  2330. visible: true,
  2331. connectNulls: false,
  2332. // 是否丢弃没有值的分组。
  2333. ignoreEmptyGroup: false,
  2334. // 是否已经初始化
  2335. isInit: false
  2336. };
  2337. };
  2338. _proto.init = function init() {
  2339. var self = this;
  2340. var isInit = self.get('isInit');
  2341. if (isInit) {
  2342. return;
  2343. }
  2344. self._initAttrs();
  2345. self._processData();
  2346. self.set('isInit', true);
  2347. };
  2348. _proto._getGroupScales = function _getGroupScales() {
  2349. var self = this;
  2350. var scales = [];
  2351. each$1(GROUP_ATTRS, function (attrName) {
  2352. var attr = self.getAttr(attrName);
  2353. if (attr) {
  2354. var attrScales = attr.scales;
  2355. each$1(attrScales, function (scale) {
  2356. if (scale && scale.isCategory && scales.indexOf(scale) === -1) {
  2357. scales.push(scale);
  2358. }
  2359. });
  2360. }
  2361. });
  2362. return scales;
  2363. };
  2364. _proto._groupData = function _groupData(data) {
  2365. var self = this;
  2366. var colDefs = self.get('colDefs');
  2367. var groupScales = self._getGroupScales();
  2368. if (groupScales.length) {
  2369. var appendConditions = {};
  2370. var names = [];
  2371. each$1(groupScales, function (scale) {
  2372. var field = scale.field;
  2373. names.push(field);
  2374. if (colDefs && colDefs[field] && colDefs[field].values) {
  2375. // users have defined
  2376. appendConditions[scale.field] = colDefs[field].values;
  2377. }
  2378. });
  2379. return group(data, names, appendConditions);
  2380. }
  2381. return [data];
  2382. };
  2383. _proto._setAttrOptions = function _setAttrOptions(attrName, attrCfg) {
  2384. var options = this.get('attrOptions');
  2385. options[attrName] = attrCfg;
  2386. var attrs = this.get('attrs'); // 说明已经初始化过了
  2387. if (Object.keys(attrs).length) {
  2388. this._createAttr(attrName, attrCfg);
  2389. }
  2390. };
  2391. _proto._createAttrOption = function _createAttrOption(attrName, field, cfg, defaultValues) {
  2392. var attrCfg = {};
  2393. attrCfg.field = field;
  2394. if (cfg) {
  2395. if (isFunction$1(cfg)) {
  2396. attrCfg.callback = cfg;
  2397. } else {
  2398. attrCfg.values = cfg;
  2399. }
  2400. } else {
  2401. attrCfg.values = defaultValues;
  2402. }
  2403. this._setAttrOptions(attrName, attrCfg);
  2404. };
  2405. _proto._createAttr = function _createAttr(type, option) {
  2406. var self = this;
  2407. var attrs = self.get('attrs');
  2408. var coord = self.get('coord');
  2409. var className = upperFirst(type);
  2410. var fields = parseFields(option.field);
  2411. if (type === 'position') {
  2412. option.coord = coord;
  2413. }
  2414. var scales = [];
  2415. for (var i = 0, len = fields.length; i < len; i++) {
  2416. var field = fields[i];
  2417. var scale = self._createScale(field);
  2418. scales.push(scale);
  2419. }
  2420. if (type === 'position') {
  2421. var yScale = scales[1]; // 饼图的处理,但是还不知道为啥
  2422. if (coord.type === 'polar' && coord.transposed && self.hasAdjust('stack')) {
  2423. if (yScale.values.length) {
  2424. yScale.change({
  2425. nice: false,
  2426. min: 0,
  2427. max: Math.max.apply(null, yScale.values)
  2428. });
  2429. }
  2430. }
  2431. }
  2432. option.scales = scales;
  2433. var attr = new Attr[className](option);
  2434. attrs[type] = attr;
  2435. return attr;
  2436. };
  2437. _proto._initAttrs = function _initAttrs() {
  2438. var self = this;
  2439. var attrOptions = self.get('attrOptions');
  2440. for (var type in attrOptions) {
  2441. if (attrOptions.hasOwnProperty(type)) {
  2442. this._createAttr(type, attrOptions[type]);
  2443. }
  2444. }
  2445. };
  2446. _proto._createScale = function _createScale(field) {
  2447. var scales = this.get('scales');
  2448. var scale = scales[field];
  2449. if (!scale) {
  2450. scale = this.get('chart').createScale(field);
  2451. scales[field] = scale;
  2452. }
  2453. return scale;
  2454. };
  2455. _proto._processData = function _processData() {
  2456. var self = this;
  2457. var data = this.get('data');
  2458. var dataArray = [];
  2459. var groupedArray = this._groupData(data);
  2460. if (this.get('ignoreEmptyGroup')) {
  2461. var yScale = this.getYScale();
  2462. groupedArray = groupedArray.filter(function (group) {
  2463. return group.some(function (item) {
  2464. return typeof item[yScale.field] !== 'undefined';
  2465. });
  2466. });
  2467. }
  2468. for (var i = 0, len = groupedArray.length; i < len; i++) {
  2469. var subData = groupedArray[i];
  2470. var tempData = self._saveOrigin(subData);
  2471. if (this.hasAdjust('dodge')) {
  2472. self._numberic(tempData);
  2473. }
  2474. dataArray.push(tempData);
  2475. }
  2476. if (self.get('adjust')) {
  2477. self._adjustData(dataArray);
  2478. }
  2479. if (self.get('sortable')) {
  2480. self._sort(dataArray);
  2481. }
  2482. self.emit('afterprocessdata', {
  2483. dataArray: dataArray
  2484. });
  2485. self.set('mappingData', dataArray);
  2486. self.set('dataArray', dataArray);
  2487. return dataArray;
  2488. };
  2489. _proto._saveOrigin = function _saveOrigin(data) {
  2490. var rst = [];
  2491. for (var i = 0, len = data.length; i < len; i++) {
  2492. var origin = data[i];
  2493. var obj = {};
  2494. for (var k in origin) {
  2495. obj[k] = origin[k];
  2496. }
  2497. obj[FIELD_ORIGIN] = origin;
  2498. rst.push(obj);
  2499. }
  2500. return rst;
  2501. };
  2502. _proto._numberic = function _numberic(data) {
  2503. var positionAttr = this.getAttr('position');
  2504. var scales = positionAttr.scales;
  2505. for (var j = 0, len = data.length; j < len; j++) {
  2506. var obj = data[j];
  2507. var count = Math.min(2, scales.length);
  2508. for (var i = 0; i < count; i++) {
  2509. var scale = scales[i];
  2510. if (scale.isCategory) {
  2511. var field = scale.field;
  2512. obj[field] = scale.translate(obj[field]);
  2513. }
  2514. }
  2515. }
  2516. };
  2517. _proto._adjustData = function _adjustData(dataArray) {
  2518. var self = this;
  2519. var adjust = self.get('adjust');
  2520. if (adjust) {
  2521. var adjustType = upperFirst(adjust.type);
  2522. if (!base[adjustType]) {
  2523. throw new Error('not support such adjust : ' + adjust);
  2524. }
  2525. var xScale = self.getXScale();
  2526. var yScale = self.getYScale();
  2527. var cfg = mix$1({
  2528. xField: xScale.field,
  2529. yField: yScale.field
  2530. }, adjust);
  2531. var adjustObject = new base[adjustType](cfg);
  2532. adjustObject.processAdjust(dataArray);
  2533. if (adjustType === 'Stack') {
  2534. self._updateStackRange(yScale.field, yScale, dataArray);
  2535. }
  2536. }
  2537. };
  2538. _proto._updateStackRange = function _updateStackRange(field, scale, dataArray) {
  2539. var mergeArray = merge$1(dataArray);
  2540. var min = scale.min;
  2541. var max = scale.max;
  2542. for (var i = 0, len = mergeArray.length; i < len; i++) {
  2543. var obj = mergeArray[i];
  2544. var tmpMin = Math.min.apply(null, obj[field]);
  2545. var tmpMax = Math.max.apply(null, obj[field]);
  2546. if (tmpMin < min) {
  2547. min = tmpMin;
  2548. }
  2549. if (tmpMax > max) {
  2550. max = tmpMax;
  2551. }
  2552. }
  2553. if (min < scale.min || max > scale.max) {
  2554. scale.change({
  2555. min: min,
  2556. max: max
  2557. });
  2558. }
  2559. };
  2560. _proto._sort = function _sort(mappedArray) {
  2561. var self = this;
  2562. var xScale = self.getXScale();
  2563. var field = xScale.field,
  2564. type = xScale.type;
  2565. if (type !== 'identity' && xScale.values.length > 1) {
  2566. each$1(mappedArray, function (itemArr) {
  2567. itemArr.sort(function (obj1, obj2) {
  2568. if (type === 'timeCat') {
  2569. return toTimeStamp$1(obj1[FIELD_ORIGIN][field]) - toTimeStamp$1(obj2[FIELD_ORIGIN][field]);
  2570. }
  2571. return xScale.translate(obj1[FIELD_ORIGIN][field]) - xScale.translate(obj2[FIELD_ORIGIN][field]);
  2572. });
  2573. });
  2574. }
  2575. self.set('hasSorted', true);
  2576. self.set('dataArray', mappedArray);
  2577. };
  2578. _proto.paint = function paint() {
  2579. var self = this;
  2580. var dataArray = self.get('mappingData');
  2581. var mappedArray = [];
  2582. var shapeFactory = self.getShapeFactory();
  2583. shapeFactory.setCoord(self.get('coord'));
  2584. self._beforeMapping(dataArray);
  2585. for (var i = 0, len = dataArray.length; i < len; i++) {
  2586. var data = dataArray[i];
  2587. if (data.length) {
  2588. var mappedData = self._mapping(data);
  2589. mappedArray.push(mappedData);
  2590. self.draw(mappedData, shapeFactory);
  2591. }
  2592. }
  2593. self.set('dataArray', mappedArray);
  2594. this.generateAria();
  2595. };
  2596. _proto.getShapeFactory = function getShapeFactory() {
  2597. var shapeFactory = this.get('shapeFactory');
  2598. if (!shapeFactory) {
  2599. var shapeType = this.get('shapeType');
  2600. shapeFactory = Shape$1.getShapeFactory(shapeType);
  2601. this.set('shapeFactory', shapeFactory);
  2602. }
  2603. return shapeFactory;
  2604. };
  2605. _proto._mapping = function _mapping(data) {
  2606. var self = this;
  2607. var attrs = self.get('attrs');
  2608. var yField = self.getYScale().field; // 用来缓存转换的值,减少mapping耗时
  2609. var mappedCache = {};
  2610. var mappedData = new Array(data.length);
  2611. for (var k in attrs) {
  2612. if (attrs.hasOwnProperty(k)) {
  2613. var attr = attrs[k];
  2614. var names = attr.names;
  2615. var scales = attr.scales;
  2616. for (var i = 0, len = data.length; i < len; i++) {
  2617. var record = data[i];
  2618. var mappedRecord = _extends({}, record, mappedData[i]);
  2619. mappedRecord[FIELD_ORIGIN_Y] = record[yField]; // 获取视觉属性对应的value值
  2620. // 位置的缓存命中率低,还是每次单独计算
  2621. if (attr.type === 'position') {
  2622. var values = self._getAttrValues(attr, record);
  2623. for (var j = 0, _len = values.length; j < _len; j++) {
  2624. var val = values[j];
  2625. var name = names[j];
  2626. mappedRecord[name] = isArray$1(val) && val.length === 1 ? val[0] : val;
  2627. }
  2628. } else {
  2629. // 除了position其他都只有一项
  2630. var _name = names[0];
  2631. var field = scales[0].field;
  2632. var value = record[field];
  2633. var key = "" + _name + value;
  2634. var _values = mappedCache[key];
  2635. if (!_values) {
  2636. _values = self._getAttrValues(attr, record);
  2637. mappedCache[key] = _values;
  2638. }
  2639. mappedRecord[_name] = _values[0];
  2640. } // 设置新数组
  2641. mappedData[i] = mappedRecord;
  2642. }
  2643. }
  2644. }
  2645. return mappedData;
  2646. };
  2647. _proto._getAttrValues = function _getAttrValues(attr, record) {
  2648. var scales = attr.scales;
  2649. var params = [];
  2650. for (var i = 0, len = scales.length; i < len; i++) {
  2651. var scale = scales[i];
  2652. var field = scale.field;
  2653. if (scale.type === 'identity') {
  2654. params.push(scale.value);
  2655. } else {
  2656. params.push(record[field]);
  2657. }
  2658. }
  2659. var values = attr.mapping.apply(attr, params);
  2660. return values;
  2661. };
  2662. _proto.getAttrValue = function getAttrValue(attrName, record) {
  2663. var attr = this.getAttr(attrName);
  2664. var rst = null;
  2665. if (attr) {
  2666. var values = this._getAttrValues(attr, record);
  2667. rst = values[0];
  2668. }
  2669. return rst;
  2670. };
  2671. _proto._beforeMapping = function _beforeMapping(dataArray) {
  2672. var self = this;
  2673. if (self.get('generatePoints')) {
  2674. self._generatePoints(dataArray);
  2675. }
  2676. };
  2677. _proto.isInCircle = function isInCircle() {
  2678. var coord = this.get('coord');
  2679. return coord && coord.isPolar;
  2680. };
  2681. _proto.getCallbackCfg = function getCallbackCfg(fields, cfg, origin) {
  2682. if (!fields) {
  2683. return cfg;
  2684. }
  2685. var tmpCfg = {};
  2686. var params = fields.map(function (field) {
  2687. return origin[field];
  2688. });
  2689. each$1(cfg, function (v, k) {
  2690. if (isFunction$1(v)) {
  2691. tmpCfg[k] = v.apply(null, params);
  2692. } else {
  2693. tmpCfg[k] = v;
  2694. }
  2695. });
  2696. return tmpCfg;
  2697. };
  2698. _proto.getDrawCfg = function getDrawCfg(obj) {
  2699. var self = this;
  2700. var isInCircle = self.isInCircle();
  2701. var cfg = {
  2702. origin: obj,
  2703. x: obj.x,
  2704. y: obj.y,
  2705. color: obj.color,
  2706. size: obj.size,
  2707. shape: obj.shape,
  2708. isInCircle: isInCircle,
  2709. opacity: obj.opacity
  2710. };
  2711. var styleOptions = self.get('styleOptions');
  2712. if (styleOptions && styleOptions.style) {
  2713. cfg.style = self.getCallbackCfg(styleOptions.fields, styleOptions.style, obj[FIELD_ORIGIN]);
  2714. }
  2715. if (self.get('generatePoints')) {
  2716. cfg.points = obj.points;
  2717. cfg.nextPoints = obj.nextPoints;
  2718. }
  2719. if (isInCircle) {
  2720. cfg.center = self.get('coord').center;
  2721. }
  2722. return cfg;
  2723. };
  2724. _proto.draw = function draw(data, shapeFactory) {
  2725. var self = this;
  2726. var container = self.get('container');
  2727. var yScale = self.getYScale();
  2728. each$1(data, function (obj, index) {
  2729. if (yScale && isNil$1(obj._origin[yScale.field])) {
  2730. return;
  2731. }
  2732. obj.index = index;
  2733. var cfg = self.getDrawCfg(obj);
  2734. var shape = obj.shape;
  2735. self.drawShape(shape, obj, cfg, container, shapeFactory);
  2736. });
  2737. };
  2738. _proto.drawShape = function drawShape(shape, shapeData, cfg, container, shapeFactory) {
  2739. var gShape = shapeFactory.drawShape(shape, cfg, container);
  2740. if (gShape) {
  2741. each$1([].concat(gShape), function (s) {
  2742. s.set('origin', shapeData);
  2743. });
  2744. }
  2745. };
  2746. _proto._generatePoints = function _generatePoints(dataArray) {
  2747. var self = this;
  2748. var shapeFactory = self.getShapeFactory();
  2749. var shapeAttr = self.getAttr('shape');
  2750. each$1(dataArray, function (data) {
  2751. for (var i = 0, len = data.length; i < len; i++) {
  2752. var obj = data[i];
  2753. var cfg = self.createShapePointsCfg(obj);
  2754. var shape = shapeAttr ? self._getAttrValues(shapeAttr, obj) : null;
  2755. var points = shapeFactory.getShapePoints(shape, cfg);
  2756. obj.points = points;
  2757. }
  2758. }); // 添加nextPoints
  2759. each$1(dataArray, function (data, index) {
  2760. var nextData = dataArray[index + 1];
  2761. if (nextData) {
  2762. data[0].nextPoints = nextData[0].points;
  2763. }
  2764. });
  2765. } // 生成无障碍文本
  2766. ;
  2767. _proto.generateAria = function generateAria() {
  2768. var container = this.get('container');
  2769. var aria = container.get('aria');
  2770. if (!aria) {
  2771. return;
  2772. }
  2773. var ariaLables = [];
  2774. var coord = this.get('coord');
  2775. var xScale = this.getXScale();
  2776. var yScale = this.getYScale();
  2777. var coordAriaLabel = generateCoordAria(coord, xScale, yScale);
  2778. ariaLables.push(coordAriaLabel);
  2779. var _lang$geometry = lang.geometry,
  2780. prefix = _lang$geometry.prefix,
  2781. oneData = _lang$geometry.oneData,
  2782. partData = _lang$geometry.partData,
  2783. allData = _lang$geometry.allData;
  2784. var dataArray = this.get('dataArray');
  2785. var count = dataArray.length; // 只处理一个,不然太复杂
  2786. var groupScale = this._getGroupScales()[0];
  2787. if (groupScale) {
  2788. var prefixLabel = substitute(prefix, {
  2789. count: count
  2790. });
  2791. ariaLables.push(prefixLabel);
  2792. each$1(dataArray, function (data, index) {
  2793. var len = data.length;
  2794. if (!len) return;
  2795. var firstObj = data[0]._origin;
  2796. if (len === 1) {
  2797. ariaLables.push(substitute(oneData, {
  2798. index: index + 1,
  2799. count: len,
  2800. name: firstObj[groupScale.field],
  2801. values: firstObj[yScale.field]
  2802. }));
  2803. } else {
  2804. var template = len > 5 ? partData : allData;
  2805. var values = data.slice(0, 5).map(function (record) {
  2806. var _origin = record._origin;
  2807. var xValue = xScale.getText(_origin[xScale.field]);
  2808. var yValue = yScale.getText(_origin[yScale.field]);
  2809. return xValue + ":" + yValue;
  2810. });
  2811. ariaLables.push(substitute(template, {
  2812. index: index + 1,
  2813. count: len,
  2814. part: 3,
  2815. name: firstObj[groupScale.field],
  2816. values: values.join(' ')
  2817. }));
  2818. }
  2819. });
  2820. }
  2821. container.set('ariaLabel', ariaLables.join(''));
  2822. }
  2823. /**
  2824. * get the info of each shape
  2825. * @protected
  2826. * @param {Object} obj the data item
  2827. * @return {Object} cfg return the result
  2828. */
  2829. ;
  2830. _proto.createShapePointsCfg = function createShapePointsCfg(obj) {
  2831. var xScale = this.getXScale();
  2832. var yScale = this.getYScale();
  2833. var x = this._normalizeValues(obj[xScale.field], xScale);
  2834. var y;
  2835. if (yScale) {
  2836. y = this._normalizeValues(obj[yScale.field], yScale);
  2837. } else {
  2838. y = obj.y ? obj.y : 0.1;
  2839. }
  2840. return {
  2841. x: x,
  2842. y: y,
  2843. y0: yScale ? yScale.scale(this.getYMinValue()) : undefined
  2844. };
  2845. };
  2846. _proto.getYMinValue = function getYMinValue() {
  2847. var yScale = this.getYScale();
  2848. var min = yScale.min,
  2849. max = yScale.max;
  2850. var value;
  2851. if (this.get('startOnZero')) {
  2852. if (max <= 0 && min <= 0) {
  2853. value = max;
  2854. } else {
  2855. value = min >= 0 ? min : 0;
  2856. }
  2857. } else {
  2858. value = min;
  2859. }
  2860. return value;
  2861. };
  2862. _proto._normalizeValues = function _normalizeValues(values, scale) {
  2863. var rst = [];
  2864. if (isArray$1(values)) {
  2865. for (var i = 0, len = values.length; i < len; i++) {
  2866. var v = values[i];
  2867. rst.push(scale.scale(v));
  2868. }
  2869. } else {
  2870. rst = scale.scale(values);
  2871. }
  2872. return rst;
  2873. };
  2874. _proto.getAttr = function getAttr(name) {
  2875. return this.get('attrs')[name];
  2876. };
  2877. _proto.getXScale = function getXScale() {
  2878. return this.getAttr('position').scales[0];
  2879. };
  2880. _proto.getYScale = function getYScale() {
  2881. return this.getAttr('position').scales[1];
  2882. };
  2883. _proto.hasAdjust = function hasAdjust(adjust) {
  2884. return this.get('adjust') && this.get('adjust').type === adjust;
  2885. };
  2886. _proto._getSnap = function _getSnap(scale, item, arr) {
  2887. var i = 0;
  2888. var values;
  2889. var yField = this.getYScale().field; // 叠加的维度
  2890. if (this.hasAdjust('stack') && scale.field === yField) {
  2891. values = [];
  2892. arr.forEach(function (obj) {
  2893. values.push(obj[FIELD_ORIGIN_Y]);
  2894. });
  2895. for (var len = values.length; i < len; i++) {
  2896. if (values[0][0] > item) {
  2897. break;
  2898. }
  2899. if (values[values.length - 1][1] <= item) {
  2900. i = values.length - 1;
  2901. break;
  2902. }
  2903. if (values[i][0] <= item && values[i][1] > item) {
  2904. break;
  2905. }
  2906. }
  2907. } else {
  2908. values = scale.values;
  2909. values.sort(function (a, b) {
  2910. return a - b;
  2911. });
  2912. for (var _len2 = values.length; i < _len2; i++) {
  2913. // 如果只有1个点直接返回第1个点
  2914. if (_len2 <= 1) {
  2915. break;
  2916. } // 第1个点和第2个点之间
  2917. if ((values[0] + values[1]) / 2 > item) {
  2918. break;
  2919. } // 中间的点
  2920. if ((values[i - 1] + values[i]) / 2 <= item && (values[i + 1] + values[i]) / 2 > item) {
  2921. break;
  2922. } // 最后2个点
  2923. if ((values[values.length - 2] + values[values.length - 1]) / 2 <= item) {
  2924. i = values.length - 1;
  2925. break;
  2926. }
  2927. }
  2928. }
  2929. var result = values[i];
  2930. return result;
  2931. };
  2932. _proto.getSnapRecords = function getSnapRecords(point) {
  2933. var self = this;
  2934. var coord = self.get('coord');
  2935. var xScale = self.getXScale();
  2936. var yScale = self.getYScale();
  2937. var xfield = xScale.field;
  2938. var dataArray = self.get('dataArray');
  2939. if (!this.get('hasSorted')) {
  2940. this._sort(dataArray);
  2941. }
  2942. var rst = [];
  2943. var invertPoint = coord.invertPoint(point);
  2944. var invertPointX = invertPoint.x;
  2945. if (self.isInCircle() && !coord.transposed && invertPointX > (1 + xScale.rangeMax()) / 2) {
  2946. invertPointX = xScale.rangeMin();
  2947. }
  2948. var xValue = xScale.invert(invertPointX);
  2949. if (!xScale.isCategory) {
  2950. xValue = self._getSnap(xScale, xValue);
  2951. }
  2952. var tmp = [];
  2953. dataArray.forEach(function (data) {
  2954. data.forEach(function (obj) {
  2955. var originValue = isNil$1(obj[FIELD_ORIGIN]) ? obj[xfield] : obj[FIELD_ORIGIN][xfield];
  2956. if (self._isEqual(originValue, xValue, xScale)) {
  2957. tmp.push(obj);
  2958. }
  2959. });
  2960. }); // special for pie chart
  2961. if (this.hasAdjust('stack') && coord.isPolar && coord.transposed) {
  2962. if (invertPointX >= 0 && invertPointX <= 1) {
  2963. var yValue = yScale.invert(invertPoint.y);
  2964. yValue = self._getSnap(yScale, yValue, tmp);
  2965. tmp.forEach(function (obj) {
  2966. if (isArray$1(yValue) ? obj[FIELD_ORIGIN_Y].toString() === yValue.toString() : obj[FIELD_ORIGIN_Y] === yValue) {
  2967. rst.push(obj);
  2968. }
  2969. });
  2970. }
  2971. } else {
  2972. rst = tmp;
  2973. }
  2974. return rst;
  2975. };
  2976. _proto.getRecords = function getRecords(value) {
  2977. var _this = this;
  2978. var xScale = this.getXScale();
  2979. var dataArray = this.get('dataArray');
  2980. var xfield = xScale.field;
  2981. return dataArray.map(function (data) {
  2982. for (var len = data.length, i = len - 1; i >= 0; i--) {
  2983. var obj = data[i];
  2984. var originValue = isNil$1(obj[FIELD_ORIGIN]) ? obj[xfield] : obj[FIELD_ORIGIN][xfield];
  2985. if (_this._isEqual(originValue, value, xScale)) {
  2986. return obj;
  2987. }
  2988. }
  2989. return null;
  2990. });
  2991. };
  2992. _proto._isEqual = function _isEqual(originValue, value, scale) {
  2993. if (scale.type === 'timeCat') {
  2994. return toTimeStamp$1(originValue) === value;
  2995. }
  2996. return value === originValue;
  2997. };
  2998. _proto.position = function position(field) {
  2999. this._setAttrOptions('position', {
  3000. field: field
  3001. });
  3002. return this;
  3003. };
  3004. _proto.color = function color(field, values) {
  3005. this._createAttrOption('color', field, values, Global.colors);
  3006. return this;
  3007. };
  3008. _proto.size = function size(field, values) {
  3009. this._createAttrOption('size', field, values, Global.sizes);
  3010. return this;
  3011. };
  3012. _proto.shape = function shape(field, values) {
  3013. var type = this.get('type');
  3014. var shapes = Global.shapes[type] || [];
  3015. this._createAttrOption('shape', field, values, shapes);
  3016. return this;
  3017. };
  3018. _proto.style = function style(field, cfg) {
  3019. var styleOptions = this.get('styleOptions');
  3020. if (!styleOptions) {
  3021. styleOptions = {};
  3022. this.set('styleOptions', styleOptions);
  3023. }
  3024. if (isObject$1(field)) {
  3025. cfg = field;
  3026. field = null;
  3027. }
  3028. var fields;
  3029. if (field) {
  3030. fields = parseFields(field);
  3031. }
  3032. styleOptions.fields = fields;
  3033. styleOptions.style = cfg;
  3034. return this;
  3035. };
  3036. _proto.adjust = function adjust(type) {
  3037. if (isString(type)) {
  3038. type = {
  3039. type: type
  3040. };
  3041. }
  3042. this.set('adjust', type);
  3043. return this;
  3044. };
  3045. _proto.animate = function animate(cfg) {
  3046. this.set('animateCfg', cfg);
  3047. return this;
  3048. };
  3049. _proto.changeData = function changeData(data) {
  3050. this.set('data', data); // 改变数据后,情况度量,因为需要重新实例化
  3051. this.set('scales', {});
  3052. if (!this.get('isInit')) return;
  3053. this.set('isInit', false);
  3054. this.init();
  3055. };
  3056. _proto.clearInner = function clearInner() {
  3057. var container = this.get('container');
  3058. if (container) {
  3059. container.clear(); // container.setMatrix([ 1, 0, 0, 1, 0, 0 ]);
  3060. }
  3061. };
  3062. _proto.reset = function reset() {
  3063. this.set('isInit', false);
  3064. this.set('attrs', {});
  3065. this.set('attrOptions', {});
  3066. this.set('adjust', null);
  3067. this.clearInner();
  3068. };
  3069. _proto.clear = function clear() {
  3070. this.clearInner();
  3071. };
  3072. _proto.destroy = function destroy() {
  3073. this.set('isInit', false);
  3074. this.clear();
  3075. _Base.prototype.destroy.call(this);
  3076. };
  3077. _proto._display = function _display(visible) {
  3078. this.set('visible', visible);
  3079. var container = this.get('container');
  3080. var canvas = container.get('canvas');
  3081. container.set('visible', visible);
  3082. canvas.draw();
  3083. };
  3084. _proto.show = function show() {
  3085. this._display(true);
  3086. };
  3087. _proto.hide = function hide() {
  3088. this._display(false);
  3089. };
  3090. return Geom;
  3091. }(Base$2);
  3092. var methodCache = {};
  3093. /**
  3094. * 获取计算 ticks 的方法
  3095. * @param key 键值
  3096. * @returns 计算 ticks 的方法
  3097. */
  3098. function getTickMethod(key) {
  3099. return methodCache[key];
  3100. }
  3101. /**
  3102. * 注册计算 ticks 的方法
  3103. * @param key 键值
  3104. * @param method 方法
  3105. */
  3106. function registerTickMethod(key, method) {
  3107. methodCache[key] = method;
  3108. }
  3109. var Scale = function () {
  3110. function Scale(cfg) {
  3111. /**
  3112. * 度量的类型
  3113. */
  3114. this.type = 'base';
  3115. /**
  3116. * 是否分类类型的度量
  3117. */
  3118. this.isCategory = false;
  3119. /**
  3120. * 是否线性度量,有linear, time 度量
  3121. */
  3122. this.isLinear = false;
  3123. /**
  3124. * 是否连续类型的度量,linear,time,log, pow, quantile, quantize 都支持
  3125. */
  3126. this.isContinuous = false;
  3127. /**
  3128. * 是否是常量的度量,传入和传出一致
  3129. */
  3130. this.isIdentity = false;
  3131. this.values = [];
  3132. this.range = [0, 1];
  3133. this.ticks = [];
  3134. this.__cfg__ = cfg;
  3135. this.initCfg();
  3136. this.init();
  3137. } // 对于原始值的必要转换,如分类、时间字段需转换成数值,用transform/map命名可能更好
  3138. Scale.prototype.translate = function (v) {
  3139. return v;
  3140. };
  3141. /** 重新初始化 */
  3142. Scale.prototype.change = function (cfg) {
  3143. // 覆盖配置项,而不替代
  3144. mix$1(this.__cfg__, cfg);
  3145. this.init();
  3146. };
  3147. Scale.prototype.clone = function () {
  3148. return this.constructor(this.__cfg__);
  3149. };
  3150. /** 获取坐标轴需要的ticks */
  3151. Scale.prototype.getTicks = function () {
  3152. var _this = this;
  3153. return map$1(this.ticks, function (tick, idx) {
  3154. if (isObject$1(tick)) {
  3155. // 仅当符合Tick类型时才有意义
  3156. return tick;
  3157. }
  3158. return {
  3159. text: _this.getText(tick, idx),
  3160. tickValue: tick,
  3161. value: _this.scale(tick)
  3162. };
  3163. });
  3164. };
  3165. /** 获取Tick的格式化结果 */
  3166. Scale.prototype.getText = function (value, key) {
  3167. var formatter = this.formatter;
  3168. var res = formatter ? formatter(value, key) : value;
  3169. if (isNil$1(res) || !isFunction$1(res.toString)) {
  3170. return '';
  3171. }
  3172. return res.toString();
  3173. }; // 获取配置项中的值,当前 scale 上的值可能会被修改
  3174. Scale.prototype.getConfig = function (key) {
  3175. return this.__cfg__[key];
  3176. }; // scale初始化
  3177. Scale.prototype.init = function () {
  3178. mix$1(this, this.__cfg__);
  3179. this.setDomain();
  3180. if (isEmpty(this.getConfig('ticks'))) {
  3181. this.ticks = this.calculateTicks();
  3182. }
  3183. }; // 子类上覆盖某些属性,不能直接在类上声明,否则会被覆盖
  3184. Scale.prototype.initCfg = function () {};
  3185. Scale.prototype.setDomain = function () {};
  3186. Scale.prototype.calculateTicks = function () {
  3187. var tickMethod = this.tickMethod;
  3188. var ticks = [];
  3189. if (isString(tickMethod)) {
  3190. var method = getTickMethod(tickMethod);
  3191. if (!method) {
  3192. throw new Error('There is no method to to calculate ticks!');
  3193. }
  3194. ticks = method(this);
  3195. } else if (isFunction$1(tickMethod)) {
  3196. ticks = tickMethod(this);
  3197. }
  3198. return ticks;
  3199. }; // range 的最小值
  3200. Scale.prototype.rangeMin = function () {
  3201. return this.range[0];
  3202. }; // range 的最大值
  3203. Scale.prototype.rangeMax = function () {
  3204. return this.range[1];
  3205. };
  3206. /** 定义域转 0~1 */
  3207. Scale.prototype.calcPercent = function (value, min, max) {
  3208. if (isNumber(value)) {
  3209. return (value - min) / (max - min);
  3210. }
  3211. return NaN;
  3212. };
  3213. /** 0~1转定义域 */
  3214. Scale.prototype.calcValue = function (percent, min, max) {
  3215. return min + percent * (max - min);
  3216. };
  3217. return Scale;
  3218. }();
  3219. /**
  3220. * 分类度量
  3221. * @class
  3222. */
  3223. var Category$1 = function (_super) {
  3224. __extends(Category, _super);
  3225. function Category() {
  3226. var _this = _super !== null && _super.apply(this, arguments) || this;
  3227. _this.type = 'cat';
  3228. _this.isCategory = true;
  3229. return _this;
  3230. }
  3231. Category.prototype.buildIndexMap = function () {
  3232. if (!this.translateIndexMap) {
  3233. this.translateIndexMap = new Map(); // 重新构建缓存
  3234. for (var i = 0; i < this.values.length; i++) {
  3235. this.translateIndexMap.set(this.values[i], i);
  3236. }
  3237. }
  3238. };
  3239. Category.prototype.translate = function (value) {
  3240. // 按需构建 map
  3241. this.buildIndexMap(); // 找得到
  3242. var idx = this.translateIndexMap.get(value);
  3243. if (idx === undefined) {
  3244. idx = isNumber(value) ? value : NaN;
  3245. }
  3246. return idx;
  3247. };
  3248. Category.prototype.scale = function (value) {
  3249. var order = this.translate(value); // 分类数据允许 0.5 范围内调整
  3250. // if (order < this.min - 0.5 || order > this.max + 0.5) {
  3251. // return NaN;
  3252. // }
  3253. var percent = this.calcPercent(order, this.min, this.max);
  3254. return this.calcValue(percent, this.rangeMin(), this.rangeMax());
  3255. };
  3256. Category.prototype.invert = function (scaledValue) {
  3257. var domainRange = this.max - this.min;
  3258. var percent = this.calcPercent(scaledValue, this.rangeMin(), this.rangeMax());
  3259. var idx = Math.round(domainRange * percent) + this.min;
  3260. if (idx < this.min || idx > this.max) {
  3261. return NaN;
  3262. }
  3263. return this.values[idx];
  3264. };
  3265. Category.prototype.getText = function (value) {
  3266. var args = [];
  3267. for (var _i = 1; _i < arguments.length; _i++) {
  3268. args[_i - 1] = arguments[_i];
  3269. }
  3270. var v = value; // value为index
  3271. if (isNumber(value) && !this.values.includes(value)) {
  3272. v = this.values[v];
  3273. }
  3274. return _super.prototype.getText.apply(this, __spreadArrays([v], args));
  3275. }; // 复写属性
  3276. Category.prototype.initCfg = function () {
  3277. this.tickMethod = 'cat';
  3278. }; // 设置 min, max
  3279. Category.prototype.setDomain = function () {
  3280. // 用户有可能设置 min
  3281. if (isNil$1(this.getConfig('min'))) {
  3282. this.min = 0;
  3283. }
  3284. if (isNil$1(this.getConfig('max'))) {
  3285. var size = this.values.length;
  3286. this.max = size > 1 ? size - 1 : size;
  3287. } // scale.init 的时候清除缓存
  3288. if (this.translateIndexMap) {
  3289. this.translateIndexMap = undefined;
  3290. }
  3291. };
  3292. return Category;
  3293. }(Scale);
  3294. var token = /d{1,4}|M{1,4}|YY(?:YY)?|S{1,3}|Do|ZZ|Z|([HhMsDm])\1?|[aA]|"[^"]*"|'[^']*'/g;
  3295. var twoDigitsOptional = "[1-9]\\d?";
  3296. var twoDigits = "\\d\\d";
  3297. var threeDigits = "\\d{3}";
  3298. var fourDigits = "\\d{4}";
  3299. var word = "[^\\s]+";
  3300. var literal = /\[([^]*?)\]/gm;
  3301. function shorten(arr, sLen) {
  3302. var newArr = [];
  3303. for (var i = 0, len = arr.length; i < len; i++) {
  3304. newArr.push(arr[i].substr(0, sLen));
  3305. }
  3306. return newArr;
  3307. }
  3308. var monthUpdate = function (arrName) {
  3309. return function (v, i18n) {
  3310. var lowerCaseArr = i18n[arrName].map(function (v) {
  3311. return v.toLowerCase();
  3312. });
  3313. var index = lowerCaseArr.indexOf(v.toLowerCase());
  3314. if (index > -1) {
  3315. return index;
  3316. }
  3317. return null;
  3318. };
  3319. };
  3320. function assign(origObj) {
  3321. var args = [];
  3322. for (var _i = 1; _i < arguments.length; _i++) {
  3323. args[_i - 1] = arguments[_i];
  3324. }
  3325. for (var _a = 0, args_1 = args; _a < args_1.length; _a++) {
  3326. var obj = args_1[_a];
  3327. for (var key in obj) {
  3328. // @ts-ignore ex
  3329. origObj[key] = obj[key];
  3330. }
  3331. }
  3332. return origObj;
  3333. }
  3334. var dayNames = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
  3335. var monthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
  3336. var monthNamesShort = shorten(monthNames, 3);
  3337. var dayNamesShort = shorten(dayNames, 3);
  3338. var defaultI18n = {
  3339. dayNamesShort: dayNamesShort,
  3340. dayNames: dayNames,
  3341. monthNamesShort: monthNamesShort,
  3342. monthNames: monthNames,
  3343. amPm: ["am", "pm"],
  3344. DoFn: function (dayOfMonth) {
  3345. return dayOfMonth + ["th", "st", "nd", "rd"][dayOfMonth % 10 > 3 ? 0 : (dayOfMonth - dayOfMonth % 10 !== 10 ? 1 : 0) * dayOfMonth % 10];
  3346. }
  3347. };
  3348. var globalI18n = assign({}, defaultI18n);
  3349. var setGlobalDateI18n = function (i18n) {
  3350. return globalI18n = assign(globalI18n, i18n);
  3351. };
  3352. var regexEscape = function (str) {
  3353. return str.replace(/[|\\{()[^$+*?.-]/g, "\\$&");
  3354. };
  3355. var pad = function (val, len) {
  3356. if (len === void 0) {
  3357. len = 2;
  3358. }
  3359. val = String(val);
  3360. while (val.length < len) {
  3361. val = "0" + val;
  3362. }
  3363. return val;
  3364. };
  3365. var formatFlags = {
  3366. D: function (dateObj) {
  3367. return String(dateObj.getDate());
  3368. },
  3369. DD: function (dateObj) {
  3370. return pad(dateObj.getDate());
  3371. },
  3372. Do: function (dateObj, i18n) {
  3373. return i18n.DoFn(dateObj.getDate());
  3374. },
  3375. d: function (dateObj) {
  3376. return String(dateObj.getDay());
  3377. },
  3378. dd: function (dateObj) {
  3379. return pad(dateObj.getDay());
  3380. },
  3381. ddd: function (dateObj, i18n) {
  3382. return i18n.dayNamesShort[dateObj.getDay()];
  3383. },
  3384. dddd: function (dateObj, i18n) {
  3385. return i18n.dayNames[dateObj.getDay()];
  3386. },
  3387. M: function (dateObj) {
  3388. return String(dateObj.getMonth() + 1);
  3389. },
  3390. MM: function (dateObj) {
  3391. return pad(dateObj.getMonth() + 1);
  3392. },
  3393. MMM: function (dateObj, i18n) {
  3394. return i18n.monthNamesShort[dateObj.getMonth()];
  3395. },
  3396. MMMM: function (dateObj, i18n) {
  3397. return i18n.monthNames[dateObj.getMonth()];
  3398. },
  3399. YY: function (dateObj) {
  3400. return pad(String(dateObj.getFullYear()), 4).substr(2);
  3401. },
  3402. YYYY: function (dateObj) {
  3403. return pad(dateObj.getFullYear(), 4);
  3404. },
  3405. h: function (dateObj) {
  3406. return String(dateObj.getHours() % 12 || 12);
  3407. },
  3408. hh: function (dateObj) {
  3409. return pad(dateObj.getHours() % 12 || 12);
  3410. },
  3411. H: function (dateObj) {
  3412. return String(dateObj.getHours());
  3413. },
  3414. HH: function (dateObj) {
  3415. return pad(dateObj.getHours());
  3416. },
  3417. m: function (dateObj) {
  3418. return String(dateObj.getMinutes());
  3419. },
  3420. mm: function (dateObj) {
  3421. return pad(dateObj.getMinutes());
  3422. },
  3423. s: function (dateObj) {
  3424. return String(dateObj.getSeconds());
  3425. },
  3426. ss: function (dateObj) {
  3427. return pad(dateObj.getSeconds());
  3428. },
  3429. S: function (dateObj) {
  3430. return String(Math.round(dateObj.getMilliseconds() / 100));
  3431. },
  3432. SS: function (dateObj) {
  3433. return pad(Math.round(dateObj.getMilliseconds() / 10), 2);
  3434. },
  3435. SSS: function (dateObj) {
  3436. return pad(dateObj.getMilliseconds(), 3);
  3437. },
  3438. a: function (dateObj, i18n) {
  3439. return dateObj.getHours() < 12 ? i18n.amPm[0] : i18n.amPm[1];
  3440. },
  3441. A: function (dateObj, i18n) {
  3442. return dateObj.getHours() < 12 ? i18n.amPm[0].toUpperCase() : i18n.amPm[1].toUpperCase();
  3443. },
  3444. ZZ: function (dateObj) {
  3445. var offset = dateObj.getTimezoneOffset();
  3446. return (offset > 0 ? "-" : "+") + pad(Math.floor(Math.abs(offset) / 60) * 100 + Math.abs(offset) % 60, 4);
  3447. },
  3448. Z: function (dateObj) {
  3449. var offset = dateObj.getTimezoneOffset();
  3450. return (offset > 0 ? "-" : "+") + pad(Math.floor(Math.abs(offset) / 60), 2) + ":" + pad(Math.abs(offset) % 60, 2);
  3451. }
  3452. };
  3453. var monthParse = function (v) {
  3454. return +v - 1;
  3455. };
  3456. var emptyDigits = [null, twoDigitsOptional];
  3457. var emptyWord = [null, word];
  3458. var amPm = ["isPm", word, function (v, i18n) {
  3459. var val = v.toLowerCase();
  3460. if (val === i18n.amPm[0]) {
  3461. return 0;
  3462. } else if (val === i18n.amPm[1]) {
  3463. return 1;
  3464. }
  3465. return null;
  3466. }];
  3467. var timezoneOffset = ["timezoneOffset", "[^\\s]*?[\\+\\-]\\d\\d:?\\d\\d|[^\\s]*?Z?", function (v) {
  3468. var parts = (v + "").match(/([+-]|\d\d)/gi);
  3469. if (parts) {
  3470. var minutes = +parts[1] * 60 + parseInt(parts[2], 10);
  3471. return parts[0] === "+" ? minutes : -minutes;
  3472. }
  3473. return 0;
  3474. }];
  3475. var parseFlags = {
  3476. D: ["day", twoDigitsOptional],
  3477. DD: ["day", twoDigits],
  3478. Do: ["day", twoDigitsOptional + word, function (v) {
  3479. return parseInt(v, 10);
  3480. }],
  3481. M: ["month", twoDigitsOptional, monthParse],
  3482. MM: ["month", twoDigits, monthParse],
  3483. YY: ["year", twoDigits, function (v) {
  3484. var now = new Date();
  3485. var cent = +("" + now.getFullYear()).substr(0, 2);
  3486. return +("" + (+v > 68 ? cent - 1 : cent) + v);
  3487. }],
  3488. h: ["hour", twoDigitsOptional, undefined, "isPm"],
  3489. hh: ["hour", twoDigits, undefined, "isPm"],
  3490. H: ["hour", twoDigitsOptional],
  3491. HH: ["hour", twoDigits],
  3492. m: ["minute", twoDigitsOptional],
  3493. mm: ["minute", twoDigits],
  3494. s: ["second", twoDigitsOptional],
  3495. ss: ["second", twoDigits],
  3496. YYYY: ["year", fourDigits],
  3497. S: ["millisecond", "\\d", function (v) {
  3498. return +v * 100;
  3499. }],
  3500. SS: ["millisecond", twoDigits, function (v) {
  3501. return +v * 10;
  3502. }],
  3503. SSS: ["millisecond", threeDigits],
  3504. d: emptyDigits,
  3505. dd: emptyDigits,
  3506. ddd: emptyWord,
  3507. dddd: emptyWord,
  3508. MMM: ["month", word, monthUpdate("monthNamesShort")],
  3509. MMMM: ["month", word, monthUpdate("monthNames")],
  3510. a: amPm,
  3511. A: amPm,
  3512. ZZ: timezoneOffset,
  3513. Z: timezoneOffset
  3514. }; // Some common format strings
  3515. var globalMasks = {
  3516. default: "ddd MMM DD YYYY HH:mm:ss",
  3517. shortDate: "M/D/YY",
  3518. mediumDate: "MMM D, YYYY",
  3519. longDate: "MMMM D, YYYY",
  3520. fullDate: "dddd, MMMM D, YYYY",
  3521. isoDate: "YYYY-MM-DD",
  3522. isoDateTime: "YYYY-MM-DDTHH:mm:ssZ",
  3523. shortTime: "HH:mm",
  3524. mediumTime: "HH:mm:ss",
  3525. longTime: "HH:mm:ss.SSS"
  3526. };
  3527. var setGlobalDateMasks = function (masks) {
  3528. return assign(globalMasks, masks);
  3529. };
  3530. /***
  3531. * Format a date
  3532. * @method format
  3533. * @param {Date|number} dateObj
  3534. * @param {string} mask Format of the date, i.e. 'mm-dd-yy' or 'shortDate'
  3535. * @returns {string} Formatted date string
  3536. */
  3537. var format = function (dateObj, mask, i18n) {
  3538. if (mask === void 0) {
  3539. mask = globalMasks["default"];
  3540. }
  3541. if (i18n === void 0) {
  3542. i18n = {};
  3543. }
  3544. if (typeof dateObj === "number") {
  3545. dateObj = new Date(dateObj);
  3546. }
  3547. if (Object.prototype.toString.call(dateObj) !== "[object Date]" || isNaN(dateObj.getTime())) {
  3548. throw new Error("Invalid Date pass to format");
  3549. }
  3550. mask = globalMasks[mask] || mask;
  3551. var literals = []; // Make literals inactive by replacing them with @@@
  3552. mask = mask.replace(literal, function ($0, $1) {
  3553. literals.push($1);
  3554. return "@@@";
  3555. });
  3556. var combinedI18nSettings = assign(assign({}, globalI18n), i18n); // Apply formatting rules
  3557. mask = mask.replace(token, function ($0) {
  3558. return formatFlags[$0](dateObj, combinedI18nSettings);
  3559. }); // Inline literal values back into the formatted value
  3560. return mask.replace(/@@@/g, function () {
  3561. return literals.shift();
  3562. });
  3563. };
  3564. /**
  3565. * Parse a date string into a Javascript Date object /
  3566. * @method parse
  3567. * @param {string} dateStr Date string
  3568. * @param {string} format Date parse format
  3569. * @param {i18n} I18nSettingsOptional Full or subset of I18N settings
  3570. * @returns {Date|null} Returns Date object. Returns null what date string is invalid or doesn't match format
  3571. */
  3572. function parse(dateStr, format, i18n) {
  3573. if (i18n === void 0) {
  3574. i18n = {};
  3575. }
  3576. if (typeof format !== "string") {
  3577. throw new Error("Invalid format in fecha parse");
  3578. } // Check to see if the format is actually a mask
  3579. format = globalMasks[format] || format; // Avoid regular expression denial of service, fail early for really long strings
  3580. // https://www.owasp.org/index.php/Regular_expression_Denial_of_Service_-_ReDoS
  3581. if (dateStr.length > 1000) {
  3582. return null;
  3583. } // Default to the beginning of the year.
  3584. var today = new Date();
  3585. var dateInfo = {
  3586. year: today.getFullYear(),
  3587. month: 0,
  3588. day: 1,
  3589. hour: 0,
  3590. minute: 0,
  3591. second: 0,
  3592. millisecond: 0,
  3593. isPm: null,
  3594. timezoneOffset: null
  3595. };
  3596. var parseInfo = [];
  3597. var literals = []; // Replace all the literals with @@@. Hopefully a string that won't exist in the format
  3598. var newFormat = format.replace(literal, function ($0, $1) {
  3599. literals.push(regexEscape($1));
  3600. return "@@@";
  3601. });
  3602. var specifiedFields = {};
  3603. var requiredFields = {}; // Change every token that we find into the correct regex
  3604. newFormat = regexEscape(newFormat).replace(token, function ($0) {
  3605. var info = parseFlags[$0];
  3606. var field = info[0],
  3607. regex = info[1],
  3608. requiredField = info[3]; // Check if the person has specified the same field twice. This will lead to confusing results.
  3609. if (specifiedFields[field]) {
  3610. throw new Error("Invalid format. " + field + " specified twice in format");
  3611. }
  3612. specifiedFields[field] = true; // Check if there are any required fields. For instance, 12 hour time requires AM/PM specified
  3613. if (requiredField) {
  3614. requiredFields[requiredField] = true;
  3615. }
  3616. parseInfo.push(info);
  3617. return "(" + regex + ")";
  3618. }); // Check all the required fields are present
  3619. Object.keys(requiredFields).forEach(function (field) {
  3620. if (!specifiedFields[field]) {
  3621. throw new Error("Invalid format. " + field + " is required in specified format");
  3622. }
  3623. }); // Add back all the literals after
  3624. newFormat = newFormat.replace(/@@@/g, function () {
  3625. return literals.shift();
  3626. }); // Check if the date string matches the format. If it doesn't return null
  3627. var matches = dateStr.match(new RegExp(newFormat, "i"));
  3628. if (!matches) {
  3629. return null;
  3630. }
  3631. var combinedI18nSettings = assign(assign({}, globalI18n), i18n); // For each match, call the parser function for that date part
  3632. for (var i = 1; i < matches.length; i++) {
  3633. var _a = parseInfo[i - 1],
  3634. field = _a[0],
  3635. parser = _a[2];
  3636. var value = parser ? parser(matches[i], combinedI18nSettings) : +matches[i]; // If the parser can't make sense of the value, return null
  3637. if (value == null) {
  3638. return null;
  3639. }
  3640. dateInfo[field] = value;
  3641. }
  3642. if (dateInfo.isPm === 1 && dateInfo.hour != null && +dateInfo.hour !== 12) {
  3643. dateInfo.hour = +dateInfo.hour + 12;
  3644. } else if (dateInfo.isPm === 0 && +dateInfo.hour === 12) {
  3645. dateInfo.hour = 0;
  3646. }
  3647. var dateWithoutTZ = new Date(dateInfo.year, dateInfo.month, dateInfo.day, dateInfo.hour, dateInfo.minute, dateInfo.second, dateInfo.millisecond);
  3648. var validateFields = [["month", "getMonth"], ["day", "getDate"], ["hour", "getHours"], ["minute", "getMinutes"], ["second", "getSeconds"]];
  3649. for (var i = 0, len = validateFields.length; i < len; i++) {
  3650. // Check to make sure the date field is within the allowed range. Javascript dates allows values
  3651. // outside the allowed range. If the values don't match the value was invalid
  3652. if (specifiedFields[validateFields[i][0]] && dateInfo[validateFields[i][0]] !== dateWithoutTZ[validateFields[i][1]]()) {
  3653. return null;
  3654. }
  3655. }
  3656. if (dateInfo.timezoneOffset == null) {
  3657. return dateWithoutTZ;
  3658. }
  3659. return new Date(Date.UTC(dateInfo.year, dateInfo.month, dateInfo.day, dateInfo.hour, dateInfo.minute - dateInfo.timezoneOffset, dateInfo.second, dateInfo.millisecond));
  3660. }
  3661. var fecha = {
  3662. format: format,
  3663. parse: parse,
  3664. defaultI18n: defaultI18n,
  3665. setGlobalDateI18n: setGlobalDateI18n,
  3666. setGlobalDateMasks: setGlobalDateMasks
  3667. };
  3668. var fecha1 = /*#__PURE__*/Object.freeze({
  3669. __proto__: null,
  3670. 'default': fecha,
  3671. assign: assign,
  3672. format: format,
  3673. parse: parse,
  3674. defaultI18n: defaultI18n,
  3675. setGlobalDateI18n: setGlobalDateI18n,
  3676. setGlobalDateMasks: setGlobalDateMasks
  3677. });
  3678. /**
  3679. * 二分右侧查找
  3680. * https://github.com/d3/d3-array/blob/master/src/bisector.js
  3681. */
  3682. function bisector (getter) {
  3683. /**
  3684. * x: 目标值
  3685. * lo: 起始位置
  3686. * hi: 结束位置
  3687. */
  3688. return function (a, x, _lo, _hi) {
  3689. var lo = isNil$1(_lo) ? 0 : _lo;
  3690. var hi = isNil$1(_hi) ? a.length : _hi;
  3691. while (lo < hi) {
  3692. var mid = lo + hi >>> 1;
  3693. if (getter(a[mid]) > x) {
  3694. hi = mid;
  3695. } else {
  3696. lo = mid + 1;
  3697. }
  3698. }
  3699. return lo;
  3700. };
  3701. }
  3702. var FORMAT_METHOD = 'format';
  3703. function timeFormat(time, mask) {
  3704. var method = fecha1[FORMAT_METHOD] || fecha[FORMAT_METHOD];
  3705. return method(time, mask);
  3706. }
  3707. /**
  3708. * 转换成时间戳
  3709. * @param value 时间值
  3710. */
  3711. function toTimeStamp(value) {
  3712. if (isString(value)) {
  3713. if (value.indexOf('T') > 0) {
  3714. value = new Date(value).getTime();
  3715. } else {
  3716. // new Date('2010/01/10') 和 new Date('2010-01-10') 的差别在于:
  3717. // 如果仅有年月日时,前者是带有时区的: Fri Jan 10 2020 02:40:13 GMT+0800 (中国标准时间)
  3718. // 后者会格式化成 Sun Jan 10 2010 08:00:00 GMT+0800 (中国标准时间)
  3719. value = new Date(value.replace(/-/gi, '/')).getTime();
  3720. }
  3721. }
  3722. if (isDate(value)) {
  3723. value = value.getTime();
  3724. }
  3725. return value;
  3726. }
  3727. var SECOND = 1000;
  3728. var MINUTE = 60 * SECOND;
  3729. var HOUR = 60 * MINUTE;
  3730. var DAY = 24 * HOUR;
  3731. var MONTH = DAY * 31;
  3732. var YEAR = DAY * 365;
  3733. var intervals = [['HH:mm:ss', SECOND], ['HH:mm:ss', SECOND * 10], ['HH:mm:ss', SECOND * 30], ['HH:mm', MINUTE], ['HH:mm', MINUTE * 10], ['HH:mm', MINUTE * 30], ['HH', HOUR], ['HH', HOUR * 6], ['HH', HOUR * 12], ['YYYY-MM-DD', DAY], ['YYYY-MM-DD', DAY * 4], ['YYYY-WW', DAY * 7], ['YYYY-MM', MONTH], ['YYYY-MM', MONTH * 4], ['YYYY-MM', MONTH * 6], ['YYYY', DAY * 380]];
  3734. function getTickInterval(min, max, tickCount) {
  3735. var target = (max - min) / tickCount;
  3736. var idx = bisector(function (o) {
  3737. return o[1];
  3738. })(intervals, target) - 1;
  3739. var interval = intervals[idx];
  3740. if (idx < 0) {
  3741. interval = intervals[0];
  3742. } else if (idx >= intervals.length) {
  3743. interval = last(intervals);
  3744. }
  3745. return interval;
  3746. }
  3747. /**
  3748. * 时间分类度量
  3749. * @class
  3750. */
  3751. var TimeCat$1 = function (_super) {
  3752. __extends(TimeCat, _super);
  3753. function TimeCat() {
  3754. var _this = _super !== null && _super.apply(this, arguments) || this;
  3755. _this.type = 'timeCat';
  3756. return _this;
  3757. }
  3758. /**
  3759. * @override
  3760. */
  3761. TimeCat.prototype.translate = function (value) {
  3762. value = toTimeStamp(value);
  3763. var index = this.values.indexOf(value);
  3764. if (index === -1) {
  3765. if (isNumber(value) && value < this.values.length) {
  3766. index = value;
  3767. } else {
  3768. index = NaN;
  3769. }
  3770. }
  3771. return index;
  3772. };
  3773. /**
  3774. * 由于时间类型数据需要转换一下,所以复写 getText
  3775. * @override
  3776. */
  3777. TimeCat.prototype.getText = function (value, tickIndex) {
  3778. var index = this.translate(value);
  3779. if (index > -1) {
  3780. var result = this.values[index];
  3781. var formatter = this.formatter;
  3782. result = formatter ? formatter(result, tickIndex) : timeFormat(result, this.mask);
  3783. return result;
  3784. }
  3785. return value;
  3786. };
  3787. TimeCat.prototype.initCfg = function () {
  3788. this.tickMethod = 'time-cat';
  3789. this.mask = 'YYYY-MM-DD';
  3790. this.tickCount = 7; // 一般时间数据会显示 7, 14, 30 天的数字
  3791. };
  3792. TimeCat.prototype.setDomain = function () {
  3793. var values = this.values; // 针对时间分类类型,会将时间统一转换为时间戳
  3794. each$1(values, function (v, i) {
  3795. values[i] = toTimeStamp(v);
  3796. });
  3797. values.sort(function (v1, v2) {
  3798. return v1 - v2;
  3799. });
  3800. _super.prototype.setDomain.call(this);
  3801. };
  3802. return TimeCat;
  3803. }(Category$1);
  3804. /**
  3805. * 连续度量的基类
  3806. * @class
  3807. */
  3808. var Continuous = function (_super) {
  3809. __extends(Continuous, _super);
  3810. function Continuous() {
  3811. var _this = _super !== null && _super.apply(this, arguments) || this;
  3812. _this.isContinuous = true;
  3813. return _this;
  3814. }
  3815. Continuous.prototype.scale = function (value) {
  3816. if (isNil$1(value)) {
  3817. return NaN;
  3818. }
  3819. var rangeMin = this.rangeMin();
  3820. var rangeMax = this.rangeMax();
  3821. var max = this.max;
  3822. var min = this.min;
  3823. if (max === min) {
  3824. return rangeMin;
  3825. }
  3826. var percent = this.getScalePercent(value);
  3827. return rangeMin + percent * (rangeMax - rangeMin);
  3828. };
  3829. Continuous.prototype.init = function () {
  3830. _super.prototype.init.call(this); // init 完成后保证 min, max 包含 ticks 的范围
  3831. var ticks = this.ticks;
  3832. var firstTick = head(ticks);
  3833. var lastTick = last(ticks);
  3834. if (firstTick < this.min) {
  3835. this.min = firstTick;
  3836. }
  3837. if (lastTick > this.max) {
  3838. this.max = lastTick;
  3839. } // strict-limit 方式
  3840. if (!isNil$1(this.minLimit)) {
  3841. this.min = firstTick;
  3842. }
  3843. if (!isNil$1(this.maxLimit)) {
  3844. this.max = lastTick;
  3845. }
  3846. };
  3847. Continuous.prototype.setDomain = function () {
  3848. var _a = getRange$1(this.values),
  3849. min = _a.min,
  3850. max = _a.max;
  3851. if (isNil$1(this.min)) {
  3852. this.min = min;
  3853. }
  3854. if (isNil$1(this.max)) {
  3855. this.max = max;
  3856. }
  3857. if (this.min > this.max) {
  3858. this.min = min;
  3859. this.max = max;
  3860. }
  3861. };
  3862. Continuous.prototype.calculateTicks = function () {
  3863. var _this = this;
  3864. var ticks = _super.prototype.calculateTicks.call(this);
  3865. if (!this.nice) {
  3866. ticks = filter(ticks, function (tick) {
  3867. return tick >= _this.min && tick <= _this.max;
  3868. });
  3869. }
  3870. return ticks;
  3871. }; // 计算原始值值占的百分比
  3872. Continuous.prototype.getScalePercent = function (value) {
  3873. var max = this.max;
  3874. var min = this.min;
  3875. return (value - min) / (max - min);
  3876. };
  3877. Continuous.prototype.getInvertPercent = function (value) {
  3878. return (value - this.rangeMin()) / (this.rangeMax() - this.rangeMin());
  3879. };
  3880. return Continuous;
  3881. }(Scale);
  3882. /**
  3883. * 线性度量
  3884. * @class
  3885. */
  3886. var Linear$1 = function (_super) {
  3887. __extends(Linear, _super);
  3888. function Linear() {
  3889. var _this = _super !== null && _super.apply(this, arguments) || this;
  3890. _this.type = 'linear';
  3891. _this.isLinear = true;
  3892. return _this;
  3893. }
  3894. Linear.prototype.invert = function (value) {
  3895. var percent = this.getInvertPercent(value);
  3896. return this.min + percent * (this.max - this.min);
  3897. };
  3898. Linear.prototype.initCfg = function () {
  3899. this.tickMethod = 'wilkinson-extended';
  3900. this.nice = false;
  3901. };
  3902. return Linear;
  3903. }(Continuous);
  3904. // 虽然数学上 b 不支持负数,但是这里需要支持 负数
  3905. function calBase(a, b) {
  3906. var e = Math.E;
  3907. var value;
  3908. if (b >= 0) {
  3909. value = Math.pow(e, Math.log(b) / a); // 使用换底公式求底
  3910. } else {
  3911. value = Math.pow(e, Math.log(-b) / a) * -1; // 使用换底公式求底
  3912. }
  3913. return value;
  3914. }
  3915. function log(a, b) {
  3916. if (a === 1) {
  3917. return 1;
  3918. }
  3919. return Math.log(b) / Math.log(a);
  3920. }
  3921. function getLogPositiveMin(values, base, max) {
  3922. if (isNil$1(max)) {
  3923. max = Math.max.apply(null, values);
  3924. }
  3925. var positiveMin = max;
  3926. each$1(values, function (value) {
  3927. if (value > 0 && value < positiveMin) {
  3928. positiveMin = value;
  3929. }
  3930. });
  3931. if (positiveMin === max) {
  3932. positiveMin = max / base;
  3933. }
  3934. if (positiveMin > 1) {
  3935. positiveMin = 1;
  3936. }
  3937. return positiveMin;
  3938. }
  3939. /**
  3940. * Log 度量,处理非均匀分布
  3941. */
  3942. var Log = function (_super) {
  3943. __extends(Log, _super);
  3944. function Log() {
  3945. var _this = _super !== null && _super.apply(this, arguments) || this;
  3946. _this.type = 'log';
  3947. return _this;
  3948. }
  3949. /**
  3950. * @override
  3951. */
  3952. Log.prototype.invert = function (value) {
  3953. var base = this.base;
  3954. var max = log(base, this.max);
  3955. var rangeMin = this.rangeMin();
  3956. var range = this.rangeMax() - rangeMin;
  3957. var min;
  3958. var positiveMin = this.positiveMin;
  3959. if (positiveMin) {
  3960. if (value === 0) {
  3961. return 0;
  3962. }
  3963. min = log(base, positiveMin / base);
  3964. var appendPercent = 1 / (max - min) * range; // 0 到 positiveMin的占比
  3965. if (value < appendPercent) {
  3966. // 落到 0 - positiveMin 之间
  3967. return value / appendPercent * positiveMin;
  3968. }
  3969. } else {
  3970. min = log(base, this.min);
  3971. }
  3972. var percent = (value - rangeMin) / range;
  3973. var tmp = percent * (max - min) + min;
  3974. return Math.pow(base, tmp);
  3975. };
  3976. Log.prototype.initCfg = function () {
  3977. this.tickMethod = 'log';
  3978. this.base = 10;
  3979. this.tickCount = 6;
  3980. this.nice = true;
  3981. }; // 设置
  3982. Log.prototype.setDomain = function () {
  3983. _super.prototype.setDomain.call(this);
  3984. var min = this.min;
  3985. if (min < 0) {
  3986. throw new Error('When you use log scale, the minimum value must be greater than zero!');
  3987. }
  3988. if (min === 0) {
  3989. this.positiveMin = getLogPositiveMin(this.values, this.base, this.max);
  3990. }
  3991. }; // 根据当前值获取占比
  3992. Log.prototype.getScalePercent = function (value) {
  3993. var max = this.max;
  3994. var min = this.min;
  3995. if (max === min) {
  3996. return 0;
  3997. } // 如果值小于等于0,则按照0处理
  3998. if (value <= 0) {
  3999. return 0;
  4000. }
  4001. var base = this.base;
  4002. var positiveMin = this.positiveMin; // 如果min == 0, 则根据比0大的最小值,计算比例关系。这个最小值作为坐标轴上的第二个tick,第一个是0但是不显示
  4003. if (positiveMin) {
  4004. min = positiveMin * 1 / base;
  4005. }
  4006. var percent; // 如果数值小于次小值,那么就计算 value / 次小值 占整体的比例
  4007. if (value < positiveMin) {
  4008. percent = value / positiveMin / (log(base, max) - log(base, min));
  4009. } else {
  4010. percent = (log(base, value) - log(base, min)) / (log(base, max) - log(base, min));
  4011. }
  4012. return percent;
  4013. };
  4014. return Log;
  4015. }(Continuous);
  4016. /**
  4017. * Pow 度量,处理非均匀分布
  4018. */
  4019. var Pow = function (_super) {
  4020. __extends(Pow, _super);
  4021. function Pow() {
  4022. var _this = _super !== null && _super.apply(this, arguments) || this;
  4023. _this.type = 'pow';
  4024. return _this;
  4025. }
  4026. /**
  4027. * @override
  4028. */
  4029. Pow.prototype.invert = function (value) {
  4030. var percent = this.getInvertPercent(value);
  4031. var exponent = this.exponent;
  4032. var max = calBase(exponent, this.max);
  4033. var min = calBase(exponent, this.min);
  4034. var tmp = percent * (max - min) + min;
  4035. var factor = tmp >= 0 ? 1 : -1;
  4036. return Math.pow(tmp, exponent) * factor;
  4037. };
  4038. Pow.prototype.initCfg = function () {
  4039. this.tickMethod = 'pow';
  4040. this.exponent = 2;
  4041. this.tickCount = 5;
  4042. this.nice = true;
  4043. }; // 获取度量计算时,value占的定义域百分比
  4044. Pow.prototype.getScalePercent = function (value) {
  4045. var max = this.max;
  4046. var min = this.min;
  4047. if (max === min) {
  4048. return 0;
  4049. }
  4050. var exponent = this.exponent;
  4051. var percent = (calBase(exponent, value) - calBase(exponent, min)) / (calBase(exponent, max) - calBase(exponent, min));
  4052. return percent;
  4053. };
  4054. return Pow;
  4055. }(Continuous);
  4056. /**
  4057. * 时间度量
  4058. * @class
  4059. */
  4060. var Time = function (_super) {
  4061. __extends(Time, _super);
  4062. function Time() {
  4063. var _this = _super !== null && _super.apply(this, arguments) || this;
  4064. _this.type = 'time';
  4065. return _this;
  4066. }
  4067. /**
  4068. * @override
  4069. */
  4070. Time.prototype.getText = function (value, index) {
  4071. var numberValue = this.translate(value);
  4072. var formatter = this.formatter;
  4073. return formatter ? formatter(numberValue, index) : timeFormat(numberValue, this.mask);
  4074. };
  4075. /**
  4076. * @override
  4077. */
  4078. Time.prototype.scale = function (value) {
  4079. var v = value;
  4080. if (isString(v) || isDate(v)) {
  4081. v = this.translate(v);
  4082. }
  4083. return _super.prototype.scale.call(this, v);
  4084. };
  4085. /**
  4086. * 将时间转换成数字
  4087. * @override
  4088. */
  4089. Time.prototype.translate = function (v) {
  4090. return toTimeStamp(v);
  4091. };
  4092. Time.prototype.initCfg = function () {
  4093. this.tickMethod = 'time-pretty';
  4094. this.mask = 'YYYY-MM-DD';
  4095. this.tickCount = 7;
  4096. this.nice = false;
  4097. };
  4098. Time.prototype.setDomain = function () {
  4099. var values = this.values; // 是否设置了 min, max,而不是直接取 this.min, this.max
  4100. var minConfig = this.getConfig('min');
  4101. var maxConfig = this.getConfig('max'); // 如果设置了 min,max 则转换成时间戳
  4102. if (!isNil$1(minConfig) || !isNumber(minConfig)) {
  4103. this.min = this.translate(this.min);
  4104. }
  4105. if (!isNil$1(maxConfig) || !isNumber(maxConfig)) {
  4106. this.max = this.translate(this.max);
  4107. } // 没有设置 min, max 时
  4108. if (values && values.length) {
  4109. // 重新计算最大最小值
  4110. var timeStamps_1 = [];
  4111. var min_1 = Infinity; // 最小值
  4112. var secondMin_1 = min_1; // 次小值
  4113. var max_1 = 0; // 使用一个循环,计算min,max,secondMin
  4114. each$1(values, function (v) {
  4115. var timeStamp = toTimeStamp(v);
  4116. if (isNaN(timeStamp)) {
  4117. throw new TypeError("Invalid Time: " + v + " in time scale!");
  4118. }
  4119. if (min_1 > timeStamp) {
  4120. secondMin_1 = min_1;
  4121. min_1 = timeStamp;
  4122. } else if (secondMin_1 > timeStamp) {
  4123. secondMin_1 = timeStamp;
  4124. }
  4125. if (max_1 < timeStamp) {
  4126. max_1 = timeStamp;
  4127. }
  4128. timeStamps_1.push(timeStamp);
  4129. }); // 存在多个值时,设置最小间距
  4130. if (values.length > 1) {
  4131. this.minTickInterval = secondMin_1 - min_1;
  4132. }
  4133. if (isNil$1(minConfig)) {
  4134. this.min = min_1;
  4135. }
  4136. if (isNil$1(maxConfig)) {
  4137. this.max = max_1;
  4138. }
  4139. }
  4140. };
  4141. return Time;
  4142. }(Linear$1);
  4143. /**
  4144. * 分段度量
  4145. */
  4146. var Quantize = function (_super) {
  4147. __extends(Quantize, _super);
  4148. function Quantize() {
  4149. var _this = _super !== null && _super.apply(this, arguments) || this;
  4150. _this.type = 'quantize';
  4151. return _this;
  4152. }
  4153. Quantize.prototype.invert = function (value) {
  4154. var ticks = this.ticks;
  4155. var length = ticks.length;
  4156. var percent = this.getInvertPercent(value);
  4157. var minIndex = Math.floor(percent * (length - 1)); // 最后一个
  4158. if (minIndex >= length - 1) {
  4159. return last(ticks);
  4160. } // 超出左边界, 则取第一个
  4161. if (minIndex < 0) {
  4162. return head(ticks);
  4163. }
  4164. var minTick = ticks[minIndex];
  4165. var nextTick = ticks[minIndex + 1]; // 比当前值小的 tick 在度量上的占比
  4166. var minIndexPercent = minIndex / (length - 1);
  4167. var maxIndexPercent = (minIndex + 1) / (length - 1);
  4168. return minTick + (percent - minIndexPercent) / (maxIndexPercent - minIndexPercent) * (nextTick - minTick);
  4169. };
  4170. Quantize.prototype.initCfg = function () {
  4171. this.tickMethod = 'r-pretty';
  4172. this.tickCount = 5;
  4173. this.nice = true;
  4174. };
  4175. Quantize.prototype.calculateTicks = function () {
  4176. var ticks = _super.prototype.calculateTicks.call(this);
  4177. if (!this.nice) {
  4178. // 如果 nice = false ,补充 min, max
  4179. if (last(ticks) !== this.max) {
  4180. ticks.push(this.max);
  4181. }
  4182. if (head(ticks) !== this.min) {
  4183. ticks.unshift(this.min);
  4184. }
  4185. }
  4186. return ticks;
  4187. }; // 计算当前值在刻度中的占比
  4188. Quantize.prototype.getScalePercent = function (value) {
  4189. var ticks = this.ticks; // 超出左边界
  4190. if (value < head(ticks)) {
  4191. return 0;
  4192. } // 超出右边界
  4193. if (value > last(ticks)) {
  4194. return 1;
  4195. }
  4196. var minIndex = 0;
  4197. each$1(ticks, function (tick, index) {
  4198. if (value >= tick) {
  4199. minIndex = index;
  4200. } else {
  4201. return false;
  4202. }
  4203. });
  4204. return minIndex / (ticks.length - 1);
  4205. };
  4206. return Quantize;
  4207. }(Continuous);
  4208. var Quantile = function (_super) {
  4209. __extends(Quantile, _super);
  4210. function Quantile() {
  4211. var _this = _super !== null && _super.apply(this, arguments) || this;
  4212. _this.type = 'quantile';
  4213. return _this;
  4214. }
  4215. Quantile.prototype.initCfg = function () {
  4216. this.tickMethod = 'quantile';
  4217. this.tickCount = 5;
  4218. this.nice = true;
  4219. };
  4220. return Quantile;
  4221. }(Quantize);
  4222. var map = {};
  4223. function getClass(key) {
  4224. return map[key];
  4225. }
  4226. function registerClass(key, cls) {
  4227. if (getClass(key)) {
  4228. throw new Error("type '" + key + "' existed.");
  4229. }
  4230. map[key] = cls;
  4231. }
  4232. /**
  4233. * identity scale原则上是定义域和值域一致,scale/invert方法也是一致的
  4234. * 参考R的实现:https://github.com/r-lib/scales/blob/master/R/pal-identity.r
  4235. * 参考d3的实现(做了下转型):https://github.com/d3/d3-scale/blob/master/src/identity.js
  4236. */
  4237. var Identity$1 = function (_super) {
  4238. __extends(Identity, _super);
  4239. function Identity() {
  4240. var _this = _super !== null && _super.apply(this, arguments) || this;
  4241. _this.type = 'identity';
  4242. _this.isIdentity = true;
  4243. return _this;
  4244. }
  4245. Identity.prototype.calculateTicks = function () {
  4246. return this.values;
  4247. };
  4248. Identity.prototype.scale = function (value) {
  4249. // 如果传入的值不等于 identity 的值,则直接返回,用于一维图时的 dodge
  4250. if (this.values[0] !== value && isNumber(value)) {
  4251. return value;
  4252. }
  4253. return this.range[0];
  4254. };
  4255. Identity.prototype.invert = function (value) {
  4256. var range = this.range;
  4257. if (value < range[0] || value > range[1]) {
  4258. return NaN;
  4259. }
  4260. return this.values[0];
  4261. };
  4262. return Identity;
  4263. }(Scale);
  4264. var DEFAULT_Q = [1, 5, 2, 2.5, 4, 3];
  4265. var eps = Number.EPSILON * 100;
  4266. function mod(n, m) {
  4267. return (n % m + m) % m;
  4268. }
  4269. function simplicity(q, Q, j, lmin, lmax, lstep) {
  4270. var n = size(Q);
  4271. var i = indexOf(Q, q);
  4272. var v = 0;
  4273. var m = mod(lmin, lstep);
  4274. if ((m < eps || lstep - m < eps) && lmin <= 0 && lmax >= 0) {
  4275. v = 1;
  4276. }
  4277. return 1 - i / (n - 1) - j + v;
  4278. }
  4279. function simplicityMax(q, Q, j) {
  4280. var n = size(Q);
  4281. var i = indexOf(Q, q);
  4282. var v = 1;
  4283. return 1 - i / (n - 1) - j + v;
  4284. }
  4285. function density(k, m, dMin, dMax, lMin, lMax) {
  4286. var r = (k - 1) / (lMax - lMin);
  4287. var rt = (m - 1) / (Math.max(lMax, dMax) - Math.min(dMin, lMin));
  4288. return 2 - Math.max(r / rt, rt / r);
  4289. }
  4290. function densityMax(k, m) {
  4291. if (k >= m) {
  4292. return 2 - (k - 1) / (m - 1);
  4293. }
  4294. return 1;
  4295. }
  4296. function coverage(dMin, dMax, lMin, lMax) {
  4297. var range = dMax - dMin;
  4298. return 1 - 0.5 * (Math.pow(dMax - lMax, 2) + Math.pow(dMin - lMin, 2)) / Math.pow(0.1 * range, 2);
  4299. }
  4300. function coverageMax(dMin, dMax, span) {
  4301. var range = dMax - dMin;
  4302. if (span > range) {
  4303. var half = (span - range) / 2;
  4304. return 1 - Math.pow(half, 2) / Math.pow(0.1 * range, 2);
  4305. }
  4306. return 1;
  4307. }
  4308. function legibility() {
  4309. return 1;
  4310. } // 解决 js 计算精度问题
  4311. function prettyNumber$1(n) {
  4312. return n < 1e-15 ? n : parseFloat(n.toFixed(15));
  4313. }
  4314. /**
  4315. * An Extension of Wilkinson's Algorithm for Position Tick Labels on Axes
  4316. * https://www.yuque.com/preview/yuque/0/2019/pdf/185317/1546999150858-45c3b9c2-4e86-4223-bf1a-8a732e8195ed.pdf
  4317. * @param dMin 最小值
  4318. * @param dMax 最大值
  4319. * @param m tick个数
  4320. * @param onlyLoose 是否允许扩展min、max,不绝对强制,例如[3, 97]
  4321. * @param Q nice numbers集合
  4322. * @param w 四个优化组件的权重
  4323. */
  4324. function extended(dMin, dMax, m, onlyLoose, Q, w) {
  4325. if (m === void 0) {
  4326. m = 5;
  4327. }
  4328. if (onlyLoose === void 0) {
  4329. onlyLoose = true;
  4330. }
  4331. if (Q === void 0) {
  4332. Q = DEFAULT_Q;
  4333. }
  4334. if (w === void 0) {
  4335. w = [0.25, 0.2, 0.5, 0.05];
  4336. } // nan 也会导致异常
  4337. if (Number.isNaN(dMin) || Number.isNaN(dMax) || typeof dMin !== 'number' || typeof dMax !== 'number' || !m) {
  4338. return {
  4339. min: 0,
  4340. max: 0,
  4341. ticks: []
  4342. };
  4343. } // js 极大值极小值问题,差值小于 1e-15 会导致计算出错
  4344. if (dMax - dMin < 1e-15 || m === 1) {
  4345. return {
  4346. min: dMin,
  4347. max: dMax,
  4348. ticks: [dMin]
  4349. };
  4350. }
  4351. var best = {
  4352. score: -2,
  4353. lmin: 0,
  4354. lmax: 0,
  4355. lstep: 0
  4356. };
  4357. var j = 1;
  4358. while (j < Infinity) {
  4359. for (var i = 0; i < Q.length; i += 1) {
  4360. var q = Q[i];
  4361. var sm = simplicityMax(q, Q, j);
  4362. if (w[0] * sm + w[1] + w[2] + w[3] < best.score) {
  4363. j = Infinity;
  4364. break;
  4365. }
  4366. var k = 2;
  4367. while (k < Infinity) {
  4368. var dm = densityMax(k, m);
  4369. if (w[0] * sm + w[1] + w[2] * dm + w[3] < best.score) {
  4370. break;
  4371. }
  4372. var delta = (dMax - dMin) / (k + 1) / j / q;
  4373. var z = Math.ceil(Math.log10(delta));
  4374. while (z < Infinity) {
  4375. var step = j * q * Math.pow(10, z);
  4376. var cm = coverageMax(dMin, dMax, step * (k - 1));
  4377. if (w[0] * sm + w[1] * cm + w[2] * dm + w[3] < best.score) {
  4378. break;
  4379. }
  4380. var minStart = Math.floor(dMax / step) * j - (k - 1) * j;
  4381. var maxStart = Math.ceil(dMin / step) * j;
  4382. if (minStart <= maxStart) {
  4383. var count = maxStart - minStart;
  4384. for (var i_1 = 0; i_1 <= count; i_1 += 1) {
  4385. var start = minStart + i_1;
  4386. var lMin = start * (step / j);
  4387. var lMax = lMin + step * (k - 1);
  4388. var lStep = step;
  4389. var s = simplicity(q, Q, j, lMin, lMax, lStep);
  4390. var c = coverage(dMin, dMax, lMin, lMax);
  4391. var g = density(k, m, dMin, dMax, lMin, lMax);
  4392. var l = legibility();
  4393. var score = w[0] * s + w[1] * c + w[2] * g + w[3] * l;
  4394. if (score > best.score && (!onlyLoose || lMin <= dMin && lMax >= dMax)) {
  4395. best.lmin = lMin;
  4396. best.lmax = lMax;
  4397. best.lstep = lStep;
  4398. best.score = score;
  4399. }
  4400. }
  4401. }
  4402. z += 1;
  4403. }
  4404. k += 1;
  4405. }
  4406. }
  4407. j += 1;
  4408. }
  4409. var lmax = best.lmax,
  4410. lmin = best.lmin,
  4411. lstep = best.lstep;
  4412. var tickCount = Math.floor((lmax - lmin) / lstep) + 1;
  4413. var ticks = new Array(tickCount);
  4414. for (var i = 0; i < tickCount; i++) {
  4415. ticks[i] = prettyNumber$1(lmin + i * lstep);
  4416. }
  4417. return {
  4418. min: Math.min(dMin, head(ticks)),
  4419. max: Math.max(dMax, last(ticks)),
  4420. ticks: ticks
  4421. };
  4422. }
  4423. /**
  4424. * 计算分类 ticks
  4425. * @param cfg 度量的配置项
  4426. * @returns 计算后的 ticks
  4427. */
  4428. function calculateCatTicks(cfg) {
  4429. var values = cfg.values,
  4430. tickInterval = cfg.tickInterval,
  4431. tickCount = cfg.tickCount;
  4432. var ticks = values;
  4433. if (isNumber(tickInterval)) {
  4434. return filter(ticks, function (__, i) {
  4435. return i % tickInterval === 0;
  4436. });
  4437. }
  4438. var min = cfg.min,
  4439. max = cfg.max;
  4440. if (isNil$1(min)) {
  4441. min = 0;
  4442. }
  4443. if (isNil$1(max)) {
  4444. max = values.length - 1;
  4445. }
  4446. if (isNumber(tickCount) && tickCount < max - min) {
  4447. // 简单过滤,部分情况下小数的倍数也可以是整数
  4448. // tslint:disable-next-line: no-shadowed-variable
  4449. var ticks_1 = extended(min, max, tickCount, false, [1, 2, 5, 3, 4, 7, 6, 8, 9]).ticks;
  4450. var valid = filter(ticks_1, function (tick) {
  4451. return tick >= min && tick <= max;
  4452. });
  4453. return valid.map(function (index) {
  4454. return values[index];
  4455. });
  4456. }
  4457. return values.slice(min, max + 1);
  4458. }
  4459. function d3Linear(cfg) {
  4460. var min = cfg.min,
  4461. max = cfg.max,
  4462. nice = cfg.nice,
  4463. tickCount = cfg.tickCount;
  4464. var linear = new D3Linear();
  4465. linear.domain([min, max]);
  4466. if (nice) {
  4467. linear.nice(tickCount);
  4468. }
  4469. return linear.ticks(tickCount);
  4470. }
  4471. var DEFAULT_COUNT$1 = 5;
  4472. var e10 = Math.sqrt(50);
  4473. var e5 = Math.sqrt(10);
  4474. var e2 = Math.sqrt(2); // https://github.com/d3/d3-scale
  4475. var D3Linear = function () {
  4476. function D3Linear() {
  4477. this._domain = [0, 1];
  4478. }
  4479. D3Linear.prototype.domain = function (domain) {
  4480. if (domain) {
  4481. this._domain = Array.from(domain, Number);
  4482. return this;
  4483. }
  4484. return this._domain.slice();
  4485. };
  4486. D3Linear.prototype.nice = function (count) {
  4487. var _a, _b;
  4488. if (count === void 0) {
  4489. count = DEFAULT_COUNT$1;
  4490. }
  4491. var d = this._domain.slice();
  4492. var i0 = 0;
  4493. var i1 = this._domain.length - 1;
  4494. var start = this._domain[i0];
  4495. var stop = this._domain[i1];
  4496. var step;
  4497. if (stop < start) {
  4498. _a = [stop, start], start = _a[0], stop = _a[1];
  4499. _b = [i1, i0], i0 = _b[0], i1 = _b[1];
  4500. }
  4501. step = tickIncrement(start, stop, count);
  4502. if (step > 0) {
  4503. start = Math.floor(start / step) * step;
  4504. stop = Math.ceil(stop / step) * step;
  4505. step = tickIncrement(start, stop, count);
  4506. } else if (step < 0) {
  4507. start = Math.ceil(start * step) / step;
  4508. stop = Math.floor(stop * step) / step;
  4509. step = tickIncrement(start, stop, count);
  4510. }
  4511. if (step > 0) {
  4512. d[i0] = Math.floor(start / step) * step;
  4513. d[i1] = Math.ceil(stop / step) * step;
  4514. this.domain(d);
  4515. } else if (step < 0) {
  4516. d[i0] = Math.ceil(start * step) / step;
  4517. d[i1] = Math.floor(stop * step) / step;
  4518. this.domain(d);
  4519. }
  4520. return this;
  4521. };
  4522. D3Linear.prototype.ticks = function (count) {
  4523. if (count === void 0) {
  4524. count = DEFAULT_COUNT$1;
  4525. }
  4526. return d3ArrayTicks(this._domain[0], this._domain[this._domain.length - 1], count || DEFAULT_COUNT$1);
  4527. };
  4528. return D3Linear;
  4529. }();
  4530. function d3ArrayTicks(start, stop, count) {
  4531. var reverse;
  4532. var i = -1;
  4533. var n;
  4534. var ticks;
  4535. var step;
  4536. stop = +stop, start = +start, count = +count;
  4537. if (start === stop && count > 0) {
  4538. return [start];
  4539. } // tslint:disable-next-line
  4540. if (reverse = stop < start) {
  4541. n = start, start = stop, stop = n;
  4542. } // tslint:disable-next-line
  4543. if ((step = tickIncrement(start, stop, count)) === 0 || !isFinite(step)) {
  4544. return [];
  4545. }
  4546. if (step > 0) {
  4547. start = Math.ceil(start / step);
  4548. stop = Math.floor(stop / step);
  4549. ticks = new Array(n = Math.ceil(stop - start + 1));
  4550. while (++i < n) {
  4551. ticks[i] = (start + i) * step;
  4552. }
  4553. } else {
  4554. start = Math.floor(start * step);
  4555. stop = Math.ceil(stop * step);
  4556. ticks = new Array(n = Math.ceil(start - stop + 1));
  4557. while (++i < n) {
  4558. ticks[i] = (start - i) / step;
  4559. }
  4560. }
  4561. if (reverse) {
  4562. ticks.reverse();
  4563. }
  4564. return ticks;
  4565. }
  4566. function tickIncrement(start, stop, count) {
  4567. var step = (stop - start) / Math.max(0, count);
  4568. var power = Math.floor(Math.log(step) / Math.LN10);
  4569. var error = step / Math.pow(10, power);
  4570. return power >= 0 ? (error >= e10 ? 10 : error >= e5 ? 5 : error >= e2 ? 2 : 1) * Math.pow(10, power) : -Math.pow(10, -power) / (error >= e10 ? 10 : error >= e5 ? 5 : error >= e2 ? 2 : 1);
  4571. }
  4572. function snapMultiple(v, base, snapType) {
  4573. var div;
  4574. if (snapType === 'ceil') {
  4575. div = Math.ceil(v / base);
  4576. } else if (snapType === 'floor') {
  4577. div = Math.floor(v / base);
  4578. } else {
  4579. div = Math.round(v / base);
  4580. }
  4581. return div * base;
  4582. }
  4583. function intervalTicks(min, max, interval) {
  4584. // 变成 interval 的倍数
  4585. var minTick = snapMultiple(min, interval, 'floor');
  4586. var maxTick = snapMultiple(max, interval, 'ceil'); // 统一小数位数
  4587. minTick = fixedBase(minTick, interval);
  4588. maxTick = fixedBase(maxTick, interval);
  4589. var ticks = [];
  4590. for (var i = minTick; i <= maxTick; i = i + interval) {
  4591. var tickValue = fixedBase(i, interval); // 防止浮点数加法出现问题
  4592. ticks.push(tickValue);
  4593. }
  4594. return {
  4595. min: minTick,
  4596. max: maxTick,
  4597. ticks: ticks
  4598. };
  4599. }
  4600. /**
  4601. * 按照给定的 minLimit/maxLimit/tickCount 均匀计算出刻度 ticks
  4602. *
  4603. * @param cfg Scale 配置项
  4604. * @return ticks
  4605. */
  4606. function strictLimit(cfg, defaultMin, defaultMax) {
  4607. var _a;
  4608. var minLimit = cfg.minLimit,
  4609. maxLimit = cfg.maxLimit,
  4610. min = cfg.min,
  4611. max = cfg.max,
  4612. _b = cfg.tickCount,
  4613. tickCount = _b === void 0 ? 5 : _b;
  4614. var tickMin = isNil$1(minLimit) ? isNil$1(defaultMin) ? min : defaultMin : minLimit;
  4615. var tickMax = isNil$1(maxLimit) ? isNil$1(defaultMax) ? max : defaultMax : maxLimit;
  4616. if (tickMin > tickMax) {
  4617. _a = [tickMin, tickMax], tickMax = _a[0], tickMin = _a[1];
  4618. }
  4619. if (tickCount <= 2) {
  4620. return [tickMin, tickMax];
  4621. }
  4622. var step = (tickMax - tickMin) / (tickCount - 1);
  4623. var ticks = [];
  4624. for (var i = 0; i < tickCount; i++) {
  4625. ticks.push(tickMin + step * i);
  4626. }
  4627. return ticks;
  4628. }
  4629. function d3LinearTickMethod(cfg) {
  4630. var min = cfg.min,
  4631. max = cfg.max,
  4632. tickInterval = cfg.tickInterval,
  4633. minLimit = cfg.minLimit,
  4634. maxLimit = cfg.maxLimit;
  4635. var ticks = d3Linear(cfg);
  4636. if (!isNil$1(minLimit) || !isNil$1(maxLimit)) {
  4637. return strictLimit(cfg, head(ticks), last(ticks));
  4638. }
  4639. if (tickInterval) {
  4640. return intervalTicks(min, max, tickInterval).ticks;
  4641. }
  4642. return ticks;
  4643. }
  4644. /**
  4645. * 计算线性的 ticks,使用 wilkinson extended 方法
  4646. * @param cfg 度量的配置项
  4647. * @returns 计算后的 ticks
  4648. */
  4649. function linear$1(cfg) {
  4650. var min = cfg.min,
  4651. max = cfg.max,
  4652. tickCount = cfg.tickCount,
  4653. nice = cfg.nice,
  4654. tickInterval = cfg.tickInterval,
  4655. minLimit = cfg.minLimit,
  4656. maxLimit = cfg.maxLimit;
  4657. var ticks = extended(min, max, tickCount, nice).ticks;
  4658. if (!isNil$1(minLimit) || !isNil$1(maxLimit)) {
  4659. return strictLimit(cfg, head(ticks), last(ticks));
  4660. }
  4661. if (tickInterval) {
  4662. return intervalTicks(min, max, tickInterval).ticks;
  4663. }
  4664. return ticks;
  4665. }
  4666. /**
  4667. * 计算 log 的 ticks,考虑 min = 0 的场景
  4668. * @param cfg 度量的配置项
  4669. * @returns 计算后的 ticks
  4670. */
  4671. function calculateLogTicks(cfg) {
  4672. var base = cfg.base,
  4673. tickCount = cfg.tickCount,
  4674. min = cfg.min,
  4675. max = cfg.max,
  4676. values = cfg.values;
  4677. var minTick;
  4678. var maxTick = log(base, max);
  4679. if (min > 0) {
  4680. minTick = Math.floor(log(base, min));
  4681. } else {
  4682. var positiveMin = getLogPositiveMin(values, base, max);
  4683. minTick = Math.floor(log(base, positiveMin));
  4684. }
  4685. var count = maxTick - minTick;
  4686. var avg = Math.ceil(count / tickCount);
  4687. var ticks = [];
  4688. for (var i = minTick; i < maxTick + avg; i = i + avg) {
  4689. ticks.push(Math.pow(base, i));
  4690. }
  4691. if (min <= 0) {
  4692. // 最小值 <= 0 时显示 0
  4693. ticks.unshift(0);
  4694. }
  4695. return ticks;
  4696. }
  4697. function prettyNumber(n) {
  4698. return n < 1e-15 ? n : parseFloat(n.toFixed(15));
  4699. }
  4700. function pretty(min, max, n) {
  4701. if (n === void 0) {
  4702. n = 5;
  4703. }
  4704. if (min === max) {
  4705. return {
  4706. max: max,
  4707. min: min,
  4708. ticks: [min]
  4709. };
  4710. }
  4711. /*
  4712. R pretty:
  4713. https://svn.r-project.org/R/trunk/src/appl/pretty.c
  4714. https://www.rdocumentation.org/packages/base/versions/3.5.2/topics/pretty
  4715. */
  4716. var h = 1.5; // high.u.bias
  4717. var h5 = 0.5 + 1.5 * h; // u5.bias
  4718. // 反正我也不会调参,跳过所有判断步骤
  4719. var d = max - min;
  4720. var c = d / n; // 当d非常小的时候触发,但似乎没什么用
  4721. // const min_n = Math.floor(n / 3);
  4722. // const shrink_sml = Math.pow(2, 5);
  4723. // if (Math.log10(d) < -2) {
  4724. // c = (_.max([ Math.abs(max), Math.abs(min) ]) * shrink_sml) / min_n;
  4725. // }
  4726. var base = Math.pow(10, Math.floor(Math.log10(c)));
  4727. var unit = base;
  4728. if (2 * base - c < h * (c - unit)) {
  4729. unit = 2 * base;
  4730. if (5 * base - c < h5 * (c - unit)) {
  4731. unit = 5 * base;
  4732. if (10 * base - c < h * (c - unit)) {
  4733. unit = 10 * base;
  4734. }
  4735. }
  4736. }
  4737. var nu = Math.ceil(max / unit);
  4738. var ns = Math.floor(min / unit);
  4739. var hi = Math.max(nu * unit, max);
  4740. var lo = Math.min(ns * unit, min);
  4741. var size = Math.floor((hi - lo) / unit) + 1;
  4742. var ticks = new Array(size);
  4743. for (var i = 0; i < size; i++) {
  4744. ticks[i] = prettyNumber(lo + i * unit);
  4745. }
  4746. return {
  4747. min: lo,
  4748. max: hi,
  4749. ticks: ticks
  4750. };
  4751. }
  4752. /**
  4753. * 计算 Pow 的 ticks
  4754. * @param cfg 度量的配置项
  4755. * @returns 计算后的 ticks
  4756. */
  4757. function calculatePowTicks(cfg) {
  4758. var exponent = cfg.exponent,
  4759. tickCount = cfg.tickCount;
  4760. var max = Math.ceil(calBase(exponent, cfg.max));
  4761. var min = Math.floor(calBase(exponent, cfg.min));
  4762. var ticks = pretty(min, max, tickCount).ticks;
  4763. return ticks.map(function (tick) {
  4764. var factor = tick >= 0 ? 1 : -1;
  4765. return Math.pow(tick, exponent) * factor;
  4766. });
  4767. }
  4768. /**
  4769. * 计算几分位 https://github.com/simple-statistics/simple-statistics/blob/master/src/quantile_sorted.js
  4770. * @param x 数组
  4771. * @param p 百分比
  4772. */
  4773. function quantileSorted(x, p) {
  4774. var idx = x.length * p;
  4775. /*if (x.length === 0) { // 当前场景这些条件不可能命中
  4776. throw new Error('quantile requires at least one value.');
  4777. } else if (p < 0 || p > 1) {
  4778. throw new Error('quantiles must be between 0 and 1');
  4779. } else */
  4780. if (p === 1) {
  4781. // If p is 1, directly return the last element
  4782. return x[x.length - 1];
  4783. } else if (p === 0) {
  4784. // If p is 0, directly return the first element
  4785. return x[0];
  4786. } else if (idx % 1 !== 0) {
  4787. // If p is not integer, return the next element in array
  4788. return x[Math.ceil(idx) - 1];
  4789. } else if (x.length % 2 === 0) {
  4790. // If the list has even-length, we'll take the average of this number
  4791. // and the next value, if there is one
  4792. return (x[idx - 1] + x[idx]) / 2;
  4793. } else {
  4794. // Finally, in the simple case of an integer value
  4795. // with an odd-length list, return the x value at the index.
  4796. return x[idx];
  4797. }
  4798. }
  4799. function calculateTicks(cfg) {
  4800. var tickCount = cfg.tickCount,
  4801. values = cfg.values;
  4802. if (!values || !values.length) {
  4803. return [];
  4804. }
  4805. var sorted = values.slice().sort(function (a, b) {
  4806. return a - b;
  4807. });
  4808. var ticks = [];
  4809. for (var i = 0; i < tickCount; i++) {
  4810. var p = i / (tickCount - 1);
  4811. ticks.push(quantileSorted(sorted, p));
  4812. }
  4813. return ticks;
  4814. }
  4815. /**
  4816. * 计算线性的 ticks,使用 R's pretty 方法
  4817. * @param cfg 度量的配置项
  4818. * @returns 计算后的 ticks
  4819. */
  4820. function linearPretty(cfg) {
  4821. var min = cfg.min,
  4822. max = cfg.max,
  4823. tickCount = cfg.tickCount,
  4824. tickInterval = cfg.tickInterval,
  4825. minLimit = cfg.minLimit,
  4826. maxLimit = cfg.maxLimit;
  4827. var ticks = pretty(min, max, tickCount).ticks;
  4828. if (!isNil$1(minLimit) || !isNil$1(maxLimit)) {
  4829. return strictLimit(cfg, head(ticks), last(ticks));
  4830. }
  4831. if (tickInterval) {
  4832. return intervalTicks(min, max, tickInterval).ticks;
  4833. }
  4834. return ticks;
  4835. }
  4836. function calculateTimeTicks(cfg) {
  4837. var min = cfg.min,
  4838. max = cfg.max,
  4839. minTickInterval = cfg.minTickInterval;
  4840. var tickInterval = cfg.tickInterval;
  4841. var tickCount = cfg.tickCount; // 指定 tickInterval 后 tickCount 不生效,需要重新计算
  4842. if (tickInterval) {
  4843. tickCount = Math.ceil((max - min) / tickInterval);
  4844. } else {
  4845. tickInterval = getTickInterval(min, max, tickCount)[1];
  4846. var count = (max - min) / tickInterval;
  4847. var ratio = count / tickCount;
  4848. if (ratio > 1) {
  4849. tickInterval = tickInterval * Math.ceil(ratio);
  4850. } // 如果设置了最小间距,则使用最小间距
  4851. if (minTickInterval && tickInterval < minTickInterval) {
  4852. tickInterval = minTickInterval;
  4853. }
  4854. }
  4855. var ticks = [];
  4856. for (var i = min; i < max + tickInterval; i += tickInterval) {
  4857. ticks.push(i);
  4858. }
  4859. return ticks;
  4860. }
  4861. /**
  4862. * 计算时间分类的 ticks, 保头,保尾
  4863. * @param cfg 度量的配置项
  4864. * @returns 计算后的 ticks
  4865. */
  4866. function calculateTimeCatTicks(cfg) {
  4867. var ticks = calculateCatTicks(cfg);
  4868. var lastValue = last(cfg.values);
  4869. if (lastValue !== last(ticks)) {
  4870. ticks.push(lastValue);
  4871. }
  4872. return ticks;
  4873. }
  4874. function getYear(date) {
  4875. return new Date(date).getFullYear();
  4876. }
  4877. function createYear(year) {
  4878. return new Date(year, 0, 1).getTime();
  4879. }
  4880. function getMonth(date) {
  4881. return new Date(date).getMonth();
  4882. }
  4883. function diffMonth(min, max) {
  4884. var minYear = getYear(min);
  4885. var maxYear = getYear(max);
  4886. var minMonth = getMonth(min);
  4887. var maxMonth = getMonth(max);
  4888. return (maxYear - minYear) * 12 + (maxMonth - minMonth) % 12;
  4889. }
  4890. function creatMonth(year, month) {
  4891. return new Date(year, month, 1).getTime();
  4892. }
  4893. function diffDay(min, max) {
  4894. return Math.ceil((max - min) / DAY);
  4895. }
  4896. function diffHour(min, max) {
  4897. return Math.ceil((max - min) / HOUR);
  4898. }
  4899. function diffMinus(min, max) {
  4900. return Math.ceil((max - min) / (60 * 1000));
  4901. }
  4902. /**
  4903. * 计算 time 的 ticks,对 month, year 进行 pretty 处理
  4904. * @param cfg 度量的配置项
  4905. * @returns 计算后的 ticks
  4906. */
  4907. function timePretty(cfg) {
  4908. var min = cfg.min,
  4909. max = cfg.max,
  4910. minTickInterval = cfg.minTickInterval,
  4911. tickCount = cfg.tickCount;
  4912. var tickInterval = cfg.tickInterval;
  4913. var ticks = []; // 指定 tickInterval 后 tickCount 不生效,需要重新计算
  4914. if (!tickInterval) {
  4915. tickInterval = (max - min) / tickCount; // 如果设置了最小间距,则使用最小间距
  4916. if (minTickInterval && tickInterval < minTickInterval) {
  4917. tickInterval = minTickInterval;
  4918. }
  4919. }
  4920. var minYear = getYear(min); // 如果间距大于 1 年,则将开始日期从整年开始
  4921. if (tickInterval > YEAR) {
  4922. var maxYear = getYear(max);
  4923. var yearInterval = Math.ceil(tickInterval / YEAR);
  4924. for (var i = minYear; i <= maxYear + yearInterval; i = i + yearInterval) {
  4925. ticks.push(createYear(i));
  4926. }
  4927. } else if (tickInterval > MONTH) {
  4928. // 大于月时
  4929. var monthInterval = Math.ceil(tickInterval / MONTH);
  4930. var mmMoth = getMonth(min);
  4931. var dMonths = diffMonth(min, max);
  4932. for (var i = 0; i <= dMonths + monthInterval; i = i + monthInterval) {
  4933. ticks.push(creatMonth(minYear, i + mmMoth));
  4934. }
  4935. } else if (tickInterval > DAY) {
  4936. // 大于天
  4937. var date = new Date(min);
  4938. var year = date.getFullYear();
  4939. var month = date.getMonth();
  4940. var mday = date.getDate();
  4941. var day = Math.ceil(tickInterval / DAY);
  4942. var ddays = diffDay(min, max);
  4943. for (var i = 0; i < ddays + day; i = i + day) {
  4944. ticks.push(new Date(year, month, mday + i).getTime());
  4945. }
  4946. } else if (tickInterval > HOUR) {
  4947. // 大于小时
  4948. var date = new Date(min);
  4949. var year = date.getFullYear();
  4950. var month = date.getMonth();
  4951. var day = date.getDate();
  4952. var hour = date.getHours();
  4953. var hours = Math.ceil(tickInterval / HOUR);
  4954. var dHours = diffHour(min, max);
  4955. for (var i = 0; i <= dHours + hours; i = i + hours) {
  4956. ticks.push(new Date(year, month, day, hour + i).getTime());
  4957. }
  4958. } else if (tickInterval > MINUTE) {
  4959. // 大于分钟
  4960. var dMinus = diffMinus(min, max);
  4961. var minutes = Math.ceil(tickInterval / MINUTE);
  4962. for (var i = 0; i <= dMinus + minutes; i = i + minutes) {
  4963. ticks.push(min + i * MINUTE);
  4964. }
  4965. } else {
  4966. // 小于分钟
  4967. var interval = tickInterval;
  4968. if (interval < SECOND) {
  4969. interval = SECOND;
  4970. }
  4971. var minSecond = Math.floor(min / SECOND) * SECOND;
  4972. var dSeconds = Math.ceil((max - min) / SECOND);
  4973. var seconds = Math.ceil(interval / SECOND);
  4974. for (var i = 0; i < dSeconds + seconds; i = i + seconds) {
  4975. ticks.push(minSecond + i * SECOND);
  4976. }
  4977. } // 最好是能从算法能解决这个问题,但是如果指定了 tickInterval,计算 ticks,也只能这么算,所以
  4978. // 打印警告提示
  4979. if (ticks.length >= 512) {
  4980. 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!");
  4981. }
  4982. return ticks;
  4983. }
  4984. registerTickMethod('cat', calculateCatTicks);
  4985. registerTickMethod('time-cat', calculateTimeCatTicks);
  4986. registerTickMethod('wilkinson-extended', linear$1);
  4987. registerTickMethod('r-pretty', linearPretty);
  4988. registerTickMethod('time', calculateTimeTicks);
  4989. registerTickMethod('time-pretty', timePretty);
  4990. registerTickMethod('log', calculateLogTicks);
  4991. registerTickMethod('pow', calculatePowTicks);
  4992. registerTickMethod('quantile', calculateTicks);
  4993. registerTickMethod('d3-linear', d3LinearTickMethod);
  4994. registerClass('cat', Category$1);
  4995. registerClass('category', Category$1);
  4996. registerClass('identity', Identity$1);
  4997. registerClass('linear', Linear$1);
  4998. registerClass('log', Log);
  4999. registerClass('pow', Pow);
  5000. registerClass('time', Time);
  5001. registerClass('timeCat', TimeCat$1);
  5002. registerClass('quantize', Quantize);
  5003. registerClass('quantile', Quantile);
  5004. // cat平均算法,保头保尾
  5005. var CatTick = (function (cfg) {
  5006. var values = cfg.values,
  5007. tickCount = cfg.tickCount;
  5008. if (!tickCount) {
  5009. return values;
  5010. }
  5011. if (values.length <= 1) {
  5012. return values;
  5013. } // 获取间隔步长, 最小是1
  5014. var step = parseInt(values.length / (tickCount - 1)) || 1;
  5015. var ticks = []; // 按间隔数取对应节点
  5016. for (var index = 0; index < values.length; index = index + step) {
  5017. ticks.push(values[index]);
  5018. }
  5019. var last = values[values.length - 1]; // 如果最后一个tick不等于原数据的最后一个
  5020. if (ticks[ticks.length - 1] !== last) {
  5021. if (ticks.length >= tickCount) {
  5022. // 如果当前的tick个数满足要求
  5023. ticks[ticks.length - 1] = last;
  5024. } else {
  5025. // 不满足tickCount则直接加入最后一个
  5026. ticks.push(last);
  5027. }
  5028. }
  5029. return ticks;
  5030. });
  5031. // 认为是nice的刻度
  5032. var SNAP_COUNT_ARRAY = [1, 1.2, 1.5, 2, 2.2, 2.4, 2.5, 3, 4, 5, 6, 7.5, 8, 10];
  5033. var DEFAULT_COUNT = 5; // 默认刻度值
  5034. var LinearTick = (function (cfg) {
  5035. var _ref = cfg || {},
  5036. tickCount = _ref.tickCount,
  5037. tickInterval = _ref.tickInterval;
  5038. var _ref2 = cfg || {},
  5039. min = _ref2.min,
  5040. max = _ref2.max;
  5041. min = isNaN(min) ? 0 : min;
  5042. max = isNaN(max) ? 0 : max;
  5043. var count = tickCount && tickCount >= 2 ? tickCount : DEFAULT_COUNT; // 计算interval, 优先取tickInterval
  5044. var interval = tickInterval || getBestInterval({
  5045. tickCount: count,
  5046. max: max,
  5047. min: min
  5048. }); // 通过interval计算最小tick
  5049. var minTick = Math.floor(min / interval) * interval; // 如果指定了tickInterval, count 需要根据指定的tickInterval来算计
  5050. if (tickInterval) {
  5051. var intervalCount = Math.abs(Math.ceil((max - minTick) / tickInterval)) + 1; // tickCount 作为最小 count 处理
  5052. count = Math.max(count, intervalCount);
  5053. }
  5054. var ticks = [];
  5055. var tickLength = 0;
  5056. var fixedLength = getFixedLength(interval);
  5057. while (tickLength < count) {
  5058. ticks.push(toFixed(minTick + tickLength * interval, fixedLength));
  5059. tickLength++;
  5060. }
  5061. return ticks;
  5062. });
  5063. var DECIMAL_LENGTH = 12;
  5064. function getFactor(number) {
  5065. // 取正数
  5066. number = Math.abs(number);
  5067. var factor = 1;
  5068. if (number === 0) {
  5069. return factor;
  5070. } // 小于1,逐渐放大
  5071. if (number < 1) {
  5072. var count = 0;
  5073. while (number < 1) {
  5074. factor = factor / 10;
  5075. number = number * 10;
  5076. count++;
  5077. } // 浮点数计算出现问题
  5078. if (factor.toString().length > DECIMAL_LENGTH) {
  5079. factor = parseFloat(factor.toFixed(count));
  5080. }
  5081. return factor;
  5082. } // 大于10逐渐缩小
  5083. while (number > 10) {
  5084. factor = factor * 10;
  5085. number = number / 10;
  5086. }
  5087. return factor;
  5088. } // 获取最佳匹配刻度
  5089. function getBestInterval(_ref3) {
  5090. var tickCount = _ref3.tickCount,
  5091. min = _ref3.min,
  5092. max = _ref3.max;
  5093. // 如果最大最小相等,则直接按1处理
  5094. if (min === max) {
  5095. return 1 * getFactor(max);
  5096. } // 1.计算平均刻度间隔
  5097. var avgInterval = (max - min) / (tickCount - 1); // 2.数据标准归一化 映射到[1-10]区间
  5098. var factor = getFactor(avgInterval);
  5099. var calInterval = avgInterval / factor;
  5100. var calMax = max / factor;
  5101. var calMin = min / factor; // 根据平均值推算最逼近刻度值
  5102. var similarityIndex = 0;
  5103. for (var index = 0; index < SNAP_COUNT_ARRAY.length; index++) {
  5104. var item = SNAP_COUNT_ARRAY[index];
  5105. if (calInterval <= item) {
  5106. similarityIndex = index;
  5107. break;
  5108. }
  5109. }
  5110. var similarityInterval = getInterval(similarityIndex, tickCount, calMin, calMax); // 小数点位数还原到数据的位数, 因为similarityIndex有可能是小数,所以需要保留similarityIndex自己的小数位数
  5111. var fixedLength = getFixedLength(similarityInterval) + getFixedLength(factor);
  5112. return toFixed(similarityInterval * factor, fixedLength);
  5113. }
  5114. function getInterval(startIndex, tickCount, min, max) {
  5115. var verify = false;
  5116. var interval = SNAP_COUNT_ARRAY[startIndex]; // 刻度值校验,如果不满足,循环下去
  5117. for (var i = startIndex; i < SNAP_COUNT_ARRAY.length; i++) {
  5118. if (intervalIsVerify({
  5119. interval: SNAP_COUNT_ARRAY[i],
  5120. tickCount: tickCount,
  5121. max: max,
  5122. min: min
  5123. })) {
  5124. // 有符合条件的interval
  5125. interval = SNAP_COUNT_ARRAY[i];
  5126. verify = true;
  5127. break;
  5128. }
  5129. } // 如果不满足, 依次缩小10倍,再计算
  5130. if (!verify) {
  5131. return 10 * getInterval(0, tickCount, min / 10, max / 10);
  5132. }
  5133. return interval;
  5134. } // 刻度是否满足展示需求
  5135. function intervalIsVerify(_ref4) {
  5136. var interval = _ref4.interval,
  5137. tickCount = _ref4.tickCount,
  5138. max = _ref4.max,
  5139. min = _ref4.min;
  5140. var minTick = Math.floor(min / interval) * interval;
  5141. if (minTick + (tickCount - 1) * interval >= max) {
  5142. return true;
  5143. }
  5144. return false;
  5145. } // 计算小数点应该保留的位数
  5146. function getFixedLength(num) {
  5147. var str = num.toString();
  5148. var index = str.indexOf('.');
  5149. var indexOfExp = str.indexOf('e-');
  5150. var length = indexOfExp >= 0 ? parseInt(str.substr(indexOfExp + 2), 10) : str.substr(index + 1).length;
  5151. if (length > 20) {
  5152. // 最多保留20位小数
  5153. length = 20;
  5154. }
  5155. return length;
  5156. } // @antv/util fixedbase不支持科学计数法的判断,需要提mr
  5157. function toFixed(v, length) {
  5158. return parseFloat(v.toFixed(length));
  5159. }
  5160. var Linear = getClass('linear');
  5161. var Identity = getClass('identity');
  5162. var Category = getClass('category');
  5163. var TimeCat = getClass('timeCat'); // 覆盖0.3.x的 cat 方法
  5164. registerTickMethod('cat', CatTick);
  5165. registerTickMethod('time-cat', CatTick); // 覆盖linear 度量的tick算法
  5166. registerTickMethod('wilkinson-extended', LinearTick);
  5167. Scale.Linear = Linear;
  5168. Scale.Identity = Identity;
  5169. Scale.Category = Category;
  5170. Scale.Cat = Category;
  5171. Scale.TimeCat = TimeCat;
  5172. function isFullCircle(coord) {
  5173. if (!coord.isPolar) {
  5174. return false;
  5175. }
  5176. var startAngle = coord.startAngle;
  5177. var endAngle = coord.endAngle;
  5178. if (!isNil$1(startAngle) && !isNil$1(endAngle) && endAngle - startAngle < Math.PI * 2) {
  5179. return false;
  5180. }
  5181. return true;
  5182. }
  5183. function clearObj(obj) {
  5184. Object.keys(obj).forEach(function (key) {
  5185. delete obj[key];
  5186. });
  5187. }
  5188. var ScaleController = /*#__PURE__*/function () {
  5189. function ScaleController(cfg) {
  5190. // defs 列定义
  5191. this.defs = {}; // 已经实例化的scale
  5192. this.scales = {};
  5193. mix$1(this, cfg);
  5194. }
  5195. var _proto = ScaleController.prototype;
  5196. _proto.setFieldDef = function setFieldDef(field, cfg) {
  5197. var defs = this.defs;
  5198. if (isObject$1(field)) {
  5199. mix$1(defs, field);
  5200. } else {
  5201. defs[field] = cfg;
  5202. } // 因为可能同时变更多个scale,所以要把所有已实例化的scale都更新下
  5203. this.updateScales();
  5204. };
  5205. _proto._getDef = function _getDef(field) {
  5206. var defs = this.defs;
  5207. var def = null;
  5208. if (Global.scales[field] || defs[field]) {
  5209. def = mix$1({}, Global.scales[field]);
  5210. each$1(defs[field], function (v, k) {
  5211. if (isNil$1(v)) {
  5212. delete def[k];
  5213. } else {
  5214. def[k] = v;
  5215. }
  5216. });
  5217. }
  5218. return def;
  5219. };
  5220. _proto._getDefaultType = function _getDefaultType(field, data, def) {
  5221. if (def && def.type) {
  5222. return def.type;
  5223. }
  5224. var type = 'linear';
  5225. var value = firstValue(data, field);
  5226. if (isArray$1(value)) {
  5227. value = value[0];
  5228. }
  5229. if (isString(value)) {
  5230. type = 'cat';
  5231. }
  5232. return type;
  5233. };
  5234. _proto._getScaleDef = function _getScaleDef(type, field, data, def) {
  5235. var values$1;
  5236. if (def && def.values) {
  5237. values$1 = def.values;
  5238. } else {
  5239. values$1 = values(data, field);
  5240. }
  5241. var cfg = {
  5242. field: field,
  5243. values: values$1
  5244. };
  5245. if (type !== 'cat' && type !== 'timeCat') {
  5246. if (!def || !(def.min && def.max)) {
  5247. var _Array$getRange = getRange(values$1),
  5248. min = _Array$getRange.min,
  5249. max = _Array$getRange.max;
  5250. cfg.min = min;
  5251. cfg.max = max;
  5252. cfg.nice = true;
  5253. }
  5254. } else {
  5255. cfg.isRounding = false; // used for tickCount calculation
  5256. }
  5257. return cfg;
  5258. } // 调整range,为了让图形居中
  5259. ;
  5260. _proto._adjustRange = function _adjustRange(type, cfg) {
  5261. var range = cfg.range,
  5262. values = cfg.values; // 如果是线性, 或者有自定义range都不处理
  5263. if (type === 'linear' || range || !values) {
  5264. return cfg;
  5265. }
  5266. var count = values.length; // 单只有一条数据时,在中间显示
  5267. if (count === 1) {
  5268. cfg.range = [0.5, 1];
  5269. } else {
  5270. var chart = this.chart;
  5271. var coord = chart.get('coord');
  5272. var widthRatio = Global.widthRatio.multiplePie;
  5273. var offset = 0;
  5274. if (isFullCircle(coord)) {
  5275. if (!coord.transposed) {
  5276. cfg.range = [0, 1 - 1 / count];
  5277. } else {
  5278. offset = 1 / count * widthRatio;
  5279. cfg.range = [offset / 2, 1 - offset / 2];
  5280. }
  5281. } else {
  5282. // 为了让图形居中,所以才设置range
  5283. offset = 1 / count * 0.5; // 这里可能用0.25会更合理
  5284. cfg.range = [offset, 1 - offset];
  5285. }
  5286. }
  5287. return cfg;
  5288. };
  5289. _proto._getScaleCfg = function _getScaleCfg(field, data) {
  5290. var self = this;
  5291. var def = self._getDef(field);
  5292. if (!data || !data.length) {
  5293. if (def && def.type) {
  5294. def.field = field;
  5295. return {
  5296. type: def.type,
  5297. cfg: def
  5298. };
  5299. }
  5300. return {
  5301. type: 'identity',
  5302. cfg: {
  5303. value: field,
  5304. field: field.toString(),
  5305. values: [field]
  5306. }
  5307. };
  5308. }
  5309. var firstObj = data[0];
  5310. var firstValue$1 = firstObj[field];
  5311. if (firstValue$1 === null) {
  5312. firstValue$1 = firstValue(data, field);
  5313. }
  5314. if (isNumber(field) || isNil$1(firstValue$1) && !def) {
  5315. return {
  5316. type: 'identity',
  5317. cfg: {
  5318. value: field,
  5319. field: field.toString(),
  5320. values: [field]
  5321. }
  5322. };
  5323. }
  5324. var type = self._getDefaultType(field, data, def);
  5325. var cfg = self._getScaleDef(type, field, data, def);
  5326. def && mix$1(cfg, def);
  5327. cfg = this._adjustRange(type, cfg);
  5328. return {
  5329. type: type,
  5330. cfg: cfg
  5331. };
  5332. };
  5333. _proto.createScale = function createScale(field, data) {
  5334. var scales = this.scales;
  5335. var _this$_getScaleCfg = this._getScaleCfg(field, data),
  5336. type = _this$_getScaleCfg.type,
  5337. cfg = _this$_getScaleCfg.cfg;
  5338. var scale = scales[field]; // 如果已经存在,且类型相等时直接返回
  5339. if (scale && scale.type === type) {
  5340. scale.change(cfg);
  5341. return scale;
  5342. }
  5343. var Scale = getClass(type);
  5344. var newScale = new Scale(cfg);
  5345. scales[field] = newScale;
  5346. return newScale;
  5347. };
  5348. _proto._updateScale = function _updateScale(scale) {
  5349. var field = scale.field; // 因为每个field的数据都会不同
  5350. var data = this.chart._getScaleData(field);
  5351. var _this$_getScaleCfg2 = this._getScaleCfg(field, data),
  5352. cfg = _this$_getScaleCfg2.cfg;
  5353. scale.change(cfg);
  5354. };
  5355. _proto.updateScales = function updateScales() {
  5356. var _this = this;
  5357. var scales = this.scales; // 修改完列定义后,需要更新已经实例化的scale
  5358. // 如果是还没有实例化的,在geom初始化的时候会被实例化,所以这里可以不用更新
  5359. each$1(scales, function (scale) {
  5360. _this._updateScale(scale);
  5361. });
  5362. } // 调整scale从0开始
  5363. ;
  5364. _proto.adjustStartZero = function adjustStartZero(scale) {
  5365. var defs = this.defs;
  5366. var field = scale.field,
  5367. min = scale.min,
  5368. max = scale.max; // 如果有定义,则不处理
  5369. if (defs[field] && defs[field].min) {
  5370. return;
  5371. }
  5372. if (min > 0) {
  5373. scale.change({
  5374. min: 0
  5375. });
  5376. } else if (max < 0) {
  5377. scale.change({
  5378. max: 0
  5379. });
  5380. }
  5381. };
  5382. _proto.clear = function clear() {
  5383. // this.defs = {};
  5384. // this.scales = {};
  5385. clearObj(this.defs);
  5386. clearObj(this.scales);
  5387. this.data = null;
  5388. };
  5389. return ScaleController;
  5390. }();
  5391. var Abastract = /*#__PURE__*/function () {
  5392. var _proto = Abastract.prototype;
  5393. _proto._initDefaultCfg = function _initDefaultCfg() {
  5394. /**
  5395. * ticks
  5396. * @type {Array}
  5397. */
  5398. this.ticks = [];
  5399. /**
  5400. * the configuration for tickLine
  5401. * @type {Object}
  5402. */
  5403. this.tickLine = {};
  5404. /**
  5405. * the direction of ticks, 1 means clockwise
  5406. * @type {Number}
  5407. */
  5408. this.offsetFactor = 1;
  5409. /**
  5410. * the top container
  5411. * @type {container}
  5412. */
  5413. this.frontContainer = null;
  5414. /**
  5415. * the back container
  5416. * @type {[type]}
  5417. */
  5418. this.backContainer = null;
  5419. /**
  5420. * points for draw grid line
  5421. * @type {Array}
  5422. */
  5423. this.gridPoints = [];
  5424. };
  5425. function Abastract(cfg) {
  5426. this._initDefaultCfg();
  5427. mix$1(this, cfg);
  5428. this.draw();
  5429. }
  5430. _proto.draw = function draw() {
  5431. var line = this.line,
  5432. tickLine = this.tickLine,
  5433. label = this.label,
  5434. grid = this.grid;
  5435. grid && this.drawGrid(grid); // draw the grid lines
  5436. tickLine && this.drawTicks(tickLine); // draw the tickLine
  5437. line && this.drawLine(line); // draw axis line
  5438. label && this.drawLabels(); // draw ticks
  5439. };
  5440. _proto.drawTicks = function drawTicks(tickCfg) {
  5441. var self = this;
  5442. var ticks = self.ticks;
  5443. var length = tickCfg.length;
  5444. var container = self.getContainer(tickCfg.top);
  5445. each$1(ticks, function (tick) {
  5446. var start = self.getOffsetPoint(tick.value);
  5447. var end = self.getSidePoint(start, length);
  5448. var shape = container.addShape('line', {
  5449. className: 'axis-tick',
  5450. attrs: mix$1({
  5451. x1: start.x,
  5452. y1: start.y,
  5453. x2: end.x,
  5454. y2: end.y
  5455. }, tickCfg)
  5456. });
  5457. shape._id = self._id + '-ticks';
  5458. });
  5459. };
  5460. _proto.drawLabels = function drawLabels() {
  5461. var self = this;
  5462. var labelOffset = self.labelOffset;
  5463. var labels = self.labels;
  5464. each$1(labels, function (labelShape) {
  5465. var container = self.getContainer(labelShape.get('top'));
  5466. var start = self.getOffsetPoint(labelShape.get('value'));
  5467. var _self$getSidePoint = self.getSidePoint(start, labelOffset),
  5468. x = _self$getSidePoint.x,
  5469. y = _self$getSidePoint.y;
  5470. labelShape.attr(mix$1({
  5471. x: x,
  5472. y: y
  5473. }, self.getTextAlignInfo(start, labelOffset), labelShape.get('textStyle')));
  5474. labelShape._id = self._id + '-' + labelShape.attr('text');
  5475. container.add(labelShape);
  5476. });
  5477. };
  5478. _proto.drawLine = function drawLine() {};
  5479. _proto.drawGrid = function drawGrid(grid) {
  5480. var self = this;
  5481. var gridPoints = self.gridPoints,
  5482. ticks = self.ticks;
  5483. var gridCfg = grid;
  5484. var count = gridPoints.length;
  5485. each$1(gridPoints, function (subPoints, index) {
  5486. if (isFunction$1(grid)) {
  5487. var tick = ticks[index] || {};
  5488. var executedGrid = grid(tick.text, index, count);
  5489. gridCfg = executedGrid ? mix$1({}, Global._defaultAxis.grid, executedGrid) : null;
  5490. }
  5491. if (gridCfg) {
  5492. var type = gridCfg.type; // has two types: 'line' and 'arc'
  5493. var points = subPoints.points;
  5494. var container = self.getContainer(gridCfg.top);
  5495. var shape;
  5496. if (type === 'arc') {
  5497. var center = self.center,
  5498. startAngle = self.startAngle,
  5499. endAngle = self.endAngle;
  5500. var radius = Vector2.length([points[0].x - center.x, points[0].y - center.y]);
  5501. shape = container.addShape('Arc', {
  5502. className: 'axis-grid',
  5503. attrs: mix$1({
  5504. x: center.x,
  5505. y: center.y,
  5506. startAngle: startAngle,
  5507. endAngle: endAngle,
  5508. r: radius
  5509. }, gridCfg)
  5510. });
  5511. } else {
  5512. shape = container.addShape('Polyline', {
  5513. className: 'axis-grid',
  5514. attrs: mix$1({
  5515. points: points
  5516. }, gridCfg)
  5517. });
  5518. }
  5519. shape._id = subPoints._id;
  5520. }
  5521. });
  5522. };
  5523. _proto.getOffsetPoint = function getOffsetPoint() {};
  5524. _proto.getAxisVector = function getAxisVector() {};
  5525. _proto.getOffsetVector = function getOffsetVector(point, offset) {
  5526. var self = this;
  5527. var axisVector = self.getAxisVector(point);
  5528. var normal = Vector2.normalize([], axisVector);
  5529. var factor = self.offsetFactor;
  5530. var verticalVector = [normal[1] * -1 * factor, normal[0] * factor];
  5531. return Vector2.scale([], verticalVector, offset);
  5532. };
  5533. _proto.getSidePoint = function getSidePoint(point, offset) {
  5534. var self = this;
  5535. var offsetVector = self.getOffsetVector(point, offset);
  5536. return {
  5537. x: point.x + offsetVector[0],
  5538. y: point.y + offsetVector[1]
  5539. };
  5540. };
  5541. _proto.getTextAlignInfo = function getTextAlignInfo(point, offset) {
  5542. var self = this;
  5543. var offsetVector = self.getOffsetVector(point, offset);
  5544. var align;
  5545. var baseLine;
  5546. if (offsetVector[0] > 0) {
  5547. align = 'left';
  5548. } else if (offsetVector[0] < 0) {
  5549. align = 'right';
  5550. } else {
  5551. align = 'center';
  5552. }
  5553. if (offsetVector[1] > 0) {
  5554. baseLine = 'top';
  5555. } else if (offsetVector[1] < 0) {
  5556. baseLine = 'bottom';
  5557. } else {
  5558. baseLine = 'middle';
  5559. }
  5560. return {
  5561. textAlign: align,
  5562. textBaseline: baseLine
  5563. };
  5564. };
  5565. _proto.getContainer = function getContainer(isTop) {
  5566. var frontContainer = this.frontContainer,
  5567. backContainer = this.backContainer;
  5568. return isTop ? frontContainer : backContainer;
  5569. };
  5570. return Abastract;
  5571. }();
  5572. var Line$3 = /*#__PURE__*/function (_Abstract) {
  5573. _inheritsLoose$3(Line, _Abstract);
  5574. function Line() {
  5575. return _Abstract.apply(this, arguments) || this;
  5576. }
  5577. var _proto = Line.prototype;
  5578. _proto._initDefaultCfg = function _initDefaultCfg() {
  5579. _Abstract.prototype._initDefaultCfg.call(this);
  5580. this.start = null;
  5581. this.end = null;
  5582. };
  5583. _proto.getOffsetPoint = function getOffsetPoint(value) {
  5584. var start = this.start,
  5585. end = this.end;
  5586. return {
  5587. x: start.x + (end.x - start.x) * value,
  5588. y: start.y + (end.y - start.y) * value
  5589. };
  5590. };
  5591. _proto.getAxisVector = function getAxisVector() {
  5592. var start = this.start,
  5593. end = this.end;
  5594. return [end.x - start.x, end.y - start.y];
  5595. };
  5596. _proto.drawLine = function drawLine(lineCfg) {
  5597. var container = this.getContainer(lineCfg.top);
  5598. var start = this.start,
  5599. end = this.end;
  5600. container.addShape('line', {
  5601. className: 'axis-line',
  5602. attrs: mix$1({
  5603. x1: start.x,
  5604. y1: start.y,
  5605. x2: end.x,
  5606. y2: end.y
  5607. }, lineCfg)
  5608. });
  5609. };
  5610. return Line;
  5611. }(Abastract);
  5612. Abastract.Line = Line$3;
  5613. function formatTicks(ticks) {
  5614. var tmp = ticks.slice(0);
  5615. if (tmp.length > 0) {
  5616. var first = tmp[0];
  5617. var last = tmp[tmp.length - 1];
  5618. if (first.value !== 0) {
  5619. tmp.unshift({
  5620. value: 0
  5621. });
  5622. }
  5623. if (last.value !== 1) {
  5624. tmp.push({
  5625. value: 1
  5626. });
  5627. }
  5628. }
  5629. return tmp;
  5630. }
  5631. var AxisController = /*#__PURE__*/function () {
  5632. function AxisController(cfg) {
  5633. this.axisCfg = {};
  5634. this.frontPlot = null;
  5635. this.backPlot = null;
  5636. this.axes = {}; // store the axes's options
  5637. mix$1(this, cfg);
  5638. }
  5639. var _proto = AxisController.prototype;
  5640. _proto._isHide = function _isHide(field) {
  5641. var axisCfg = this.axisCfg;
  5642. return !axisCfg || axisCfg[field] === false;
  5643. };
  5644. _proto._getLinePosition = function _getLinePosition(scale, dimType, index, transposed) {
  5645. var position = '';
  5646. var field = scale.field;
  5647. var axisCfg = this.axisCfg;
  5648. if (axisCfg[field] && axisCfg[field].position) {
  5649. position = axisCfg[field].position;
  5650. } else if (dimType === 'x') {
  5651. position = transposed ? 'left' : 'bottom';
  5652. } else if (dimType === 'y') {
  5653. position = index ? 'right' : 'left';
  5654. if (transposed) {
  5655. position = 'bottom';
  5656. }
  5657. }
  5658. return position;
  5659. };
  5660. _proto._getLineCfg = function _getLineCfg(coord, dimType, position) {
  5661. var start;
  5662. var end;
  5663. var factor = 1; // Mark clockwise or counterclockwise
  5664. if (dimType === 'x') {
  5665. start = {
  5666. x: 0,
  5667. y: 0
  5668. };
  5669. end = {
  5670. x: 1,
  5671. y: 0
  5672. };
  5673. } else {
  5674. if (position === 'right') {
  5675. // there will be several y axes
  5676. start = {
  5677. x: 1,
  5678. y: 0
  5679. };
  5680. end = {
  5681. x: 1,
  5682. y: 1
  5683. };
  5684. } else {
  5685. start = {
  5686. x: 0,
  5687. y: 0
  5688. };
  5689. end = {
  5690. x: 0,
  5691. y: 1
  5692. };
  5693. factor = -1;
  5694. }
  5695. }
  5696. if (coord.transposed) {
  5697. factor *= -1;
  5698. }
  5699. return {
  5700. offsetFactor: factor,
  5701. start: coord.convertPoint(start),
  5702. end: coord.convertPoint(end)
  5703. };
  5704. };
  5705. _proto._getCircleCfg = function _getCircleCfg(coord) {
  5706. return {
  5707. startAngle: coord.startAngle,
  5708. endAngle: coord.endAngle,
  5709. center: coord.center,
  5710. radius: coord.circleRadius
  5711. };
  5712. };
  5713. _proto._getRadiusCfg = function _getRadiusCfg(coord) {
  5714. var transposed = coord.transposed;
  5715. var start;
  5716. var end;
  5717. if (transposed) {
  5718. start = {
  5719. x: 0,
  5720. y: 0
  5721. };
  5722. end = {
  5723. x: 1,
  5724. y: 0
  5725. };
  5726. } else {
  5727. start = {
  5728. x: 0,
  5729. y: 0
  5730. };
  5731. end = {
  5732. x: 0,
  5733. y: 1
  5734. };
  5735. }
  5736. return {
  5737. offsetFactor: -1,
  5738. start: coord.convertPoint(start),
  5739. end: coord.convertPoint(end)
  5740. };
  5741. };
  5742. _proto._getAxisCfg = function _getAxisCfg(coord, scale, verticalScale, dimType, defaultCfg) {
  5743. var _this = this;
  5744. var self = this;
  5745. var axisCfg = this.axisCfg;
  5746. var ticks = scale.getTicks();
  5747. var cfg = deepMix({
  5748. ticks: ticks,
  5749. frontContainer: this.frontPlot,
  5750. backContainer: this.backPlot
  5751. }, defaultCfg, axisCfg[scale.field]);
  5752. var labels = [];
  5753. var label = cfg.label;
  5754. var count = ticks.length;
  5755. var maxWidth = 0;
  5756. var maxHeight = 0;
  5757. var labelCfg = label;
  5758. each$1(ticks, function (tick, index) {
  5759. if (isFunction$1(label)) {
  5760. var executedLabel = label(tick.text, index, count);
  5761. labelCfg = executedLabel ? mix$1({}, Global._defaultAxis.label, executedLabel) : null;
  5762. }
  5763. if (labelCfg) {
  5764. var textStyle = {};
  5765. if (labelCfg.textAlign) {
  5766. textStyle.textAlign = labelCfg.textAlign;
  5767. }
  5768. if (labelCfg.textBaseline) {
  5769. textStyle.textBaseline = labelCfg.textBaseline;
  5770. }
  5771. var container = labelCfg.top ? _this.frontPlot : _this.backPlot;
  5772. var axisLabel = container.addShape('text', {
  5773. className: 'axis-label',
  5774. aria: false,
  5775. attrs: mix$1({
  5776. x: 0,
  5777. y: 0,
  5778. text: tick.text,
  5779. fontFamily: self.chart.get('canvas').get('fontFamily')
  5780. }, labelCfg),
  5781. value: tick.value,
  5782. textStyle: textStyle,
  5783. top: labelCfg.top,
  5784. context: self.chart.get('canvas').get('context')
  5785. });
  5786. labels.push(axisLabel);
  5787. var _axisLabel$getBBox = axisLabel.getBBox(),
  5788. width = _axisLabel$getBBox.width,
  5789. height = _axisLabel$getBBox.height;
  5790. maxWidth = Math.max(maxWidth, width);
  5791. maxHeight = Math.max(maxHeight, height);
  5792. }
  5793. });
  5794. cfg.labels = labels;
  5795. cfg.maxWidth = maxWidth;
  5796. cfg.maxHeight = maxHeight;
  5797. return cfg;
  5798. };
  5799. _proto._createAxis = function _createAxis(coord, scale, verticalScale, dimType, index) {
  5800. if (index === void 0) {
  5801. index = '';
  5802. }
  5803. var self = this;
  5804. var coordType = coord.type;
  5805. var transposed = coord.transposed;
  5806. var type;
  5807. var key;
  5808. var defaultCfg;
  5809. if (coordType === 'cartesian' || coordType === 'rect') {
  5810. var position = self._getLinePosition(scale, dimType, index, transposed);
  5811. defaultCfg = Global.axis[position];
  5812. defaultCfg.position = position;
  5813. type = 'Line';
  5814. key = position;
  5815. } else {
  5816. if (dimType === 'x' && !transposed || dimType === 'y' && transposed) {
  5817. defaultCfg = Global.axis.circle;
  5818. type = 'Circle';
  5819. key = 'circle';
  5820. } else {
  5821. defaultCfg = Global.axis.radius;
  5822. type = 'Line';
  5823. key = 'radius';
  5824. }
  5825. }
  5826. var cfg = self._getAxisCfg(coord, scale, verticalScale, dimType, defaultCfg);
  5827. cfg.type = type;
  5828. cfg.dimType = dimType;
  5829. cfg.verticalScale = verticalScale;
  5830. cfg.index = index;
  5831. this.axes[key] = cfg;
  5832. };
  5833. _proto.createAxis = function createAxis(coord, xScale, yScales) {
  5834. var self = this;
  5835. if (xScale && !self._isHide(xScale.field)) {
  5836. self._createAxis(coord, xScale, yScales[0], 'x');
  5837. }
  5838. each$1(yScales, function (yScale, index) {
  5839. if (!self._isHide(yScale.field)) {
  5840. self._createAxis(coord, yScale, xScale, 'y', index);
  5841. }
  5842. });
  5843. var axes = this.axes;
  5844. var chart = self.chart;
  5845. if (chart._isAutoPadding()) {
  5846. var userPadding = parsePadding(chart.get('padding'));
  5847. var appendPadding = parsePadding(chart.get('appendPadding'));
  5848. var legendRange = chart.get('legendRange') || {
  5849. top: 0,
  5850. right: 0,
  5851. bottom: 0,
  5852. left: 0
  5853. };
  5854. var padding = [userPadding[0] === 'auto' ? legendRange.top + appendPadding[0] * 2 : userPadding[0], userPadding[1] === 'auto' ? legendRange.right + appendPadding[1] : userPadding[1], userPadding[2] === 'auto' ? legendRange.bottom + appendPadding[2] : userPadding[2], userPadding[3] === 'auto' ? legendRange.left + appendPadding[3] : userPadding[3]];
  5855. if (coord.isPolar) {
  5856. var circleAxis = axes.circle;
  5857. if (circleAxis) {
  5858. var maxHeight = circleAxis.maxHeight,
  5859. maxWidth = circleAxis.maxWidth,
  5860. labelOffset = circleAxis.labelOffset;
  5861. padding[0] += maxHeight + labelOffset;
  5862. padding[1] += maxWidth + labelOffset;
  5863. padding[2] += maxHeight + labelOffset;
  5864. padding[3] += maxWidth + labelOffset;
  5865. }
  5866. } else {
  5867. if (axes.right && userPadding[1] === 'auto') {
  5868. var _axes$right = axes.right,
  5869. _maxWidth = _axes$right.maxWidth,
  5870. _labelOffset = _axes$right.labelOffset;
  5871. padding[1] += _maxWidth + _labelOffset;
  5872. }
  5873. if (axes.left && userPadding[3] === 'auto') {
  5874. var _axes$left = axes.left,
  5875. _maxWidth2 = _axes$left.maxWidth,
  5876. _labelOffset2 = _axes$left.labelOffset;
  5877. padding[3] += _maxWidth2 + _labelOffset2;
  5878. }
  5879. if (axes.bottom && userPadding[2] === 'auto') {
  5880. var _axes$bottom = axes.bottom,
  5881. _maxHeight = _axes$bottom.maxHeight,
  5882. _labelOffset3 = _axes$bottom.labelOffset;
  5883. padding[2] += _maxHeight + _labelOffset3;
  5884. }
  5885. }
  5886. chart.set('_padding', padding);
  5887. chart._updateLayout(padding);
  5888. }
  5889. each$1(axes, function (axis) {
  5890. var type = axis.type,
  5891. grid = axis.grid,
  5892. verticalScale = axis.verticalScale,
  5893. ticks = axis.ticks,
  5894. dimType = axis.dimType,
  5895. position = axis.position,
  5896. index = axis.index;
  5897. var appendCfg;
  5898. if (coord.isPolar) {
  5899. if (type === 'Line') {
  5900. appendCfg = self._getRadiusCfg(coord);
  5901. } else if (type === 'Circle') {
  5902. appendCfg = self._getCircleCfg(coord);
  5903. }
  5904. } else {
  5905. appendCfg = self._getLineCfg(coord, dimType, position);
  5906. }
  5907. if (grid && verticalScale) {
  5908. var gridPoints = [];
  5909. var verticalTicks = formatTicks(verticalScale.getTicks());
  5910. each$1(ticks, function (tick) {
  5911. var subPoints = [];
  5912. each$1(verticalTicks, function (verticalTick) {
  5913. var x = dimType === 'x' ? tick.value : verticalTick.value;
  5914. var y = dimType === 'x' ? verticalTick.value : tick.value;
  5915. if (x >= 0 && x <= 1 && y >= 0 && y <= 1) {
  5916. var point = coord.convertPoint({
  5917. x: x,
  5918. y: y
  5919. });
  5920. subPoints.push(point);
  5921. }
  5922. });
  5923. gridPoints.push({
  5924. points: subPoints,
  5925. _id: 'axis-' + dimType + index + '-grid-' + tick.tickValue
  5926. });
  5927. });
  5928. axis.gridPoints = gridPoints;
  5929. if (coord.isPolar) {
  5930. axis.center = coord.center;
  5931. axis.startAngle = coord.startAngle;
  5932. axis.endAngle = coord.endAngle;
  5933. }
  5934. }
  5935. appendCfg._id = 'axis-' + dimType;
  5936. if (!isNil$1(index)) {
  5937. appendCfg._id = 'axis-' + dimType + index;
  5938. }
  5939. new Abastract[type](mix$1(axis, appendCfg));
  5940. });
  5941. };
  5942. _proto.clear = function clear() {
  5943. this.axes = {};
  5944. this.frontPlot.clear();
  5945. this.backPlot.clear();
  5946. };
  5947. return AxisController;
  5948. }();
  5949. var calcDirection = function calcDirection(start, end) {
  5950. var xDistance = end.x - start.x;
  5951. var yDistance = end.y - start.y; // x 的距离大于y 说明是横向,否则就是纵向
  5952. if (Math.abs(xDistance) > Math.abs(yDistance)) {
  5953. return xDistance > 0 ? 'right' : 'left';
  5954. }
  5955. return yDistance > 0 ? 'down' : 'up';
  5956. }; // 计算2点之间的距离
  5957. var calcDistance = function calcDistance(point1, point2) {
  5958. var xDistance = Math.abs(point2.x - point1.x);
  5959. var yDistance = Math.abs(point2.y - point1.y);
  5960. return Math.sqrt(xDistance * xDistance + yDistance * yDistance);
  5961. };
  5962. var getCenter = function getCenter(point1, point2) {
  5963. var x = point1.x + (point2.x - point1.x) / 2;
  5964. var y = point1.y + (point2.y - point1.y) / 2;
  5965. return {
  5966. x: x,
  5967. y: y
  5968. };
  5969. };
  5970. var PRESS_DELAY = 250;
  5971. var EventController = /*#__PURE__*/function () {
  5972. function EventController(_ref) {
  5973. var _this = this;
  5974. var canvas = _ref.canvas,
  5975. el = _ref.el;
  5976. _defineProperty(this, "_click", function (ev) {
  5977. var points = convertPoints(ev, _this.canvas);
  5978. ev.points = points;
  5979. _this.emitEvent('click', ev);
  5980. });
  5981. _defineProperty(this, "_start", function (ev) {
  5982. var points = convertPoints(ev, _this.canvas);
  5983. if (!points) {
  5984. return;
  5985. }
  5986. ev.points = points;
  5987. _this.emitEvent('touchstart', ev); // 防止上次的内容没有清理掉,重新reset下
  5988. _this.reset(); // 记录touch start 的时间
  5989. _this.startTime = Date.now(); // 记录touch start 的点
  5990. _this.startPoints = points;
  5991. if (points.length > 1) {
  5992. _this.startDistance = calcDistance(points[0], points[1]);
  5993. _this.center = getCenter(points[0], points[1]);
  5994. } else {
  5995. // 如果touchstart后停顿250ms, 则也触发press事件
  5996. _this.pressTimeout = setTimeout(function () {
  5997. // 这里固定触发press事件
  5998. var eventType = 'press';
  5999. var direction = 'none';
  6000. ev.direction = direction;
  6001. _this.emitStart(eventType, ev);
  6002. _this.emitEvent(eventType, ev);
  6003. _this.eventType = eventType;
  6004. _this.direction = direction;
  6005. }, PRESS_DELAY);
  6006. }
  6007. });
  6008. _defineProperty(this, "_move", function (ev) {
  6009. var points = convertPoints(ev, _this.canvas);
  6010. if (!points) return;
  6011. _this.clearPressTimeout();
  6012. ev.points = points;
  6013. _this.emitEvent('touchmove', ev);
  6014. var startPoints = _this.startPoints;
  6015. if (!startPoints) return; // 多指触控
  6016. if (points.length > 1) {
  6017. // touchstart的距离
  6018. var startDistance = _this.startDistance;
  6019. var currentDistance = calcDistance(points[0], points[1]);
  6020. ev.zoom = currentDistance / startDistance;
  6021. ev.center = _this.center; // 触发缩放事件
  6022. _this.emitStart('pinch', ev);
  6023. _this.emitEvent('pinch', ev);
  6024. } else {
  6025. var deltaX = points[0].x - startPoints[0].x;
  6026. var deltaY = points[0].y - startPoints[0].y;
  6027. var direction = _this.direction || calcDirection(startPoints[0], points[0]);
  6028. _this.direction = direction; // 获取press或者pan的事件类型
  6029. // press 按住滑动, pan表示平移
  6030. // 如果start后立刻move,则触发pan, 如果有停顿,则触发press
  6031. var eventType = _this.getEventType(points);
  6032. ev.direction = direction;
  6033. ev.deltaX = deltaX;
  6034. ev.deltaY = deltaY;
  6035. _this.emitStart(eventType, ev);
  6036. _this.emitEvent(eventType, ev); // 记录最后2次move的时间和坐标,为了给swipe事件用
  6037. var prevMoveTime = _this.lastMoveTime;
  6038. var now = Date.now(); // 最后2次的时间间隔一定要大于0,否则swipe没发计算
  6039. if (now - prevMoveTime > 0) {
  6040. _this.prevMoveTime = prevMoveTime;
  6041. _this.prevMovePoints = _this.lastMovePoints;
  6042. _this.lastMoveTime = now;
  6043. _this.lastMovePoints = points;
  6044. }
  6045. }
  6046. });
  6047. _defineProperty(this, "_end", function (ev) {
  6048. var points = convertPoints(ev, _this.canvas);
  6049. ev.points = points;
  6050. _this.emitEnd(ev);
  6051. _this.emitEvent('touchend', ev); // swipe事件处理, 在touchend之后触发
  6052. var lastMoveTime = _this.lastMoveTime;
  6053. var now = Date.now(); // 做这个判断是为了最后一次touchmove后到end前,还有一个停顿的过程
  6054. // 100 是拍的一个值,理论这个值会很短,一般不卡顿的话在10ms以内
  6055. if (now - lastMoveTime < 100) {
  6056. var prevMoveTime = _this.prevMoveTime || _this.startTime;
  6057. var intervalTime = lastMoveTime - prevMoveTime; // 时间间隔一定要大于0, 否则计算没意义
  6058. if (intervalTime > 0) {
  6059. var prevMovePoints = _this.prevMovePoints || _this.startPoints;
  6060. var lastMovePoints = _this.lastMovePoints; // move速率
  6061. var velocity = calcDistance(prevMovePoints[0], lastMovePoints[0]) / intervalTime; // 0.3 是参考hammerjs的设置
  6062. if (velocity > 0.3) {
  6063. ev.velocity = velocity;
  6064. ev.direction = calcDirection(prevMovePoints[0], lastMovePoints[0]);
  6065. _this.emitEvent('swipe', ev);
  6066. }
  6067. }
  6068. }
  6069. _this.reset();
  6070. var touches = ev.touches; // 当多指只释放了1指时也会触发end, 这时重新触发一次start
  6071. if (touches && touches.length > 0) {
  6072. _this._start(ev);
  6073. }
  6074. });
  6075. _defineProperty(this, "_cancel", function (ev) {
  6076. _this.emitEvent('touchcancel', ev);
  6077. _this.reset();
  6078. });
  6079. // canvasEl
  6080. this.canvas = canvas;
  6081. this.delegateEvent(el); // 用来记录当前触发的事件
  6082. this.processEvent = {};
  6083. }
  6084. var _proto = EventController.prototype;
  6085. _proto.delegateEvent = function delegateEvent(canvasEl) {
  6086. // 代理这几个事件
  6087. canvasEl.addEventListener('click', this._click);
  6088. canvasEl.addEventListener('touchstart', this._start);
  6089. canvasEl.addEventListener('touchmove', this._move);
  6090. canvasEl.addEventListener('touchend', this._end);
  6091. canvasEl.addEventListener('touchcancel', this._cancel);
  6092. };
  6093. _proto.emitEvent = function emitEvent(type, ev) {
  6094. var canvas = this.canvas;
  6095. canvas.emit(type, ev);
  6096. };
  6097. _proto.getEventType = function getEventType(points) {
  6098. var eventType = this.eventType,
  6099. canvas = this.canvas,
  6100. startTime = this.startTime,
  6101. startPoints = this.startPoints;
  6102. if (eventType) {
  6103. return eventType;
  6104. }
  6105. var type;
  6106. var panEventListeners = canvas.__events.pan; // 如果没有pan事件的监听,默认都是press
  6107. if (!panEventListeners || !panEventListeners.length) {
  6108. type = 'press';
  6109. } else {
  6110. // 如果有pan事件的处理,press则需要停顿250ms, 且移动距离小于10
  6111. var now = Date.now();
  6112. if (now - startTime > PRESS_DELAY && calcDistance(startPoints[0], points[0]) < 10) {
  6113. type = 'press';
  6114. } else {
  6115. type = 'pan';
  6116. }
  6117. }
  6118. this.eventType = type;
  6119. return type;
  6120. };
  6121. _proto.enable = function enable(eventType) {
  6122. this.processEvent[eventType] = true;
  6123. } // 是否进行中的事件
  6124. ;
  6125. _proto.isProcess = function isProcess(eventType) {
  6126. return this.processEvent[eventType];
  6127. } // 触发start事件
  6128. ;
  6129. _proto.emitStart = function emitStart(type, ev) {
  6130. if (this.isProcess(type)) {
  6131. return;
  6132. }
  6133. this.enable(type);
  6134. this.emitEvent(type + "start", ev);
  6135. } // 触发end事件
  6136. ;
  6137. _proto.emitEnd = function emitEnd(ev) {
  6138. var _this2 = this;
  6139. var processEvent = this.processEvent;
  6140. Object.keys(processEvent).forEach(function (type) {
  6141. _this2.emitEvent(type + "end", ev);
  6142. delete processEvent[type];
  6143. });
  6144. };
  6145. _proto.clearPressTimeout = function clearPressTimeout() {
  6146. if (this.pressTimeout) {
  6147. clearTimeout(this.pressTimeout);
  6148. this.pressTimeout = 0;
  6149. }
  6150. };
  6151. _proto.reset = function reset() {
  6152. this.clearPressTimeout();
  6153. this.startTime = 0;
  6154. this.startPoints = null;
  6155. this.startDistance = 0;
  6156. this.direction = null;
  6157. this.eventType = null;
  6158. this.pinch = false;
  6159. this.prevMoveTime = 0;
  6160. this.prevMovePoints = null;
  6161. this.lastMoveTime = 0;
  6162. this.lastMovePoints = null;
  6163. };
  6164. return EventController;
  6165. }();
  6166. var CanvasElement = /*#__PURE__*/function (_EventEmit) {
  6167. _inheritsLoose$3(CanvasElement, _EventEmit);
  6168. function CanvasElement(ctx) {
  6169. var _this;
  6170. _this = _EventEmit.call(this) || this;
  6171. _this.context = ctx; // canvas实际的宽高 (width/height) * pixelRatio
  6172. _this.width = 0;
  6173. _this.height = 0;
  6174. _this.style = {};
  6175. _this.currentStyle = {};
  6176. _this.attrs = {}; // 用来标识是CanvasElement实例
  6177. _this.isCanvasElement = true;
  6178. return _this;
  6179. }
  6180. var _proto = CanvasElement.prototype;
  6181. _proto.getContext = function getContext() {
  6182. return this.context;
  6183. };
  6184. _proto.getBoundingClientRect = function getBoundingClientRect() {
  6185. var width = this.width;
  6186. var height = this.height; // 默认都处理成可视窗口的顶部位置
  6187. return {
  6188. top: 0,
  6189. right: width,
  6190. bottom: height,
  6191. left: 0
  6192. };
  6193. };
  6194. _proto.setAttribute = function setAttribute(key, value) {
  6195. this.attrs[key] = value;
  6196. };
  6197. _proto.addEventListener = function addEventListener(type, listener) {
  6198. this.on(type, listener);
  6199. };
  6200. _proto.removeEventListener = function removeEventListener(type, listener) {
  6201. this.off(type, listener);
  6202. };
  6203. _proto.dispatchEvent = function dispatchEvent(type, e) {
  6204. this.emit(type, e);
  6205. };
  6206. return CanvasElement;
  6207. }(EventEmit);
  6208. function supportEventListener(canvas) {
  6209. if (!canvas) {
  6210. return false;
  6211. } // 非 HTMLCanvasElement
  6212. if (canvas.nodeType !== 1 || !canvas.nodeName || canvas.nodeName.toLowerCase() !== 'canvas') {
  6213. return false;
  6214. } // 微信小程序canvas.getContext('2d')时也是CanvasRenderingContext2D
  6215. // 也会有ctx.canvas, 而且nodeType也是1,所以还要在看下是否支持addEventListener
  6216. var support = false;
  6217. try {
  6218. canvas.addEventListener('eventTest', function () {
  6219. support = true;
  6220. });
  6221. canvas.dispatchEvent(new Event('eventTest'));
  6222. } catch (error) {
  6223. support = false;
  6224. }
  6225. return support;
  6226. }
  6227. var CanvasElement$1 = {
  6228. create: function create(ctx) {
  6229. if (!ctx) {
  6230. return null;
  6231. }
  6232. if (supportEventListener(ctx.canvas)) {
  6233. return ctx.canvas;
  6234. }
  6235. return new CanvasElement(ctx);
  6236. }
  6237. };
  6238. function _mod(n, m) {
  6239. return (n % m + m) % m;
  6240. }
  6241. function _addStop(steps, gradient) {
  6242. each$1(steps, function (item) {
  6243. item = item.split(':');
  6244. gradient.addColorStop(Number(item[0]), item[1]);
  6245. });
  6246. } // the string format: 'l(0) 0:#ffffff 0.5:#7ec2f3 1:#1890ff'
  6247. function _parseLineGradient(color, shape, context) {
  6248. var arr = color.split(' ');
  6249. var angle = arr[0].slice(2, arr[0].length - 1);
  6250. angle = _mod(parseFloat(angle) * Math.PI / 180, Math.PI * 2);
  6251. var steps = arr.slice(1);
  6252. var _shape$getBBox = shape.getBBox(),
  6253. minX = _shape$getBBox.minX,
  6254. minY = _shape$getBBox.minY,
  6255. maxX = _shape$getBBox.maxX,
  6256. maxY = _shape$getBBox.maxY;
  6257. var start;
  6258. var end;
  6259. if (angle >= 0 && angle < 0.5 * Math.PI) {
  6260. start = {
  6261. x: minX,
  6262. y: minY
  6263. };
  6264. end = {
  6265. x: maxX,
  6266. y: maxY
  6267. };
  6268. } else if (0.5 * Math.PI <= angle && angle < Math.PI) {
  6269. start = {
  6270. x: maxX,
  6271. y: minY
  6272. };
  6273. end = {
  6274. x: minX,
  6275. y: maxY
  6276. };
  6277. } else if (Math.PI <= angle && angle < 1.5 * Math.PI) {
  6278. start = {
  6279. x: maxX,
  6280. y: maxY
  6281. };
  6282. end = {
  6283. x: minX,
  6284. y: minY
  6285. };
  6286. } else {
  6287. start = {
  6288. x: minX,
  6289. y: maxY
  6290. };
  6291. end = {
  6292. x: maxX,
  6293. y: minY
  6294. };
  6295. }
  6296. var tanTheta = Math.tan(angle);
  6297. var tanTheta2 = tanTheta * tanTheta;
  6298. var x = (end.x - start.x + tanTheta * (end.y - start.y)) / (tanTheta2 + 1) + start.x;
  6299. var y = tanTheta * (end.x - start.x + tanTheta * (end.y - start.y)) / (tanTheta2 + 1) + start.y;
  6300. var gradient = context.createLinearGradient(start.x, start.y, x, y);
  6301. _addStop(steps, gradient);
  6302. return gradient;
  6303. } // the string format: 'r(0.5, 0.5, 0.1) 0:#ffffff 1:#1890ff'
  6304. function _parseRadialGradient(color, shape, context) {
  6305. var arr = color.split(' ');
  6306. var circleCfg = arr[0].slice(2, arr[0].length - 1);
  6307. circleCfg = circleCfg.split(',');
  6308. var fx = parseFloat(circleCfg[0]);
  6309. var fy = parseFloat(circleCfg[1]);
  6310. var fr = parseFloat(circleCfg[2]);
  6311. var steps = arr.slice(1); // if radius is 0, no gradient, stroke with the last color
  6312. if (fr === 0) {
  6313. var _color = steps[steps.length - 1];
  6314. return _color.split(':')[1];
  6315. }
  6316. var _shape$getBBox2 = shape.getBBox(),
  6317. width = _shape$getBBox2.width,
  6318. height = _shape$getBBox2.height,
  6319. minX = _shape$getBBox2.minX,
  6320. minY = _shape$getBBox2.minY;
  6321. var r = Math.sqrt(width * width + height * height) / 2;
  6322. var gradient = context.createRadialGradient(minX + width * fx, minY + height * fy, fr * r, minX + width / 2, minY + height / 2, r);
  6323. _addStop(steps, gradient);
  6324. return gradient;
  6325. }
  6326. function parseStyle(color, shape, context) {
  6327. if (color[1] === '(') {
  6328. try {
  6329. var firstCode = color[0];
  6330. if (firstCode === 'l') {
  6331. return _parseLineGradient(color, shape, context);
  6332. } else if (firstCode === 'r') {
  6333. return _parseRadialGradient(color, shape, context);
  6334. }
  6335. } catch (ev) {
  6336. console.error('error in parsing gradient string, please check if there are any extra whitespaces.');
  6337. console.error(ev);
  6338. }
  6339. }
  6340. return color;
  6341. }
  6342. var ALIAS_ATTRS_MAP = {
  6343. stroke: 'strokeStyle',
  6344. fill: 'fillStyle',
  6345. opacity: 'globalAlpha'
  6346. };
  6347. var SHAPE_ATTRS = ['fillStyle', 'font', 'globalAlpha', 'lineCap', 'lineWidth', 'lineJoin', 'miterLimit', 'shadowBlur', 'shadowColor', 'shadowOffsetX', 'shadowOffsetY', 'strokeStyle', 'textAlign', 'textBaseline', 'lineDash', 'shadow' // 兼容支付宝小程序
  6348. ];
  6349. var CLIP_SHAPES = ['circle', 'sector', 'polygon', 'rect', 'polyline'];
  6350. var Element = /*#__PURE__*/function () {
  6351. var _proto = Element.prototype;
  6352. _proto._initProperties = function _initProperties() {
  6353. this._attrs = {
  6354. zIndex: 0,
  6355. visible: true,
  6356. destroyed: false
  6357. };
  6358. };
  6359. function Element(cfg) {
  6360. this._initProperties();
  6361. mix$1(this._attrs, cfg);
  6362. var attrs = this._attrs.attrs;
  6363. if (attrs) {
  6364. this.initAttrs(attrs);
  6365. }
  6366. this.initTransform();
  6367. }
  6368. _proto.get = function get(name) {
  6369. return this._attrs[name];
  6370. };
  6371. _proto.set = function set(name, value) {
  6372. this._attrs[name] = value;
  6373. };
  6374. _proto.isGroup = function isGroup() {
  6375. return this.get('isGroup');
  6376. };
  6377. _proto.isShape = function isShape() {
  6378. return this.get('isShape');
  6379. };
  6380. _proto.initAttrs = function initAttrs(attrs) {
  6381. this.attr(mix$1(this.getDefaultAttrs(), attrs));
  6382. };
  6383. _proto.getDefaultAttrs = function getDefaultAttrs() {
  6384. return {};
  6385. };
  6386. _proto._setAttr = function _setAttr(name, value) {
  6387. var attrs = this._attrs.attrs;
  6388. if (name === 'clip') {
  6389. value = this._setAttrClip(value);
  6390. } else {
  6391. var alias = ALIAS_ATTRS_MAP[name];
  6392. if (alias) {
  6393. attrs[alias] = value;
  6394. }
  6395. }
  6396. attrs[name] = value;
  6397. };
  6398. _proto._getAttr = function _getAttr(name) {
  6399. return this._attrs.attrs[name];
  6400. } // _afterAttrsSet() {}
  6401. ;
  6402. _proto._setAttrClip = function _setAttrClip(clip) {
  6403. if (clip && CLIP_SHAPES.indexOf(clip._attrs.type) > -1) {
  6404. if (clip.get('canvas') === null) {
  6405. clip = Object.assign({}, clip);
  6406. }
  6407. clip.set('parent', this.get('parent'));
  6408. clip.set('context', this.get('context'));
  6409. return clip;
  6410. }
  6411. return null;
  6412. };
  6413. _proto.attr = function attr(name, value) {
  6414. var self = this;
  6415. if (self.get('destroyed')) return null;
  6416. var argumentsLen = arguments.length;
  6417. if (argumentsLen === 0) {
  6418. return self._attrs.attrs;
  6419. }
  6420. if (isObject$1(name)) {
  6421. this._attrs.bbox = null;
  6422. for (var k in name) {
  6423. self._setAttr(k, name[k]);
  6424. }
  6425. if (self._afterAttrsSet) {
  6426. self._afterAttrsSet();
  6427. }
  6428. return self;
  6429. }
  6430. if (argumentsLen === 2) {
  6431. this._attrs.bbox = null;
  6432. self._setAttr(name, value);
  6433. if (self._afterAttrsSet) {
  6434. self._afterAttrsSet();
  6435. }
  6436. return self;
  6437. }
  6438. return self._getAttr(name);
  6439. };
  6440. _proto.getParent = function getParent() {
  6441. return this.get('parent');
  6442. };
  6443. _proto.draw = function draw(context) {
  6444. if (this.get('destroyed')) {
  6445. return;
  6446. }
  6447. if (this.get('visible')) {
  6448. this.setContext(context);
  6449. this.drawInner(context);
  6450. this.restoreContext(context);
  6451. }
  6452. };
  6453. _proto.setContext = function setContext(context) {
  6454. var clip = this._attrs.attrs.clip;
  6455. context.save();
  6456. if (clip) {
  6457. clip.resetTransform(context);
  6458. clip.createPath(context);
  6459. context.clip();
  6460. }
  6461. this.resetContext(context);
  6462. this.resetTransform(context);
  6463. };
  6464. _proto.restoreContext = function restoreContext(context) {
  6465. context.restore();
  6466. };
  6467. _proto.resetContext = function resetContext(context) {
  6468. var elAttrs = this._attrs.attrs;
  6469. for (var k in elAttrs) {
  6470. if (SHAPE_ATTRS.indexOf(k) > -1) {
  6471. var v = elAttrs[k];
  6472. if ((k === 'fillStyle' || k === 'strokeStyle') && v) {
  6473. v = parseStyle(v, this, context);
  6474. }
  6475. if (k === 'lineDash' && context.setLineDash && isArray$1(v)) {
  6476. context.setLineDash(v);
  6477. } else {
  6478. context[k] = v;
  6479. }
  6480. }
  6481. }
  6482. };
  6483. _proto.hasFill = function hasFill() {
  6484. return this.get('canFill') && this._attrs.attrs.fillStyle;
  6485. };
  6486. _proto.hasStroke = function hasStroke() {
  6487. return this.get('canStroke') && this._attrs.attrs.strokeStyle;
  6488. };
  6489. _proto.drawInner = function drawInner() {};
  6490. _proto.show = function show() {
  6491. this.set('visible', true);
  6492. return this;
  6493. };
  6494. _proto.hide = function hide() {
  6495. this.set('visible', false);
  6496. return this;
  6497. };
  6498. _proto.isVisible = function isVisible() {
  6499. return this.get('visible');
  6500. };
  6501. _proto.getAriaLabel = function getAriaLabel() {
  6502. var _this$_attrs = this._attrs,
  6503. destroyed = _this$_attrs.destroyed,
  6504. visible = _this$_attrs.visible,
  6505. isShape = _this$_attrs.isShape,
  6506. aria = _this$_attrs.aria;
  6507. if (destroyed || !visible || isShape && !aria) {
  6508. return;
  6509. }
  6510. return this._getAriaLabel();
  6511. };
  6512. _proto._getAriaLabel = function _getAriaLabel() {
  6513. return this._attrs.ariaLabel;
  6514. };
  6515. _proto._removeFromParent = function _removeFromParent() {
  6516. var parent = this.get('parent');
  6517. if (parent) {
  6518. var children = parent.get('children');
  6519. remove(children, this);
  6520. }
  6521. return this;
  6522. };
  6523. _proto.remove = function remove(destroy) {
  6524. if (destroy) {
  6525. this.destroy();
  6526. } else {
  6527. this._removeFromParent();
  6528. }
  6529. };
  6530. _proto.destroy = function destroy() {
  6531. var destroyed = this.get('destroyed');
  6532. if (destroyed) {
  6533. return null;
  6534. }
  6535. this._removeFromParent();
  6536. this._attrs = {};
  6537. this.set('destroyed', true);
  6538. };
  6539. _proto.getBBox = function getBBox() {
  6540. return {
  6541. minX: 0,
  6542. maxX: 0,
  6543. minY: 0,
  6544. maxY: 0,
  6545. width: 0,
  6546. height: 0
  6547. };
  6548. };
  6549. _proto.initTransform = function initTransform() {
  6550. var attrs = this._attrs.attrs || {};
  6551. if (!attrs.matrix) {
  6552. attrs.matrix = [1, 0, 0, 1, 0, 0];
  6553. }
  6554. this._attrs.attrs = attrs;
  6555. };
  6556. _proto.getMatrix = function getMatrix() {
  6557. return this._attrs.attrs.matrix;
  6558. };
  6559. _proto.setMatrix = function setMatrix(m) {
  6560. this._attrs.attrs.matrix = [m[0], m[1], m[2], m[3], m[4], m[5]];
  6561. };
  6562. _proto.transform = function transform(actions) {
  6563. var matrix = this._attrs.attrs.matrix;
  6564. this._attrs.attrs.matrix = Matrix.transform(matrix, actions);
  6565. return this;
  6566. };
  6567. _proto.setTransform = function setTransform(actions) {
  6568. this._attrs.attrs.matrix = [1, 0, 0, 1, 0, 0];
  6569. return this.transform(actions);
  6570. };
  6571. _proto.translate = function translate(x, y) {
  6572. var matrix = this._attrs.attrs.matrix;
  6573. Matrix.translate(matrix, matrix, [x, y]);
  6574. };
  6575. _proto.rotate = function rotate(rad) {
  6576. var matrix = this._attrs.attrs.matrix;
  6577. Matrix.rotate(matrix, matrix, rad);
  6578. };
  6579. _proto.scale = function scale(sx, sy) {
  6580. var matrix = this._attrs.attrs.matrix;
  6581. Matrix.scale(matrix, matrix, [sx, sy]);
  6582. };
  6583. _proto.moveTo = function moveTo(x, y) {
  6584. var cx = this._attrs.x || 0;
  6585. var cy = this._attrs.y || 0;
  6586. this.translate(x - cx, y - cy);
  6587. this.set('x', x);
  6588. this.set('y', y);
  6589. };
  6590. _proto.apply = function apply(v) {
  6591. var m = this._attrs.attrs.matrix;
  6592. Vector2.transformMat2d(v, v, m);
  6593. return this;
  6594. };
  6595. _proto.resetTransform = function resetTransform(context) {
  6596. var mo = this._attrs.attrs.matrix;
  6597. if (Matrix.isChanged(mo)) {
  6598. context.transform(mo[0], mo[1], mo[2], mo[3], mo[4], mo[5]);
  6599. }
  6600. };
  6601. _proto.isDestroyed = function isDestroyed() {
  6602. return this.get('destroyed');
  6603. };
  6604. return Element;
  6605. }();
  6606. var Shape = /*#__PURE__*/function (_Element) {
  6607. _inheritsLoose$3(Shape, _Element);
  6608. function Shape() {
  6609. return _Element.apply(this, arguments) || this;
  6610. }
  6611. var _proto = Shape.prototype;
  6612. _proto._initProperties = function _initProperties() {
  6613. this._attrs = {
  6614. zIndex: 0,
  6615. visible: true,
  6616. destroyed: false,
  6617. isShape: true,
  6618. attrs: {}
  6619. };
  6620. };
  6621. _proto.getType = function getType() {
  6622. return this._attrs.type;
  6623. };
  6624. _proto.drawInner = function drawInner(context) {
  6625. var self = this;
  6626. var attrs = self.get('attrs');
  6627. self.createPath(context);
  6628. var originOpacity = context.globalAlpha;
  6629. if (self.hasFill()) {
  6630. var fillOpacity = attrs.fillOpacity;
  6631. if (!isNil$1(fillOpacity) && fillOpacity !== 1) {
  6632. context.globalAlpha = fillOpacity;
  6633. context.fill();
  6634. context.globalAlpha = originOpacity;
  6635. } else {
  6636. context.fill();
  6637. }
  6638. }
  6639. if (self.hasStroke()) {
  6640. var lineWidth = attrs.lineWidth;
  6641. if (lineWidth > 0) {
  6642. var strokeOpacity = attrs.strokeOpacity;
  6643. if (!isNil$1(strokeOpacity) && strokeOpacity !== 1) {
  6644. context.globalAlpha = strokeOpacity;
  6645. }
  6646. context.stroke();
  6647. }
  6648. }
  6649. };
  6650. _proto.getBBox = function getBBox() {
  6651. var bbox = this._attrs.bbox;
  6652. if (!bbox) {
  6653. bbox = this.calculateBox();
  6654. if (bbox) {
  6655. bbox.x = bbox.minX;
  6656. bbox.y = bbox.minY;
  6657. bbox.width = bbox.maxX - bbox.minX;
  6658. bbox.height = bbox.maxY - bbox.minY;
  6659. }
  6660. this._attrs.bbox = bbox;
  6661. }
  6662. return bbox;
  6663. };
  6664. _proto.calculateBox = function calculateBox() {
  6665. return null;
  6666. };
  6667. _proto.createPath = function createPath() {};
  6668. return Shape;
  6669. }(Element);
  6670. function parseRadius(radius, width, height) {
  6671. radius = parsePadding(radius); // 都为0
  6672. if (!radius[0] && !radius[1] && !radius[2] && !radius[3]) {
  6673. return radius;
  6674. }
  6675. var minWidth = Math.max(radius[0] + radius[1], radius[2] + radius[3]);
  6676. var minHeight = Math.max(radius[0] + radius[3], radius[1] + radius[2]);
  6677. var scale = Math.min(width / minWidth, height / minHeight);
  6678. if (scale < 1) {
  6679. return radius.map(function (r) {
  6680. return r * scale;
  6681. });
  6682. }
  6683. return radius;
  6684. }
  6685. var Rect$2 = /*#__PURE__*/function (_Shape) {
  6686. _inheritsLoose$3(Rect, _Shape);
  6687. function Rect() {
  6688. return _Shape.apply(this, arguments) || this;
  6689. }
  6690. var _proto = Rect.prototype;
  6691. _proto._initProperties = function _initProperties() {
  6692. _Shape.prototype._initProperties.call(this);
  6693. this._attrs.canFill = true;
  6694. this._attrs.canStroke = true;
  6695. this._attrs.type = 'rect';
  6696. };
  6697. _proto.getDefaultAttrs = function getDefaultAttrs() {
  6698. return {
  6699. x: 0,
  6700. y: 0,
  6701. width: 0,
  6702. height: 0,
  6703. radius: 0,
  6704. lineWidth: 0
  6705. };
  6706. };
  6707. _proto.createRadiusPath = function createRadiusPath(context, x, y, width, height, radius) {
  6708. radius = parseRadius(radius, width, height);
  6709. context.moveTo(x + radius[0], y);
  6710. context.lineTo(x + width - radius[1], y);
  6711. context.arc(x + width - radius[1], y + radius[1], radius[1], -Math.PI / 2, 0, false);
  6712. context.lineTo(x + width, y + height - radius[2]);
  6713. context.arc(x + width - radius[2], y + height - radius[2], radius[2], 0, Math.PI / 2, false);
  6714. context.lineTo(x + radius[3], y + height);
  6715. context.arc(x + radius[3], y + height - radius[3], radius[3], Math.PI / 2, Math.PI, false);
  6716. context.lineTo(x, y + radius[0]);
  6717. context.arc(x + radius[0], y + radius[0], radius[0], Math.PI, Math.PI * 3 / 2, false);
  6718. context.closePath();
  6719. };
  6720. _proto.createPath = function createPath(context) {
  6721. var self = this;
  6722. var attrs = self.get('attrs');
  6723. var x = attrs.x,
  6724. y = attrs.y,
  6725. width = attrs.width,
  6726. height = attrs.height,
  6727. radius = attrs.radius;
  6728. context.beginPath();
  6729. if (!radius || !(width * height)) {
  6730. context.rect(x, y, width, height);
  6731. } else {
  6732. this.createRadiusPath(context, x, y, width, height, radius);
  6733. }
  6734. };
  6735. _proto.calculateBox = function calculateBox() {
  6736. var attrs = this.get('attrs');
  6737. var x = attrs.x,
  6738. y = attrs.y,
  6739. width = attrs.width,
  6740. height = attrs.height;
  6741. return {
  6742. minX: x,
  6743. minY: y,
  6744. maxX: x + width,
  6745. maxY: y + height
  6746. };
  6747. };
  6748. return Rect;
  6749. }(Shape);
  6750. var imageCaches = {};
  6751. var ImageShape = /*#__PURE__*/function (_Rect) {
  6752. _inheritsLoose$3(ImageShape, _Rect);
  6753. function ImageShape() {
  6754. return _Rect.apply(this, arguments) || this;
  6755. }
  6756. var _proto = ImageShape.prototype;
  6757. _proto._initProperties = function _initProperties() {
  6758. _Rect.prototype._initProperties.call(this);
  6759. this._attrs.canFill = false;
  6760. this._attrs.canStroke = false;
  6761. this._attrs.loading = false;
  6762. this._attrs.image = null;
  6763. this._attrs.type = 'image';
  6764. };
  6765. _proto.draw = function draw(context) {
  6766. var _this = this;
  6767. // 如果图片还在loading中直接返回,等下次绘制
  6768. if (this.get('loading')) {
  6769. return;
  6770. } // 如果已经有image对象,直接绘制,会调用createPath绘制
  6771. var image = this.get('image');
  6772. if (image) {
  6773. _Rect.prototype.draw.call(this, context);
  6774. return;
  6775. }
  6776. var attrs = this.get('attrs');
  6777. var src = attrs.src;
  6778. if (src && window.Image) {
  6779. var cacheImage = this.get('cacheImage'); // 如果有缓存,则直接从缓存中拿
  6780. if (cacheImage && imageCaches[src]) {
  6781. this.set('image', imageCaches[src]);
  6782. this.draw(context);
  6783. return;
  6784. }
  6785. this.set('loading', true);
  6786. var _image = new Image(); // 设置跨域, 等同于 image.crossOrigin = 'anonymous'
  6787. _image.crossOrigin = '';
  6788. _image.onload = function () {
  6789. _this.set('loading', false);
  6790. _this.set('image', _image);
  6791. _this.draw(context);
  6792. }; // src 一定要在 crossOrigin 之后,否则 toDataURL 就会报 SecurityError
  6793. _image.src = src; // 设置全局缓存
  6794. if (cacheImage) {
  6795. imageCaches[src] = _image;
  6796. }
  6797. }
  6798. };
  6799. _proto.createPath = function createPath(context) {
  6800. var image = this.get('image');
  6801. this.drawImage(context, image);
  6802. };
  6803. _proto.drawImage = function drawImage(context, image) {
  6804. var _this$_attrs = this._attrs,
  6805. attrs = _this$_attrs.attrs,
  6806. destroyed = _this$_attrs.destroyed;
  6807. if (destroyed) {
  6808. return;
  6809. }
  6810. var x = attrs.x,
  6811. y = attrs.y,
  6812. width = attrs.width,
  6813. height = attrs.height,
  6814. sx = attrs.sx,
  6815. sy = attrs.sy,
  6816. swidth = attrs.swidth,
  6817. sheight = attrs.sheight,
  6818. radius = attrs.radius,
  6819. fillOpacity = attrs.fillOpacity;
  6820. if (radius) {
  6821. context.save();
  6822. this.createRadiusPath(context, x, y, width, height, radius);
  6823. context.clip();
  6824. } // 设置透明度
  6825. var originOpacity = context.globalAlpha;
  6826. if (!isNil$1(fillOpacity)) {
  6827. context.globalAlpha = fillOpacity;
  6828. }
  6829. if (!isNil$1(sx) && !isNil$1(sy) && !isNil$1(swidth) && !isNil$1(sheight)) {
  6830. context.drawImage(image, sx, sy, swidth, sheight, x, y, width, height);
  6831. } else {
  6832. context.drawImage(image, x, y, width, height);
  6833. }
  6834. context.globalAlpha = originOpacity;
  6835. if (radius) {
  6836. // 因为 save 和 restore 会一定程度上影响绘图性能,所以只在必要是调用
  6837. context.restore();
  6838. }
  6839. };
  6840. return ImageShape;
  6841. }(Rect$2);
  6842. var Circle$1 = /*#__PURE__*/function (_Shape) {
  6843. _inheritsLoose$3(Circle, _Shape);
  6844. function Circle() {
  6845. return _Shape.apply(this, arguments) || this;
  6846. }
  6847. var _proto = Circle.prototype;
  6848. _proto._initProperties = function _initProperties() {
  6849. _Shape.prototype._initProperties.call(this);
  6850. this._attrs.canFill = true;
  6851. this._attrs.canStroke = true;
  6852. this._attrs.type = 'circle';
  6853. };
  6854. _proto.getDefaultAttrs = function getDefaultAttrs() {
  6855. return {
  6856. x: 0,
  6857. y: 0,
  6858. r: 0,
  6859. lineWidth: 0
  6860. };
  6861. };
  6862. _proto.createPath = function createPath(context) {
  6863. var attrs = this.get('attrs');
  6864. var x = attrs.x,
  6865. y = attrs.y,
  6866. r = attrs.r;
  6867. context.beginPath();
  6868. context.arc(x, y, r, 0, Math.PI * 2, false);
  6869. context.closePath();
  6870. };
  6871. _proto.calculateBox = function calculateBox() {
  6872. var attrs = this.get('attrs');
  6873. var x = attrs.x,
  6874. y = attrs.y,
  6875. r = attrs.r;
  6876. return {
  6877. minX: x - r,
  6878. maxX: x + r,
  6879. minY: y - r,
  6880. maxY: y + r
  6881. };
  6882. };
  6883. return Circle;
  6884. }(Shape);
  6885. var start = Vector2.create();
  6886. var end = Vector2.create();
  6887. var extremity = Vector2.create();
  6888. function getCubicBezierXYatT(startPt, controlPt1, controlPt2, endPt, T) {
  6889. var x = CubicN(T, startPt.x, controlPt1.x, controlPt2.x, endPt.x);
  6890. var y = CubicN(T, startPt.y, controlPt1.y, controlPt2.y, endPt.y);
  6891. return {
  6892. x: x,
  6893. y: y
  6894. };
  6895. } // cubic helper formula at T distance
  6896. function CubicN(T, a, b, c, d) {
  6897. var t2 = T * T;
  6898. var t3 = t2 * T;
  6899. 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;
  6900. }
  6901. function cubicBezierBounds(c) {
  6902. var minX = Infinity;
  6903. var maxX = -Infinity;
  6904. var minY = Infinity;
  6905. var maxY = -Infinity;
  6906. var s = {
  6907. x: c[0],
  6908. y: c[1]
  6909. };
  6910. var c1 = {
  6911. x: c[2],
  6912. y: c[3]
  6913. };
  6914. var c2 = {
  6915. x: c[4],
  6916. y: c[5]
  6917. };
  6918. var e = {
  6919. x: c[6],
  6920. y: c[7]
  6921. };
  6922. for (var t = 0; t < 100; t++) {
  6923. var pt = getCubicBezierXYatT(s, c1, c2, e, t / 100);
  6924. if (pt.x < minX) {
  6925. minX = pt.x;
  6926. }
  6927. if (pt.x > maxX) {
  6928. maxX = pt.x;
  6929. }
  6930. if (pt.y < minY) {
  6931. minY = pt.y;
  6932. }
  6933. if (pt.y > maxY) {
  6934. maxY = pt.y;
  6935. }
  6936. }
  6937. return {
  6938. minX: minX,
  6939. minY: minY,
  6940. maxX: maxX,
  6941. maxY: maxY
  6942. };
  6943. }
  6944. function getBBoxFromPoints(points, lineWidth) {
  6945. if (points.length === 0) {
  6946. return;
  6947. }
  6948. var p = points[0];
  6949. var left = p.x;
  6950. var right = p.x;
  6951. var top = p.y;
  6952. var bottom = p.y;
  6953. var len = points.length;
  6954. for (var i = 1; i < len; i++) {
  6955. p = points[i];
  6956. left = Math.min(left, p.x);
  6957. right = Math.max(right, p.x);
  6958. top = Math.min(top, p.y);
  6959. bottom = Math.max(bottom, p.y);
  6960. }
  6961. lineWidth = lineWidth / 2 || 0;
  6962. return {
  6963. minX: left - lineWidth,
  6964. minY: top - lineWidth,
  6965. maxX: right + lineWidth,
  6966. maxY: bottom + lineWidth
  6967. };
  6968. }
  6969. function getBBoxFromLine(x0, y0, x1, y1, lineWidth) {
  6970. lineWidth = lineWidth / 2 || 0;
  6971. return {
  6972. minX: Math.min(x0, x1) - lineWidth,
  6973. minY: Math.min(y0, y1) - lineWidth,
  6974. maxX: Math.max(x0, x1) + lineWidth,
  6975. maxY: Math.max(y0, y1) + lineWidth
  6976. };
  6977. }
  6978. function getBBoxFromArc(x, y, r, startAngle, endAngle, anticlockwise) {
  6979. var diff = Math.abs(startAngle - endAngle);
  6980. if (diff % (Math.PI * 2) < 1e-4 && diff > 1e-4) {
  6981. // Is a circle
  6982. return {
  6983. minX: x - r,
  6984. minY: y - r,
  6985. maxX: x + r,
  6986. maxY: y + r
  6987. };
  6988. }
  6989. start[0] = Math.cos(startAngle) * r + x;
  6990. start[1] = Math.sin(startAngle) * r + y;
  6991. end[0] = Math.cos(endAngle) * r + x;
  6992. end[1] = Math.sin(endAngle) * r + y;
  6993. var min = [0, 0];
  6994. var max = [0, 0];
  6995. Vector2.min(min, start, end);
  6996. Vector2.max(max, start, end); // Thresh to [0, Math.PI * 2]
  6997. startAngle = startAngle % (Math.PI * 2);
  6998. if (startAngle < 0) {
  6999. startAngle = startAngle + Math.PI * 2;
  7000. }
  7001. endAngle = endAngle % (Math.PI * 2);
  7002. if (endAngle < 0) {
  7003. endAngle = endAngle + Math.PI * 2;
  7004. }
  7005. if (startAngle > endAngle && !anticlockwise) {
  7006. endAngle += Math.PI * 2;
  7007. } else if (startAngle < endAngle && anticlockwise) {
  7008. startAngle += Math.PI * 2;
  7009. }
  7010. if (anticlockwise) {
  7011. var tmp = endAngle;
  7012. endAngle = startAngle;
  7013. startAngle = tmp;
  7014. }
  7015. for (var angle = 0; angle < endAngle; angle += Math.PI / 2) {
  7016. if (angle > startAngle) {
  7017. extremity[0] = Math.cos(angle) * r + x;
  7018. extremity[1] = Math.sin(angle) * r + y;
  7019. Vector2.min(min, extremity, min);
  7020. Vector2.max(max, extremity, max);
  7021. }
  7022. }
  7023. return {
  7024. minX: min[0],
  7025. minY: min[1],
  7026. maxX: max[0],
  7027. maxY: max[1]
  7028. };
  7029. }
  7030. function getBBoxFromBezierGroup(points, lineWidth) {
  7031. var minX = Infinity;
  7032. var maxX = -Infinity;
  7033. var minY = Infinity;
  7034. var maxY = -Infinity;
  7035. for (var i = 0, len = points.length; i < len; i++) {
  7036. var bbox = cubicBezierBounds(points[i]);
  7037. if (bbox.minX < minX) {
  7038. minX = bbox.minX;
  7039. }
  7040. if (bbox.maxX > maxX) {
  7041. maxX = bbox.maxX;
  7042. }
  7043. if (bbox.minY < minY) {
  7044. minY = bbox.minY;
  7045. }
  7046. if (bbox.maxY > maxY) {
  7047. maxY = bbox.maxY;
  7048. }
  7049. }
  7050. lineWidth = lineWidth / 2 || 0;
  7051. return {
  7052. minX: minX - lineWidth,
  7053. minY: minY - lineWidth,
  7054. maxX: maxX + lineWidth,
  7055. maxY: maxY + lineWidth
  7056. };
  7057. }
  7058. var Line$2 = /*#__PURE__*/function (_Shape) {
  7059. _inheritsLoose$3(Line, _Shape);
  7060. function Line() {
  7061. return _Shape.apply(this, arguments) || this;
  7062. }
  7063. var _proto = Line.prototype;
  7064. _proto._initProperties = function _initProperties() {
  7065. _Shape.prototype._initProperties.call(this);
  7066. this._attrs.canStroke = true;
  7067. this._attrs.type = 'line';
  7068. };
  7069. _proto.getDefaultAttrs = function getDefaultAttrs() {
  7070. return {
  7071. x1: 0,
  7072. y1: 0,
  7073. x2: 0,
  7074. y2: 0,
  7075. lineWidth: 1
  7076. };
  7077. };
  7078. _proto.createPath = function createPath(context) {
  7079. var attrs = this.get('attrs');
  7080. var x1 = attrs.x1,
  7081. y1 = attrs.y1,
  7082. x2 = attrs.x2,
  7083. y2 = attrs.y2;
  7084. context.beginPath();
  7085. context.moveTo(x1, y1);
  7086. context.lineTo(x2, y2);
  7087. };
  7088. _proto.calculateBox = function calculateBox() {
  7089. var attrs = this.get('attrs');
  7090. var x1 = attrs.x1,
  7091. y1 = attrs.y1,
  7092. x2 = attrs.x2,
  7093. y2 = attrs.y2,
  7094. lineWidth = attrs.lineWidth;
  7095. return getBBoxFromLine(x1, y1, x2, y2, lineWidth);
  7096. };
  7097. return Line;
  7098. }(Shape);
  7099. var Polygon$1 = /*#__PURE__*/function (_Shape) {
  7100. _inheritsLoose$3(Polygon, _Shape);
  7101. function Polygon() {
  7102. return _Shape.apply(this, arguments) || this;
  7103. }
  7104. var _proto = Polygon.prototype;
  7105. _proto._initProperties = function _initProperties() {
  7106. _Shape.prototype._initProperties.call(this);
  7107. this._attrs.canFill = true;
  7108. this._attrs.canStroke = true;
  7109. this._attrs.type = 'polygon';
  7110. };
  7111. _proto.getDefaultAttrs = function getDefaultAttrs() {
  7112. return {
  7113. points: null,
  7114. lineWidth: 0
  7115. };
  7116. };
  7117. _proto.createPath = function createPath(context) {
  7118. var self = this;
  7119. var attrs = self.get('attrs');
  7120. var points = attrs.points;
  7121. context.beginPath();
  7122. for (var i = 0, len = points.length; i < len; i++) {
  7123. var point = points[i];
  7124. if (i === 0) {
  7125. context.moveTo(point.x, point.y);
  7126. } else {
  7127. context.lineTo(point.x, point.y);
  7128. }
  7129. }
  7130. context.closePath();
  7131. };
  7132. _proto.calculateBox = function calculateBox() {
  7133. var attrs = this.get('attrs');
  7134. var points = attrs.points;
  7135. return getBBoxFromPoints(points);
  7136. };
  7137. return Polygon;
  7138. }(Shape);
  7139. /**
  7140. * @fileOverview convert the line to curve
  7141. * @author dxq613@gmail.com
  7142. */
  7143. function getPoint(v) {
  7144. return [v.x, v.y];
  7145. }
  7146. function smoothBezier(points, smooth, isLoop, constraint) {
  7147. var cps = [];
  7148. var prevPoint;
  7149. var nextPoint;
  7150. var hasConstraint = !!constraint;
  7151. var min;
  7152. var max;
  7153. var point;
  7154. var len;
  7155. var l;
  7156. var i;
  7157. if (hasConstraint) {
  7158. min = [Infinity, Infinity];
  7159. max = [-Infinity, -Infinity];
  7160. for (i = 0, l = points.length; i < l; i++) {
  7161. point = getPoint(points[i]);
  7162. Vector2.min(min, min, point);
  7163. Vector2.max(max, max, point);
  7164. }
  7165. Vector2.min(min, min, constraint[0]);
  7166. Vector2.max(max, max, constraint[1]);
  7167. }
  7168. for (i = 0, len = points.length; i < len; i++) {
  7169. point = getPoint(points[i]);
  7170. if (isLoop) {
  7171. prevPoint = getPoint(points[i ? i - 1 : len - 1]);
  7172. nextPoint = getPoint(points[(i + 1) % len]);
  7173. } else {
  7174. if (i === 0 || i === len - 1) {
  7175. cps.push([point[0], point[1]]);
  7176. continue;
  7177. } else {
  7178. prevPoint = getPoint(points[i - 1]);
  7179. nextPoint = getPoint(points[i + 1]);
  7180. }
  7181. }
  7182. var v = Vector2.sub([], nextPoint, prevPoint);
  7183. Vector2.scale(v, v, smooth);
  7184. var d0 = Vector2.distance(point, prevPoint);
  7185. var d1 = Vector2.distance(point, nextPoint);
  7186. var sum = d0 + d1;
  7187. if (sum !== 0) {
  7188. d0 /= sum;
  7189. d1 /= sum;
  7190. }
  7191. var v1 = Vector2.scale([], v, -d0);
  7192. var v2 = Vector2.scale([], v, d1);
  7193. var cp0 = Vector2.add([], point, v1);
  7194. var cp1 = Vector2.add([], point, v2);
  7195. if (hasConstraint) {
  7196. Vector2.max(cp0, cp0, min);
  7197. Vector2.min(cp0, cp0, max);
  7198. Vector2.max(cp1, cp1, min);
  7199. Vector2.min(cp1, cp1, max);
  7200. }
  7201. cps.push([cp0[0], cp0[1]]);
  7202. cps.push([cp1[0], cp1[1]]);
  7203. }
  7204. if (isLoop) {
  7205. cps.push(cps.shift());
  7206. }
  7207. return cps;
  7208. }
  7209. function catmullRom2bezier(pointList, z, constraint) {
  7210. var isLoop = !!z;
  7211. var controlPointList = smoothBezier(pointList, 0.4, isLoop, constraint);
  7212. var len = pointList.length;
  7213. var d1 = [];
  7214. var cp1;
  7215. var cp2;
  7216. var p;
  7217. for (var i = 0; i < len - 1; i++) {
  7218. cp1 = controlPointList[i * 2];
  7219. cp2 = controlPointList[i * 2 + 1];
  7220. p = pointList[i + 1];
  7221. d1.push(['C', cp1[0], cp1[1], cp2[0], cp2[1], p.x, p.y]);
  7222. }
  7223. if (isLoop) {
  7224. cp1 = controlPointList[len];
  7225. cp2 = controlPointList[len + 1];
  7226. p = pointList[0];
  7227. d1.push(['C', cp1[0], cp1[1], cp2[0], cp2[1], p.x, p.y]);
  7228. }
  7229. return d1;
  7230. }
  7231. function _filterPoints(points) {
  7232. var filteredPoints = [];
  7233. for (var i = 0, len = points.length; i < len; i++) {
  7234. var point = points[i];
  7235. if (!isNaN(point.x) && !isNaN(point.y)) {
  7236. filteredPoints.push(point);
  7237. }
  7238. }
  7239. return filteredPoints;
  7240. }
  7241. var Polyline = /*#__PURE__*/function (_Shape) {
  7242. _inheritsLoose$3(Polyline, _Shape);
  7243. function Polyline() {
  7244. return _Shape.apply(this, arguments) || this;
  7245. }
  7246. var _proto = Polyline.prototype;
  7247. _proto._initProperties = function _initProperties() {
  7248. _Shape.prototype._initProperties.call(this);
  7249. this._attrs.canFill = true;
  7250. this._attrs.canStroke = true;
  7251. this._attrs.type = 'polyline';
  7252. };
  7253. _proto.getDefaultAttrs = function getDefaultAttrs() {
  7254. return {
  7255. points: null,
  7256. lineWidth: 1,
  7257. smooth: false
  7258. };
  7259. };
  7260. _proto.createPath = function createPath(context) {
  7261. var self = this;
  7262. var attrs = self.get('attrs');
  7263. var points = attrs.points,
  7264. smooth = attrs.smooth;
  7265. var filteredPoints = _filterPoints(points);
  7266. context.beginPath();
  7267. if (filteredPoints.length) {
  7268. context.moveTo(filteredPoints[0].x, filteredPoints[0].y);
  7269. if (smooth) {
  7270. var constaint = [[0, 0], [1, 1]];
  7271. var sps = catmullRom2bezier(filteredPoints, false, constaint);
  7272. for (var i = 0, n = sps.length; i < n; i++) {
  7273. var sp = sps[i];
  7274. context.bezierCurveTo(sp[1], sp[2], sp[3], sp[4], sp[5], sp[6]);
  7275. }
  7276. } else {
  7277. var _i;
  7278. var l;
  7279. for (_i = 1, l = filteredPoints.length - 1; _i < l; _i++) {
  7280. context.lineTo(filteredPoints[_i].x, filteredPoints[_i].y);
  7281. }
  7282. context.lineTo(filteredPoints[l].x, filteredPoints[l].y);
  7283. }
  7284. }
  7285. };
  7286. _proto.calculateBox = function calculateBox() {
  7287. var attrs = this.get('attrs');
  7288. var points = attrs.points,
  7289. smooth = attrs.smooth,
  7290. lineWidth = attrs.lineWidth;
  7291. var filteredPoints = _filterPoints(points);
  7292. if (smooth) {
  7293. var newPoints = [];
  7294. var constaint = [[0, 0], [1, 1]];
  7295. var sps = catmullRom2bezier(filteredPoints, false, constaint);
  7296. for (var i = 0, n = sps.length; i < n; i++) {
  7297. var sp = sps[i];
  7298. if (i === 0) {
  7299. newPoints.push([filteredPoints[0].x, filteredPoints[0].y, sp[1], sp[2], sp[3], sp[4], sp[5], sp[6]]);
  7300. } else {
  7301. var lastPoint = sps[i - 1];
  7302. newPoints.push([lastPoint[5], lastPoint[6], sp[1], sp[2], sp[3], sp[4], sp[5], sp[6]]);
  7303. }
  7304. }
  7305. return getBBoxFromBezierGroup(newPoints, lineWidth);
  7306. }
  7307. return getBBoxFromPoints(filteredPoints, lineWidth);
  7308. };
  7309. return Polyline;
  7310. }(Shape);
  7311. var Arc$1 = /*#__PURE__*/function (_Shape) {
  7312. _inheritsLoose$3(Arc, _Shape);
  7313. function Arc() {
  7314. return _Shape.apply(this, arguments) || this;
  7315. }
  7316. var _proto = Arc.prototype;
  7317. _proto._initProperties = function _initProperties() {
  7318. _Shape.prototype._initProperties.call(this);
  7319. this._attrs.canStroke = true;
  7320. this._attrs.canFill = true;
  7321. this._attrs.type = 'arc';
  7322. };
  7323. _proto.getDefaultAttrs = function getDefaultAttrs() {
  7324. return {
  7325. x: 0,
  7326. y: 0,
  7327. r: 0,
  7328. startAngle: 0,
  7329. endAngle: Math.PI * 2,
  7330. anticlockwise: false,
  7331. lineWidth: 1
  7332. };
  7333. };
  7334. _proto.createPath = function createPath(context) {
  7335. var attrs = this.get('attrs');
  7336. var x = attrs.x,
  7337. y = attrs.y,
  7338. r = attrs.r,
  7339. startAngle = attrs.startAngle,
  7340. endAngle = attrs.endAngle,
  7341. anticlockwise = attrs.anticlockwise;
  7342. context.beginPath();
  7343. if (startAngle !== endAngle) {
  7344. context.arc(x, y, r, startAngle, endAngle, anticlockwise);
  7345. }
  7346. };
  7347. _proto.calculateBox = function calculateBox() {
  7348. var attrs = this.get('attrs');
  7349. var x = attrs.x,
  7350. y = attrs.y,
  7351. r = attrs.r,
  7352. startAngle = attrs.startAngle,
  7353. endAngle = attrs.endAngle,
  7354. anticlockwise = attrs.anticlockwise;
  7355. return getBBoxFromArc(x, y, r, startAngle, endAngle, anticlockwise);
  7356. };
  7357. return Arc;
  7358. }(Shape);
  7359. var Sector = /*#__PURE__*/function (_Shape) {
  7360. _inheritsLoose$3(Sector, _Shape);
  7361. function Sector() {
  7362. return _Shape.apply(this, arguments) || this;
  7363. }
  7364. var _proto = Sector.prototype;
  7365. _proto._initProperties = function _initProperties() {
  7366. _Shape.prototype._initProperties.call(this);
  7367. this._attrs.canFill = true;
  7368. this._attrs.canStroke = true;
  7369. this._attrs.type = 'sector';
  7370. };
  7371. _proto.getDefaultAttrs = function getDefaultAttrs() {
  7372. return {
  7373. x: 0,
  7374. y: 0,
  7375. lineWidth: 0,
  7376. r: 0,
  7377. r0: 0,
  7378. startAngle: 0,
  7379. endAngle: Math.PI * 2,
  7380. anticlockwise: false
  7381. };
  7382. };
  7383. _proto.createPath = function createPath(context) {
  7384. var attrs = this.get('attrs');
  7385. var x = attrs.x,
  7386. y = attrs.y,
  7387. startAngle = attrs.startAngle,
  7388. endAngle = attrs.endAngle,
  7389. r = attrs.r,
  7390. r0 = attrs.r0,
  7391. anticlockwise = attrs.anticlockwise;
  7392. context.beginPath();
  7393. var unitX = Math.cos(startAngle);
  7394. var unitY = Math.sin(startAngle);
  7395. context.moveTo(unitX * r0 + x, unitY * r0 + y);
  7396. context.lineTo(unitX * r + x, unitY * r + y); // 当扇形的角度非常小的时候,就不进行弧线的绘制;或者整个只有1个扇形时,会出现end<0的情况不绘制
  7397. if (Math.abs(endAngle - startAngle) > 0.0001 || startAngle === 0 && endAngle < 0) {
  7398. context.arc(x, y, r, startAngle, endAngle, anticlockwise);
  7399. context.lineTo(Math.cos(endAngle) * r0 + x, Math.sin(endAngle) * r0 + y);
  7400. if (r0 !== 0) {
  7401. context.arc(x, y, r0, endAngle, startAngle, !anticlockwise);
  7402. }
  7403. }
  7404. context.closePath();
  7405. };
  7406. _proto.calculateBox = function calculateBox() {
  7407. var attrs = this.get('attrs');
  7408. var x = attrs.x,
  7409. y = attrs.y,
  7410. r = attrs.r,
  7411. r0 = attrs.r0,
  7412. startAngle = attrs.startAngle,
  7413. endAngle = attrs.endAngle,
  7414. anticlockwise = attrs.anticlockwise;
  7415. var outerBBox = getBBoxFromArc(x, y, r, startAngle, endAngle, anticlockwise);
  7416. var innerBBox = getBBoxFromArc(x, y, r0, startAngle, endAngle, anticlockwise);
  7417. return {
  7418. minX: Math.min(outerBBox.minX, innerBBox.minX),
  7419. minY: Math.min(outerBBox.minY, innerBBox.minY),
  7420. maxX: Math.max(outerBBox.maxX, innerBBox.maxX),
  7421. maxY: Math.max(outerBBox.maxY, innerBBox.maxY)
  7422. };
  7423. };
  7424. return Sector;
  7425. }(Shape);
  7426. var Rect$1 = {
  7427. calcRotatedBox: function calcRotatedBox(_ref) {
  7428. var width = _ref.width,
  7429. height = _ref.height,
  7430. rotate = _ref.rotate;
  7431. var absRotate = Math.abs(rotate);
  7432. return {
  7433. width: Math.abs(width * Math.cos(absRotate) + height * Math.sin(absRotate)),
  7434. height: Math.abs(height * Math.cos(absRotate) + width * Math.sin(absRotate))
  7435. };
  7436. }
  7437. };
  7438. var textWidthCacheCounter = 0;
  7439. var textWidthCache = {};
  7440. var TEXT_CACHE_MAX = 5000;
  7441. var Text$1 = /*#__PURE__*/function (_Shape) {
  7442. _inheritsLoose$3(Text, _Shape);
  7443. function Text() {
  7444. return _Shape.apply(this, arguments) || this;
  7445. }
  7446. var _proto = Text.prototype;
  7447. _proto._initProperties = function _initProperties() {
  7448. _Shape.prototype._initProperties.call(this);
  7449. this._attrs.canFill = true;
  7450. this._attrs.canStroke = true;
  7451. this._attrs.type = 'text';
  7452. };
  7453. _proto.getDefaultAttrs = function getDefaultAttrs() {
  7454. return {
  7455. lineWidth: 0,
  7456. lineCount: 1,
  7457. fontSize: 12,
  7458. fontFamily: 'sans-serif',
  7459. fontStyle: 'normal',
  7460. fontWeight: 'normal',
  7461. fontVariant: 'normal',
  7462. textAlign: 'start',
  7463. textBaseline: 'bottom',
  7464. lineHeight: null,
  7465. textArr: null
  7466. };
  7467. };
  7468. _proto._getFontStyle = function _getFontStyle() {
  7469. var attrs = this._attrs.attrs;
  7470. var fontSize = attrs.fontSize,
  7471. fontFamily = attrs.fontFamily,
  7472. fontWeight = attrs.fontWeight,
  7473. fontStyle = attrs.fontStyle,
  7474. fontVariant = attrs.fontVariant;
  7475. return fontStyle + " " + fontVariant + " " + fontWeight + " " + fontSize + "px " + fontFamily;
  7476. };
  7477. _proto._afterAttrsSet = function _afterAttrsSet() {
  7478. var attrs = this._attrs.attrs;
  7479. attrs.font = this._getFontStyle();
  7480. if (attrs.text) {
  7481. var text = attrs.text;
  7482. var textArr = null;
  7483. var lineCount = 1;
  7484. if (isString(text) && text.indexOf('\n') !== -1) {
  7485. textArr = text.split('\n');
  7486. lineCount = textArr.length;
  7487. }
  7488. attrs.lineCount = lineCount;
  7489. attrs.textArr = textArr;
  7490. }
  7491. this.set('attrs', attrs);
  7492. };
  7493. _proto._getTextHeight = function _getTextHeight() {
  7494. var attrs = this._attrs.attrs;
  7495. if (attrs.height) {
  7496. return attrs.height;
  7497. }
  7498. var lineCount = attrs.lineCount;
  7499. var fontSize = attrs.fontSize * 1;
  7500. if (lineCount > 1) {
  7501. var spaceingY = this._getSpaceingY();
  7502. return fontSize * lineCount + spaceingY * (lineCount - 1);
  7503. }
  7504. return fontSize;
  7505. };
  7506. _proto._getSpaceingY = function _getSpaceingY() {
  7507. var attrs = this._attrs.attrs;
  7508. var lineHeight = attrs.lineHeight;
  7509. var fontSize = attrs.fontSize * 1;
  7510. return lineHeight ? lineHeight - fontSize : fontSize * 0.14;
  7511. };
  7512. _proto.drawInner = function drawInner(context) {
  7513. var self = this;
  7514. var attrs = self._attrs.attrs;
  7515. var text = attrs.text;
  7516. var x = attrs.x;
  7517. var y = attrs.y;
  7518. if (isNil$1(text) || isNaN(x) || isNaN(y)) {
  7519. // text will be 0
  7520. return;
  7521. }
  7522. var textArr = attrs.textArr;
  7523. var fontSize = attrs.fontSize * 1;
  7524. var spaceingY = self._getSpaceingY();
  7525. if (attrs.rotate) {
  7526. // do rotation
  7527. context.translate(x, y);
  7528. context.rotate(attrs.rotate);
  7529. x = 0;
  7530. y = 0;
  7531. }
  7532. var textBaseline = attrs.textBaseline;
  7533. var height;
  7534. if (textArr) {
  7535. height = self._getTextHeight();
  7536. }
  7537. var subY; // context.beginPath();
  7538. if (self.hasFill()) {
  7539. var fillOpacity = attrs.fillOpacity;
  7540. if (!isNil$1(fillOpacity) && fillOpacity !== 1) {
  7541. context.globalAlpha = fillOpacity;
  7542. }
  7543. if (textArr) {
  7544. for (var i = 0, len = textArr.length; i < len; i++) {
  7545. var subText = textArr[i];
  7546. subY = y + i * (spaceingY + fontSize) - height + fontSize; // bottom;
  7547. if (textBaseline === 'middle') {
  7548. subY += height - fontSize - (height - fontSize) / 2;
  7549. }
  7550. if (textBaseline === 'top') {
  7551. subY += height - fontSize;
  7552. }
  7553. context.fillText(subText, x, subY);
  7554. }
  7555. } else {
  7556. context.fillText(text, x, y);
  7557. }
  7558. }
  7559. if (self.hasStroke()) {
  7560. if (textArr) {
  7561. for (var _i = 0, _len = textArr.length; _i < _len; _i++) {
  7562. var _subText = textArr[_i];
  7563. subY = y + _i * (spaceingY + fontSize) - height + fontSize; // bottom;
  7564. if (textBaseline === 'middle') {
  7565. subY += height - fontSize - (height - fontSize) / 2;
  7566. }
  7567. if (textBaseline === 'top') {
  7568. subY += height - fontSize;
  7569. }
  7570. context.strokeText(_subText, x, subY);
  7571. }
  7572. } else {
  7573. context.strokeText(text, x, y);
  7574. }
  7575. }
  7576. };
  7577. _proto._getAriaLabel = function _getAriaLabel() {
  7578. return this._attrs.attrs.text;
  7579. };
  7580. _proto.calculateBox = function calculateBox() {
  7581. var self = this;
  7582. var attrs = self._attrs.attrs;
  7583. var x = attrs.x,
  7584. y = attrs.y,
  7585. textAlign = attrs.textAlign,
  7586. textBaseline = attrs.textBaseline;
  7587. var width = self._getTextWidth(); // attrs.width
  7588. if (!width) {
  7589. return {
  7590. minX: x,
  7591. minY: y,
  7592. maxX: x,
  7593. maxY: y
  7594. };
  7595. }
  7596. var height = self._getTextHeight(); // attrs.height
  7597. if (attrs.rotate) {
  7598. var rotatedBox = Rect$1.calcRotatedBox({
  7599. width: width,
  7600. height: height,
  7601. rotate: attrs.rotate
  7602. });
  7603. width = rotatedBox.width;
  7604. height = rotatedBox.height;
  7605. }
  7606. var point = {
  7607. x: x,
  7608. y: y - height
  7609. }; // default textAlign: start, textBaseline: bottom
  7610. if (textAlign) {
  7611. if (textAlign === 'end' || textAlign === 'right') {
  7612. point.x -= width;
  7613. } else if (textAlign === 'center') {
  7614. point.x -= width / 2;
  7615. }
  7616. }
  7617. if (textBaseline) {
  7618. if (textBaseline === 'top') {
  7619. point.y += height;
  7620. } else if (textBaseline === 'middle') {
  7621. point.y += height / 2;
  7622. }
  7623. }
  7624. return {
  7625. minX: point.x,
  7626. minY: point.y,
  7627. maxX: point.x + width,
  7628. maxY: point.y + height
  7629. };
  7630. };
  7631. _proto._getTextWidth = function _getTextWidth() {
  7632. var attrs = this._attrs.attrs;
  7633. if (attrs.width) {
  7634. return attrs.width;
  7635. }
  7636. var text = attrs.text;
  7637. var context = this.get('context');
  7638. if (isNil$1(text)) return undefined;
  7639. var font = attrs.font;
  7640. var textArr = attrs.textArr;
  7641. var key = text + '' + font;
  7642. if (textWidthCache[key]) {
  7643. return textWidthCache[key];
  7644. }
  7645. var width = 0;
  7646. if (textArr) {
  7647. for (var i = 0, length = textArr.length; i < length; i++) {
  7648. var subText = textArr[i];
  7649. width = Math.max(width, measureText(subText, font, context).width);
  7650. }
  7651. } else {
  7652. width = measureText(text, font, context).width;
  7653. }
  7654. if (textWidthCacheCounter > TEXT_CACHE_MAX) {
  7655. textWidthCacheCounter = 0;
  7656. textWidthCache = {};
  7657. }
  7658. textWidthCacheCounter++;
  7659. textWidthCache[key] = width;
  7660. return width;
  7661. };
  7662. return Text;
  7663. }(Shape);
  7664. var Custom = /*#__PURE__*/function (_Shape) {
  7665. _inheritsLoose$3(Custom, _Shape);
  7666. function Custom() {
  7667. return _Shape.apply(this, arguments) || this;
  7668. }
  7669. var _proto = Custom.prototype;
  7670. _proto._initProperties = function _initProperties() {
  7671. _Shape.prototype._initProperties.call(this);
  7672. this._attrs.canFill = true;
  7673. this._attrs.canStroke = true;
  7674. this._attrs.createPath = null;
  7675. this._attrs.type = 'custom';
  7676. };
  7677. _proto.createPath = function createPath(context) {
  7678. var createPath = this.get('createPath');
  7679. createPath && createPath.call(this, context);
  7680. };
  7681. _proto.calculateBox = function calculateBox() {
  7682. var calculateBox = this.get('calculateBox');
  7683. return calculateBox && calculateBox.call(this);
  7684. };
  7685. return Custom;
  7686. }(Shape);
  7687. var SYMBOLS = {
  7688. circle: function circle(x, y, r, ctx) {
  7689. ctx.arc(x, y, r, 0, Math.PI * 2, false);
  7690. },
  7691. square: function square(x, y, r, ctx) {
  7692. ctx.moveTo(x - r, y - r);
  7693. ctx.lineTo(x + r, y - r);
  7694. ctx.lineTo(x + r, y + r);
  7695. ctx.lineTo(x - r, y + r);
  7696. ctx.closePath();
  7697. }
  7698. };
  7699. var Marker = /*#__PURE__*/function (_Shape) {
  7700. _inheritsLoose$3(Marker, _Shape);
  7701. function Marker() {
  7702. return _Shape.apply(this, arguments) || this;
  7703. }
  7704. var _proto = Marker.prototype;
  7705. _proto._initProperties = function _initProperties() {
  7706. _Shape.prototype._initProperties.call(this);
  7707. this._attrs.canFill = true;
  7708. this._attrs.canStroke = true;
  7709. this._attrs.type = 'marker';
  7710. };
  7711. _proto.getDefaultAttrs = function getDefaultAttrs() {
  7712. return {
  7713. x: 0,
  7714. y: 0,
  7715. lineWidth: 0
  7716. };
  7717. };
  7718. _proto.createPath = function createPath(context) {
  7719. var attrs = this.get('attrs');
  7720. var x = attrs.x,
  7721. y = attrs.y,
  7722. radius = attrs.radius;
  7723. var symbol = attrs.symbol || 'circle';
  7724. var method;
  7725. if (isFunction$1(symbol)) {
  7726. method = symbol;
  7727. } else {
  7728. method = SYMBOLS[symbol];
  7729. }
  7730. context.beginPath();
  7731. method(x, y, radius, context, this);
  7732. };
  7733. _proto.calculateBox = function calculateBox() {
  7734. var attrs = this.get('attrs');
  7735. var x = attrs.x,
  7736. y = attrs.y,
  7737. radius = attrs.radius;
  7738. return {
  7739. minX: x - radius,
  7740. minY: y - radius,
  7741. maxX: x + radius,
  7742. maxY: y + radius
  7743. };
  7744. };
  7745. return Marker;
  7746. }(Shape);
  7747. Shape.Rect = Rect$2;
  7748. Shape.Image = ImageShape;
  7749. Shape.Circle = Circle$1;
  7750. Shape.Line = Line$2;
  7751. Shape.Polygon = Polygon$1;
  7752. Shape.Polyline = Polyline;
  7753. Shape.Arc = Arc$1;
  7754. Shape.Sector = Sector;
  7755. Shape.Text = Text$1;
  7756. Shape.Custom = Custom;
  7757. Shape.Marker = Marker;
  7758. var SHAPE_MAP = {};
  7759. var INDEX = '_INDEX';
  7760. function getComparer(compare) {
  7761. return function (left, right) {
  7762. var result = compare(left, right);
  7763. return result === 0 ? left[INDEX] - right[INDEX] : result;
  7764. };
  7765. }
  7766. var Container = {
  7767. getGroupClass: function getGroupClass() {},
  7768. getChildren: function getChildren() {
  7769. return this.get('children');
  7770. },
  7771. addShape: function addShape(type, cfg) {
  7772. if (cfg === void 0) {
  7773. cfg = {};
  7774. }
  7775. var shapeType = SHAPE_MAP[type];
  7776. if (!shapeType) {
  7777. shapeType = upperFirst(type);
  7778. SHAPE_MAP[type] = shapeType;
  7779. }
  7780. var shape = new Shape[shapeType](cfg);
  7781. this.add(shape);
  7782. return shape;
  7783. },
  7784. addGroup: function addGroup(cfg) {
  7785. var groupClass = this.getGroupClass();
  7786. var rst = new groupClass(cfg);
  7787. this.add(rst);
  7788. return rst;
  7789. },
  7790. contain: function contain(item) {
  7791. var children = this.get('children');
  7792. return children.indexOf(item) > -1;
  7793. },
  7794. sort: function sort() {
  7795. var children = this.get('children');
  7796. for (var i = 0, len = children.length; i < len; i++) {
  7797. var child = children[i];
  7798. child[INDEX] = i;
  7799. }
  7800. children.sort(getComparer(function (obj1, obj2) {
  7801. return obj1.get('zIndex') - obj2.get('zIndex');
  7802. }));
  7803. return this;
  7804. },
  7805. drawChildren: function drawChildren(context) {
  7806. var children = this.get('children');
  7807. for (var i = 0, len = children.length; i < len; i++) {
  7808. var child = children[i];
  7809. child.draw(context);
  7810. }
  7811. return this;
  7812. },
  7813. clear: function clear() {
  7814. var children = this.get('children');
  7815. while (children.length !== 0) {
  7816. children[children.length - 1].remove(true);
  7817. }
  7818. return this;
  7819. },
  7820. add: function add(items) {
  7821. var self = this;
  7822. var children = self.get('children');
  7823. if (!isArray$1(items)) {
  7824. items = [items];
  7825. }
  7826. for (var i = 0, len = items.length; i < len; i++) {
  7827. var item = items[i];
  7828. var parent = item.get('parent');
  7829. if (parent) {
  7830. var descendants = parent.get('children');
  7831. remove(descendants, item);
  7832. }
  7833. self._setEvn(item);
  7834. children.push(item);
  7835. }
  7836. return self;
  7837. },
  7838. _setEvn: function _setEvn(item) {
  7839. var self = this;
  7840. var _self$_attrs = self._attrs,
  7841. context = _self$_attrs.context,
  7842. canvas = _self$_attrs.canvas,
  7843. aria = _self$_attrs.aria;
  7844. var _item$_attrs = item._attrs,
  7845. isGroup = _item$_attrs.isGroup,
  7846. type = _item$_attrs.type;
  7847. item._attrs.parent = self;
  7848. item._attrs.context = context;
  7849. item._attrs.canvas = canvas; // 是否需要无障碍处理
  7850. if (aria && item._attrs.aria !== false) {
  7851. item._attrs.aria = aria;
  7852. }
  7853. if (type === 'text' && canvas && canvas.get('fontFamily')) {
  7854. item._attrs.attrs.fontFamily = item._attrs.attrs.fontFamily || canvas.get('fontFamily');
  7855. }
  7856. var clip = item._attrs.attrs.clip;
  7857. if (clip) {
  7858. clip._attrs.parent = self;
  7859. clip._attrs.context = context;
  7860. clip._attrs.canvas = canvas;
  7861. }
  7862. if (isGroup) {
  7863. var children = item._attrs.children;
  7864. for (var i = 0, len = children.length; i < len; i++) {
  7865. item._setEvn(children[i]);
  7866. }
  7867. }
  7868. },
  7869. _getAriaLabel: function _getAriaLabel() {
  7870. var _this$_attrs = this._attrs,
  7871. aria = _this$_attrs.aria,
  7872. ariaLabel = _this$_attrs.ariaLabel,
  7873. children = _this$_attrs.children; // 主动关闭
  7874. if (!aria) return;
  7875. var childAriaLabels = [];
  7876. if (children && children.length) {
  7877. for (var i = 0, len = children.length; i < len; i++) {
  7878. var _childAriaLabel = children[i].getAriaLabel();
  7879. if (_childAriaLabel) {
  7880. childAriaLabels.push(_childAriaLabel);
  7881. }
  7882. }
  7883. }
  7884. var childAriaLabel = childAriaLabels.join(' '); // 2个都有时拼接成完整句子
  7885. if (ariaLabel && childAriaLabel) {
  7886. return ariaLabel + " " + childAriaLabel + " ";
  7887. } // 只有1个,或者都没有
  7888. return ariaLabel || childAriaLabel;
  7889. }
  7890. };
  7891. var Group = /*#__PURE__*/function (_Rect) {
  7892. _inheritsLoose$3(Group, _Rect);
  7893. function Group() {
  7894. return _Rect.apply(this, arguments) || this;
  7895. }
  7896. var _proto = Group.prototype;
  7897. _proto._initProperties = function _initProperties() {
  7898. this._attrs = {
  7899. type: 'group',
  7900. zIndex: 0,
  7901. visible: true,
  7902. destroyed: false,
  7903. isGroup: true,
  7904. canFill: true,
  7905. canStroke: true,
  7906. attrs: {},
  7907. children: []
  7908. };
  7909. };
  7910. _proto.getBBox = function getBBox() {
  7911. var self = this;
  7912. var minX = Infinity;
  7913. var maxX = -Infinity;
  7914. var minY = Infinity;
  7915. var maxY = -Infinity;
  7916. var children = self.get('children');
  7917. for (var i = 0, length = children.length; i < length; i++) {
  7918. var child = children[i];
  7919. if (child.get('visible')) {
  7920. var box = child.getBBox();
  7921. if (!box) {
  7922. continue;
  7923. }
  7924. var leftTop = [box.minX, box.minY];
  7925. var leftBottom = [box.minX, box.maxY];
  7926. var rightTop = [box.maxX, box.minY];
  7927. var rightBottom = [box.maxX, box.maxY];
  7928. var matrix = child.attr('matrix');
  7929. Vector2.transformMat2d(leftTop, leftTop, matrix);
  7930. Vector2.transformMat2d(leftBottom, leftBottom, matrix);
  7931. Vector2.transformMat2d(rightTop, rightTop, matrix);
  7932. Vector2.transformMat2d(rightBottom, rightBottom, matrix);
  7933. minX = Math.min(leftTop[0], leftBottom[0], rightTop[0], rightBottom[0], minX);
  7934. maxX = Math.max(leftTop[0], leftBottom[0], rightTop[0], rightBottom[0], maxX);
  7935. minY = Math.min(leftTop[1], leftBottom[1], rightTop[1], rightBottom[1], minY);
  7936. maxY = Math.max(leftTop[1], leftBottom[1], rightTop[1], rightBottom[1], maxY);
  7937. }
  7938. }
  7939. return {
  7940. minX: minX,
  7941. minY: minY,
  7942. maxX: maxX,
  7943. maxY: maxY,
  7944. x: minX,
  7945. y: minY,
  7946. width: maxX - minX,
  7947. height: maxY - minY
  7948. };
  7949. };
  7950. _proto.createPath = function createPath(context) {
  7951. var attrs = this.get('attrs'); // 只有在有fillStyle或strokeStyle 时才需要绘制
  7952. if (!attrs.fillStyle && !attrs.strokeStyle) {
  7953. return;
  7954. }
  7955. _Rect.prototype.createPath.call(this, context);
  7956. };
  7957. _proto.drawInner = function drawInner(context) {
  7958. _Rect.prototype.drawInner.call(this, context);
  7959. this.drawChildren(context);
  7960. };
  7961. _proto.destroy = function destroy() {
  7962. if (this.get('destroyed')) {
  7963. return;
  7964. }
  7965. this.clear();
  7966. _Rect.prototype.destroy.call(this);
  7967. };
  7968. return Group;
  7969. }(Rect$2);
  7970. mix$1(Group.prototype, Container, {
  7971. getGroupClass: function getGroupClass() {
  7972. return Group;
  7973. }
  7974. });
  7975. var requestAnimationFrame = typeof window === 'object' && window.requestAnimationFrame ? window.requestAnimationFrame : function (fn) {
  7976. return setTimeout(fn, 16);
  7977. };
  7978. var Canvas = /*#__PURE__*/function (_EventEmit) {
  7979. _inheritsLoose$3(Canvas, _EventEmit);
  7980. var _proto = Canvas.prototype;
  7981. _proto.get = function get(name) {
  7982. return this._attrs[name];
  7983. };
  7984. _proto.set = function set(name, value) {
  7985. this._attrs[name] = value;
  7986. };
  7987. function Canvas(cfg) {
  7988. var _this;
  7989. _this = _EventEmit.call(this) || this;
  7990. var title = cfg.title;
  7991. var ariaLabel = title ? substitute(lang.general.withTitle, {
  7992. title: title
  7993. }) : lang.general.title;
  7994. _this._attrs = mix$1({
  7995. type: 'canvas',
  7996. children: [],
  7997. ariaLabel: ariaLabel
  7998. }, cfg);
  7999. _this._initPixelRatio();
  8000. _this._initCanvas();
  8001. return _this;
  8002. }
  8003. _proto._initPixelRatio = function _initPixelRatio() {
  8004. var pixelRatio = this.get('pixelRatio');
  8005. if (!pixelRatio) {
  8006. this.set('pixelRatio', getPixelRatio());
  8007. }
  8008. };
  8009. _proto.beforeDraw = function beforeDraw() {
  8010. var context = this._attrs.context;
  8011. var el = this._attrs.el;
  8012. context && context.clearRect && context.clearRect(0, 0, el.width, el.height);
  8013. };
  8014. _proto._initCanvas = function _initCanvas() {
  8015. var self = this;
  8016. var el = self.get('el');
  8017. var context = self.get('context');
  8018. if (!el && !context) {
  8019. throw new Error('Please specify the id, el or context of the chart!');
  8020. }
  8021. var canvas;
  8022. if (el) {
  8023. // DOMElement or String
  8024. canvas = isString(el) ? getDomById(el) : el;
  8025. } else {
  8026. // 说明没有指定el
  8027. canvas = CanvasElement$1.create(context);
  8028. }
  8029. if (context && canvas && !canvas.getContext) {
  8030. canvas.getContext = function () {
  8031. return context;
  8032. };
  8033. }
  8034. var width = self.get('width');
  8035. if (!width) {
  8036. width = getWidth(canvas);
  8037. }
  8038. var height = self.get('height');
  8039. if (!height) {
  8040. height = getHeight(canvas);
  8041. }
  8042. self.set('canvas', this);
  8043. self.set('el', canvas);
  8044. self.set('context', context || canvas.getContext('2d'));
  8045. self.changeSize(width, height); // 初始化事件控制器
  8046. var eventController = new EventController({
  8047. canvas: this,
  8048. el: canvas
  8049. });
  8050. self.set('eventController', eventController);
  8051. };
  8052. _proto.changeSize = function changeSize(width, height) {
  8053. var pixelRatio = this.get('pixelRatio');
  8054. var canvasDOM = this.get('el'); // HTMLCanvasElement or canvasElement
  8055. // 浏览器环境设置style样式
  8056. if (canvasDOM.style) {
  8057. canvasDOM.style.width = width + 'px';
  8058. canvasDOM.style.height = height + 'px';
  8059. }
  8060. if (isCanvasElement(canvasDOM)) {
  8061. canvasDOM.width = width * pixelRatio;
  8062. canvasDOM.height = height * pixelRatio;
  8063. if (pixelRatio !== 1) {
  8064. var ctx = this.get('context');
  8065. ctx.scale(pixelRatio, pixelRatio);
  8066. }
  8067. }
  8068. this.set('width', width);
  8069. this.set('height', height);
  8070. };
  8071. _proto.getWidth = function getWidth() {
  8072. var pixelRatio = this.get('pixelRatio');
  8073. var width = this.get('width');
  8074. return width * pixelRatio;
  8075. };
  8076. _proto.getHeight = function getHeight() {
  8077. var pixelRatio = this.get('pixelRatio');
  8078. var height = this.get('height');
  8079. return height * pixelRatio;
  8080. };
  8081. _proto.getPointByClient = function getPointByClient(clientX, clientY) {
  8082. var el = this.get('el');
  8083. var bbox = el.getBoundingClientRect();
  8084. var width = bbox.right - bbox.left;
  8085. var height = bbox.bottom - bbox.top;
  8086. return {
  8087. x: (clientX - bbox.left) * (el.width / width),
  8088. y: (clientY - bbox.top) * (el.height / height)
  8089. };
  8090. };
  8091. _proto._beginDraw = function _beginDraw() {
  8092. this._attrs.toDraw = true;
  8093. };
  8094. _proto._endDraw = function _endDraw() {
  8095. this._attrs.toDraw = false;
  8096. };
  8097. _proto.draw = function draw() {
  8098. var self = this;
  8099. function drawInner() {
  8100. self.set('animateHandler', requestAnimationFrame(function () {
  8101. self.set('animateHandler', undefined);
  8102. if (self.get('toDraw')) {
  8103. drawInner();
  8104. }
  8105. }));
  8106. self.beforeDraw();
  8107. try {
  8108. var context = self._attrs.context;
  8109. self.drawChildren(context); // 支付宝,微信小程序,需要调context.draw才能完成绘制, 所以这里直接判断是否有.draw方法
  8110. if (context.draw) {
  8111. context.draw();
  8112. } // 设置无障碍文本
  8113. self.setAriaLabel();
  8114. } catch (ev) {
  8115. console.warn('error in draw canvas, detail as:');
  8116. console.warn(ev);
  8117. self._endDraw();
  8118. }
  8119. self._endDraw();
  8120. }
  8121. if (self.get('destroyed')) {
  8122. return;
  8123. }
  8124. if (self.get('animateHandler')) {
  8125. this._beginDraw();
  8126. } else {
  8127. drawInner();
  8128. }
  8129. } // 设置无障碍文本
  8130. ;
  8131. _proto.setAriaLabel = function setAriaLabel() {
  8132. var el = this._attrs.el;
  8133. var ariaLabel = this._getAriaLabel();
  8134. if (ariaLabel && el.setAttribute) {
  8135. el.setAttribute('aria-label', ariaLabel);
  8136. }
  8137. };
  8138. _proto.destroy = function destroy() {
  8139. if (this.get('destroyed')) {
  8140. return;
  8141. } // 需要清理 canvas 画布内容,否则会导致 spa 应用 ios 下 canvas 白屏
  8142. // https://stackoverflow.com/questions/52532614/total-canvas-memory-use-exceeds-the-maximum-limit-safari-12
  8143. // https://github.com/antvis/F2/issues/630
  8144. var el = this.get('el');
  8145. el.width = 0;
  8146. el.height = 0;
  8147. this.clear();
  8148. this._attrs = {};
  8149. this.set('destroyed', true);
  8150. };
  8151. _proto.isDestroyed = function isDestroyed() {
  8152. return this.get('destroyed');
  8153. };
  8154. return Canvas;
  8155. }(EventEmit);
  8156. mix$1(Canvas.prototype, Container, {
  8157. getGroupClass: function getGroupClass() {
  8158. return Group;
  8159. }
  8160. });
  8161. var engines = {};
  8162. function registerEngine(name, engine) {
  8163. engines[name] = engine;
  8164. }
  8165. function getEngine(name) {
  8166. var G = engines[name];
  8167. if (G) {
  8168. return G;
  8169. }
  8170. return {
  8171. Canvas: Canvas,
  8172. Group: Group,
  8173. Shape: Shape
  8174. };
  8175. }
  8176. function createCanvas(cfg) {
  8177. var renderer = cfg.renderer;
  8178. var G = getEngine(renderer);
  8179. return new G.Canvas(cfg);
  8180. }
  8181. var G = /*#__PURE__*/Object.freeze({
  8182. __proto__: null,
  8183. registerEngine: registerEngine,
  8184. getEngine: getEngine,
  8185. createCanvas: createCanvas,
  8186. Canvas: Canvas,
  8187. Group: Group,
  8188. Shape: Shape,
  8189. Matrix: Matrix,
  8190. Vector2: Vector2
  8191. });
  8192. function getClip(coord) {
  8193. var start = coord.start;
  8194. var end = coord.end;
  8195. var width = end.x - start.x;
  8196. var height = Math.abs(end.y - start.y);
  8197. var margin = 10;
  8198. var clip;
  8199. if (coord.isPolar) {
  8200. var circleRadius = coord.circleRadius,
  8201. center = coord.center,
  8202. startAngle = coord.startAngle,
  8203. endAngle = coord.endAngle;
  8204. clip = new Shape.Sector({
  8205. attrs: {
  8206. x: center.x,
  8207. y: center.y,
  8208. r: circleRadius,
  8209. r0: 0,
  8210. startAngle: startAngle,
  8211. endAngle: endAngle
  8212. }
  8213. });
  8214. } else {
  8215. clip = new Shape.Rect({
  8216. attrs: {
  8217. x: start.x,
  8218. y: end.y - margin,
  8219. width: width,
  8220. height: height + 2 * margin
  8221. }
  8222. });
  8223. }
  8224. clip.isClip = true;
  8225. return clip;
  8226. }
  8227. function isPointInPlot(point, plot) {
  8228. var x = point.x,
  8229. y = point.y;
  8230. var tl = plot.tl,
  8231. tr = plot.tr,
  8232. br = plot.br;
  8233. return x >= tl.x && x <= tr.x && y >= tl.y && y <= br.y;
  8234. }
  8235. var Helper = /*#__PURE__*/Object.freeze({
  8236. __proto__: null,
  8237. getClip: getClip,
  8238. isPointInPlot: isPointInPlot
  8239. });
  8240. function compare(a, b) {
  8241. return a - b;
  8242. }
  8243. function _isScaleExist(scales, compareScale) {
  8244. var flag = false;
  8245. each$1(scales, function (scale) {
  8246. var scaleValues = [].concat(scale.values);
  8247. var compareScaleValues = [].concat(compareScale.values);
  8248. if (scale.type === compareScale.type && scale.field === compareScale.field && scaleValues.sort(compare).toString() === compareScaleValues.sort(compare).toString()) {
  8249. flag = true;
  8250. return;
  8251. }
  8252. });
  8253. return flag;
  8254. }
  8255. var Chart = /*#__PURE__*/function (_Base) {
  8256. _inheritsLoose$3(Chart, _Base);
  8257. Chart.initPlugins = function initPlugins() {
  8258. return {
  8259. _plugins: [],
  8260. _cacheId: 0,
  8261. register: function register(plugins) {
  8262. var p = this._plugins;
  8263. [].concat(plugins).forEach(function (plugin) {
  8264. if (p.indexOf(plugin) === -1) {
  8265. p.push(plugin);
  8266. }
  8267. });
  8268. this._cacheId++;
  8269. },
  8270. unregister: function unregister(plugins) {
  8271. var p = this._plugins;
  8272. [].concat(plugins).forEach(function (plugin) {
  8273. var idx = p.indexOf(plugin);
  8274. if (idx !== -1) {
  8275. p.splice(idx, 1);
  8276. }
  8277. });
  8278. this._cacheId++;
  8279. },
  8280. clear: function clear() {
  8281. this._plugins = [];
  8282. this._cacheId++;
  8283. },
  8284. count: function count() {
  8285. return this._plugins.length;
  8286. },
  8287. getAll: function getAll() {
  8288. return this._plugins;
  8289. },
  8290. notify: function notify(chart, hook, args) {
  8291. var descriptors = this.descriptors(chart);
  8292. var ilen = descriptors.length;
  8293. var i;
  8294. var descriptor;
  8295. var plugin;
  8296. var params;
  8297. var method;
  8298. for (i = 0; i < ilen; ++i) {
  8299. descriptor = descriptors[i];
  8300. plugin = descriptor.plugin;
  8301. method = plugin[hook];
  8302. if (typeof method === 'function') {
  8303. params = [chart].concat(args || []);
  8304. if (method.apply(plugin, params) === false) {
  8305. return false;
  8306. }
  8307. }
  8308. }
  8309. return true;
  8310. },
  8311. descriptors: function descriptors(chart) {
  8312. var cache = chart._plugins || (chart._plugins = {});
  8313. if (cache.id === this._cacheId) {
  8314. return cache.descriptors;
  8315. }
  8316. var plugins = [];
  8317. var descriptors = [];
  8318. this._plugins.concat(chart && chart.get('plugins') || []).forEach(function (plugin) {
  8319. var idx = plugins.indexOf(plugin);
  8320. if (idx !== -1) {
  8321. return;
  8322. }
  8323. plugins.push(plugin);
  8324. descriptors.push({
  8325. plugin: plugin
  8326. });
  8327. });
  8328. cache.descriptors = descriptors;
  8329. cache.id = this._cacheId;
  8330. return descriptors;
  8331. }
  8332. };
  8333. };
  8334. var _proto = Chart.prototype;
  8335. _proto.getDefaultCfg = function getDefaultCfg() {
  8336. return {
  8337. /**
  8338. * the id of canvas
  8339. * @type {String}
  8340. */
  8341. id: null,
  8342. /** 图表渲染引擎 */
  8343. renderer: 'canvas',
  8344. rendered: false,
  8345. /**
  8346. * padding
  8347. * @type {Array|Number}
  8348. */
  8349. padding: Global.padding,
  8350. /**
  8351. * data
  8352. * @type {Array}
  8353. */
  8354. data: null,
  8355. /**
  8356. * scales of chart
  8357. * @type {Object}
  8358. */
  8359. scales: {},
  8360. /**
  8361. * @private
  8362. * geometry instances
  8363. * @type {Array}
  8364. */
  8365. geoms: [],
  8366. /**
  8367. * scale configuration
  8368. * @type {Object}
  8369. */
  8370. colDefs: null,
  8371. pixelRatio: Global.pixelRatio,
  8372. /**
  8373. * filter options
  8374. * @type {Object}
  8375. */
  8376. filters: null,
  8377. appendPadding: Global.appendPadding
  8378. };
  8379. };
  8380. _proto._syncYScales = function _syncYScales() {
  8381. var syncY = this.get('syncY');
  8382. if (!syncY) {
  8383. return;
  8384. }
  8385. var geoms = this.get('geoms');
  8386. var syncScales = [];
  8387. var min = [];
  8388. var max = [];
  8389. each$1(geoms, function (geom) {
  8390. var yScale = geom.getYScale();
  8391. if (yScale.isLinear) {
  8392. syncScales.push(yScale);
  8393. min.push(yScale.min);
  8394. max.push(yScale.max);
  8395. }
  8396. });
  8397. min = Math.min.apply(null, min);
  8398. max = Math.max.apply(null, max);
  8399. each$1(syncScales, function (scale) {
  8400. scale.change({
  8401. min: min
  8402. });
  8403. scale.change({
  8404. max: max
  8405. });
  8406. });
  8407. };
  8408. _proto._getFieldsForLegend = function _getFieldsForLegend() {
  8409. var fields = [];
  8410. var geoms = this.get('geoms');
  8411. each$1(geoms, function (geom) {
  8412. var attrOptions = geom.get('attrOptions');
  8413. var attrCfg = attrOptions.color;
  8414. if (attrCfg && attrCfg.field && isString(attrCfg.field)) {
  8415. var arr = attrCfg.field.split('*');
  8416. each$1(arr, function (item) {
  8417. if (fields.indexOf(item) === -1) {
  8418. fields.push(item);
  8419. }
  8420. });
  8421. }
  8422. });
  8423. return fields;
  8424. };
  8425. _proto._getScaleData = function _getScaleData(field) {
  8426. var data = this.get('data');
  8427. var filteredData = this.get('filteredData');
  8428. if (filteredData.length) {
  8429. var legendFields = this._getFieldsForLegend();
  8430. if (legendFields.indexOf(field) === -1) {
  8431. data = filteredData;
  8432. }
  8433. }
  8434. return data;
  8435. } // _updateScales() {
  8436. // const scaleController = this.get('scaleController');
  8437. // scaleController.updateScales();
  8438. // this._adjustScale();
  8439. // }
  8440. ;
  8441. _proto._adjustScale = function _adjustScale() {
  8442. var self = this;
  8443. var scaleController = self.get('scaleController'); // 看起来是为了让柱状图最小或最大都默认从0开始
  8444. var geoms = this.get('geoms');
  8445. for (var i = 0; i < geoms.length; i++) {
  8446. var geom = geoms[i];
  8447. if (geom.get('type') === 'interval') {
  8448. var yScale = geom.getYScale();
  8449. scaleController.adjustStartZero(yScale);
  8450. }
  8451. }
  8452. };
  8453. _proto._removeGeoms = function _removeGeoms() {
  8454. var geoms = this.get('geoms');
  8455. while (geoms.length > 0) {
  8456. var geom = geoms.shift();
  8457. geom.destroy();
  8458. }
  8459. };
  8460. _proto._clearGeoms = function _clearGeoms() {
  8461. var geoms = this.get('geoms');
  8462. for (var i = 0, length = geoms.length; i < length; i++) {
  8463. var geom = geoms[i];
  8464. geom.clear();
  8465. }
  8466. };
  8467. _proto._clearInner = function _clearInner() {
  8468. this._clearGeoms();
  8469. Chart.plugins.notify(this, 'clearInner');
  8470. this.emit(EVENT_CLEAR_INNER);
  8471. this.get('axisController') && this.get('axisController').clear();
  8472. };
  8473. _proto._initFilteredData = function _initFilteredData() {
  8474. var filters = this.get('filters');
  8475. var data = this.get('data') || [];
  8476. if (filters) {
  8477. data = data.filter(function (obj) {
  8478. var rst = true;
  8479. each$1(filters, function (fn, k) {
  8480. if (fn) {
  8481. rst = fn(obj[k], obj);
  8482. if (!rst) {
  8483. return false;
  8484. }
  8485. }
  8486. });
  8487. return rst;
  8488. });
  8489. }
  8490. this.set('filteredData', data);
  8491. };
  8492. _proto._changeGeomsData = function _changeGeomsData() {
  8493. var geoms = this.get('geoms');
  8494. var data = this.get('filteredData');
  8495. for (var i = 0, length = geoms.length; i < length; i++) {
  8496. var geom = geoms[i];
  8497. geom.changeData(data);
  8498. }
  8499. };
  8500. _proto._initGeom = function _initGeom(geom) {
  8501. if (geom.get('isInit')) {
  8502. return;
  8503. }
  8504. var coord = this.get('coord');
  8505. var data = this.get('filteredData');
  8506. var colDefs = this.get('colDefs');
  8507. var middlePlot = this.get('middlePlot');
  8508. geom.set('chart', this);
  8509. geom.set('container', middlePlot.addGroup());
  8510. geom.set('data', data);
  8511. geom.set('coord', coord);
  8512. geom.set('colDefs', colDefs);
  8513. geom.init();
  8514. this.emit(EVENT_AFTER_GEOM_INIT, geom);
  8515. };
  8516. _proto._initGeoms = function _initGeoms() {
  8517. var geoms = this.get('geoms');
  8518. for (var i = 0, length = geoms.length; i < length; i++) {
  8519. this._initGeom(geoms[i]);
  8520. }
  8521. };
  8522. _proto._initCoord = function _initCoord() {
  8523. var plot = this.get('plotRange');
  8524. var coordCfg = mix$1({
  8525. type: 'cartesian'
  8526. }, this.get('coordCfg'), {
  8527. plot: plot
  8528. });
  8529. var type = coordCfg.type;
  8530. var C = Base$1[upperFirst(type)];
  8531. var coord = new C(coordCfg);
  8532. this.set('coord', coord);
  8533. };
  8534. _proto._initLayout = function _initLayout() {
  8535. var padding = this.get('_padding');
  8536. if (!padding) {
  8537. padding = this.get('margin') || this.get('padding');
  8538. padding = parsePadding(padding);
  8539. }
  8540. var top = padding[0] === 'auto' ? 0 : padding[0];
  8541. var right = padding[1] === 'auto' ? 0 : padding[1];
  8542. var bottom = padding[2] === 'auto' ? 0 : padding[2];
  8543. var left = padding[3] === 'auto' ? 0 : padding[3];
  8544. var width = this.get('width');
  8545. var height = this.get('height');
  8546. var start = {
  8547. x: left,
  8548. y: top
  8549. };
  8550. var end = {
  8551. x: width - right,
  8552. y: height - bottom
  8553. };
  8554. var plot = this.get('plot');
  8555. if (plot) {
  8556. plot.reset(start, end);
  8557. return;
  8558. }
  8559. var newPlot = new Plot({
  8560. start: start,
  8561. end: end
  8562. });
  8563. this.set('plotRange', newPlot);
  8564. this.set('plot', newPlot);
  8565. };
  8566. _proto._initCanvas = function _initCanvas() {
  8567. var self = this;
  8568. try {
  8569. var canvas = createCanvas({
  8570. renderer: self.get('renderer'),
  8571. el: self.get('el') || self.get('id'),
  8572. context: self.get('context'),
  8573. pixelRatio: self.get('pixelRatio'),
  8574. width: self.get('width'),
  8575. height: self.get('height'),
  8576. fontFamily: Global.fontFamily,
  8577. aria: self.get('aria'),
  8578. title: self.get('title'),
  8579. landscape: self.get('landscape')
  8580. });
  8581. self.set('canvas', canvas);
  8582. self.set('el', canvas.get('el'));
  8583. self.set('width', canvas.get('width'));
  8584. self.set('height', canvas.get('height'));
  8585. } catch (error) {
  8586. throw error;
  8587. }
  8588. Chart.plugins.notify(self, 'afterCanvasInit');
  8589. };
  8590. _proto._initLayers = function _initLayers() {
  8591. var canvas = this.get('canvas');
  8592. this.set('backPlot', canvas.addGroup());
  8593. this.set('middlePlot', canvas.addGroup({
  8594. zIndex: 10
  8595. }));
  8596. this.set('frontPlot', canvas.addGroup({
  8597. zIndex: 20
  8598. }));
  8599. };
  8600. _proto._initEvents = function _initEvents() {
  8601. var _this2 = this;
  8602. // 数据更新后的一些更新
  8603. this.on(EVENT_AFTER_DATA_CHANGE, function () {
  8604. // 数据更新后,重新设置filterdata
  8605. _this2._initFilteredData(); // 更新geoms里的数据
  8606. _this2._changeGeomsData();
  8607. }); // 大小变化后的一些更新
  8608. this.on(EVENT_AFTER_SIZE_CHANGE, function () {
  8609. _this2._initLayout(); // layout变化后,坐标轴也需要做相应的变化
  8610. var coord = _this2.get('coord');
  8611. if (coord) {
  8612. coord.reset(_this2.get('plot'));
  8613. }
  8614. });
  8615. };
  8616. _proto._initScaleController = function _initScaleController() {
  8617. var scaleController = new ScaleController({
  8618. chart: this
  8619. }); // 让colDefs 和 scaleController.defs 用同一个对象,这样就不用考虑同步的问题
  8620. this.set('colDefs', scaleController.defs); // 已经实例化的scales 也保持统一个对象
  8621. this.set('scales', scaleController.scales);
  8622. this.set('scaleController', scaleController);
  8623. };
  8624. _proto._clearScaleController = function _clearScaleController() {
  8625. var scaleController = this.get('scaleController');
  8626. scaleController.clear();
  8627. };
  8628. _proto._init = function _init() {
  8629. var self = this;
  8630. self._initCanvas();
  8631. self._initLayout();
  8632. self._initLayers();
  8633. self._initEvents();
  8634. self._initScaleController();
  8635. self.set('axisController', new AxisController({
  8636. frontPlot: self.get('frontPlot').addGroup({
  8637. className: 'axisContainer'
  8638. }),
  8639. backPlot: self.get('backPlot').addGroup({
  8640. className: 'axisContainer'
  8641. }),
  8642. chart: self
  8643. }));
  8644. Chart.plugins.notify(self, 'init');
  8645. };
  8646. function Chart(cfg) {
  8647. var _this;
  8648. _this = _Base.call(this, cfg) || this;
  8649. var self = _assertThisInitialized(_this);
  8650. each$1(Geom, function (geomConstructor, className) {
  8651. var methodName = lowerFirst(className);
  8652. self[methodName] = function (cfg) {
  8653. var geom = new geomConstructor(cfg);
  8654. self.addGeom(geom);
  8655. return geom;
  8656. };
  8657. });
  8658. self._init();
  8659. return _this;
  8660. }
  8661. _proto.init = function init() {
  8662. // 初始filterData
  8663. this._initFilteredData(); // initialization coordinate instance
  8664. this._initCoord();
  8665. Chart.plugins.notify(this, 'beforeGeomInit'); // init all geometry instances
  8666. this._initGeoms(); // 多 Y 轴的情况时,统一 Y 轴的数值范围。
  8667. this._syncYScales(); // do some adjust for data
  8668. this._adjustScale();
  8669. this.emit(EVENT_AFTER_INIT);
  8670. }
  8671. /**
  8672. * set data and some scale configuration
  8673. * @chainable
  8674. * @param {Array} data the dataset to visualize
  8675. * @param {Object} colDefs the configuration for scales
  8676. * @return {Chart} return the chart instance
  8677. */
  8678. ;
  8679. _proto.source = function source(data, colDefs) {
  8680. this.set('data', data);
  8681. if (colDefs) {
  8682. this.scale(colDefs);
  8683. }
  8684. return this;
  8685. };
  8686. _proto.scale = function scale(field, cfg) {
  8687. var scaleController = this.get('scaleController');
  8688. scaleController.setFieldDef(field, cfg);
  8689. return this;
  8690. }
  8691. /**
  8692. * configure the axis
  8693. * @chainable
  8694. * @param {String|Boolean} field the field name of data
  8695. * @param {Object} cfg configuration for axis
  8696. * @return {Chart} return the chart instance
  8697. */
  8698. ;
  8699. _proto.axis = function axis(field, cfg) {
  8700. var axisController = this.get('axisController');
  8701. if (!field) {
  8702. axisController.axisCfg = null;
  8703. } else {
  8704. axisController.axisCfg = axisController.axisCfg || {};
  8705. axisController.axisCfg[field] = cfg;
  8706. }
  8707. return this;
  8708. }
  8709. /**
  8710. * configure the coordinate
  8711. * @chainable
  8712. * @param {String} type set the type of coodinate
  8713. * @param {Object} cfg configuration for coordinate
  8714. * @return {Chart} return the chart instance
  8715. */
  8716. ;
  8717. _proto.coord = function coord(type, cfg) {
  8718. var coordCfg;
  8719. if (isObject$1(type)) {
  8720. coordCfg = type;
  8721. } else {
  8722. coordCfg = cfg || {};
  8723. coordCfg.type = type || 'cartesian';
  8724. }
  8725. this.set('coordCfg', coordCfg);
  8726. return this;
  8727. };
  8728. _proto.filter = function filter(field, condition) {
  8729. var filters = this.get('filters') || {};
  8730. filters[field] = condition;
  8731. this.set('filters', filters); // 如果已经render过,则再重新触发一次change
  8732. if (this.get('rendered')) {
  8733. this.emit(EVENT_AFTER_DATA_CHANGE, this.get('data'));
  8734. }
  8735. }
  8736. /**
  8737. * render the chart
  8738. * @chainable
  8739. * @return {Chart} return the chart instance
  8740. */
  8741. ;
  8742. _proto.render = function render() {
  8743. var rendered = this.get('rendered');
  8744. var canvas = this.get('canvas');
  8745. var geoms = this.get('geoms'); // 已经渲染过
  8746. if (rendered) {
  8747. this._initGeoms();
  8748. this._adjustScale();
  8749. } else {
  8750. this.init();
  8751. this.set('rendered', true);
  8752. }
  8753. this.emit(EVENT_BEFORE_RENDER);
  8754. Chart.plugins.notify(this, 'beforeGeomDraw');
  8755. this._renderAxis();
  8756. var middlePlot = this.get('middlePlot');
  8757. if (this.get('limitInPlot') && !middlePlot.attr('clip')) {
  8758. var coord = this.get('coord');
  8759. var clip = getClip(coord);
  8760. clip.set('canvas', middlePlot.get('canvas'));
  8761. middlePlot.attr('clip', clip);
  8762. }
  8763. this.emit(EVENT_BEFORE_GEOM_DRAW);
  8764. for (var i = 0, length = geoms.length; i < length; i++) {
  8765. var geom = geoms[i];
  8766. geom.paint();
  8767. }
  8768. this.emit(EVENT_AFTER_GEOM_DRAW);
  8769. Chart.plugins.notify(this, 'afterGeomDraw');
  8770. canvas.sort();
  8771. this.get('frontPlot').sort();
  8772. Chart.plugins.notify(this, 'beforeCanvasDraw');
  8773. canvas.draw();
  8774. this.emit(EVENT_AFTER_RENDER);
  8775. return this;
  8776. }
  8777. /**
  8778. * clear the chart, include geometris and all the shapes
  8779. * @chainable
  8780. * @return {Chart} return the chart
  8781. */
  8782. ;
  8783. _proto.clear = function clear() {
  8784. Chart.plugins.notify(this, 'clear');
  8785. this.emit(EVENT_CLEAR);
  8786. this._clearInner();
  8787. this._removeGeoms();
  8788. this._clearScaleController();
  8789. this.set('legendItems', null);
  8790. this.set('filters', null);
  8791. this.set('isUpdate', false);
  8792. this.set('_padding', null);
  8793. this.set('rendered', false);
  8794. var canvas = this.get('canvas');
  8795. canvas.draw();
  8796. return this;
  8797. };
  8798. _proto.repaint = function repaint() {
  8799. // 如果在没有render之前就repaint的,就直接return退出
  8800. var rendered = this.get('rendered');
  8801. if (!rendered) {
  8802. return;
  8803. }
  8804. this.set('isUpdate', true);
  8805. this.set('legendItems', null);
  8806. Chart.plugins.notify(this, 'repaint');
  8807. this._clearInner();
  8808. this.emit(EVENT_REPAINT);
  8809. this.render();
  8810. };
  8811. _proto.changeData = function changeData(data) {
  8812. this.emit(EVENT_BEFORE_DATA_CHANGE, data);
  8813. this.set('data', data);
  8814. Chart.plugins.notify(this, 'changeData');
  8815. this.emit(EVENT_AFTER_DATA_CHANGE, data);
  8816. this.set('_padding', null);
  8817. this.repaint();
  8818. };
  8819. _proto.changeSize = function changeSize(width, height) {
  8820. if (width) {
  8821. this.set('width', width);
  8822. } else {
  8823. width = this.get('width');
  8824. }
  8825. if (height) {
  8826. this.set('height', height);
  8827. } else {
  8828. height = this.get('height');
  8829. }
  8830. var canvas = this.get('canvas');
  8831. canvas.changeSize(width, height);
  8832. this.emit(EVENT_AFTER_SIZE_CHANGE, {
  8833. width: width,
  8834. height: height
  8835. });
  8836. this.repaint();
  8837. return this;
  8838. };
  8839. _proto.destroy = function destroy() {
  8840. this.clear();
  8841. var canvas = this.get('canvas');
  8842. canvas.destroy();
  8843. Chart.plugins.notify(this, 'afterCanvasDestroyed');
  8844. if (this._interactions) {
  8845. each$1(this._interactions, function (interaction) {
  8846. interaction.destroy();
  8847. });
  8848. }
  8849. _Base.prototype.destroy.call(this);
  8850. }
  8851. /**
  8852. * calculate dataset's position on canvas
  8853. * @param {Object} record the dataset
  8854. * @return {Object} return the position
  8855. */
  8856. ;
  8857. _proto.getPosition = function getPosition(record) {
  8858. var self = this;
  8859. var coord = self.get('coord');
  8860. var xScale = self.getXScale();
  8861. var xField = xScale.field;
  8862. var yScales = self.getYScales(); // default first
  8863. var yScale = yScales[0];
  8864. var yField = yScale.field;
  8865. for (var i = 0, len = yScales.length; i < len; i++) {
  8866. var scale = yScales[i];
  8867. var field = scale.field;
  8868. if (record[field]) {
  8869. yScale = scale;
  8870. yField = field;
  8871. break;
  8872. }
  8873. }
  8874. var x = xScale.scale(record[xField]);
  8875. var y = yScale.scale(record[yField]);
  8876. return coord.convertPoint({
  8877. x: x,
  8878. y: y
  8879. });
  8880. }
  8881. /**
  8882. * get the data item of the point
  8883. * @param {Object} point canvas position
  8884. * @return {Object} return the data item
  8885. */
  8886. ;
  8887. _proto.getRecord = function getRecord(point) {
  8888. var self = this;
  8889. var coord = self.get('coord');
  8890. var xScale = self.getXScale();
  8891. var yScale = self.getYScales()[0];
  8892. var invertPoint = coord.invertPoint(point);
  8893. var record = {};
  8894. record[xScale.field] = xScale.invert(invertPoint.x);
  8895. record[yScale.field] = yScale.invert(invertPoint.y);
  8896. return record;
  8897. }
  8898. /**
  8899. * get the dataset of the point
  8900. * @param {Object} point canvas position
  8901. * @return {Array} return the dataset
  8902. **/
  8903. ;
  8904. _proto.getSnapRecords = function getSnapRecords(point) {
  8905. var geom = this.get('geoms')[0];
  8906. var data = [];
  8907. if (geom) {
  8908. // need to judge
  8909. data = geom.getSnapRecords(point);
  8910. }
  8911. return data;
  8912. }
  8913. /**
  8914. * creat scale instances
  8915. * @param {String} field field name of data
  8916. * @return {Scale} return the scale
  8917. */
  8918. ;
  8919. _proto.createScale = function createScale(field) {
  8920. var data = this._getScaleData(field);
  8921. var scaleController = this.get('scaleController');
  8922. return scaleController.createScale(field, data);
  8923. }
  8924. /**
  8925. * @protected
  8926. * add geometry instance to geoms
  8927. * @param {Geom} geom geometry instance
  8928. */
  8929. ;
  8930. _proto.addGeom = function addGeom(geom) {
  8931. var geoms = this.get('geoms');
  8932. geoms.push(geom);
  8933. }
  8934. /**
  8935. * get the scale of x axis
  8936. * @return {Scale} return the scale
  8937. */
  8938. ;
  8939. _proto.getXScale = function getXScale() {
  8940. var self = this;
  8941. var geoms = self.get('geoms');
  8942. var xScale = geoms[0].getXScale();
  8943. return xScale;
  8944. }
  8945. /**
  8946. * get the scale of y axis
  8947. * @return {Array} return the scale
  8948. */
  8949. ;
  8950. _proto.getYScales = function getYScales() {
  8951. var geoms = this.get('geoms');
  8952. var rst = [];
  8953. each$1(geoms, function (geom) {
  8954. var yScale = geom.getYScale();
  8955. if (rst.indexOf(yScale) === -1) {
  8956. rst.push(yScale);
  8957. }
  8958. });
  8959. return rst;
  8960. };
  8961. _proto.getLegendItems = function getLegendItems() {
  8962. if (this.get('legendItems')) {
  8963. return this.get('legendItems');
  8964. }
  8965. var legendItems = {};
  8966. var scales = [];
  8967. var geoms = this.get('geoms');
  8968. each$1(geoms, function (geom) {
  8969. var colorAttr = geom.getAttr('color');
  8970. if (colorAttr) {
  8971. var scale = colorAttr.getScale('color'); // 只支持分类图例
  8972. if (scale.isCategory && !_isScaleExist(scales, scale)) {
  8973. scales.push(scale);
  8974. var field = scale.field;
  8975. var ticks = scale.getTicks();
  8976. var items = [];
  8977. each$1(ticks, function (tick) {
  8978. var text = tick.text;
  8979. var name = text;
  8980. var scaleValue = tick.value;
  8981. var value = scale.invert(scaleValue);
  8982. var color = colorAttr.mapping(value).join('') || Global.defaultColor;
  8983. var marker = {
  8984. fill: color,
  8985. radius: 3,
  8986. symbol: 'circle',
  8987. stroke: '#fff'
  8988. };
  8989. items.push({
  8990. name: name,
  8991. // for display
  8992. dataValue: value,
  8993. // the origin value
  8994. checked: true,
  8995. marker: marker
  8996. });
  8997. });
  8998. legendItems[field] = items;
  8999. }
  9000. }
  9001. });
  9002. this.set('legendItems', legendItems);
  9003. return legendItems;
  9004. } // register the plugins
  9005. ;
  9006. _proto.registerPlugins = function registerPlugins(plugins) {
  9007. var self = this;
  9008. var chartPlugins = self.get('plugins') || [];
  9009. if (!isArray$1(chartPlugins)) {
  9010. chartPlugins = [chartPlugins];
  9011. }
  9012. [].concat(plugins).forEach(function (plugin) {
  9013. if (chartPlugins.indexOf(plugin) === -1) {
  9014. plugin.init && plugin.init(self); // init
  9015. chartPlugins.push(plugin);
  9016. }
  9017. });
  9018. Chart.plugins._cacheId++;
  9019. self.set('plugins', chartPlugins);
  9020. };
  9021. _proto._renderAxis = function _renderAxis() {
  9022. var axisController = this.get('axisController');
  9023. var xScale = this.getXScale();
  9024. var yScales = this.getYScales();
  9025. var coord = this.get('coord');
  9026. Chart.plugins.notify(this, 'beforeRenderAxis');
  9027. axisController.createAxis(coord, xScale, yScales);
  9028. };
  9029. _proto._isAutoPadding = function _isAutoPadding() {
  9030. if (this.get('_padding')) {
  9031. return false;
  9032. }
  9033. var padding = this.get('padding');
  9034. if (isArray$1(padding)) {
  9035. return padding.indexOf('auto') !== -1;
  9036. }
  9037. return padding === 'auto';
  9038. };
  9039. _proto._updateLayout = function _updateLayout(padding) {
  9040. var width = this.get('width');
  9041. var height = this.get('height');
  9042. var start = {
  9043. x: padding[3],
  9044. y: padding[0]
  9045. };
  9046. var end = {
  9047. x: width - padding[1],
  9048. y: height - padding[2]
  9049. };
  9050. var plot = this.get('plot');
  9051. var coord = this.get('coord');
  9052. plot.reset(start, end);
  9053. coord.reset(plot);
  9054. }
  9055. /**
  9056. * 是否为横屏展示
  9057. *
  9058. * @param {Boolean} landscape 是否为横屏
  9059. */
  9060. ;
  9061. _proto.landscape = function landscape(_landscape) {
  9062. var canvas = this.get('canvas');
  9063. canvas.set('landscape', _landscape);
  9064. };
  9065. return Chart;
  9066. }(Base$2);
  9067. Chart.plugins = Chart.initPlugins();
  9068. var track = function track() {
  9069. return null;
  9070. };
  9071. Global.version;
  9072. /**
  9073. * @fileOverview shape util
  9074. * @author dxq613@gmail.com
  9075. */
  9076. function splitPoints(obj) {
  9077. var points = [];
  9078. var x = obj.x;
  9079. var y = obj.y;
  9080. y = isArray$1(y) ? y : [y];
  9081. y.forEach(function (yItem, index) {
  9082. var point = {
  9083. x: isArray$1(x) ? x[index] : x,
  9084. y: yItem
  9085. };
  9086. points.push(point);
  9087. });
  9088. return points;
  9089. }
  9090. function splitArray(data, yField, connectNulls) {
  9091. if (!data.length) return [];
  9092. var arr = [];
  9093. var tmp = [];
  9094. var yValue;
  9095. each$1(data, function (obj) {
  9096. yValue = obj._origin ? obj._origin[yField] : obj[yField];
  9097. if (connectNulls) {
  9098. if (!isNil$1(yValue)) {
  9099. tmp.push(obj);
  9100. }
  9101. } else {
  9102. if (isArray$1(yValue) && isNil$1(yValue[0]) || isNil$1(yValue)) {
  9103. if (tmp.length) {
  9104. arr.push(tmp);
  9105. tmp = [];
  9106. }
  9107. } else {
  9108. tmp.push(obj);
  9109. }
  9110. }
  9111. });
  9112. if (tmp.length) {
  9113. arr.push(tmp);
  9114. }
  9115. return arr;
  9116. }
  9117. var SHAPES$2 = ['circle', 'hollowCircle', 'rect'];
  9118. Shape$1.registerFactory('point', {
  9119. defaultShapeType: 'circle',
  9120. getDefaultPoints: function getDefaultPoints(pointInfo) {
  9121. return splitPoints(pointInfo);
  9122. }
  9123. });
  9124. function getPointsCfg(cfg) {
  9125. var style = {
  9126. lineWidth: 0,
  9127. stroke: cfg.color,
  9128. fill: cfg.color
  9129. };
  9130. if (cfg.size) {
  9131. style.size = cfg.size;
  9132. }
  9133. mix$1(style, cfg.style);
  9134. return mix$1({}, Global.shape.point, style);
  9135. }
  9136. function drawShape$1(cfg, container, shape) {
  9137. if (cfg.size === 0) return;
  9138. var pointCfg = getPointsCfg(cfg);
  9139. var size = pointCfg.r || pointCfg.size;
  9140. var x = cfg.x;
  9141. var y = !isArray$1(cfg.y) ? [cfg.y] : cfg.y;
  9142. if (shape === 'hollowCircle') {
  9143. pointCfg.lineWidth = 1;
  9144. pointCfg.fill = null;
  9145. }
  9146. for (var i = 0, len = y.length; i < len; i++) {
  9147. if (shape === 'rect') {
  9148. return container.addShape('Rect', {
  9149. className: 'point',
  9150. attrs: mix$1({
  9151. x: x - size,
  9152. y: y[i] - size,
  9153. width: size * 2,
  9154. height: size * 2
  9155. }, pointCfg)
  9156. });
  9157. }
  9158. return container.addShape('Circle', {
  9159. className: 'point',
  9160. attrs: mix$1({
  9161. x: x,
  9162. y: y[i],
  9163. r: size
  9164. }, pointCfg)
  9165. });
  9166. }
  9167. }
  9168. each$1(SHAPES$2, function (shapeType) {
  9169. Shape$1.registerShape('point', shapeType, {
  9170. draw: function draw(cfg, container) {
  9171. return drawShape$1(cfg, container, shapeType);
  9172. }
  9173. });
  9174. });
  9175. var Point$1 = /*#__PURE__*/function (_Geom) {
  9176. _inheritsLoose$3(Point, _Geom);
  9177. function Point() {
  9178. return _Geom.apply(this, arguments) || this;
  9179. }
  9180. var _proto = Point.prototype;
  9181. _proto.getDefaultCfg = function getDefaultCfg() {
  9182. var cfg = _Geom.prototype.getDefaultCfg.call(this);
  9183. cfg.type = 'point';
  9184. cfg.shapeType = 'point';
  9185. cfg.generatePoints = false;
  9186. return cfg;
  9187. };
  9188. _proto.draw = function draw(data, shapeFactory) {
  9189. var self = this;
  9190. var container = self.get('container');
  9191. each$1(data, function (obj) {
  9192. var shape = obj.shape;
  9193. var cfg = self.getDrawCfg(obj);
  9194. if (isArray$1(obj.y)) {
  9195. var hasStack = self.hasAdjust('stack');
  9196. each$1(obj.y, function (y, idx) {
  9197. cfg.y = y;
  9198. if (!hasStack || idx !== 0) {
  9199. self.drawShape(shape, obj, cfg, container, shapeFactory);
  9200. }
  9201. });
  9202. } else if (!isNil$1(obj.y)) {
  9203. self.drawShape(shape, obj, cfg, container, shapeFactory);
  9204. }
  9205. });
  9206. };
  9207. return Point;
  9208. }(Geom);
  9209. Geom.Point = Point$1;
  9210. Shape$1.registerFactory('line', {
  9211. defaultShapeType: 'line'
  9212. });
  9213. function getStyle(cfg) {
  9214. var style = {
  9215. strokeStyle: cfg.color
  9216. };
  9217. if (cfg.size >= 0) {
  9218. style.lineWidth = cfg.size;
  9219. }
  9220. mix$1(style, cfg.style);
  9221. return mix$1({}, Global.shape.line, style);
  9222. }
  9223. function drawLines(cfg, container, style, smooth) {
  9224. var points = cfg.points;
  9225. if (points.length && isArray$1(points[0].y)) {
  9226. var topPoints = [];
  9227. var bottomPoints = [];
  9228. for (var i = 0, len = points.length; i < len; i++) {
  9229. var point = points[i];
  9230. var tmp = splitPoints(point);
  9231. bottomPoints.push(tmp[0]);
  9232. topPoints.push(tmp[1]);
  9233. }
  9234. if (cfg.isInCircle) {
  9235. topPoints.push(topPoints[0]);
  9236. bottomPoints.push(bottomPoints[0]);
  9237. }
  9238. if (cfg.isStack) {
  9239. return container.addShape('Polyline', {
  9240. className: 'line',
  9241. attrs: mix$1({
  9242. points: topPoints,
  9243. smooth: smooth
  9244. }, style)
  9245. });
  9246. }
  9247. var topShape = container.addShape('Polyline', {
  9248. className: 'line',
  9249. attrs: mix$1({
  9250. points: topPoints,
  9251. smooth: smooth
  9252. }, style)
  9253. });
  9254. var bottomShape = container.addShape('Polyline', {
  9255. className: 'line',
  9256. attrs: mix$1({
  9257. points: bottomPoints,
  9258. smooth: smooth
  9259. }, style)
  9260. });
  9261. return [topShape, bottomShape];
  9262. }
  9263. if (cfg.isInCircle) {
  9264. points.push(points[0]);
  9265. }
  9266. return container.addShape('Polyline', {
  9267. className: 'line',
  9268. attrs: mix$1({
  9269. points: points,
  9270. smooth: smooth
  9271. }, style)
  9272. });
  9273. }
  9274. var SHAPES$1 = ['line', 'smooth', 'dash'];
  9275. each$1(SHAPES$1, function (shapeType) {
  9276. Shape$1.registerShape('line', shapeType, {
  9277. draw: function draw(cfg, container) {
  9278. var smooth = shapeType === 'smooth';
  9279. var style = getStyle(cfg);
  9280. if (shapeType === 'dash') {
  9281. style.lineDash = Global.lineDash;
  9282. }
  9283. return drawLines(cfg, container, style, smooth);
  9284. }
  9285. });
  9286. });
  9287. var Path = /*#__PURE__*/function (_Geom) {
  9288. _inheritsLoose$3(Path, _Geom);
  9289. function Path() {
  9290. return _Geom.apply(this, arguments) || this;
  9291. }
  9292. var _proto = Path.prototype;
  9293. _proto.getDefaultCfg = function getDefaultCfg() {
  9294. var cfg = _Geom.prototype.getDefaultCfg.call(this);
  9295. cfg.type = 'path';
  9296. cfg.shapeType = 'line';
  9297. return cfg;
  9298. };
  9299. _proto.getDrawCfg = function getDrawCfg(obj) {
  9300. var cfg = _Geom.prototype.getDrawCfg.call(this, obj);
  9301. cfg.isStack = this.hasAdjust('stack');
  9302. return cfg;
  9303. };
  9304. _proto.draw = function draw(data, shapeFactory) {
  9305. var self = this;
  9306. var container = self.get('container');
  9307. var yScale = self.getYScale();
  9308. var connectNulls = self.get('connectNulls');
  9309. var splitArrayObj = splitArray(data, yScale.field, connectNulls);
  9310. var cfg = this.getDrawCfg(data[0]);
  9311. cfg.origin = data;
  9312. each$1(splitArrayObj, function (subData, splitedIndex) {
  9313. cfg.splitedIndex = splitedIndex;
  9314. cfg.points = subData;
  9315. self.drawShape(cfg.shape, data[0], cfg, container, shapeFactory);
  9316. });
  9317. };
  9318. return Path;
  9319. }(Geom);
  9320. Geom.Path = Path;
  9321. var Line$1 = /*#__PURE__*/function (_Path) {
  9322. _inheritsLoose$3(Line, _Path);
  9323. function Line() {
  9324. return _Path.apply(this, arguments) || this;
  9325. }
  9326. var _proto = Line.prototype;
  9327. _proto.getDefaultCfg = function getDefaultCfg() {
  9328. var cfg = _Path.prototype.getDefaultCfg.call(this);
  9329. cfg.type = 'line';
  9330. cfg.sortable = true;
  9331. return cfg;
  9332. };
  9333. return Line;
  9334. }(Path);
  9335. Geom.Line = Line$1;
  9336. function equals(v1, v2) {
  9337. return Math.abs(v1 - v2) < 0.00001;
  9338. }
  9339. function notEmpty(value) {
  9340. return !isNaN(value) && !isNil$1(value);
  9341. }
  9342. function filterPoints(points) {
  9343. var filteredPoints = []; // filter the point which x or y is NaN
  9344. for (var i = 0, len = points.length; i < len; i++) {
  9345. var point = points[i];
  9346. if (notEmpty(point.x) && notEmpty(point.y)) {
  9347. filteredPoints.push(point);
  9348. }
  9349. }
  9350. return filteredPoints;
  9351. }
  9352. function equalsCenter(points, center) {
  9353. var eqls = true;
  9354. each$1(points, function (point) {
  9355. if (!equals(point.x, center.x) || !equals(point.y, center.y)) {
  9356. eqls = false;
  9357. return false;
  9358. }
  9359. });
  9360. return eqls;
  9361. }
  9362. function drawRectShape(topPoints, bottomPoints, container, style, isSmooth) {
  9363. var shape;
  9364. var points = topPoints.concat(bottomPoints);
  9365. if (isSmooth) {
  9366. shape = container.addShape('Custom', {
  9367. className: 'area',
  9368. attrs: mix$1({
  9369. points: points
  9370. }, style),
  9371. createPath: function createPath(context) {
  9372. var constaint = [[0, 0], [1, 1]];
  9373. var points = filterPoints(this._attrs.attrs.points);
  9374. var pointsLen = points.length;
  9375. var topPoints = points.slice(0, pointsLen / 2);
  9376. var bottomPoints = points.slice(pointsLen / 2, pointsLen);
  9377. var topSps = catmullRom2bezier(topPoints, false, constaint);
  9378. context.beginPath();
  9379. context.moveTo(topPoints[0].x, topPoints[0].y);
  9380. for (var i = 0, n = topSps.length; i < n; i++) {
  9381. var sp = topSps[i];
  9382. context.bezierCurveTo(sp[1], sp[2], sp[3], sp[4], sp[5], sp[6]);
  9383. }
  9384. if (bottomPoints.length) {
  9385. var bottomSps = catmullRom2bezier(bottomPoints, false, constaint);
  9386. context.lineTo(bottomPoints[0].x, bottomPoints[0].y);
  9387. for (var _i = 0, _n = bottomSps.length; _i < _n; _i++) {
  9388. var _sp = bottomSps[_i];
  9389. context.bezierCurveTo(_sp[1], _sp[2], _sp[3], _sp[4], _sp[5], _sp[6]);
  9390. }
  9391. }
  9392. context.closePath();
  9393. },
  9394. calculateBox: function calculateBox() {
  9395. var points = filterPoints(this._attrs.attrs.points);
  9396. return getBBoxFromPoints(points);
  9397. }
  9398. });
  9399. } else {
  9400. shape = container.addShape('Polyline', {
  9401. className: 'area',
  9402. attrs: mix$1({
  9403. points: points
  9404. }, style)
  9405. });
  9406. }
  9407. return shape;
  9408. }
  9409. function drawShape(cfg, container, isSmooth) {
  9410. var self = this;
  9411. var points = cfg.points;
  9412. var topPoints = [];
  9413. var bottomPoints = [];
  9414. each$1(points, function (point) {
  9415. bottomPoints.push(point[0]);
  9416. topPoints.push(point[1]);
  9417. });
  9418. var style = mix$1({
  9419. fillStyle: cfg.color
  9420. }, Global.shape.area, cfg.style);
  9421. bottomPoints.reverse();
  9422. topPoints = self.parsePoints(topPoints);
  9423. bottomPoints = self.parsePoints(bottomPoints);
  9424. if (cfg.isInCircle) {
  9425. topPoints.push(topPoints[0]);
  9426. bottomPoints.unshift(bottomPoints[bottomPoints.length - 1]);
  9427. if (equalsCenter(bottomPoints, cfg.center)) {
  9428. bottomPoints = [];
  9429. }
  9430. }
  9431. return drawRectShape(topPoints, bottomPoints, container, style, isSmooth);
  9432. }
  9433. Shape$1.registerFactory('area', {
  9434. defaultShapeType: 'area',
  9435. getDefaultPoints: function getDefaultPoints(obj) {
  9436. var x = obj.x;
  9437. var y = obj.y;
  9438. var y0 = obj.y0;
  9439. y = isArray$1(y) ? y : [y0, y];
  9440. var points = [];
  9441. points.push({
  9442. x: x,
  9443. y: y[0]
  9444. }, {
  9445. x: x,
  9446. y: y[1]
  9447. });
  9448. return points;
  9449. }
  9450. });
  9451. var SHAPES = ['area', 'smooth'];
  9452. each$1(SHAPES, function (shapeType) {
  9453. Shape$1.registerShape('area', shapeType, {
  9454. draw: function draw(cfg, container) {
  9455. var smooth = shapeType === 'smooth';
  9456. return drawShape.call(this, cfg, container, smooth);
  9457. }
  9458. });
  9459. });
  9460. var Area = /*#__PURE__*/function (_Geom) {
  9461. _inheritsLoose$3(Area, _Geom);
  9462. function Area() {
  9463. return _Geom.apply(this, arguments) || this;
  9464. }
  9465. var _proto = Area.prototype;
  9466. /**
  9467. * get the default configuration
  9468. * @protected
  9469. * @return {Object} return the result
  9470. */
  9471. _proto.getDefaultCfg = function getDefaultCfg() {
  9472. var cfg = _Geom.prototype.getDefaultCfg.call(this);
  9473. cfg.type = 'area';
  9474. cfg.shapeType = 'area';
  9475. cfg.generatePoints = true;
  9476. cfg.sortable = true;
  9477. return cfg;
  9478. };
  9479. _proto.draw = function draw(data, shapeFactory) {
  9480. var self = this;
  9481. var container = self.get('container');
  9482. var cfg = this.getDrawCfg(data[0]);
  9483. var yScale = self.getYScale();
  9484. var connectNulls = self.get('connectNulls');
  9485. var splitArrayfn = splitArray(data, yScale.field, connectNulls);
  9486. cfg.origin = data;
  9487. each$1(splitArrayfn, function (subData, splitedIndex) {
  9488. cfg.splitedIndex = splitedIndex;
  9489. var points = subData.map(function (obj) {
  9490. return obj.points;
  9491. });
  9492. cfg.points = points;
  9493. self.drawShape(cfg.shape, data[0], cfg, container, shapeFactory);
  9494. });
  9495. };
  9496. return Area;
  9497. }(Geom);
  9498. Geom.Area = Area;
  9499. /**
  9500. * @fileOverview Utility for calculate the with ratui in x axis
  9501. * @author sima.zhang1990@gmail.com
  9502. * @author dxq613@gmail.com
  9503. */
  9504. var SizeMixin = {
  9505. initEvent: function initEvent() {
  9506. var _this = this;
  9507. var chart = this.get('chart');
  9508. if (!chart) {
  9509. return;
  9510. }
  9511. chart.on(EVENT_AFTER_SIZE_CHANGE, function () {
  9512. _this.set('_width', null);
  9513. });
  9514. },
  9515. getDefaultSize: function getDefaultSize() {
  9516. var defaultSize = this.get('defaultSize');
  9517. if (!defaultSize) {
  9518. var coord = this.get('coord');
  9519. var xScale = this.getXScale();
  9520. var dataArray = this.get('dataArray');
  9521. var values = uniq(xScale.values);
  9522. var count = values.length;
  9523. var range = xScale.range;
  9524. var normalizeSize = 1 / count;
  9525. var widthRatio = 1;
  9526. if (coord && coord.isPolar) {
  9527. if (coord.transposed && count > 1) {
  9528. widthRatio = Global.widthRatio.multiplePie;
  9529. } else {
  9530. widthRatio = Global.widthRatio.rose;
  9531. }
  9532. } else {
  9533. if (xScale.isLinear) {
  9534. normalizeSize *= range[1] - range[0];
  9535. }
  9536. widthRatio = Global.widthRatio.column;
  9537. }
  9538. normalizeSize *= widthRatio;
  9539. if (this.hasAdjust('dodge')) {
  9540. normalizeSize = normalizeSize / dataArray.length;
  9541. }
  9542. defaultSize = normalizeSize;
  9543. this.set('defaultSize', defaultSize);
  9544. }
  9545. return defaultSize;
  9546. },
  9547. getDimWidth: function getDimWidth(dimName) {
  9548. var coord = this.get('coord');
  9549. var start = coord.convertPoint({
  9550. x: 0,
  9551. y: 0
  9552. });
  9553. var end = coord.convertPoint({
  9554. x: dimName === 'x' ? 1 : 0,
  9555. y: dimName === 'x' ? 0 : 1
  9556. });
  9557. var width = 0;
  9558. if (start && end) {
  9559. width = Math.sqrt(Math.pow(end.x - start.x, 2) + Math.pow(end.y - start.y, 2));
  9560. }
  9561. return width;
  9562. },
  9563. _getWidth: function _getWidth() {
  9564. var width = this.get('_width');
  9565. if (!width) {
  9566. var coord = this.get('coord');
  9567. if (coord && coord.isPolar && !coord.transposed) {
  9568. width = (coord.endAngle - coord.startAngle) * coord.circleRadius;
  9569. } else {
  9570. width = this.getDimWidth('x');
  9571. }
  9572. this.set('_width', width);
  9573. }
  9574. return width;
  9575. },
  9576. _toNormalizedSize: function _toNormalizedSize(size) {
  9577. var width = this._getWidth();
  9578. return size / width;
  9579. },
  9580. _toCoordSize: function _toCoordSize(normalizeSize) {
  9581. var width = this._getWidth();
  9582. return width * normalizeSize;
  9583. },
  9584. getNormalizedSize: function getNormalizedSize(obj) {
  9585. var size = this.getAttrValue('size', obj);
  9586. if (isNil$1(size)) {
  9587. size = this.getDefaultSize();
  9588. } else {
  9589. size = this._toNormalizedSize(size);
  9590. }
  9591. return size;
  9592. },
  9593. getSize: function getSize(obj) {
  9594. var size = this.getAttrValue('size', obj);
  9595. if (isNil$1(size)) {
  9596. var normalizeSize = this.getDefaultSize();
  9597. size = this._toCoordSize(normalizeSize);
  9598. }
  9599. return size;
  9600. }
  9601. };
  9602. function getRectPoints(cfg) {
  9603. var x = cfg.x,
  9604. y = cfg.y,
  9605. y0 = cfg.y0,
  9606. size = cfg.size;
  9607. var ymin = y0;
  9608. var ymax = y;
  9609. if (isArray$1(y)) {
  9610. ymax = y[1];
  9611. ymin = y[0];
  9612. }
  9613. var xmin;
  9614. var xmax;
  9615. if (isArray$1(x)) {
  9616. xmin = x[0];
  9617. xmax = x[1];
  9618. } else {
  9619. xmin = x - size / 2;
  9620. xmax = x + size / 2;
  9621. }
  9622. return [{
  9623. x: xmin,
  9624. y: ymin
  9625. }, {
  9626. x: xmin,
  9627. y: ymax
  9628. }, {
  9629. x: xmax,
  9630. y: ymax
  9631. }, {
  9632. x: xmax,
  9633. y: ymin
  9634. }];
  9635. }
  9636. function getRectRange(points) {
  9637. var xValues = [];
  9638. var yValues = [];
  9639. for (var i = 0, len = points.length; i < len; i++) {
  9640. var point = points[i];
  9641. xValues.push(point.x);
  9642. yValues.push(point.y);
  9643. }
  9644. var xMin = Math.min.apply(null, xValues);
  9645. var yMin = Math.min.apply(null, yValues);
  9646. var xMax = Math.max.apply(null, xValues);
  9647. var yMax = Math.max.apply(null, yValues);
  9648. return {
  9649. x: xMin,
  9650. y: yMin,
  9651. width: xMax - xMin,
  9652. height: yMax - yMin
  9653. };
  9654. }
  9655. function getMiddlePoint(a, b) {
  9656. var x = (a.x - b.x) / 2 + b.x;
  9657. var y = (a.y - b.y) / 2 + b.y;
  9658. return {
  9659. x: x,
  9660. y: y
  9661. };
  9662. }
  9663. Shape$1.registerFactory('interval', {
  9664. defaultShapeType: 'rect',
  9665. getDefaultPoints: function getDefaultPoints(cfg) {
  9666. return getRectPoints(cfg);
  9667. }
  9668. });
  9669. Shape$1.registerShape('interval', 'rect', {
  9670. draw: function draw(cfg, container) {
  9671. var points = this.parsePoints(cfg.points);
  9672. var style = mix$1({
  9673. fill: cfg.color
  9674. }, Global.shape.interval, cfg.style);
  9675. if (cfg.isInCircle) {
  9676. var newPoints = points.slice(0);
  9677. if (this._coord.transposed) {
  9678. newPoints = [points[0], points[3], points[2], points[1]];
  9679. }
  9680. var _cfg$center = cfg.center,
  9681. x = _cfg$center.x,
  9682. y = _cfg$center.y;
  9683. var v = [1, 0];
  9684. var v0 = [newPoints[0].x - x, newPoints[0].y - y];
  9685. var v1 = [newPoints[1].x - x, newPoints[1].y - y];
  9686. var v2 = [newPoints[2].x - x, newPoints[2].y - y];
  9687. var startAngle = Vector2.angleTo(v, v1);
  9688. var endAngle = Vector2.angleTo(v, v2);
  9689. var r0 = Vector2.length(v0);
  9690. var r = Vector2.length(v1);
  9691. if (startAngle >= 1.5 * Math.PI) {
  9692. startAngle = startAngle - 2 * Math.PI;
  9693. }
  9694. if (endAngle >= 1.5 * Math.PI) {
  9695. endAngle = endAngle - 2 * Math.PI;
  9696. }
  9697. return container.addShape('Sector', {
  9698. className: 'interval',
  9699. attrs: mix$1({
  9700. x: x,
  9701. y: y,
  9702. r: r,
  9703. r0: r0,
  9704. startAngle: startAngle,
  9705. endAngle: endAngle
  9706. }, style)
  9707. });
  9708. }
  9709. var rectCfg = getRectRange(points);
  9710. return container.addShape('rect', {
  9711. className: 'interval',
  9712. attrs: mix$1(rectCfg, style)
  9713. });
  9714. }
  9715. }); // 金字塔 和 漏斗图
  9716. ['pyramid', 'funnel'].forEach(function (shapeType) {
  9717. Shape$1.registerShape('interval', shapeType, {
  9718. getPoints: function getPoints(cfg) {
  9719. cfg.size = cfg.size * 2; // 漏斗图的 size 是柱状图的两倍
  9720. return getRectPoints(cfg);
  9721. },
  9722. draw: function draw(cfg, container) {
  9723. var points = this.parsePoints(cfg.points);
  9724. var nextPoints = this.parsePoints(cfg.nextPoints);
  9725. var polygonPoints = null;
  9726. if (nextPoints) {
  9727. polygonPoints = [points[0], points[1], nextPoints[1], nextPoints[0]];
  9728. } else {
  9729. polygonPoints = [points[0], points[1]]; // pyramid 顶部是三角形,所以取中心点就好了,funnel顶部是长方形
  9730. if (shapeType === 'pyramid') {
  9731. polygonPoints.push(getMiddlePoint(points[2], points[3]));
  9732. } else {
  9733. polygonPoints.push(points[2], points[3]);
  9734. }
  9735. }
  9736. var attrs = mix$1({
  9737. fill: cfg.color,
  9738. points: polygonPoints
  9739. }, Global.shape.interval, cfg.style);
  9740. return container.addShape('polygon', {
  9741. className: 'interval',
  9742. attrs: attrs
  9743. });
  9744. }
  9745. });
  9746. });
  9747. var Interval = /*#__PURE__*/function (_Geom) {
  9748. _inheritsLoose$3(Interval, _Geom);
  9749. var _proto = Interval.prototype;
  9750. _proto.getDefaultCfg = function getDefaultCfg() {
  9751. var cfg = _Geom.prototype.getDefaultCfg.call(this);
  9752. cfg.type = 'interval';
  9753. cfg.shapeType = 'interval';
  9754. cfg.generatePoints = true;
  9755. return cfg;
  9756. };
  9757. function Interval(cfg) {
  9758. var _this;
  9759. _this = _Geom.call(this, cfg) || this;
  9760. mix$1(_assertThisInitialized(_this), SizeMixin);
  9761. return _this;
  9762. }
  9763. _proto.init = function init() {
  9764. _Geom.prototype.init.call(this); // 绑定事件
  9765. this.initEvent();
  9766. };
  9767. _proto.createShapePointsCfg = function createShapePointsCfg(obj) {
  9768. var cfg = _Geom.prototype.createShapePointsCfg.call(this, obj);
  9769. cfg.size = this.getNormalizedSize(obj);
  9770. return cfg;
  9771. };
  9772. _proto.clearInner = function clearInner() {
  9773. _Geom.prototype.clearInner.call(this);
  9774. this.set('defaultSize', null);
  9775. };
  9776. return Interval;
  9777. }(Geom);
  9778. Geom.Interval = Interval;
  9779. Shape$1.registerFactory('polygon', {
  9780. defaultShapeType: 'polygon',
  9781. getDefaultPoints: function getDefaultPoints(pointInfo) {
  9782. var points = [];
  9783. var x = pointInfo.x,
  9784. y = pointInfo.y;
  9785. for (var i = 0, len = x.length; i < len; i++) {
  9786. points.push({
  9787. x: x[i],
  9788. y: y[i]
  9789. });
  9790. }
  9791. return points;
  9792. }
  9793. });
  9794. Shape$1.registerShape('polygon', 'polygon', {
  9795. draw: function draw(cfg, container) {
  9796. var points = this.parsePoints(cfg.points);
  9797. var style = mix$1({
  9798. fill: cfg.color,
  9799. points: points
  9800. }, cfg.style);
  9801. return container.addShape('Polygon', {
  9802. className: 'polygon',
  9803. attrs: style
  9804. });
  9805. }
  9806. });
  9807. var Polygon = /*#__PURE__*/function (_Geom) {
  9808. _inheritsLoose$3(Polygon, _Geom);
  9809. function Polygon() {
  9810. return _Geom.apply(this, arguments) || this;
  9811. }
  9812. var _proto = Polygon.prototype;
  9813. _proto.getDefaultCfg = function getDefaultCfg() {
  9814. var cfg = _Geom.prototype.getDefaultCfg.call(this);
  9815. cfg.type = 'polygon';
  9816. cfg.shapeType = 'polygon';
  9817. cfg.generatePoints = true;
  9818. return cfg;
  9819. };
  9820. _proto.createShapePointsCfg = function createShapePointsCfg(obj) {
  9821. var cfg = _Geom.prototype.createShapePointsCfg.call(this, obj);
  9822. var self = this;
  9823. var x = cfg.x;
  9824. var y = cfg.y;
  9825. var temp;
  9826. if (!(isArray$1(x) && isArray$1(y))) {
  9827. var xScale = self.getXScale();
  9828. var yScale = self.getYScale();
  9829. var xCount = xScale.values ? xScale.values.length : xScale.ticks.length;
  9830. var yCount = yScale.values ? yScale.values.length : yScale.ticks.length;
  9831. var xOffset = 0.5 * 1 / xCount;
  9832. var yOffset = 0.5 * 1 / yCount;
  9833. if (xScale.isCategory && yScale.isCategory) {
  9834. x = [x - xOffset, x - xOffset, x + xOffset, x + xOffset];
  9835. y = [y - yOffset, y + yOffset, y + yOffset, y - yOffset];
  9836. } else if (isArray$1(x)) {
  9837. temp = x;
  9838. x = [temp[0], temp[0], temp[1], temp[1]];
  9839. y = [y - yOffset / 2, y + yOffset / 2, y + yOffset / 2, y - yOffset / 2];
  9840. } else if (isArray$1(y)) {
  9841. temp = y;
  9842. y = [temp[0], temp[1], temp[1], temp[0]];
  9843. x = [x - xOffset / 2, x - xOffset / 2, x + xOffset / 2, x + xOffset / 2];
  9844. }
  9845. cfg.x = x;
  9846. cfg.y = y;
  9847. }
  9848. return cfg;
  9849. };
  9850. return Polygon;
  9851. }(Geom);
  9852. Geom.Polygon = Polygon;
  9853. function _sortValue(value) {
  9854. var sorted = value.sort(function (a, b) {
  9855. return a < b ? 1 : -1;
  9856. });
  9857. var length = sorted.length;
  9858. if (length < 4) {
  9859. var min = sorted[length - 1];
  9860. for (var i = 0; i < 4 - length; i++) {
  9861. sorted.push(min);
  9862. }
  9863. }
  9864. return sorted;
  9865. } // from left bottom corner, and clockwise
  9866. function getCandlePoints(x, y, width) {
  9867. var yValues = _sortValue(y);
  9868. var points = [{
  9869. x: x,
  9870. y: yValues[0]
  9871. }, {
  9872. x: x,
  9873. y: yValues[1]
  9874. }, {
  9875. x: x - width / 2,
  9876. y: yValues[2]
  9877. }, {
  9878. x: x - width / 2,
  9879. y: yValues[1]
  9880. }, {
  9881. x: x + width / 2,
  9882. y: yValues[1]
  9883. }, {
  9884. x: x + width / 2,
  9885. y: yValues[2]
  9886. }, {
  9887. x: x,
  9888. y: yValues[2]
  9889. }, {
  9890. x: x,
  9891. y: yValues[3]
  9892. }];
  9893. return points;
  9894. }
  9895. Shape$1.registerFactory('schema', {});
  9896. Shape$1.registerShape('schema', 'candle', {
  9897. getPoints: function getPoints(cfg) {
  9898. return getCandlePoints(cfg.x, cfg.y, cfg.size);
  9899. },
  9900. draw: function draw(cfg, container) {
  9901. var points = this.parsePoints(cfg.points);
  9902. var style = mix$1({
  9903. stroke: cfg.color,
  9904. fill: cfg.color,
  9905. lineWidth: 1
  9906. }, cfg.style);
  9907. return container.addShape('Custom', {
  9908. className: 'schema',
  9909. attrs: style,
  9910. createPath: function createPath(ctx) {
  9911. ctx.beginPath();
  9912. ctx.moveTo(points[0].x, points[0].y);
  9913. ctx.lineTo(points[1].x, points[1].y);
  9914. ctx.moveTo(points[2].x, points[2].y);
  9915. for (var i = 3; i < 6; i++) {
  9916. ctx.lineTo(points[i].x, points[i].y);
  9917. }
  9918. ctx.closePath();
  9919. ctx.moveTo(points[6].x, points[6].y);
  9920. ctx.lineTo(points[7].x, points[7].y);
  9921. }
  9922. });
  9923. }
  9924. });
  9925. var Schema = /*#__PURE__*/function (_Geom) {
  9926. _inheritsLoose$3(Schema, _Geom);
  9927. var _proto = Schema.prototype;
  9928. _proto.getDefaultCfg = function getDefaultCfg() {
  9929. var cfg = _Geom.prototype.getDefaultCfg.call(this);
  9930. cfg.type = 'schema';
  9931. cfg.shapeType = 'schema';
  9932. cfg.generatePoints = true;
  9933. return cfg;
  9934. };
  9935. function Schema(cfg) {
  9936. var _this;
  9937. _this = _Geom.call(this, cfg) || this;
  9938. mix$1(_assertThisInitialized(_this), SizeMixin);
  9939. return _this;
  9940. }
  9941. _proto.init = function init() {
  9942. _Geom.prototype.init.call(this); // 绑定事件
  9943. this.initEvent();
  9944. };
  9945. _proto.createShapePointsCfg = function createShapePointsCfg(obj) {
  9946. var cfg = _Geom.prototype.createShapePointsCfg.call(this, obj);
  9947. cfg.size = this.getNormalizedSize(obj);
  9948. return cfg;
  9949. };
  9950. _proto.clearInner = function clearInner() {
  9951. _Geom.prototype.clearInner.call(this);
  9952. this.set('defaultSize', null);
  9953. };
  9954. return Schema;
  9955. }(Geom);
  9956. Geom.Schema = Schema;
  9957. var toString = {}.toString;
  9958. var isType = function isType(value, type) {
  9959. return toString.call(value) === '[object ' + type + ']';
  9960. };
  9961. var isType_1 = isType;
  9962. var isArray = Array.isArray ? Array.isArray : function (value) {
  9963. return isType_1(value, 'Array');
  9964. };
  9965. var isArray_1 = isArray;
  9966. // isFinite,
  9967. var isNil = function isNil(value) {
  9968. /**
  9969. * isNil(null) => true
  9970. * isNil() => true
  9971. */
  9972. return value === null || value === undefined;
  9973. };
  9974. var isNil_1 = isNil;
  9975. function _inheritsLoose$2(subClass, superClass) {
  9976. subClass.prototype = Object.create(superClass.prototype);
  9977. subClass.prototype.constructor = subClass;
  9978. subClass.__proto__ = superClass;
  9979. }
  9980. var Stack = /*#__PURE__*/function (_Adjust) {
  9981. _inheritsLoose$2(Stack, _Adjust);
  9982. function Stack() {
  9983. return _Adjust.apply(this, arguments) || this;
  9984. }
  9985. var _proto = Stack.prototype;
  9986. _proto._initDefaultCfg = function _initDefaultCfg() {
  9987. this.xField = null; // 调整对应的 x 方向对应的字段名称
  9988. this.yField = null; // 调整对应的 y 方向对应的字段名称
  9989. };
  9990. _proto.processAdjust = function processAdjust(dataArray) {
  9991. this.processStack(dataArray);
  9992. };
  9993. _proto.processStack = function processStack(dataArray) {
  9994. var self = this;
  9995. var xField = self.xField;
  9996. var yField = self.yField;
  9997. var count = dataArray.length;
  9998. var stackCache = {
  9999. positive: {},
  10000. negative: {}
  10001. }; // 层叠顺序翻转
  10002. if (self.reverseOrder) {
  10003. dataArray = dataArray.slice(0).reverse();
  10004. }
  10005. for (var i = 0; i < count; i++) {
  10006. var data = dataArray[i];
  10007. for (var j = 0, len = data.length; j < len; j++) {
  10008. var item = data[j];
  10009. var x = item[xField] || 0;
  10010. var y = item[yField];
  10011. var xkey = x.toString();
  10012. y = isArray_1(y) ? y[1] : y;
  10013. if (!isNil_1(y)) {
  10014. var direction = y >= 0 ? 'positive' : 'negative';
  10015. if (!stackCache[direction][xkey]) {
  10016. stackCache[direction][xkey] = 0;
  10017. }
  10018. item[yField] = [stackCache[direction][xkey], y + stackCache[direction][xkey]];
  10019. stackCache[direction][xkey] += y;
  10020. }
  10021. }
  10022. }
  10023. };
  10024. return Stack;
  10025. }(base);
  10026. base.Stack = Stack;
  10027. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
  10028. return typeof obj;
  10029. } : function (obj) {
  10030. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  10031. };
  10032. var isObject = function isObject(value) {
  10033. /**
  10034. * isObject({}) => true
  10035. * isObject([1, 2, 3]) => true
  10036. * isObject(Function) => true
  10037. * isObject(null) => false
  10038. */
  10039. var type = typeof value === 'undefined' ? 'undefined' : _typeof(value);
  10040. return value !== null && type === 'object' || type === 'function';
  10041. };
  10042. var isObject_1 = isObject;
  10043. var each = function each(elements, func) {
  10044. if (!elements) {
  10045. return;
  10046. }
  10047. var rst = void 0;
  10048. if (isArray_1(elements)) {
  10049. for (var i = 0, len = elements.length; i < len; i++) {
  10050. rst = func(elements[i], i);
  10051. if (rst === false) {
  10052. break;
  10053. }
  10054. }
  10055. } else if (isObject_1(elements)) {
  10056. for (var k in elements) {
  10057. if (elements.hasOwnProperty(k)) {
  10058. rst = func(elements[k], k);
  10059. if (rst === false) {
  10060. break;
  10061. }
  10062. }
  10063. }
  10064. }
  10065. };
  10066. var each_1 = each;
  10067. function _inheritsLoose$1(subClass, superClass) {
  10068. subClass.prototype = Object.create(superClass.prototype);
  10069. subClass.prototype.constructor = subClass;
  10070. subClass.__proto__ = superClass;
  10071. }
  10072. var MARGIN_RATIO = 1 / 2;
  10073. var DODGE_RATIO = 1 / 2;
  10074. var Dodge = /*#__PURE__*/function (_Adjust) {
  10075. _inheritsLoose$1(Dodge, _Adjust);
  10076. function Dodge() {
  10077. return _Adjust.apply(this, arguments) || this;
  10078. }
  10079. var _proto = Dodge.prototype;
  10080. _proto._initDefaultCfg = function _initDefaultCfg() {
  10081. /**
  10082. * 调整过程中,2个数据的间距
  10083. * @type {Number}
  10084. */
  10085. this.marginRatio = MARGIN_RATIO;
  10086. /**
  10087. * 调整占单位宽度的比例,例如:占2个分类间距的 1/2
  10088. * @type {Number}
  10089. */
  10090. this.dodgeRatio = DODGE_RATIO;
  10091. this.adjustNames = ['x', 'y']; // 调整的维度,默认,x,y都做调整
  10092. };
  10093. _proto.getDodgeOffset = function getDodgeOffset(range, index, count) {
  10094. var self = this;
  10095. var pre = range.pre;
  10096. var next = range.next;
  10097. var tickLength = next - pre;
  10098. var width = tickLength * self.dodgeRatio / count;
  10099. var margin = self.marginRatio * width;
  10100. var offset = 1 / 2 * (tickLength - count * width - (count - 1) * margin) + ((index + 1) * width + index * margin) - 1 / 2 * width - 1 / 2 * tickLength;
  10101. return (pre + next) / 2 + offset;
  10102. };
  10103. _proto.processAdjust = function processAdjust(dataArray) {
  10104. var self = this;
  10105. var count = dataArray.length;
  10106. var xField = self.xField;
  10107. each_1(dataArray, function (data, index) {
  10108. for (var i = 0, len = data.length; i < len; i++) {
  10109. var obj = data[i];
  10110. var value = obj[xField];
  10111. var range = {
  10112. pre: len === 1 ? value - 1 : value - 0.5,
  10113. next: len === 1 ? value + 1 : value + 0.5
  10114. };
  10115. var dodgeValue = self.getDodgeOffset(range, index, count);
  10116. obj[xField] = dodgeValue;
  10117. }
  10118. });
  10119. };
  10120. return Dodge;
  10121. }(base);
  10122. base.Dodge = Dodge;
  10123. /**
  10124. * 是否为函数
  10125. * @param {*} fn 对象
  10126. * @return {Boolean} 是否函数
  10127. */
  10128. var isFunction = function isFunction(value) {
  10129. return isType_1(value, 'Function');
  10130. };
  10131. var isFunction_1 = isFunction;
  10132. /**
  10133. * @param {Array} arr The array to iterate over.
  10134. * @param {Function} [fn] The iteratee invoked per element.
  10135. * @return {*} Returns the maximum value.
  10136. * @example
  10137. *
  10138. * var objects = [{ 'n': 1 }, { 'n': 2 }];
  10139. *
  10140. * maxBy(objects, function(o) { return o.n; });
  10141. * // => { 'n': 2 }
  10142. *
  10143. * maxBy(objects, 'n');
  10144. * // => { 'n': 2 }
  10145. */
  10146. var maxBy = function maxBy(arr, fn) {
  10147. if (!isArray_1(arr)) {
  10148. return undefined;
  10149. }
  10150. var max = arr[0];
  10151. var maxData = void 0;
  10152. if (isFunction_1(fn)) {
  10153. maxData = fn(arr[0]);
  10154. } else {
  10155. maxData = arr[0][fn];
  10156. }
  10157. var data = void 0;
  10158. each_1(arr, function (val) {
  10159. if (isFunction_1(fn)) {
  10160. data = fn(val);
  10161. } else {
  10162. data = val[fn];
  10163. }
  10164. if (data > maxData) {
  10165. max = val;
  10166. maxData = data;
  10167. }
  10168. });
  10169. return max;
  10170. };
  10171. var maxBy_1 = maxBy;
  10172. var merge = function merge(dataArray) {
  10173. var rst = [];
  10174. for (var i = 0; i < dataArray.length; i++) {
  10175. rst = rst.concat(dataArray[i]);
  10176. }
  10177. return rst;
  10178. };
  10179. var merge_1 = merge;
  10180. function _inheritsLoose(subClass, superClass) {
  10181. subClass.prototype = Object.create(superClass.prototype);
  10182. subClass.prototype.constructor = subClass;
  10183. subClass.__proto__ = superClass;
  10184. }
  10185. var ArrayUtil = {
  10186. merge: merge_1
  10187. };
  10188. var Symmetric = /*#__PURE__*/function (_Adjust) {
  10189. _inheritsLoose(Symmetric, _Adjust);
  10190. function Symmetric() {
  10191. return _Adjust.apply(this, arguments) || this;
  10192. }
  10193. var _proto = Symmetric.prototype;
  10194. _proto._initDefaultCfg = function _initDefaultCfg() {
  10195. this.xField = null; // 调整对应的 x 方向对应的字段名称
  10196. this.yField = null; // 调整对应的 y 方向对应的字段名称
  10197. this.cacheMax = null; // 缓存的最大值
  10198. this.adjustNames = ['y']; // Only support stack y
  10199. this.groupFields = null; // 参与分组的数据维度
  10200. }; // 获取最大的y值
  10201. _proto._getMax = function _getMax(dim) {
  10202. var self = this;
  10203. var mergeData = self.mergeData;
  10204. var maxRecord = maxBy_1(mergeData, function (obj) {
  10205. var value = obj[dim];
  10206. if (isArray_1(value)) {
  10207. return Math.max.apply(null, value);
  10208. }
  10209. return value;
  10210. });
  10211. var maxValue = maxRecord[dim];
  10212. var max = isArray_1(maxValue) ? Math.max.apply(null, maxValue) : maxValue;
  10213. return max;
  10214. }; // 获取每个字段最大的值
  10215. _proto._getXValuesMax = function _getXValuesMax() {
  10216. var self = this;
  10217. var yField = self.yField;
  10218. var xField = self.xField;
  10219. var cache = {};
  10220. var mergeData = self.mergeData;
  10221. each_1(mergeData, function (obj) {
  10222. var xValue = obj[xField];
  10223. var yValue = obj[yField];
  10224. var max = isArray_1(yValue) ? Math.max.apply(null, yValue) : yValue;
  10225. cache[xValue] = cache[xValue] || 0;
  10226. if (cache[xValue] < max) {
  10227. cache[xValue] = max;
  10228. }
  10229. });
  10230. return cache;
  10231. }; // 入口函数
  10232. _proto.processAdjust = function processAdjust(dataArray) {
  10233. var self = this;
  10234. var mergeData = ArrayUtil.merge(dataArray);
  10235. self.mergeData = mergeData;
  10236. self._processSymmetric(dataArray);
  10237. self.mergeData = null;
  10238. }; // 处理对称
  10239. _proto._processSymmetric = function _processSymmetric(dataArray) {
  10240. var self = this;
  10241. var xField = self.xField;
  10242. var yField = self.yField;
  10243. var max = self._getMax(yField);
  10244. var first = dataArray[0][0];
  10245. var cache;
  10246. if (first && isArray_1(first[yField])) {
  10247. cache = self._getXValuesMax();
  10248. }
  10249. each_1(dataArray, function (data) {
  10250. each_1(data, function (obj) {
  10251. var value = obj[yField];
  10252. var offset;
  10253. if (isArray_1(value)) {
  10254. var xValue = obj[xField];
  10255. var valueMax = cache[xValue];
  10256. offset = (max - valueMax) / 2;
  10257. var tmp = [];
  10258. /* eslint-disable no-loop-func */
  10259. each_1(value, function (subVal) {
  10260. // 多个字段
  10261. tmp.push(offset + subVal);
  10262. });
  10263. /* eslint-enable no-loop-func */
  10264. obj[yField] = tmp;
  10265. } else {
  10266. offset = (max - value) / 2;
  10267. obj[yField] = [offset, value + offset];
  10268. }
  10269. });
  10270. });
  10271. };
  10272. return Symmetric;
  10273. }(base);
  10274. base.Symmetric = Symmetric;
  10275. var Polar = /*#__PURE__*/function (_Base) {
  10276. _inheritsLoose$3(Polar, _Base);
  10277. function Polar() {
  10278. return _Base.apply(this, arguments) || this;
  10279. }
  10280. var _proto = Polar.prototype;
  10281. _proto._initDefaultCfg = function _initDefaultCfg() {
  10282. this.type = 'polar';
  10283. this.startAngle = -Math.PI / 2;
  10284. this.endAngle = Math.PI * 3 / 2;
  10285. this.inner = 0;
  10286. this.innerRadius = 0; // alias
  10287. this.isPolar = true;
  10288. this.transposed = false;
  10289. this.center = null;
  10290. this.radius = null; // relative, 0 ~ 1
  10291. };
  10292. _proto.init = function init(start, end) {
  10293. _Base.prototype.init.call(this, start, end);
  10294. var self = this;
  10295. var inner = self.inner || self.innerRadius;
  10296. var width = Math.abs(end.x - start.x);
  10297. var height = Math.abs(end.y - start.y);
  10298. var maxRadius;
  10299. var center;
  10300. if (self.startAngle === -Math.PI && self.endAngle === 0) {
  10301. maxRadius = Math.min(width / 2, height);
  10302. center = {
  10303. x: (start.x + end.x) / 2,
  10304. y: start.y
  10305. };
  10306. } else {
  10307. maxRadius = Math.min(width, height) / 2;
  10308. center = {
  10309. x: (start.x + end.x) / 2,
  10310. y: (start.y + end.y) / 2
  10311. };
  10312. }
  10313. var radius = self.radius;
  10314. if (radius > 0 && radius <= 1) {
  10315. maxRadius = maxRadius * radius;
  10316. }
  10317. this.x = {
  10318. start: self.startAngle,
  10319. end: self.endAngle
  10320. };
  10321. this.y = {
  10322. start: maxRadius * inner,
  10323. end: maxRadius
  10324. };
  10325. this.center = center;
  10326. this.circleRadius = maxRadius; // the radius value in px
  10327. };
  10328. _proto._convertPoint = function _convertPoint(point) {
  10329. var self = this;
  10330. var center = self.center;
  10331. var transposed = self.transposed;
  10332. var xDim = transposed ? 'y' : 'x';
  10333. var yDim = transposed ? 'x' : 'y';
  10334. var x = self.x;
  10335. var y = self.y;
  10336. var angle = x.start + (x.end - x.start) * point[xDim];
  10337. var radius = y.start + (y.end - y.start) * point[yDim];
  10338. return {
  10339. x: center.x + Math.cos(angle) * radius,
  10340. y: center.y + Math.sin(angle) * radius
  10341. };
  10342. };
  10343. _proto._invertPoint = function _invertPoint(point) {
  10344. var self = this;
  10345. var center = self.center,
  10346. transposed = self.transposed,
  10347. x = self.x,
  10348. y = self.y;
  10349. var xDim = transposed ? 'y' : 'x';
  10350. var yDim = transposed ? 'x' : 'y';
  10351. var m = [1, 0, 0, 1, 0, 0];
  10352. Matrix.rotate(m, m, x.start);
  10353. var startV = [1, 0];
  10354. Vector2.transformMat2d(startV, startV, m);
  10355. startV = [startV[0], startV[1]];
  10356. var pointV = [point.x - center.x, point.y - center.y];
  10357. if (Vector2.zero(pointV)) {
  10358. return {
  10359. x: 0,
  10360. y: 0
  10361. };
  10362. }
  10363. var theta = Vector2.angleTo(startV, pointV, x.end < x.start);
  10364. if (Math.abs(theta - Math.PI * 2) < 0.001) {
  10365. theta = 0;
  10366. }
  10367. var l = Vector2.length(pointV);
  10368. var percentX = theta / (x.end - x.start);
  10369. percentX = x.end - x.start > 0 ? percentX : -percentX;
  10370. var percentY = (l - y.start) / (y.end - y.start);
  10371. var rst = {};
  10372. rst[xDim] = percentX;
  10373. rst[yDim] = percentY;
  10374. return rst;
  10375. };
  10376. return Polar;
  10377. }(Base$1);
  10378. Base$1.Polar = Polar;
  10379. var Circle = /*#__PURE__*/function (_Abstract) {
  10380. _inheritsLoose$3(Circle, _Abstract);
  10381. function Circle() {
  10382. return _Abstract.apply(this, arguments) || this;
  10383. }
  10384. var _proto = Circle.prototype;
  10385. _proto._initDefaultCfg = function _initDefaultCfg() {
  10386. _Abstract.prototype._initDefaultCfg.call(this);
  10387. this.startAngle = -Math.PI / 2; // start angle,in radian
  10388. this.endAngle = Math.PI * 3 / 2; // end angle, in radian
  10389. this.radius = null; // radius
  10390. this.center = null; // center
  10391. };
  10392. _proto.getOffsetPoint = function getOffsetPoint(value) {
  10393. var startAngle = this.startAngle,
  10394. endAngle = this.endAngle;
  10395. var angle = startAngle + (endAngle - startAngle) * value;
  10396. return this._getCirclePoint(angle);
  10397. };
  10398. _proto._getCirclePoint = function _getCirclePoint(angle, radius) {
  10399. var self = this;
  10400. var center = self.center;
  10401. radius = radius || self.radius;
  10402. return {
  10403. x: center.x + Math.cos(angle) * radius,
  10404. y: center.y + Math.sin(angle) * radius
  10405. };
  10406. };
  10407. _proto.getTextAlignInfo = function getTextAlignInfo(point, offset) {
  10408. var self = this;
  10409. var offsetVector = self.getOffsetVector(point, offset);
  10410. var align;
  10411. var baseLine = 'middle';
  10412. if (offsetVector[0] > 0) {
  10413. align = 'left';
  10414. } else if (offsetVector[0] < 0) {
  10415. align = 'right';
  10416. } else {
  10417. align = 'center';
  10418. if (offsetVector[1] > 0) {
  10419. baseLine = 'top';
  10420. } else if (offsetVector[1] < 0) {
  10421. baseLine = 'bottom';
  10422. }
  10423. }
  10424. return {
  10425. textAlign: align,
  10426. textBaseline: baseLine
  10427. };
  10428. };
  10429. _proto.getAxisVector = function getAxisVector(point) {
  10430. var center = this.center;
  10431. var factor = this.offsetFactor;
  10432. return [(point.y - center.y) * factor, (point.x - center.x) * -1 * factor];
  10433. };
  10434. _proto.drawLine = function drawLine(lineCfg) {
  10435. var center = this.center,
  10436. radius = this.radius,
  10437. startAngle = this.startAngle,
  10438. endAngle = this.endAngle;
  10439. var container = this.getContainer(lineCfg.top);
  10440. container.addShape('arc', {
  10441. className: 'axis-line',
  10442. attrs: mix$1({
  10443. x: center.x,
  10444. y: center.y,
  10445. r: radius,
  10446. startAngle: startAngle,
  10447. endAngle: endAngle
  10448. }, lineCfg)
  10449. });
  10450. };
  10451. return Circle;
  10452. }(Abastract);
  10453. Abastract.Circle = Circle;
  10454. var KEYWORDS_PERCENT = {
  10455. min: 0,
  10456. median: 0.5,
  10457. max: 1
  10458. };
  10459. var GuideBase = /*#__PURE__*/function () {
  10460. var _proto = GuideBase.prototype;
  10461. _proto._initDefaultCfg = function _initDefaultCfg() {};
  10462. function GuideBase(cfg) {
  10463. this._initDefaultCfg();
  10464. deepMix(this, cfg);
  10465. }
  10466. _proto._getNormalizedValue = function _getNormalizedValue(val, scale) {
  10467. var rst;
  10468. if (isNil$1(KEYWORDS_PERCENT[val])) {
  10469. rst = scale.scale(val);
  10470. } else {
  10471. rst = KEYWORDS_PERCENT[val];
  10472. }
  10473. return rst;
  10474. };
  10475. _proto.parsePercentPoint = function parsePercentPoint(coord, position) {
  10476. var xPercent = parseFloat(position[0]) / 100;
  10477. var yPercent = parseFloat(position[1]) / 100;
  10478. var start = coord.start;
  10479. var end = coord.end;
  10480. var width = Math.abs(start.x - end.x);
  10481. var height = Math.abs(start.y - end.y);
  10482. var x = width * xPercent + Math.min(start.x, end.x);
  10483. var y = height * yPercent + Math.min(start.y, end.y);
  10484. return {
  10485. x: x,
  10486. y: y
  10487. };
  10488. };
  10489. _proto.parsePoint = function parsePoint(coord, position) {
  10490. var self = this;
  10491. var xScale = self.xScale;
  10492. var yScales = self.yScales;
  10493. if (isFunction$1(position)) {
  10494. position = position(xScale, yScales); // position 必须是对象
  10495. } // 如果数据格式是 ['50%', '50%'] 的格式
  10496. // fix: 原始数据中可能会包含 'xxx5%xxx' 这样的数据,需要判断下 https://github.com/antvis/f2/issues/590
  10497. if (isString(position[0]) && position[0].indexOf('%') !== -1 && !isNaN(position[0].slice(0, -1))) {
  10498. return this.parsePercentPoint(coord, position);
  10499. }
  10500. var x = self._getNormalizedValue(position[0], xScale);
  10501. var y = self._getNormalizedValue(position[1], yScales[0]);
  10502. var point = coord.convertPoint({
  10503. x: x,
  10504. y: y
  10505. });
  10506. if (self.limitInPlot) {
  10507. // limit in chart plotRange
  10508. if (x >= 0 && x <= 1 && y >= 0 && y <= 1) {
  10509. return point;
  10510. }
  10511. return null;
  10512. }
  10513. return point;
  10514. }
  10515. /**
  10516. * render the guide component
  10517. * @param {Coord} coord coordinate instance
  10518. * @param {Canvas.Group} group the container
  10519. */
  10520. ;
  10521. _proto.render = function render() {};
  10522. _proto.repaint = function repaint() {
  10523. this.remove();
  10524. var coord = this.coord,
  10525. container = this.container,
  10526. canvas = this.canvas;
  10527. if (container && !container.isDestroyed()) {
  10528. this.render(coord, container);
  10529. canvas.draw();
  10530. }
  10531. };
  10532. _proto.remove = function remove() {
  10533. var element = this.element;
  10534. element && element.remove(true);
  10535. };
  10536. _proto.changeVisible = function changeVisible(visible) {
  10537. var self = this;
  10538. self.visible = visible;
  10539. var element = self.element;
  10540. if (!element) return;
  10541. if (element.set) {
  10542. element.set('visible', visible);
  10543. } else {
  10544. element.style.display = visible ? '' : 'none';
  10545. }
  10546. };
  10547. return GuideBase;
  10548. }();
  10549. var Arc = /*#__PURE__*/function (_GuideBase) {
  10550. _inheritsLoose$3(Arc, _GuideBase);
  10551. function Arc() {
  10552. return _GuideBase.apply(this, arguments) || this;
  10553. }
  10554. var _proto = Arc.prototype;
  10555. _proto._initDefaultCfg = function _initDefaultCfg() {
  10556. this.type = 'arc';
  10557. /**
  10558. * start point
  10559. * @type {Array | Function}
  10560. */
  10561. this.start = [];
  10562. /**
  10563. * end point
  10564. * @type {Array | Function}
  10565. */
  10566. this.end = [];
  10567. /**
  10568. * style configuration
  10569. * @type {Object}
  10570. */
  10571. this.style = {
  10572. stroke: '#999',
  10573. lineWidth: 1
  10574. };
  10575. };
  10576. _proto.render = function render(coord, container) {
  10577. var self = this;
  10578. var start = self.parsePoint(coord, self.start);
  10579. var end = self.parsePoint(coord, self.end);
  10580. if (!start || !end) {
  10581. return;
  10582. }
  10583. var coordCenter = coord.center;
  10584. var radius = Math.sqrt((start.x - coordCenter.x) * (start.x - coordCenter.x) + (start.y - coordCenter.y) * (start.y - coordCenter.y));
  10585. var startAngle = Math.atan2(start.y - coordCenter.y, start.x - coordCenter.x);
  10586. var endAngle = Math.atan2(end.y - coordCenter.y, end.x - coordCenter.x);
  10587. var shape = container.addShape('arc', {
  10588. className: 'guide-arc',
  10589. attrs: mix$1({
  10590. x: coordCenter.x,
  10591. y: coordCenter.y,
  10592. r: radius,
  10593. startAngle: startAngle,
  10594. endAngle: endAngle
  10595. }, self.style)
  10596. });
  10597. self.element = shape;
  10598. return shape;
  10599. };
  10600. return Arc;
  10601. }(GuideBase);
  10602. GuideBase.Arc = Arc;
  10603. function getOffsetFromAlign(alignX, alignY, width, height) {
  10604. var result = [];
  10605. if (alignX === 'left' && alignY === 'top') {
  10606. result[0] = 0;
  10607. result[1] = 0;
  10608. } else if (alignX === 'right' && alignY === 'top') {
  10609. result[0] = -width;
  10610. result[1] = 0;
  10611. } else if (alignX === 'left' && alignY === 'bottom') {
  10612. result[0] = 0;
  10613. result[1] = Math.floor(-height);
  10614. } else if (alignX === 'right' && alignY === 'bottom') {
  10615. result[0] = Math.floor(-width);
  10616. result[1] = Math.floor(-height);
  10617. } else if (alignX === 'right' && alignY === 'middle') {
  10618. result[0] = Math.floor(-width);
  10619. result[1] = Math.floor(-height / 2);
  10620. } else if (alignX === 'left' && alignY === 'middle') {
  10621. result[0] = 0;
  10622. result[1] = Math.floor(-height / 2);
  10623. } else if (alignX === 'center' && alignY === 'bottom') {
  10624. result[0] = Math.floor(-width / 2);
  10625. result[1] = Math.floor(-height);
  10626. } else if (alignX === 'center' && alignY === 'top') {
  10627. result[0] = Math.floor(-width / 2);
  10628. result[1] = 0;
  10629. } else {
  10630. result[0] = Math.floor(-width / 2);
  10631. result[1] = Math.floor(-height / 2);
  10632. }
  10633. return result;
  10634. }
  10635. function modifyCSS(DOM, CSS) {
  10636. for (var key in CSS) {
  10637. if (CSS.hasOwnProperty(key)) {
  10638. DOM.style[key] = CSS[key];
  10639. }
  10640. }
  10641. return DOM;
  10642. }
  10643. function createDom(str) {
  10644. var container = document.createElement('div');
  10645. str = str.replace(/(^\s*)|(\s*$)/g, '');
  10646. container.innerHTML = '' + str;
  10647. return container.childNodes[0];
  10648. }
  10649. var Html = /*#__PURE__*/function (_GuideBase) {
  10650. _inheritsLoose$3(Html, _GuideBase);
  10651. function Html() {
  10652. return _GuideBase.apply(this, arguments) || this;
  10653. }
  10654. var _proto = Html.prototype;
  10655. _proto._initDefaultCfg = function _initDefaultCfg() {
  10656. this.type = 'html';
  10657. /**
  10658. * dom position
  10659. * @type {Object | Array}
  10660. */
  10661. this.position = null;
  10662. /**
  10663. * alignment for horizontal direction,can be 'left','center','right'
  10664. * @type {String}
  10665. */
  10666. this.alignX = 'center';
  10667. /**
  10668. * alignment for vertical direction,can be 'top', 'middle', 'bottom'
  10669. * @type {String}
  10670. */
  10671. this.alignY = 'middle';
  10672. /**
  10673. * offset for horizontal direction
  10674. * @type {Number}
  10675. */
  10676. this.offsetX = null;
  10677. /**
  10678. * offset for vertical direction
  10679. * @type {Number}
  10680. */
  10681. this.offsetY = null;
  10682. /**
  10683. * the html string
  10684. *@type {String | Function}
  10685. */
  10686. this.html = null;
  10687. } // override paint
  10688. ;
  10689. _proto.render = function render(coord, container) {
  10690. var self = this;
  10691. var position = self.parsePoint(coord, self.position);
  10692. if (!position) {
  10693. return;
  10694. }
  10695. var myNode = createDom(self.html);
  10696. myNode = modifyCSS(myNode, {
  10697. position: 'absolute',
  10698. top: Math.floor(position.y) + 'px',
  10699. left: Math.floor(position.x) + 'px',
  10700. visibility: 'hidden'
  10701. });
  10702. var canvasDom = container.get('canvas').get('el');
  10703. var parentNode = canvasDom.parentNode;
  10704. parentNode = modifyCSS(parentNode, {
  10705. position: 'relative'
  10706. });
  10707. var wrapperNode = createDom('<div class="guideWapper" style="position: absolute;top: 0; left: 0;"></div>');
  10708. parentNode.appendChild(wrapperNode);
  10709. wrapperNode.appendChild(myNode);
  10710. var canvasOffsetTop = canvasDom.offsetTop;
  10711. var canvasOffsetLeft = canvasDom.offsetLeft;
  10712. var alignX = self.alignX,
  10713. alignY = self.alignY,
  10714. offsetX = self.offsetX,
  10715. offsetY = self.offsetY;
  10716. var width = getWidth(myNode);
  10717. var height = getHeight(myNode);
  10718. var newOffset = getOffsetFromAlign(alignX, alignY, width, height);
  10719. position.x = position.x + newOffset[0] + canvasOffsetLeft;
  10720. position.y = position.y + newOffset[1] + canvasOffsetTop;
  10721. if (offsetX) {
  10722. position.x += offsetX;
  10723. }
  10724. if (offsetY) {
  10725. position.y += offsetY;
  10726. }
  10727. modifyCSS(myNode, {
  10728. top: Math.floor(position.y) + 'px',
  10729. left: Math.floor(position.x) + 'px',
  10730. visibility: 'visible'
  10731. });
  10732. self.element = wrapperNode;
  10733. };
  10734. _proto.remove = function remove() {
  10735. var element = this.element;
  10736. element && element.parentNode && element.parentNode.removeChild(element);
  10737. };
  10738. return Html;
  10739. }(GuideBase);
  10740. GuideBase.Html = Html;
  10741. var Line = /*#__PURE__*/function (_GuideBase) {
  10742. _inheritsLoose$3(Line, _GuideBase);
  10743. function Line() {
  10744. return _GuideBase.apply(this, arguments) || this;
  10745. }
  10746. var _proto = Line.prototype;
  10747. _proto._initDefaultCfg = function _initDefaultCfg() {
  10748. this.type = 'line';
  10749. this.start = [];
  10750. this.end = [];
  10751. this.style = {
  10752. stroke: '#000',
  10753. lineWidth: 1
  10754. };
  10755. };
  10756. _proto.render = function render(coord, container) {
  10757. var points = [];
  10758. points[0] = this.parsePoint(coord, this.start);
  10759. points[1] = this.parsePoint(coord, this.end);
  10760. if (!points[0] || !points[1]) {
  10761. return;
  10762. }
  10763. var shape = container.addShape('Line', {
  10764. className: 'guide-line',
  10765. attrs: mix$1({
  10766. x1: points[0].x,
  10767. y1: points[0].y,
  10768. x2: points[1].x,
  10769. y2: points[1].y
  10770. }, this.style)
  10771. });
  10772. this.element = shape;
  10773. return shape;
  10774. };
  10775. return Line;
  10776. }(GuideBase);
  10777. GuideBase.Line = Line;
  10778. var Rect = /*#__PURE__*/function (_GuideBase) {
  10779. _inheritsLoose$3(Rect, _GuideBase);
  10780. function Rect() {
  10781. return _GuideBase.apply(this, arguments) || this;
  10782. }
  10783. var _proto = Rect.prototype;
  10784. _proto._initDefaultCfg = function _initDefaultCfg() {
  10785. this.type = 'rect';
  10786. this.start = [];
  10787. this.end = [];
  10788. this.style = {
  10789. fill: '#CCD7EB',
  10790. opacity: 0.4
  10791. };
  10792. };
  10793. _proto.render = function render(coord, container) {
  10794. var start = this.parsePoint(coord, this.start);
  10795. var end = this.parsePoint(coord, this.end);
  10796. if (!start || !end) {
  10797. return;
  10798. }
  10799. var shape = container.addShape('rect', {
  10800. className: 'guide-rect',
  10801. attrs: mix$1({
  10802. x: Math.min(start.x, end.x),
  10803. y: Math.min(start.y, end.y),
  10804. width: Math.abs(end.x - start.x),
  10805. height: Math.abs(start.y - end.y)
  10806. }, this.style)
  10807. });
  10808. this.element = shape;
  10809. return shape;
  10810. };
  10811. return Rect;
  10812. }(GuideBase);
  10813. GuideBase.Rect = Rect;
  10814. var Text = /*#__PURE__*/function (_GuideBase) {
  10815. _inheritsLoose$3(Text, _GuideBase);
  10816. function Text() {
  10817. return _GuideBase.apply(this, arguments) || this;
  10818. }
  10819. var _proto = Text.prototype;
  10820. _proto._initDefaultCfg = function _initDefaultCfg() {
  10821. this.type = 'text';
  10822. /**
  10823. * the position of text
  10824. * @type {Function | Array}
  10825. */
  10826. this.position = null;
  10827. /**
  10828. * the display content
  10829. * @type {String}
  10830. */
  10831. this.content = null;
  10832. /**
  10833. * style configuration for text
  10834. * @type {Object}
  10835. */
  10836. this.style = {
  10837. fill: '#000'
  10838. };
  10839. /**
  10840. * offset of horizontal direction
  10841. * @type {Number}
  10842. */
  10843. this.offsetX = 0;
  10844. /**
  10845. * offset of vertical direction
  10846. * @type {Number}
  10847. */
  10848. this.offsetY = 0;
  10849. };
  10850. _proto.render = function render(coord, container) {
  10851. var position = this.position;
  10852. var point = this.parsePoint(coord, position);
  10853. if (!point) {
  10854. return;
  10855. }
  10856. var content = this.content,
  10857. style = this.style,
  10858. offsetX = this.offsetX,
  10859. offsetY = this.offsetY;
  10860. if (offsetX) {
  10861. point.x += offsetX;
  10862. }
  10863. if (offsetY) {
  10864. point.y += offsetY;
  10865. }
  10866. var shape = container.addShape('text', {
  10867. className: 'guide-text',
  10868. attrs: mix$1({
  10869. x: point.x,
  10870. y: point.y,
  10871. text: content
  10872. }, style)
  10873. });
  10874. this.element = shape;
  10875. return shape;
  10876. };
  10877. return Text;
  10878. }(GuideBase);
  10879. GuideBase.Text = Text;
  10880. var Tag = /*#__PURE__*/function (_GuideBase) {
  10881. _inheritsLoose$3(Tag, _GuideBase);
  10882. function Tag() {
  10883. return _GuideBase.apply(this, arguments) || this;
  10884. }
  10885. var _proto = Tag.prototype;
  10886. _proto._initDefaultCfg = function _initDefaultCfg() {
  10887. this.type = 'tag';
  10888. this.position = null;
  10889. this.content = null;
  10890. this.direct = 'tl';
  10891. this.autoAdjust = true;
  10892. this.offsetX = 0;
  10893. this.offsetY = 0;
  10894. this.side = 4;
  10895. this.background = {
  10896. padding: 5,
  10897. radius: 2,
  10898. fill: '#1890FF'
  10899. };
  10900. this.textStyle = {
  10901. fontSize: 12,
  10902. fill: '#fff',
  10903. textAlign: 'center',
  10904. textBaseline: 'middle'
  10905. };
  10906. this.withPoint = true;
  10907. this.pointStyle = {
  10908. fill: '#1890FF',
  10909. r: 3,
  10910. lineWidth: 1,
  10911. stroke: '#fff'
  10912. };
  10913. };
  10914. _proto._getDirect = function _getDirect(container, point, tagWidth, tagHeight) {
  10915. var direct = this.direct;
  10916. var side = this.side;
  10917. var canvas = container.get('canvas');
  10918. var clientWidth = canvas.get('width');
  10919. var clientHeight = canvas.get('height');
  10920. var x = point.x,
  10921. y = point.y;
  10922. var vertical = direct[0];
  10923. var horizontal = direct[1]; // adjust for vertical direction
  10924. if (vertical === 't' && y - side - tagHeight < 0) {
  10925. vertical = 'b';
  10926. } else if (vertical === 'b' && y + side + tagHeight > clientHeight) {
  10927. vertical = 't';
  10928. } // adjust for horizontal direction
  10929. var diff = vertical === 'c' ? side : 0;
  10930. if (horizontal === 'l' && x - diff - tagWidth < 0) {
  10931. horizontal = 'r';
  10932. } else if (horizontal === 'r' && x + diff + tagWidth > clientWidth) {
  10933. horizontal = 'l';
  10934. } else if (horizontal === 'c') {
  10935. if (tagWidth / 2 + x + diff > clientWidth) {
  10936. horizontal = 'l';
  10937. } else if (x - tagWidth / 2 - diff < 0) {
  10938. horizontal = 'r';
  10939. }
  10940. }
  10941. direct = vertical + horizontal;
  10942. return direct;
  10943. };
  10944. _proto.render = function render(coord, container) {
  10945. var position = this.parsePoint(coord, this.position);
  10946. if (!position) {
  10947. return;
  10948. } // 数据不在显示范围内时,x/y 会为NaN
  10949. if (isNaN(position.x) || isNaN(position.y)) {
  10950. return;
  10951. }
  10952. var content = this.content,
  10953. background = this.background,
  10954. textStyle = this.textStyle;
  10955. var shapes = [];
  10956. var wrapperContainer = container.addGroup({
  10957. className: 'guide-tag'
  10958. });
  10959. if (this.withPoint) {
  10960. var pointShape = wrapperContainer.addShape('Circle', {
  10961. className: 'guide-tag-point',
  10962. attrs: mix$1({
  10963. x: position.x,
  10964. y: position.y
  10965. }, this.pointStyle)
  10966. });
  10967. shapes.push(pointShape);
  10968. }
  10969. var tagContainer = wrapperContainer.addGroup(); // create a text shape
  10970. var tagText = tagContainer.addShape('text', {
  10971. className: 'guide-tag-text',
  10972. zIndex: 1,
  10973. attrs: mix$1({
  10974. x: 0,
  10975. y: 0,
  10976. text: content
  10977. }, textStyle)
  10978. });
  10979. shapes.push(tagText); // create background box
  10980. var textBBox = tagText.getBBox();
  10981. var padding = parsePadding(background.padding);
  10982. var tagWidth = textBBox.width + padding[1] + padding[3];
  10983. var tagHeight = textBBox.height + padding[0] + padding[2];
  10984. var yMin = textBBox.minY - padding[0];
  10985. var xMin = textBBox.minX - padding[3];
  10986. var tagBg = tagContainer.addShape('rect', {
  10987. className: 'guide-tag-bg',
  10988. zIndex: -1,
  10989. attrs: mix$1({
  10990. x: xMin,
  10991. y: yMin,
  10992. width: tagWidth,
  10993. height: tagHeight
  10994. }, background)
  10995. });
  10996. shapes.push(tagBg);
  10997. var direct = this.autoAdjust ? this._getDirect(container, position, tagWidth, tagHeight) : this.direct;
  10998. var side = this.side;
  10999. var x = position.x + this.offsetX;
  11000. var y = position.y + this.offsetY;
  11001. var arrowPoints;
  11002. var radius = parsePadding(background.radius);
  11003. if (direct === 'tl') {
  11004. arrowPoints = [{
  11005. x: tagWidth + xMin - side - 1,
  11006. y: tagHeight + yMin - 1
  11007. }, // 这个 1 是为了防止出现白边
  11008. {
  11009. x: tagWidth + xMin,
  11010. y: tagHeight + yMin - 1
  11011. }, {
  11012. x: tagWidth + xMin,
  11013. y: tagHeight + side + yMin
  11014. }];
  11015. radius[2] = 0;
  11016. x = x - tagWidth;
  11017. y = y - side - tagHeight;
  11018. } else if (direct === 'cl') {
  11019. arrowPoints = [{
  11020. x: tagWidth + xMin - 1,
  11021. y: (tagHeight - side) / 2 + yMin - 1
  11022. }, {
  11023. x: tagWidth + xMin - 1,
  11024. y: (tagHeight + side) / 2 + yMin + 1
  11025. }, {
  11026. x: tagWidth + side + xMin,
  11027. y: tagHeight / 2 + yMin
  11028. }];
  11029. x = x - tagWidth - side;
  11030. y = y - tagHeight / 2;
  11031. } else if (direct === 'bl') {
  11032. arrowPoints = [{
  11033. x: tagWidth + xMin,
  11034. y: -side + yMin
  11035. }, {
  11036. x: tagWidth + xMin - side - 1,
  11037. y: yMin + 1
  11038. }, {
  11039. x: tagWidth + xMin,
  11040. y: yMin + 1
  11041. }];
  11042. radius[1] = 0;
  11043. x = x - tagWidth;
  11044. y = y + side;
  11045. } else if (direct === 'bc') {
  11046. arrowPoints = [{
  11047. x: tagWidth / 2 + xMin,
  11048. y: -side + yMin
  11049. }, {
  11050. x: (tagWidth - side) / 2 + xMin - 1,
  11051. y: yMin + 1
  11052. }, {
  11053. x: (tagWidth + side) / 2 + xMin + 1,
  11054. y: yMin + 1
  11055. }];
  11056. x = x - tagWidth / 2;
  11057. y = y + side;
  11058. } else if (direct === 'br') {
  11059. arrowPoints = [{
  11060. x: xMin,
  11061. y: yMin - side
  11062. }, {
  11063. x: xMin,
  11064. y: yMin + 1
  11065. }, {
  11066. x: xMin + side + 1,
  11067. y: yMin + 1
  11068. }];
  11069. radius[0] = 0;
  11070. y = y + side;
  11071. } else if (direct === 'cr') {
  11072. arrowPoints = [{
  11073. x: xMin - side,
  11074. y: tagHeight / 2 + yMin
  11075. }, {
  11076. x: xMin + 1,
  11077. y: (tagHeight - side) / 2 + yMin - 1
  11078. }, {
  11079. x: xMin + 1,
  11080. y: (tagHeight + side) / 2 + yMin + 1
  11081. }];
  11082. x = x + side;
  11083. y = y - tagHeight / 2;
  11084. } else if (direct === 'tr') {
  11085. arrowPoints = [{
  11086. x: xMin,
  11087. y: tagHeight + side + yMin
  11088. }, {
  11089. x: xMin,
  11090. y: tagHeight + yMin - 1
  11091. }, {
  11092. x: side + xMin + 1,
  11093. y: tagHeight + yMin - 1
  11094. }];
  11095. radius[3] = 0;
  11096. y = y - tagHeight - side;
  11097. } else if (direct === 'tc') {
  11098. arrowPoints = [{
  11099. x: (tagWidth - side) / 2 + xMin - 1,
  11100. y: tagHeight + yMin - 1
  11101. }, {
  11102. x: (tagWidth + side) / 2 + xMin + 1,
  11103. y: tagHeight + yMin - 1
  11104. }, {
  11105. x: tagWidth / 2 + xMin,
  11106. y: tagHeight + side + yMin
  11107. }];
  11108. x = x - tagWidth / 2;
  11109. y = y - tagHeight - side;
  11110. }
  11111. var sideShape = tagContainer.addShape('Polygon', {
  11112. className: 'guide-tag-side',
  11113. zIndex: 0,
  11114. attrs: {
  11115. points: arrowPoints,
  11116. fill: background.fill
  11117. }
  11118. });
  11119. shapes.push(sideShape);
  11120. tagBg.attr('radius', radius);
  11121. tagContainer.moveTo(x - xMin, y - yMin);
  11122. tagContainer.sort();
  11123. this.element = wrapperContainer;
  11124. return shapes;
  11125. };
  11126. return Tag;
  11127. }(GuideBase);
  11128. GuideBase.Tag = Tag;
  11129. var Point = /*#__PURE__*/function (_GuideBase) {
  11130. _inheritsLoose$3(Point, _GuideBase);
  11131. function Point() {
  11132. return _GuideBase.apply(this, arguments) || this;
  11133. }
  11134. var _proto = Point.prototype;
  11135. _proto._initDefaultCfg = function _initDefaultCfg() {
  11136. this.type = 'point';
  11137. this.position = null;
  11138. this.offsetX = 0;
  11139. this.offsetY = 0;
  11140. this.style = {
  11141. fill: '#1890FF',
  11142. r: 3,
  11143. lineWidth: 1,
  11144. stroke: '#fff'
  11145. };
  11146. };
  11147. _proto.render = function render(coord, container) {
  11148. var position = this.parsePoint(coord, this.position);
  11149. if (!position) return null;
  11150. var shape = container.addShape('Circle', {
  11151. className: 'guide-point',
  11152. attrs: mix$1({
  11153. x: position.x + this.offsetX,
  11154. y: position.y + this.offsetY
  11155. }, this.style)
  11156. });
  11157. this.element = shape;
  11158. return shape;
  11159. };
  11160. return Point;
  11161. }(GuideBase);
  11162. GuideBase.Point = Point;
  11163. var MARKER_RADIUS = 3;
  11164. var List = /*#__PURE__*/function () {
  11165. var _proto = List.prototype;
  11166. _proto.getDefaultCfg = function getDefaultCfg() {
  11167. return {
  11168. showTitle: false,
  11169. /**
  11170. * title string
  11171. * @type {?String}
  11172. */
  11173. title: null,
  11174. /**
  11175. * items array
  11176. * @type {?Array}
  11177. */
  11178. items: null,
  11179. /**
  11180. * offset between title and items
  11181. * @type {Number}
  11182. */
  11183. titleGap: 12,
  11184. /**
  11185. * offset between each item
  11186. * @type {Number}
  11187. */
  11188. itemGap: 10,
  11189. /**
  11190. * the offset between each item in vertical direaction
  11191. * @type {Number}
  11192. */
  11193. itemMarginBottom: 12,
  11194. /**
  11195. * the formatter for item text
  11196. * @type {[type]}
  11197. */
  11198. itemFormatter: null,
  11199. itemWidth: null,
  11200. /**
  11201. * offset between marker and text
  11202. * @type {Number}
  11203. */
  11204. wordSpace: 6,
  11205. x: 0,
  11206. y: 0,
  11207. layout: 'horizontal',
  11208. /**
  11209. * the join string of `name` and `value`
  11210. * @type {String}
  11211. */
  11212. joinString: ': '
  11213. };
  11214. };
  11215. function List(cfg) {
  11216. deepMix(this, this.getDefaultCfg(), cfg);
  11217. this._init();
  11218. this._renderTitle();
  11219. this._renderItems();
  11220. }
  11221. _proto._init = function _init() {
  11222. var parent = this.parent;
  11223. if (!parent) return;
  11224. var container = parent.addGroup({
  11225. zIndex: this.zIndex || 0
  11226. });
  11227. this.container = container;
  11228. var wrapper = container.addGroup();
  11229. this.wrapper = wrapper;
  11230. var itemsGroup = wrapper.addGroup({
  11231. className: 'itemsGroup'
  11232. });
  11233. this.itemsGroup = itemsGroup;
  11234. };
  11235. _proto._renderTitle = function _renderTitle(title) {
  11236. title = title || this.title;
  11237. var titleShape = this.titleShape;
  11238. var titleHeight = 0;
  11239. if (this.showTitle && title) {
  11240. if (titleShape && !titleShape.get('destroyed')) {
  11241. titleShape.attr('text', title);
  11242. } else {
  11243. var wrapper = this.wrapper,
  11244. titleStyle = this.titleStyle;
  11245. titleShape = wrapper.addShape('text', {
  11246. className: 'title',
  11247. attrs: mix$1({
  11248. x: 0,
  11249. y: 0,
  11250. text: title
  11251. }, titleStyle)
  11252. });
  11253. this.titleShape = titleShape;
  11254. }
  11255. titleHeight = titleShape.getBBox().height + this.titleGap;
  11256. }
  11257. this._titleHeight = titleHeight;
  11258. };
  11259. _proto._renderItems = function _renderItems(items) {
  11260. var self = this;
  11261. items = items || self.items;
  11262. if (!items) {
  11263. return;
  11264. }
  11265. if (self.reversed) {
  11266. items.reverse();
  11267. }
  11268. each$1(items, function (item, index) {
  11269. self._addItem(item, index);
  11270. });
  11271. if (items.length > 1) {
  11272. this._adjustItems();
  11273. }
  11274. this._renderBackground();
  11275. };
  11276. _proto._renderBackground = function _renderBackground() {
  11277. var background = this.background;
  11278. if (background) {
  11279. var container = this.container;
  11280. var wrapper = this.wrapper;
  11281. var _wrapper$getBBox = wrapper.getBBox(),
  11282. minX = _wrapper$getBBox.minX,
  11283. minY = _wrapper$getBBox.minY,
  11284. width = _wrapper$getBBox.width,
  11285. height = _wrapper$getBBox.height;
  11286. var padding = background.padding || [0, 0, 0, 0];
  11287. padding = parsePadding(padding);
  11288. var attrs = mix$1({
  11289. x: minX - padding[3],
  11290. y: minY - padding[0],
  11291. width: width + padding[1] + padding[3],
  11292. height: height + padding[0] + padding[2]
  11293. }, background);
  11294. var backShape = this.backShape;
  11295. if (backShape) {
  11296. backShape.attr(attrs);
  11297. } else {
  11298. backShape = container.addShape('Rect', {
  11299. zIndex: -1,
  11300. attrs: attrs
  11301. });
  11302. }
  11303. this.backShape = backShape;
  11304. container.sort();
  11305. }
  11306. };
  11307. _proto._addItem = function _addItem(item) {
  11308. var itemsGroup = this.itemsGroup;
  11309. var itemGroup = itemsGroup.addGroup({
  11310. name: item.name,
  11311. value: item.value,
  11312. dataValue: item.dataValue,
  11313. checked: item.checked
  11314. });
  11315. var unCheckStyle = this.unCheckStyle,
  11316. unCheckColor = this.unCheckColor,
  11317. nameStyle = this.nameStyle,
  11318. valueStyle = this.valueStyle,
  11319. wordSpace = this.wordSpace;
  11320. var marker = item.marker,
  11321. value = item.value;
  11322. var startX = 0;
  11323. if (unCheckColor) {
  11324. unCheckStyle.fill = unCheckColor;
  11325. }
  11326. if (marker) {
  11327. var radius = marker.radius || MARKER_RADIUS;
  11328. var markerAttrs = mix$1({
  11329. x: radius,
  11330. y: this._titleHeight
  11331. }, marker);
  11332. if (item.checked === false) {
  11333. mix$1(markerAttrs, unCheckStyle);
  11334. }
  11335. var markerShape = itemGroup.addShape('marker', {
  11336. className: 'item-marker',
  11337. attrs: markerAttrs
  11338. });
  11339. startX += markerShape.getBBox().width + wordSpace;
  11340. }
  11341. var nameText;
  11342. var name = item.name;
  11343. if (name) {
  11344. var joinString = this.joinString || '';
  11345. name = value ? name + joinString : name;
  11346. nameText = itemGroup.addShape('text', {
  11347. className: 'name',
  11348. attrs: mix$1({
  11349. x: startX,
  11350. y: this._titleHeight,
  11351. text: this._formatItemValue(name)
  11352. }, nameStyle, item.checked === false ? unCheckStyle : null)
  11353. });
  11354. }
  11355. if (value) {
  11356. var valueX = startX;
  11357. if (nameText) {
  11358. valueX += nameText.getBBox().width;
  11359. }
  11360. itemGroup.addShape('text', {
  11361. className: 'value',
  11362. attrs: mix$1({
  11363. x: valueX,
  11364. y: this._titleHeight,
  11365. text: value
  11366. }, valueStyle, item.checked === false ? unCheckStyle : null)
  11367. });
  11368. }
  11369. return itemGroup;
  11370. };
  11371. _proto._formatItemValue = function _formatItemValue(value) {
  11372. var formatter = this.itemFormatter;
  11373. if (formatter) {
  11374. value = formatter.call(this, value);
  11375. }
  11376. return value;
  11377. };
  11378. _proto._getMaxItemWidth = function _getMaxItemWidth() {
  11379. var width;
  11380. var itemWidth = this.itemWidth;
  11381. if (isNumber(itemWidth) || isNil$1(itemWidth)) {
  11382. return itemWidth;
  11383. }
  11384. if (itemWidth === 'auto') {
  11385. var itemsGroup = this.itemsGroup;
  11386. var children = itemsGroup.get('children');
  11387. var count = children.length;
  11388. var maxItemWidth = 0;
  11389. for (var i = 0; i < count; i++) {
  11390. var _children$i$getBBox = children[i].getBBox(),
  11391. _width = _children$i$getBBox.width;
  11392. maxItemWidth = Math.max(maxItemWidth, _width);
  11393. }
  11394. var maxLength = this.maxLength;
  11395. var itemGap = this.itemGap;
  11396. var twoAvgWidth = (maxLength - itemGap) / 2;
  11397. var threeAvgWidth = (maxLength - itemGap * 2) / 3;
  11398. if (count === 2) {
  11399. width = Math.max(maxItemWidth, twoAvgWidth);
  11400. } else {
  11401. // 1. max <= 3Avg, 3Avg
  11402. // 2. 3Avg < max && max < 2avg, 2avg
  11403. // 3. max > 2avg, max, one column
  11404. if (maxItemWidth <= threeAvgWidth) {
  11405. width = threeAvgWidth;
  11406. } else if (maxItemWidth <= twoAvgWidth) {
  11407. width = twoAvgWidth;
  11408. } else {
  11409. width = maxItemWidth;
  11410. }
  11411. }
  11412. return width;
  11413. }
  11414. };
  11415. _proto._adjustHorizontal = function _adjustHorizontal() {
  11416. var maxLength = this.maxLength,
  11417. itemsGroup = this.itemsGroup;
  11418. var children = itemsGroup.get('children');
  11419. var itemGap = this.itemGap,
  11420. itemMarginBottom = this.itemMarginBottom;
  11421. var titleHeight = this._titleHeight;
  11422. var row = 0;
  11423. var rowWidth = 0;
  11424. var width;
  11425. var height;
  11426. var itemWidth = this._getMaxItemWidth();
  11427. var legendHitBoxes = [];
  11428. for (var i = 0, len = children.length; i < len; i++) {
  11429. var child = children[i];
  11430. var box = child.getBBox();
  11431. var childHeight = box.height;
  11432. var childWidth = box.width;
  11433. width = itemWidth || childWidth;
  11434. height = childHeight + itemMarginBottom;
  11435. if (width - (maxLength - rowWidth) > 0.0001) {
  11436. row++;
  11437. rowWidth = 0;
  11438. }
  11439. child.moveTo(rowWidth, row * height);
  11440. legendHitBoxes.push({
  11441. x: rowWidth,
  11442. y: row * height + titleHeight - childHeight / 2,
  11443. width: childWidth * 1.375,
  11444. height: childHeight * 1.375
  11445. });
  11446. rowWidth += width + itemGap;
  11447. }
  11448. this.legendHitBoxes = legendHitBoxes;
  11449. return;
  11450. };
  11451. _proto._adjustVertical = function _adjustVertical() {
  11452. var maxLength = this.maxLength,
  11453. itemsGroup = this.itemsGroup;
  11454. var itemGap = this.itemGap,
  11455. itemMarginBottom = this.itemMarginBottom,
  11456. itemWidth = this.itemWidth;
  11457. var titleHeight = this._titleHeight;
  11458. var children = itemsGroup.get('children');
  11459. var colHeight = 0;
  11460. var width;
  11461. var height;
  11462. var maxItemWidth = 0;
  11463. var totalWidth = 0;
  11464. var legendHitBoxes = [];
  11465. for (var i = 0, length = children.length; i < length; i++) {
  11466. var child = children[i];
  11467. var bbox = child.getBBox();
  11468. width = bbox.width;
  11469. height = bbox.height;
  11470. if (isNumber(itemWidth)) {
  11471. maxItemWidth = itemWidth + itemGap;
  11472. } else if (width > maxItemWidth) {
  11473. maxItemWidth = width + itemGap;
  11474. }
  11475. if (maxLength - colHeight < height) {
  11476. colHeight = 0;
  11477. totalWidth += maxItemWidth;
  11478. child.moveTo(totalWidth, 0);
  11479. legendHitBoxes.push({
  11480. x: totalWidth,
  11481. y: titleHeight - height / 2,
  11482. width: width * 1.375,
  11483. height: height * 1.375
  11484. });
  11485. } else {
  11486. child.moveTo(totalWidth, colHeight);
  11487. legendHitBoxes.push({
  11488. x: totalWidth,
  11489. y: colHeight - height / 2 + titleHeight,
  11490. width: width * 1.375,
  11491. height: height * 1.375
  11492. });
  11493. }
  11494. colHeight += height + itemMarginBottom;
  11495. }
  11496. this.legendHitBoxes = legendHitBoxes;
  11497. return;
  11498. };
  11499. _proto._adjustItems = function _adjustItems() {
  11500. var layout = this.layout;
  11501. if (layout === 'horizontal') {
  11502. this._adjustHorizontal();
  11503. } else {
  11504. this._adjustVertical();
  11505. }
  11506. };
  11507. _proto.moveTo = function moveTo(x, y) {
  11508. this.x = x;
  11509. this.y = y;
  11510. var container = this.container;
  11511. container && container.moveTo(x, y);
  11512. return this;
  11513. };
  11514. _proto.setItems = function setItems(items) {
  11515. this.clearItems();
  11516. this._renderItems(items);
  11517. };
  11518. _proto.setTitle = function setTitle(title) {
  11519. this._renderTitle(title);
  11520. };
  11521. _proto.clearItems = function clearItems() {
  11522. var itemsGroup = this.itemsGroup;
  11523. itemsGroup.clear();
  11524. };
  11525. _proto.getWidth = function getWidth() {
  11526. var container = this.container;
  11527. var bbox = container.getBBox();
  11528. return bbox.width;
  11529. };
  11530. _proto.getHeight = function getHeight() {
  11531. var container = this.container;
  11532. var bbox = container.getBBox();
  11533. return bbox.height;
  11534. };
  11535. _proto.show = function show() {
  11536. var container = this.container;
  11537. container.show();
  11538. };
  11539. _proto.hide = function hide() {
  11540. var container = this.container;
  11541. container.hide();
  11542. };
  11543. _proto.clear = function clear() {
  11544. var container = this.container;
  11545. container.clear();
  11546. container.remove(true);
  11547. };
  11548. return List;
  11549. }();
  11550. var TextBox = /*#__PURE__*/function () {
  11551. var _proto = TextBox.prototype;
  11552. _proto.getDefaultCfg = function getDefaultCfg() {
  11553. return {
  11554. x: 0,
  11555. y: 0,
  11556. content: '',
  11557. textStyle: {
  11558. fontSize: 12,
  11559. fill: '#fff',
  11560. textAlign: 'center',
  11561. textBaseline: 'middle',
  11562. fontFamily: 'Arial'
  11563. },
  11564. background: {
  11565. radius: 1,
  11566. fill: 'rgba(0, 0, 0, 0.65)',
  11567. padding: [3, 5]
  11568. },
  11569. width: 0,
  11570. height: 0,
  11571. className: ''
  11572. };
  11573. };
  11574. function TextBox(cfg) {
  11575. deepMix(this, this.getDefaultCfg(), cfg);
  11576. this._init();
  11577. var content = this.content,
  11578. x = this.x,
  11579. y = this.y;
  11580. if (!isNil$1(content)) {
  11581. this.updateContent(content);
  11582. }
  11583. this.updatePosition(x, y);
  11584. }
  11585. _proto._init = function _init() {
  11586. var content = this.content,
  11587. textStyle = this.textStyle,
  11588. background = this.background,
  11589. className = this.className,
  11590. visible = this.visible,
  11591. context = this.context;
  11592. var container = new Group({
  11593. context: context,
  11594. className: className,
  11595. zIndex: 0,
  11596. visible: visible
  11597. });
  11598. var text = container.addShape('Text', {
  11599. className: className + '-text',
  11600. zIndex: 1,
  11601. attrs: mix$1({
  11602. text: content,
  11603. x: 0,
  11604. y: 0
  11605. }, textStyle)
  11606. });
  11607. var backgroundShape = container.addShape('Rect', {
  11608. className: className + '-bg',
  11609. zIndex: -1,
  11610. attrs: mix$1({
  11611. x: 0,
  11612. y: 0,
  11613. width: 0,
  11614. height: 0
  11615. }, background)
  11616. });
  11617. container.sort();
  11618. this.container = container;
  11619. this.textShape = text;
  11620. this.backgroundShape = backgroundShape;
  11621. };
  11622. _proto._getBBox = function _getBBox() {
  11623. var textShape = this.textShape;
  11624. var background = this.background;
  11625. var textBBox = textShape.getBBox();
  11626. var padding = parsePadding(background.padding);
  11627. var width = textBBox.width + padding[1] + padding[3];
  11628. var height = textBBox.height + padding[0] + padding[2];
  11629. var x = textBBox.minX - padding[3];
  11630. var y = textBBox.minY - padding[0];
  11631. return {
  11632. x: x,
  11633. y: y,
  11634. width: width,
  11635. height: height
  11636. };
  11637. };
  11638. _proto.updateContent = function updateContent(text) {
  11639. var textShape = this.textShape,
  11640. backgroundShape = this.backgroundShape;
  11641. if (!isNil$1(text)) {
  11642. if (!isObject$1(text)) {
  11643. text = {
  11644. text: text
  11645. };
  11646. }
  11647. textShape.attr(text); // update box shape
  11648. var _this$_getBBox = this._getBBox(),
  11649. x = _this$_getBBox.x,
  11650. y = _this$_getBBox.y,
  11651. tipWidth = _this$_getBBox.width,
  11652. tipHeight = _this$_getBBox.height;
  11653. var width = this.width || tipWidth;
  11654. var height = this.height || tipHeight;
  11655. backgroundShape.attr({
  11656. x: x,
  11657. y: y,
  11658. width: width,
  11659. height: height
  11660. });
  11661. this._width = width;
  11662. this._height = height;
  11663. this.content = text.text;
  11664. }
  11665. };
  11666. _proto.updatePosition = function updatePosition(x, y) {
  11667. var container = this.container;
  11668. var _this$_getBBox2 = this._getBBox(),
  11669. xMin = _this$_getBBox2.x,
  11670. yMin = _this$_getBBox2.y;
  11671. container.moveTo(x - xMin, y - yMin);
  11672. this.x = x - xMin;
  11673. this.y = y - yMin;
  11674. };
  11675. _proto.getWidth = function getWidth() {
  11676. return this._width;
  11677. };
  11678. _proto.getHeight = function getHeight() {
  11679. return this._height;
  11680. };
  11681. _proto.show = function show() {
  11682. this.container.show();
  11683. };
  11684. _proto.hide = function hide() {
  11685. this.container.hide();
  11686. };
  11687. _proto.clear = function clear() {
  11688. var container = this.container;
  11689. container.clear();
  11690. container.remove(true);
  11691. this.container = null;
  11692. this.textShape = null;
  11693. this.backgroundShape = null;
  11694. };
  11695. return TextBox;
  11696. }();
  11697. var GAP = 4;
  11698. /**
  11699. * TODOList:
  11700. * 1. 移除 fixed 参数
  11701. */
  11702. var Tooltip$1 = /*#__PURE__*/function () {
  11703. var _proto = Tooltip.prototype;
  11704. _proto.getDefaultCfg = function getDefaultCfg() {
  11705. return {
  11706. /**
  11707. * wether show the crosshairs
  11708. * @type {Object}
  11709. */
  11710. showCrosshairs: false,
  11711. /**
  11712. * the style for crosshairs
  11713. * @type {Object}
  11714. */
  11715. crosshairsStyle: {
  11716. stroke: 'rgba(0, 0, 0, 0.25)',
  11717. lineWidth: 1
  11718. },
  11719. /**
  11720. * the type of crosshairs, optional value is 'x', 'y' or 'xy', default is 'y'
  11721. */
  11722. crosshairsType: 'y',
  11723. /**
  11724. * show or hide the x axis tip
  11725. */
  11726. showXTip: false,
  11727. /**
  11728. * show or hide the y axis tip
  11729. */
  11730. showYTip: false,
  11731. xTip: null,
  11732. xTipBackground: {
  11733. radius: 1,
  11734. fill: 'rgba(0, 0, 0, 0.65)',
  11735. padding: [3, 5]
  11736. },
  11737. xTipTextStyle: {
  11738. fontSize: 12,
  11739. fill: '#fff',
  11740. textAlign: 'center',
  11741. textBaseline: 'middle'
  11742. },
  11743. yTip: null,
  11744. yTipBackground: {
  11745. radius: 1,
  11746. fill: 'rgba(0, 0, 0, 0.65)',
  11747. padding: [3, 5]
  11748. },
  11749. yTipTextStyle: {
  11750. fontSize: 12,
  11751. fill: '#fff',
  11752. textAlign: 'center',
  11753. textBaseline: 'middle'
  11754. },
  11755. /**
  11756. * the style for tooltip container's background
  11757. * @type {Object}
  11758. */
  11759. background: null,
  11760. /**
  11761. * layout, can be horizontal or vertical
  11762. * @type {String}
  11763. */
  11764. layout: 'horizontal',
  11765. offsetX: 0,
  11766. offsetY: 0
  11767. };
  11768. };
  11769. function Tooltip(cfg) {
  11770. deepMix(this, this.getDefaultCfg(), cfg);
  11771. var frontPlot = this.frontPlot,
  11772. custom = this.custom;
  11773. if (!custom) {
  11774. // custom means user do customize
  11775. var container = new List(mix$1({
  11776. parent: frontPlot,
  11777. zIndex: 3
  11778. }, cfg));
  11779. this.container = container;
  11780. var fixed = this.fixed,
  11781. background = this.background;
  11782. if (!fixed) {
  11783. this.tooltipArrow = frontPlot.addShape('Polygon', {
  11784. className: 'tooltip-arrow',
  11785. visible: false,
  11786. zIndex: 2,
  11787. attrs: mix$1({
  11788. points: []
  11789. }, background)
  11790. });
  11791. }
  11792. }
  11793. if (this.showXTip) {
  11794. var xTipBackground = this.xTipBackground,
  11795. xTipTextStyle = this.xTipTextStyle;
  11796. var xTipBox = new TextBox({
  11797. context: frontPlot.get('context'),
  11798. className: 'xTip',
  11799. background: xTipBackground,
  11800. textStyle: xTipTextStyle,
  11801. visible: false
  11802. });
  11803. frontPlot.add(xTipBox.container);
  11804. this.xTipBox = xTipBox;
  11805. }
  11806. if (this.showYTip) {
  11807. var yTipBackground = this.yTipBackground,
  11808. yTipTextStyle = this.yTipTextStyle;
  11809. var yTipBox = new TextBox({
  11810. context: frontPlot.get('context'),
  11811. className: 'yTip',
  11812. background: yTipBackground,
  11813. textStyle: yTipTextStyle,
  11814. visible: false
  11815. });
  11816. frontPlot.add(yTipBox.container);
  11817. this.yTipBox = yTipBox;
  11818. }
  11819. if (this.showCrosshairs) {
  11820. this._renderCrosshairs();
  11821. }
  11822. frontPlot.sort();
  11823. }
  11824. _proto.setContent = function setContent(title, items) {
  11825. this.title = title;
  11826. this.items = items;
  11827. if (!this.custom) {
  11828. var container = this.container;
  11829. container.setTitle(title);
  11830. container.setItems(items);
  11831. }
  11832. };
  11833. _proto.setYTipContent = function setYTipContent(val) {
  11834. var yTip = this.yTip;
  11835. if (isFunction$1(yTip)) {
  11836. val = yTip(val);
  11837. } else {
  11838. val = mix$1({
  11839. text: val
  11840. }, yTip);
  11841. }
  11842. this.yTipBox && this.yTipBox.updateContent(val);
  11843. };
  11844. _proto.setYTipPosition = function setYTipPosition(pos) {
  11845. var plotRange = this.plotRange;
  11846. var crosshairsShapeX = this.crosshairsShapeX;
  11847. if (this.showYTip) {
  11848. var yTipBox = this.yTipBox;
  11849. var yTipHeight = yTipBox.getHeight();
  11850. var yTipWidth = yTipBox.getWidth();
  11851. var posX = plotRange.tl.x - yTipWidth;
  11852. var posY = pos - yTipHeight / 2;
  11853. if (posY <= plotRange.tl.y) {
  11854. posY = plotRange.tl.y;
  11855. }
  11856. if (posY + yTipHeight >= plotRange.br.y) {
  11857. posY = plotRange.br.y - yTipHeight;
  11858. }
  11859. if (posX < 0) {
  11860. posX = plotRange.tl.x;
  11861. crosshairsShapeX && crosshairsShapeX.attr('x1', plotRange.tl.x + yTipWidth);
  11862. }
  11863. yTipBox.updatePosition(posX, posY);
  11864. }
  11865. };
  11866. _proto.setXTipContent = function setXTipContent(val) {
  11867. var xTip = this.xTip;
  11868. if (isFunction$1(xTip)) {
  11869. val = xTip(val);
  11870. } else {
  11871. val = mix$1({
  11872. text: val
  11873. }, xTip);
  11874. }
  11875. this.xTipBox && this.xTipBox.updateContent(val);
  11876. };
  11877. _proto.setXTipPosition = function setXTipPosition(pos) {
  11878. var showXTip = this.showXTip,
  11879. canvas = this.canvas,
  11880. plotRange = this.plotRange,
  11881. xTipBox = this.xTipBox,
  11882. crosshairsShapeY = this.crosshairsShapeY;
  11883. if (showXTip) {
  11884. // const el = canvas.get('el');
  11885. // const canvasHeight = Util.getHeight(el);
  11886. var canvasHeight = canvas.get('height');
  11887. var xTipWidth = xTipBox.getWidth();
  11888. var xTipHeight = xTipBox.getHeight();
  11889. var posX = pos - xTipWidth / 2;
  11890. var posY = plotRange.br.y;
  11891. if (posX <= plotRange.tl.x) {
  11892. posX = plotRange.tl.x;
  11893. }
  11894. if (posX + xTipWidth >= plotRange.tr.x) {
  11895. posX = plotRange.tr.x - xTipWidth;
  11896. }
  11897. if (canvasHeight - posY < xTipHeight) {
  11898. posY -= xTipHeight;
  11899. }
  11900. xTipBox.updatePosition(posX, posY);
  11901. crosshairsShapeY && crosshairsShapeY.attr('y1', posY);
  11902. }
  11903. };
  11904. _proto.setXCrosshairPosition = function setXCrosshairPosition(pos) {
  11905. this.crosshairsShapeX && this.crosshairsShapeX.moveTo(0, pos);
  11906. };
  11907. _proto.setYCrosshairPosition = function setYCrosshairPosition(pos) {
  11908. this.crosshairsShapeY && this.crosshairsShapeY.moveTo(pos, 0);
  11909. };
  11910. _proto.setPosition = function setPosition(items) {
  11911. var container = this.container,
  11912. plotRange = this.plotRange,
  11913. offsetX = this.offsetX,
  11914. offsetY = this.offsetY,
  11915. fixed = this.fixed,
  11916. tooltipArrow = this.tooltipArrow;
  11917. if (!container) {
  11918. return;
  11919. }
  11920. var containerBBox = container.container.getBBox();
  11921. var minX = containerBBox.minX,
  11922. minY = containerBBox.minY,
  11923. width = containerBBox.width,
  11924. height = containerBBox.height;
  11925. var tl = plotRange.tl,
  11926. tr = plotRange.tr;
  11927. var posX = 0;
  11928. var posY = tl.y - height - GAP + offsetY;
  11929. if (posY < 0) {
  11930. posY = 0;
  11931. }
  11932. if (fixed) {
  11933. var x = (tl.x + tr.x) / 2;
  11934. posX = x - width / 2 + offsetX;
  11935. } else {
  11936. var _x;
  11937. if (items.length > 1) {
  11938. _x = (items[0].x + items[items.length - 1].x) / 2;
  11939. } else {
  11940. _x = items[0].x;
  11941. }
  11942. posX = _x - width / 2 + offsetX;
  11943. if (posX < tl.x) {
  11944. posX = tl.x;
  11945. }
  11946. if (posX + width > tr.x) {
  11947. posX = tr.x - width;
  11948. }
  11949. if (tooltipArrow) {
  11950. var arrowY = posY + height;
  11951. tooltipArrow.attr('points', [{
  11952. x: _x - 3,
  11953. y: arrowY
  11954. }, {
  11955. x: _x + 3,
  11956. y: arrowY
  11957. }, {
  11958. x: _x,
  11959. y: arrowY + GAP
  11960. }]);
  11961. var backShape = container.backShape;
  11962. var radius = parsePadding(backShape.attr('radius'));
  11963. if (_x === tl.x) {
  11964. radius[3] = 0;
  11965. tooltipArrow.attr('points', [{
  11966. x: tl.x,
  11967. y: arrowY
  11968. }, {
  11969. x: tl.x + GAP,
  11970. y: arrowY
  11971. }, {
  11972. x: tl.x,
  11973. y: arrowY + GAP
  11974. }]);
  11975. } else if (_x === tr.x) {
  11976. radius[2] = 0;
  11977. tooltipArrow.attr('points', [{
  11978. x: tr.x - GAP,
  11979. y: arrowY
  11980. }, {
  11981. x: tr.x,
  11982. y: arrowY
  11983. }, {
  11984. x: tr.x,
  11985. y: arrowY + GAP
  11986. }]);
  11987. }
  11988. backShape.attr('radius', radius);
  11989. }
  11990. }
  11991. container.moveTo(posX - minX, posY - minY);
  11992. };
  11993. _proto.setMarkers = function setMarkers(cfg) {
  11994. if (cfg === void 0) {
  11995. cfg = {};
  11996. }
  11997. var self = this;
  11998. var _cfg = cfg,
  11999. items = _cfg.items,
  12000. style = _cfg.style,
  12001. type = _cfg.type;
  12002. var markerGroup = self._getMarkerGroup(type);
  12003. if (type === 'circle') {
  12004. for (var i = 0, length = items.length; i < length; i++) {
  12005. var item = items[i];
  12006. markerGroup.addShape('marker', {
  12007. className: 'tooltip-circle-marker',
  12008. attrs: mix$1({
  12009. x: item.x,
  12010. y: item.y,
  12011. stroke: item.color
  12012. }, style)
  12013. });
  12014. }
  12015. } else {
  12016. markerGroup.addShape('rect', {
  12017. className: 'tooltip-rect-marker',
  12018. attrs: style
  12019. });
  12020. }
  12021. };
  12022. _proto.clearMarkers = function clearMarkers() {
  12023. var markerGroup = this.markerGroup;
  12024. markerGroup && markerGroup.clear();
  12025. };
  12026. _proto.show = function show() {
  12027. var crosshairsShapeX = this.crosshairsShapeX;
  12028. var crosshairsShapeY = this.crosshairsShapeY;
  12029. var markerGroup = this.markerGroup;
  12030. var container = this.container;
  12031. var tooltipArrow = this.tooltipArrow;
  12032. var xTipBox = this.xTipBox;
  12033. var yTipBox = this.yTipBox;
  12034. var canvas = this.canvas;
  12035. crosshairsShapeX && crosshairsShapeX.show();
  12036. crosshairsShapeY && crosshairsShapeY.show();
  12037. markerGroup && markerGroup.show();
  12038. container && container.show();
  12039. tooltipArrow && tooltipArrow.show();
  12040. xTipBox && xTipBox.show();
  12041. yTipBox && yTipBox.show();
  12042. canvas.draw();
  12043. };
  12044. _proto.hide = function hide() {
  12045. var crosshairsShapeX = this.crosshairsShapeX;
  12046. var crosshairsShapeY = this.crosshairsShapeY;
  12047. var markerGroup = this.markerGroup;
  12048. var container = this.container;
  12049. var tooltipArrow = this.tooltipArrow;
  12050. var xTipBox = this.xTipBox;
  12051. var yTipBox = this.yTipBox;
  12052. crosshairsShapeX && crosshairsShapeX.hide();
  12053. crosshairsShapeY && crosshairsShapeY.hide();
  12054. markerGroup && markerGroup.hide();
  12055. container && container.hide();
  12056. tooltipArrow && tooltipArrow.hide();
  12057. xTipBox && xTipBox.hide();
  12058. yTipBox && yTipBox.hide();
  12059. };
  12060. _proto.destroy = function destroy() {
  12061. var crosshairsShapeX = this.crosshairsShapeX;
  12062. var crosshairsShapeY = this.crosshairsShapeY;
  12063. var markerGroup = this.markerGroup;
  12064. var container = this.container;
  12065. var tooltipArrow = this.tooltipArrow;
  12066. var xTipBox = this.xTipBox;
  12067. var yTipBox = this.yTipBox;
  12068. crosshairsShapeX && crosshairsShapeX.remove(true);
  12069. crosshairsShapeY && crosshairsShapeY.remove(true);
  12070. markerGroup && markerGroup.remove(true);
  12071. tooltipArrow && tooltipArrow.remove(true);
  12072. container && container.clear();
  12073. xTipBox && xTipBox.clear();
  12074. yTipBox && yTipBox.clear();
  12075. this.destroyed = true;
  12076. };
  12077. _proto._getMarkerGroup = function _getMarkerGroup(type) {
  12078. var markerGroup = this.markerGroup;
  12079. if (!markerGroup) {
  12080. if (type === 'circle') {
  12081. markerGroup = this.frontPlot.addGroup({
  12082. zIndex: 1
  12083. });
  12084. this.frontPlot.sort();
  12085. } else {
  12086. markerGroup = this.backPlot.addGroup();
  12087. }
  12088. this.markerGroup = markerGroup;
  12089. } else {
  12090. markerGroup.clear();
  12091. }
  12092. return markerGroup;
  12093. };
  12094. _proto._renderCrosshairs = function _renderCrosshairs() {
  12095. var crosshairsType = this.crosshairsType,
  12096. crosshairsStyle = this.crosshairsStyle,
  12097. frontPlot = this.frontPlot,
  12098. plotRange = this.plotRange;
  12099. var tl = plotRange.tl,
  12100. br = plotRange.br;
  12101. if (directionEnabled(crosshairsType, 'x')) {
  12102. this.crosshairsShapeX = frontPlot.addShape('Line', {
  12103. className: 'tooltip-crosshairs-x',
  12104. zIndex: 0,
  12105. visible: false,
  12106. attrs: mix$1({
  12107. x1: tl.x,
  12108. y1: 0,
  12109. x2: br.x,
  12110. y2: 0
  12111. }, crosshairsStyle)
  12112. });
  12113. }
  12114. if (directionEnabled(crosshairsType, 'y')) {
  12115. this.crosshairsShapeY = frontPlot.addShape('Line', {
  12116. className: 'tooltip-crosshairs-y',
  12117. zIndex: 0,
  12118. visible: false,
  12119. attrs: mix$1({
  12120. x1: 0,
  12121. y1: br.y,
  12122. x2: 0,
  12123. y2: tl.y
  12124. }, crosshairsStyle)
  12125. });
  12126. }
  12127. };
  12128. return Tooltip;
  12129. }();
  12130. Global.tooltip = deepMix({
  12131. triggerOn: 'press',
  12132. triggerOff: 'pressend',
  12133. alwaysShow: false,
  12134. showTitle: false,
  12135. showCrosshairs: false,
  12136. crosshairsStyle: {
  12137. stroke: 'rgba(0, 0, 0, 0.25)',
  12138. lineWidth: 1
  12139. },
  12140. showTooltipMarker: true,
  12141. background: {
  12142. radius: 1,
  12143. fill: 'rgba(0, 0, 0, 0.65)',
  12144. padding: [3, 5]
  12145. },
  12146. titleStyle: {
  12147. fontSize: 12,
  12148. fill: '#fff',
  12149. textAlign: 'start',
  12150. textBaseline: 'top'
  12151. },
  12152. nameStyle: {
  12153. fontSize: 12,
  12154. fill: 'rgba(255, 255, 255, 0.65)',
  12155. textAlign: 'start',
  12156. textBaseline: 'middle'
  12157. },
  12158. valueStyle: {
  12159. fontSize: 12,
  12160. fill: '#fff',
  12161. textAlign: 'start',
  12162. textBaseline: 'middle'
  12163. },
  12164. showItemMarker: true,
  12165. itemMarkerStyle: {
  12166. radius: 3,
  12167. symbol: 'circle',
  12168. lineWidth: 1,
  12169. stroke: '#fff'
  12170. },
  12171. layout: 'horizontal',
  12172. snap: false
  12173. }, Global.tooltip || {});
  12174. function _getTooltipValueScale(geom) {
  12175. var colorAttr = geom.getAttr('color');
  12176. if (colorAttr) {
  12177. var colorScale = colorAttr.getScale(colorAttr.type);
  12178. if (colorScale.isLinear) {
  12179. return colorScale;
  12180. }
  12181. }
  12182. var xScale = geom.getXScale();
  12183. var yScale = geom.getYScale();
  12184. if (yScale) {
  12185. return yScale;
  12186. }
  12187. return xScale;
  12188. }
  12189. function getTooltipName(geom, origin) {
  12190. var name;
  12191. var nameScale;
  12192. var groupScales = geom._getGroupScales();
  12193. if (groupScales.length) {
  12194. each$1(groupScales, function (scale) {
  12195. nameScale = scale;
  12196. return false;
  12197. });
  12198. }
  12199. if (nameScale) {
  12200. var field = nameScale.field;
  12201. name = nameScale.getText(origin[field]);
  12202. } else {
  12203. var valueScale = _getTooltipValueScale(geom);
  12204. name = valueScale.alias || valueScale.field;
  12205. }
  12206. return name;
  12207. }
  12208. function getTooltipValue(geom, origin) {
  12209. var scale = _getTooltipValueScale(geom);
  12210. return scale.getText(origin[scale.field]);
  12211. }
  12212. function getTooltipTitle(geom, origin) {
  12213. var position = geom.getAttr('position');
  12214. var field = position.getFields()[0];
  12215. var scale = geom.get('scales')[field];
  12216. return scale.getText(origin[scale.field]);
  12217. }
  12218. function _indexOfArray(items, item) {
  12219. var rst = -1;
  12220. each$1(items, function (sub, index) {
  12221. if (sub.title === item.title && sub.name === item.name && sub.value === item.value && sub.color === item.color) {
  12222. rst = index;
  12223. return false;
  12224. }
  12225. });
  12226. return rst;
  12227. }
  12228. function _uniqItems(items) {
  12229. var tmp = [];
  12230. each$1(items, function (item) {
  12231. var index = _indexOfArray(tmp, item);
  12232. if (index === -1) {
  12233. tmp.push(item);
  12234. } else {
  12235. tmp[index] = item;
  12236. }
  12237. });
  12238. return tmp;
  12239. }
  12240. function isEqual(arr1, arr2) {
  12241. return JSON.stringify(arr1) === JSON.stringify(arr2);
  12242. }
  12243. var TooltipController = /*#__PURE__*/function () {
  12244. function TooltipController(cfg) {
  12245. var _this = this;
  12246. _defineProperty(this, "handleShowEvent", function (ev) {
  12247. var chart = _this.chart;
  12248. if (!_this.enable) return;
  12249. var plot = chart.get('plotRange');
  12250. var point = createEvent(ev, chart);
  12251. if (!isPointInPlot(point, plot) && !_this._tooltipCfg.alwaysShow) {
  12252. // not in chart plot
  12253. _this.hideTooltip();
  12254. return;
  12255. }
  12256. var lastTimeStamp = _this.timeStamp;
  12257. var timeStamp = +new Date();
  12258. if (timeStamp - lastTimeStamp > 16) {
  12259. _this.showTooltip(point);
  12260. _this.timeStamp = timeStamp;
  12261. }
  12262. });
  12263. _defineProperty(this, "handleHideEvent", function () {
  12264. if (!_this.enable) return;
  12265. _this.hideTooltip();
  12266. });
  12267. this.enable = true;
  12268. this.cfg = {};
  12269. this.tooltip = null;
  12270. this.chart = null;
  12271. this.timeStamp = 0;
  12272. mix$1(this, cfg);
  12273. var _chart = this.chart;
  12274. var canvas = _chart.get('canvas');
  12275. this.canvas = canvas;
  12276. this.canvasDom = canvas.get('el');
  12277. }
  12278. var _proto = TooltipController.prototype;
  12279. _proto._setCrosshairsCfg = function _setCrosshairsCfg() {
  12280. var self = this;
  12281. var chart = self.chart;
  12282. var defaultCfg = mix$1({}, Global.tooltip);
  12283. var geoms = chart.get('geoms');
  12284. var shapes = [];
  12285. each$1(geoms, function (geom) {
  12286. var type = geom.get('type');
  12287. if (shapes.indexOf(type) === -1) {
  12288. shapes.push(type);
  12289. }
  12290. });
  12291. var coordType = chart.get('coord').type;
  12292. if (geoms.length && (coordType === 'cartesian' || coordType === 'rect')) {
  12293. if (shapes.length === 1 && ['line', 'area', 'path', 'point'].indexOf(shapes[0]) !== -1) {
  12294. mix$1(defaultCfg, {
  12295. showCrosshairs: true
  12296. });
  12297. }
  12298. }
  12299. return defaultCfg;
  12300. };
  12301. _proto._getMaxLength = function _getMaxLength(cfg) {
  12302. if (cfg === void 0) {
  12303. cfg = {};
  12304. }
  12305. var _cfg = cfg,
  12306. layout = _cfg.layout,
  12307. plotRange = _cfg.plotRange;
  12308. return layout === 'horizontal' ? plotRange.br.x - plotRange.bl.x : plotRange.bl.y - plotRange.tr.y;
  12309. };
  12310. _proto.render = function render() {
  12311. var self = this;
  12312. if (self.tooltip) {
  12313. return;
  12314. }
  12315. var chart = self.chart;
  12316. var canvas = chart.get('canvas');
  12317. var frontPlot = chart.get('frontPlot').addGroup({
  12318. className: 'tooltipContainer',
  12319. zIndex: 10
  12320. });
  12321. var backPlot = chart.get('backPlot').addGroup({
  12322. className: 'tooltipContainer'
  12323. });
  12324. var plotRange = chart.get('plotRange');
  12325. var coord = chart.get('coord');
  12326. var defaultCfg = self._setCrosshairsCfg();
  12327. var cfg = self.cfg; // 通过 chart.tooltip() 接口传入的 tooltip 配置项
  12328. var tooltipCfg = deepMix({
  12329. plotRange: plotRange,
  12330. frontPlot: frontPlot,
  12331. backPlot: backPlot,
  12332. canvas: canvas,
  12333. fixed: coord.transposed || coord.isPolar
  12334. }, defaultCfg, cfg); // 创建 tooltip 实例需要的配置,不应该修改 this.cfg,即用户传入的配置
  12335. tooltipCfg.maxLength = self._getMaxLength(tooltipCfg);
  12336. this._tooltipCfg = tooltipCfg;
  12337. var tooltip = new Tooltip$1(tooltipCfg);
  12338. self.tooltip = tooltip; // 需要保持tooltip一直显示
  12339. if (tooltipCfg.alwaysShow && self.prePoint) {
  12340. this.showTooltip(self.prePoint);
  12341. }
  12342. self.bindEvents();
  12343. };
  12344. _proto.clear = function clear() {
  12345. var tooltip = this.tooltip;
  12346. if (tooltip) {
  12347. tooltip.destroy();
  12348. this.unBindEvents();
  12349. }
  12350. this.tooltip = null;
  12351. this._lastActive = null;
  12352. };
  12353. _proto._getTooltipMarkerStyle = function _getTooltipMarkerStyle(cfg) {
  12354. if (cfg === void 0) {
  12355. cfg = {};
  12356. }
  12357. var _cfg2 = cfg,
  12358. type = _cfg2.type,
  12359. items = _cfg2.items;
  12360. var tooltipCfg = this._tooltipCfg;
  12361. if (type === 'rect') {
  12362. var x;
  12363. var y;
  12364. var width;
  12365. var height;
  12366. var chart = this.chart;
  12367. var _chart$get = chart.get('plotRange'),
  12368. tl = _chart$get.tl,
  12369. br = _chart$get.br;
  12370. var coord = chart.get('coord');
  12371. var firstItem = items[0];
  12372. var lastItem = items[items.length - 1];
  12373. var intervalWidth = firstItem.width;
  12374. if (coord.transposed) {
  12375. x = tl.x;
  12376. y = lastItem.y - intervalWidth * 0.75;
  12377. width = br.x - tl.x;
  12378. height = firstItem.y - lastItem.y + 1.5 * intervalWidth;
  12379. } else {
  12380. x = firstItem.x - intervalWidth * 0.75;
  12381. y = tl.y;
  12382. width = lastItem.x - firstItem.x + 1.5 * intervalWidth;
  12383. height = br.y - tl.y;
  12384. }
  12385. cfg.style = mix$1({
  12386. x: x,
  12387. y: y,
  12388. width: width,
  12389. height: height,
  12390. fill: '#CCD6EC',
  12391. opacity: 0.3
  12392. }, tooltipCfg.tooltipMarkerStyle);
  12393. } else {
  12394. cfg.style = mix$1({
  12395. radius: 4,
  12396. fill: '#fff',
  12397. lineWidth: 2
  12398. }, tooltipCfg.tooltipMarkerStyle);
  12399. }
  12400. return cfg;
  12401. };
  12402. _proto._setTooltip = function _setTooltip(point, items, tooltipMarkerCfg) {
  12403. if (tooltipMarkerCfg === void 0) {
  12404. tooltipMarkerCfg = {};
  12405. }
  12406. this.prePoint = point;
  12407. var lastActive = this._lastActive;
  12408. var tooltip = this.tooltip;
  12409. var cfg = this._tooltipCfg;
  12410. items = _uniqItems(items);
  12411. var chart = this.chart;
  12412. var coord = chart.get('coord');
  12413. var yScale = chart.getYScales()[0];
  12414. var snap = cfg.snap;
  12415. if (snap === false && yScale.isLinear) {
  12416. var invertPoint = coord.invertPoint(point);
  12417. var plot = chart.get('plotRange');
  12418. var tip;
  12419. var pos;
  12420. if (isPointInPlot(point, plot)) {
  12421. if (coord.transposed) {
  12422. tip = yScale.invert(invertPoint.x);
  12423. pos = point.x;
  12424. tooltip.setXTipContent(tip);
  12425. tooltip.setXTipPosition(pos);
  12426. tooltip.setYCrosshairPosition(pos);
  12427. } else {
  12428. tip = yScale.invert(invertPoint.y);
  12429. pos = point.y;
  12430. tooltip.setYTipContent(tip);
  12431. tooltip.setYTipPosition(pos);
  12432. tooltip.setXCrosshairPosition(pos);
  12433. }
  12434. }
  12435. }
  12436. if (cfg.onShow) {
  12437. cfg.onShow({
  12438. x: point.x,
  12439. y: point.y,
  12440. tooltip: tooltip,
  12441. items: items,
  12442. tooltipMarkerCfg: tooltipMarkerCfg
  12443. });
  12444. }
  12445. if (isEqual(lastActive, items)) {
  12446. if (snap === false && (directionEnabled(cfg.crosshairsType, 'y') || cfg.showYTip)) {
  12447. var canvas = this.chart.get('canvas');
  12448. canvas.draw();
  12449. }
  12450. return;
  12451. }
  12452. this._lastActive = items;
  12453. var onChange = cfg.onChange;
  12454. if (onChange) {
  12455. onChange({
  12456. x: point.x,
  12457. y: point.y,
  12458. tooltip: tooltip,
  12459. items: items,
  12460. tooltipMarkerCfg: tooltipMarkerCfg
  12461. });
  12462. }
  12463. var first = items[0];
  12464. var title = first.title || first.name;
  12465. var xTipPosX = first.x;
  12466. if (items.length > 1) {
  12467. xTipPosX = (items[0].x + items[items.length - 1].x) / 2;
  12468. }
  12469. tooltip.setContent(title, items, coord.transposed);
  12470. tooltip.setPosition(items, point);
  12471. if (coord.transposed) {
  12472. var yTipPosY = first.y;
  12473. if (items.length > 1) {
  12474. yTipPosY = (items[0].y + items[items.length - 1].y) / 2;
  12475. }
  12476. tooltip.setYTipContent(title);
  12477. tooltip.setYTipPosition(yTipPosY);
  12478. tooltip.setXCrosshairPosition(yTipPosY);
  12479. if (snap) {
  12480. tooltip.setXTipContent(first.value);
  12481. tooltip.setXTipPosition(xTipPosX);
  12482. tooltip.setYCrosshairPosition(xTipPosX);
  12483. }
  12484. } else {
  12485. tooltip.setXTipContent(title);
  12486. tooltip.setXTipPosition(xTipPosX);
  12487. tooltip.setYCrosshairPosition(xTipPosX);
  12488. if (snap) {
  12489. tooltip.setYTipContent(first.value);
  12490. tooltip.setYTipPosition(first.y);
  12491. tooltip.setXCrosshairPosition(first.y);
  12492. }
  12493. }
  12494. var markerItems = tooltipMarkerCfg.items;
  12495. if (cfg.showTooltipMarker && markerItems.length) {
  12496. tooltipMarkerCfg = this._getTooltipMarkerStyle(tooltipMarkerCfg);
  12497. tooltip.setMarkers(tooltipMarkerCfg);
  12498. } else {
  12499. tooltip.clearMarkers();
  12500. }
  12501. tooltip.show();
  12502. };
  12503. _proto.showTooltip = function showTooltip(point) {
  12504. var self = this;
  12505. var chart = self.chart;
  12506. var tooltipMarkerType;
  12507. var tooltipMarkerItems = [];
  12508. var items = [];
  12509. var cfg = self._tooltipCfg;
  12510. var showItemMarker = cfg.showItemMarker,
  12511. itemMarkerStyle = cfg.itemMarkerStyle,
  12512. alwaysShow = cfg.alwaysShow;
  12513. var marker;
  12514. if (showItemMarker) {
  12515. marker = itemMarkerStyle;
  12516. }
  12517. var geoms = chart.get('geoms');
  12518. var coord = chart.get('coord');
  12519. each$1(geoms, function (geom) {
  12520. if (geom.get('visible')) {
  12521. var type = geom.get('type');
  12522. var records = geom.getSnapRecords(point);
  12523. var adjust = geom.get('adjust'); // 漏斗图和金子塔图tooltip位置有问题,暂时不开放显示
  12524. if (type === 'interval' && adjust && adjust.type === 'symmetric') {
  12525. return;
  12526. }
  12527. each$1(records, function (record) {
  12528. var x = record.x,
  12529. y = record.y,
  12530. _origin = record._origin,
  12531. color = record.color;
  12532. if ((x || !isNaN(x)) && (y || !isNaN(y))) {
  12533. var tooltipItem = {
  12534. x: x,
  12535. y: isArray$1(y) ? y[1] : y,
  12536. color: color || Global.defaultColor,
  12537. origin: _origin,
  12538. name: getTooltipName(geom, _origin),
  12539. value: getTooltipValue(geom, _origin),
  12540. title: getTooltipTitle(geom, _origin)
  12541. };
  12542. if (marker) {
  12543. tooltipItem.marker = mix$1({
  12544. fill: color || Global.defaultColor
  12545. }, marker);
  12546. }
  12547. items.push(tooltipItem);
  12548. if (['line', 'area', 'path'].indexOf(type) !== -1) {
  12549. tooltipMarkerType = 'circle';
  12550. tooltipMarkerItems.push(tooltipItem);
  12551. } else if (type === 'interval' && (coord.type === 'cartesian' || coord.type === 'rect')) {
  12552. tooltipMarkerType = 'rect';
  12553. tooltipItem.width = geom.getSize(record._origin);
  12554. tooltipMarkerItems.push(tooltipItem);
  12555. }
  12556. }
  12557. });
  12558. }
  12559. });
  12560. if (items.length) {
  12561. var tooltipMarkerCfg = {
  12562. items: tooltipMarkerItems,
  12563. type: tooltipMarkerType
  12564. };
  12565. self._setTooltip(point, items, tooltipMarkerCfg);
  12566. return;
  12567. }
  12568. if (!alwaysShow) {
  12569. self.hideTooltip();
  12570. }
  12571. };
  12572. _proto.hideTooltip = function hideTooltip() {
  12573. var cfg = this._tooltipCfg;
  12574. this._lastActive = null;
  12575. var tooltip = this.tooltip;
  12576. if (tooltip) {
  12577. tooltip.hide();
  12578. if (cfg.onHide) {
  12579. cfg.onHide({
  12580. tooltip: tooltip
  12581. });
  12582. }
  12583. var canvas = this.chart.get('canvas');
  12584. canvas.draw();
  12585. }
  12586. };
  12587. _proto._handleEvent = function _handleEvent(methodName, method, action) {
  12588. var canvas = this.canvas;
  12589. each$1([].concat(methodName), function (aMethod) {
  12590. if (action === 'bind') {
  12591. canvas.on(aMethod, method);
  12592. } else {
  12593. canvas.off(aMethod, method);
  12594. }
  12595. });
  12596. };
  12597. _proto.bindEvents = function bindEvents() {
  12598. var cfg = this._tooltipCfg;
  12599. var triggerOn = cfg.triggerOn,
  12600. triggerOff = cfg.triggerOff,
  12601. alwaysShow = cfg.alwaysShow;
  12602. triggerOn && this._handleEvent(triggerOn, this.handleShowEvent, 'bind'); // 如果 !alwaysShow, 则在手势离开后就隐藏
  12603. if (!alwaysShow) {
  12604. this._handleEvent(triggerOff, this.handleHideEvent, 'bind');
  12605. }
  12606. };
  12607. _proto.unBindEvents = function unBindEvents() {
  12608. var cfg = this._tooltipCfg;
  12609. var triggerOn = cfg.triggerOn,
  12610. triggerOff = cfg.triggerOff,
  12611. alwaysShow = cfg.alwaysShow;
  12612. triggerOn && this._handleEvent(triggerOn, this.handleShowEvent, 'unBind');
  12613. if (!alwaysShow) {
  12614. this._handleEvent(triggerOff, this.handleHideEvent, 'unBind');
  12615. }
  12616. };
  12617. return TooltipController;
  12618. }();
  12619. function init$2(chart) {
  12620. var tooltipController = new TooltipController({
  12621. chart: chart
  12622. });
  12623. chart.set('tooltipController', tooltipController);
  12624. chart.tooltip = function (enable, cfg) {
  12625. if (isObject$1(enable)) {
  12626. cfg = enable;
  12627. enable = true;
  12628. }
  12629. tooltipController.enable = enable;
  12630. if (cfg) {
  12631. tooltipController.cfg = cfg;
  12632. }
  12633. return this;
  12634. };
  12635. }
  12636. function afterGeomDraw$2(chart) {
  12637. var tooltipController = chart.get('tooltipController');
  12638. tooltipController.render();
  12639. chart.showTooltip = function (point) {
  12640. tooltipController.showTooltip(point);
  12641. return this;
  12642. };
  12643. chart.hideTooltip = function () {
  12644. tooltipController.hideTooltip();
  12645. return this;
  12646. };
  12647. }
  12648. function clearInner$1(chart) {
  12649. var tooltipController = chart.get('tooltipController');
  12650. tooltipController.clear();
  12651. }
  12652. var tooltip = {
  12653. init: init$2,
  12654. afterGeomDraw: afterGeomDraw$2,
  12655. clearInner: clearInner$1
  12656. };
  12657. var Tooltip = /*#__PURE__*/Object.freeze({
  12658. __proto__: null,
  12659. init: init$2,
  12660. afterGeomDraw: afterGeomDraw$2,
  12661. clearInner: clearInner$1,
  12662. 'default': tooltip
  12663. });
  12664. Global.guide = deepMix({
  12665. line: {
  12666. style: {
  12667. stroke: '#a3a3a3',
  12668. lineWidth: 1
  12669. },
  12670. top: true
  12671. },
  12672. text: {
  12673. style: {
  12674. fill: '#787878',
  12675. textAlign: 'center',
  12676. textBaseline: 'middle'
  12677. },
  12678. offsetX: 0,
  12679. offsetY: 0,
  12680. top: true
  12681. },
  12682. rect: {
  12683. style: {
  12684. fill: '#fafafa'
  12685. },
  12686. top: false
  12687. },
  12688. arc: {
  12689. style: {
  12690. stroke: '#a3a3a3'
  12691. },
  12692. top: true
  12693. },
  12694. html: {
  12695. offsetX: 0,
  12696. offsetY: 0,
  12697. alignX: 'center',
  12698. alignY: 'middle'
  12699. },
  12700. tag: {
  12701. top: true,
  12702. offsetX: 0,
  12703. offsetY: 0,
  12704. side: 4,
  12705. background: {
  12706. padding: 5,
  12707. radius: 2,
  12708. fill: '#1890FF'
  12709. },
  12710. textStyle: {
  12711. fontSize: 12,
  12712. fill: '#fff',
  12713. textAlign: 'center',
  12714. textBaseline: 'middle'
  12715. }
  12716. },
  12717. point: {
  12718. top: true,
  12719. offsetX: 0,
  12720. offsetY: 0,
  12721. style: {
  12722. fill: '#fff',
  12723. r: 3,
  12724. lineWidth: 2,
  12725. stroke: '#1890ff'
  12726. }
  12727. }
  12728. }, Global.guide || {});
  12729. var GuideController = /*#__PURE__*/function () {
  12730. function GuideController(cfg) {
  12731. this.guides = [];
  12732. this.xScale = null;
  12733. this.yScales = null;
  12734. this.guideShapes = [];
  12735. mix$1(this, cfg);
  12736. }
  12737. var _proto = GuideController.prototype;
  12738. _proto._toString = function _toString(position) {
  12739. if (isFunction$1(position)) {
  12740. position = position(this.xScale, this.yScales);
  12741. }
  12742. position = position.toString();
  12743. return position;
  12744. };
  12745. _proto._getId = function _getId(shape, guide) {
  12746. var id = guide.id;
  12747. if (!id) {
  12748. var type = guide.type;
  12749. if (type === 'arc' || type === 'line' || type === 'rect') {
  12750. id = this._toString(guide.start) + '-' + this._toString(guide.end);
  12751. } else {
  12752. id = this._toString(guide.position);
  12753. }
  12754. }
  12755. return id;
  12756. };
  12757. _proto.paint = function paint(coord) {
  12758. var self = this;
  12759. var chart = self.chart,
  12760. guides = self.guides,
  12761. xScale = self.xScale,
  12762. yScales = self.yScales;
  12763. var guideShapes = [];
  12764. each$1(guides, function (guide, idx) {
  12765. guide.xScale = xScale;
  12766. guide.yScales = yScales;
  12767. var container;
  12768. if (guide.type === 'regionFilter') {
  12769. // TODO: RegionFilter support animation
  12770. guide.chart = chart;
  12771. } else {
  12772. container = guide.top ? self.frontPlot : self.backPlot;
  12773. }
  12774. guide.coord = coord;
  12775. guide.container = container;
  12776. guide.canvas = chart.get('canvas');
  12777. var shape = guide.render(coord, container);
  12778. if (shape) {
  12779. var id = self._getId(shape, guide);
  12780. [].concat(shape).forEach(function (s) {
  12781. s._id = s.get('className') + '-' + id;
  12782. s.set('index', idx);
  12783. guideShapes.push(s);
  12784. });
  12785. }
  12786. });
  12787. self.guideShapes = guideShapes;
  12788. };
  12789. _proto.clear = function clear() {
  12790. this.reset();
  12791. this.guides = [];
  12792. return this;
  12793. };
  12794. _proto.reset = function reset() {
  12795. var guides = this.guides;
  12796. each$1(guides, function (guide) {
  12797. guide.remove();
  12798. });
  12799. };
  12800. _proto._createGuide = function _createGuide(type, cfg) {
  12801. var ClassName = upperFirst(type);
  12802. var guide = new GuideBase[ClassName](deepMix({}, Global.guide[type], cfg));
  12803. this.guides.push(guide);
  12804. return guide;
  12805. };
  12806. _proto.line = function line(cfg) {
  12807. if (cfg === void 0) {
  12808. cfg = {};
  12809. }
  12810. return this._createGuide('line', cfg);
  12811. };
  12812. _proto.text = function text(cfg) {
  12813. if (cfg === void 0) {
  12814. cfg = {};
  12815. }
  12816. return this._createGuide('text', cfg);
  12817. };
  12818. _proto.arc = function arc(cfg) {
  12819. if (cfg === void 0) {
  12820. cfg = {};
  12821. }
  12822. return this._createGuide('arc', cfg);
  12823. };
  12824. _proto.html = function html(cfg) {
  12825. if (cfg === void 0) {
  12826. cfg = {};
  12827. }
  12828. return this._createGuide('html', cfg);
  12829. };
  12830. _proto.rect = function rect(cfg) {
  12831. if (cfg === void 0) {
  12832. cfg = {};
  12833. }
  12834. return this._createGuide('rect', cfg);
  12835. };
  12836. _proto.tag = function tag(cfg) {
  12837. if (cfg === void 0) {
  12838. cfg = {};
  12839. }
  12840. return this._createGuide('tag', cfg);
  12841. };
  12842. _proto.point = function point(cfg) {
  12843. if (cfg === void 0) {
  12844. cfg = {};
  12845. }
  12846. return this._createGuide('point', cfg);
  12847. };
  12848. _proto.regionFilter = function regionFilter(cfg) {
  12849. if (cfg === void 0) {
  12850. cfg = {};
  12851. }
  12852. return this._createGuide('regionFilter', cfg);
  12853. };
  12854. return GuideController;
  12855. }();
  12856. function init$1(chart) {
  12857. var guideController = new GuideController({
  12858. frontPlot: chart.get('frontPlot').addGroup({
  12859. zIndex: 20,
  12860. className: 'guideContainer'
  12861. }),
  12862. backPlot: chart.get('backPlot').addGroup({
  12863. className: 'guideContainer'
  12864. })
  12865. });
  12866. chart.set('guideController', guideController);
  12867. /**
  12868. * 为图表添加 guide
  12869. * @return {GuideController} 返回 guide 控制器
  12870. */
  12871. chart.guide = function () {
  12872. return guideController;
  12873. };
  12874. }
  12875. function afterGeomDraw$1(chart) {
  12876. var guideController = chart.get('guideController');
  12877. if (!guideController.guides.length) {
  12878. return;
  12879. }
  12880. var xScale = chart.getXScale();
  12881. var yScales = chart.getYScales();
  12882. var coord = chart.get('coord');
  12883. guideController.xScale = xScale;
  12884. guideController.yScales = yScales;
  12885. guideController.chart = chart; // for regionFilter
  12886. guideController.paint(coord);
  12887. }
  12888. function clear(chart) {
  12889. chart.get('guideController').clear();
  12890. }
  12891. function repaint(chart) {
  12892. chart.get('guideController').reset();
  12893. }
  12894. var guide = {
  12895. init: init$1,
  12896. afterGeomDraw: afterGeomDraw$1,
  12897. clear: clear,
  12898. repaint: repaint
  12899. };
  12900. var Guide = /*#__PURE__*/Object.freeze({
  12901. __proto__: null,
  12902. init: init$1,
  12903. afterGeomDraw: afterGeomDraw$1,
  12904. clear: clear,
  12905. repaint: repaint,
  12906. 'default': guide
  12907. });
  12908. var LEGEND_GAP = 12;
  12909. var MARKER_SIZE = 3;
  12910. var DEFAULT_CFG = {
  12911. itemMarginBottom: 12,
  12912. itemGap: 10,
  12913. showTitle: false,
  12914. titleStyle: {
  12915. fontSize: 12,
  12916. fill: '#808080',
  12917. textAlign: 'start',
  12918. textBaseline: 'top'
  12919. },
  12920. nameStyle: {
  12921. fill: '#808080',
  12922. fontSize: 12,
  12923. textAlign: 'start',
  12924. textBaseline: 'middle'
  12925. },
  12926. valueStyle: {
  12927. fill: '#000000',
  12928. fontSize: 12,
  12929. textAlign: 'start',
  12930. textBaseline: 'middle'
  12931. },
  12932. unCheckStyle: {
  12933. fill: '#bfbfbf'
  12934. },
  12935. itemWidth: 'auto',
  12936. wordSpace: 6,
  12937. selectedMode: 'multiple' // 'multiple' or 'single'
  12938. }; // Register the default configuration for Legend
  12939. Global.legend = deepMix({
  12940. common: DEFAULT_CFG,
  12941. // common legend configuration
  12942. right: mix$1({
  12943. position: 'right',
  12944. layout: 'vertical'
  12945. }, DEFAULT_CFG),
  12946. left: mix$1({
  12947. position: 'left',
  12948. layout: 'vertical'
  12949. }, DEFAULT_CFG),
  12950. top: mix$1({
  12951. position: 'top',
  12952. layout: 'horizontal'
  12953. }, DEFAULT_CFG),
  12954. bottom: mix$1({
  12955. position: 'bottom',
  12956. layout: 'horizontal'
  12957. }, DEFAULT_CFG)
  12958. }, Global.legend || {});
  12959. function getPaddingByPos(pos, appendPadding) {
  12960. var padding = 0;
  12961. appendPadding = parsePadding(appendPadding);
  12962. switch (pos) {
  12963. case 'top':
  12964. padding = appendPadding[0];
  12965. break;
  12966. case 'right':
  12967. padding = appendPadding[1];
  12968. break;
  12969. case 'bottom':
  12970. padding = appendPadding[2];
  12971. break;
  12972. case 'left':
  12973. padding = appendPadding[3];
  12974. break;
  12975. }
  12976. return padding;
  12977. }
  12978. var LegendController = /*#__PURE__*/function () {
  12979. function LegendController(cfg) {
  12980. var _this = this;
  12981. _defineProperty(this, "handleEvent", function (ev) {
  12982. var self = _this;
  12983. function findItem(x, y) {
  12984. var result = null;
  12985. var legends = self.legends;
  12986. each$1(legends, function (legendItems) {
  12987. each$1(legendItems, function (legend) {
  12988. var itemsGroup = legend.itemsGroup,
  12989. legendHitBoxes = legend.legendHitBoxes;
  12990. var children = itemsGroup.get('children');
  12991. if (children.length) {
  12992. var legendPosX = legend.x;
  12993. var legendPosY = legend.y;
  12994. each$1(legendHitBoxes, function (box, index) {
  12995. if (x >= box.x + legendPosX && x <= box.x + box.width + legendPosX && y >= box.y + legendPosY && y <= box.height + box.y + legendPosY) {
  12996. // inbox
  12997. result = {
  12998. clickedItem: children[index],
  12999. clickedLegend: legend
  13000. };
  13001. return false;
  13002. }
  13003. });
  13004. }
  13005. });
  13006. });
  13007. return result;
  13008. }
  13009. var chart = self.chart;
  13010. var _createEvent = createEvent(ev, chart),
  13011. x = _createEvent.x,
  13012. y = _createEvent.y;
  13013. var clicked = findItem(x, y);
  13014. if (clicked && clicked.clickedLegend.clickable !== false) {
  13015. var clickedItem = clicked.clickedItem,
  13016. clickedLegend = clicked.clickedLegend;
  13017. if (clickedLegend.onClick) {
  13018. ev.clickedItem = clickedItem;
  13019. clickedLegend.onClick(ev);
  13020. } else if (!clickedLegend.custom) {
  13021. var checked = clickedItem.get('checked');
  13022. var value = clickedItem.get('dataValue');
  13023. var filteredVals = clickedLegend.filteredVals,
  13024. field = clickedLegend.field,
  13025. selectedMode = clickedLegend.selectedMode;
  13026. var isSingeSelected = selectedMode === 'single';
  13027. if (isSingeSelected) {
  13028. chart.filter(field, function (val) {
  13029. return val === value;
  13030. });
  13031. } else {
  13032. if (checked) {
  13033. filteredVals.push(value);
  13034. } else {
  13035. remove(filteredVals, value);
  13036. }
  13037. chart.filter(field, function (val) {
  13038. return filteredVals.indexOf(val) === -1;
  13039. });
  13040. }
  13041. chart.repaint();
  13042. }
  13043. }
  13044. });
  13045. this.legendCfg = {};
  13046. this.enable = true;
  13047. this.position = 'top';
  13048. mix$1(this, cfg);
  13049. var _chart = this.chart;
  13050. this.canvasDom = _chart.get('canvas').get('el');
  13051. this.clear();
  13052. }
  13053. var _proto = LegendController.prototype;
  13054. _proto.addLegend = function addLegend(scale, items, filteredVals) {
  13055. var self = this;
  13056. var legendCfg = self.legendCfg;
  13057. var field = scale.field;
  13058. var fieldCfg = legendCfg[field];
  13059. if (fieldCfg === false) {
  13060. return null;
  13061. }
  13062. if (fieldCfg && fieldCfg.custom) {
  13063. self.addCustomLegend(field);
  13064. } else {
  13065. var position = legendCfg.position || self.position;
  13066. if (fieldCfg && fieldCfg.position) {
  13067. position = fieldCfg.position;
  13068. }
  13069. if (scale.isCategory) {
  13070. self._addCategoryLegend(scale, items, position, filteredVals);
  13071. }
  13072. }
  13073. };
  13074. _proto.addCustomLegend = function addCustomLegend(field) {
  13075. var self = this;
  13076. var legendCfg = self.legendCfg;
  13077. if (field && legendCfg[field]) {
  13078. legendCfg = legendCfg[field];
  13079. }
  13080. var position = legendCfg.position || self.position;
  13081. var legends = self.legends;
  13082. legends[position] = legends[position] || [];
  13083. var items = legendCfg.items;
  13084. if (!items) {
  13085. return null;
  13086. }
  13087. var container = self.container;
  13088. each$1(items, function (item) {
  13089. if (!isPlainObject(item.marker)) {
  13090. item.marker = {
  13091. symbol: item.marker || 'circle',
  13092. fill: item.fill,
  13093. radius: MARKER_SIZE
  13094. };
  13095. } else {
  13096. item.marker.radius = item.marker.radius || MARKER_SIZE;
  13097. }
  13098. item.checked = isNil$1(item.checked) ? true : item.checked;
  13099. item.name = item.name || item.value;
  13100. });
  13101. var legend = new List(deepMix({}, Global.legend[position], legendCfg, {
  13102. maxLength: self._getMaxLength(position),
  13103. items: items,
  13104. parent: container
  13105. }));
  13106. legends[position].push(legend);
  13107. };
  13108. _proto.clear = function clear() {
  13109. var legends = this.legends;
  13110. each$1(legends, function (legendItems) {
  13111. each$1(legendItems, function (legend) {
  13112. legend.clear();
  13113. });
  13114. });
  13115. this.legends = {};
  13116. this.unBindEvents();
  13117. };
  13118. _proto._isFiltered = function _isFiltered(scale, values, value) {
  13119. var rst = false;
  13120. each$1(values, function (val) {
  13121. rst = rst || scale.getText(val) === scale.getText(value);
  13122. if (rst) {
  13123. return false;
  13124. }
  13125. });
  13126. return rst;
  13127. };
  13128. _proto._getMaxLength = function _getMaxLength(position) {
  13129. var chart = this.chart;
  13130. var appendPadding = parsePadding(chart.get('appendPadding'));
  13131. return position === 'right' || position === 'left' ? chart.get('height') - (appendPadding[0] + appendPadding[2]) : chart.get('width') - (appendPadding[1] + appendPadding[3]);
  13132. };
  13133. _proto._addCategoryLegend = function _addCategoryLegend(scale, items, position, filteredVals) {
  13134. var self = this;
  13135. var legendCfg = self.legendCfg,
  13136. legends = self.legends,
  13137. container = self.container,
  13138. chart = self.chart;
  13139. var field = scale.field;
  13140. legends[position] = legends[position] || [];
  13141. var symbol = 'circle';
  13142. if (legendCfg[field] && legendCfg[field].marker) {
  13143. symbol = legendCfg[field].marker;
  13144. } else if (legendCfg.marker) {
  13145. symbol = legendCfg.marker;
  13146. }
  13147. each$1(items, function (item) {
  13148. if (isPlainObject(symbol)) {
  13149. mix$1(item.marker, symbol);
  13150. } else {
  13151. item.marker.symbol = symbol;
  13152. }
  13153. if (filteredVals) {
  13154. item.checked = !self._isFiltered(scale, filteredVals, item.dataValue);
  13155. }
  13156. });
  13157. var legendItems = chart.get('legendItems');
  13158. legendItems[field] = items;
  13159. var lastCfg = deepMix({}, Global.legend[position], legendCfg[field] || legendCfg, {
  13160. maxLength: self._getMaxLength(position),
  13161. items: items,
  13162. field: field,
  13163. filteredVals: filteredVals,
  13164. parent: container
  13165. });
  13166. if (lastCfg.showTitle) {
  13167. deepMix(lastCfg, {
  13168. title: scale.alias || scale.field
  13169. });
  13170. }
  13171. var legend = new List(lastCfg);
  13172. legends[position].push(legend);
  13173. return legend;
  13174. };
  13175. _proto._alignLegend = function _alignLegend(legend, pre, position) {
  13176. var self = this;
  13177. var _self$plotRange = self.plotRange,
  13178. tl = _self$plotRange.tl,
  13179. bl = _self$plotRange.bl;
  13180. var chart = self.chart;
  13181. var offsetX = legend.offsetX || 0;
  13182. var offsetY = legend.offsetY || 0;
  13183. var chartWidth = chart.get('width');
  13184. var chartHeight = chart.get('height');
  13185. var appendPadding = parsePadding(chart.get('appendPadding'));
  13186. var legendHeight = legend.getHeight();
  13187. var legendWidth = legend.getWidth();
  13188. var x = 0;
  13189. var y = 0;
  13190. if (position === 'left' || position === 'right') {
  13191. var verticalAlign = legend.verticalAlign || 'middle';
  13192. var height = Math.abs(tl.y - bl.y);
  13193. x = position === 'left' ? appendPadding[3] : chartWidth - legendWidth - appendPadding[1];
  13194. y = (height - legendHeight) / 2 + tl.y;
  13195. if (verticalAlign === 'top') {
  13196. y = tl.y;
  13197. } else if (verticalAlign === 'bottom') {
  13198. y = bl.y - legendHeight;
  13199. }
  13200. if (pre) {
  13201. y = pre.get('y') - legendHeight - LEGEND_GAP;
  13202. }
  13203. } else {
  13204. var align = legend.align || 'left';
  13205. x = appendPadding[3];
  13206. if (align === 'center') {
  13207. x = chartWidth / 2 - legendWidth / 2;
  13208. } else if (align === 'right') {
  13209. x = chartWidth - (legendWidth + appendPadding[1]);
  13210. }
  13211. y = position === 'top' ? appendPadding[0] + Math.abs(legend.container.getBBox().minY) : chartHeight - legendHeight;
  13212. if (pre) {
  13213. var preWidth = pre.getWidth();
  13214. x = pre.x + preWidth + LEGEND_GAP;
  13215. }
  13216. }
  13217. if (position === 'bottom' && offsetY > 0) {
  13218. offsetY = 0;
  13219. }
  13220. if (position === 'right' && offsetX > 0) {
  13221. offsetX = 0;
  13222. }
  13223. legend.moveTo(x + offsetX, y + offsetY);
  13224. };
  13225. _proto.alignLegends = function alignLegends() {
  13226. var self = this;
  13227. var legends = self.legends;
  13228. each$1(legends, function (legendItems, position) {
  13229. each$1(legendItems, function (legend, index) {
  13230. var pre = legendItems[index - 1];
  13231. self._alignLegend(legend, pre, position);
  13232. });
  13233. });
  13234. return self;
  13235. };
  13236. _proto.bindEvents = function bindEvents() {
  13237. var legendCfg = this.legendCfg;
  13238. var triggerOn = legendCfg.triggerOn || 'touchstart';
  13239. addEventListener(this.canvasDom, triggerOn, this.handleEvent);
  13240. };
  13241. _proto.unBindEvents = function unBindEvents() {
  13242. var legendCfg = this.legendCfg;
  13243. var triggerOn = legendCfg.triggerOn || 'touchstart';
  13244. removeEventListener(this.canvasDom, triggerOn, this.handleEvent);
  13245. };
  13246. return LegendController;
  13247. }();
  13248. function init(chart) {
  13249. var legendController = new LegendController({
  13250. container: chart.get('backPlot').addGroup(),
  13251. plotRange: chart.get('plotRange'),
  13252. chart: chart
  13253. });
  13254. chart.set('legendController', legendController);
  13255. chart.legend = function (field, cfg) {
  13256. var legendCfg = legendController.legendCfg;
  13257. legendController.enable = true;
  13258. if (isBoolean(field)) {
  13259. legendController.enable = field;
  13260. legendCfg = cfg || {};
  13261. } else if (isObject$1(field)) {
  13262. legendCfg = field;
  13263. } else {
  13264. legendCfg[field] = cfg;
  13265. }
  13266. legendController.legendCfg = legendCfg;
  13267. return this;
  13268. };
  13269. }
  13270. function beforeGeomDraw(chart) {
  13271. var legendController = chart.get('legendController');
  13272. if (!legendController.enable) return null; // legend is not displayed
  13273. var legendCfg = legendController.legendCfg,
  13274. container = legendController.container;
  13275. if (legendCfg && legendCfg.custom) {
  13276. legendController.addCustomLegend();
  13277. } else {
  13278. var legendItems = chart.getLegendItems();
  13279. var scales = chart.get('scales');
  13280. var filters = chart.get('filters');
  13281. each$1(legendItems, function (items, field) {
  13282. var scale = scales[field];
  13283. var values = scale.values;
  13284. var filteredVals;
  13285. if (filters && filters[field]) {
  13286. filteredVals = values.filter(function (v) {
  13287. return !filters[field](v);
  13288. });
  13289. } else {
  13290. filteredVals = [];
  13291. }
  13292. legendController.addLegend(scale, items, filteredVals);
  13293. });
  13294. }
  13295. if (legendCfg && legendCfg.clickable !== false) {
  13296. legendController.bindEvents();
  13297. }
  13298. var legends = legendController.legends;
  13299. var legendRange = {
  13300. top: 0,
  13301. right: 0,
  13302. bottom: 0,
  13303. left: 0
  13304. };
  13305. each$1(legends, function (legendItems, position) {
  13306. var padding = 0;
  13307. each$1(legendItems, function (legend) {
  13308. var width = legend.getWidth();
  13309. var height = legend.getHeight();
  13310. if (position === 'top' || position === 'bottom') {
  13311. padding = Math.max(padding, height);
  13312. if (legend.offsetY > 0) {
  13313. padding += legend.offsetY;
  13314. }
  13315. } else {
  13316. padding = Math.max(padding, width);
  13317. if (legend.offsetX > 0) {
  13318. padding += legend.offsetX;
  13319. }
  13320. }
  13321. });
  13322. legendRange[position] = padding + getPaddingByPos(position, chart.get('appendPadding'));
  13323. });
  13324. chart.set('legendRange', legendRange);
  13325. if (Object.keys(legends).length) {
  13326. container.set('ariaLabel', lang.legend.prefix);
  13327. } else {
  13328. container.set('ariaLabel', null);
  13329. }
  13330. }
  13331. function afterGeomDraw(chart) {
  13332. var legendController = chart.get('legendController');
  13333. legendController.alignLegends();
  13334. }
  13335. function clearInner(chart) {
  13336. var legendController = chart.get('legendController');
  13337. legendController.clear();
  13338. chart.set('legendRange', null);
  13339. }
  13340. var legend = {
  13341. init: init,
  13342. beforeGeomDraw: beforeGeomDraw,
  13343. afterGeomDraw: afterGeomDraw,
  13344. clearInner: clearInner
  13345. };
  13346. var Legend = /*#__PURE__*/Object.freeze({
  13347. __proto__: null,
  13348. init: init,
  13349. beforeGeomDraw: beforeGeomDraw,
  13350. afterGeomDraw: afterGeomDraw,
  13351. clearInner: clearInner,
  13352. 'default': legend
  13353. });
  13354. var clock = typeof performance === 'object' && performance.now ? performance : Date;
  13355. var Timeline = /*#__PURE__*/function () {
  13356. function Timeline() {
  13357. this.anims = [];
  13358. this.time = null;
  13359. this.playing = false;
  13360. this.canvas = [];
  13361. }
  13362. var _proto = Timeline.prototype;
  13363. _proto.play = function play() {
  13364. var self = this;
  13365. self.time = clock.now();
  13366. self.playing = true;
  13367. function step() {
  13368. if (self.playing) {
  13369. requestAnimationFrame(step);
  13370. self.update();
  13371. }
  13372. }
  13373. requestAnimationFrame(step);
  13374. };
  13375. _proto.stop = function stop() {
  13376. this.playing = false;
  13377. this.time = null;
  13378. this.canvas = [];
  13379. };
  13380. _proto.pushAnim = function pushAnim(animInfo) {
  13381. // 先启动动画
  13382. if (!this.playing) {
  13383. this.play();
  13384. }
  13385. var delay = animInfo.delay,
  13386. duration = animInfo.duration;
  13387. var startTime = this.time + delay;
  13388. var endTime = startTime + duration;
  13389. animInfo.startTime = startTime;
  13390. animInfo.endTime = endTime;
  13391. this.anims.push(animInfo);
  13392. };
  13393. _proto.update = function update() {
  13394. var currentTime = clock.now();
  13395. this.canvas = [];
  13396. if (!this.anims.length) {
  13397. this.stop();
  13398. return;
  13399. }
  13400. for (var i = 0; i < this.anims.length; i++) {
  13401. var propertyAnim = this.anims[i];
  13402. if (currentTime < propertyAnim.startTime || propertyAnim.hasEnded) {
  13403. continue;
  13404. }
  13405. var shape = propertyAnim.shape; // shape
  13406. if (shape.get('destroyed')) {
  13407. this.anims.splice(i, 1);
  13408. i--;
  13409. continue;
  13410. }
  13411. var startState = propertyAnim.startState,
  13412. endState = propertyAnim.endState,
  13413. interpolate = propertyAnim.interpolate,
  13414. duration = propertyAnim.duration;
  13415. if (currentTime >= propertyAnim.startTime && !propertyAnim.hasStarted) {
  13416. propertyAnim.hasStarted = true;
  13417. if (propertyAnim.onStart) {
  13418. propertyAnim.onStart();
  13419. }
  13420. }
  13421. var t = (currentTime - propertyAnim.startTime) / duration;
  13422. t = Math.max(0, Math.min(t, 1));
  13423. t = propertyAnim.easing(t);
  13424. if (propertyAnim.onFrame) {
  13425. propertyAnim.onFrame(t);
  13426. } else {
  13427. for (var key in interpolate) {
  13428. var diff = interpolate[key];
  13429. var value = diff(t);
  13430. var newValue = void 0;
  13431. if (key === 'points') {
  13432. newValue = [];
  13433. var aLen = Math.max(startState.points.length, endState.points.length);
  13434. for (var j = 0; j < aLen; j += 2) {
  13435. newValue.push({
  13436. x: value[j],
  13437. y: value[j + 1]
  13438. });
  13439. }
  13440. } else {
  13441. newValue = value;
  13442. }
  13443. shape._attrs.attrs[key] = newValue;
  13444. shape._attrs.bbox = null; // should clear calculated bbox
  13445. }
  13446. }
  13447. var canvas = shape.get('canvas');
  13448. if (this.canvas.indexOf(canvas) === -1) {
  13449. this.canvas.push(canvas);
  13450. }
  13451. if (propertyAnim.onUpdate) {
  13452. propertyAnim.onUpdate(t);
  13453. }
  13454. if (currentTime >= propertyAnim.endTime && !propertyAnim.hasEnded) {
  13455. propertyAnim.hasEnded = true;
  13456. if (propertyAnim.onEnd) {
  13457. propertyAnim.onEnd();
  13458. }
  13459. }
  13460. if (t === 1) {
  13461. // end
  13462. this.anims.splice(i, 1);
  13463. i--;
  13464. }
  13465. }
  13466. this.canvas.map(function (c) {
  13467. c.draw();
  13468. return c;
  13469. });
  13470. this.time = clock.now();
  13471. };
  13472. return Timeline;
  13473. }();
  13474. function linear(k) {
  13475. return k;
  13476. }
  13477. function quadraticIn(k) {
  13478. return k * k;
  13479. }
  13480. function quadraticOut(k) {
  13481. return k * (2 - k);
  13482. }
  13483. function quadraticInOut(k) {
  13484. if ((k *= 2) < 1) {
  13485. return 0.5 * k * k;
  13486. }
  13487. return -0.5 * (--k * (k - 2) - 1);
  13488. }
  13489. function cubicIn(k) {
  13490. return k * k * k;
  13491. }
  13492. function cubicOut(k) {
  13493. return --k * k * k + 1;
  13494. }
  13495. function cubicInOut(k) {
  13496. if ((k *= 2) < 1) {
  13497. return 0.5 * k * k * k;
  13498. }
  13499. return 0.5 * ((k -= 2) * k * k + 2);
  13500. }
  13501. function elasticIn(k) {
  13502. var s;
  13503. var a = 0.1;
  13504. var p = 0.4;
  13505. if (k === 0) return 0;
  13506. if (k === 1) return 1;
  13507. if (!a || a < 1) {
  13508. a = 1;
  13509. s = p / 4;
  13510. } else {
  13511. s = p / (2 * Math.PI) * Math.asin(1 / a);
  13512. }
  13513. return -(a * Math.pow(2, 10 * (k -= 1)) * Math.sin((k - s) * (2 * Math.PI) / p));
  13514. }
  13515. function elasticOut(k) {
  13516. var s;
  13517. var a = 0.1;
  13518. var p = 0.4;
  13519. if (k === 0) return 0;
  13520. if (k === 1) return 1;
  13521. if (!a || a < 1) {
  13522. a = 1;
  13523. s = p / 4;
  13524. } else {
  13525. s = p / (2 * Math.PI) * Math.asin(1 / a);
  13526. }
  13527. return a * Math.pow(2, -10 * k) * Math.sin((k - s) * (2 * Math.PI) / p) + 1;
  13528. }
  13529. function elasticInOut(k) {
  13530. var s;
  13531. var a = 0.1;
  13532. var p = 0.4;
  13533. if (k === 0) return 0;
  13534. if (k === 1) return 1;
  13535. if (!a || a < 1) {
  13536. a = 1;
  13537. s = p / 4;
  13538. } else {
  13539. s = p / (2 * Math.PI) * Math.asin(1 / a);
  13540. }
  13541. if ((k *= 2) < 1) {
  13542. return -0.5 * (a * Math.pow(2, 10 * (k -= 1)) * Math.sin((k - s) * (2 * Math.PI) / p));
  13543. }
  13544. return a * Math.pow(2, -10 * (k -= 1)) * Math.sin((k - s) * (2 * Math.PI) / p) * 0.5 + 1;
  13545. }
  13546. function backIn(k) {
  13547. var s = 1.70158;
  13548. return k * k * ((s + 1) * k - s);
  13549. }
  13550. function backOut(k) {
  13551. var s = 1.70158;
  13552. return (k = k - 1) * k * ((s + 1) * k + s) + 1;
  13553. }
  13554. function backInOut(k) {
  13555. var s = 1.70158 * 1.525;
  13556. if ((k *= 2) < 1) {
  13557. return 0.5 * (k * k * ((s + 1) * k - s));
  13558. }
  13559. return 0.5 * ((k -= 2) * k * ((s + 1) * k + s) + 2);
  13560. }
  13561. function bounceIn(k) {
  13562. return 1 - bounceOut(1 - k);
  13563. }
  13564. function bounceOut(k) {
  13565. if ((k /= 1) < 1 / 2.75) {
  13566. return 7.5625 * k * k;
  13567. } else if (k < 2 / 2.75) {
  13568. return 7.5625 * (k -= 1.5 / 2.75) * k + 0.75;
  13569. } else if (k < 2.5 / 2.75) {
  13570. return 7.5625 * (k -= 2.25 / 2.75) * k + 0.9375;
  13571. }
  13572. return 7.5625 * (k -= 2.625 / 2.75) * k + 0.984375;
  13573. }
  13574. function bounceInOut(k) {
  13575. if (k < 0.5) {
  13576. return bounceIn(k * 2) * 0.5;
  13577. }
  13578. return bounceOut(k * 2 - 1) * 0.5 + 0.5;
  13579. }
  13580. var Easing = /*#__PURE__*/Object.freeze({
  13581. __proto__: null,
  13582. linear: linear,
  13583. quadraticIn: quadraticIn,
  13584. quadraticOut: quadraticOut,
  13585. quadraticInOut: quadraticInOut,
  13586. cubicIn: cubicIn,
  13587. cubicOut: cubicOut,
  13588. cubicInOut: cubicInOut,
  13589. elasticIn: elasticIn,
  13590. elasticOut: elasticOut,
  13591. elasticInOut: elasticInOut,
  13592. backIn: backIn,
  13593. backOut: backOut,
  13594. backInOut: backInOut,
  13595. bounceIn: bounceIn,
  13596. bounceOut: bounceOut,
  13597. bounceInOut: bounceInOut
  13598. });
  13599. function plainArray(arr) {
  13600. var result = [];
  13601. for (var i = 0, len = arr.length; i < len; i++) {
  13602. if (arr[i]) {
  13603. result.push(arr[i].x);
  13604. result.push(arr[i].y);
  13605. }
  13606. }
  13607. return result;
  13608. }
  13609. function interpolateNumber(a, b) {
  13610. a = +a;
  13611. b -= a;
  13612. return function (t) {
  13613. return a + b * t;
  13614. };
  13615. }
  13616. function interpolateArray(a, b) {
  13617. var nb = b ? b.length : 0;
  13618. var na = a ? Math.min(nb, a.length) : 0;
  13619. var x = new Array(na);
  13620. var c = new Array(nb);
  13621. var i;
  13622. for (i = 0; i < na; ++i) {
  13623. x[i] = interpolateNumber(a[i], b[i]);
  13624. }
  13625. for (; i < nb; ++i) {
  13626. c[i] = b[i];
  13627. }
  13628. return function (t) {
  13629. for (i = 0; i < na; ++i) {
  13630. c[i] = x[i](t);
  13631. }
  13632. return c;
  13633. };
  13634. }
  13635. var Animator = /*#__PURE__*/function () {
  13636. function Animator(shape, source, timeline) {
  13637. this.hasStarted = false;
  13638. this.hasEnded = false;
  13639. this.shape = shape;
  13640. this.source = source;
  13641. this.timeline = timeline;
  13642. this.animate = null;
  13643. } // delay, attrs, duration, easing
  13644. var _proto = Animator.prototype;
  13645. _proto.to = function to(cfg) {
  13646. if (cfg === void 0) {
  13647. cfg = {};
  13648. }
  13649. var delay = cfg.delay || 0;
  13650. var attrs = cfg.attrs || {};
  13651. var duration = cfg.duration || 1000;
  13652. var easing; // 缓动函数
  13653. if (typeof cfg.easing === 'function') {
  13654. easing = cfg.easing;
  13655. } else {
  13656. easing = Easing[cfg.easing] || linear;
  13657. }
  13658. var animInfo = {
  13659. shape: this.shape,
  13660. delay: delay,
  13661. duration: duration,
  13662. easing: easing
  13663. };
  13664. var interpolate = {}; // 差值函数
  13665. for (var attrName in attrs) {
  13666. var startValue = this.source[attrName];
  13667. var endValue = attrs[attrName];
  13668. if (attrName === 'points') {
  13669. startValue = plainArray(startValue);
  13670. endValue = plainArray(endValue);
  13671. interpolate.points = interpolateArray(startValue, endValue);
  13672. this.source.points = startValue;
  13673. attrs.points = endValue;
  13674. } else if (attrName === 'matrix') {
  13675. interpolate.matrix = interpolateArray(startValue, endValue);
  13676. } else {
  13677. interpolate[attrName] = interpolateNumber(startValue, endValue);
  13678. }
  13679. }
  13680. animInfo.interpolate = interpolate;
  13681. animInfo.startState = this.source;
  13682. animInfo.endState = attrs;
  13683. this.timeline.pushAnim(animInfo);
  13684. this.animate = animInfo;
  13685. return this;
  13686. };
  13687. _proto.onFrame = function onFrame(callback) {
  13688. // 自定义每一帧动画的动作
  13689. if (this.animate) {
  13690. this.animate.onFrame = function (frame) {
  13691. callback(frame);
  13692. };
  13693. }
  13694. return this;
  13695. };
  13696. _proto.onStart = function onStart(callback) {
  13697. if (this.animate) {
  13698. this.animate.onStart = function () {
  13699. callback();
  13700. };
  13701. }
  13702. return this;
  13703. };
  13704. _proto.onUpdate = function onUpdate(callback) {
  13705. if (this.animate) {
  13706. this.animate.onUpdate = function (frame) {
  13707. callback(frame);
  13708. };
  13709. }
  13710. return this;
  13711. };
  13712. _proto.onEnd = function onEnd(callback) {
  13713. if (this.animate) {
  13714. this.animate.onEnd = function () {
  13715. callback();
  13716. };
  13717. }
  13718. return this;
  13719. };
  13720. return Animator;
  13721. }();
  13722. var defaultAnimationCfg = {
  13723. appear: {
  13724. duration: 450,
  13725. easing: 'quadraticOut'
  13726. },
  13727. // 'appear' animation options
  13728. update: {
  13729. duration: 300,
  13730. easing: 'quadraticOut'
  13731. },
  13732. // 'update' animation options
  13733. enter: {
  13734. duration: 300,
  13735. easing: 'quadraticOut'
  13736. },
  13737. // 'enter' animation options
  13738. leave: {
  13739. duration: 350,
  13740. easing: 'quadraticIn'
  13741. } // 'leave' animation options
  13742. };
  13743. var Animate = {
  13744. defaultCfg: {},
  13745. Action: {},
  13746. getAnimation: function getAnimation(geomType, coord, animationType) {
  13747. var geomAnimateCfg = this.defaultCfg[geomType];
  13748. if (geomAnimateCfg) {
  13749. var animation = geomAnimateCfg[animationType];
  13750. if (isFunction$1(animation)) {
  13751. return animation(coord);
  13752. }
  13753. }
  13754. return false;
  13755. },
  13756. getAnimateCfg: function getAnimateCfg(geomType, animationType) {
  13757. var defaultCfg = defaultAnimationCfg[animationType];
  13758. var geomConfig = this.defaultCfg[geomType];
  13759. if (geomConfig && geomConfig.cfg && geomConfig.cfg[animationType]) {
  13760. return deepMix({}, defaultCfg, geomConfig.cfg[animationType]);
  13761. }
  13762. return defaultCfg;
  13763. },
  13764. registerAnimation: function registerAnimation(animationName, animationFun) {
  13765. var _extends2;
  13766. if (!this.Action) {
  13767. this.Action = {};
  13768. }
  13769. this.Action = _extends({}, this.Action, (_extends2 = {}, _extends2[animationName] = animationFun, _extends2));
  13770. }
  13771. };
  13772. /**
  13773. * Utility
  13774. * @author sima.zhang1990@gmail.com
  13775. */
  13776. function getCoordInfo(coord) {
  13777. var start = coord.start;
  13778. var end = coord.end;
  13779. return {
  13780. start: start,
  13781. end: end,
  13782. width: end.x - start.x,
  13783. height: Math.abs(end.y - start.y)
  13784. };
  13785. }
  13786. function getScaledMatrix(shape, v, direct) {
  13787. var scaledMatrix;
  13788. shape.apply(v);
  13789. var x = v[0];
  13790. var y = v[1];
  13791. if (direct === 'x') {
  13792. shape.transform([['t', x, y], ['s', 0.01, 1], ['t', -x, -y]]);
  13793. var matrix = shape.getMatrix();
  13794. scaledMatrix = Matrix.transform(matrix, [['t', x, y], ['s', 100, 1], ['t', -x, -y]]);
  13795. } else if (direct === 'y') {
  13796. shape.transform([['t', x, y], ['s', 1, 0.01], ['t', -x, -y]]);
  13797. var _matrix = shape.getMatrix();
  13798. scaledMatrix = Matrix.transform(_matrix, [['t', x, y], ['s', 1, 100], ['t', -x, -y]]);
  13799. } else if (direct === 'xy') {
  13800. shape.transform([['t', x, y], ['s', 0.01, 0.01], ['t', -x, -y]]);
  13801. var _matrix2 = shape.getMatrix();
  13802. scaledMatrix = Matrix.transform(_matrix2, [['t', x, y], ['s', 100, 100], ['t', -x, -y]]);
  13803. }
  13804. return scaledMatrix;
  13805. }
  13806. function getAnimateParam(animateCfg, index, id) {
  13807. var result = {};
  13808. if (animateCfg.delay) {
  13809. result.delay = isFunction$1(animateCfg.delay) ? animateCfg.delay(index, id) : animateCfg.delay;
  13810. }
  13811. result.easing = animateCfg.easing;
  13812. result.duration = animateCfg.duration;
  13813. result.delay = animateCfg.delay;
  13814. return result;
  13815. }
  13816. function doAnimation(shape, endState, animateCfg, callback) {
  13817. var id = shape._id;
  13818. var index = shape.get('index');
  13819. var _getAnimateParam = getAnimateParam(animateCfg, index, id),
  13820. easing = _getAnimateParam.easing,
  13821. delay = _getAnimateParam.delay,
  13822. duration = _getAnimateParam.duration;
  13823. var anim = shape.animate().to({
  13824. attrs: endState,
  13825. duration: duration,
  13826. delay: delay,
  13827. easing: easing
  13828. });
  13829. if (callback) {
  13830. anim.onEnd(function () {
  13831. callback();
  13832. });
  13833. }
  13834. }
  13835. /**
  13836. * Animation functions for shape
  13837. * @author sima.zhang1990@gmail.com
  13838. */
  13839. /*
  13840. function waveIn(shape, animateCfg, coord) {
  13841. const clip = Helpers.getClip(coord);
  13842. clip.set('canvas', shape.get('canvas'));
  13843. shape.attr('clip', clip);
  13844. const onEnd = function() {
  13845. shape.attr('clip', null);
  13846. clip.remove(true);
  13847. };
  13848. Helpers.doAnimation(clip, clip.endState, animateCfg, onEnd);
  13849. }
  13850. function scaleInX(shape, animateCfg) {
  13851. const box = shape.getBBox();
  13852. const points = shape.get('origin').points;
  13853. let x;
  13854. const y = (box.minY + box.maxY) / 2;
  13855. if (points[0].y - points[1].y > 0) { // 当顶点在零点之下
  13856. x = box.maxX;
  13857. } else {
  13858. x = box.minX;
  13859. }
  13860. const scaledMatrix = Helpers.getScaledMatrix(shape, [ x, y ], 'x');
  13861. Helpers.doAnimation(shape, { matrix: scaledMatrix }, animateCfg);
  13862. }
  13863. function scaleInY(shape, animateCfg) {
  13864. const box = shape.getBBox();
  13865. const points = shape.get('origin').points;
  13866. const x = (box.minX + box.maxX) / 2;
  13867. let y;
  13868. if (points[0].y - points[1].y <= 0) { // 当顶点在零点之下
  13869. y = box.maxY;
  13870. } else {
  13871. y = box.minY;
  13872. }
  13873. const scaledMatrix = Helpers.getScaledMatrix(shape, [ x, y ], 'x');
  13874. Helpers.doAnimation(shape, { matrix: scaledMatrix }, animateCfg);
  13875. }
  13876. */
  13877. function fadeIn(shape, animateCfg) {
  13878. var fillOpacity = isNil$1(shape.attr('fillOpacity')) ? 1 : shape.attr('fillOpacity');
  13879. var strokeOpacity = isNil$1(shape.attr('strokeOpacity')) ? 1 : shape.attr('strokeOpacity');
  13880. shape.attr('fillOpacity', 0);
  13881. shape.attr('strokeOpacity', 0);
  13882. var endState = {
  13883. fillOpacity: fillOpacity,
  13884. strokeOpacity: strokeOpacity
  13885. };
  13886. doAnimation(shape, endState, animateCfg);
  13887. }
  13888. var ShapeAction = /*#__PURE__*/Object.freeze({
  13889. __proto__: null,
  13890. fadeIn: fadeIn
  13891. });
  13892. /**
  13893. * Group animate functions
  13894. * @author sima.zhang1990@gmail.com
  13895. */
  13896. function _groupScaleIn(container, animateCfg, coord, zeroY, type) {
  13897. var _getCoordInfo = getCoordInfo(coord),
  13898. start = _getCoordInfo.start,
  13899. end = _getCoordInfo.end,
  13900. width = _getCoordInfo.width,
  13901. height = _getCoordInfo.height;
  13902. var x;
  13903. var y;
  13904. var clip = new Shape.Rect({
  13905. attrs: {
  13906. x: start.x,
  13907. y: end.y,
  13908. width: width,
  13909. height: height
  13910. }
  13911. });
  13912. if (type === 'y') {
  13913. x = start.x + width / 2;
  13914. y = zeroY.y < start.y ? zeroY.y : start.y;
  13915. } else if (type === 'x') {
  13916. x = zeroY.x > start.x ? zeroY.x : start.x;
  13917. y = start.y + height / 2;
  13918. } else if (type === 'xy') {
  13919. if (coord.isPolar) {
  13920. x = coord.center.x;
  13921. y = coord.center.y;
  13922. } else {
  13923. x = (start.x + end.x) / 2;
  13924. y = (start.y + end.y) / 2;
  13925. }
  13926. }
  13927. var endMatrix = getScaledMatrix(clip, [x, y], type);
  13928. clip.isClip = true;
  13929. clip.endState = {
  13930. matrix: endMatrix
  13931. };
  13932. clip.set('canvas', container.get('canvas'));
  13933. container.attr('clip', clip);
  13934. var onEnd = function onEnd() {
  13935. container.attr('clip', null);
  13936. clip.remove(true);
  13937. };
  13938. doAnimation(clip, clip.endState, animateCfg, onEnd);
  13939. }
  13940. function _shapeScale(container, animateCfg, type) {
  13941. var shapes = container.get('children');
  13942. var x;
  13943. var y;
  13944. var endMatrix;
  13945. for (var i = 0, len = shapes.length; i < len; i++) {
  13946. var shape = shapes[i];
  13947. var box = shape.getBBox();
  13948. x = (box.minX + box.maxX) / 2;
  13949. y = (box.minY + box.maxY) / 2;
  13950. endMatrix = getScaledMatrix(shape, [x, y], type);
  13951. doAnimation(shape, {
  13952. matrix: endMatrix
  13953. }, animateCfg);
  13954. }
  13955. }
  13956. function groupScaleInX(container, animateCfg, coord, zeroY) {
  13957. _groupScaleIn(container, animateCfg, coord, zeroY, 'x');
  13958. }
  13959. function groupScaleInY(container, animateCfg, coord, zeroY) {
  13960. _groupScaleIn(container, animateCfg, coord, zeroY, 'y');
  13961. }
  13962. function groupScaleInXY(container, animateCfg, coord, zeroY) {
  13963. _groupScaleIn(container, animateCfg, coord, zeroY, 'xy');
  13964. }
  13965. function shapesScaleInX(container, animateCfg) {
  13966. _shapeScale(container, animateCfg, 'x');
  13967. }
  13968. function shapesScaleInY(container, animateCfg) {
  13969. _shapeScale(container, animateCfg, 'y');
  13970. }
  13971. function shapesScaleInXY(container, animateCfg) {
  13972. _shapeScale(container, animateCfg, 'xy');
  13973. }
  13974. function groupWaveIn(container, animateCfg, coord) {
  13975. var clip = getClip(coord);
  13976. clip.set('canvas', container.get('canvas'));
  13977. container.attr('clip', clip);
  13978. var onEnd = function onEnd() {
  13979. container.attr('clip', null);
  13980. clip.remove(true);
  13981. };
  13982. var endState = {};
  13983. if (coord.isPolar) {
  13984. var startAngle = coord.startAngle,
  13985. endAngle = coord.endAngle;
  13986. endState.endAngle = endAngle;
  13987. clip.attr('endAngle', startAngle);
  13988. } else {
  13989. var start = coord.start,
  13990. end = coord.end;
  13991. var width = Math.abs(start.x - end.x);
  13992. var height = Math.abs(start.y - end.y);
  13993. if (coord.isTransposed) {
  13994. clip.attr('height', 0);
  13995. endState.height = height;
  13996. } else {
  13997. clip.attr('width', 0);
  13998. endState.width = width;
  13999. }
  14000. }
  14001. doAnimation(clip, endState, animateCfg, onEnd);
  14002. }
  14003. var GroupAction = /*#__PURE__*/Object.freeze({
  14004. __proto__: null,
  14005. groupWaveIn: groupWaveIn,
  14006. groupScaleInX: groupScaleInX,
  14007. groupScaleInY: groupScaleInY,
  14008. groupScaleInXY: groupScaleInXY,
  14009. shapesScaleInX: shapesScaleInX,
  14010. shapesScaleInY: shapesScaleInY,
  14011. shapesScaleInXY: shapesScaleInXY
  14012. });
  14013. /**
  14014. * Handle the detail animations
  14015. * @author sima.zhang1990@gmail.com
  14016. */
  14017. var timeline;
  14018. Element.prototype.animate = function () {
  14019. var attrs = mix$1({}, this.get('attrs'));
  14020. return new Animator(this, attrs, timeline);
  14021. };
  14022. Chart.prototype.animate = function (cfg) {
  14023. this.set('animate', cfg);
  14024. return this;
  14025. };
  14026. Animate.Action = ShapeAction;
  14027. Animate.defaultCfg = {
  14028. interval: {
  14029. enter: function enter(coord) {
  14030. if (coord.isPolar && coord.transposed) {
  14031. // for pie chart
  14032. return function (shape) {
  14033. shape.set('zIndex', -1);
  14034. var container = shape.get('parent');
  14035. container.sort();
  14036. };
  14037. }
  14038. return fadeIn;
  14039. }
  14040. },
  14041. area: {
  14042. enter: function enter(coord) {
  14043. if (coord.isPolar) return null;
  14044. return fadeIn;
  14045. }
  14046. },
  14047. line: {
  14048. enter: function enter(coord) {
  14049. if (coord.isPolar) return null;
  14050. return fadeIn;
  14051. }
  14052. },
  14053. path: {
  14054. enter: function enter(coord) {
  14055. if (coord.isPolar) return null;
  14056. return fadeIn;
  14057. }
  14058. }
  14059. };
  14060. var GROUP_ANIMATION = {
  14061. line: function line(coord) {
  14062. if (coord.isPolar) {
  14063. return groupScaleInXY;
  14064. }
  14065. return groupWaveIn;
  14066. },
  14067. area: function area(coord) {
  14068. if (coord.isPolar) {
  14069. return groupScaleInXY;
  14070. }
  14071. return groupWaveIn;
  14072. },
  14073. path: function path(coord) {
  14074. if (coord.isPolar) {
  14075. return groupScaleInXY;
  14076. }
  14077. return groupWaveIn;
  14078. },
  14079. point: function point() {
  14080. return shapesScaleInXY;
  14081. },
  14082. interval: function interval(coord) {
  14083. var result;
  14084. if (coord.isPolar) {
  14085. // polar coodinate
  14086. result = groupScaleInXY;
  14087. if (coord.transposed) {
  14088. // pie chart
  14089. result = groupWaveIn;
  14090. }
  14091. } else {
  14092. result = coord.transposed ? groupScaleInX : groupScaleInY;
  14093. }
  14094. return result;
  14095. },
  14096. schema: function schema() {
  14097. return groupWaveIn;
  14098. }
  14099. };
  14100. function diff(fromAttrs, toAttrs) {
  14101. var endState = {};
  14102. for (var k in toAttrs) {
  14103. if (isNumber(fromAttrs[k]) && fromAttrs[k] !== toAttrs[k]) {
  14104. endState[k] = toAttrs[k];
  14105. } else if (isArray$1(fromAttrs[k]) && JSON.stringify(fromAttrs[k]) !== JSON.stringify(toAttrs[k])) {
  14106. endState[k] = toAttrs[k];
  14107. }
  14108. }
  14109. return endState;
  14110. } // Add a unique id identifier to each shape
  14111. function _getShapeId(geom, dataObj, geomIdx) {
  14112. var type = geom.get('type');
  14113. var id = 'geom' + geomIdx + '-' + type;
  14114. var xScale = geom.getXScale();
  14115. var yScale = geom.getYScale();
  14116. var xField = xScale.field || 'x';
  14117. var yField = yScale.field || 'y';
  14118. var yVal = dataObj[yField];
  14119. var xVal;
  14120. if (xScale.isIdentity) {
  14121. xVal = xScale.value;
  14122. } else {
  14123. xVal = dataObj[xField];
  14124. }
  14125. if (type === 'interval' || type === 'schema') {
  14126. id += '-' + xVal;
  14127. } else if (type === 'line' || type === 'area' || type === 'path') {
  14128. id += '-' + type;
  14129. } else {
  14130. id += xScale.isCategory ? '-' + xVal : '-' + xVal + '-' + yVal;
  14131. }
  14132. var groupScales = geom._getGroupScales();
  14133. each$1(groupScales, function (groupScale) {
  14134. var field = groupScale.field;
  14135. if (groupScale.type !== 'identity') {
  14136. id += '-' + dataObj[field];
  14137. }
  14138. });
  14139. return id;
  14140. } // get geometry's shapes
  14141. function getShapes(geoms, chart, coord) {
  14142. var shapes = [];
  14143. each$1(geoms, function (geom, geomIdx) {
  14144. var geomContainer = geom.get('container');
  14145. var geomShapes = geomContainer.get('children');
  14146. var type = geom.get('type');
  14147. var animateCfg = isNil$1(geom.get('animateCfg')) ? _getAnimateCfgByShapeType(type, chart) : geom.get('animateCfg');
  14148. if (animateCfg !== false) {
  14149. each$1(geomShapes, function (shape, index) {
  14150. if (shape.get('className') === type) {
  14151. shape._id = _getShapeId(geom, shape.get('origin')._origin, geomIdx);
  14152. shape.set('coord', coord);
  14153. shape.set('animateCfg', animateCfg);
  14154. shape.set('index', index);
  14155. shapes.push(shape);
  14156. }
  14157. });
  14158. }
  14159. geom.set('shapes', geomShapes);
  14160. });
  14161. return shapes;
  14162. }
  14163. function cache(shapes) {
  14164. var rst = {};
  14165. for (var i = 0, len = shapes.length; i < len; i++) {
  14166. var shape = shapes[i];
  14167. if (!shape._id || shape.isClip) continue;
  14168. var id = shape._id;
  14169. rst[id] = {
  14170. _id: id,
  14171. type: shape.get('type'),
  14172. // the type of shape
  14173. attrs: mix$1({}, shape._attrs.attrs),
  14174. // the graphics attributes of shape
  14175. className: shape.get('className'),
  14176. geomType: shape.get('className'),
  14177. index: shape.get('index'),
  14178. coord: shape.get('coord'),
  14179. animateCfg: shape.get('animateCfg')
  14180. };
  14181. }
  14182. return rst;
  14183. }
  14184. function getAnimate(geomType, coord, animationType, animationName) {
  14185. var result;
  14186. if (isFunction$1(animationName)) {
  14187. result = animationName;
  14188. } else if (isString(animationName)) {
  14189. result = Animate.Action[animationName];
  14190. } else {
  14191. result = Animate.getAnimation(geomType, coord, animationType);
  14192. }
  14193. return result;
  14194. }
  14195. function getAnimateCfg(geomType, animationType, animateCfg) {
  14196. if (animateCfg === false || isObject$1(animateCfg) && animateCfg[animationType] === false) {
  14197. return false;
  14198. }
  14199. var defaultCfg = Animate.getAnimateCfg(geomType, animationType);
  14200. if (animateCfg && animateCfg[animationType]) {
  14201. return deepMix({}, defaultCfg, animateCfg[animationType]);
  14202. }
  14203. return defaultCfg;
  14204. }
  14205. function addAnimate(cache, shapes, canvas) {
  14206. var animate;
  14207. var animateCfg; // the order of animation: leave -> update -> enter
  14208. var updateShapes = [];
  14209. var newShapes = [];
  14210. each$1(shapes, function (shape) {
  14211. var result = cache[shape._id];
  14212. if (!result) {
  14213. newShapes.push(shape);
  14214. } else {
  14215. shape.set('cacheShape', result);
  14216. updateShapes.push(shape);
  14217. delete cache[shape._id];
  14218. }
  14219. }); // first do the leave animation
  14220. each$1(cache, function (deletedShape) {
  14221. var className = deletedShape.className,
  14222. coord = deletedShape.coord,
  14223. _id = deletedShape._id,
  14224. attrs = deletedShape.attrs,
  14225. index = deletedShape.index,
  14226. type = deletedShape.type;
  14227. animateCfg = getAnimateCfg(className, 'leave', deletedShape.animateCfg);
  14228. if (animateCfg === false) return true;
  14229. animate = getAnimate(className, coord, 'leave', animateCfg.animation);
  14230. if (isFunction$1(animate)) {
  14231. var tempShape = canvas.addShape(type, {
  14232. attrs: attrs,
  14233. index: index,
  14234. canvas: canvas,
  14235. className: className
  14236. });
  14237. tempShape._id = _id;
  14238. animate(tempShape, animateCfg, coord);
  14239. }
  14240. }); // then do the update animation
  14241. each$1(updateShapes, function (updateShape) {
  14242. var className = updateShape.get('className');
  14243. animateCfg = getAnimateCfg(className, 'update', updateShape.get('animateCfg'));
  14244. if (animateCfg === false) return true;
  14245. var coord = updateShape.get('coord');
  14246. var cacheAttrs = updateShape.get('cacheShape').attrs;
  14247. var endState = diff(cacheAttrs, updateShape._attrs.attrs); // 判断如果属性相同的话就不进行变换
  14248. if (Object.keys(endState).length) {
  14249. animate = getAnimate(className, coord, 'update', animateCfg.animation);
  14250. if (isFunction$1(animate)) {
  14251. animate(updateShape, animateCfg, coord);
  14252. } else {
  14253. var startState = {};
  14254. each$1(endState, function (value, key) {
  14255. startState[key] = cacheAttrs[key];
  14256. });
  14257. updateShape.attr(startState);
  14258. updateShape.animate().to({
  14259. attrs: endState,
  14260. duration: animateCfg.duration,
  14261. easing: animateCfg.easing,
  14262. delay: animateCfg.delay
  14263. }).onEnd(function () {
  14264. updateShape.set('cacheShape', null);
  14265. });
  14266. }
  14267. }
  14268. }); // last, enter animation
  14269. each$1(newShapes, function (newShape) {
  14270. // 新图形元素的进场元素
  14271. var className = newShape.get('className');
  14272. var coord = newShape.get('coord');
  14273. animateCfg = getAnimateCfg(className, 'enter', newShape.get('animateCfg'));
  14274. if (animateCfg === false) return true;
  14275. animate = getAnimate(className, coord, 'enter', animateCfg.animation);
  14276. if (isFunction$1(animate)) {
  14277. if (className === 'interval' && coord.isPolar && coord.transposed) {
  14278. var index = newShape.get('index');
  14279. var lastShape = updateShapes[index - 1];
  14280. animate(newShape, animateCfg, lastShape);
  14281. } else {
  14282. animate(newShape, animateCfg, coord);
  14283. }
  14284. }
  14285. });
  14286. }
  14287. function _getAnimateCfgByShapeType(type, chart) {
  14288. if (!type) {
  14289. return null;
  14290. }
  14291. var animateCfg = chart.get('animate');
  14292. if (type.indexOf('guide-tag') > -1) {
  14293. type = 'guide-tag';
  14294. }
  14295. if (isObject$1(animateCfg)) {
  14296. return animateCfg[type];
  14297. }
  14298. if (animateCfg === false) {
  14299. return false;
  14300. }
  14301. return null;
  14302. }
  14303. function afterCanvasInit() {
  14304. timeline = new Timeline();
  14305. timeline.play();
  14306. }
  14307. function beforeCanvasDraw(chart) {
  14308. if (chart.get('animate') === false) {
  14309. return;
  14310. }
  14311. var isUpdate = chart.get('isUpdate');
  14312. var canvas = chart.get('canvas');
  14313. var coord = chart.get('coord');
  14314. var geoms = chart.get('geoms');
  14315. var caches = canvas.get('caches') || [];
  14316. if (caches.length === 0) {
  14317. isUpdate = false;
  14318. }
  14319. var cacheShapes = getShapes(geoms, chart, coord);
  14320. var _chart$get = chart.get('axisController'),
  14321. frontPlot = _chart$get.frontPlot,
  14322. backPlot = _chart$get.backPlot;
  14323. var axisShapes = frontPlot.get('children').concat(backPlot.get('children'));
  14324. var guideShapes = [];
  14325. if (chart.get('guideController')) {
  14326. guideShapes = chart.get('guideController').guideShapes;
  14327. }
  14328. var componentShapes = [];
  14329. axisShapes.concat(guideShapes).forEach(function (s) {
  14330. var className = s.get('className');
  14331. var animateCfg = _getAnimateCfgByShapeType(className, chart);
  14332. s.set('coord', coord);
  14333. s.set('animateCfg', animateCfg);
  14334. componentShapes.push(s);
  14335. cacheShapes.push(s);
  14336. });
  14337. canvas.set('caches', cache(cacheShapes));
  14338. if (isUpdate) {
  14339. addAnimate(caches, cacheShapes, canvas);
  14340. } else {
  14341. // do the appear animation
  14342. var animateCfg;
  14343. var animate;
  14344. each$1(geoms, function (geom) {
  14345. var type = geom.get('type');
  14346. var geomCfg = isNil$1(geom.get('animateCfg')) ? _getAnimateCfgByShapeType(type, chart) : geom.get('animateCfg');
  14347. if (geomCfg !== false) {
  14348. animateCfg = getAnimateCfg(type, 'appear', geomCfg);
  14349. animate = getAnimate(type, coord, 'appear', animateCfg.animation);
  14350. if (isFunction$1(animate)) {
  14351. var shapes = geom.get('shapes');
  14352. each$1(shapes, function (shape) {
  14353. animate(shape, animateCfg, coord);
  14354. });
  14355. } else if (GROUP_ANIMATION[type]) {
  14356. // do the default animation
  14357. animate = GroupAction[animateCfg.animation] || GROUP_ANIMATION[type](coord);
  14358. var yScale = geom.getYScale();
  14359. var zeroY = coord.convertPoint({
  14360. x: 0,
  14361. y: yScale.scale(geom.getYMinValue())
  14362. });
  14363. var container = geom.get('container');
  14364. animate && animate(container, animateCfg, coord, zeroY);
  14365. }
  14366. }
  14367. }); // do the animation of components
  14368. each$1(componentShapes, function (shape) {
  14369. var animateCfg = shape.get('animateCfg');
  14370. var className = shape.get('className');
  14371. if (animateCfg && animateCfg.appear) {
  14372. // if user configure
  14373. var defaultCfg = Animate.getAnimateCfg(className, 'appear');
  14374. var appearCfg = deepMix({}, defaultCfg, animateCfg.appear);
  14375. var _animate = getAnimate(className, coord, 'appear', appearCfg.animation);
  14376. if (isFunction$1(_animate)) {
  14377. _animate(shape, appearCfg, coord);
  14378. }
  14379. }
  14380. });
  14381. }
  14382. }
  14383. function afterCanvasDestroyed() {
  14384. timeline.stop();
  14385. }
  14386. var detail = {
  14387. afterCanvasInit: afterCanvasInit,
  14388. beforeCanvasDraw: beforeCanvasDraw,
  14389. afterCanvasDestroyed: afterCanvasDestroyed
  14390. };
  14391. var Animation = /*#__PURE__*/Object.freeze({
  14392. __proto__: null,
  14393. afterCanvasInit: afterCanvasInit,
  14394. beforeCanvasDraw: beforeCanvasDraw,
  14395. afterCanvasDestroyed: afterCanvasDestroyed,
  14396. 'default': detail
  14397. });
  14398. Chart._Interactions = {};
  14399. Chart.registerInteraction = function (type, constructor) {
  14400. Chart._Interactions[type] = constructor;
  14401. };
  14402. Chart.getInteraction = function (type) {
  14403. return Chart._Interactions[type];
  14404. };
  14405. Chart.prototype.interaction = function (type, cfg) {
  14406. var interactions = this._interactions || {};
  14407. if (interactions[type]) {
  14408. // if reprated, destroy last
  14409. interactions[type].destroy();
  14410. }
  14411. var Ctor = Chart.getInteraction(type);
  14412. var interact = new Ctor(cfg, this);
  14413. interactions[type] = interact;
  14414. this._interactions = interactions;
  14415. return this;
  14416. };
  14417. Chart.prototype.clearInteraction = function (type) {
  14418. var interactions = this._interactions;
  14419. if (!interactions) return;
  14420. if (type) {
  14421. interactions[type] && interactions[type].destroy();
  14422. delete interactions[type];
  14423. } else {
  14424. each$1(interactions, function (interaction, key) {
  14425. interaction.destroy();
  14426. delete interactions[key];
  14427. });
  14428. }
  14429. return this;
  14430. };
  14431. function isValuesEqual(values, newValues) {
  14432. if (values.length !== newValues.length) {
  14433. return false;
  14434. }
  14435. var lastIndex = values.length - 1;
  14436. return values[0] === newValues[0] && values[lastIndex] === newValues[lastIndex];
  14437. } // 不同交互之间共享的上下文
  14438. var defaultRange = [0, 1];
  14439. var Context = /*#__PURE__*/function () {
  14440. // 最开始的原始值
  14441. // 当前显示的范围
  14442. // 缩放最小的点数
  14443. // 最小的缩放比例, 默认通过minCount计算
  14444. // minScale = 0.01;
  14445. // 交互开始时,ticks个数,主要为了每次缩放后,更新ticks个数
  14446. // lastTickCount;
  14447. function Context(chart) {
  14448. var _this = this;
  14449. _defineProperty(this, "chart", null);
  14450. _defineProperty(this, "values", null);
  14451. _defineProperty(this, "range", defaultRange);
  14452. _defineProperty(this, "startRange", defaultRange);
  14453. _defineProperty(this, "minCount", 10);
  14454. _defineProperty(this, "_afterinit", function () {
  14455. // 初始化value值
  14456. var scale = _this.getPinchScale(); // 记录原始全量数据
  14457. var values = [].concat(scale.values);
  14458. _this.values = values; // 最小的缩放比例
  14459. if (!_this.minScale) {
  14460. _this.minScale = _this.minCount / values.length;
  14461. } // 初始化的时候有设置range,则初始化成默认比例
  14462. if (_this.range !== defaultRange) {
  14463. _this.updateRange(_this.range);
  14464. _this.updateTicks();
  14465. }
  14466. });
  14467. _defineProperty(this, "_afterdatachange", function () {
  14468. _this.updateRange(_this.range);
  14469. });
  14470. this.chart = chart;
  14471. this._initEvent(chart);
  14472. }
  14473. var _proto = Context.prototype;
  14474. _proto._initEvent = function _initEvent(chart) {
  14475. // 在整体初始化后还需要设置一些初始状态
  14476. chart.on(EVENT_AFTER_INIT, this._afterinit);
  14477. chart.on(EVENT_AFTER_DATA_CHANGE, this._afterdatachange);
  14478. } // 缩放的主轴scale
  14479. ;
  14480. _proto.getPinchScale = function getPinchScale() {
  14481. var chart = this.chart; // 默认缩放x轴
  14482. var scale = chart.getXScale();
  14483. return scale;
  14484. } // 跟随轴的scale
  14485. ;
  14486. _proto.getFollowScale = function getFollowScale() {
  14487. var chart = this.chart; // 默认缩放x轴
  14488. var scales = chart.getYScales() || [];
  14489. return scales[0];
  14490. };
  14491. _proto.start = function start() {
  14492. var range = this.range;
  14493. var scale = this.getPinchScale();
  14494. var start = range[0],
  14495. end = range[1]; // 记录交互起始的范围
  14496. this.startRange = [start, end]; // 记录开始时的ticks个数
  14497. this.lastTickCount = scale.tickCount;
  14498. };
  14499. _proto.doZoom = function doZoom(leftScale, rightScale, zoom) {
  14500. var range = this.startRange,
  14501. minScale = this.minScale;
  14502. var start = range[0],
  14503. end = range[1];
  14504. var zoomOffset = 1 - zoom;
  14505. var rangeLen = end - start;
  14506. var rangeOffset = rangeLen * zoomOffset;
  14507. var leftOffset = rangeOffset * leftScale;
  14508. var rightOffset = rangeOffset * rightScale;
  14509. var newStart = Math.max(0, start - leftOffset);
  14510. var newEnd = Math.min(1, end + rightOffset);
  14511. var newRange = [newStart, newEnd]; // 如果已经到了最小比例,则不能再继续再放大
  14512. if (newEnd - newStart < minScale) {
  14513. return;
  14514. }
  14515. this.updateRange(newRange);
  14516. };
  14517. _proto.doMove = function doMove(ratio) {
  14518. // 不管是0, 还是其他,都不用处理
  14519. if (!ratio) return;
  14520. var range = this.startRange;
  14521. var start = range[0],
  14522. end = range[1];
  14523. var rangeLen = end - start;
  14524. var rangeOffset = rangeLen * ratio;
  14525. var newStart = start - rangeOffset;
  14526. var newEnd = end - rangeOffset; // 处理边界值
  14527. var newRange;
  14528. if (newStart < 0) {
  14529. newRange = [0, rangeLen];
  14530. } else if (newEnd > 1) {
  14531. newRange = [1 - rangeLen, 1];
  14532. } else {
  14533. newRange = [newStart, newEnd];
  14534. }
  14535. this.updateRange(newRange);
  14536. };
  14537. _proto.updateRange = function updateRange(range) {
  14538. var values = this.values; // 0, 1 的范围之间
  14539. var start = range[0],
  14540. end = range[1]; // start 不能小于0
  14541. start = Math.max(0, start); // end 不能大于1
  14542. end = Math.min(1, end); // 设置当前的范围
  14543. this.range = [start, end];
  14544. var len = values.length;
  14545. var valueStart = start * len;
  14546. var valueEnd = end * len; // 从原始数据里截取需要显示的数据
  14547. var newValues = values.slice(valueStart, valueEnd);
  14548. this.repaint(newValues);
  14549. };
  14550. _proto.repaint = function repaint(newValues) {
  14551. var chart = this.chart;
  14552. var scale = this.getPinchScale();
  14553. var currentValues = scale.values,
  14554. ticks = scale.ticks; // 如果新数组和当前显示的数组相同,则不更新
  14555. if (isValuesEqual(currentValues, newValues)) {
  14556. return;
  14557. } // 更新主轴values
  14558. this.updateScale(scale, {
  14559. ticks: ticks,
  14560. values: newValues
  14561. });
  14562. this.updateFollowScale(scale, newValues);
  14563. chart.repaint();
  14564. };
  14565. _proto.updateFollowScale = function updateFollowScale(pinchScale, pinchValues) {
  14566. var chart = this.chart;
  14567. var followScale = this.getFollowScale();
  14568. var pinchField = pinchScale.field,
  14569. pinchScaleType = pinchScale.type;
  14570. var followField = followScale.field; // 根据主轴的value值,找到所有从轴的value值
  14571. var values = []; // 转成map,让查找性能更高
  14572. var pinchValueMap = {};
  14573. pinchValues.forEach(function (item) {
  14574. pinchValueMap[item] = true;
  14575. });
  14576. var data = chart.get('data');
  14577. data.forEach(function (item) {
  14578. if (pinchScaleType === 'timeCat') {
  14579. var value = toTimeStamp$1(item[pinchField]);
  14580. if (pinchValueMap[value]) {
  14581. values.push(item[followField]);
  14582. }
  14583. }
  14584. });
  14585. var _getRange = getRange(values),
  14586. min = _getRange.min,
  14587. max = _getRange.max;
  14588. this.updateScale(followScale, {
  14589. min: min,
  14590. max: max,
  14591. nice: true
  14592. });
  14593. };
  14594. _proto.updateScale = function updateScale(scale, cfg) {
  14595. if (!scale) {
  14596. return;
  14597. }
  14598. scale.change(cfg);
  14599. } // 上一次的tick个数
  14600. ;
  14601. _proto.updateTicks = function updateTicks() {
  14602. var chart = this.chart,
  14603. values = this.values;
  14604. var scale = this.getPinchScale();
  14605. var currentValues = scale.values,
  14606. tickCount = scale.tickCount; // 根据当前数据的比例,和定义的tickCount计算应该需要多少个ticks
  14607. var newTickCount = Math.round(tickCount * values.length / currentValues.length);
  14608. var catTicks = getTickMethod('cat');
  14609. var ticks = catTicks({
  14610. tickCount: newTickCount,
  14611. values: values
  14612. });
  14613. this.updateScale(scale, {
  14614. ticks: ticks,
  14615. values: currentValues
  14616. }); // 更新完后,需要重新绘制一次
  14617. chart.repaint();
  14618. };
  14619. _proto.destroy = function destroy() {
  14620. var chart = this.chart;
  14621. chart.off(EVENT_AFTER_INIT, this._afterinit);
  14622. chart.off(EVENT_AFTER_DATA_CHANGE, this._afterdatachange);
  14623. };
  14624. return Context;
  14625. }();
  14626. var Base = /*#__PURE__*/function () {
  14627. var _proto = Base.prototype;
  14628. // 交互的上下文
  14629. _proto.getDefaultCfg = function getDefaultCfg() {
  14630. return {};
  14631. };
  14632. _proto.getInteractionContext = function getInteractionContext(chart) {
  14633. var interactionContext = chart.get('interactionContext');
  14634. if (interactionContext) {
  14635. return interactionContext;
  14636. }
  14637. interactionContext = new Context(chart);
  14638. chart.set('interactionContext', interactionContext);
  14639. return interactionContext;
  14640. };
  14641. function Base(cfg, chart) {
  14642. var _this = this;
  14643. _defineProperty(this, "type", '');
  14644. _defineProperty(this, "startEvent", 'touchstart');
  14645. _defineProperty(this, "processEvent", 'touchmove');
  14646. _defineProperty(this, "endEvent", 'touchend');
  14647. _defineProperty(this, "resetEvent", null);
  14648. _defineProperty(this, "context", null);
  14649. _defineProperty(this, "_start", function (ev) {
  14650. _this.preStart && _this.preStart(ev);
  14651. _this.start(ev);
  14652. _this.onStart && _this.onStart(ev);
  14653. });
  14654. _defineProperty(this, "_process", function (ev) {
  14655. _this.preProcess && _this.preProcess(ev);
  14656. _this.process(ev);
  14657. _this.onProcess && _this.onProcess(ev);
  14658. });
  14659. _defineProperty(this, "_end", function (ev) {
  14660. _this.preEnd && _this.preEnd(ev);
  14661. _this.end(ev);
  14662. _this.onEnd && _this.onEnd(ev);
  14663. });
  14664. _defineProperty(this, "_reset", function (ev) {
  14665. _this.preReset && _this.preReset(ev);
  14666. _this.reset(ev);
  14667. _this.onReset && _this.onReset(ev);
  14668. });
  14669. mix$1(this, this.getDefaultCfg(), cfg);
  14670. this.context = this.getInteractionContext(chart);
  14671. this.chart = chart; // 只处理range, 暂时先这么处理后面再看情况调整
  14672. var range = this.range;
  14673. if (range) {
  14674. this.context.range = range;
  14675. }
  14676. this._bindEvents(chart);
  14677. }
  14678. _proto._bindEvents = function _bindEvents(chart) {
  14679. var startEvent = this.startEvent,
  14680. processEvent = this.processEvent,
  14681. endEvent = this.endEvent,
  14682. resetEvent = this.resetEvent;
  14683. var canvas = chart.get('canvas'); // 统一绑定事件
  14684. canvas.on(startEvent, this._start);
  14685. canvas.on(processEvent, this._process);
  14686. canvas.on(endEvent, this._end);
  14687. canvas.on(resetEvent, this._reset);
  14688. };
  14689. _proto._clearEvents = function _clearEvents() {
  14690. var chart = this.chart,
  14691. startEvent = this.startEvent,
  14692. processEvent = this.processEvent,
  14693. endEvent = this.endEvent,
  14694. resetEvent = this.resetEvent;
  14695. var canvas = chart.get('canvas'); // 统一绑定事件
  14696. canvas.off(startEvent, this._start);
  14697. canvas.off(processEvent, this._process);
  14698. canvas.off(endEvent, this._end);
  14699. canvas.off(resetEvent, this._start);
  14700. };
  14701. // override
  14702. _proto.start = function start() {} // override
  14703. ;
  14704. _proto.process = function process() {} // override
  14705. ;
  14706. _proto.end = function end() {} // override
  14707. ;
  14708. _proto.reset = function reset() {};
  14709. _proto.destroy = function destroy() {
  14710. this.context.destroy();
  14711. this._clearEvents();
  14712. };
  14713. return Base;
  14714. }();
  14715. var Pan = /*#__PURE__*/function (_Base) {
  14716. _inheritsLoose$3(Pan, _Base);
  14717. function Pan() {
  14718. return _Base.apply(this, arguments) || this;
  14719. }
  14720. var _proto = Pan.prototype;
  14721. _proto.getDefaultCfg = function getDefaultCfg() {
  14722. return {
  14723. type: 'pan',
  14724. startEvent: 'panstart',
  14725. processEvent: 'pan',
  14726. endEvent: 'panend'
  14727. };
  14728. };
  14729. _proto.start = function start() {
  14730. var context = this.context;
  14731. context.start();
  14732. };
  14733. _proto.process = function process(e) {
  14734. var direction = e.direction,
  14735. deltaX = e.deltaX;
  14736. if (direction === 'up' || direction === 'down') {
  14737. return;
  14738. }
  14739. e.preventDefault && e.preventDefault();
  14740. var context = this.context;
  14741. var chart = context.chart;
  14742. var coord = chart.get('coord');
  14743. var start = coord.start,
  14744. end = coord.end;
  14745. var coordWidth = end.x - start.x;
  14746. var ratio = deltaX / coordWidth;
  14747. context.doMove(ratio);
  14748. };
  14749. return Pan;
  14750. }(Base);
  14751. var Pinch = /*#__PURE__*/function (_Base) {
  14752. _inheritsLoose$3(Pinch, _Base);
  14753. var _proto = Pinch.prototype;
  14754. _proto.getDefaultCfg = function getDefaultCfg() {
  14755. return {
  14756. type: 'pinch',
  14757. startEvent: 'pinchstart',
  14758. processEvent: 'pinch',
  14759. endEvent: 'pinchend'
  14760. };
  14761. };
  14762. function Pinch(cfg, chart) {
  14763. var _this;
  14764. _this = _Base.call(this, cfg, chart) || this;
  14765. var _assertThisInitialize = _assertThisInitialized(_this),
  14766. context = _assertThisInitialize.context;
  14767. mix$1(context, cfg);
  14768. return _this;
  14769. }
  14770. _proto.start = function start() {
  14771. var context = this.context;
  14772. context.start();
  14773. };
  14774. _proto.process = function process(e) {
  14775. e.preventDefault && e.preventDefault();
  14776. var zoom = e.zoom,
  14777. center = e.center;
  14778. var context = this.context;
  14779. var chart = context.chart;
  14780. var coord = chart.get('coord');
  14781. var start = coord.start,
  14782. end = coord.end;
  14783. var coordWidth = end.x - start.x;
  14784. var leftLen = Math.abs(center.x - start.x);
  14785. var rightLen = Math.abs(end.x - center.x); // 计算左右缩放的比例
  14786. var leftScale = leftLen / coordWidth;
  14787. var rightScale = rightLen / coordWidth;
  14788. context.doZoom(leftScale, rightScale, zoom);
  14789. };
  14790. _proto.end = function end() {
  14791. // 缩放完成后再更新ticks
  14792. var context = this.context;
  14793. context.updateTicks();
  14794. };
  14795. return Pinch;
  14796. }(Base);
  14797. Chart.registerInteraction('pan', Pan);
  14798. Chart.registerInteraction('pinch', Pinch);
  14799. /**
  14800. * Default, without interactins
  14801. */
  14802. var Component = {
  14803. // 为了兼容之前版本
  14804. Marker: Shape.Marker,
  14805. Tooltip: Tooltip$1
  14806. }; // register plugins
  14807. Chart.plugins.register([Tooltip, Legend, Guide, Animation]); // 默认添加交互
  14808. var index = {
  14809. Component: Component,
  14810. Global: Global,
  14811. Chart: Chart,
  14812. Shape: Shape$1,
  14813. G: G,
  14814. Util: Util,
  14815. Helper: Helper,
  14816. track: track,
  14817. Animate: Animate
  14818. };
  14819. exports.Animate = Animate;
  14820. exports.Chart = Chart;
  14821. exports.Component = Component;
  14822. exports.G = G;
  14823. exports.Global = Global;
  14824. exports.Helper = Helper;
  14825. exports.Shape = Shape$1;
  14826. exports.Util = Util;
  14827. exports["default"] = index;
  14828. exports.track = track;
  14829. Object.defineProperty(exports, '__esModule', { value: true });
  14830. }));